1 /*****************************************************************************
2 * Copyright (c) 2007, 2013 Intel Corporation, Ericsson
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 *****************************************************************************/
16 package org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
;
18 import java
.util
.ArrayList
;
19 import java
.util
.List
;
21 import org
.eclipse
.jface
.action
.Action
;
22 import org
.eclipse
.jface
.viewers
.ISelectionProvider
;
23 import org
.eclipse
.jface
.viewers
.ViewerFilter
;
24 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.Activator
;
25 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.ITmfImageConstants
;
26 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.Messages
;
27 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.dialogs
.TimeGraphLegend
;
28 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.model
.ITimeEvent
;
29 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.model
.ITimeGraphEntry
;
30 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.widgets
.ITimeDataProvider2
;
31 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.widgets
.TimeGraphColorScheme
;
32 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.widgets
.TimeGraphControl
;
33 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.widgets
.TimeGraphScale
;
34 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.widgets
.TimeGraphTooltipHandler
;
35 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.widgets
.Utils
;
36 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.widgets
.Utils
.TimeFormat
;
37 import org
.eclipse
.swt
.SWT
;
38 import org
.eclipse
.swt
.events
.ControlAdapter
;
39 import org
.eclipse
.swt
.events
.ControlEvent
;
40 import org
.eclipse
.swt
.events
.KeyAdapter
;
41 import org
.eclipse
.swt
.events
.KeyEvent
;
42 import org
.eclipse
.swt
.events
.MenuDetectListener
;
43 import org
.eclipse
.swt
.events
.MouseEvent
;
44 import org
.eclipse
.swt
.events
.MouseWheelListener
;
45 import org
.eclipse
.swt
.events
.SelectionAdapter
;
46 import org
.eclipse
.swt
.events
.SelectionEvent
;
47 import org
.eclipse
.swt
.events
.SelectionListener
;
48 import org
.eclipse
.swt
.graphics
.Rectangle
;
49 import org
.eclipse
.swt
.layout
.FillLayout
;
50 import org
.eclipse
.swt
.layout
.GridData
;
51 import org
.eclipse
.swt
.layout
.GridLayout
;
52 import org
.eclipse
.swt
.widgets
.Composite
;
53 import org
.eclipse
.swt
.widgets
.Control
;
54 import org
.eclipse
.swt
.widgets
.ScrollBar
;
55 import org
.eclipse
.swt
.widgets
.Slider
;
58 * Generic time graph viewer implementation
61 * @author Patrick Tasse, and others
63 public class TimeGraphViewer
implements ITimeDataProvider2
, SelectionListener
{
65 private static final int DEFAULT_NAME_WIDTH
= 200;
66 private static final int MIN_NAME_WIDTH
= 6;
67 private static final int MAX_NAME_WIDTH
= 1000;
68 private static final int DEFAULT_HEIGHT
= 22;
69 private static final long RECENTERING_MARGIN_FACTOR
= 50;
71 private long fMinTimeInterval
;
72 private ITimeGraphEntry fSelectedEntry
;
73 private long fBeginTime
;
74 private long fEndTime
;
77 private long fSelectionBegin
= 0;
78 private long fSelectionEnd
= 0;
79 private long fTime0Bound
;
80 private long fTime1Bound
;
81 private long fTime0ExtSynch
= 0;
82 private long fTime1ExtSynch
= 0;
83 private boolean fTimeRangeFixed
;
84 private int fNameWidthPref
= DEFAULT_NAME_WIDTH
;
85 private int fMinNameWidth
= MIN_NAME_WIDTH
;
86 private int fNameWidth
;
87 private Composite fDataViewer
;
89 private TimeGraphControl fTimeGraphCtrl
;
90 private TimeGraphScale fTimeScaleCtrl
;
91 private Slider fVerticalScrollBar
;
92 private TimeGraphColorScheme fColorScheme
;
93 private ITimeGraphPresentationProvider fTimeGraphProvider
;
95 private List
<ITimeGraphSelectionListener
> fSelectionListeners
= new ArrayList
<ITimeGraphSelectionListener
>();
96 private List
<ITimeGraphTimeListener
> fTimeListeners
= new ArrayList
<ITimeGraphTimeListener
>();
97 private List
<ITimeGraphRangeListener
> fRangeListeners
= new ArrayList
<ITimeGraphRangeListener
>();
99 // Time format, using Epoch reference, Relative time format(default) or Number
100 private TimeFormat fTimeFormat
= TimeFormat
.RELATIVE
;
101 private int fBorderWidth
= 0;
102 private int fTimeScaleHeight
= DEFAULT_HEIGHT
;
104 private Action fResetScaleAction
;
105 private Action fShowLegendAction
;
106 private Action fNextEventAction
;
107 private Action fPrevEventAction
;
108 private Action fNextItemAction
;
109 private Action fPreviousItemAction
;
110 private Action fZoomInAction
;
111 private Action fZoomOutAction
;
114 * Standard constructor
117 * The parent UI composite object
121 public TimeGraphViewer(Composite parent
, int style
) {
122 createDataViewer(parent
, style
);
126 * Sets the timegraph provider used by this timegraph viewer.
128 * @param timeGraphProvider the timegraph provider
130 public void setTimeGraphProvider(ITimeGraphPresentationProvider timeGraphProvider
) {
131 fTimeGraphProvider
= timeGraphProvider
;
132 fTimeGraphCtrl
.setTimeGraphProvider(timeGraphProvider
);
133 TimeGraphTooltipHandler toolTipHandler
= new TimeGraphTooltipHandler(fTimeGraphProvider
, this);
134 toolTipHandler
.activateHoverHelp(fTimeGraphCtrl
);
138 * Sets or clears the input for this time graph viewer.
139 * The input array should only contain top-level elements.
141 * @param input The input of this time graph viewer, or <code>null</code> if none
143 public void setInput(ITimeGraphEntry
[] input
) {
144 ITimeGraphEntry
[] realInput
= input
;
146 if (fTimeGraphCtrl
!= null) {
147 if (realInput
== null) {
148 realInput
= new ITimeGraphEntry
[0];
150 setTimeRange(realInput
);
151 fVerticalScrollBar
.setEnabled(true);
155 fSelectedEntry
= null;
156 refreshAllData(realInput
);
163 public void refresh() {
164 setTimeRange(fTimeGraphCtrl
.getTraces());
165 fVerticalScrollBar
.setEnabled(true);
166 refreshAllData(fTimeGraphCtrl
.getTraces());
170 * Callback for when the control is moved
175 public void controlMoved(ControlEvent e
) {
179 * Callback for when the control is resized
184 public void controlResized(ControlEvent e
) {
189 * Handler for when the model is updated. Called from the display order in
193 * The traces in the model
198 * @param updateTimeBounds
199 * Should we updated the time bounds too
201 public void modelUpdate(ITimeGraphEntry
[] traces
, long start
,
202 long end
, boolean updateTimeBounds
) {
203 if (null != fTimeGraphCtrl
) {
204 updateInternalData(traces
, start
, end
);
205 if (updateTimeBounds
) {
206 fTimeRangeFixed
= true;
207 // set window to match limits
208 setStartFinishTime(fTime0Bound
, fTime1Bound
);
210 fTimeGraphCtrl
.redraw();
211 fTimeScaleCtrl
.redraw();
217 * @return The string representing the view type
219 protected String
getViewTypeStr() {
220 return "viewoption.threads"; //$NON-NLS-1$
223 int getMarginWidth() {
227 int getMarginHeight() {
232 fMinTimeInterval
= 1;
233 fSelectionBegin
= -1;
235 fNameWidth
= Utils
.loadIntOption(getPreferenceString("namewidth"), //$NON-NLS-1$
236 fNameWidthPref
, fMinNameWidth
, MAX_NAME_WIDTH
);
240 Utils
.saveIntOption(getPreferenceString("namewidth"), fNameWidth
); //$NON-NLS-1$
244 * Create a data viewer.
250 * @return The new data viewer
252 protected Control
createDataViewer(Composite parent
, int style
) {
254 fColorScheme
= new TimeGraphColorScheme();
255 fDataViewer
= new Composite(parent
, style
) {
257 public void redraw() {
258 fTimeScaleCtrl
.redraw();
259 fTimeGraphCtrl
.redraw();
263 GridLayout gl
= new GridLayout(2, false);
264 gl
.marginHeight
= fBorderWidth
;
266 gl
.verticalSpacing
= 0;
267 gl
.horizontalSpacing
= 0;
268 fDataViewer
.setLayout(gl
);
270 fTimeScaleCtrl
= new TimeGraphScale(fDataViewer
, fColorScheme
);
271 fTimeScaleCtrl
.setTimeProvider(this);
272 fTimeScaleCtrl
.setLayoutData(new GridData(SWT
.FILL
, SWT
.DEFAULT
, true, false));
273 fTimeScaleCtrl
.setHeight(fTimeScaleHeight
);
275 fVerticalScrollBar
= new Slider(fDataViewer
, SWT
.VERTICAL
| SWT
.NO_FOCUS
);
276 fVerticalScrollBar
.setLayoutData(new GridData(SWT
.DEFAULT
, SWT
.FILL
, false, true, 1, 2));
277 fVerticalScrollBar
.addSelectionListener(new SelectionAdapter() {
279 public void widgetSelected(SelectionEvent e
) {
280 setTopIndex(fVerticalScrollBar
.getSelection());
283 fVerticalScrollBar
.setEnabled(false);
285 fTimeGraphCtrl
= createTimeGraphControl(fDataViewer
, fColorScheme
);
287 fTimeGraphCtrl
.setTimeProvider(this);
288 fTimeGraphCtrl
.setTimeGraphScale(fTimeScaleCtrl
);
289 fTimeGraphCtrl
.addSelectionListener(this);
290 fTimeGraphCtrl
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true, 1, 2));
291 fTimeGraphCtrl
.addMouseWheelListener(new MouseWheelListener() {
293 public void mouseScrolled(MouseEvent e
) {
294 adjustVerticalScrollBar();
297 fTimeGraphCtrl
.addKeyListener(new KeyAdapter() {
299 public void keyPressed(KeyEvent e
) {
300 adjustVerticalScrollBar();
304 Composite filler
= new Composite(fDataViewer
, SWT
.NONE
);
305 GridData gd
= new GridData(SWT
.DEFAULT
, SWT
.DEFAULT
, false, false);
306 gd
.heightHint
= fTimeGraphCtrl
.getHorizontalBar().getSize().y
;
307 filler
.setLayoutData(gd
);
308 filler
.setLayout(new FillLayout());
310 fTimeGraphCtrl
.addControlListener(new ControlAdapter() {
312 public void controlResized(ControlEvent event
) {
317 fDataViewer
.update();
318 adjustVerticalScrollBar();
325 public void dispose() {
327 fTimeGraphCtrl
.dispose();
328 fDataViewer
.dispose();
329 fColorScheme
.dispose();
333 * Create a new time graph control.
336 * The parent composite
339 * @return The new TimeGraphControl
342 protected TimeGraphControl
createTimeGraphControl(Composite parent
,
343 TimeGraphColorScheme colors
) {
344 return new TimeGraphControl(parent
, colors
);
348 * Resize the controls
350 public void resizeControls() {
351 Rectangle r
= fDataViewer
.getClientArea();
357 if (fNameWidth
> width
- fMinNameWidth
) {
358 fNameWidth
= width
- fMinNameWidth
;
360 if (fNameWidth
< fMinNameWidth
) {
361 fNameWidth
= fMinNameWidth
;
363 adjustVerticalScrollBar();
367 * Try to set most convenient time range for display.
370 * The traces in the model
372 public void setTimeRange(ITimeGraphEntry traces
[]) {
375 for (int i
= 0; i
< traces
.length
; i
++) {
376 ITimeGraphEntry entry
= traces
[i
];
377 if (entry
.getEndTime() >= entry
.getStartTime() && entry
.getEndTime() > 0) {
378 if (fBeginTime
< 0 || entry
.getStartTime() < fBeginTime
) {
379 fBeginTime
= entry
.getStartTime();
381 if (entry
.getEndTime() > fEndTime
) {
382 fEndTime
= entry
.getEndTime();
387 if (fBeginTime
< 0) {
393 * Recalculate the time bounds
395 public void setTimeBounds() {
396 fTime0Bound
= fBeginTime
;
397 if (fTime0Bound
< 0) {
400 fTime1Bound
= fEndTime
;
401 if (!fTimeRangeFixed
) {
402 fTime0
= fTime0Bound
;
403 fTime1
= fTime1Bound
;
405 if (fTime1
- fTime0
< fMinTimeInterval
) {
406 fTime1
= Math
.min(fTime1Bound
, fTime0
+ fMinTimeInterval
);
415 void updateInternalData(ITimeGraphEntry
[] traces
, long start
, long end
) {
416 ITimeGraphEntry
[] realTraces
= traces
;
418 if (null == realTraces
) {
419 realTraces
= new ITimeGraphEntry
[0];
421 if ((start
== 0 && end
== 0) || start
< 0 || end
< 0) {
422 // Start and end time are unspecified and need to be determined from
423 // individual processes
424 setTimeRange(realTraces
);
430 refreshAllData(realTraces
);
436 private void refreshAllData(ITimeGraphEntry
[] traces
) {
438 if (fSelectionBegin
< fBeginTime
) {
439 fSelectionBegin
= fBeginTime
;
440 } else if (fSelectionBegin
> fEndTime
) {
441 fSelectionBegin
= fEndTime
;
443 if (fSelectionEnd
< fBeginTime
) {
444 fSelectionEnd
= fBeginTime
;
445 } else if (fSelectionEnd
> fEndTime
) {
446 fSelectionEnd
= fEndTime
;
448 fTimeGraphCtrl
.refreshData(traces
);
449 fTimeScaleCtrl
.redraw();
450 adjustVerticalScrollBar();
454 * Callback for when this view is focused
456 public void setFocus() {
457 if (null != fTimeGraphCtrl
) {
458 fTimeGraphCtrl
.setFocus();
463 * Get the current focus status of this view.
465 * @return If the view is currently focused, or not
467 public boolean isInFocus() {
468 return fTimeGraphCtrl
.isInFocus();
472 * Get the view's current selection
474 * @return The entry that is selected
476 public ITimeGraphEntry
getSelection() {
477 return fTimeGraphCtrl
.getSelectedTrace();
481 * Get the index of the current selection
485 public int getSelectionIndex() {
486 return fTimeGraphCtrl
.getSelectedIndex();
490 public long getTime0() {
495 public long getTime1() {
500 public long getMinTimeInterval() {
501 return fMinTimeInterval
;
505 public int getNameSpace() {
510 public void setNameSpace(int width
) {
512 int w
= fTimeGraphCtrl
.getClientArea().width
;
513 if (fNameWidth
> w
- MIN_NAME_WIDTH
) {
514 fNameWidth
= w
- MIN_NAME_WIDTH
;
516 if (fNameWidth
< MIN_NAME_WIDTH
) {
517 fNameWidth
= MIN_NAME_WIDTH
;
519 fTimeGraphCtrl
.adjustScrolls();
520 fTimeGraphCtrl
.redraw();
521 fTimeScaleCtrl
.redraw();
525 public int getTimeSpace() {
526 int w
= fTimeGraphCtrl
.getClientArea().width
;
527 return w
- fNameWidth
;
530 @SuppressWarnings("deprecation")
533 public long getSelectedTime() {
534 return fSelectionBegin
;
538 public long getBeginTime() {
543 public long getEndTime() {
548 public long getMaxTime() {
553 public long getMinTime() {
561 public long getSelectionBegin() {
562 return fSelectionBegin
;
569 public long getSelectionEnd() {
570 return fSelectionEnd
;
574 public void setStartFinishTimeNotify(long time0
, long time1
) {
575 setStartFinishTime(time0
, time1
);
576 notifyRangeListeners(time0
, time1
);
580 public void notifyStartFinishTime() {
581 notifyRangeListeners(fTime0
, fTime1
);
585 public void setStartFinishTime(long time0
, long time1
) {
587 if (fTime0
< fTime0Bound
) {
588 fTime0
= fTime0Bound
;
590 if (fTime0
> fTime1Bound
) {
591 fTime0
= fTime1Bound
;
594 if (fTime1
< fTime0Bound
) {
595 fTime1
= fTime0Bound
;
597 if (fTime1
> fTime1Bound
) {
598 fTime1
= fTime1Bound
;
600 if (fTime1
- fTime0
< fMinTimeInterval
) {
601 fTime1
= Math
.min(fTime1Bound
, fTime0
+ fMinTimeInterval
);
603 fTimeRangeFixed
= true;
604 fTimeGraphCtrl
.adjustScrolls();
605 fTimeGraphCtrl
.redraw();
606 fTimeScaleCtrl
.redraw();
610 * Set the time bounds to the provided values
613 * The start time of the window
617 public void setTimeBounds(long beginTime
, long endTime
) {
618 fBeginTime
= beginTime
;
620 fTime0Bound
= beginTime
;
621 fTime1Bound
= endTime
;
622 fTimeGraphCtrl
.adjustScrolls();
626 public void resetStartFinishTime() {
627 setStartFinishTime(fTime0Bound
, fTime1Bound
);
628 fTimeRangeFixed
= false;
632 public void setSelectedTimeNotify(long time
, boolean ensureVisible
) {
633 setSelectedTimeInt(time
, ensureVisible
, true);
637 public void setSelectedTime(long time
, boolean ensureVisible
) {
638 setSelectedTimeInt(time
, ensureVisible
, false);
645 public void setSelectionRangeNotify(long beginTime
, long endTime
) {
646 boolean changed
= (beginTime
!= fSelectionBegin
|| endTime
!= fSelectionEnd
);
647 fSelectionBegin
= Math
.max(fTime0Bound
, Math
.min(fTime1Bound
, beginTime
));
648 fSelectionEnd
= Math
.max(fTime0Bound
, Math
.min(fTime1Bound
, endTime
));
649 fTimeGraphCtrl
.redraw();
650 fTimeScaleCtrl
.redraw();
652 notifyTimeListeners(fSelectionBegin
, fSelectionEnd
);
660 public void setSelectionRange(long beginTime
, long endTime
) {
661 fSelectionBegin
= Math
.max(fTime0Bound
, Math
.min(fTime1Bound
, beginTime
));
662 fSelectionEnd
= Math
.max(fTime0Bound
, Math
.min(fTime1Bound
, endTime
));
663 fTimeGraphCtrl
.redraw();
664 fTimeScaleCtrl
.redraw();
667 private void setSelectedTimeInt(long time
, boolean ensureVisible
, boolean doNotify
) {
671 long timeSpace
= (fTime1
- fTime0
) / RECENTERING_MARGIN_FACTOR
;
672 long timeMid
= (fTime1
- fTime0
) / 2;
673 if (time
< fTime0
+ timeSpace
) {
674 long dt
= fTime0
- time
+ timeMid
;
677 } else if (time
> fTime1
- timeSpace
) {
678 long dt
= time
- fTime1
+ timeMid
;
682 if (fTime0
< fTime0Bound
) {
683 fTime1
= Math
.min(fTime1Bound
, fTime1
+ (fTime0Bound
- fTime0
));
684 fTime0
= fTime0Bound
;
685 } else if (fTime1
> fTime1Bound
) {
686 fTime0
= Math
.max(fTime0Bound
, fTime0
- (fTime1
- fTime1Bound
));
687 fTime1
= fTime1Bound
;
690 if (fTime1
- fTime0
< fMinTimeInterval
) {
691 fTime1
= Math
.min(fTime1Bound
, fTime0
+ fMinTimeInterval
);
693 fTimeGraphCtrl
.adjustScrolls();
694 fTimeGraphCtrl
.redraw();
695 fTimeScaleCtrl
.redraw();
697 boolean notifySelectedTime
= (time
!= fSelectionBegin
|| time
!= fSelectionEnd
);
698 fSelectionBegin
= time
;
699 fSelectionEnd
= time
;
701 if (doNotify
&& ((time0
!= fTime0
) || (time1
!= fTime1
))) {
702 notifyRangeListeners(fTime0
, fTime1
);
705 if (doNotify
&& notifySelectedTime
) {
706 notifyTimeListeners(fSelectionBegin
, fSelectionEnd
);
711 public void widgetDefaultSelected(SelectionEvent e
) {
712 if (fSelectedEntry
!= getSelection()) {
713 fSelectedEntry
= getSelection();
714 notifySelectionListeners(fSelectedEntry
);
719 public void widgetSelected(SelectionEvent e
) {
720 if (fSelectedEntry
!= getSelection()) {
721 fSelectedEntry
= getSelection();
722 notifySelectionListeners(fSelectedEntry
);
727 * Callback for when the next event is selected
729 public void selectNextEvent() {
730 fTimeGraphCtrl
.selectNextEvent();
731 adjustVerticalScrollBar();
735 * Callback for when the previous event is selected
737 public void selectPrevEvent() {
738 fTimeGraphCtrl
.selectPrevEvent();
739 adjustVerticalScrollBar();
743 * Callback for when the next item is selected
745 public void selectNextItem() {
746 fTimeGraphCtrl
.selectNextTrace();
747 adjustVerticalScrollBar();
751 * Callback for when the previous item is selected
753 public void selectPrevItem() {
754 fTimeGraphCtrl
.selectPrevTrace();
755 adjustVerticalScrollBar();
759 * Callback for the show legend action
761 public void showLegend() {
762 if (fDataViewer
== null || fDataViewer
.isDisposed()) {
766 TimeGraphLegend
.open(fDataViewer
.getShell(), fTimeGraphProvider
);
770 * Callback for the Zoom In action
772 public void zoomIn() {
773 fTimeGraphCtrl
.zoomIn();
777 * Callback for the Zoom Out action
779 public void zoomOut() {
780 fTimeGraphCtrl
.zoomOut();
783 private String
getPreferenceString(String string
) {
784 return getViewTypeStr() + "." + string
; //$NON-NLS-1$
788 * Add a selection listener
791 * The listener to add
793 public void addSelectionListener(ITimeGraphSelectionListener listener
) {
794 fSelectionListeners
.add(listener
);
798 * Remove a selection listener
801 * The listener to remove
803 public void removeSelectionListener(ITimeGraphSelectionListener listener
) {
804 fSelectionListeners
.remove(listener
);
807 private void notifySelectionListeners(ITimeGraphEntry selection
) {
808 TimeGraphSelectionEvent event
= new TimeGraphSelectionEvent(this, selection
);
810 for (ITimeGraphSelectionListener listener
: fSelectionListeners
) {
811 listener
.selectionChanged(event
);
816 * Add a time listener
819 * The listener to add
821 public void addTimeListener(ITimeGraphTimeListener listener
) {
822 fTimeListeners
.add(listener
);
826 * Remove a time listener
829 * The listener to remove
831 public void removeTimeListener(ITimeGraphTimeListener listener
) {
832 fTimeListeners
.remove(listener
);
835 private void notifyTimeListeners(long startTime
, long endTime
) {
836 TimeGraphTimeEvent event
= new TimeGraphTimeEvent(this, startTime
, endTime
);
838 for (ITimeGraphTimeListener listener
: fTimeListeners
) {
839 listener
.timeSelected(event
);
844 * Add a range listener
847 * The listener to add
849 public void addRangeListener(ITimeGraphRangeListener listener
) {
850 fRangeListeners
.add(listener
);
854 * Remove a range listener
857 * The listener to remove
859 public void removeRangeListener(ITimeGraphRangeListener listener
) {
860 fRangeListeners
.remove(listener
);
863 private void notifyRangeListeners(long startTime
, long endTime
) {
864 // Check if the time has actually changed from last notification
865 if (startTime
!= fTime0ExtSynch
|| endTime
!= fTime1ExtSynch
) {
866 // Notify Time Scale Selection Listeners
867 TimeGraphRangeUpdateEvent event
= new TimeGraphRangeUpdateEvent(this, startTime
, endTime
);
869 for (ITimeGraphRangeListener listener
: fRangeListeners
) {
870 listener
.timeRangeUpdated(event
);
873 // update external synch timers
874 updateExtSynchTimers();
879 * Callback to set a selected event in the view
882 * The event that was selected
884 * The source of this selection event
886 public void setSelectedEvent(ITimeEvent event
, Object source
) {
887 if (event
== null || source
== this) {
890 fSelectedEntry
= event
.getEntry();
891 fTimeGraphCtrl
.selectItem(fSelectedEntry
, false);
893 setSelectedTimeInt(event
.getTime(), true, true);
894 adjustVerticalScrollBar();
898 * Set the seeked time of a trace
901 * The trace that was seeked
905 * The source of this seek event
907 public void setSelectedTraceTime(ITimeGraphEntry trace
, long time
, Object source
) {
908 if (trace
== null || source
== this) {
911 fSelectedEntry
= trace
;
912 fTimeGraphCtrl
.selectItem(trace
, false);
914 setSelectedTimeInt(time
, true, true);
918 * Callback for a trace selection
921 * The trace that was selected
923 public void setSelection(ITimeGraphEntry trace
) {
924 fSelectedEntry
= trace
;
925 fTimeGraphCtrl
.selectItem(trace
, false);
926 adjustVerticalScrollBar();
930 * Callback for a time window selection
933 * Start time of the range
935 * End time of the range
937 * Source of the event
939 public void setSelectVisTimeWindow(long time0
, long time1
, Object source
) {
940 if (source
== this) {
944 setStartFinishTime(time0
, time1
);
946 // update notification time values since we are now in synch with the
947 // external application
948 updateExtSynchTimers();
952 * update the cache timers used to identify the need to send a time window
953 * update to external registered listeners
955 private void updateExtSynchTimers() {
956 // last time notification cache
957 fTime0ExtSynch
= fTime0
;
958 fTime1ExtSynch
= fTime1
;
965 public TimeFormat
getTimeFormat() {
970 * @param tf the {@link TimeFormat} used to display timestamps
973 public void setTimeFormat(TimeFormat tf
) {
974 this.fTimeFormat
= tf
;
978 * Retrieve the border width
982 public int getBorderWidth() {
987 * Set the border width
992 public void setBorderWidth(int borderWidth
) {
993 if (borderWidth
> -1) {
994 this.fBorderWidth
= borderWidth
;
995 GridLayout gl
= (GridLayout
)fDataViewer
.getLayout();
996 gl
.marginHeight
= borderWidth
;
1001 * Retrieve the height of the header
1003 * @return The height
1005 public int getHeaderHeight() {
1006 return fTimeScaleHeight
;
1010 * Set the height of the header
1012 * @param headerHeight
1015 public void setHeaderHeight(int headerHeight
) {
1016 if (headerHeight
> -1) {
1017 this.fTimeScaleHeight
= headerHeight
;
1018 fTimeScaleCtrl
.setHeight(headerHeight
);
1023 * Retrieve the height of an item row
1025 * @return The height
1027 public int getItemHeight() {
1028 if (fTimeGraphCtrl
!= null) {
1029 return fTimeGraphCtrl
.getItemHeight();
1035 * Set the height of an item row
1040 public void setItemHeight(int rowHeight
) {
1041 if (fTimeGraphCtrl
!= null) {
1042 fTimeGraphCtrl
.setItemHeight(rowHeight
);
1047 * Set the minimum item width
1052 public void setMinimumItemWidth(int width
) {
1053 if (fTimeGraphCtrl
!= null) {
1054 fTimeGraphCtrl
.setMinimumItemWidth(width
);
1059 * Set the width for the name column
1061 * @param width The width
1063 public void setNameWidthPref(int width
) {
1064 fNameWidthPref
= width
;
1072 * Retrieve the configure width for the name column
1078 public int getNameWidthPref(int width
) {
1079 return fNameWidthPref
;
1083 * Returns the primary control associated with this viewer.
1085 * @return the SWT control which displays this viewer's content
1087 public Control
getControl() {
1092 * Returns the time graph control associated with this viewer.
1094 * @return the time graph control
1097 public TimeGraphControl
getTimeGraphControl() {
1098 return fTimeGraphCtrl
;
1102 * Returns the time graph scale associated with this viewer.
1104 * @return the time graph scale
1107 public TimeGraphScale
getTimeGraphScale() {
1108 return fTimeScaleCtrl
;
1112 * Return the x coordinate corresponding to a time
1114 * @param time the time
1115 * @return the x coordinate corresponding to the time
1119 public int getXForTime(long time
) {
1120 return fTimeGraphCtrl
.getXForTime(time
);
1124 * Return the time corresponding to an x coordinate
1126 * @param x the x coordinate
1127 * @return the time corresponding to the x coordinate
1131 public long getTimeAtX(int x
) {
1132 return fTimeGraphCtrl
.getTimeAtX(x
);
1136 * Get the selection provider
1138 * @return the selection provider
1140 public ISelectionProvider
getSelectionProvider() {
1141 return fTimeGraphCtrl
;
1145 * Wait for the cursor
1148 * Wait indefinitely?
1150 public void waitCursor(boolean waitInd
) {
1151 fTimeGraphCtrl
.waitCursor(waitInd
);
1155 * Get the horizontal scroll bar object
1157 * @return The scroll bar
1159 public ScrollBar
getHorizontalBar() {
1160 return fTimeGraphCtrl
.getHorizontalBar();
1164 * Get the vertical scroll bar object
1166 * @return The scroll bar
1168 public Slider
getVerticalBar() {
1169 return fVerticalScrollBar
;
1173 * Set the given index as the top one
1176 * The index that will go to the top
1178 public void setTopIndex(int index
) {
1179 fTimeGraphCtrl
.setTopIndex(index
);
1180 adjustVerticalScrollBar();
1184 * Retrieve the current top index
1186 * @return The top index
1188 public int getTopIndex() {
1189 return fTimeGraphCtrl
.getTopIndex();
1193 * Set the expanded state of an entry
1196 * The entry to expand/collapse
1198 * True for expanded, false for collapsed
1200 public void setExpandedState(ITimeGraphEntry entry
, boolean expanded
) {
1201 fTimeGraphCtrl
.setExpandedState(entry
, expanded
);
1202 adjustVerticalScrollBar();
1206 * Collapses all nodes of the viewer's tree, starting with the root.
1210 public void collapseAll() {
1211 fTimeGraphCtrl
.collapseAll();
1212 adjustVerticalScrollBar();
1216 * Expands all nodes of the viewer's tree, starting with the root.
1220 public void expandAll() {
1221 fTimeGraphCtrl
.expandAll();
1222 adjustVerticalScrollBar();
1226 * Get the number of sub-elements when expanded
1228 * @return The element count
1230 public int getExpandedElementCount() {
1231 return fTimeGraphCtrl
.getExpandedElementCount();
1235 * Get the sub-elements
1237 * @return The array of entries that are below this one
1239 public ITimeGraphEntry
[] getExpandedElements() {
1240 return fTimeGraphCtrl
.getExpandedElements();
1244 * Add a tree listener
1247 * The listener to add
1249 public void addTreeListener(ITimeGraphTreeListener listener
) {
1250 fTimeGraphCtrl
.addTreeListener(listener
);
1254 * Remove a tree listener
1257 * The listener to remove
1259 public void removeTreeListener(ITimeGraphTreeListener listener
) {
1260 fTimeGraphCtrl
.removeTreeListener(listener
);
1264 * Get the reset scale action.
1266 * @return The Action object
1268 public Action
getResetScaleAction() {
1269 if (fResetScaleAction
== null) {
1271 fResetScaleAction
= new Action() {
1274 resetStartFinishTime();
1275 notifyStartFinishTime();
1278 fResetScaleAction
.setText(Messages
.TmfTimeGraphViewer_ResetScaleActionNameText
);
1279 fResetScaleAction
.setToolTipText(Messages
.TmfTimeGraphViewer_ResetScaleActionToolTipText
);
1280 fResetScaleAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_HOME_MENU
));
1282 return fResetScaleAction
;
1286 * Get the show legend action.
1288 * @return The Action object
1290 public Action
getShowLegendAction() {
1291 if (fShowLegendAction
== null) {
1293 fShowLegendAction
= new Action() {
1299 fShowLegendAction
.setText(Messages
.TmfTimeGraphViewer_LegendActionNameText
);
1300 fShowLegendAction
.setToolTipText(Messages
.TmfTimeGraphViewer_LegendActionToolTipText
);
1301 fShowLegendAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_SHOW_LEGEND
));
1304 return fShowLegendAction
;
1308 * Get the the next event action.
1310 * @return The action object
1312 public Action
getNextEventAction() {
1313 if (fNextEventAction
== null) {
1314 fNextEventAction
= new Action() {
1321 fNextEventAction
.setText(Messages
.TmfTimeGraphViewer_NextEventActionNameText
);
1322 fNextEventAction
.setToolTipText(Messages
.TmfTimeGraphViewer_NextEventActionToolTipText
);
1323 fNextEventAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_NEXT_EVENT
));
1326 return fNextEventAction
;
1330 * Get the previous event action.
1332 * @return The Action object
1334 public Action
getPreviousEventAction() {
1335 if (fPrevEventAction
== null) {
1336 fPrevEventAction
= new Action() {
1343 fPrevEventAction
.setText(Messages
.TmfTimeGraphViewer_PreviousEventActionNameText
);
1344 fPrevEventAction
.setToolTipText(Messages
.TmfTimeGraphViewer_PreviousEventActionToolTipText
);
1345 fPrevEventAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_PREV_EVENT
));
1348 return fPrevEventAction
;
1352 * Get the next item action.
1354 * @return The Action object
1356 public Action
getNextItemAction() {
1357 if (fNextItemAction
== null) {
1359 fNextItemAction
= new Action() {
1365 fNextItemAction
.setText(Messages
.TmfTimeGraphViewer_NextItemActionNameText
);
1366 fNextItemAction
.setToolTipText(Messages
.TmfTimeGraphViewer_NextItemActionToolTipText
);
1367 fNextItemAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_NEXT_ITEM
));
1369 return fNextItemAction
;
1373 * Get the previous item action.
1375 * @return The Action object
1377 public Action
getPreviousItemAction() {
1378 if (fPreviousItemAction
== null) {
1380 fPreviousItemAction
= new Action() {
1386 fPreviousItemAction
.setText(Messages
.TmfTimeGraphViewer_PreviousItemActionNameText
);
1387 fPreviousItemAction
.setToolTipText(Messages
.TmfTimeGraphViewer_PreviousItemActionToolTipText
);
1388 fPreviousItemAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_PREV_ITEM
));
1390 return fPreviousItemAction
;
1394 * Get the zoom in action
1396 * @return The Action object
1398 public Action
getZoomInAction() {
1399 if (fZoomInAction
== null) {
1400 fZoomInAction
= new Action() {
1406 fZoomInAction
.setText(Messages
.TmfTimeGraphViewer_ZoomInActionNameText
);
1407 fZoomInAction
.setToolTipText(Messages
.TmfTimeGraphViewer_ZoomInActionToolTipText
);
1408 fZoomInAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_ZOOM_IN_MENU
));
1410 return fZoomInAction
;
1414 * Get the zoom out action
1416 * @return The Action object
1418 public Action
getZoomOutAction() {
1419 if (fZoomOutAction
== null) {
1420 fZoomOutAction
= new Action() {
1426 fZoomOutAction
.setText(Messages
.TmfTimeGraphViewer_ZoomOutActionNameText
);
1427 fZoomOutAction
.setToolTipText(Messages
.TmfTimeGraphViewer_ZoomOutActionToolTipText
);
1428 fZoomOutAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_ZOOM_OUT_MENU
));
1430 return fZoomOutAction
;
1434 private void adjustVerticalScrollBar() {
1435 int topIndex
= fTimeGraphCtrl
.getTopIndex();
1436 int countPerPage
= fTimeGraphCtrl
.countPerPage();
1437 int expandedElementCount
= fTimeGraphCtrl
.getExpandedElementCount();
1438 if (topIndex
+ countPerPage
> expandedElementCount
) {
1439 fTimeGraphCtrl
.setTopIndex(Math
.max(0, expandedElementCount
- countPerPage
));
1442 int selection
= fTimeGraphCtrl
.getTopIndex();
1444 int max
= Math
.max(1, expandedElementCount
- 1);
1445 int thumb
= Math
.min(max
, Math
.max(1, countPerPage
- 1));
1447 int pageIncrement
= Math
.max(1, countPerPage
);
1448 fVerticalScrollBar
.setValues(selection
, min
, max
, thumb
, increment
, pageIncrement
);
1452 * @param listener a {@link MenuDetectListener}
1453 * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TimeGraphControl#addTimeGraphEntryMenuListener(org.eclipse.swt.events.MenuDetectListener)
1456 public void addTimeGraphEntryMenuListener(MenuDetectListener listener
) {
1457 fTimeGraphCtrl
.addTimeGraphEntryMenuListener(listener
);
1461 * @param listener a {@link MenuDetectListener}
1462 * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TimeGraphControl#removeTimeGraphEntryMenuListener(org.eclipse.swt.events.MenuDetectListener)
1465 public void removeTimeGraphEntryMenuListener(MenuDetectListener listener
) {
1466 fTimeGraphCtrl
.removeTimeGraphEntryMenuListener(listener
);
1470 * @param listener a {@link MenuDetectListener}
1471 * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TimeGraphControl#addTimeEventMenuListener(org.eclipse.swt.events.MenuDetectListener)
1474 public void addTimeEventMenuListener(MenuDetectListener listener
) {
1475 fTimeGraphCtrl
.addTimeEventMenuListener(listener
);
1479 * @param listener a {@link MenuDetectListener}
1480 * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TimeGraphControl#removeTimeEventMenuListener(org.eclipse.swt.events.MenuDetectListener)
1483 public void removeTimeEventMenuListener(MenuDetectListener listener
) {
1484 fTimeGraphCtrl
.removeTimeEventMenuListener(listener
);
1488 * @param filter The filter object to be attached to the view
1491 public void addFilter(ViewerFilter filter
) {
1492 fTimeGraphCtrl
.addFilter(filter
);
1497 * @param filter The filter object to be attached to the view
1500 public void removeFilter(ViewerFilter filter
) {
1501 fTimeGraphCtrl
.removeFilter(filter
);