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
<>();
101 private List
<ITimeGraphTimeListener
> fTimeListeners
= new ArrayList
<>();
102 private List
<ITimeGraphRangeListener
> fRangeListeners
= new ArrayList
<>();
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
;
119 private Action fFollowArrowFwdAction
;
120 private Action fFollowArrowBwdAction
;
123 * Standard constructor
126 * The parent UI composite object
130 public TimeGraphViewer(Composite parent
, int style
) {
131 createDataViewer(parent
, style
);
135 * Sets the timegraph provider used by this timegraph viewer.
137 * @param timeGraphProvider
138 * the timegraph provider
140 public void setTimeGraphProvider(ITimeGraphPresentationProvider timeGraphProvider
) {
141 fTimeGraphProvider
= timeGraphProvider
;
142 fTimeGraphCtrl
.setTimeGraphProvider(timeGraphProvider
);
143 TimeGraphTooltipHandler toolTipHandler
= new TimeGraphTooltipHandler(fTimeGraphProvider
, this);
144 toolTipHandler
.activateHoverHelp(fTimeGraphCtrl
);
148 * Sets or clears the input for this time graph viewer. The input array
149 * should only contain top-level elements.
152 * The input of this time graph viewer, or <code>null</code> if
155 public void setInput(ITimeGraphEntry
[] input
) {
156 ITimeGraphEntry
[] realInput
= input
;
158 if (fTimeGraphCtrl
!= null) {
159 if (realInput
== null) {
160 realInput
= new ITimeGraphEntry
[0];
162 setTimeRange(realInput
);
163 fVerticalScrollBar
.setEnabled(true);
167 fSelectedEntry
= null;
168 refreshAllData(realInput
);
173 * Sets (or clears if null) the list of links to display on this combo
176 * the links to display in this time graph combo
179 public void setLinks(List
<ILinkEvent
> links
) {
180 if (fTimeGraphCtrl
!= null) {
181 fTimeGraphCtrl
.refreshArrows(links
);
188 public void refresh() {
189 setTimeRange(fTimeGraphCtrl
.getTraces());
190 fVerticalScrollBar
.setEnabled(true);
191 refreshAllData(fTimeGraphCtrl
.getTraces());
195 * Callback for when the control is moved
200 public void controlMoved(ControlEvent e
) {
204 * Callback for when the control is resized
209 public void controlResized(ControlEvent e
) {
214 * Handler for when the model is updated. Called from the display order in
218 * The traces in the model
223 * @param updateTimeBounds
224 * Should we updated the time bounds too
226 public void modelUpdate(ITimeGraphEntry
[] traces
, long start
,
227 long end
, boolean updateTimeBounds
) {
228 if (null != fTimeGraphCtrl
) {
229 updateInternalData(traces
, start
, end
);
230 if (updateTimeBounds
) {
231 fTimeRangeFixed
= true;
232 // set window to match limits
233 setStartFinishTime(fTime0Bound
, fTime1Bound
);
235 fTimeGraphCtrl
.redraw();
236 fTimeScaleCtrl
.redraw();
242 * @return The string representing the view type
244 protected String
getViewTypeStr() {
245 return "viewoption.threads"; //$NON-NLS-1$
248 int getMarginWidth() {
252 int getMarginHeight() {
257 fMinTimeInterval
= 1;
258 fSelectionBegin
= -1;
260 fNameWidth
= Utils
.loadIntOption(getPreferenceString("namewidth"), //$NON-NLS-1$
261 fNameWidthPref
, fMinNameWidth
, MAX_NAME_WIDTH
);
265 Utils
.saveIntOption(getPreferenceString("namewidth"), fNameWidth
); //$NON-NLS-1$
269 * Create a data viewer.
275 * @return The new data viewer
277 protected Control
createDataViewer(Composite parent
, int style
) {
279 fColorScheme
= new TimeGraphColorScheme();
280 fDataViewer
= new Composite(parent
, style
) {
282 public void redraw() {
283 fTimeScaleCtrl
.redraw();
284 fTimeGraphCtrl
.redraw();
288 GridLayout gl
= new GridLayout(2, false);
289 gl
.marginHeight
= fBorderWidth
;
291 gl
.verticalSpacing
= 0;
292 gl
.horizontalSpacing
= 0;
293 fDataViewer
.setLayout(gl
);
295 fTimeScaleCtrl
= new TimeGraphScale(fDataViewer
, fColorScheme
);
296 fTimeScaleCtrl
.setTimeProvider(this);
297 fTimeScaleCtrl
.setLayoutData(new GridData(SWT
.FILL
, SWT
.DEFAULT
, true, false));
298 fTimeScaleCtrl
.setHeight(fTimeScaleHeight
);
300 fVerticalScrollBar
= new Slider(fDataViewer
, SWT
.VERTICAL
| SWT
.NO_FOCUS
);
301 fVerticalScrollBar
.setLayoutData(new GridData(SWT
.DEFAULT
, SWT
.FILL
, false, true, 1, 2));
302 fVerticalScrollBar
.addSelectionListener(new SelectionAdapter() {
304 public void widgetSelected(SelectionEvent e
) {
305 setTopIndex(fVerticalScrollBar
.getSelection());
308 fVerticalScrollBar
.setEnabled(false);
310 fTimeGraphCtrl
= createTimeGraphControl(fDataViewer
, fColorScheme
);
312 fTimeGraphCtrl
.setTimeProvider(this);
313 fTimeGraphCtrl
.setTimeGraphScale(fTimeScaleCtrl
);
314 fTimeGraphCtrl
.addSelectionListener(this);
315 fTimeGraphCtrl
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true, 1, 2));
316 fTimeGraphCtrl
.addMouseWheelListener(new MouseWheelListener() {
318 public void mouseScrolled(MouseEvent e
) {
319 adjustVerticalScrollBar();
322 fTimeGraphCtrl
.addKeyListener(new KeyAdapter() {
324 public void keyPressed(KeyEvent e
) {
325 adjustVerticalScrollBar();
329 Composite filler
= new Composite(fDataViewer
, SWT
.NONE
);
330 GridData gd
= new GridData(SWT
.DEFAULT
, SWT
.DEFAULT
, false, false);
331 gd
.heightHint
= fTimeGraphCtrl
.getHorizontalBar().getSize().y
;
332 filler
.setLayoutData(gd
);
333 filler
.setLayout(new FillLayout());
335 fTimeGraphCtrl
.addControlListener(new ControlAdapter() {
337 public void controlResized(ControlEvent event
) {
342 fDataViewer
.update();
343 adjustVerticalScrollBar();
350 public void dispose() {
352 fTimeGraphCtrl
.dispose();
353 fDataViewer
.dispose();
354 fColorScheme
.dispose();
358 * Create a new time graph control.
361 * The parent composite
364 * @return The new TimeGraphControl
367 protected TimeGraphControl
createTimeGraphControl(Composite parent
,
368 TimeGraphColorScheme colors
) {
369 return new TimeGraphControl(parent
, colors
);
373 * Resize the controls
375 public void resizeControls() {
376 Rectangle r
= fDataViewer
.getClientArea();
382 if (fNameWidth
> width
- fMinNameWidth
) {
383 fNameWidth
= width
- fMinNameWidth
;
385 if (fNameWidth
< fMinNameWidth
) {
386 fNameWidth
= fMinNameWidth
;
388 adjustVerticalScrollBar();
392 * Try to set most convenient time range for display.
395 * The traces in the model
397 public void setTimeRange(ITimeGraphEntry traces
[]) {
400 for (int i
= 0; i
< traces
.length
; i
++) {
401 ITimeGraphEntry entry
= traces
[i
];
402 if (entry
.getEndTime() >= entry
.getStartTime() && entry
.getEndTime() > 0) {
403 if (fBeginTime
< 0 || entry
.getStartTime() < fBeginTime
) {
404 fBeginTime
= entry
.getStartTime();
406 if (entry
.getEndTime() > fEndTime
) {
407 fEndTime
= entry
.getEndTime();
412 if (fBeginTime
< 0) {
418 * Recalculate the time bounds
420 public void setTimeBounds() {
421 fTime0Bound
= fBeginTime
;
422 if (fTime0Bound
< 0) {
425 fTime1Bound
= fEndTime
;
426 if (!fTimeRangeFixed
) {
427 fTime0
= fTime0Bound
;
428 fTime1
= fTime1Bound
;
430 fTime0
= Math
.max(fTime0Bound
, Math
.min(fTime0
, fTime1Bound
));
431 fTime1
= Math
.max(fTime0Bound
, Math
.min(fTime1
, fTime1Bound
));
432 if (fTime1
- fTime0
< fMinTimeInterval
) {
433 fTime1
= Math
.min(fTime1Bound
, fTime0
+ fMinTimeInterval
);
442 void updateInternalData(ITimeGraphEntry
[] traces
, long start
, long end
) {
443 ITimeGraphEntry
[] realTraces
= traces
;
445 if (null == realTraces
) {
446 realTraces
= new ITimeGraphEntry
[0];
448 if ((start
== 0 && end
== 0) || start
< 0 || end
< 0) {
449 // Start and end time are unspecified and need to be determined from
450 // individual processes
451 setTimeRange(realTraces
);
457 refreshAllData(realTraces
);
463 private void refreshAllData(ITimeGraphEntry
[] traces
) {
465 if (fSelectionBegin
< fBeginTime
) {
466 fSelectionBegin
= fBeginTime
;
467 } else if (fSelectionBegin
> fEndTime
) {
468 fSelectionBegin
= fEndTime
;
470 if (fSelectionEnd
< fBeginTime
) {
471 fSelectionEnd
= fBeginTime
;
472 } else if (fSelectionEnd
> fEndTime
) {
473 fSelectionEnd
= fEndTime
;
475 fTimeGraphCtrl
.refreshData(traces
);
476 fTimeScaleCtrl
.redraw();
477 adjustVerticalScrollBar();
481 * Callback for when this view is focused
483 public void setFocus() {
484 if (null != fTimeGraphCtrl
) {
485 fTimeGraphCtrl
.setFocus();
490 * Get the current focus status of this view.
492 * @return If the view is currently focused, or not
494 public boolean isInFocus() {
495 return fTimeGraphCtrl
.isInFocus();
499 * Get the view's current selection
501 * @return The entry that is selected
503 public ITimeGraphEntry
getSelection() {
504 return fTimeGraphCtrl
.getSelectedTrace();
508 * Get the index of the current selection
512 public int getSelectionIndex() {
513 return fTimeGraphCtrl
.getSelectedIndex();
517 public long getTime0() {
522 public long getTime1() {
527 public long getMinTimeInterval() {
528 return fMinTimeInterval
;
532 public int getNameSpace() {
537 public void setNameSpace(int width
) {
539 int w
= fTimeGraphCtrl
.getClientArea().width
;
540 if (fNameWidth
> w
- MIN_NAME_WIDTH
) {
541 fNameWidth
= w
- MIN_NAME_WIDTH
;
543 if (fNameWidth
< MIN_NAME_WIDTH
) {
544 fNameWidth
= MIN_NAME_WIDTH
;
546 fTimeGraphCtrl
.adjustScrolls();
547 fTimeGraphCtrl
.redraw();
548 fTimeScaleCtrl
.redraw();
552 public int getTimeSpace() {
553 int w
= fTimeGraphCtrl
.getClientArea().width
;
554 return w
- fNameWidth
;
557 @SuppressWarnings("deprecation")
560 public long getSelectedTime() {
561 return fSelectionBegin
;
565 public long getBeginTime() {
570 public long getEndTime() {
575 public long getMaxTime() {
580 public long getMinTime() {
588 public long getSelectionBegin() {
589 return fSelectionBegin
;
596 public long getSelectionEnd() {
597 return fSelectionEnd
;
601 public void setStartFinishTimeNotify(long time0
, long time1
) {
602 setStartFinishTime(time0
, time1
);
603 notifyRangeListeners(time0
, time1
);
607 public void notifyStartFinishTime() {
608 notifyRangeListeners(fTime0
, fTime1
);
612 public void setStartFinishTime(long time0
, long time1
) {
614 if (fTime0
< fTime0Bound
) {
615 fTime0
= fTime0Bound
;
617 if (fTime0
> fTime1Bound
) {
618 fTime0
= fTime1Bound
;
621 if (fTime1
< fTime0Bound
) {
622 fTime1
= fTime0Bound
;
624 if (fTime1
> fTime1Bound
) {
625 fTime1
= fTime1Bound
;
627 if (fTime1
- fTime0
< fMinTimeInterval
) {
628 fTime1
= Math
.min(fTime1Bound
, fTime0
+ fMinTimeInterval
);
630 fTimeRangeFixed
= true;
631 fTimeGraphCtrl
.adjustScrolls();
632 fTimeGraphCtrl
.redraw();
633 fTimeScaleCtrl
.redraw();
637 * Set the time bounds to the provided values
640 * The start time of the window
644 public void setTimeBounds(long beginTime
, long endTime
) {
645 if (endTime
>= beginTime
) {
646 fBeginTime
= beginTime
;
648 fTime0Bound
= beginTime
;
649 fTime1Bound
= endTime
;
656 fTimeGraphCtrl
.adjustScrolls();
660 public void resetStartFinishTime() {
661 setStartFinishTime(fTime0Bound
, fTime1Bound
);
662 fTimeRangeFixed
= false;
666 public void setSelectedTimeNotify(long time
, boolean ensureVisible
) {
667 setSelectedTimeInt(time
, ensureVisible
, true);
671 public void setSelectedTime(long time
, boolean ensureVisible
) {
672 setSelectedTimeInt(time
, ensureVisible
, false);
679 public void setSelectionRangeNotify(long beginTime
, long endTime
) {
680 boolean changed
= (beginTime
!= fSelectionBegin
|| endTime
!= fSelectionEnd
);
681 fSelectionBegin
= Math
.max(fTime0Bound
, Math
.min(fTime1Bound
, beginTime
));
682 fSelectionEnd
= Math
.max(fTime0Bound
, Math
.min(fTime1Bound
, endTime
));
683 fTimeGraphCtrl
.redraw();
684 fTimeScaleCtrl
.redraw();
686 notifyTimeListeners(fSelectionBegin
, fSelectionEnd
);
694 public void setSelectionRange(long beginTime
, long endTime
) {
695 fSelectionBegin
= Math
.max(fTime0Bound
, Math
.min(fTime1Bound
, beginTime
));
696 fSelectionEnd
= Math
.max(fTime0Bound
, Math
.min(fTime1Bound
, endTime
));
697 fTimeGraphCtrl
.redraw();
698 fTimeScaleCtrl
.redraw();
701 private void setSelectedTimeInt(long time
, boolean ensureVisible
, boolean doNotify
) {
705 long timeSpace
= (fTime1
- fTime0
) / RECENTERING_MARGIN_FACTOR
;
706 long timeMid
= (fTime1
- fTime0
) / 2;
707 if (time
< fTime0
+ timeSpace
) {
708 long dt
= fTime0
- time
+ timeMid
;
711 } else if (time
> fTime1
- timeSpace
) {
712 long dt
= time
- fTime1
+ timeMid
;
716 if (fTime0
< fTime0Bound
) {
717 fTime1
= Math
.min(fTime1Bound
, fTime1
+ (fTime0Bound
- fTime0
));
718 fTime0
= fTime0Bound
;
719 } else if (fTime1
> fTime1Bound
) {
720 fTime0
= Math
.max(fTime0Bound
, fTime0
- (fTime1
- fTime1Bound
));
721 fTime1
= fTime1Bound
;
724 if (fTime1
- fTime0
< fMinTimeInterval
) {
725 fTime1
= Math
.min(fTime1Bound
, fTime0
+ fMinTimeInterval
);
727 fTimeGraphCtrl
.adjustScrolls();
728 fTimeGraphCtrl
.redraw();
729 fTimeScaleCtrl
.redraw();
731 boolean notifySelectedTime
= (time
!= fSelectionBegin
|| time
!= fSelectionEnd
);
732 fSelectionBegin
= time
;
733 fSelectionEnd
= time
;
735 if (doNotify
&& ((time0
!= fTime0
) || (time1
!= fTime1
))) {
736 notifyRangeListeners(fTime0
, fTime1
);
739 if (doNotify
&& notifySelectedTime
) {
740 notifyTimeListeners(fSelectionBegin
, fSelectionEnd
);
745 public void widgetDefaultSelected(SelectionEvent e
) {
746 if (fSelectedEntry
!= getSelection()) {
747 fSelectedEntry
= getSelection();
748 notifySelectionListeners(fSelectedEntry
);
753 public void widgetSelected(SelectionEvent e
) {
754 if (fSelectedEntry
!= getSelection()) {
755 fSelectedEntry
= getSelection();
756 notifySelectionListeners(fSelectedEntry
);
761 * Callback for when the next event is selected
763 public void selectNextEvent() {
764 fTimeGraphCtrl
.selectNextEvent();
765 adjustVerticalScrollBar();
769 * Callback for when the previous event is selected
771 public void selectPrevEvent() {
772 fTimeGraphCtrl
.selectPrevEvent();
773 adjustVerticalScrollBar();
777 * Callback for when the next item is selected
779 public void selectNextItem() {
780 fTimeGraphCtrl
.selectNextTrace();
781 adjustVerticalScrollBar();
785 * Callback for when the previous item is selected
787 public void selectPrevItem() {
788 fTimeGraphCtrl
.selectPrevTrace();
789 adjustVerticalScrollBar();
793 * Callback for the show legend action
795 public void showLegend() {
796 if (fDataViewer
== null || fDataViewer
.isDisposed()) {
800 TimeGraphLegend
.open(fDataViewer
.getShell(), fTimeGraphProvider
);
804 * Callback for the Zoom In action
806 public void zoomIn() {
807 fTimeGraphCtrl
.zoomIn();
811 * Callback for the Zoom Out action
813 public void zoomOut() {
814 fTimeGraphCtrl
.zoomOut();
817 private String
getPreferenceString(String string
) {
818 return getViewTypeStr() + "." + string
; //$NON-NLS-1$
822 * Add a selection listener
825 * The listener to add
827 public void addSelectionListener(ITimeGraphSelectionListener listener
) {
828 fSelectionListeners
.add(listener
);
832 * Remove a selection listener
835 * The listener to remove
837 public void removeSelectionListener(ITimeGraphSelectionListener listener
) {
838 fSelectionListeners
.remove(listener
);
841 private void notifySelectionListeners(ITimeGraphEntry selection
) {
842 TimeGraphSelectionEvent event
= new TimeGraphSelectionEvent(this, selection
);
844 for (ITimeGraphSelectionListener listener
: fSelectionListeners
) {
845 listener
.selectionChanged(event
);
850 * Add a time listener
853 * The listener to add
855 public void addTimeListener(ITimeGraphTimeListener listener
) {
856 fTimeListeners
.add(listener
);
860 * Remove a time listener
863 * The listener to remove
865 public void removeTimeListener(ITimeGraphTimeListener listener
) {
866 fTimeListeners
.remove(listener
);
869 private void notifyTimeListeners(long startTime
, long endTime
) {
870 TimeGraphTimeEvent event
= new TimeGraphTimeEvent(this, startTime
, endTime
);
872 for (ITimeGraphTimeListener listener
: fTimeListeners
) {
873 listener
.timeSelected(event
);
878 * Add a range listener
881 * The listener to add
883 public void addRangeListener(ITimeGraphRangeListener listener
) {
884 fRangeListeners
.add(listener
);
888 * Remove a range listener
891 * The listener to remove
893 public void removeRangeListener(ITimeGraphRangeListener listener
) {
894 fRangeListeners
.remove(listener
);
897 private void notifyRangeListeners(long startTime
, long endTime
) {
898 // Check if the time has actually changed from last notification
899 if (startTime
!= fTime0ExtSynch
|| endTime
!= fTime1ExtSynch
) {
900 // Notify Time Scale Selection Listeners
901 TimeGraphRangeUpdateEvent event
= new TimeGraphRangeUpdateEvent(this, startTime
, endTime
);
903 for (ITimeGraphRangeListener listener
: fRangeListeners
) {
904 listener
.timeRangeUpdated(event
);
907 // update external synch timers
908 updateExtSynchTimers();
913 * Callback to set a selected event in the view
916 * The event that was selected
918 * The source of this selection event
920 public void setSelectedEvent(ITimeEvent event
, Object source
) {
921 if (event
== null || source
== this) {
924 fSelectedEntry
= event
.getEntry();
925 fTimeGraphCtrl
.selectItem(fSelectedEntry
, false);
927 setSelectedTimeInt(event
.getTime(), true, true);
928 adjustVerticalScrollBar();
932 * Set the seeked time of a trace
935 * The trace that was seeked
939 * The source of this seek event
941 public void setSelectedTraceTime(ITimeGraphEntry trace
, long time
, Object source
) {
942 if (trace
== null || source
== this) {
945 fSelectedEntry
= trace
;
946 fTimeGraphCtrl
.selectItem(trace
, false);
948 setSelectedTimeInt(time
, true, true);
952 * Callback for a trace selection
955 * The trace that was selected
957 public void setSelection(ITimeGraphEntry trace
) {
958 fSelectedEntry
= trace
;
959 fTimeGraphCtrl
.selectItem(trace
, false);
960 adjustVerticalScrollBar();
964 * Callback for a time window selection
967 * Start time of the range
969 * End time of the range
971 * Source of the event
973 public void setSelectVisTimeWindow(long time0
, long time1
, Object source
) {
974 if (source
== this) {
978 setStartFinishTime(time0
, time1
);
980 // update notification time values since we are now in synch with the
981 // external application
982 updateExtSynchTimers();
986 * update the cache timers used to identify the need to send a time window
987 * update to external registered listeners
989 private void updateExtSynchTimers() {
990 // last time notification cache
991 fTime0ExtSynch
= fTime0
;
992 fTime1ExtSynch
= fTime1
;
999 public TimeFormat
getTimeFormat() {
1005 * the {@link TimeFormat} used to display timestamps
1008 public void setTimeFormat(TimeFormat tf
) {
1009 this.fTimeFormat
= tf
;
1013 * Retrieve the border width
1017 public int getBorderWidth() {
1018 return fBorderWidth
;
1022 * Set the border width
1024 * @param borderWidth
1027 public void setBorderWidth(int borderWidth
) {
1028 if (borderWidth
> -1) {
1029 this.fBorderWidth
= borderWidth
;
1030 GridLayout gl
= (GridLayout
) fDataViewer
.getLayout();
1031 gl
.marginHeight
= borderWidth
;
1036 * Retrieve the height of the header
1038 * @return The height
1040 public int getHeaderHeight() {
1041 return fTimeScaleHeight
;
1045 * Set the height of the header
1047 * @param headerHeight
1050 public void setHeaderHeight(int headerHeight
) {
1051 if (headerHeight
> -1) {
1052 this.fTimeScaleHeight
= headerHeight
;
1053 fTimeScaleCtrl
.setHeight(headerHeight
);
1058 * Retrieve the height of an item row
1060 * @return The height
1062 public int getItemHeight() {
1063 if (fTimeGraphCtrl
!= null) {
1064 return fTimeGraphCtrl
.getItemHeight();
1070 * Set the height of an item row
1075 public void setItemHeight(int rowHeight
) {
1076 if (fTimeGraphCtrl
!= null) {
1077 fTimeGraphCtrl
.setItemHeight(rowHeight
);
1082 * Set the minimum item width
1087 public void setMinimumItemWidth(int width
) {
1088 if (fTimeGraphCtrl
!= null) {
1089 fTimeGraphCtrl
.setMinimumItemWidth(width
);
1094 * Set the width for the name column
1099 public void setNameWidthPref(int width
) {
1100 fNameWidthPref
= width
;
1108 * Retrieve the configure width for the name column
1114 public int getNameWidthPref(int width
) {
1115 return fNameWidthPref
;
1119 * Returns the primary control associated with this viewer.
1121 * @return the SWT control which displays this viewer's content
1123 public Control
getControl() {
1128 * Returns the time graph control associated with this viewer.
1130 * @return the time graph control
1133 public TimeGraphControl
getTimeGraphControl() {
1134 return fTimeGraphCtrl
;
1138 * Returns the time graph scale associated with this viewer.
1140 * @return the time graph scale
1143 public TimeGraphScale
getTimeGraphScale() {
1144 return fTimeScaleCtrl
;
1148 * Return the x coordinate corresponding to a time
1152 * @return the x coordinate corresponding to the time
1156 public int getXForTime(long time
) {
1157 return fTimeGraphCtrl
.getXForTime(time
);
1161 * Return the time corresponding to an x coordinate
1165 * @return the time corresponding to the x coordinate
1169 public long getTimeAtX(int x
) {
1170 return fTimeGraphCtrl
.getTimeAtX(x
);
1174 * Get the selection provider
1176 * @return the selection provider
1178 public ISelectionProvider
getSelectionProvider() {
1179 return fTimeGraphCtrl
;
1183 * Wait for the cursor
1186 * Wait indefinitely?
1188 public void waitCursor(boolean waitInd
) {
1189 fTimeGraphCtrl
.waitCursor(waitInd
);
1193 * Get the horizontal scroll bar object
1195 * @return The scroll bar
1197 public ScrollBar
getHorizontalBar() {
1198 return fTimeGraphCtrl
.getHorizontalBar();
1202 * Get the vertical scroll bar object
1204 * @return The scroll bar
1206 public Slider
getVerticalBar() {
1207 return fVerticalScrollBar
;
1211 * Set the given index as the top one
1214 * The index that will go to the top
1216 public void setTopIndex(int index
) {
1217 fTimeGraphCtrl
.setTopIndex(index
);
1218 adjustVerticalScrollBar();
1222 * Retrieve the current top index
1224 * @return The top index
1226 public int getTopIndex() {
1227 return fTimeGraphCtrl
.getTopIndex();
1231 * Set the expanded state of an entry
1234 * The entry to expand/collapse
1236 * True for expanded, false for collapsed
1238 public void setExpandedState(ITimeGraphEntry entry
, boolean expanded
) {
1239 fTimeGraphCtrl
.setExpandedState(entry
, expanded
);
1240 adjustVerticalScrollBar();
1244 * Collapses all nodes of the viewer's tree, starting with the root.
1248 public void collapseAll() {
1249 fTimeGraphCtrl
.collapseAll();
1250 adjustVerticalScrollBar();
1254 * Expands all nodes of the viewer's tree, starting with the root.
1258 public void expandAll() {
1259 fTimeGraphCtrl
.expandAll();
1260 adjustVerticalScrollBar();
1264 * Get the number of sub-elements when expanded
1266 * @return The element count
1268 public int getExpandedElementCount() {
1269 return fTimeGraphCtrl
.getExpandedElementCount();
1273 * Get the sub-elements
1275 * @return The array of entries that are below this one
1277 public ITimeGraphEntry
[] getExpandedElements() {
1278 return fTimeGraphCtrl
.getExpandedElements();
1282 * Add a tree listener
1285 * The listener to add
1287 public void addTreeListener(ITimeGraphTreeListener listener
) {
1288 fTimeGraphCtrl
.addTreeListener(listener
);
1292 * Remove a tree listener
1295 * The listener to remove
1297 public void removeTreeListener(ITimeGraphTreeListener listener
) {
1298 fTimeGraphCtrl
.removeTreeListener(listener
);
1302 * Get the reset scale action.
1304 * @return The Action object
1306 public Action
getResetScaleAction() {
1307 if (fResetScaleAction
== null) {
1309 fResetScaleAction
= new Action() {
1312 resetStartFinishTime();
1313 notifyStartFinishTime();
1316 fResetScaleAction
.setText(Messages
.TmfTimeGraphViewer_ResetScaleActionNameText
);
1317 fResetScaleAction
.setToolTipText(Messages
.TmfTimeGraphViewer_ResetScaleActionToolTipText
);
1318 fResetScaleAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_HOME_MENU
));
1320 return fResetScaleAction
;
1324 * Get the show legend action.
1326 * @return The Action object
1328 public Action
getShowLegendAction() {
1329 if (fShowLegendAction
== null) {
1331 fShowLegendAction
= new Action() {
1337 fShowLegendAction
.setText(Messages
.TmfTimeGraphViewer_LegendActionNameText
);
1338 fShowLegendAction
.setToolTipText(Messages
.TmfTimeGraphViewer_LegendActionToolTipText
);
1339 fShowLegendAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_SHOW_LEGEND
));
1342 return fShowLegendAction
;
1346 * Get the the next event action.
1348 * @return The action object
1350 public Action
getNextEventAction() {
1351 if (fNextEventAction
== null) {
1352 fNextEventAction
= new Action() {
1359 fNextEventAction
.setText(Messages
.TmfTimeGraphViewer_NextEventActionNameText
);
1360 fNextEventAction
.setToolTipText(Messages
.TmfTimeGraphViewer_NextEventActionToolTipText
);
1361 fNextEventAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_NEXT_EVENT
));
1364 return fNextEventAction
;
1368 * Get the previous event action.
1370 * @return The Action object
1372 public Action
getPreviousEventAction() {
1373 if (fPrevEventAction
== null) {
1374 fPrevEventAction
= new Action() {
1381 fPrevEventAction
.setText(Messages
.TmfTimeGraphViewer_PreviousEventActionNameText
);
1382 fPrevEventAction
.setToolTipText(Messages
.TmfTimeGraphViewer_PreviousEventActionToolTipText
);
1383 fPrevEventAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_PREV_EVENT
));
1386 return fPrevEventAction
;
1390 * Get the next item action.
1392 * @return The Action object
1394 public Action
getNextItemAction() {
1395 if (fNextItemAction
== null) {
1397 fNextItemAction
= new Action() {
1403 fNextItemAction
.setText(Messages
.TmfTimeGraphViewer_NextItemActionNameText
);
1404 fNextItemAction
.setToolTipText(Messages
.TmfTimeGraphViewer_NextItemActionToolTipText
);
1405 fNextItemAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_NEXT_ITEM
));
1407 return fNextItemAction
;
1411 * Get the previous item action.
1413 * @return The Action object
1415 public Action
getPreviousItemAction() {
1416 if (fPreviousItemAction
== null) {
1418 fPreviousItemAction
= new Action() {
1424 fPreviousItemAction
.setText(Messages
.TmfTimeGraphViewer_PreviousItemActionNameText
);
1425 fPreviousItemAction
.setToolTipText(Messages
.TmfTimeGraphViewer_PreviousItemActionToolTipText
);
1426 fPreviousItemAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_PREV_ITEM
));
1428 return fPreviousItemAction
;
1432 * Get the zoom in action
1434 * @return The Action object
1436 public Action
getZoomInAction() {
1437 if (fZoomInAction
== null) {
1438 fZoomInAction
= new Action() {
1444 fZoomInAction
.setText(Messages
.TmfTimeGraphViewer_ZoomInActionNameText
);
1445 fZoomInAction
.setToolTipText(Messages
.TmfTimeGraphViewer_ZoomInActionToolTipText
);
1446 fZoomInAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_ZOOM_IN_MENU
));
1448 return fZoomInAction
;
1452 * Get the zoom out action
1454 * @return The Action object
1456 public Action
getZoomOutAction() {
1457 if (fZoomOutAction
== null) {
1458 fZoomOutAction
= new Action() {
1464 fZoomOutAction
.setText(Messages
.TmfTimeGraphViewer_ZoomOutActionNameText
);
1465 fZoomOutAction
.setToolTipText(Messages
.TmfTimeGraphViewer_ZoomOutActionToolTipText
);
1466 fZoomOutAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_ZOOM_OUT_MENU
));
1468 return fZoomOutAction
;
1472 * Get the hide arrows action
1474 * @param dialogSettings
1475 * The dialog settings section where the state should be stored,
1478 * @return The Action object
1482 public Action
getHideArrowsAction(final IDialogSettings dialogSettings
) {
1483 if (fHideArrowsAction
== null) {
1484 fHideArrowsAction
= new Action(Messages
.TmfTimeGraphViewer_HideArrowsActionNameText
, IAction
.AS_CHECK_BOX
) {
1487 boolean hideArrows
= fHideArrowsAction
.isChecked();
1488 fTimeGraphCtrl
.hideArrows(hideArrows
);
1490 if (dialogSettings
!= null) {
1491 dialogSettings
.put(HIDE_ARROWS_KEY
, hideArrows
);
1493 if (fFollowArrowFwdAction
!= null) {
1494 fFollowArrowFwdAction
.setEnabled(!hideArrows
);
1496 if (fFollowArrowBwdAction
!= null) {
1497 fFollowArrowBwdAction
.setEnabled(!hideArrows
);
1501 fHideArrowsAction
.setToolTipText(Messages
.TmfTimeGraphViewer_HideArrowsActionToolTipText
);
1502 fHideArrowsAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_HIDE_ARROWS
));
1503 if (dialogSettings
!= null) {
1504 boolean hideArrows
= dialogSettings
.getBoolean(HIDE_ARROWS_KEY
);
1505 fTimeGraphCtrl
.hideArrows(hideArrows
);
1506 fHideArrowsAction
.setChecked(hideArrows
);
1507 if (fFollowArrowFwdAction
!= null) {
1508 fFollowArrowFwdAction
.setEnabled(!hideArrows
);
1510 if (fFollowArrowBwdAction
!= null) {
1511 fFollowArrowBwdAction
.setEnabled(!hideArrows
);
1515 return fHideArrowsAction
;
1519 * Get the follow arrow forward action.
1521 * @return The Action object
1525 public Action
getFollowArrowFwdAction() {
1526 if (fFollowArrowFwdAction
== null) {
1527 fFollowArrowFwdAction
= new Action() {
1530 fTimeGraphCtrl
.followArrowFwd();
1531 adjustVerticalScrollBar();
1534 fFollowArrowFwdAction
.setText(Messages
.TmfTimeGraphViewer_FollowArrowForwardActionNameText
);
1535 fFollowArrowFwdAction
.setToolTipText(Messages
.TmfTimeGraphViewer_FollowArrowForwardActionToolTipText
);
1536 fFollowArrowFwdAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_FOLLOW_ARROW_FORWARD
));
1537 if (fHideArrowsAction
!= null) {
1538 fFollowArrowFwdAction
.setEnabled(!fHideArrowsAction
.isChecked());
1541 return fFollowArrowFwdAction
;
1545 * Get the follow arrow backward action.
1547 * @return The Action object
1551 public Action
getFollowArrowBwdAction() {
1552 if (fFollowArrowBwdAction
== null) {
1553 fFollowArrowBwdAction
= new Action() {
1556 fTimeGraphCtrl
.followArrowBwd();
1557 adjustVerticalScrollBar();
1560 fFollowArrowBwdAction
.setText(Messages
.TmfTimeGraphViewer_FollowArrowBackwardActionNameText
);
1561 fFollowArrowBwdAction
.setToolTipText(Messages
.TmfTimeGraphViewer_FollowArrowBackwardActionToolTipText
);
1562 fFollowArrowBwdAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_FOLLOW_ARROW_BACKWARD
));
1563 if (fHideArrowsAction
!= null) {
1564 fFollowArrowBwdAction
.setEnabled(!fHideArrowsAction
.isChecked());
1567 return fFollowArrowBwdAction
;
1570 private void adjustVerticalScrollBar() {
1571 int topIndex
= fTimeGraphCtrl
.getTopIndex();
1572 int countPerPage
= fTimeGraphCtrl
.countPerPage();
1573 int expandedElementCount
= fTimeGraphCtrl
.getExpandedElementCount();
1574 if (topIndex
+ countPerPage
> expandedElementCount
) {
1575 fTimeGraphCtrl
.setTopIndex(Math
.max(0, expandedElementCount
- countPerPage
));
1578 int selection
= fTimeGraphCtrl
.getTopIndex();
1580 int max
= Math
.max(1, expandedElementCount
- 1);
1581 int thumb
= Math
.min(max
, Math
.max(1, countPerPage
- 1));
1583 int pageIncrement
= Math
.max(1, countPerPage
);
1584 fVerticalScrollBar
.setValues(selection
, min
, max
, thumb
, increment
, pageIncrement
);
1589 * a {@link MenuDetectListener}
1590 * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TimeGraphControl#addTimeGraphEntryMenuListener(org.eclipse.swt.events.MenuDetectListener)
1593 public void addTimeGraphEntryMenuListener(MenuDetectListener listener
) {
1594 fTimeGraphCtrl
.addTimeGraphEntryMenuListener(listener
);
1599 * a {@link MenuDetectListener}
1600 * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TimeGraphControl#removeTimeGraphEntryMenuListener(org.eclipse.swt.events.MenuDetectListener)
1603 public void removeTimeGraphEntryMenuListener(MenuDetectListener listener
) {
1604 fTimeGraphCtrl
.removeTimeGraphEntryMenuListener(listener
);
1609 * a {@link MenuDetectListener}
1610 * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TimeGraphControl#addTimeEventMenuListener(org.eclipse.swt.events.MenuDetectListener)
1613 public void addTimeEventMenuListener(MenuDetectListener listener
) {
1614 fTimeGraphCtrl
.addTimeEventMenuListener(listener
);
1619 * a {@link MenuDetectListener}
1620 * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TimeGraphControl#removeTimeEventMenuListener(org.eclipse.swt.events.MenuDetectListener)
1623 public void removeTimeEventMenuListener(MenuDetectListener listener
) {
1624 fTimeGraphCtrl
.removeTimeEventMenuListener(listener
);
1629 * The filter object to be attached to the view
1632 public void addFilter(ViewerFilter filter
) {
1633 fTimeGraphCtrl
.addFilter(filter
);
1639 * The filter object to be attached to the view
1642 public void removeFilter(ViewerFilter filter
) {
1643 fTimeGraphCtrl
.removeFilter(filter
);