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
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 *****************************************************************************/
17 package org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
;
19 import java
.util
.ArrayList
;
20 import java
.util
.List
;
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
.ISelectionProvider
;
26 import org
.eclipse
.jface
.viewers
.ViewerFilter
;
27 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.Activator
;
28 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.ITmfImageConstants
;
29 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.Messages
;
30 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.dialogs
.TimeGraphLegend
;
31 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.model
.ILinkEvent
;
32 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.model
.ITimeEvent
;
33 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.model
.ITimeGraphEntry
;
34 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.widgets
.ITimeDataProvider
;
35 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.widgets
.TimeGraphColorScheme
;
36 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.widgets
.TimeGraphControl
;
37 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.widgets
.TimeGraphScale
;
38 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.widgets
.TimeGraphTooltipHandler
;
39 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.widgets
.Utils
;
40 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.widgets
.Utils
.TimeFormat
;
41 import org
.eclipse
.swt
.SWT
;
42 import org
.eclipse
.swt
.events
.ControlAdapter
;
43 import org
.eclipse
.swt
.events
.ControlEvent
;
44 import org
.eclipse
.swt
.events
.KeyAdapter
;
45 import org
.eclipse
.swt
.events
.KeyEvent
;
46 import org
.eclipse
.swt
.events
.MenuDetectListener
;
47 import org
.eclipse
.swt
.events
.MouseEvent
;
48 import org
.eclipse
.swt
.events
.MouseWheelListener
;
49 import org
.eclipse
.swt
.events
.SelectionAdapter
;
50 import org
.eclipse
.swt
.events
.SelectionEvent
;
51 import org
.eclipse
.swt
.events
.SelectionListener
;
52 import org
.eclipse
.swt
.graphics
.Rectangle
;
53 import org
.eclipse
.swt
.layout
.FillLayout
;
54 import org
.eclipse
.swt
.layout
.GridData
;
55 import org
.eclipse
.swt
.layout
.GridLayout
;
56 import org
.eclipse
.swt
.widgets
.Composite
;
57 import org
.eclipse
.swt
.widgets
.Control
;
58 import org
.eclipse
.swt
.widgets
.ScrollBar
;
59 import org
.eclipse
.swt
.widgets
.Slider
;
62 * Generic time graph viewer implementation
65 * @author Patrick Tasse, and others
67 public class TimeGraphViewer
implements ITimeDataProvider
, SelectionListener
{
69 private static final int DEFAULT_NAME_WIDTH
= 200;
70 private static final int MIN_NAME_WIDTH
= 6;
71 private static final int MAX_NAME_WIDTH
= 1000;
72 private static final int DEFAULT_HEIGHT
= 22;
73 private static final long RECENTERING_MARGIN_FACTOR
= 50;
74 private static final String HIDE_ARROWS_KEY
= "hide.arrows"; //$NON-NLS-1$
76 private long fMinTimeInterval
;
77 private ITimeGraphEntry fSelectedEntry
;
78 private long fBeginTime
;
79 private long fEndTime
;
82 private long fSelectionBegin
= 0;
83 private long fSelectionEnd
= 0;
84 private long fTime0Bound
;
85 private long fTime1Bound
;
86 private long fTime0ExtSynch
= 0;
87 private long fTime1ExtSynch
= 0;
88 private boolean fTimeRangeFixed
;
89 private int fNameWidthPref
= DEFAULT_NAME_WIDTH
;
90 private int fMinNameWidth
= MIN_NAME_WIDTH
;
91 private int fNameWidth
;
92 private Composite fDataViewer
;
94 private TimeGraphControl fTimeGraphCtrl
;
95 private TimeGraphScale fTimeScaleCtrl
;
96 private Slider fVerticalScrollBar
;
97 private TimeGraphColorScheme fColorScheme
;
98 private Object fInputElement
;
99 private ITimeGraphContentProvider fTimeGraphContentProvider
;
100 private ITimeGraphPresentationProvider fTimeGraphProvider
;
102 private List
<ITimeGraphSelectionListener
> fSelectionListeners
= new ArrayList
<>();
103 private List
<ITimeGraphTimeListener
> fTimeListeners
= new ArrayList
<>();
104 private List
<ITimeGraphRangeListener
> fRangeListeners
= new ArrayList
<>();
106 // Time format, using Epoch reference, Relative time format(default) or
108 private TimeFormat fTimeFormat
= TimeFormat
.RELATIVE
;
109 private int fBorderWidth
= 0;
110 private int fTimeScaleHeight
= DEFAULT_HEIGHT
;
112 private Action fResetScaleAction
;
113 private Action fShowLegendAction
;
114 private Action fNextEventAction
;
115 private Action fPrevEventAction
;
116 private Action fNextItemAction
;
117 private Action fPreviousItemAction
;
118 private Action fZoomInAction
;
119 private Action fZoomOutAction
;
120 private Action fHideArrowsAction
;
121 private Action fFollowArrowFwdAction
;
122 private Action fFollowArrowBwdAction
;
125 * Standard constructor.
127 * The default timegraph content provider accepts an ITimeGraphEntry[] as input element.
130 * The parent UI composite object
134 public TimeGraphViewer(Composite parent
, int style
) {
135 createDataViewer(parent
, style
);
136 fTimeGraphContentProvider
= new ITimeGraphContentProvider() {
138 public ITimeGraphEntry
[] getElements(Object inputElement
) {
139 if (inputElement
instanceof ITimeGraphEntry
[]) {
140 return (ITimeGraphEntry
[]) inputElement
;
142 return new ITimeGraphEntry
[0];
148 * Sets the timegraph content provider used by this timegraph viewer.
150 * @param timeGraphContentProvider
151 * the timegraph content provider
155 public void setTimeGraphContentProvider(ITimeGraphContentProvider timeGraphContentProvider
) {
156 fTimeGraphContentProvider
= timeGraphContentProvider
;
160 * Gets the timegraph content provider used by this timegraph viewer.
162 * @return the timegraph content provider
166 public ITimeGraphContentProvider
getTimeGraphContentProvider() {
167 return fTimeGraphContentProvider
;
171 * Sets the timegraph presentation provider used by this timegraph viewer.
173 * @param timeGraphProvider
174 * the timegraph provider
176 public void setTimeGraphProvider(ITimeGraphPresentationProvider timeGraphProvider
) {
177 fTimeGraphProvider
= timeGraphProvider
;
178 fTimeGraphCtrl
.setTimeGraphProvider(timeGraphProvider
);
179 TimeGraphTooltipHandler toolTipHandler
= new TimeGraphTooltipHandler(fTimeGraphProvider
, this);
180 toolTipHandler
.activateHoverHelp(fTimeGraphCtrl
);
184 * Sets or clears the input for this time graph viewer.
186 * @param inputElement
187 * The input of this time graph viewer, or <code>null</code> if
192 public void setInput(Object inputElement
) {
193 fInputElement
= inputElement
;
194 ITimeGraphEntry
[] input
= fTimeGraphContentProvider
.getElements(inputElement
);
196 if (fTimeGraphCtrl
!= null) {
198 fVerticalScrollBar
.setEnabled(true);
202 fSelectedEntry
= null;
203 refreshAllData(input
);
208 * Gets the input for this time graph viewer.
210 * @return The input of this time graph viewer, or <code>null</code> if none
214 public Object
getInput() {
215 return fInputElement
;
219 * Sets (or clears if null) the list of links to display on this combo
222 * the links to display in this time graph combo
225 public void setLinks(List
<ILinkEvent
> links
) {
226 if (fTimeGraphCtrl
!= null) {
227 fTimeGraphCtrl
.refreshArrows(links
);
234 public void refresh() {
235 ITimeGraphEntry
[] input
= fTimeGraphContentProvider
.getElements(fInputElement
);
237 fVerticalScrollBar
.setEnabled(true);
238 refreshAllData(input
);
242 * Callback for when the control is moved
247 public void controlMoved(ControlEvent e
) {
251 * Callback for when the control is resized
256 public void controlResized(ControlEvent e
) {
261 * Handler for when the model is updated. Called from the display order in
265 * The traces in the model
270 * @param updateTimeBounds
271 * Should we updated the time bounds too
273 public void modelUpdate(ITimeGraphEntry
[] traces
, long start
,
274 long end
, boolean updateTimeBounds
) {
275 if (null != fTimeGraphCtrl
) {
276 updateInternalData(traces
, start
, end
);
277 if (updateTimeBounds
) {
278 fTimeRangeFixed
= true;
279 // set window to match limits
280 setStartFinishTime(fTime0Bound
, fTime1Bound
);
282 fTimeGraphCtrl
.redraw();
283 fTimeScaleCtrl
.redraw();
289 * @return The string representing the view type
291 protected String
getViewTypeStr() {
292 return "viewoption.threads"; //$NON-NLS-1$
295 int getMarginWidth() {
299 int getMarginHeight() {
304 fMinTimeInterval
= 1;
305 fSelectionBegin
= -1;
307 fNameWidth
= Utils
.loadIntOption(getPreferenceString("namewidth"), //$NON-NLS-1$
308 fNameWidthPref
, fMinNameWidth
, MAX_NAME_WIDTH
);
312 Utils
.saveIntOption(getPreferenceString("namewidth"), fNameWidth
); //$NON-NLS-1$
316 * Create a data viewer.
322 * @return The new data viewer
324 protected Control
createDataViewer(Composite parent
, int style
) {
326 fColorScheme
= new TimeGraphColorScheme();
327 fDataViewer
= new Composite(parent
, style
) {
329 public void redraw() {
330 fTimeScaleCtrl
.redraw();
331 fTimeGraphCtrl
.redraw();
335 GridLayout gl
= new GridLayout(2, false);
336 gl
.marginHeight
= fBorderWidth
;
338 gl
.verticalSpacing
= 0;
339 gl
.horizontalSpacing
= 0;
340 fDataViewer
.setLayout(gl
);
342 fTimeScaleCtrl
= new TimeGraphScale(fDataViewer
, fColorScheme
);
343 fTimeScaleCtrl
.setTimeProvider(this);
344 fTimeScaleCtrl
.setLayoutData(new GridData(SWT
.FILL
, SWT
.DEFAULT
, true, false));
345 fTimeScaleCtrl
.setHeight(fTimeScaleHeight
);
347 fVerticalScrollBar
= new Slider(fDataViewer
, SWT
.VERTICAL
| SWT
.NO_FOCUS
);
348 fVerticalScrollBar
.setLayoutData(new GridData(SWT
.DEFAULT
, SWT
.FILL
, false, true, 1, 2));
349 fVerticalScrollBar
.addSelectionListener(new SelectionAdapter() {
351 public void widgetSelected(SelectionEvent e
) {
352 setTopIndex(fVerticalScrollBar
.getSelection());
355 fVerticalScrollBar
.setEnabled(false);
357 fTimeGraphCtrl
= createTimeGraphControl(fDataViewer
, fColorScheme
);
359 fTimeGraphCtrl
.setTimeProvider(this);
360 fTimeGraphCtrl
.setTimeGraphScale(fTimeScaleCtrl
);
361 fTimeGraphCtrl
.addSelectionListener(this);
362 fTimeGraphCtrl
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true, 1, 2));
363 fTimeGraphCtrl
.addMouseWheelListener(new MouseWheelListener() {
365 public void mouseScrolled(MouseEvent e
) {
366 adjustVerticalScrollBar();
369 fTimeGraphCtrl
.addKeyListener(new KeyAdapter() {
371 public void keyPressed(KeyEvent e
) {
372 adjustVerticalScrollBar();
376 Composite filler
= new Composite(fDataViewer
, SWT
.NONE
);
377 GridData gd
= new GridData(SWT
.DEFAULT
, SWT
.DEFAULT
, false, false);
378 gd
.heightHint
= fTimeGraphCtrl
.getHorizontalBar().getSize().y
;
379 filler
.setLayoutData(gd
);
380 filler
.setLayout(new FillLayout());
382 fTimeGraphCtrl
.addControlListener(new ControlAdapter() {
384 public void controlResized(ControlEvent event
) {
389 fDataViewer
.update();
390 adjustVerticalScrollBar();
397 public void dispose() {
399 fTimeGraphCtrl
.dispose();
400 fDataViewer
.dispose();
401 fColorScheme
.dispose();
405 * Create a new time graph control.
408 * The parent composite
411 * @return The new TimeGraphControl
414 protected TimeGraphControl
createTimeGraphControl(Composite parent
,
415 TimeGraphColorScheme colors
) {
416 return new TimeGraphControl(parent
, colors
);
420 * Resize the controls
422 public void resizeControls() {
423 Rectangle r
= fDataViewer
.getClientArea();
429 if (fNameWidth
> width
- fMinNameWidth
) {
430 fNameWidth
= width
- fMinNameWidth
;
432 if (fNameWidth
< fMinNameWidth
) {
433 fNameWidth
= fMinNameWidth
;
435 adjustVerticalScrollBar();
439 * Try to set most convenient time range for display.
442 * The traces in the model
444 public void setTimeRange(ITimeGraphEntry traces
[]) {
447 for (int i
= 0; i
< traces
.length
; i
++) {
448 ITimeGraphEntry entry
= traces
[i
];
449 if (entry
.getEndTime() >= entry
.getStartTime() && entry
.getEndTime() > 0) {
450 if (fBeginTime
< 0 || entry
.getStartTime() < fBeginTime
) {
451 fBeginTime
= entry
.getStartTime();
453 if (entry
.getEndTime() > fEndTime
) {
454 fEndTime
= entry
.getEndTime();
459 if (fBeginTime
< 0) {
465 * Recalculate the time bounds
467 public void setTimeBounds() {
468 fTime0Bound
= fBeginTime
;
469 if (fTime0Bound
< 0) {
472 fTime1Bound
= fEndTime
;
473 if (!fTimeRangeFixed
) {
474 fTime0
= fTime0Bound
;
475 fTime1
= fTime1Bound
;
477 fTime0
= Math
.max(fTime0Bound
, Math
.min(fTime0
, fTime1Bound
));
478 fTime1
= Math
.max(fTime0Bound
, Math
.min(fTime1
, fTime1Bound
));
479 if (fTime1
- fTime0
< fMinTimeInterval
) {
480 fTime1
= Math
.min(fTime1Bound
, fTime0
+ fMinTimeInterval
);
489 void updateInternalData(ITimeGraphEntry
[] traces
, long start
, long end
) {
490 ITimeGraphEntry
[] realTraces
= traces
;
492 if (null == realTraces
) {
493 realTraces
= new ITimeGraphEntry
[0];
495 if ((start
== 0 && end
== 0) || start
< 0 || end
< 0) {
496 // Start and end time are unspecified and need to be determined from
497 // individual processes
498 setTimeRange(realTraces
);
504 refreshAllData(realTraces
);
510 private void refreshAllData(ITimeGraphEntry
[] traces
) {
512 if (fSelectionBegin
< fBeginTime
) {
513 fSelectionBegin
= fBeginTime
;
514 } else if (fSelectionBegin
> fEndTime
) {
515 fSelectionBegin
= fEndTime
;
517 if (fSelectionEnd
< fBeginTime
) {
518 fSelectionEnd
= fBeginTime
;
519 } else if (fSelectionEnd
> fEndTime
) {
520 fSelectionEnd
= fEndTime
;
522 fTimeGraphCtrl
.refreshData(traces
);
523 fTimeScaleCtrl
.redraw();
524 adjustVerticalScrollBar();
528 * Callback for when this view is focused
530 public void setFocus() {
531 if (null != fTimeGraphCtrl
) {
532 fTimeGraphCtrl
.setFocus();
537 * Get the current focus status of this view.
539 * @return If the view is currently focused, or not
541 public boolean isInFocus() {
542 return fTimeGraphCtrl
.isInFocus();
546 * Get the view's current selection
548 * @return The entry that is selected
550 public ITimeGraphEntry
getSelection() {
551 return fTimeGraphCtrl
.getSelectedTrace();
555 * Get the index of the current selection
559 public int getSelectionIndex() {
560 return fTimeGraphCtrl
.getSelectedIndex();
564 public long getTime0() {
569 public long getTime1() {
574 public long getMinTimeInterval() {
575 return fMinTimeInterval
;
579 public int getNameSpace() {
584 public void setNameSpace(int width
) {
586 int w
= fTimeGraphCtrl
.getClientArea().width
;
587 if (fNameWidth
> w
- MIN_NAME_WIDTH
) {
588 fNameWidth
= w
- MIN_NAME_WIDTH
;
590 if (fNameWidth
< MIN_NAME_WIDTH
) {
591 fNameWidth
= MIN_NAME_WIDTH
;
593 fTimeGraphCtrl
.adjustScrolls();
594 fTimeGraphCtrl
.redraw();
595 fTimeScaleCtrl
.redraw();
599 public int getTimeSpace() {
600 int w
= fTimeGraphCtrl
.getClientArea().width
;
601 return w
- fNameWidth
;
605 public long getBeginTime() {
610 public long getEndTime() {
615 public long getMaxTime() {
620 public long getMinTime() {
628 public long getSelectionBegin() {
629 return fSelectionBegin
;
636 public long getSelectionEnd() {
637 return fSelectionEnd
;
641 public void setStartFinishTimeNotify(long time0
, long time1
) {
642 setStartFinishTime(time0
, time1
);
643 notifyRangeListeners(time0
, time1
);
647 public void notifyStartFinishTime() {
648 notifyRangeListeners(fTime0
, fTime1
);
652 public void setStartFinishTime(long time0
, long time1
) {
654 if (fTime0
< fTime0Bound
) {
655 fTime0
= fTime0Bound
;
657 if (fTime0
> fTime1Bound
) {
658 fTime0
= fTime1Bound
;
661 if (fTime1
< fTime0Bound
) {
662 fTime1
= fTime0Bound
;
664 if (fTime1
> fTime1Bound
) {
665 fTime1
= fTime1Bound
;
667 if (fTime1
- fTime0
< fMinTimeInterval
) {
668 fTime1
= Math
.min(fTime1Bound
, fTime0
+ fMinTimeInterval
);
670 fTimeRangeFixed
= true;
671 fTimeGraphCtrl
.adjustScrolls();
672 fTimeGraphCtrl
.redraw();
673 fTimeScaleCtrl
.redraw();
677 * Set the time bounds to the provided values
680 * The start time of the window
684 public void setTimeBounds(long beginTime
, long endTime
) {
685 if (endTime
>= beginTime
) {
686 fBeginTime
= beginTime
;
688 fTime0Bound
= beginTime
;
689 fTime1Bound
= endTime
;
696 fTimeGraphCtrl
.adjustScrolls();
700 public void resetStartFinishTime() {
701 setStartFinishTime(fTime0Bound
, fTime1Bound
);
702 fTimeRangeFixed
= false;
706 public void setSelectedTimeNotify(long time
, boolean ensureVisible
) {
707 setSelectedTimeInt(time
, ensureVisible
, true);
711 public void setSelectedTime(long time
, boolean ensureVisible
) {
712 setSelectedTimeInt(time
, ensureVisible
, false);
719 public void setSelectionRangeNotify(long beginTime
, long endTime
) {
720 boolean changed
= (beginTime
!= fSelectionBegin
|| endTime
!= fSelectionEnd
);
721 fSelectionBegin
= Math
.max(fTime0Bound
, Math
.min(fTime1Bound
, beginTime
));
722 fSelectionEnd
= Math
.max(fTime0Bound
, Math
.min(fTime1Bound
, endTime
));
723 fTimeGraphCtrl
.redraw();
724 fTimeScaleCtrl
.redraw();
726 notifyTimeListeners(fSelectionBegin
, fSelectionEnd
);
734 public void setSelectionRange(long beginTime
, long endTime
) {
735 fSelectionBegin
= Math
.max(fTime0Bound
, Math
.min(fTime1Bound
, beginTime
));
736 fSelectionEnd
= Math
.max(fTime0Bound
, Math
.min(fTime1Bound
, endTime
));
737 fTimeGraphCtrl
.redraw();
738 fTimeScaleCtrl
.redraw();
741 private void setSelectedTimeInt(long time
, boolean ensureVisible
, boolean doNotify
) {
745 long timeSpace
= (fTime1
- fTime0
) / RECENTERING_MARGIN_FACTOR
;
746 long timeMid
= (fTime1
- fTime0
) / 2;
747 if (time
< fTime0
+ timeSpace
) {
748 long dt
= fTime0
- time
+ timeMid
;
751 } else if (time
> fTime1
- timeSpace
) {
752 long dt
= time
- fTime1
+ timeMid
;
756 if (fTime0
< fTime0Bound
) {
757 fTime1
= Math
.min(fTime1Bound
, fTime1
+ (fTime0Bound
- fTime0
));
758 fTime0
= fTime0Bound
;
759 } else if (fTime1
> fTime1Bound
) {
760 fTime0
= Math
.max(fTime0Bound
, fTime0
- (fTime1
- fTime1Bound
));
761 fTime1
= fTime1Bound
;
764 if (fTime1
- fTime0
< fMinTimeInterval
) {
765 fTime1
= Math
.min(fTime1Bound
, fTime0
+ fMinTimeInterval
);
767 fTimeGraphCtrl
.adjustScrolls();
768 fTimeGraphCtrl
.redraw();
769 fTimeScaleCtrl
.redraw();
771 boolean notifySelectedTime
= (time
!= fSelectionBegin
|| time
!= fSelectionEnd
);
772 fSelectionBegin
= time
;
773 fSelectionEnd
= time
;
775 if (doNotify
&& ((time0
!= fTime0
) || (time1
!= fTime1
))) {
776 notifyRangeListeners(fTime0
, fTime1
);
779 if (doNotify
&& notifySelectedTime
) {
780 notifyTimeListeners(fSelectionBegin
, fSelectionEnd
);
785 public void widgetDefaultSelected(SelectionEvent e
) {
786 if (fSelectedEntry
!= getSelection()) {
787 fSelectedEntry
= getSelection();
788 notifySelectionListeners(fSelectedEntry
);
793 public void widgetSelected(SelectionEvent e
) {
794 if (fSelectedEntry
!= getSelection()) {
795 fSelectedEntry
= getSelection();
796 notifySelectionListeners(fSelectedEntry
);
801 * Callback for when the next event is selected
803 public void selectNextEvent() {
804 fTimeGraphCtrl
.selectNextEvent();
805 adjustVerticalScrollBar();
809 * Callback for when the previous event is selected
811 public void selectPrevEvent() {
812 fTimeGraphCtrl
.selectPrevEvent();
813 adjustVerticalScrollBar();
817 * Callback for when the next item is selected
819 public void selectNextItem() {
820 fTimeGraphCtrl
.selectNextTrace();
821 adjustVerticalScrollBar();
825 * Callback for when the previous item is selected
827 public void selectPrevItem() {
828 fTimeGraphCtrl
.selectPrevTrace();
829 adjustVerticalScrollBar();
833 * Callback for the show legend action
835 public void showLegend() {
836 if (fDataViewer
== null || fDataViewer
.isDisposed()) {
840 TimeGraphLegend
.open(fDataViewer
.getShell(), fTimeGraphProvider
);
844 * Callback for the Zoom In action
846 public void zoomIn() {
847 fTimeGraphCtrl
.zoomIn();
851 * Callback for the Zoom Out action
853 public void zoomOut() {
854 fTimeGraphCtrl
.zoomOut();
857 private String
getPreferenceString(String string
) {
858 return getViewTypeStr() + "." + string
; //$NON-NLS-1$
862 * Add a selection listener
865 * The listener to add
867 public void addSelectionListener(ITimeGraphSelectionListener listener
) {
868 fSelectionListeners
.add(listener
);
872 * Remove a selection listener
875 * The listener to remove
877 public void removeSelectionListener(ITimeGraphSelectionListener listener
) {
878 fSelectionListeners
.remove(listener
);
881 private void notifySelectionListeners(ITimeGraphEntry selection
) {
882 TimeGraphSelectionEvent event
= new TimeGraphSelectionEvent(this, selection
);
884 for (ITimeGraphSelectionListener listener
: fSelectionListeners
) {
885 listener
.selectionChanged(event
);
890 * Add a time listener
893 * The listener to add
895 public void addTimeListener(ITimeGraphTimeListener listener
) {
896 fTimeListeners
.add(listener
);
900 * Remove a time listener
903 * The listener to remove
905 public void removeTimeListener(ITimeGraphTimeListener listener
) {
906 fTimeListeners
.remove(listener
);
909 private void notifyTimeListeners(long startTime
, long endTime
) {
910 TimeGraphTimeEvent event
= new TimeGraphTimeEvent(this, startTime
, endTime
);
912 for (ITimeGraphTimeListener listener
: fTimeListeners
) {
913 listener
.timeSelected(event
);
918 * Add a range listener
921 * The listener to add
923 public void addRangeListener(ITimeGraphRangeListener listener
) {
924 fRangeListeners
.add(listener
);
928 * Remove a range listener
931 * The listener to remove
933 public void removeRangeListener(ITimeGraphRangeListener listener
) {
934 fRangeListeners
.remove(listener
);
937 private void notifyRangeListeners(long startTime
, long endTime
) {
938 // Check if the time has actually changed from last notification
939 if (startTime
!= fTime0ExtSynch
|| endTime
!= fTime1ExtSynch
) {
940 // Notify Time Scale Selection Listeners
941 TimeGraphRangeUpdateEvent event
= new TimeGraphRangeUpdateEvent(this, startTime
, endTime
);
943 for (ITimeGraphRangeListener listener
: fRangeListeners
) {
944 listener
.timeRangeUpdated(event
);
947 // update external synch timers
948 updateExtSynchTimers();
953 * Callback to set a selected event in the view
956 * The event that was selected
958 * The source of this selection event
960 public void setSelectedEvent(ITimeEvent event
, Object source
) {
961 if (event
== null || source
== this) {
964 fSelectedEntry
= event
.getEntry();
965 fTimeGraphCtrl
.selectItem(fSelectedEntry
, false);
967 setSelectedTimeInt(event
.getTime(), true, true);
968 adjustVerticalScrollBar();
972 * Set the seeked time of a trace
975 * The trace that was seeked
979 * The source of this seek event
981 public void setSelectedTraceTime(ITimeGraphEntry trace
, long time
, Object source
) {
982 if (trace
== null || source
== this) {
985 fSelectedEntry
= trace
;
986 fTimeGraphCtrl
.selectItem(trace
, false);
988 setSelectedTimeInt(time
, true, true);
992 * Callback for a trace selection
995 * The trace that was selected
997 public void setSelection(ITimeGraphEntry trace
) {
998 fSelectedEntry
= trace
;
999 fTimeGraphCtrl
.selectItem(trace
, false);
1000 adjustVerticalScrollBar();
1004 * Callback for a time window selection
1007 * Start time of the range
1009 * End time of the range
1011 * Source of the event
1013 public void setSelectVisTimeWindow(long time0
, long time1
, Object source
) {
1014 if (source
== this) {
1018 setStartFinishTime(time0
, time1
);
1020 // update notification time values since we are now in synch with the
1021 // external application
1022 updateExtSynchTimers();
1026 * update the cache timers used to identify the need to send a time window
1027 * update to external registered listeners
1029 private void updateExtSynchTimers() {
1030 // last time notification cache
1031 fTime0ExtSynch
= fTime0
;
1032 fTime1ExtSynch
= fTime1
;
1039 public TimeFormat
getTimeFormat() {
1045 * the {@link TimeFormat} used to display timestamps
1048 public void setTimeFormat(TimeFormat tf
) {
1049 this.fTimeFormat
= tf
;
1053 * Retrieve the border width
1057 public int getBorderWidth() {
1058 return fBorderWidth
;
1062 * Set the border width
1064 * @param borderWidth
1067 public void setBorderWidth(int borderWidth
) {
1068 if (borderWidth
> -1) {
1069 this.fBorderWidth
= borderWidth
;
1070 GridLayout gl
= (GridLayout
) fDataViewer
.getLayout();
1071 gl
.marginHeight
= borderWidth
;
1076 * Retrieve the height of the header
1078 * @return The height
1080 public int getHeaderHeight() {
1081 return fTimeScaleHeight
;
1085 * Set the height of the header
1087 * @param headerHeight
1090 public void setHeaderHeight(int headerHeight
) {
1091 if (headerHeight
> -1) {
1092 this.fTimeScaleHeight
= headerHeight
;
1093 fTimeScaleCtrl
.setHeight(headerHeight
);
1098 * Retrieve the height of an item row
1100 * @return The height
1102 public int getItemHeight() {
1103 if (fTimeGraphCtrl
!= null) {
1104 return fTimeGraphCtrl
.getItemHeight();
1110 * Set the height of an item row
1115 public void setItemHeight(int rowHeight
) {
1116 if (fTimeGraphCtrl
!= null) {
1117 fTimeGraphCtrl
.setItemHeight(rowHeight
);
1122 * Set the minimum item width
1127 public void setMinimumItemWidth(int width
) {
1128 if (fTimeGraphCtrl
!= null) {
1129 fTimeGraphCtrl
.setMinimumItemWidth(width
);
1134 * Set the width for the name column
1139 public void setNameWidthPref(int width
) {
1140 fNameWidthPref
= width
;
1148 * Retrieve the configure width for the name column
1154 public int getNameWidthPref(int width
) {
1155 return fNameWidthPref
;
1159 * Returns the primary control associated with this viewer.
1161 * @return the SWT control which displays this viewer's content
1163 public Control
getControl() {
1168 * Returns the time graph control associated with this viewer.
1170 * @return the time graph control
1173 public TimeGraphControl
getTimeGraphControl() {
1174 return fTimeGraphCtrl
;
1178 * Returns the time graph scale associated with this viewer.
1180 * @return the time graph scale
1183 public TimeGraphScale
getTimeGraphScale() {
1184 return fTimeScaleCtrl
;
1188 * Return the x coordinate corresponding to a time
1192 * @return the x coordinate corresponding to the time
1196 public int getXForTime(long time
) {
1197 return fTimeGraphCtrl
.getXForTime(time
);
1201 * Return the time corresponding to an x coordinate
1205 * @return the time corresponding to the x coordinate
1209 public long getTimeAtX(int x
) {
1210 return fTimeGraphCtrl
.getTimeAtX(x
);
1214 * Get the selection provider
1216 * @return the selection provider
1218 public ISelectionProvider
getSelectionProvider() {
1219 return fTimeGraphCtrl
;
1223 * Wait for the cursor
1226 * Wait indefinitely?
1228 public void waitCursor(boolean waitInd
) {
1229 fTimeGraphCtrl
.waitCursor(waitInd
);
1233 * Get the horizontal scroll bar object
1235 * @return The scroll bar
1237 public ScrollBar
getHorizontalBar() {
1238 return fTimeGraphCtrl
.getHorizontalBar();
1242 * Get the vertical scroll bar object
1244 * @return The scroll bar
1246 public Slider
getVerticalBar() {
1247 return fVerticalScrollBar
;
1251 * Set the given index as the top one
1254 * The index that will go to the top
1256 public void setTopIndex(int index
) {
1257 fTimeGraphCtrl
.setTopIndex(index
);
1258 adjustVerticalScrollBar();
1262 * Retrieve the current top index
1264 * @return The top index
1266 public int getTopIndex() {
1267 return fTimeGraphCtrl
.getTopIndex();
1271 * Set the expanded state of an entry
1274 * The entry to expand/collapse
1276 * True for expanded, false for collapsed
1278 public void setExpandedState(ITimeGraphEntry entry
, boolean expanded
) {
1279 fTimeGraphCtrl
.setExpandedState(entry
, expanded
);
1280 adjustVerticalScrollBar();
1284 * Collapses all nodes of the viewer's tree, starting with the root.
1288 public void collapseAll() {
1289 fTimeGraphCtrl
.collapseAll();
1290 adjustVerticalScrollBar();
1294 * Expands all nodes of the viewer's tree, starting with the root.
1298 public void expandAll() {
1299 fTimeGraphCtrl
.expandAll();
1300 adjustVerticalScrollBar();
1304 * Get the number of sub-elements when expanded
1306 * @return The element count
1308 public int getExpandedElementCount() {
1309 return fTimeGraphCtrl
.getExpandedElementCount();
1313 * Get the sub-elements
1315 * @return The array of entries that are below this one
1317 public ITimeGraphEntry
[] getExpandedElements() {
1318 return fTimeGraphCtrl
.getExpandedElements();
1322 * Add a tree listener
1325 * The listener to add
1327 public void addTreeListener(ITimeGraphTreeListener listener
) {
1328 fTimeGraphCtrl
.addTreeListener(listener
);
1332 * Remove a tree listener
1335 * The listener to remove
1337 public void removeTreeListener(ITimeGraphTreeListener listener
) {
1338 fTimeGraphCtrl
.removeTreeListener(listener
);
1342 * Get the reset scale action.
1344 * @return The Action object
1346 public Action
getResetScaleAction() {
1347 if (fResetScaleAction
== null) {
1349 fResetScaleAction
= new Action() {
1352 resetStartFinishTime();
1353 notifyStartFinishTime();
1356 fResetScaleAction
.setText(Messages
.TmfTimeGraphViewer_ResetScaleActionNameText
);
1357 fResetScaleAction
.setToolTipText(Messages
.TmfTimeGraphViewer_ResetScaleActionToolTipText
);
1358 fResetScaleAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_HOME_MENU
));
1360 return fResetScaleAction
;
1364 * Get the show legend action.
1366 * @return The Action object
1368 public Action
getShowLegendAction() {
1369 if (fShowLegendAction
== null) {
1371 fShowLegendAction
= new Action() {
1377 fShowLegendAction
.setText(Messages
.TmfTimeGraphViewer_LegendActionNameText
);
1378 fShowLegendAction
.setToolTipText(Messages
.TmfTimeGraphViewer_LegendActionToolTipText
);
1379 fShowLegendAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_SHOW_LEGEND
));
1382 return fShowLegendAction
;
1386 * Get the the next event action.
1388 * @return The action object
1390 public Action
getNextEventAction() {
1391 if (fNextEventAction
== null) {
1392 fNextEventAction
= new Action() {
1399 fNextEventAction
.setText(Messages
.TmfTimeGraphViewer_NextEventActionNameText
);
1400 fNextEventAction
.setToolTipText(Messages
.TmfTimeGraphViewer_NextEventActionToolTipText
);
1401 fNextEventAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_NEXT_EVENT
));
1404 return fNextEventAction
;
1408 * Get the previous event action.
1410 * @return The Action object
1412 public Action
getPreviousEventAction() {
1413 if (fPrevEventAction
== null) {
1414 fPrevEventAction
= new Action() {
1421 fPrevEventAction
.setText(Messages
.TmfTimeGraphViewer_PreviousEventActionNameText
);
1422 fPrevEventAction
.setToolTipText(Messages
.TmfTimeGraphViewer_PreviousEventActionToolTipText
);
1423 fPrevEventAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_PREV_EVENT
));
1426 return fPrevEventAction
;
1430 * Get the next item action.
1432 * @return The Action object
1434 public Action
getNextItemAction() {
1435 if (fNextItemAction
== null) {
1437 fNextItemAction
= new Action() {
1443 fNextItemAction
.setText(Messages
.TmfTimeGraphViewer_NextItemActionNameText
);
1444 fNextItemAction
.setToolTipText(Messages
.TmfTimeGraphViewer_NextItemActionToolTipText
);
1445 fNextItemAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_NEXT_ITEM
));
1447 return fNextItemAction
;
1451 * Get the previous item action.
1453 * @return The Action object
1455 public Action
getPreviousItemAction() {
1456 if (fPreviousItemAction
== null) {
1458 fPreviousItemAction
= new Action() {
1464 fPreviousItemAction
.setText(Messages
.TmfTimeGraphViewer_PreviousItemActionNameText
);
1465 fPreviousItemAction
.setToolTipText(Messages
.TmfTimeGraphViewer_PreviousItemActionToolTipText
);
1466 fPreviousItemAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_PREV_ITEM
));
1468 return fPreviousItemAction
;
1472 * Get the zoom in action
1474 * @return The Action object
1476 public Action
getZoomInAction() {
1477 if (fZoomInAction
== null) {
1478 fZoomInAction
= new Action() {
1484 fZoomInAction
.setText(Messages
.TmfTimeGraphViewer_ZoomInActionNameText
);
1485 fZoomInAction
.setToolTipText(Messages
.TmfTimeGraphViewer_ZoomInActionToolTipText
);
1486 fZoomInAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_ZOOM_IN_MENU
));
1488 return fZoomInAction
;
1492 * Get the zoom out action
1494 * @return The Action object
1496 public Action
getZoomOutAction() {
1497 if (fZoomOutAction
== null) {
1498 fZoomOutAction
= new Action() {
1504 fZoomOutAction
.setText(Messages
.TmfTimeGraphViewer_ZoomOutActionNameText
);
1505 fZoomOutAction
.setToolTipText(Messages
.TmfTimeGraphViewer_ZoomOutActionToolTipText
);
1506 fZoomOutAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_ZOOM_OUT_MENU
));
1508 return fZoomOutAction
;
1512 * Get the hide arrows action
1514 * @param dialogSettings
1515 * The dialog settings section where the state should be stored,
1518 * @return The Action object
1522 public Action
getHideArrowsAction(final IDialogSettings dialogSettings
) {
1523 if (fHideArrowsAction
== null) {
1524 fHideArrowsAction
= new Action(Messages
.TmfTimeGraphViewer_HideArrowsActionNameText
, IAction
.AS_CHECK_BOX
) {
1527 boolean hideArrows
= fHideArrowsAction
.isChecked();
1528 fTimeGraphCtrl
.hideArrows(hideArrows
);
1530 if (dialogSettings
!= null) {
1531 dialogSettings
.put(HIDE_ARROWS_KEY
, hideArrows
);
1533 if (fFollowArrowFwdAction
!= null) {
1534 fFollowArrowFwdAction
.setEnabled(!hideArrows
);
1536 if (fFollowArrowBwdAction
!= null) {
1537 fFollowArrowBwdAction
.setEnabled(!hideArrows
);
1541 fHideArrowsAction
.setToolTipText(Messages
.TmfTimeGraphViewer_HideArrowsActionToolTipText
);
1542 fHideArrowsAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_HIDE_ARROWS
));
1543 if (dialogSettings
!= null) {
1544 boolean hideArrows
= dialogSettings
.getBoolean(HIDE_ARROWS_KEY
);
1545 fTimeGraphCtrl
.hideArrows(hideArrows
);
1546 fHideArrowsAction
.setChecked(hideArrows
);
1547 if (fFollowArrowFwdAction
!= null) {
1548 fFollowArrowFwdAction
.setEnabled(!hideArrows
);
1550 if (fFollowArrowBwdAction
!= null) {
1551 fFollowArrowBwdAction
.setEnabled(!hideArrows
);
1555 return fHideArrowsAction
;
1559 * Get the follow arrow forward action.
1561 * @return The Action object
1565 public Action
getFollowArrowFwdAction() {
1566 if (fFollowArrowFwdAction
== null) {
1567 fFollowArrowFwdAction
= new Action() {
1570 fTimeGraphCtrl
.followArrowFwd();
1571 adjustVerticalScrollBar();
1574 fFollowArrowFwdAction
.setText(Messages
.TmfTimeGraphViewer_FollowArrowForwardActionNameText
);
1575 fFollowArrowFwdAction
.setToolTipText(Messages
.TmfTimeGraphViewer_FollowArrowForwardActionToolTipText
);
1576 fFollowArrowFwdAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_FOLLOW_ARROW_FORWARD
));
1577 if (fHideArrowsAction
!= null) {
1578 fFollowArrowFwdAction
.setEnabled(!fHideArrowsAction
.isChecked());
1581 return fFollowArrowFwdAction
;
1585 * Get the follow arrow backward action.
1587 * @return The Action object
1591 public Action
getFollowArrowBwdAction() {
1592 if (fFollowArrowBwdAction
== null) {
1593 fFollowArrowBwdAction
= new Action() {
1596 fTimeGraphCtrl
.followArrowBwd();
1597 adjustVerticalScrollBar();
1600 fFollowArrowBwdAction
.setText(Messages
.TmfTimeGraphViewer_FollowArrowBackwardActionNameText
);
1601 fFollowArrowBwdAction
.setToolTipText(Messages
.TmfTimeGraphViewer_FollowArrowBackwardActionToolTipText
);
1602 fFollowArrowBwdAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_FOLLOW_ARROW_BACKWARD
));
1603 if (fHideArrowsAction
!= null) {
1604 fFollowArrowBwdAction
.setEnabled(!fHideArrowsAction
.isChecked());
1607 return fFollowArrowBwdAction
;
1610 private void adjustVerticalScrollBar() {
1611 int topIndex
= fTimeGraphCtrl
.getTopIndex();
1612 int countPerPage
= fTimeGraphCtrl
.countPerPage();
1613 int expandedElementCount
= fTimeGraphCtrl
.getExpandedElementCount();
1614 if (topIndex
+ countPerPage
> expandedElementCount
) {
1615 fTimeGraphCtrl
.setTopIndex(Math
.max(0, expandedElementCount
- countPerPage
));
1618 int selection
= fTimeGraphCtrl
.getTopIndex();
1620 int max
= Math
.max(1, expandedElementCount
- 1);
1621 int thumb
= Math
.min(max
, Math
.max(1, countPerPage
- 1));
1623 int pageIncrement
= Math
.max(1, countPerPage
);
1624 fVerticalScrollBar
.setValues(selection
, min
, max
, thumb
, increment
, pageIncrement
);
1629 * a {@link MenuDetectListener}
1630 * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TimeGraphControl#addTimeGraphEntryMenuListener(org.eclipse.swt.events.MenuDetectListener)
1633 public void addTimeGraphEntryMenuListener(MenuDetectListener listener
) {
1634 fTimeGraphCtrl
.addTimeGraphEntryMenuListener(listener
);
1639 * a {@link MenuDetectListener}
1640 * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TimeGraphControl#removeTimeGraphEntryMenuListener(org.eclipse.swt.events.MenuDetectListener)
1643 public void removeTimeGraphEntryMenuListener(MenuDetectListener listener
) {
1644 fTimeGraphCtrl
.removeTimeGraphEntryMenuListener(listener
);
1649 * a {@link MenuDetectListener}
1650 * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TimeGraphControl#addTimeEventMenuListener(org.eclipse.swt.events.MenuDetectListener)
1653 public void addTimeEventMenuListener(MenuDetectListener listener
) {
1654 fTimeGraphCtrl
.addTimeEventMenuListener(listener
);
1659 * a {@link MenuDetectListener}
1660 * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TimeGraphControl#removeTimeEventMenuListener(org.eclipse.swt.events.MenuDetectListener)
1663 public void removeTimeEventMenuListener(MenuDetectListener listener
) {
1664 fTimeGraphCtrl
.removeTimeEventMenuListener(listener
);
1669 * The filter object to be attached to the view
1672 public void addFilter(ViewerFilter filter
) {
1673 fTimeGraphCtrl
.addFilter(filter
);
1679 * The filter object to be attached to the view
1682 public void removeFilter(ViewerFilter filter
) {
1683 fTimeGraphCtrl
.removeFilter(filter
);