1 /*****************************************************************************
2 * Copyright (c) 2007, 2013 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
.viewers
.ISelectionProvider
;
24 import org
.eclipse
.jface
.viewers
.ViewerFilter
;
25 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.Activator
;
26 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.ITmfImageConstants
;
27 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.Messages
;
28 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.dialogs
.TimeGraphLegend
;
29 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.model
.ILinkEvent
;
30 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.model
.ITimeEvent
;
31 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.model
.ITimeGraphEntry
;
32 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.widgets
.ITimeDataProvider2
;
33 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.widgets
.TimeGraphColorScheme
;
34 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.widgets
.TimeGraphControl
;
35 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.widgets
.TimeGraphScale
;
36 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.widgets
.TimeGraphTooltipHandler
;
37 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.widgets
.Utils
;
38 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.widgets
.Utils
.TimeFormat
;
39 import org
.eclipse
.swt
.SWT
;
40 import org
.eclipse
.swt
.events
.ControlAdapter
;
41 import org
.eclipse
.swt
.events
.ControlEvent
;
42 import org
.eclipse
.swt
.events
.KeyAdapter
;
43 import org
.eclipse
.swt
.events
.KeyEvent
;
44 import org
.eclipse
.swt
.events
.MenuDetectListener
;
45 import org
.eclipse
.swt
.events
.MouseEvent
;
46 import org
.eclipse
.swt
.events
.MouseWheelListener
;
47 import org
.eclipse
.swt
.events
.SelectionAdapter
;
48 import org
.eclipse
.swt
.events
.SelectionEvent
;
49 import org
.eclipse
.swt
.events
.SelectionListener
;
50 import org
.eclipse
.swt
.graphics
.Rectangle
;
51 import org
.eclipse
.swt
.layout
.FillLayout
;
52 import org
.eclipse
.swt
.layout
.GridData
;
53 import org
.eclipse
.swt
.layout
.GridLayout
;
54 import org
.eclipse
.swt
.widgets
.Composite
;
55 import org
.eclipse
.swt
.widgets
.Control
;
56 import org
.eclipse
.swt
.widgets
.ScrollBar
;
57 import org
.eclipse
.swt
.widgets
.Slider
;
60 * Generic time graph viewer implementation
63 * @author Patrick Tasse, and others
65 public class TimeGraphViewer
implements ITimeDataProvider2
, SelectionListener
{
67 private static final int DEFAULT_NAME_WIDTH
= 200;
68 private static final int MIN_NAME_WIDTH
= 6;
69 private static final int MAX_NAME_WIDTH
= 1000;
70 private static final int DEFAULT_HEIGHT
= 22;
71 private static final long RECENTERING_MARGIN_FACTOR
= 50;
73 private long fMinTimeInterval
;
74 private ITimeGraphEntry fSelectedEntry
;
75 private long fBeginTime
;
76 private long fEndTime
;
79 private long fSelectionBegin
= 0;
80 private long fSelectionEnd
= 0;
81 private long fTime0Bound
;
82 private long fTime1Bound
;
83 private long fTime0ExtSynch
= 0;
84 private long fTime1ExtSynch
= 0;
85 private boolean fTimeRangeFixed
;
86 private int fNameWidthPref
= DEFAULT_NAME_WIDTH
;
87 private int fMinNameWidth
= MIN_NAME_WIDTH
;
88 private int fNameWidth
;
89 private Composite fDataViewer
;
91 private TimeGraphControl fTimeGraphCtrl
;
92 private TimeGraphScale fTimeScaleCtrl
;
93 private Slider fVerticalScrollBar
;
94 private TimeGraphColorScheme fColorScheme
;
95 private ITimeGraphPresentationProvider fTimeGraphProvider
;
97 private List
<ITimeGraphSelectionListener
> fSelectionListeners
= new ArrayList
<ITimeGraphSelectionListener
>();
98 private List
<ITimeGraphTimeListener
> fTimeListeners
= new ArrayList
<ITimeGraphTimeListener
>();
99 private List
<ITimeGraphRangeListener
> fRangeListeners
= new ArrayList
<ITimeGraphRangeListener
>();
101 // Time format, using Epoch reference, Relative time format(default) or Number
102 private TimeFormat fTimeFormat
= TimeFormat
.RELATIVE
;
103 private int fBorderWidth
= 0;
104 private int fTimeScaleHeight
= DEFAULT_HEIGHT
;
106 private Action fResetScaleAction
;
107 private Action fShowLegendAction
;
108 private Action fNextEventAction
;
109 private Action fPrevEventAction
;
110 private Action fNextItemAction
;
111 private Action fPreviousItemAction
;
112 private Action fZoomInAction
;
113 private Action fZoomOutAction
;
116 * Standard constructor
119 * The parent UI composite object
123 public TimeGraphViewer(Composite parent
, int style
) {
124 createDataViewer(parent
, style
);
128 * Sets the timegraph provider used by this timegraph viewer.
130 * @param timeGraphProvider the timegraph provider
132 public void setTimeGraphProvider(ITimeGraphPresentationProvider timeGraphProvider
) {
133 fTimeGraphProvider
= timeGraphProvider
;
134 fTimeGraphCtrl
.setTimeGraphProvider(timeGraphProvider
);
135 TimeGraphTooltipHandler toolTipHandler
= new TimeGraphTooltipHandler(fTimeGraphProvider
, this);
136 toolTipHandler
.activateHoverHelp(fTimeGraphCtrl
);
140 * Sets or clears the input for this time graph viewer.
141 * The input array should only contain top-level elements.
143 * @param input The input of this time graph viewer, or <code>null</code> if none
145 public void setInput(ITimeGraphEntry
[] input
) {
146 ITimeGraphEntry
[] realInput
= input
;
148 if (fTimeGraphCtrl
!= null) {
149 if (realInput
== null) {
150 realInput
= new ITimeGraphEntry
[0];
152 setTimeRange(realInput
);
153 fVerticalScrollBar
.setEnabled(true);
157 fSelectedEntry
= null;
158 refreshAllData(realInput
);
163 * Sets (or clears if null) the list of links to display on this combo
166 * the links to display in this time graph combo
169 public void setLinks(List
<ILinkEvent
> links
) {
170 if (fTimeGraphCtrl
!= null) {
171 fTimeGraphCtrl
.refreshArrows(links
);
178 public void refresh() {
179 setTimeRange(fTimeGraphCtrl
.getTraces());
180 fVerticalScrollBar
.setEnabled(true);
181 refreshAllData(fTimeGraphCtrl
.getTraces());
185 * Callback for when the control is moved
190 public void controlMoved(ControlEvent e
) {
194 * Callback for when the control is resized
199 public void controlResized(ControlEvent e
) {
204 * Handler for when the model is updated. Called from the display order in
208 * The traces in the model
213 * @param updateTimeBounds
214 * Should we updated the time bounds too
216 public void modelUpdate(ITimeGraphEntry
[] traces
, long start
,
217 long end
, boolean updateTimeBounds
) {
218 if (null != fTimeGraphCtrl
) {
219 updateInternalData(traces
, start
, end
);
220 if (updateTimeBounds
) {
221 fTimeRangeFixed
= true;
222 // set window to match limits
223 setStartFinishTime(fTime0Bound
, fTime1Bound
);
225 fTimeGraphCtrl
.redraw();
226 fTimeScaleCtrl
.redraw();
232 * @return The string representing the view type
234 protected String
getViewTypeStr() {
235 return "viewoption.threads"; //$NON-NLS-1$
238 int getMarginWidth() {
242 int getMarginHeight() {
247 fMinTimeInterval
= 1;
248 fSelectionBegin
= -1;
250 fNameWidth
= Utils
.loadIntOption(getPreferenceString("namewidth"), //$NON-NLS-1$
251 fNameWidthPref
, fMinNameWidth
, MAX_NAME_WIDTH
);
255 Utils
.saveIntOption(getPreferenceString("namewidth"), fNameWidth
); //$NON-NLS-1$
259 * Create a data viewer.
265 * @return The new data viewer
267 protected Control
createDataViewer(Composite parent
, int style
) {
269 fColorScheme
= new TimeGraphColorScheme();
270 fDataViewer
= new Composite(parent
, style
) {
272 public void redraw() {
273 fTimeScaleCtrl
.redraw();
274 fTimeGraphCtrl
.redraw();
278 GridLayout gl
= new GridLayout(2, false);
279 gl
.marginHeight
= fBorderWidth
;
281 gl
.verticalSpacing
= 0;
282 gl
.horizontalSpacing
= 0;
283 fDataViewer
.setLayout(gl
);
285 fTimeScaleCtrl
= new TimeGraphScale(fDataViewer
, fColorScheme
);
286 fTimeScaleCtrl
.setTimeProvider(this);
287 fTimeScaleCtrl
.setLayoutData(new GridData(SWT
.FILL
, SWT
.DEFAULT
, true, false));
288 fTimeScaleCtrl
.setHeight(fTimeScaleHeight
);
290 fVerticalScrollBar
= new Slider(fDataViewer
, SWT
.VERTICAL
| SWT
.NO_FOCUS
);
291 fVerticalScrollBar
.setLayoutData(new GridData(SWT
.DEFAULT
, SWT
.FILL
, false, true, 1, 2));
292 fVerticalScrollBar
.addSelectionListener(new SelectionAdapter() {
294 public void widgetSelected(SelectionEvent e
) {
295 setTopIndex(fVerticalScrollBar
.getSelection());
298 fVerticalScrollBar
.setEnabled(false);
300 fTimeGraphCtrl
= createTimeGraphControl(fDataViewer
, fColorScheme
);
302 fTimeGraphCtrl
.setTimeProvider(this);
303 fTimeGraphCtrl
.setTimeGraphScale(fTimeScaleCtrl
);
304 fTimeGraphCtrl
.addSelectionListener(this);
305 fTimeGraphCtrl
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true, 1, 2));
306 fTimeGraphCtrl
.addMouseWheelListener(new MouseWheelListener() {
308 public void mouseScrolled(MouseEvent e
) {
309 adjustVerticalScrollBar();
312 fTimeGraphCtrl
.addKeyListener(new KeyAdapter() {
314 public void keyPressed(KeyEvent e
) {
315 adjustVerticalScrollBar();
319 Composite filler
= new Composite(fDataViewer
, SWT
.NONE
);
320 GridData gd
= new GridData(SWT
.DEFAULT
, SWT
.DEFAULT
, false, false);
321 gd
.heightHint
= fTimeGraphCtrl
.getHorizontalBar().getSize().y
;
322 filler
.setLayoutData(gd
);
323 filler
.setLayout(new FillLayout());
325 fTimeGraphCtrl
.addControlListener(new ControlAdapter() {
327 public void controlResized(ControlEvent event
) {
332 fDataViewer
.update();
333 adjustVerticalScrollBar();
340 public void dispose() {
342 fTimeGraphCtrl
.dispose();
343 fDataViewer
.dispose();
344 fColorScheme
.dispose();
348 * Create a new time graph control.
351 * The parent composite
354 * @return The new TimeGraphControl
357 protected TimeGraphControl
createTimeGraphControl(Composite parent
,
358 TimeGraphColorScheme colors
) {
359 return new TimeGraphControl(parent
, colors
);
363 * Resize the controls
365 public void resizeControls() {
366 Rectangle r
= fDataViewer
.getClientArea();
372 if (fNameWidth
> width
- fMinNameWidth
) {
373 fNameWidth
= width
- fMinNameWidth
;
375 if (fNameWidth
< fMinNameWidth
) {
376 fNameWidth
= fMinNameWidth
;
378 adjustVerticalScrollBar();
382 * Try to set most convenient time range for display.
385 * The traces in the model
387 public void setTimeRange(ITimeGraphEntry traces
[]) {
390 for (int i
= 0; i
< traces
.length
; i
++) {
391 ITimeGraphEntry entry
= traces
[i
];
392 if (entry
.getEndTime() >= entry
.getStartTime() && entry
.getEndTime() > 0) {
393 if (fBeginTime
< 0 || entry
.getStartTime() < fBeginTime
) {
394 fBeginTime
= entry
.getStartTime();
396 if (entry
.getEndTime() > fEndTime
) {
397 fEndTime
= entry
.getEndTime();
402 if (fBeginTime
< 0) {
408 * Recalculate the time bounds
410 public void setTimeBounds() {
411 fTime0Bound
= fBeginTime
;
412 if (fTime0Bound
< 0) {
415 fTime1Bound
= fEndTime
;
416 if (!fTimeRangeFixed
) {
417 fTime0
= fTime0Bound
;
418 fTime1
= fTime1Bound
;
420 if (fTime1
- fTime0
< fMinTimeInterval
) {
421 fTime1
= Math
.min(fTime1Bound
, fTime0
+ fMinTimeInterval
);
430 void updateInternalData(ITimeGraphEntry
[] traces
, long start
, long end
) {
431 ITimeGraphEntry
[] realTraces
= traces
;
433 if (null == realTraces
) {
434 realTraces
= new ITimeGraphEntry
[0];
436 if ((start
== 0 && end
== 0) || start
< 0 || end
< 0) {
437 // Start and end time are unspecified and need to be determined from
438 // individual processes
439 setTimeRange(realTraces
);
445 refreshAllData(realTraces
);
451 private void refreshAllData(ITimeGraphEntry
[] traces
) {
453 if (fSelectionBegin
< fBeginTime
) {
454 fSelectionBegin
= fBeginTime
;
455 } else if (fSelectionBegin
> fEndTime
) {
456 fSelectionBegin
= fEndTime
;
458 if (fSelectionEnd
< fBeginTime
) {
459 fSelectionEnd
= fBeginTime
;
460 } else if (fSelectionEnd
> fEndTime
) {
461 fSelectionEnd
= fEndTime
;
463 fTimeGraphCtrl
.refreshData(traces
);
464 fTimeScaleCtrl
.redraw();
465 adjustVerticalScrollBar();
469 * Callback for when this view is focused
471 public void setFocus() {
472 if (null != fTimeGraphCtrl
) {
473 fTimeGraphCtrl
.setFocus();
478 * Get the current focus status of this view.
480 * @return If the view is currently focused, or not
482 public boolean isInFocus() {
483 return fTimeGraphCtrl
.isInFocus();
487 * Get the view's current selection
489 * @return The entry that is selected
491 public ITimeGraphEntry
getSelection() {
492 return fTimeGraphCtrl
.getSelectedTrace();
496 * Get the index of the current selection
500 public int getSelectionIndex() {
501 return fTimeGraphCtrl
.getSelectedIndex();
505 public long getTime0() {
510 public long getTime1() {
515 public long getMinTimeInterval() {
516 return fMinTimeInterval
;
520 public int getNameSpace() {
525 public void setNameSpace(int width
) {
527 int w
= fTimeGraphCtrl
.getClientArea().width
;
528 if (fNameWidth
> w
- MIN_NAME_WIDTH
) {
529 fNameWidth
= w
- MIN_NAME_WIDTH
;
531 if (fNameWidth
< MIN_NAME_WIDTH
) {
532 fNameWidth
= MIN_NAME_WIDTH
;
534 fTimeGraphCtrl
.adjustScrolls();
535 fTimeGraphCtrl
.redraw();
536 fTimeScaleCtrl
.redraw();
540 public int getTimeSpace() {
541 int w
= fTimeGraphCtrl
.getClientArea().width
;
542 return w
- fNameWidth
;
545 @SuppressWarnings("deprecation")
548 public long getSelectedTime() {
549 return fSelectionBegin
;
553 public long getBeginTime() {
558 public long getEndTime() {
563 public long getMaxTime() {
568 public long getMinTime() {
576 public long getSelectionBegin() {
577 return fSelectionBegin
;
584 public long getSelectionEnd() {
585 return fSelectionEnd
;
589 public void setStartFinishTimeNotify(long time0
, long time1
) {
590 setStartFinishTime(time0
, time1
);
591 notifyRangeListeners(time0
, time1
);
595 public void notifyStartFinishTime() {
596 notifyRangeListeners(fTime0
, fTime1
);
600 public void setStartFinishTime(long time0
, long time1
) {
602 if (fTime0
< fTime0Bound
) {
603 fTime0
= fTime0Bound
;
605 if (fTime0
> fTime1Bound
) {
606 fTime0
= fTime1Bound
;
609 if (fTime1
< fTime0Bound
) {
610 fTime1
= fTime0Bound
;
612 if (fTime1
> fTime1Bound
) {
613 fTime1
= fTime1Bound
;
615 if (fTime1
- fTime0
< fMinTimeInterval
) {
616 fTime1
= Math
.min(fTime1Bound
, fTime0
+ fMinTimeInterval
);
618 fTimeRangeFixed
= true;
619 fTimeGraphCtrl
.adjustScrolls();
620 fTimeGraphCtrl
.redraw();
621 fTimeScaleCtrl
.redraw();
625 * Set the time bounds to the provided values
628 * The start time of the window
632 public void setTimeBounds(long beginTime
, long endTime
) {
633 fBeginTime
= beginTime
;
635 fTime0Bound
= beginTime
;
636 fTime1Bound
= endTime
;
637 fTimeGraphCtrl
.adjustScrolls();
641 public void resetStartFinishTime() {
642 setStartFinishTime(fTime0Bound
, fTime1Bound
);
643 fTimeRangeFixed
= false;
647 public void setSelectedTimeNotify(long time
, boolean ensureVisible
) {
648 setSelectedTimeInt(time
, ensureVisible
, true);
652 public void setSelectedTime(long time
, boolean ensureVisible
) {
653 setSelectedTimeInt(time
, ensureVisible
, false);
660 public void setSelectionRangeNotify(long beginTime
, long endTime
) {
661 boolean changed
= (beginTime
!= fSelectionBegin
|| endTime
!= fSelectionEnd
);
662 fSelectionBegin
= Math
.max(fTime0Bound
, Math
.min(fTime1Bound
, beginTime
));
663 fSelectionEnd
= Math
.max(fTime0Bound
, Math
.min(fTime1Bound
, endTime
));
664 fTimeGraphCtrl
.redraw();
665 fTimeScaleCtrl
.redraw();
667 notifyTimeListeners(fSelectionBegin
, fSelectionEnd
);
675 public void setSelectionRange(long beginTime
, long endTime
) {
676 fSelectionBegin
= Math
.max(fTime0Bound
, Math
.min(fTime1Bound
, beginTime
));
677 fSelectionEnd
= Math
.max(fTime0Bound
, Math
.min(fTime1Bound
, endTime
));
678 fTimeGraphCtrl
.redraw();
679 fTimeScaleCtrl
.redraw();
682 private void setSelectedTimeInt(long time
, boolean ensureVisible
, boolean doNotify
) {
686 long timeSpace
= (fTime1
- fTime0
) / RECENTERING_MARGIN_FACTOR
;
687 long timeMid
= (fTime1
- fTime0
) / 2;
688 if (time
< fTime0
+ timeSpace
) {
689 long dt
= fTime0
- time
+ timeMid
;
692 } else if (time
> fTime1
- timeSpace
) {
693 long dt
= time
- fTime1
+ timeMid
;
697 if (fTime0
< fTime0Bound
) {
698 fTime1
= Math
.min(fTime1Bound
, fTime1
+ (fTime0Bound
- fTime0
));
699 fTime0
= fTime0Bound
;
700 } else if (fTime1
> fTime1Bound
) {
701 fTime0
= Math
.max(fTime0Bound
, fTime0
- (fTime1
- fTime1Bound
));
702 fTime1
= fTime1Bound
;
705 if (fTime1
- fTime0
< fMinTimeInterval
) {
706 fTime1
= Math
.min(fTime1Bound
, fTime0
+ fMinTimeInterval
);
708 fTimeGraphCtrl
.adjustScrolls();
709 fTimeGraphCtrl
.redraw();
710 fTimeScaleCtrl
.redraw();
712 boolean notifySelectedTime
= (time
!= fSelectionBegin
|| time
!= fSelectionEnd
);
713 fSelectionBegin
= time
;
714 fSelectionEnd
= time
;
716 if (doNotify
&& ((time0
!= fTime0
) || (time1
!= fTime1
))) {
717 notifyRangeListeners(fTime0
, fTime1
);
720 if (doNotify
&& notifySelectedTime
) {
721 notifyTimeListeners(fSelectionBegin
, fSelectionEnd
);
726 public void widgetDefaultSelected(SelectionEvent e
) {
727 if (fSelectedEntry
!= getSelection()) {
728 fSelectedEntry
= getSelection();
729 notifySelectionListeners(fSelectedEntry
);
734 public void widgetSelected(SelectionEvent e
) {
735 if (fSelectedEntry
!= getSelection()) {
736 fSelectedEntry
= getSelection();
737 notifySelectionListeners(fSelectedEntry
);
742 * Callback for when the next event is selected
744 public void selectNextEvent() {
745 fTimeGraphCtrl
.selectNextEvent();
746 adjustVerticalScrollBar();
750 * Callback for when the previous event is selected
752 public void selectPrevEvent() {
753 fTimeGraphCtrl
.selectPrevEvent();
754 adjustVerticalScrollBar();
758 * Callback for when the next item is selected
760 public void selectNextItem() {
761 fTimeGraphCtrl
.selectNextTrace();
762 adjustVerticalScrollBar();
766 * Callback for when the previous item is selected
768 public void selectPrevItem() {
769 fTimeGraphCtrl
.selectPrevTrace();
770 adjustVerticalScrollBar();
774 * Callback for the show legend action
776 public void showLegend() {
777 if (fDataViewer
== null || fDataViewer
.isDisposed()) {
781 TimeGraphLegend
.open(fDataViewer
.getShell(), fTimeGraphProvider
);
785 * Callback for the Zoom In action
787 public void zoomIn() {
788 fTimeGraphCtrl
.zoomIn();
792 * Callback for the Zoom Out action
794 public void zoomOut() {
795 fTimeGraphCtrl
.zoomOut();
798 private String
getPreferenceString(String string
) {
799 return getViewTypeStr() + "." + string
; //$NON-NLS-1$
803 * Add a selection listener
806 * The listener to add
808 public void addSelectionListener(ITimeGraphSelectionListener listener
) {
809 fSelectionListeners
.add(listener
);
813 * Remove a selection listener
816 * The listener to remove
818 public void removeSelectionListener(ITimeGraphSelectionListener listener
) {
819 fSelectionListeners
.remove(listener
);
822 private void notifySelectionListeners(ITimeGraphEntry selection
) {
823 TimeGraphSelectionEvent event
= new TimeGraphSelectionEvent(this, selection
);
825 for (ITimeGraphSelectionListener listener
: fSelectionListeners
) {
826 listener
.selectionChanged(event
);
831 * Add a time listener
834 * The listener to add
836 public void addTimeListener(ITimeGraphTimeListener listener
) {
837 fTimeListeners
.add(listener
);
841 * Remove a time listener
844 * The listener to remove
846 public void removeTimeListener(ITimeGraphTimeListener listener
) {
847 fTimeListeners
.remove(listener
);
850 private void notifyTimeListeners(long startTime
, long endTime
) {
851 TimeGraphTimeEvent event
= new TimeGraphTimeEvent(this, startTime
, endTime
);
853 for (ITimeGraphTimeListener listener
: fTimeListeners
) {
854 listener
.timeSelected(event
);
859 * Add a range listener
862 * The listener to add
864 public void addRangeListener(ITimeGraphRangeListener listener
) {
865 fRangeListeners
.add(listener
);
869 * Remove a range listener
872 * The listener to remove
874 public void removeRangeListener(ITimeGraphRangeListener listener
) {
875 fRangeListeners
.remove(listener
);
878 private void notifyRangeListeners(long startTime
, long endTime
) {
879 // Check if the time has actually changed from last notification
880 if (startTime
!= fTime0ExtSynch
|| endTime
!= fTime1ExtSynch
) {
881 // Notify Time Scale Selection Listeners
882 TimeGraphRangeUpdateEvent event
= new TimeGraphRangeUpdateEvent(this, startTime
, endTime
);
884 for (ITimeGraphRangeListener listener
: fRangeListeners
) {
885 listener
.timeRangeUpdated(event
);
888 // update external synch timers
889 updateExtSynchTimers();
894 * Callback to set a selected event in the view
897 * The event that was selected
899 * The source of this selection event
901 public void setSelectedEvent(ITimeEvent event
, Object source
) {
902 if (event
== null || source
== this) {
905 fSelectedEntry
= event
.getEntry();
906 fTimeGraphCtrl
.selectItem(fSelectedEntry
, false);
908 setSelectedTimeInt(event
.getTime(), true, true);
909 adjustVerticalScrollBar();
913 * Set the seeked time of a trace
916 * The trace that was seeked
920 * The source of this seek event
922 public void setSelectedTraceTime(ITimeGraphEntry trace
, long time
, Object source
) {
923 if (trace
== null || source
== this) {
926 fSelectedEntry
= trace
;
927 fTimeGraphCtrl
.selectItem(trace
, false);
929 setSelectedTimeInt(time
, true, true);
933 * Callback for a trace selection
936 * The trace that was selected
938 public void setSelection(ITimeGraphEntry trace
) {
939 fSelectedEntry
= trace
;
940 fTimeGraphCtrl
.selectItem(trace
, false);
941 adjustVerticalScrollBar();
945 * Callback for a time window selection
948 * Start time of the range
950 * End time of the range
952 * Source of the event
954 public void setSelectVisTimeWindow(long time0
, long time1
, Object source
) {
955 if (source
== this) {
959 setStartFinishTime(time0
, time1
);
961 // update notification time values since we are now in synch with the
962 // external application
963 updateExtSynchTimers();
967 * update the cache timers used to identify the need to send a time window
968 * update to external registered listeners
970 private void updateExtSynchTimers() {
971 // last time notification cache
972 fTime0ExtSynch
= fTime0
;
973 fTime1ExtSynch
= fTime1
;
980 public TimeFormat
getTimeFormat() {
985 * @param tf the {@link TimeFormat} used to display timestamps
988 public void setTimeFormat(TimeFormat tf
) {
989 this.fTimeFormat
= tf
;
993 * Retrieve the border width
997 public int getBorderWidth() {
1002 * Set the border width
1004 * @param borderWidth
1007 public void setBorderWidth(int borderWidth
) {
1008 if (borderWidth
> -1) {
1009 this.fBorderWidth
= borderWidth
;
1010 GridLayout gl
= (GridLayout
)fDataViewer
.getLayout();
1011 gl
.marginHeight
= borderWidth
;
1016 * Retrieve the height of the header
1018 * @return The height
1020 public int getHeaderHeight() {
1021 return fTimeScaleHeight
;
1025 * Set the height of the header
1027 * @param headerHeight
1030 public void setHeaderHeight(int headerHeight
) {
1031 if (headerHeight
> -1) {
1032 this.fTimeScaleHeight
= headerHeight
;
1033 fTimeScaleCtrl
.setHeight(headerHeight
);
1038 * Retrieve the height of an item row
1040 * @return The height
1042 public int getItemHeight() {
1043 if (fTimeGraphCtrl
!= null) {
1044 return fTimeGraphCtrl
.getItemHeight();
1050 * Set the height of an item row
1055 public void setItemHeight(int rowHeight
) {
1056 if (fTimeGraphCtrl
!= null) {
1057 fTimeGraphCtrl
.setItemHeight(rowHeight
);
1062 * Set the minimum item width
1067 public void setMinimumItemWidth(int width
) {
1068 if (fTimeGraphCtrl
!= null) {
1069 fTimeGraphCtrl
.setMinimumItemWidth(width
);
1074 * Set the width for the name column
1076 * @param width The width
1078 public void setNameWidthPref(int width
) {
1079 fNameWidthPref
= width
;
1087 * Retrieve the configure width for the name column
1093 public int getNameWidthPref(int width
) {
1094 return fNameWidthPref
;
1098 * Returns the primary control associated with this viewer.
1100 * @return the SWT control which displays this viewer's content
1102 public Control
getControl() {
1107 * Returns the time graph control associated with this viewer.
1109 * @return the time graph control
1112 public TimeGraphControl
getTimeGraphControl() {
1113 return fTimeGraphCtrl
;
1117 * Returns the time graph scale associated with this viewer.
1119 * @return the time graph scale
1122 public TimeGraphScale
getTimeGraphScale() {
1123 return fTimeScaleCtrl
;
1127 * Return the x coordinate corresponding to a time
1129 * @param time the time
1130 * @return the x coordinate corresponding to the time
1134 public int getXForTime(long time
) {
1135 return fTimeGraphCtrl
.getXForTime(time
);
1139 * Return the time corresponding to an x coordinate
1141 * @param x the x coordinate
1142 * @return the time corresponding to the x coordinate
1146 public long getTimeAtX(int x
) {
1147 return fTimeGraphCtrl
.getTimeAtX(x
);
1151 * Get the selection provider
1153 * @return the selection provider
1155 public ISelectionProvider
getSelectionProvider() {
1156 return fTimeGraphCtrl
;
1160 * Wait for the cursor
1163 * Wait indefinitely?
1165 public void waitCursor(boolean waitInd
) {
1166 fTimeGraphCtrl
.waitCursor(waitInd
);
1170 * Get the horizontal scroll bar object
1172 * @return The scroll bar
1174 public ScrollBar
getHorizontalBar() {
1175 return fTimeGraphCtrl
.getHorizontalBar();
1179 * Get the vertical scroll bar object
1181 * @return The scroll bar
1183 public Slider
getVerticalBar() {
1184 return fVerticalScrollBar
;
1188 * Set the given index as the top one
1191 * The index that will go to the top
1193 public void setTopIndex(int index
) {
1194 fTimeGraphCtrl
.setTopIndex(index
);
1195 adjustVerticalScrollBar();
1199 * Retrieve the current top index
1201 * @return The top index
1203 public int getTopIndex() {
1204 return fTimeGraphCtrl
.getTopIndex();
1208 * Set the expanded state of an entry
1211 * The entry to expand/collapse
1213 * True for expanded, false for collapsed
1215 public void setExpandedState(ITimeGraphEntry entry
, boolean expanded
) {
1216 fTimeGraphCtrl
.setExpandedState(entry
, expanded
);
1217 adjustVerticalScrollBar();
1221 * Collapses all nodes of the viewer's tree, starting with the root.
1225 public void collapseAll() {
1226 fTimeGraphCtrl
.collapseAll();
1227 adjustVerticalScrollBar();
1231 * Expands all nodes of the viewer's tree, starting with the root.
1235 public void expandAll() {
1236 fTimeGraphCtrl
.expandAll();
1237 adjustVerticalScrollBar();
1241 * Get the number of sub-elements when expanded
1243 * @return The element count
1245 public int getExpandedElementCount() {
1246 return fTimeGraphCtrl
.getExpandedElementCount();
1250 * Get the sub-elements
1252 * @return The array of entries that are below this one
1254 public ITimeGraphEntry
[] getExpandedElements() {
1255 return fTimeGraphCtrl
.getExpandedElements();
1259 * Add a tree listener
1262 * The listener to add
1264 public void addTreeListener(ITimeGraphTreeListener listener
) {
1265 fTimeGraphCtrl
.addTreeListener(listener
);
1269 * Remove a tree listener
1272 * The listener to remove
1274 public void removeTreeListener(ITimeGraphTreeListener listener
) {
1275 fTimeGraphCtrl
.removeTreeListener(listener
);
1279 * Get the reset scale action.
1281 * @return The Action object
1283 public Action
getResetScaleAction() {
1284 if (fResetScaleAction
== null) {
1286 fResetScaleAction
= new Action() {
1289 resetStartFinishTime();
1290 notifyStartFinishTime();
1293 fResetScaleAction
.setText(Messages
.TmfTimeGraphViewer_ResetScaleActionNameText
);
1294 fResetScaleAction
.setToolTipText(Messages
.TmfTimeGraphViewer_ResetScaleActionToolTipText
);
1295 fResetScaleAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_HOME_MENU
));
1297 return fResetScaleAction
;
1301 * Get the show legend action.
1303 * @return The Action object
1305 public Action
getShowLegendAction() {
1306 if (fShowLegendAction
== null) {
1308 fShowLegendAction
= new Action() {
1314 fShowLegendAction
.setText(Messages
.TmfTimeGraphViewer_LegendActionNameText
);
1315 fShowLegendAction
.setToolTipText(Messages
.TmfTimeGraphViewer_LegendActionToolTipText
);
1316 fShowLegendAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_SHOW_LEGEND
));
1319 return fShowLegendAction
;
1323 * Get the the next event action.
1325 * @return The action object
1327 public Action
getNextEventAction() {
1328 if (fNextEventAction
== null) {
1329 fNextEventAction
= new Action() {
1336 fNextEventAction
.setText(Messages
.TmfTimeGraphViewer_NextEventActionNameText
);
1337 fNextEventAction
.setToolTipText(Messages
.TmfTimeGraphViewer_NextEventActionToolTipText
);
1338 fNextEventAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_NEXT_EVENT
));
1341 return fNextEventAction
;
1345 * Get the previous event action.
1347 * @return The Action object
1349 public Action
getPreviousEventAction() {
1350 if (fPrevEventAction
== null) {
1351 fPrevEventAction
= new Action() {
1358 fPrevEventAction
.setText(Messages
.TmfTimeGraphViewer_PreviousEventActionNameText
);
1359 fPrevEventAction
.setToolTipText(Messages
.TmfTimeGraphViewer_PreviousEventActionToolTipText
);
1360 fPrevEventAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_PREV_EVENT
));
1363 return fPrevEventAction
;
1367 * Get the next item action.
1369 * @return The Action object
1371 public Action
getNextItemAction() {
1372 if (fNextItemAction
== null) {
1374 fNextItemAction
= new Action() {
1380 fNextItemAction
.setText(Messages
.TmfTimeGraphViewer_NextItemActionNameText
);
1381 fNextItemAction
.setToolTipText(Messages
.TmfTimeGraphViewer_NextItemActionToolTipText
);
1382 fNextItemAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_NEXT_ITEM
));
1384 return fNextItemAction
;
1388 * Get the previous item action.
1390 * @return The Action object
1392 public Action
getPreviousItemAction() {
1393 if (fPreviousItemAction
== null) {
1395 fPreviousItemAction
= new Action() {
1401 fPreviousItemAction
.setText(Messages
.TmfTimeGraphViewer_PreviousItemActionNameText
);
1402 fPreviousItemAction
.setToolTipText(Messages
.TmfTimeGraphViewer_PreviousItemActionToolTipText
);
1403 fPreviousItemAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_PREV_ITEM
));
1405 return fPreviousItemAction
;
1409 * Get the zoom in action
1411 * @return The Action object
1413 public Action
getZoomInAction() {
1414 if (fZoomInAction
== null) {
1415 fZoomInAction
= new Action() {
1421 fZoomInAction
.setText(Messages
.TmfTimeGraphViewer_ZoomInActionNameText
);
1422 fZoomInAction
.setToolTipText(Messages
.TmfTimeGraphViewer_ZoomInActionToolTipText
);
1423 fZoomInAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_ZOOM_IN_MENU
));
1425 return fZoomInAction
;
1429 * Get the zoom out action
1431 * @return The Action object
1433 public Action
getZoomOutAction() {
1434 if (fZoomOutAction
== null) {
1435 fZoomOutAction
= new Action() {
1441 fZoomOutAction
.setText(Messages
.TmfTimeGraphViewer_ZoomOutActionNameText
);
1442 fZoomOutAction
.setToolTipText(Messages
.TmfTimeGraphViewer_ZoomOutActionToolTipText
);
1443 fZoomOutAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_ZOOM_OUT_MENU
));
1445 return fZoomOutAction
;
1449 private void adjustVerticalScrollBar() {
1450 int topIndex
= fTimeGraphCtrl
.getTopIndex();
1451 int countPerPage
= fTimeGraphCtrl
.countPerPage();
1452 int expandedElementCount
= fTimeGraphCtrl
.getExpandedElementCount();
1453 if (topIndex
+ countPerPage
> expandedElementCount
) {
1454 fTimeGraphCtrl
.setTopIndex(Math
.max(0, expandedElementCount
- countPerPage
));
1457 int selection
= fTimeGraphCtrl
.getTopIndex();
1459 int max
= Math
.max(1, expandedElementCount
- 1);
1460 int thumb
= Math
.min(max
, Math
.max(1, countPerPage
- 1));
1462 int pageIncrement
= Math
.max(1, countPerPage
);
1463 fVerticalScrollBar
.setValues(selection
, min
, max
, thumb
, increment
, pageIncrement
);
1467 * @param listener a {@link MenuDetectListener}
1468 * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TimeGraphControl#addTimeGraphEntryMenuListener(org.eclipse.swt.events.MenuDetectListener)
1471 public void addTimeGraphEntryMenuListener(MenuDetectListener listener
) {
1472 fTimeGraphCtrl
.addTimeGraphEntryMenuListener(listener
);
1476 * @param listener a {@link MenuDetectListener}
1477 * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TimeGraphControl#removeTimeGraphEntryMenuListener(org.eclipse.swt.events.MenuDetectListener)
1480 public void removeTimeGraphEntryMenuListener(MenuDetectListener listener
) {
1481 fTimeGraphCtrl
.removeTimeGraphEntryMenuListener(listener
);
1485 * @param listener a {@link MenuDetectListener}
1486 * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TimeGraphControl#addTimeEventMenuListener(org.eclipse.swt.events.MenuDetectListener)
1489 public void addTimeEventMenuListener(MenuDetectListener listener
) {
1490 fTimeGraphCtrl
.addTimeEventMenuListener(listener
);
1494 * @param listener a {@link MenuDetectListener}
1495 * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TimeGraphControl#removeTimeEventMenuListener(org.eclipse.swt.events.MenuDetectListener)
1498 public void removeTimeEventMenuListener(MenuDetectListener listener
) {
1499 fTimeGraphCtrl
.removeTimeEventMenuListener(listener
);
1503 * @param filter The filter object to be attached to the view
1506 public void addFilter(ViewerFilter filter
) {
1507 fTimeGraphCtrl
.addFilter(filter
);
1512 * @param filter The filter object to be attached to the view
1515 public void removeFilter(ViewerFilter filter
) {
1516 fTimeGraphCtrl
.removeFilter(filter
);