ss: Move plugins to Trace Compass namespace
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / widgets / timegraph / TimeGraphViewer.java
1 /*****************************************************************************
2 * Copyright (c) 2007, 2014 Intel Corporation, Ericsson, others
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 * Intel Corporation - Initial API and implementation
10 * Ruslan A. Scherbakov, Intel - Initial API and implementation
11 * Alexander N. Alexeev, Intel - Add monitors statistics support
12 * Alvaro Sanchez-Leon - Adapted for TMF
13 * Patrick Tasse - Refactoring
14 * Geneviève Bastien - Add event links between entries
15 *****************************************************************************/
16
17 package org.eclipse.linuxtools.tmf.ui.widgets.timegraph;
18
19 import java.util.ArrayList;
20 import java.util.List;
21
22 import org.eclipse.jface.action.Action;
23 import org.eclipse.jface.action.IAction;
24 import org.eclipse.jface.dialogs.IDialogSettings;
25 import org.eclipse.jface.viewers.AbstractTreeViewer;
26 import org.eclipse.jface.viewers.ISelectionProvider;
27 import org.eclipse.jface.viewers.ViewerFilter;
28 import org.eclipse.linuxtools.internal.tmf.ui.Activator;
29 import org.eclipse.linuxtools.internal.tmf.ui.ITmfImageConstants;
30 import org.eclipse.linuxtools.internal.tmf.ui.Messages;
31 import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.dialogs.TimeGraphLegend;
32 import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ILinkEvent;
33 import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent;
34 import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeGraphEntry;
35 import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.ITimeDataProvider;
36 import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TimeDataProviderCyclesConverter;
37 import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TimeGraphColorScheme;
38 import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TimeGraphControl;
39 import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TimeGraphScale;
40 import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TimeGraphTooltipHandler;
41 import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.Utils;
42 import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.Utils.TimeFormat;
43 import org.eclipse.swt.SWT;
44 import org.eclipse.swt.events.ControlAdapter;
45 import org.eclipse.swt.events.ControlEvent;
46 import org.eclipse.swt.events.KeyAdapter;
47 import org.eclipse.swt.events.KeyEvent;
48 import org.eclipse.swt.events.MenuDetectListener;
49 import org.eclipse.swt.events.MouseEvent;
50 import org.eclipse.swt.events.MouseWheelListener;
51 import org.eclipse.swt.events.SelectionAdapter;
52 import org.eclipse.swt.events.SelectionEvent;
53 import org.eclipse.swt.events.SelectionListener;
54 import org.eclipse.swt.graphics.Rectangle;
55 import org.eclipse.swt.layout.FillLayout;
56 import org.eclipse.swt.layout.GridData;
57 import org.eclipse.swt.layout.GridLayout;
58 import org.eclipse.swt.widgets.Composite;
59 import org.eclipse.swt.widgets.Control;
60 import org.eclipse.swt.widgets.ScrollBar;
61 import org.eclipse.swt.widgets.Slider;
62
63 /**
64 * Generic time graph viewer implementation
65 *
66 * @version 1.0
67 * @author Patrick Tasse, and others
68 */
69 public class TimeGraphViewer implements ITimeDataProvider, SelectionListener {
70
71 /** Constant indicating that all levels of the time graph should be expanded
72 * @since 3.1 */
73 public static final int ALL_LEVELS = AbstractTreeViewer.ALL_LEVELS;
74
75 private static final int DEFAULT_NAME_WIDTH = 200;
76 private static final int MIN_NAME_WIDTH = 6;
77 private static final int MAX_NAME_WIDTH = 1000;
78 private static final int DEFAULT_HEIGHT = 22;
79 private static final long RECENTERING_MARGIN_FACTOR = 50;
80 private static final String HIDE_ARROWS_KEY = "hide.arrows"; //$NON-NLS-1$
81 private static final long DEFAULT_FREQUENCY = 1000000000L;
82
83 private long fMinTimeInterval;
84 private ITimeGraphEntry fSelectedEntry;
85 private long fBeginTime;
86 private long fEndTime;
87 private long fTime0;
88 private long fTime1;
89 private long fSelectionBegin = 0;
90 private long fSelectionEnd = 0;
91 private long fTime0Bound;
92 private long fTime1Bound;
93 private long fTime0ExtSynch = 0;
94 private long fTime1ExtSynch = 0;
95 private boolean fTimeRangeFixed;
96 private int fNameWidthPref = DEFAULT_NAME_WIDTH;
97 private int fMinNameWidth = MIN_NAME_WIDTH;
98 private int fNameWidth;
99 private Composite fDataViewer;
100
101 private TimeGraphControl fTimeGraphCtrl;
102 private TimeGraphScale fTimeScaleCtrl;
103 private Slider fVerticalScrollBar;
104 private TimeGraphColorScheme fColorScheme;
105 private Object fInputElement;
106 private ITimeGraphContentProvider fTimeGraphContentProvider;
107 private ITimeGraphPresentationProvider fTimeGraphProvider;
108 private ITimeDataProvider fTimeDataProvider = this;
109 private TimeGraphTooltipHandler fToolTipHandler;
110
111 private List<ITimeGraphSelectionListener> fSelectionListeners = new ArrayList<>();
112 private List<ITimeGraphTimeListener> fTimeListeners = new ArrayList<>();
113 private List<ITimeGraphRangeListener> fRangeListeners = new ArrayList<>();
114
115 // Time format, using Epoch reference, Relative time format(default),
116 // Number, or Cycles
117 private TimeFormat fTimeFormat = TimeFormat.RELATIVE;
118 // Clock frequency to use for Cycles time format
119 private long fClockFrequency = DEFAULT_FREQUENCY;
120 private int fBorderWidth = 0;
121 private int fTimeScaleHeight = DEFAULT_HEIGHT;
122
123 private Action fResetScaleAction;
124 private Action fShowLegendAction;
125 private Action fNextEventAction;
126 private Action fPrevEventAction;
127 private Action fNextItemAction;
128 private Action fPreviousItemAction;
129 private Action fZoomInAction;
130 private Action fZoomOutAction;
131 private Action fHideArrowsAction;
132 private Action fFollowArrowFwdAction;
133 private Action fFollowArrowBwdAction;
134
135 /**
136 * Standard constructor.
137 * <p>
138 * The default timegraph content provider accepts an ITimeGraphEntry[] as input element.
139 *
140 * @param parent
141 * The parent UI composite object
142 * @param style
143 * The style to use
144 */
145 public TimeGraphViewer(Composite parent, int style) {
146 createDataViewer(parent, style);
147 fTimeGraphContentProvider = new ITimeGraphContentProvider() {
148 @Override
149 public ITimeGraphEntry[] getElements(Object inputElement) {
150 if (inputElement instanceof ITimeGraphEntry[]) {
151 return (ITimeGraphEntry[]) inputElement;
152 }
153 return new ITimeGraphEntry[0];
154 }
155 };
156 }
157
158 /**
159 * Sets the timegraph content provider used by this timegraph viewer.
160 *
161 * @param timeGraphContentProvider
162 * the timegraph content provider
163 *
164 * @since 3.0
165 */
166 public void setTimeGraphContentProvider(ITimeGraphContentProvider timeGraphContentProvider) {
167 fTimeGraphContentProvider = timeGraphContentProvider;
168 }
169
170 /**
171 * Gets the timegraph content provider used by this timegraph viewer.
172 *
173 * @return the timegraph content provider
174 *
175 * @since 3.0
176 */
177 public ITimeGraphContentProvider getTimeGraphContentProvider() {
178 return fTimeGraphContentProvider;
179 }
180
181 /**
182 * Sets the timegraph presentation provider used by this timegraph viewer.
183 *
184 * @param timeGraphProvider
185 * the timegraph provider
186 */
187 public void setTimeGraphProvider(ITimeGraphPresentationProvider timeGraphProvider) {
188 fTimeGraphProvider = timeGraphProvider;
189 fTimeGraphCtrl.setTimeGraphProvider(timeGraphProvider);
190 fToolTipHandler = new TimeGraphTooltipHandler(fTimeGraphProvider, fTimeDataProvider);
191 fToolTipHandler.activateHoverHelp(fTimeGraphCtrl);
192 }
193
194 /**
195 * Sets or clears the input for this time graph viewer.
196 *
197 * @param inputElement
198 * The input of this time graph viewer, or <code>null</code> if
199 * none
200 *
201 * @since 3.0
202 */
203 public void setInput(Object inputElement) {
204 fInputElement = inputElement;
205 ITimeGraphEntry[] input = fTimeGraphContentProvider.getElements(inputElement);
206
207 if (fTimeGraphCtrl != null) {
208 setTimeRange(input);
209 fVerticalScrollBar.setEnabled(true);
210 setTopIndex(0);
211 fSelectionBegin = 0;
212 fSelectionEnd = 0;
213 fSelectedEntry = null;
214 refreshAllData(input);
215 }
216 }
217
218 /**
219 * Gets the input for this time graph viewer.
220 *
221 * @return The input of this time graph viewer, or <code>null</code> if none
222 *
223 * @since 3.0
224 */
225 public Object getInput() {
226 return fInputElement;
227 }
228
229 /**
230 * Sets (or clears if null) the list of links to display on this combo
231 *
232 * @param links
233 * the links to display in this time graph combo
234 * @since 2.1
235 */
236 public void setLinks(List<ILinkEvent> links) {
237 if (fTimeGraphCtrl != null) {
238 fTimeGraphCtrl.refreshArrows(links);
239 }
240 }
241
242 /**
243 * Refresh the view
244 */
245 public void refresh() {
246 ITimeGraphEntry[] input = fTimeGraphContentProvider.getElements(fInputElement);
247 setTimeRange(input);
248 fVerticalScrollBar.setEnabled(true);
249 refreshAllData(input);
250 }
251
252 /**
253 * Callback for when the control is moved
254 *
255 * @param e
256 * The caller event
257 */
258 public void controlMoved(ControlEvent e) {
259 }
260
261 /**
262 * Callback for when the control is resized
263 *
264 * @param e
265 * The caller event
266 */
267 public void controlResized(ControlEvent e) {
268 resizeControls();
269 }
270
271 /**
272 * Handler for when the model is updated. Called from the display order in
273 * the API
274 *
275 * @param traces
276 * The traces in the model
277 * @param start
278 * The start time
279 * @param end
280 * The end time
281 * @param updateTimeBounds
282 * Should we updated the time bounds too
283 */
284 public void modelUpdate(ITimeGraphEntry[] traces, long start,
285 long end, boolean updateTimeBounds) {
286 if (null != fTimeGraphCtrl) {
287 updateInternalData(traces, start, end);
288 if (updateTimeBounds) {
289 fTimeRangeFixed = true;
290 // set window to match limits
291 setStartFinishTime(fTime0Bound, fTime1Bound);
292 } else {
293 fTimeGraphCtrl.redraw();
294 fTimeScaleCtrl.redraw();
295 }
296 }
297 }
298
299 /**
300 * @return The string representing the view type
301 */
302 protected String getViewTypeStr() {
303 return "viewoption.threads"; //$NON-NLS-1$
304 }
305
306 int getMarginWidth() {
307 return 0;
308 }
309
310 int getMarginHeight() {
311 return 0;
312 }
313
314 void loadOptions() {
315 fMinTimeInterval = 1;
316 fSelectionBegin = -1;
317 fSelectionEnd = -1;
318 fNameWidth = Utils.loadIntOption(getPreferenceString("namewidth"), //$NON-NLS-1$
319 fNameWidthPref, fMinNameWidth, MAX_NAME_WIDTH);
320 }
321
322 void saveOptions() {
323 Utils.saveIntOption(getPreferenceString("namewidth"), fNameWidth); //$NON-NLS-1$
324 }
325
326 /**
327 * Create a data viewer.
328 *
329 * @param parent
330 * Parent composite
331 * @param style
332 * Style to use
333 * @return The new data viewer
334 */
335 protected Control createDataViewer(Composite parent, int style) {
336 loadOptions();
337 fColorScheme = new TimeGraphColorScheme();
338 fDataViewer = new Composite(parent, style) {
339 @Override
340 public void redraw() {
341 fTimeScaleCtrl.redraw();
342 fTimeGraphCtrl.redraw();
343 super.redraw();
344 }
345 };
346 GridLayout gl = new GridLayout(2, false);
347 gl.marginHeight = fBorderWidth;
348 gl.marginWidth = 0;
349 gl.verticalSpacing = 0;
350 gl.horizontalSpacing = 0;
351 fDataViewer.setLayout(gl);
352
353 fTimeScaleCtrl = new TimeGraphScale(fDataViewer, fColorScheme);
354 fTimeScaleCtrl.setTimeProvider(fTimeDataProvider);
355 fTimeScaleCtrl.setLayoutData(new GridData(SWT.FILL, SWT.DEFAULT, true, false));
356 fTimeScaleCtrl.setHeight(fTimeScaleHeight);
357
358 fVerticalScrollBar = new Slider(fDataViewer, SWT.VERTICAL | SWT.NO_FOCUS);
359 fVerticalScrollBar.setLayoutData(new GridData(SWT.DEFAULT, SWT.FILL, false, true, 1, 2));
360 fVerticalScrollBar.addSelectionListener(new SelectionAdapter() {
361 @Override
362 public void widgetSelected(SelectionEvent e) {
363 setTopIndex(fVerticalScrollBar.getSelection());
364 }
365 });
366 fVerticalScrollBar.setEnabled(false);
367
368 fTimeGraphCtrl = createTimeGraphControl(fDataViewer, fColorScheme);
369
370 fTimeGraphCtrl.setTimeProvider(this);
371 fTimeGraphCtrl.setTimeGraphScale(fTimeScaleCtrl);
372 fTimeGraphCtrl.addSelectionListener(this);
373 fTimeGraphCtrl.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 2));
374 fTimeGraphCtrl.addMouseWheelListener(new MouseWheelListener() {
375 @Override
376 public void mouseScrolled(MouseEvent e) {
377 adjustVerticalScrollBar();
378 }
379 });
380 fTimeGraphCtrl.addKeyListener(new KeyAdapter() {
381 @Override
382 public void keyPressed(KeyEvent e) {
383 if (e.character == '+') {
384 zoomIn();
385 } else if (e.character == '-') {
386 zoomOut();
387 }
388 adjustVerticalScrollBar();
389 }
390 });
391
392 Composite filler = new Composite(fDataViewer, SWT.NONE);
393 GridData gd = new GridData(SWT.DEFAULT, SWT.DEFAULT, false, false);
394 gd.heightHint = fTimeGraphCtrl.getHorizontalBar().getSize().y;
395 filler.setLayoutData(gd);
396 filler.setLayout(new FillLayout());
397
398 fTimeGraphCtrl.addControlListener(new ControlAdapter() {
399 @Override
400 public void controlResized(ControlEvent event) {
401 resizeControls();
402 }
403 });
404 resizeControls();
405 fDataViewer.update();
406 adjustVerticalScrollBar();
407 return fDataViewer;
408 }
409
410 /**
411 * Dispose the view.
412 */
413 public void dispose() {
414 saveOptions();
415 fTimeGraphCtrl.dispose();
416 fDataViewer.dispose();
417 fColorScheme.dispose();
418 }
419
420 /**
421 * Create a new time graph control.
422 *
423 * @param parent
424 * The parent composite
425 * @param colors
426 * The color scheme
427 * @return The new TimeGraphControl
428 * @since 2.0
429 */
430 protected TimeGraphControl createTimeGraphControl(Composite parent,
431 TimeGraphColorScheme colors) {
432 return new TimeGraphControl(parent, colors);
433 }
434
435 /**
436 * Resize the controls
437 */
438 public void resizeControls() {
439 Rectangle r = fDataViewer.getClientArea();
440 if (r.isEmpty()) {
441 return;
442 }
443
444 int width = r.width;
445 if (fNameWidth > width - fMinNameWidth) {
446 fNameWidth = width - fMinNameWidth;
447 }
448 if (fNameWidth < fMinNameWidth) {
449 fNameWidth = fMinNameWidth;
450 }
451 adjustVerticalScrollBar();
452 }
453
454 /**
455 * Try to set most convenient time range for display.
456 *
457 * @param traces
458 * The traces in the model
459 */
460 public void setTimeRange(ITimeGraphEntry traces[]) {
461 fEndTime = 0;
462 fBeginTime = -1;
463 for (int i = 0; i < traces.length; i++) {
464 ITimeGraphEntry entry = traces[i];
465 if (entry.getEndTime() >= entry.getStartTime() && entry.getEndTime() > 0) {
466 if (fBeginTime < 0 || entry.getStartTime() < fBeginTime) {
467 fBeginTime = entry.getStartTime();
468 }
469 if (entry.getEndTime() > fEndTime) {
470 fEndTime = entry.getEndTime();
471 }
472 }
473 }
474
475 if (fBeginTime < 0) {
476 fBeginTime = 0;
477 }
478 }
479
480 /**
481 * Recalculate the time bounds
482 */
483 public void setTimeBounds() {
484 fTime0Bound = fBeginTime;
485 if (fTime0Bound < 0) {
486 fTime0Bound = 0;
487 }
488 fTime1Bound = fEndTime;
489 if (!fTimeRangeFixed) {
490 fTime0 = fTime0Bound;
491 fTime1 = fTime1Bound;
492 }
493 fTime0 = Math.max(fTime0Bound, Math.min(fTime0, fTime1Bound));
494 fTime1 = Math.max(fTime0Bound, Math.min(fTime1, fTime1Bound));
495 if (fTime1 - fTime0 < fMinTimeInterval) {
496 fTime1 = Math.min(fTime1Bound, fTime0 + fMinTimeInterval);
497 }
498 }
499
500 /**
501 * @param traces
502 * @param start
503 * @param end
504 */
505 void updateInternalData(ITimeGraphEntry[] traces, long start, long end) {
506 ITimeGraphEntry[] realTraces = traces;
507
508 if (null == realTraces) {
509 realTraces = new ITimeGraphEntry[0];
510 }
511 if ((start == 0 && end == 0) || start < 0 || end < 0) {
512 // Start and end time are unspecified and need to be determined from
513 // individual processes
514 setTimeRange(realTraces);
515 } else {
516 fBeginTime = start;
517 fEndTime = end;
518 }
519
520 refreshAllData(realTraces);
521 }
522
523 /**
524 * @param traces
525 */
526 private void refreshAllData(ITimeGraphEntry[] traces) {
527 setTimeBounds();
528 if (fSelectionBegin < fBeginTime) {
529 fSelectionBegin = fBeginTime;
530 } else if (fSelectionBegin > fEndTime) {
531 fSelectionBegin = fEndTime;
532 }
533 if (fSelectionEnd < fBeginTime) {
534 fSelectionEnd = fBeginTime;
535 } else if (fSelectionEnd > fEndTime) {
536 fSelectionEnd = fEndTime;
537 }
538 fTimeGraphCtrl.refreshData(traces);
539 fTimeScaleCtrl.redraw();
540 adjustVerticalScrollBar();
541 }
542
543 /**
544 * Callback for when this view is focused
545 */
546 public void setFocus() {
547 if (null != fTimeGraphCtrl) {
548 fTimeGraphCtrl.setFocus();
549 }
550 }
551
552 /**
553 * Get the current focus status of this view.
554 *
555 * @return If the view is currently focused, or not
556 */
557 public boolean isInFocus() {
558 return fTimeGraphCtrl.isInFocus();
559 }
560
561 /**
562 * Get the view's current selection
563 *
564 * @return The entry that is selected
565 */
566 public ITimeGraphEntry getSelection() {
567 return fTimeGraphCtrl.getSelectedTrace();
568 }
569
570 /**
571 * Get the index of the current selection
572 *
573 * @return The index
574 */
575 public int getSelectionIndex() {
576 return fTimeGraphCtrl.getSelectedIndex();
577 }
578
579 @Override
580 public long getTime0() {
581 return fTime0;
582 }
583
584 @Override
585 public long getTime1() {
586 return fTime1;
587 }
588
589 @Override
590 public long getMinTimeInterval() {
591 return fMinTimeInterval;
592 }
593
594 @Override
595 public int getNameSpace() {
596 return fNameWidth;
597 }
598
599 @Override
600 public void setNameSpace(int width) {
601 fNameWidth = width;
602 int w = fTimeGraphCtrl.getClientArea().width;
603 if (fNameWidth > w - MIN_NAME_WIDTH) {
604 fNameWidth = w - MIN_NAME_WIDTH;
605 }
606 if (fNameWidth < MIN_NAME_WIDTH) {
607 fNameWidth = MIN_NAME_WIDTH;
608 }
609 fTimeGraphCtrl.adjustScrolls();
610 fTimeGraphCtrl.redraw();
611 fTimeScaleCtrl.redraw();
612 }
613
614 @Override
615 public int getTimeSpace() {
616 int w = fTimeGraphCtrl.getClientArea().width;
617 return w - fNameWidth;
618 }
619
620 @Override
621 public long getBeginTime() {
622 return fBeginTime;
623 }
624
625 @Override
626 public long getEndTime() {
627 return fEndTime;
628 }
629
630 @Override
631 public long getMaxTime() {
632 return fTime1Bound;
633 }
634
635 @Override
636 public long getMinTime() {
637 return fTime0Bound;
638 }
639
640 /**
641 * @since 2.1
642 */
643 @Override
644 public long getSelectionBegin() {
645 return fSelectionBegin;
646 }
647
648 /**
649 * @since 2.1
650 */
651 @Override
652 public long getSelectionEnd() {
653 return fSelectionEnd;
654 }
655
656 @Override
657 public void setStartFinishTimeNotify(long time0, long time1) {
658 setStartFinishTime(time0, time1);
659 notifyRangeListeners(fTime0, fTime1);
660 }
661
662 @Override
663 public void notifyStartFinishTime() {
664 notifyRangeListeners(fTime0, fTime1);
665 }
666
667 @Override
668 public void setStartFinishTime(long time0, long time1) {
669 fTime0 = time0;
670 if (fTime0 < fTime0Bound) {
671 fTime0 = fTime0Bound;
672 }
673 if (fTime0 > fTime1Bound) {
674 fTime0 = fTime1Bound;
675 }
676 fTime1 = time1;
677 if (fTime1 < fTime0Bound) {
678 fTime1 = fTime0Bound;
679 }
680 if (fTime1 > fTime1Bound) {
681 fTime1 = fTime1Bound;
682 }
683 if (fTime1 - fTime0 < fMinTimeInterval) {
684 fTime1 = Math.min(fTime1Bound, fTime0 + fMinTimeInterval);
685 }
686 fTimeRangeFixed = true;
687 fTimeGraphCtrl.adjustScrolls();
688 fTimeGraphCtrl.redraw();
689 fTimeScaleCtrl.redraw();
690 }
691
692 /**
693 * Set the time bounds to the provided values
694 *
695 * @param beginTime
696 * The start time of the window
697 * @param endTime
698 * The end time
699 */
700 public void setTimeBounds(long beginTime, long endTime) {
701 if (endTime >= beginTime) {
702 fBeginTime = beginTime;
703 fEndTime = endTime;
704 fTime0Bound = beginTime;
705 fTime1Bound = endTime;
706 } else {
707 fBeginTime = 0;
708 fEndTime = 0;
709 fTime0Bound = 0;
710 fTime1Bound = 0;
711 }
712 fTimeGraphCtrl.adjustScrolls();
713 }
714
715 @Override
716 public void resetStartFinishTime() {
717 setStartFinishTime(fTime0Bound, fTime1Bound);
718 fTimeRangeFixed = false;
719 }
720
721 @Override
722 public void setSelectedTimeNotify(long time, boolean ensureVisible) {
723 setSelectedTimeInt(time, ensureVisible, true);
724 }
725
726 @Override
727 public void setSelectedTime(long time, boolean ensureVisible) {
728 setSelectedTimeInt(time, ensureVisible, false);
729 }
730
731 /**
732 * @since 2.1
733 */
734 @Override
735 public void setSelectionRangeNotify(long beginTime, long endTime) {
736 boolean changed = (beginTime != fSelectionBegin || endTime != fSelectionEnd);
737 fSelectionBegin = Math.max(fTime0Bound, Math.min(fTime1Bound, beginTime));
738 fSelectionEnd = Math.max(fTime0Bound, Math.min(fTime1Bound, endTime));
739 fTimeGraphCtrl.redraw();
740 fTimeScaleCtrl.redraw();
741 if (changed) {
742 notifyTimeListeners(fSelectionBegin, fSelectionEnd);
743 }
744 }
745
746 /**
747 * @since 2.1
748 */
749 @Override
750 public void setSelectionRange(long beginTime, long endTime) {
751 fSelectionBegin = Math.max(fTime0Bound, Math.min(fTime1Bound, beginTime));
752 fSelectionEnd = Math.max(fTime0Bound, Math.min(fTime1Bound, endTime));
753 fTimeGraphCtrl.redraw();
754 fTimeScaleCtrl.redraw();
755 }
756
757 private void setSelectedTimeInt(long time, boolean ensureVisible, boolean doNotify) {
758 long time0 = fTime0;
759 long time1 = fTime1;
760 if (ensureVisible) {
761 long timeSpace = (fTime1 - fTime0) / RECENTERING_MARGIN_FACTOR;
762 long timeMid = (fTime1 - fTime0) / 2;
763 if (time < fTime0 + timeSpace) {
764 long dt = fTime0 - time + timeMid;
765 fTime0 -= dt;
766 fTime1 -= dt;
767 } else if (time > fTime1 - timeSpace) {
768 long dt = time - fTime1 + timeMid;
769 fTime0 += dt;
770 fTime1 += dt;
771 }
772 if (fTime0 < fTime0Bound) {
773 fTime1 = Math.min(fTime1Bound, fTime1 + (fTime0Bound - fTime0));
774 fTime0 = fTime0Bound;
775 } else if (fTime1 > fTime1Bound) {
776 fTime0 = Math.max(fTime0Bound, fTime0 - (fTime1 - fTime1Bound));
777 fTime1 = fTime1Bound;
778 }
779 }
780 if (fTime1 - fTime0 < fMinTimeInterval) {
781 fTime1 = Math.min(fTime1Bound, fTime0 + fMinTimeInterval);
782 }
783 fTimeGraphCtrl.adjustScrolls();
784 fTimeGraphCtrl.redraw();
785 fTimeScaleCtrl.redraw();
786
787 boolean notifySelectedTime = (time != fSelectionBegin || time != fSelectionEnd);
788 fSelectionBegin = time;
789 fSelectionEnd = time;
790
791 if (doNotify && ((time0 != fTime0) || (time1 != fTime1))) {
792 notifyRangeListeners(fTime0, fTime1);
793 }
794
795 if (doNotify && notifySelectedTime) {
796 notifyTimeListeners(fSelectionBegin, fSelectionEnd);
797 }
798 }
799
800 @Override
801 public void widgetDefaultSelected(SelectionEvent e) {
802 if (fSelectedEntry != getSelection()) {
803 fSelectedEntry = getSelection();
804 notifySelectionListeners(fSelectedEntry);
805 }
806 }
807
808 @Override
809 public void widgetSelected(SelectionEvent e) {
810 if (fSelectedEntry != getSelection()) {
811 fSelectedEntry = getSelection();
812 notifySelectionListeners(fSelectedEntry);
813 }
814 }
815
816 /**
817 * Callback for when the next event is selected
818 */
819 public void selectNextEvent() {
820 fTimeGraphCtrl.selectNextEvent();
821 adjustVerticalScrollBar();
822 }
823
824 /**
825 * Callback for when the previous event is selected
826 */
827 public void selectPrevEvent() {
828 fTimeGraphCtrl.selectPrevEvent();
829 adjustVerticalScrollBar();
830 }
831
832 /**
833 * Callback for when the next item is selected
834 */
835 public void selectNextItem() {
836 fTimeGraphCtrl.selectNextTrace();
837 adjustVerticalScrollBar();
838 }
839
840 /**
841 * Callback for when the previous item is selected
842 */
843 public void selectPrevItem() {
844 fTimeGraphCtrl.selectPrevTrace();
845 adjustVerticalScrollBar();
846 }
847
848 /**
849 * Callback for the show legend action
850 */
851 public void showLegend() {
852 if (fDataViewer == null || fDataViewer.isDisposed()) {
853 return;
854 }
855
856 TimeGraphLegend.open(fDataViewer.getShell(), fTimeGraphProvider);
857 }
858
859 /**
860 * Callback for the Zoom In action
861 */
862 public void zoomIn() {
863 fTimeGraphCtrl.zoomIn();
864 }
865
866 /**
867 * Callback for the Zoom Out action
868 */
869 public void zoomOut() {
870 fTimeGraphCtrl.zoomOut();
871 }
872
873 private String getPreferenceString(String string) {
874 return getViewTypeStr() + "." + string; //$NON-NLS-1$
875 }
876
877 /**
878 * Add a selection listener
879 *
880 * @param listener
881 * The listener to add
882 */
883 public void addSelectionListener(ITimeGraphSelectionListener listener) {
884 fSelectionListeners.add(listener);
885 }
886
887 /**
888 * Remove a selection listener
889 *
890 * @param listener
891 * The listener to remove
892 */
893 public void removeSelectionListener(ITimeGraphSelectionListener listener) {
894 fSelectionListeners.remove(listener);
895 }
896
897 private void notifySelectionListeners(ITimeGraphEntry selection) {
898 TimeGraphSelectionEvent event = new TimeGraphSelectionEvent(this, selection);
899
900 for (ITimeGraphSelectionListener listener : fSelectionListeners) {
901 listener.selectionChanged(event);
902 }
903 }
904
905 /**
906 * Add a time listener
907 *
908 * @param listener
909 * The listener to add
910 */
911 public void addTimeListener(ITimeGraphTimeListener listener) {
912 fTimeListeners.add(listener);
913 }
914
915 /**
916 * Remove a time listener
917 *
918 * @param listener
919 * The listener to remove
920 */
921 public void removeTimeListener(ITimeGraphTimeListener listener) {
922 fTimeListeners.remove(listener);
923 }
924
925 private void notifyTimeListeners(long startTime, long endTime) {
926 TimeGraphTimeEvent event = new TimeGraphTimeEvent(this, startTime, endTime);
927
928 for (ITimeGraphTimeListener listener : fTimeListeners) {
929 listener.timeSelected(event);
930 }
931 }
932
933 /**
934 * Add a range listener
935 *
936 * @param listener
937 * The listener to add
938 */
939 public void addRangeListener(ITimeGraphRangeListener listener) {
940 fRangeListeners.add(listener);
941 }
942
943 /**
944 * Remove a range listener
945 *
946 * @param listener
947 * The listener to remove
948 */
949 public void removeRangeListener(ITimeGraphRangeListener listener) {
950 fRangeListeners.remove(listener);
951 }
952
953 private void notifyRangeListeners(long startTime, long endTime) {
954 // Check if the time has actually changed from last notification
955 if (startTime != fTime0ExtSynch || endTime != fTime1ExtSynch) {
956 // Notify Time Scale Selection Listeners
957 TimeGraphRangeUpdateEvent event = new TimeGraphRangeUpdateEvent(this, startTime, endTime);
958
959 for (ITimeGraphRangeListener listener : fRangeListeners) {
960 listener.timeRangeUpdated(event);
961 }
962
963 // update external synch timers
964 updateExtSynchTimers();
965 }
966 }
967
968 /**
969 * Callback to set a selected event in the view
970 *
971 * @param event
972 * The event that was selected
973 * @param source
974 * The source of this selection event
975 */
976 public void setSelectedEvent(ITimeEvent event, Object source) {
977 if (event == null || source == this) {
978 return;
979 }
980 fSelectedEntry = event.getEntry();
981 fTimeGraphCtrl.selectItem(fSelectedEntry, false);
982
983 setSelectedTimeInt(event.getTime(), true, true);
984 adjustVerticalScrollBar();
985 }
986
987 /**
988 * Set the seeked time of a trace
989 *
990 * @param trace
991 * The trace that was seeked
992 * @param time
993 * The target time
994 * @param source
995 * The source of this seek event
996 */
997 public void setSelectedTraceTime(ITimeGraphEntry trace, long time, Object source) {
998 if (trace == null || source == this) {
999 return;
1000 }
1001 fSelectedEntry = trace;
1002 fTimeGraphCtrl.selectItem(trace, false);
1003
1004 setSelectedTimeInt(time, true, true);
1005 }
1006
1007 /**
1008 * Callback for a trace selection
1009 *
1010 * @param trace
1011 * The trace that was selected
1012 */
1013 public void setSelection(ITimeGraphEntry trace) {
1014 fSelectedEntry = trace;
1015 fTimeGraphCtrl.selectItem(trace, false);
1016 adjustVerticalScrollBar();
1017 }
1018
1019 /**
1020 * Callback for a time window selection
1021 *
1022 * @param time0
1023 * Start time of the range
1024 * @param time1
1025 * End time of the range
1026 * @param source
1027 * Source of the event
1028 */
1029 public void setSelectVisTimeWindow(long time0, long time1, Object source) {
1030 if (source == this) {
1031 return;
1032 }
1033
1034 setStartFinishTime(time0, time1);
1035
1036 // update notification time values since we are now in synch with the
1037 // external application
1038 updateExtSynchTimers();
1039 }
1040
1041 /**
1042 * update the cache timers used to identify the need to send a time window
1043 * update to external registered listeners
1044 */
1045 private void updateExtSynchTimers() {
1046 // last time notification cache
1047 fTime0ExtSynch = fTime0;
1048 fTime1ExtSynch = fTime1;
1049 }
1050
1051 /**
1052 * @since 2.0
1053 */
1054 @Override
1055 public TimeFormat getTimeFormat() {
1056 return fTimeFormat;
1057 }
1058
1059 /**
1060 * @param tf
1061 * the {@link TimeFormat} used to display timestamps
1062 * @since 2.0
1063 */
1064 public void setTimeFormat(TimeFormat tf) {
1065 this.fTimeFormat = tf;
1066 if (tf == TimeFormat.CYCLES) {
1067 fTimeDataProvider = new TimeDataProviderCyclesConverter(this, fClockFrequency);
1068 } else {
1069 fTimeDataProvider = this;
1070 }
1071 fTimeScaleCtrl.setTimeProvider(fTimeDataProvider);
1072 if (fToolTipHandler != null) {
1073 fToolTipHandler.setTimeProvider(fTimeDataProvider);
1074 }
1075 }
1076
1077 /**
1078 * Sets the clock frequency. Used when the time format is set to CYCLES.
1079 *
1080 * @param clockFrequency
1081 * the clock frequency in Hz
1082 * @since 3.2
1083 */
1084 public void setClockFrequency(long clockFrequency) {
1085 fClockFrequency = clockFrequency;
1086 if (fTimeFormat == TimeFormat.CYCLES) {
1087 fTimeDataProvider = new TimeDataProviderCyclesConverter(this, fClockFrequency);
1088 fTimeScaleCtrl.setTimeProvider(fTimeDataProvider);
1089 if (fToolTipHandler != null) {
1090 fToolTipHandler.setTimeProvider(fTimeDataProvider);
1091 }
1092 }
1093 }
1094
1095 /**
1096 * Retrieve the border width
1097 *
1098 * @return The width
1099 */
1100 public int getBorderWidth() {
1101 return fBorderWidth;
1102 }
1103
1104 /**
1105 * Set the border width
1106 *
1107 * @param borderWidth
1108 * The width
1109 */
1110 public void setBorderWidth(int borderWidth) {
1111 if (borderWidth > -1) {
1112 this.fBorderWidth = borderWidth;
1113 GridLayout gl = (GridLayout) fDataViewer.getLayout();
1114 gl.marginHeight = borderWidth;
1115 }
1116 }
1117
1118 /**
1119 * Retrieve the height of the header
1120 *
1121 * @return The height
1122 */
1123 public int getHeaderHeight() {
1124 return fTimeScaleHeight;
1125 }
1126
1127 /**
1128 * Set the height of the header
1129 *
1130 * @param headerHeight
1131 * The height to set
1132 */
1133 public void setHeaderHeight(int headerHeight) {
1134 if (headerHeight > -1) {
1135 this.fTimeScaleHeight = headerHeight;
1136 fTimeScaleCtrl.setHeight(headerHeight);
1137 }
1138 }
1139
1140 /**
1141 * Retrieve the height of an item row
1142 *
1143 * @return The height
1144 */
1145 public int getItemHeight() {
1146 if (fTimeGraphCtrl != null) {
1147 return fTimeGraphCtrl.getItemHeight();
1148 }
1149 return 0;
1150 }
1151
1152 /**
1153 * Set the height of an item row
1154 *
1155 * @param rowHeight
1156 * The height to set
1157 */
1158 public void setItemHeight(int rowHeight) {
1159 if (fTimeGraphCtrl != null) {
1160 fTimeGraphCtrl.setItemHeight(rowHeight);
1161 }
1162 }
1163
1164 /**
1165 * Set the minimum item width
1166 *
1167 * @param width
1168 * The min width
1169 */
1170 public void setMinimumItemWidth(int width) {
1171 if (fTimeGraphCtrl != null) {
1172 fTimeGraphCtrl.setMinimumItemWidth(width);
1173 }
1174 }
1175
1176 /**
1177 * Set the width for the name column
1178 *
1179 * @param width
1180 * The width
1181 */
1182 public void setNameWidthPref(int width) {
1183 fNameWidthPref = width;
1184 if (width == 0) {
1185 fMinNameWidth = 0;
1186 fNameWidth = 0;
1187 }
1188 }
1189
1190 /**
1191 * Retrieve the configure width for the name column
1192 *
1193 * @param width
1194 * Unused?
1195 * @return The width
1196 */
1197 public int getNameWidthPref(int width) {
1198 return fNameWidthPref;
1199 }
1200
1201 /**
1202 * Returns the primary control associated with this viewer.
1203 *
1204 * @return the SWT control which displays this viewer's content
1205 */
1206 public Control getControl() {
1207 return fDataViewer;
1208 }
1209
1210 /**
1211 * Returns the time graph control associated with this viewer.
1212 *
1213 * @return the time graph control
1214 * @since 2.0
1215 */
1216 public TimeGraphControl getTimeGraphControl() {
1217 return fTimeGraphCtrl;
1218 }
1219
1220 /**
1221 * Returns the time graph scale associated with this viewer.
1222 *
1223 * @return the time graph scale
1224 * @since 2.0
1225 */
1226 public TimeGraphScale getTimeGraphScale() {
1227 return fTimeScaleCtrl;
1228 }
1229
1230 /**
1231 * Return the x coordinate corresponding to a time
1232 *
1233 * @param time
1234 * the time
1235 * @return the x coordinate corresponding to the time
1236 *
1237 * @since 2.0
1238 */
1239 public int getXForTime(long time) {
1240 return fTimeGraphCtrl.getXForTime(time);
1241 }
1242
1243 /**
1244 * Return the time corresponding to an x coordinate
1245 *
1246 * @param x
1247 * the x coordinate
1248 * @return the time corresponding to the x coordinate
1249 *
1250 * @since 2.0
1251 */
1252 public long getTimeAtX(int x) {
1253 return fTimeGraphCtrl.getTimeAtX(x);
1254 }
1255
1256 /**
1257 * Get the selection provider
1258 *
1259 * @return the selection provider
1260 */
1261 public ISelectionProvider getSelectionProvider() {
1262 return fTimeGraphCtrl;
1263 }
1264
1265 /**
1266 * Wait for the cursor
1267 *
1268 * @param waitInd
1269 * Wait indefinitely?
1270 */
1271 public void waitCursor(boolean waitInd) {
1272 fTimeGraphCtrl.waitCursor(waitInd);
1273 }
1274
1275 /**
1276 * Get the horizontal scroll bar object
1277 *
1278 * @return The scroll bar
1279 */
1280 public ScrollBar getHorizontalBar() {
1281 return fTimeGraphCtrl.getHorizontalBar();
1282 }
1283
1284 /**
1285 * Get the vertical scroll bar object
1286 *
1287 * @return The scroll bar
1288 */
1289 public Slider getVerticalBar() {
1290 return fVerticalScrollBar;
1291 }
1292
1293 /**
1294 * Set the given index as the top one
1295 *
1296 * @param index
1297 * The index that will go to the top
1298 */
1299 public void setTopIndex(int index) {
1300 fTimeGraphCtrl.setTopIndex(index);
1301 adjustVerticalScrollBar();
1302 }
1303
1304 /**
1305 * Retrieve the current top index
1306 *
1307 * @return The top index
1308 */
1309 public int getTopIndex() {
1310 return fTimeGraphCtrl.getTopIndex();
1311 }
1312
1313 /**
1314 * Sets the auto-expand level to be used when the input of the viewer is set
1315 * using {@link #setInput(Object)}. The value 0 means that there is no
1316 * auto-expand; 1 means that top-level elements are expanded, but not their
1317 * children; 2 means that top-level elements are expanded, and their
1318 * children, but not grand-children; and so on.
1319 * <p>
1320 * The value {@link #ALL_LEVELS} means that all subtrees should be expanded.
1321 * </p>
1322 * @param level
1323 * non-negative level, or <code>ALL_LEVELS</code> to expand all
1324 * levels of the tree
1325 * @since 3.1
1326 */
1327 public void setAutoExpandLevel(int level) {
1328 fTimeGraphCtrl.setAutoExpandLevel(level);
1329 }
1330
1331 /**
1332 * Returns the auto-expand level.
1333 *
1334 * @return non-negative level, or <code>ALL_LEVELS</code> if all levels of
1335 * the tree are expanded automatically
1336 * @see #setAutoExpandLevel
1337 * @since 3.1
1338 */
1339 public int getAutoExpandLevel() {
1340 return fTimeGraphCtrl.getAutoExpandLevel();
1341 }
1342
1343 /**
1344 * Set the expanded state of an entry
1345 *
1346 * @param entry
1347 * The entry to expand/collapse
1348 * @param expanded
1349 * True for expanded, false for collapsed
1350 */
1351 public void setExpandedState(ITimeGraphEntry entry, boolean expanded) {
1352 fTimeGraphCtrl.setExpandedState(entry, expanded);
1353 adjustVerticalScrollBar();
1354 }
1355
1356 /**
1357 * Collapses all nodes of the viewer's tree, starting with the root.
1358 *
1359 * @since 2.0
1360 */
1361 public void collapseAll() {
1362 fTimeGraphCtrl.collapseAll();
1363 adjustVerticalScrollBar();
1364 }
1365
1366 /**
1367 * Expands all nodes of the viewer's tree, starting with the root.
1368 *
1369 * @since 2.0
1370 */
1371 public void expandAll() {
1372 fTimeGraphCtrl.expandAll();
1373 adjustVerticalScrollBar();
1374 }
1375
1376 /**
1377 * Get the number of sub-elements when expanded
1378 *
1379 * @return The element count
1380 */
1381 public int getExpandedElementCount() {
1382 return fTimeGraphCtrl.getExpandedElementCount();
1383 }
1384
1385 /**
1386 * Get the sub-elements
1387 *
1388 * @return The array of entries that are below this one
1389 */
1390 public ITimeGraphEntry[] getExpandedElements() {
1391 return fTimeGraphCtrl.getExpandedElements();
1392 }
1393
1394 /**
1395 * Add a tree listener
1396 *
1397 * @param listener
1398 * The listener to add
1399 */
1400 public void addTreeListener(ITimeGraphTreeListener listener) {
1401 fTimeGraphCtrl.addTreeListener(listener);
1402 }
1403
1404 /**
1405 * Remove a tree listener
1406 *
1407 * @param listener
1408 * The listener to remove
1409 */
1410 public void removeTreeListener(ITimeGraphTreeListener listener) {
1411 fTimeGraphCtrl.removeTreeListener(listener);
1412 }
1413
1414 /**
1415 * Get the reset scale action.
1416 *
1417 * @return The Action object
1418 */
1419 public Action getResetScaleAction() {
1420 if (fResetScaleAction == null) {
1421 // resetScale
1422 fResetScaleAction = new Action() {
1423 @Override
1424 public void run() {
1425 resetStartFinishTime();
1426 notifyStartFinishTime();
1427 }
1428 };
1429 fResetScaleAction.setText(Messages.TmfTimeGraphViewer_ResetScaleActionNameText);
1430 fResetScaleAction.setToolTipText(Messages.TmfTimeGraphViewer_ResetScaleActionToolTipText);
1431 fResetScaleAction.setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_HOME_MENU));
1432 }
1433 return fResetScaleAction;
1434 }
1435
1436 /**
1437 * Get the show legend action.
1438 *
1439 * @return The Action object
1440 */
1441 public Action getShowLegendAction() {
1442 if (fShowLegendAction == null) {
1443 // showLegend
1444 fShowLegendAction = new Action() {
1445 @Override
1446 public void run() {
1447 showLegend();
1448 }
1449 };
1450 fShowLegendAction.setText(Messages.TmfTimeGraphViewer_LegendActionNameText);
1451 fShowLegendAction.setToolTipText(Messages.TmfTimeGraphViewer_LegendActionToolTipText);
1452 fShowLegendAction.setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_SHOW_LEGEND));
1453 }
1454
1455 return fShowLegendAction;
1456 }
1457
1458 /**
1459 * Get the the next event action.
1460 *
1461 * @return The action object
1462 */
1463 public Action getNextEventAction() {
1464 if (fNextEventAction == null) {
1465 fNextEventAction = new Action() {
1466 @Override
1467 public void run() {
1468 selectNextEvent();
1469 }
1470 };
1471
1472 fNextEventAction.setText(Messages.TmfTimeGraphViewer_NextEventActionNameText);
1473 fNextEventAction.setToolTipText(Messages.TmfTimeGraphViewer_NextEventActionToolTipText);
1474 fNextEventAction.setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_NEXT_EVENT));
1475 }
1476
1477 return fNextEventAction;
1478 }
1479
1480 /**
1481 * Get the previous event action.
1482 *
1483 * @return The Action object
1484 */
1485 public Action getPreviousEventAction() {
1486 if (fPrevEventAction == null) {
1487 fPrevEventAction = new Action() {
1488 @Override
1489 public void run() {
1490 selectPrevEvent();
1491 }
1492 };
1493
1494 fPrevEventAction.setText(Messages.TmfTimeGraphViewer_PreviousEventActionNameText);
1495 fPrevEventAction.setToolTipText(Messages.TmfTimeGraphViewer_PreviousEventActionToolTipText);
1496 fPrevEventAction.setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_PREV_EVENT));
1497 }
1498
1499 return fPrevEventAction;
1500 }
1501
1502 /**
1503 * Get the next item action.
1504 *
1505 * @return The Action object
1506 */
1507 public Action getNextItemAction() {
1508 if (fNextItemAction == null) {
1509
1510 fNextItemAction = new Action() {
1511 @Override
1512 public void run() {
1513 selectNextItem();
1514 }
1515 };
1516 fNextItemAction.setText(Messages.TmfTimeGraphViewer_NextItemActionNameText);
1517 fNextItemAction.setToolTipText(Messages.TmfTimeGraphViewer_NextItemActionToolTipText);
1518 fNextItemAction.setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_NEXT_ITEM));
1519 }
1520 return fNextItemAction;
1521 }
1522
1523 /**
1524 * Get the previous item action.
1525 *
1526 * @return The Action object
1527 */
1528 public Action getPreviousItemAction() {
1529 if (fPreviousItemAction == null) {
1530
1531 fPreviousItemAction = new Action() {
1532 @Override
1533 public void run() {
1534 selectPrevItem();
1535 }
1536 };
1537 fPreviousItemAction.setText(Messages.TmfTimeGraphViewer_PreviousItemActionNameText);
1538 fPreviousItemAction.setToolTipText(Messages.TmfTimeGraphViewer_PreviousItemActionToolTipText);
1539 fPreviousItemAction.setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_PREV_ITEM));
1540 }
1541 return fPreviousItemAction;
1542 }
1543
1544 /**
1545 * Get the zoom in action
1546 *
1547 * @return The Action object
1548 */
1549 public Action getZoomInAction() {
1550 if (fZoomInAction == null) {
1551 fZoomInAction = new Action() {
1552 @Override
1553 public void run() {
1554 zoomIn();
1555 }
1556 };
1557 fZoomInAction.setText(Messages.TmfTimeGraphViewer_ZoomInActionNameText);
1558 fZoomInAction.setToolTipText(Messages.TmfTimeGraphViewer_ZoomInActionToolTipText);
1559 fZoomInAction.setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_ZOOM_IN_MENU));
1560 }
1561 return fZoomInAction;
1562 }
1563
1564 /**
1565 * Get the zoom out action
1566 *
1567 * @return The Action object
1568 */
1569 public Action getZoomOutAction() {
1570 if (fZoomOutAction == null) {
1571 fZoomOutAction = new Action() {
1572 @Override
1573 public void run() {
1574 zoomOut();
1575 }
1576 };
1577 fZoomOutAction.setText(Messages.TmfTimeGraphViewer_ZoomOutActionNameText);
1578 fZoomOutAction.setToolTipText(Messages.TmfTimeGraphViewer_ZoomOutActionToolTipText);
1579 fZoomOutAction.setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_ZOOM_OUT_MENU));
1580 }
1581 return fZoomOutAction;
1582 }
1583
1584 /**
1585 * Get the hide arrows action
1586 *
1587 * @param dialogSettings
1588 * The dialog settings section where the state should be stored,
1589 * or null
1590 *
1591 * @return The Action object
1592 *
1593 * @since 2.1
1594 */
1595 public Action getHideArrowsAction(final IDialogSettings dialogSettings) {
1596 if (fHideArrowsAction == null) {
1597 fHideArrowsAction = new Action(Messages.TmfTimeGraphViewer_HideArrowsActionNameText, IAction.AS_CHECK_BOX) {
1598 @Override
1599 public void run() {
1600 boolean hideArrows = fHideArrowsAction.isChecked();
1601 fTimeGraphCtrl.hideArrows(hideArrows);
1602 refresh();
1603 if (dialogSettings != null) {
1604 dialogSettings.put(HIDE_ARROWS_KEY, hideArrows);
1605 }
1606 if (fFollowArrowFwdAction != null) {
1607 fFollowArrowFwdAction.setEnabled(!hideArrows);
1608 }
1609 if (fFollowArrowBwdAction != null) {
1610 fFollowArrowBwdAction.setEnabled(!hideArrows);
1611 }
1612 }
1613 };
1614 fHideArrowsAction.setToolTipText(Messages.TmfTimeGraphViewer_HideArrowsActionToolTipText);
1615 fHideArrowsAction.setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_HIDE_ARROWS));
1616 if (dialogSettings != null) {
1617 boolean hideArrows = dialogSettings.getBoolean(HIDE_ARROWS_KEY);
1618 fTimeGraphCtrl.hideArrows(hideArrows);
1619 fHideArrowsAction.setChecked(hideArrows);
1620 if (fFollowArrowFwdAction != null) {
1621 fFollowArrowFwdAction.setEnabled(!hideArrows);
1622 }
1623 if (fFollowArrowBwdAction != null) {
1624 fFollowArrowBwdAction.setEnabled(!hideArrows);
1625 }
1626 }
1627 }
1628 return fHideArrowsAction;
1629 }
1630
1631 /**
1632 * Get the follow arrow forward action.
1633 *
1634 * @return The Action object
1635 *
1636 * @since 2.1
1637 */
1638 public Action getFollowArrowFwdAction() {
1639 if (fFollowArrowFwdAction == null) {
1640 fFollowArrowFwdAction = new Action() {
1641 @Override
1642 public void run() {
1643 fTimeGraphCtrl.followArrowFwd();
1644 adjustVerticalScrollBar();
1645 }
1646 };
1647 fFollowArrowFwdAction.setText(Messages.TmfTimeGraphViewer_FollowArrowForwardActionNameText);
1648 fFollowArrowFwdAction.setToolTipText(Messages.TmfTimeGraphViewer_FollowArrowForwardActionToolTipText);
1649 fFollowArrowFwdAction.setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_FOLLOW_ARROW_FORWARD));
1650 if (fHideArrowsAction != null) {
1651 fFollowArrowFwdAction.setEnabled(!fHideArrowsAction.isChecked());
1652 }
1653 }
1654 return fFollowArrowFwdAction;
1655 }
1656
1657 /**
1658 * Get the follow arrow backward action.
1659 *
1660 * @return The Action object
1661 *
1662 * @since 2.1
1663 */
1664 public Action getFollowArrowBwdAction() {
1665 if (fFollowArrowBwdAction == null) {
1666 fFollowArrowBwdAction = new Action() {
1667 @Override
1668 public void run() {
1669 fTimeGraphCtrl.followArrowBwd();
1670 adjustVerticalScrollBar();
1671 }
1672 };
1673 fFollowArrowBwdAction.setText(Messages.TmfTimeGraphViewer_FollowArrowBackwardActionNameText);
1674 fFollowArrowBwdAction.setToolTipText(Messages.TmfTimeGraphViewer_FollowArrowBackwardActionToolTipText);
1675 fFollowArrowBwdAction.setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_FOLLOW_ARROW_BACKWARD));
1676 if (fHideArrowsAction != null) {
1677 fFollowArrowBwdAction.setEnabled(!fHideArrowsAction.isChecked());
1678 }
1679 }
1680 return fFollowArrowBwdAction;
1681 }
1682
1683 private void adjustVerticalScrollBar() {
1684 int topIndex = fTimeGraphCtrl.getTopIndex();
1685 int countPerPage = fTimeGraphCtrl.countPerPage();
1686 int expandedElementCount = fTimeGraphCtrl.getExpandedElementCount();
1687 if (topIndex + countPerPage > expandedElementCount) {
1688 fTimeGraphCtrl.setTopIndex(Math.max(0, expandedElementCount - countPerPage));
1689 }
1690
1691 int selection = fTimeGraphCtrl.getTopIndex();
1692 int min = 0;
1693 int max = Math.max(1, expandedElementCount - 1);
1694 int thumb = Math.min(max, Math.max(1, countPerPage - 1));
1695 int increment = 1;
1696 int pageIncrement = Math.max(1, countPerPage);
1697 fVerticalScrollBar.setValues(selection, min, max, thumb, increment, pageIncrement);
1698 }
1699
1700 /**
1701 * @param listener
1702 * a {@link MenuDetectListener}
1703 * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TimeGraphControl#addTimeGraphEntryMenuListener(org.eclipse.swt.events.MenuDetectListener)
1704 * @since 1.2
1705 */
1706 public void addTimeGraphEntryMenuListener(MenuDetectListener listener) {
1707 fTimeGraphCtrl.addTimeGraphEntryMenuListener(listener);
1708 }
1709
1710 /**
1711 * @param listener
1712 * a {@link MenuDetectListener}
1713 * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TimeGraphControl#removeTimeGraphEntryMenuListener(org.eclipse.swt.events.MenuDetectListener)
1714 * @since 1.2
1715 */
1716 public void removeTimeGraphEntryMenuListener(MenuDetectListener listener) {
1717 fTimeGraphCtrl.removeTimeGraphEntryMenuListener(listener);
1718 }
1719
1720 /**
1721 * @param listener
1722 * a {@link MenuDetectListener}
1723 * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TimeGraphControl#addTimeEventMenuListener(org.eclipse.swt.events.MenuDetectListener)
1724 * @since 1.2
1725 */
1726 public void addTimeEventMenuListener(MenuDetectListener listener) {
1727 fTimeGraphCtrl.addTimeEventMenuListener(listener);
1728 }
1729
1730 /**
1731 * @param listener
1732 * a {@link MenuDetectListener}
1733 * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TimeGraphControl#removeTimeEventMenuListener(org.eclipse.swt.events.MenuDetectListener)
1734 * @since 1.2
1735 */
1736 public void removeTimeEventMenuListener(MenuDetectListener listener) {
1737 fTimeGraphCtrl.removeTimeEventMenuListener(listener);
1738 }
1739
1740 /**
1741 * @param filter
1742 * The filter object to be attached to the view
1743 * @since 2.0
1744 */
1745 public void addFilter(ViewerFilter filter) {
1746 fTimeGraphCtrl.addFilter(filter);
1747 refresh();
1748 }
1749
1750 /**
1751 * @param filter
1752 * The filter object to be attached to the view
1753 * @since 2.0
1754 */
1755 public void removeFilter(ViewerFilter filter) {
1756 fTimeGraphCtrl.removeFilter(filter);
1757 refresh();
1758 }
1759
1760 }
This page took 0.06974 seconds and 5 git commands to generate.