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
.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
.ITimeDataProvider2
;
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 ITimeDataProvider2
, 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 ITimeGraphPresentationProvider fTimeGraphProvider
;
100 private List
<ITimeGraphSelectionListener
> fSelectionListeners
= new ArrayList
<ITimeGraphSelectionListener
>();
101 private List
<ITimeGraphTimeListener
> fTimeListeners
= new ArrayList
<ITimeGraphTimeListener
>();
102 private List
<ITimeGraphRangeListener
> fRangeListeners
= new ArrayList
<ITimeGraphRangeListener
>();
104 // Time format, using Epoch reference, Relative time format(default) or
106 private TimeFormat fTimeFormat
= TimeFormat
.RELATIVE
;
107 private int fBorderWidth
= 0;
108 private int fTimeScaleHeight
= DEFAULT_HEIGHT
;
110 private Action fResetScaleAction
;
111 private Action fShowLegendAction
;
112 private Action fNextEventAction
;
113 private Action fPrevEventAction
;
114 private Action fNextItemAction
;
115 private Action fPreviousItemAction
;
116 private Action fZoomInAction
;
117 private Action fZoomOutAction
;
118 private Action fHideArrowsAction
;
121 * Standard constructor
124 * The parent UI composite object
128 public TimeGraphViewer(Composite parent
, int style
) {
129 createDataViewer(parent
, style
);
133 * Sets the timegraph provider used by this timegraph viewer.
135 * @param timeGraphProvider
136 * the timegraph provider
138 public void setTimeGraphProvider(ITimeGraphPresentationProvider timeGraphProvider
) {
139 fTimeGraphProvider
= timeGraphProvider
;
140 fTimeGraphCtrl
.setTimeGraphProvider(timeGraphProvider
);
141 TimeGraphTooltipHandler toolTipHandler
= new TimeGraphTooltipHandler(fTimeGraphProvider
, this);
142 toolTipHandler
.activateHoverHelp(fTimeGraphCtrl
);
146 * Sets or clears the input for this time graph viewer. The input array
147 * should only contain top-level elements.
150 * The input of this time graph viewer, or <code>null</code> if
153 public void setInput(ITimeGraphEntry
[] input
) {
154 ITimeGraphEntry
[] realInput
= input
;
156 if (fTimeGraphCtrl
!= null) {
157 if (realInput
== null) {
158 realInput
= new ITimeGraphEntry
[0];
160 setTimeRange(realInput
);
161 fVerticalScrollBar
.setEnabled(true);
165 fSelectedEntry
= null;
166 refreshAllData(realInput
);
171 * Sets (or clears if null) the list of links to display on this combo
174 * the links to display in this time graph combo
177 public void setLinks(List
<ILinkEvent
> links
) {
178 if (fTimeGraphCtrl
!= null) {
179 fTimeGraphCtrl
.refreshArrows(links
);
186 public void refresh() {
187 setTimeRange(fTimeGraphCtrl
.getTraces());
188 fVerticalScrollBar
.setEnabled(true);
189 refreshAllData(fTimeGraphCtrl
.getTraces());
193 * Callback for when the control is moved
198 public void controlMoved(ControlEvent e
) {
202 * Callback for when the control is resized
207 public void controlResized(ControlEvent e
) {
212 * Handler for when the model is updated. Called from the display order in
216 * The traces in the model
221 * @param updateTimeBounds
222 * Should we updated the time bounds too
224 public void modelUpdate(ITimeGraphEntry
[] traces
, long start
,
225 long end
, boolean updateTimeBounds
) {
226 if (null != fTimeGraphCtrl
) {
227 updateInternalData(traces
, start
, end
);
228 if (updateTimeBounds
) {
229 fTimeRangeFixed
= true;
230 // set window to match limits
231 setStartFinishTime(fTime0Bound
, fTime1Bound
);
233 fTimeGraphCtrl
.redraw();
234 fTimeScaleCtrl
.redraw();
240 * @return The string representing the view type
242 protected String
getViewTypeStr() {
243 return "viewoption.threads"; //$NON-NLS-1$
246 int getMarginWidth() {
250 int getMarginHeight() {
255 fMinTimeInterval
= 1;
256 fSelectionBegin
= -1;
258 fNameWidth
= Utils
.loadIntOption(getPreferenceString("namewidth"), //$NON-NLS-1$
259 fNameWidthPref
, fMinNameWidth
, MAX_NAME_WIDTH
);
263 Utils
.saveIntOption(getPreferenceString("namewidth"), fNameWidth
); //$NON-NLS-1$
267 * Create a data viewer.
273 * @return The new data viewer
275 protected Control
createDataViewer(Composite parent
, int style
) {
277 fColorScheme
= new TimeGraphColorScheme();
278 fDataViewer
= new Composite(parent
, style
) {
280 public void redraw() {
281 fTimeScaleCtrl
.redraw();
282 fTimeGraphCtrl
.redraw();
286 GridLayout gl
= new GridLayout(2, false);
287 gl
.marginHeight
= fBorderWidth
;
289 gl
.verticalSpacing
= 0;
290 gl
.horizontalSpacing
= 0;
291 fDataViewer
.setLayout(gl
);
293 fTimeScaleCtrl
= new TimeGraphScale(fDataViewer
, fColorScheme
);
294 fTimeScaleCtrl
.setTimeProvider(this);
295 fTimeScaleCtrl
.setLayoutData(new GridData(SWT
.FILL
, SWT
.DEFAULT
, true, false));
296 fTimeScaleCtrl
.setHeight(fTimeScaleHeight
);
298 fVerticalScrollBar
= new Slider(fDataViewer
, SWT
.VERTICAL
| SWT
.NO_FOCUS
);
299 fVerticalScrollBar
.setLayoutData(new GridData(SWT
.DEFAULT
, SWT
.FILL
, false, true, 1, 2));
300 fVerticalScrollBar
.addSelectionListener(new SelectionAdapter() {
302 public void widgetSelected(SelectionEvent e
) {
303 setTopIndex(fVerticalScrollBar
.getSelection());
306 fVerticalScrollBar
.setEnabled(false);
308 fTimeGraphCtrl
= createTimeGraphControl(fDataViewer
, fColorScheme
);
310 fTimeGraphCtrl
.setTimeProvider(this);
311 fTimeGraphCtrl
.setTimeGraphScale(fTimeScaleCtrl
);
312 fTimeGraphCtrl
.addSelectionListener(this);
313 fTimeGraphCtrl
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true, 1, 2));
314 fTimeGraphCtrl
.addMouseWheelListener(new MouseWheelListener() {
316 public void mouseScrolled(MouseEvent e
) {
317 adjustVerticalScrollBar();
320 fTimeGraphCtrl
.addKeyListener(new KeyAdapter() {
322 public void keyPressed(KeyEvent e
) {
323 adjustVerticalScrollBar();
327 Composite filler
= new Composite(fDataViewer
, SWT
.NONE
);
328 GridData gd
= new GridData(SWT
.DEFAULT
, SWT
.DEFAULT
, false, false);
329 gd
.heightHint
= fTimeGraphCtrl
.getHorizontalBar().getSize().y
;
330 filler
.setLayoutData(gd
);
331 filler
.setLayout(new FillLayout());
333 fTimeGraphCtrl
.addControlListener(new ControlAdapter() {
335 public void controlResized(ControlEvent event
) {
340 fDataViewer
.update();
341 adjustVerticalScrollBar();
348 public void dispose() {
350 fTimeGraphCtrl
.dispose();
351 fDataViewer
.dispose();
352 fColorScheme
.dispose();
356 * Create a new time graph control.
359 * The parent composite
362 * @return The new TimeGraphControl
365 protected TimeGraphControl
createTimeGraphControl(Composite parent
,
366 TimeGraphColorScheme colors
) {
367 return new TimeGraphControl(parent
, colors
);
371 * Resize the controls
373 public void resizeControls() {
374 Rectangle r
= fDataViewer
.getClientArea();
380 if (fNameWidth
> width
- fMinNameWidth
) {
381 fNameWidth
= width
- fMinNameWidth
;
383 if (fNameWidth
< fMinNameWidth
) {
384 fNameWidth
= fMinNameWidth
;
386 adjustVerticalScrollBar();
390 * Try to set most convenient time range for display.
393 * The traces in the model
395 public void setTimeRange(ITimeGraphEntry traces
[]) {
398 for (int i
= 0; i
< traces
.length
; i
++) {
399 ITimeGraphEntry entry
= traces
[i
];
400 if (entry
.getEndTime() >= entry
.getStartTime() && entry
.getEndTime() > 0) {
401 if (fBeginTime
< 0 || entry
.getStartTime() < fBeginTime
) {
402 fBeginTime
= entry
.getStartTime();
404 if (entry
.getEndTime() > fEndTime
) {
405 fEndTime
= entry
.getEndTime();
410 if (fBeginTime
< 0) {
416 * Recalculate the time bounds
418 public void setTimeBounds() {
419 fTime0Bound
= fBeginTime
;
420 if (fTime0Bound
< 0) {
423 fTime1Bound
= fEndTime
;
424 if (!fTimeRangeFixed
) {
425 fTime0
= fTime0Bound
;
426 fTime1
= fTime1Bound
;
428 if (fTime1
- fTime0
< fMinTimeInterval
) {
429 fTime1
= Math
.min(fTime1Bound
, fTime0
+ fMinTimeInterval
);
438 void updateInternalData(ITimeGraphEntry
[] traces
, long start
, long end
) {
439 ITimeGraphEntry
[] realTraces
= traces
;
441 if (null == realTraces
) {
442 realTraces
= new ITimeGraphEntry
[0];
444 if ((start
== 0 && end
== 0) || start
< 0 || end
< 0) {
445 // Start and end time are unspecified and need to be determined from
446 // individual processes
447 setTimeRange(realTraces
);
453 refreshAllData(realTraces
);
459 private void refreshAllData(ITimeGraphEntry
[] traces
) {
461 if (fSelectionBegin
< fBeginTime
) {
462 fSelectionBegin
= fBeginTime
;
463 } else if (fSelectionBegin
> fEndTime
) {
464 fSelectionBegin
= fEndTime
;
466 if (fSelectionEnd
< fBeginTime
) {
467 fSelectionEnd
= fBeginTime
;
468 } else if (fSelectionEnd
> fEndTime
) {
469 fSelectionEnd
= fEndTime
;
471 fTimeGraphCtrl
.refreshData(traces
);
472 fTimeScaleCtrl
.redraw();
473 adjustVerticalScrollBar();
477 * Callback for when this view is focused
479 public void setFocus() {
480 if (null != fTimeGraphCtrl
) {
481 fTimeGraphCtrl
.setFocus();
486 * Get the current focus status of this view.
488 * @return If the view is currently focused, or not
490 public boolean isInFocus() {
491 return fTimeGraphCtrl
.isInFocus();
495 * Get the view's current selection
497 * @return The entry that is selected
499 public ITimeGraphEntry
getSelection() {
500 return fTimeGraphCtrl
.getSelectedTrace();
504 * Get the index of the current selection
508 public int getSelectionIndex() {
509 return fTimeGraphCtrl
.getSelectedIndex();
513 public long getTime0() {
518 public long getTime1() {
523 public long getMinTimeInterval() {
524 return fMinTimeInterval
;
528 public int getNameSpace() {
533 public void setNameSpace(int width
) {
535 int w
= fTimeGraphCtrl
.getClientArea().width
;
536 if (fNameWidth
> w
- MIN_NAME_WIDTH
) {
537 fNameWidth
= w
- MIN_NAME_WIDTH
;
539 if (fNameWidth
< MIN_NAME_WIDTH
) {
540 fNameWidth
= MIN_NAME_WIDTH
;
542 fTimeGraphCtrl
.adjustScrolls();
543 fTimeGraphCtrl
.redraw();
544 fTimeScaleCtrl
.redraw();
548 public int getTimeSpace() {
549 int w
= fTimeGraphCtrl
.getClientArea().width
;
550 return w
- fNameWidth
;
553 @SuppressWarnings("deprecation")
556 public long getSelectedTime() {
557 return fSelectionBegin
;
561 public long getBeginTime() {
566 public long getEndTime() {
571 public long getMaxTime() {
576 public long getMinTime() {
584 public long getSelectionBegin() {
585 return fSelectionBegin
;
592 public long getSelectionEnd() {
593 return fSelectionEnd
;
597 public void setStartFinishTimeNotify(long time0
, long time1
) {
598 setStartFinishTime(time0
, time1
);
599 notifyRangeListeners(time0
, time1
);
603 public void notifyStartFinishTime() {
604 notifyRangeListeners(fTime0
, fTime1
);
608 public void setStartFinishTime(long time0
, long time1
) {
610 if (fTime0
< fTime0Bound
) {
611 fTime0
= fTime0Bound
;
613 if (fTime0
> fTime1Bound
) {
614 fTime0
= fTime1Bound
;
617 if (fTime1
< fTime0Bound
) {
618 fTime1
= fTime0Bound
;
620 if (fTime1
> fTime1Bound
) {
621 fTime1
= fTime1Bound
;
623 if (fTime1
- fTime0
< fMinTimeInterval
) {
624 fTime1
= Math
.min(fTime1Bound
, fTime0
+ fMinTimeInterval
);
626 fTimeRangeFixed
= true;
627 fTimeGraphCtrl
.adjustScrolls();
628 fTimeGraphCtrl
.redraw();
629 fTimeScaleCtrl
.redraw();
633 * Set the time bounds to the provided values
636 * The start time of the window
640 public void setTimeBounds(long beginTime
, long endTime
) {
641 fBeginTime
= beginTime
;
643 fTime0Bound
= beginTime
;
644 fTime1Bound
= endTime
;
645 fTimeGraphCtrl
.adjustScrolls();
649 public void resetStartFinishTime() {
650 setStartFinishTime(fTime0Bound
, fTime1Bound
);
651 fTimeRangeFixed
= false;
655 public void setSelectedTimeNotify(long time
, boolean ensureVisible
) {
656 setSelectedTimeInt(time
, ensureVisible
, true);
660 public void setSelectedTime(long time
, boolean ensureVisible
) {
661 setSelectedTimeInt(time
, ensureVisible
, false);
668 public void setSelectionRangeNotify(long beginTime
, long endTime
) {
669 boolean changed
= (beginTime
!= fSelectionBegin
|| endTime
!= fSelectionEnd
);
670 fSelectionBegin
= Math
.max(fTime0Bound
, Math
.min(fTime1Bound
, beginTime
));
671 fSelectionEnd
= Math
.max(fTime0Bound
, Math
.min(fTime1Bound
, endTime
));
672 fTimeGraphCtrl
.redraw();
673 fTimeScaleCtrl
.redraw();
675 notifyTimeListeners(fSelectionBegin
, fSelectionEnd
);
683 public void setSelectionRange(long beginTime
, long endTime
) {
684 fSelectionBegin
= Math
.max(fTime0Bound
, Math
.min(fTime1Bound
, beginTime
));
685 fSelectionEnd
= Math
.max(fTime0Bound
, Math
.min(fTime1Bound
, endTime
));
686 fTimeGraphCtrl
.redraw();
687 fTimeScaleCtrl
.redraw();
690 private void setSelectedTimeInt(long time
, boolean ensureVisible
, boolean doNotify
) {
694 long timeSpace
= (fTime1
- fTime0
) / RECENTERING_MARGIN_FACTOR
;
695 long timeMid
= (fTime1
- fTime0
) / 2;
696 if (time
< fTime0
+ timeSpace
) {
697 long dt
= fTime0
- time
+ timeMid
;
700 } else if (time
> fTime1
- timeSpace
) {
701 long dt
= time
- fTime1
+ timeMid
;
705 if (fTime0
< fTime0Bound
) {
706 fTime1
= Math
.min(fTime1Bound
, fTime1
+ (fTime0Bound
- fTime0
));
707 fTime0
= fTime0Bound
;
708 } else if (fTime1
> fTime1Bound
) {
709 fTime0
= Math
.max(fTime0Bound
, fTime0
- (fTime1
- fTime1Bound
));
710 fTime1
= fTime1Bound
;
713 if (fTime1
- fTime0
< fMinTimeInterval
) {
714 fTime1
= Math
.min(fTime1Bound
, fTime0
+ fMinTimeInterval
);
716 fTimeGraphCtrl
.adjustScrolls();
717 fTimeGraphCtrl
.redraw();
718 fTimeScaleCtrl
.redraw();
720 boolean notifySelectedTime
= (time
!= fSelectionBegin
|| time
!= fSelectionEnd
);
721 fSelectionBegin
= time
;
722 fSelectionEnd
= time
;
724 if (doNotify
&& ((time0
!= fTime0
) || (time1
!= fTime1
))) {
725 notifyRangeListeners(fTime0
, fTime1
);
728 if (doNotify
&& notifySelectedTime
) {
729 notifyTimeListeners(fSelectionBegin
, fSelectionEnd
);
734 public void widgetDefaultSelected(SelectionEvent e
) {
735 if (fSelectedEntry
!= getSelection()) {
736 fSelectedEntry
= getSelection();
737 notifySelectionListeners(fSelectedEntry
);
742 public void widgetSelected(SelectionEvent e
) {
743 if (fSelectedEntry
!= getSelection()) {
744 fSelectedEntry
= getSelection();
745 notifySelectionListeners(fSelectedEntry
);
750 * Callback for when the next event is selected
752 public void selectNextEvent() {
753 fTimeGraphCtrl
.selectNextEvent();
754 adjustVerticalScrollBar();
758 * Callback for when the previous event is selected
760 public void selectPrevEvent() {
761 fTimeGraphCtrl
.selectPrevEvent();
762 adjustVerticalScrollBar();
766 * Callback for when the next item is selected
768 public void selectNextItem() {
769 fTimeGraphCtrl
.selectNextTrace();
770 adjustVerticalScrollBar();
774 * Callback for when the previous item is selected
776 public void selectPrevItem() {
777 fTimeGraphCtrl
.selectPrevTrace();
778 adjustVerticalScrollBar();
782 * Callback for the show legend action
784 public void showLegend() {
785 if (fDataViewer
== null || fDataViewer
.isDisposed()) {
789 TimeGraphLegend
.open(fDataViewer
.getShell(), fTimeGraphProvider
);
793 * Callback for the Zoom In action
795 public void zoomIn() {
796 fTimeGraphCtrl
.zoomIn();
800 * Callback for the Zoom Out action
802 public void zoomOut() {
803 fTimeGraphCtrl
.zoomOut();
806 private String
getPreferenceString(String string
) {
807 return getViewTypeStr() + "." + string
; //$NON-NLS-1$
811 * Add a selection listener
814 * The listener to add
816 public void addSelectionListener(ITimeGraphSelectionListener listener
) {
817 fSelectionListeners
.add(listener
);
821 * Remove a selection listener
824 * The listener to remove
826 public void removeSelectionListener(ITimeGraphSelectionListener listener
) {
827 fSelectionListeners
.remove(listener
);
830 private void notifySelectionListeners(ITimeGraphEntry selection
) {
831 TimeGraphSelectionEvent event
= new TimeGraphSelectionEvent(this, selection
);
833 for (ITimeGraphSelectionListener listener
: fSelectionListeners
) {
834 listener
.selectionChanged(event
);
839 * Add a time listener
842 * The listener to add
844 public void addTimeListener(ITimeGraphTimeListener listener
) {
845 fTimeListeners
.add(listener
);
849 * Remove a time listener
852 * The listener to remove
854 public void removeTimeListener(ITimeGraphTimeListener listener
) {
855 fTimeListeners
.remove(listener
);
858 private void notifyTimeListeners(long startTime
, long endTime
) {
859 TimeGraphTimeEvent event
= new TimeGraphTimeEvent(this, startTime
, endTime
);
861 for (ITimeGraphTimeListener listener
: fTimeListeners
) {
862 listener
.timeSelected(event
);
867 * Add a range listener
870 * The listener to add
872 public void addRangeListener(ITimeGraphRangeListener listener
) {
873 fRangeListeners
.add(listener
);
877 * Remove a range listener
880 * The listener to remove
882 public void removeRangeListener(ITimeGraphRangeListener listener
) {
883 fRangeListeners
.remove(listener
);
886 private void notifyRangeListeners(long startTime
, long endTime
) {
887 // Check if the time has actually changed from last notification
888 if (startTime
!= fTime0ExtSynch
|| endTime
!= fTime1ExtSynch
) {
889 // Notify Time Scale Selection Listeners
890 TimeGraphRangeUpdateEvent event
= new TimeGraphRangeUpdateEvent(this, startTime
, endTime
);
892 for (ITimeGraphRangeListener listener
: fRangeListeners
) {
893 listener
.timeRangeUpdated(event
);
896 // update external synch timers
897 updateExtSynchTimers();
902 * Callback to set a selected event in the view
905 * The event that was selected
907 * The source of this selection event
909 public void setSelectedEvent(ITimeEvent event
, Object source
) {
910 if (event
== null || source
== this) {
913 fSelectedEntry
= event
.getEntry();
914 fTimeGraphCtrl
.selectItem(fSelectedEntry
, false);
916 setSelectedTimeInt(event
.getTime(), true, true);
917 adjustVerticalScrollBar();
921 * Set the seeked time of a trace
924 * The trace that was seeked
928 * The source of this seek event
930 public void setSelectedTraceTime(ITimeGraphEntry trace
, long time
, Object source
) {
931 if (trace
== null || source
== this) {
934 fSelectedEntry
= trace
;
935 fTimeGraphCtrl
.selectItem(trace
, false);
937 setSelectedTimeInt(time
, true, true);
941 * Callback for a trace selection
944 * The trace that was selected
946 public void setSelection(ITimeGraphEntry trace
) {
947 fSelectedEntry
= trace
;
948 fTimeGraphCtrl
.selectItem(trace
, false);
949 adjustVerticalScrollBar();
953 * Callback for a time window selection
956 * Start time of the range
958 * End time of the range
960 * Source of the event
962 public void setSelectVisTimeWindow(long time0
, long time1
, Object source
) {
963 if (source
== this) {
967 setStartFinishTime(time0
, time1
);
969 // update notification time values since we are now in synch with the
970 // external application
971 updateExtSynchTimers();
975 * update the cache timers used to identify the need to send a time window
976 * update to external registered listeners
978 private void updateExtSynchTimers() {
979 // last time notification cache
980 fTime0ExtSynch
= fTime0
;
981 fTime1ExtSynch
= fTime1
;
988 public TimeFormat
getTimeFormat() {
994 * the {@link TimeFormat} used to display timestamps
997 public void setTimeFormat(TimeFormat tf
) {
998 this.fTimeFormat
= tf
;
1002 * Retrieve the border width
1006 public int getBorderWidth() {
1007 return fBorderWidth
;
1011 * Set the border width
1013 * @param borderWidth
1016 public void setBorderWidth(int borderWidth
) {
1017 if (borderWidth
> -1) {
1018 this.fBorderWidth
= borderWidth
;
1019 GridLayout gl
= (GridLayout
) fDataViewer
.getLayout();
1020 gl
.marginHeight
= borderWidth
;
1025 * Retrieve the height of the header
1027 * @return The height
1029 public int getHeaderHeight() {
1030 return fTimeScaleHeight
;
1034 * Set the height of the header
1036 * @param headerHeight
1039 public void setHeaderHeight(int headerHeight
) {
1040 if (headerHeight
> -1) {
1041 this.fTimeScaleHeight
= headerHeight
;
1042 fTimeScaleCtrl
.setHeight(headerHeight
);
1047 * Retrieve the height of an item row
1049 * @return The height
1051 public int getItemHeight() {
1052 if (fTimeGraphCtrl
!= null) {
1053 return fTimeGraphCtrl
.getItemHeight();
1059 * Set the height of an item row
1064 public void setItemHeight(int rowHeight
) {
1065 if (fTimeGraphCtrl
!= null) {
1066 fTimeGraphCtrl
.setItemHeight(rowHeight
);
1071 * Set the minimum item width
1076 public void setMinimumItemWidth(int width
) {
1077 if (fTimeGraphCtrl
!= null) {
1078 fTimeGraphCtrl
.setMinimumItemWidth(width
);
1083 * Set the width for the name column
1088 public void setNameWidthPref(int width
) {
1089 fNameWidthPref
= width
;
1097 * Retrieve the configure width for the name column
1103 public int getNameWidthPref(int width
) {
1104 return fNameWidthPref
;
1108 * Returns the primary control associated with this viewer.
1110 * @return the SWT control which displays this viewer's content
1112 public Control
getControl() {
1117 * Returns the time graph control associated with this viewer.
1119 * @return the time graph control
1122 public TimeGraphControl
getTimeGraphControl() {
1123 return fTimeGraphCtrl
;
1127 * Returns the time graph scale associated with this viewer.
1129 * @return the time graph scale
1132 public TimeGraphScale
getTimeGraphScale() {
1133 return fTimeScaleCtrl
;
1137 * Return the x coordinate corresponding to a time
1141 * @return the x coordinate corresponding to the time
1145 public int getXForTime(long time
) {
1146 return fTimeGraphCtrl
.getXForTime(time
);
1150 * Return the time corresponding to an x coordinate
1154 * @return the time corresponding to the x coordinate
1158 public long getTimeAtX(int x
) {
1159 return fTimeGraphCtrl
.getTimeAtX(x
);
1163 * Get the selection provider
1165 * @return the selection provider
1167 public ISelectionProvider
getSelectionProvider() {
1168 return fTimeGraphCtrl
;
1172 * Wait for the cursor
1175 * Wait indefinitely?
1177 public void waitCursor(boolean waitInd
) {
1178 fTimeGraphCtrl
.waitCursor(waitInd
);
1182 * Get the horizontal scroll bar object
1184 * @return The scroll bar
1186 public ScrollBar
getHorizontalBar() {
1187 return fTimeGraphCtrl
.getHorizontalBar();
1191 * Get the vertical scroll bar object
1193 * @return The scroll bar
1195 public Slider
getVerticalBar() {
1196 return fVerticalScrollBar
;
1200 * Set the given index as the top one
1203 * The index that will go to the top
1205 public void setTopIndex(int index
) {
1206 fTimeGraphCtrl
.setTopIndex(index
);
1207 adjustVerticalScrollBar();
1211 * Retrieve the current top index
1213 * @return The top index
1215 public int getTopIndex() {
1216 return fTimeGraphCtrl
.getTopIndex();
1220 * Set the expanded state of an entry
1223 * The entry to expand/collapse
1225 * True for expanded, false for collapsed
1227 public void setExpandedState(ITimeGraphEntry entry
, boolean expanded
) {
1228 fTimeGraphCtrl
.setExpandedState(entry
, expanded
);
1229 adjustVerticalScrollBar();
1233 * Collapses all nodes of the viewer's tree, starting with the root.
1237 public void collapseAll() {
1238 fTimeGraphCtrl
.collapseAll();
1239 adjustVerticalScrollBar();
1243 * Expands all nodes of the viewer's tree, starting with the root.
1247 public void expandAll() {
1248 fTimeGraphCtrl
.expandAll();
1249 adjustVerticalScrollBar();
1253 * Get the number of sub-elements when expanded
1255 * @return The element count
1257 public int getExpandedElementCount() {
1258 return fTimeGraphCtrl
.getExpandedElementCount();
1262 * Get the sub-elements
1264 * @return The array of entries that are below this one
1266 public ITimeGraphEntry
[] getExpandedElements() {
1267 return fTimeGraphCtrl
.getExpandedElements();
1271 * Add a tree listener
1274 * The listener to add
1276 public void addTreeListener(ITimeGraphTreeListener listener
) {
1277 fTimeGraphCtrl
.addTreeListener(listener
);
1281 * Remove a tree listener
1284 * The listener to remove
1286 public void removeTreeListener(ITimeGraphTreeListener listener
) {
1287 fTimeGraphCtrl
.removeTreeListener(listener
);
1291 * Get the reset scale action.
1293 * @return The Action object
1295 public Action
getResetScaleAction() {
1296 if (fResetScaleAction
== null) {
1298 fResetScaleAction
= new Action() {
1301 resetStartFinishTime();
1302 notifyStartFinishTime();
1305 fResetScaleAction
.setText(Messages
.TmfTimeGraphViewer_ResetScaleActionNameText
);
1306 fResetScaleAction
.setToolTipText(Messages
.TmfTimeGraphViewer_ResetScaleActionToolTipText
);
1307 fResetScaleAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_HOME_MENU
));
1309 return fResetScaleAction
;
1313 * Get the show legend action.
1315 * @return The Action object
1317 public Action
getShowLegendAction() {
1318 if (fShowLegendAction
== null) {
1320 fShowLegendAction
= new Action() {
1326 fShowLegendAction
.setText(Messages
.TmfTimeGraphViewer_LegendActionNameText
);
1327 fShowLegendAction
.setToolTipText(Messages
.TmfTimeGraphViewer_LegendActionToolTipText
);
1328 fShowLegendAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_SHOW_LEGEND
));
1331 return fShowLegendAction
;
1335 * Get the the next event action.
1337 * @return The action object
1339 public Action
getNextEventAction() {
1340 if (fNextEventAction
== null) {
1341 fNextEventAction
= new Action() {
1348 fNextEventAction
.setText(Messages
.TmfTimeGraphViewer_NextEventActionNameText
);
1349 fNextEventAction
.setToolTipText(Messages
.TmfTimeGraphViewer_NextEventActionToolTipText
);
1350 fNextEventAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_NEXT_EVENT
));
1353 return fNextEventAction
;
1357 * Get the previous event action.
1359 * @return The Action object
1361 public Action
getPreviousEventAction() {
1362 if (fPrevEventAction
== null) {
1363 fPrevEventAction
= new Action() {
1370 fPrevEventAction
.setText(Messages
.TmfTimeGraphViewer_PreviousEventActionNameText
);
1371 fPrevEventAction
.setToolTipText(Messages
.TmfTimeGraphViewer_PreviousEventActionToolTipText
);
1372 fPrevEventAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_PREV_EVENT
));
1375 return fPrevEventAction
;
1379 * Get the next item action.
1381 * @return The Action object
1383 public Action
getNextItemAction() {
1384 if (fNextItemAction
== null) {
1386 fNextItemAction
= new Action() {
1392 fNextItemAction
.setText(Messages
.TmfTimeGraphViewer_NextItemActionNameText
);
1393 fNextItemAction
.setToolTipText(Messages
.TmfTimeGraphViewer_NextItemActionToolTipText
);
1394 fNextItemAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_NEXT_ITEM
));
1396 return fNextItemAction
;
1400 * Get the previous item action.
1402 * @return The Action object
1404 public Action
getPreviousItemAction() {
1405 if (fPreviousItemAction
== null) {
1407 fPreviousItemAction
= new Action() {
1413 fPreviousItemAction
.setText(Messages
.TmfTimeGraphViewer_PreviousItemActionNameText
);
1414 fPreviousItemAction
.setToolTipText(Messages
.TmfTimeGraphViewer_PreviousItemActionToolTipText
);
1415 fPreviousItemAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_PREV_ITEM
));
1417 return fPreviousItemAction
;
1421 * Get the zoom in action
1423 * @return The Action object
1425 public Action
getZoomInAction() {
1426 if (fZoomInAction
== null) {
1427 fZoomInAction
= new Action() {
1433 fZoomInAction
.setText(Messages
.TmfTimeGraphViewer_ZoomInActionNameText
);
1434 fZoomInAction
.setToolTipText(Messages
.TmfTimeGraphViewer_ZoomInActionToolTipText
);
1435 fZoomInAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_ZOOM_IN_MENU
));
1437 return fZoomInAction
;
1441 * Get the zoom out action
1443 * @return The Action object
1445 public Action
getZoomOutAction() {
1446 if (fZoomOutAction
== null) {
1447 fZoomOutAction
= new Action() {
1453 fZoomOutAction
.setText(Messages
.TmfTimeGraphViewer_ZoomOutActionNameText
);
1454 fZoomOutAction
.setToolTipText(Messages
.TmfTimeGraphViewer_ZoomOutActionToolTipText
);
1455 fZoomOutAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_ZOOM_OUT_MENU
));
1457 return fZoomOutAction
;
1461 * Get the hide arrows action
1463 * @param dialogSettings
1464 * The dialog settings section where the state should be stored,
1467 * @return The Action object
1471 public Action
getHideArrowsAction(final IDialogSettings dialogSettings
) {
1472 if (fHideArrowsAction
== null) {
1473 fHideArrowsAction
= new Action(Messages
.TmfTimeGraphViewer_HideArrowsActionNameText
, IAction
.AS_CHECK_BOX
) {
1476 boolean hideArrows
= fHideArrowsAction
.isChecked();
1477 fTimeGraphCtrl
.hideArrows(hideArrows
);
1479 if (dialogSettings
!= null) {
1480 dialogSettings
.put(HIDE_ARROWS_KEY
, hideArrows
);
1484 fHideArrowsAction
.setToolTipText(Messages
.TmfTimeGraphViewer_HideArrowsActionToolTipText
);
1485 fHideArrowsAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_HIDE_ARROWS
));
1486 if (dialogSettings
!= null) {
1487 boolean hideArrows
= dialogSettings
.getBoolean(HIDE_ARROWS_KEY
);
1488 fTimeGraphCtrl
.hideArrows(hideArrows
);
1489 fHideArrowsAction
.setChecked(hideArrows
);
1492 return fHideArrowsAction
;
1495 private void adjustVerticalScrollBar() {
1496 int topIndex
= fTimeGraphCtrl
.getTopIndex();
1497 int countPerPage
= fTimeGraphCtrl
.countPerPage();
1498 int expandedElementCount
= fTimeGraphCtrl
.getExpandedElementCount();
1499 if (topIndex
+ countPerPage
> expandedElementCount
) {
1500 fTimeGraphCtrl
.setTopIndex(Math
.max(0, expandedElementCount
- countPerPage
));
1503 int selection
= fTimeGraphCtrl
.getTopIndex();
1505 int max
= Math
.max(1, expandedElementCount
- 1);
1506 int thumb
= Math
.min(max
, Math
.max(1, countPerPage
- 1));
1508 int pageIncrement
= Math
.max(1, countPerPage
);
1509 fVerticalScrollBar
.setValues(selection
, min
, max
, thumb
, increment
, pageIncrement
);
1514 * a {@link MenuDetectListener}
1515 * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TimeGraphControl#addTimeGraphEntryMenuListener(org.eclipse.swt.events.MenuDetectListener)
1518 public void addTimeGraphEntryMenuListener(MenuDetectListener listener
) {
1519 fTimeGraphCtrl
.addTimeGraphEntryMenuListener(listener
);
1524 * a {@link MenuDetectListener}
1525 * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TimeGraphControl#removeTimeGraphEntryMenuListener(org.eclipse.swt.events.MenuDetectListener)
1528 public void removeTimeGraphEntryMenuListener(MenuDetectListener listener
) {
1529 fTimeGraphCtrl
.removeTimeGraphEntryMenuListener(listener
);
1534 * a {@link MenuDetectListener}
1535 * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TimeGraphControl#addTimeEventMenuListener(org.eclipse.swt.events.MenuDetectListener)
1538 public void addTimeEventMenuListener(MenuDetectListener listener
) {
1539 fTimeGraphCtrl
.addTimeEventMenuListener(listener
);
1544 * a {@link MenuDetectListener}
1545 * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TimeGraphControl#removeTimeEventMenuListener(org.eclipse.swt.events.MenuDetectListener)
1548 public void removeTimeEventMenuListener(MenuDetectListener listener
) {
1549 fTimeGraphCtrl
.removeTimeEventMenuListener(listener
);
1554 * The filter object to be attached to the view
1557 public void addFilter(ViewerFilter filter
) {
1558 fTimeGraphCtrl
.addFilter(filter
);
1564 * The filter object to be attached to the view
1567 public void removeFilter(ViewerFilter filter
) {
1568 fTimeGraphCtrl
.removeFilter(filter
);