1 /*****************************************************************************
2 * Copyright (c) 2007, 2015 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
.tracecompass
.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
.AbstractTreeViewer
;
26 import org
.eclipse
.jface
.viewers
.ISelectionProvider
;
27 import org
.eclipse
.jface
.viewers
.ViewerFilter
;
28 import org
.eclipse
.swt
.SWT
;
29 import org
.eclipse
.swt
.events
.ControlAdapter
;
30 import org
.eclipse
.swt
.events
.ControlEvent
;
31 import org
.eclipse
.swt
.events
.KeyAdapter
;
32 import org
.eclipse
.swt
.events
.KeyEvent
;
33 import org
.eclipse
.swt
.events
.MenuDetectListener
;
34 import org
.eclipse
.swt
.events
.MouseEvent
;
35 import org
.eclipse
.swt
.events
.MouseWheelListener
;
36 import org
.eclipse
.swt
.events
.SelectionAdapter
;
37 import org
.eclipse
.swt
.events
.SelectionEvent
;
38 import org
.eclipse
.swt
.events
.SelectionListener
;
39 import org
.eclipse
.swt
.graphics
.Rectangle
;
40 import org
.eclipse
.swt
.layout
.FillLayout
;
41 import org
.eclipse
.swt
.layout
.GridData
;
42 import org
.eclipse
.swt
.layout
.GridLayout
;
43 import org
.eclipse
.swt
.widgets
.Composite
;
44 import org
.eclipse
.swt
.widgets
.Control
;
45 import org
.eclipse
.swt
.widgets
.Display
;
46 import org
.eclipse
.swt
.widgets
.Event
;
47 import org
.eclipse
.swt
.widgets
.Listener
;
48 import org
.eclipse
.swt
.widgets
.Slider
;
49 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.Activator
;
50 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.ITmfImageConstants
;
51 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.Messages
;
52 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.dialogs
.TimeGraphLegend
;
53 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.ILinkEvent
;
54 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.ITimeEvent
;
55 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.ITimeGraphEntry
;
56 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.widgets
.ITimeDataProvider
;
57 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.widgets
.TimeDataProviderCyclesConverter
;
58 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.widgets
.TimeGraphColorScheme
;
59 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.widgets
.TimeGraphControl
;
60 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.widgets
.TimeGraphScale
;
61 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.widgets
.TimeGraphTooltipHandler
;
62 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.widgets
.Utils
;
63 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.widgets
.Utils
.TimeFormat
;
66 * Generic time graph viewer implementation
68 * @author Patrick Tasse, and others
70 public class TimeGraphViewer
implements ITimeDataProvider
, SelectionListener
{
72 /** Constant indicating that all levels of the time graph should be expanded */
73 public static final int ALL_LEVELS
= AbstractTreeViewer
.ALL_LEVELS
;
75 private static final int DEFAULT_NAME_WIDTH
= 200;
76 private static final int MIN_NAME_WIDTH
= 6;
77 private static final int MAX_NAME_WIDTH
= 1000;
78 private static final int DEFAULT_HEIGHT
= 22;
79 private static final long RECENTERING_MARGIN_FACTOR
= 50;
80 private static final String HIDE_ARROWS_KEY
= "hide.arrows"; //$NON-NLS-1$
81 private static final long DEFAULT_FREQUENCY
= 1000000000L;
82 private static final int H_SCROLLBAR_MAX
= Integer
.MAX_VALUE
- 1;
84 private long fMinTimeInterval
;
85 private ITimeGraphEntry fSelectedEntry
;
86 private long fBeginTime
= SWT
.DEFAULT
; // The user-specified bounds start time
87 private long fEndTime
= SWT
.DEFAULT
; // The user-specified bounds end time
88 private long fTime0
= SWT
.DEFAULT
; // The current window start time
89 private long fTime1
= SWT
.DEFAULT
; // The current window end time
90 private long fSelectionBegin
= SWT
.DEFAULT
;
91 private long fSelectionEnd
= SWT
.DEFAULT
;
92 private long fTime0Bound
= SWT
.DEFAULT
; // The bounds start time
93 private long fTime1Bound
= SWT
.DEFAULT
; // The bounds end time
94 private long fTime0ExtSynch
= SWT
.DEFAULT
;
95 private long fTime1ExtSynch
= SWT
.DEFAULT
;
96 private boolean fTimeRangeFixed
;
97 private int fNameWidthPref
= DEFAULT_NAME_WIDTH
;
98 private int fMinNameWidth
= MIN_NAME_WIDTH
;
99 private int fNameWidth
;
100 private Composite fDataViewer
;
102 private TimeGraphControl fTimeGraphCtrl
;
103 private TimeGraphScale fTimeScaleCtrl
;
104 private Slider fHorizontalScrollBar
;
105 private Slider fVerticalScrollBar
;
106 private TimeGraphColorScheme fColorScheme
;
107 private Object fInputElement
;
108 private ITimeGraphContentProvider fTimeGraphContentProvider
;
109 private ITimeGraphPresentationProvider fTimeGraphProvider
;
110 private ITimeDataProvider fTimeDataProvider
= this;
111 private TimeGraphTooltipHandler fToolTipHandler
;
113 private List
<ITimeGraphSelectionListener
> fSelectionListeners
= new ArrayList
<>();
114 private List
<ITimeGraphTimeListener
> fTimeListeners
= new ArrayList
<>();
115 private List
<ITimeGraphRangeListener
> fRangeListeners
= new ArrayList
<>();
117 // Time format, using Epoch reference, Relative time format(default),
119 private TimeFormat fTimeFormat
= TimeFormat
.RELATIVE
;
120 // Clock frequency to use for Cycles time format
121 private long fClockFrequency
= DEFAULT_FREQUENCY
;
122 private int fBorderWidth
= 0;
123 private int fTimeScaleHeight
= DEFAULT_HEIGHT
;
125 private Action fResetScaleAction
;
126 private Action fShowLegendAction
;
127 private Action fNextEventAction
;
128 private Action fPrevEventAction
;
129 private Action fNextItemAction
;
130 private Action fPreviousItemAction
;
131 private Action fZoomInAction
;
132 private Action fZoomOutAction
;
133 private Action fHideArrowsAction
;
134 private Action fFollowArrowFwdAction
;
135 private Action fFollowArrowBwdAction
;
137 private ListenerNotifier fListenerNotifier
;
138 private final Object fListenerNotifierLock
= new Object();
140 private class ListenerNotifier
extends Thread
{
141 private static final long DELAY
= 400L;
142 private static final long POLLING_INTERVAL
= 10L;
143 private long fLastUpdateTime
= Long
.MAX_VALUE
;
144 private boolean fSelectionChanged
= false;
145 private boolean fTimeRangeUpdated
= false;
146 private boolean fTimeSelected
= false;
150 while ((System
.currentTimeMillis() - fLastUpdateTime
) < DELAY
) {
152 Thread
.sleep(POLLING_INTERVAL
);
153 } catch (Exception e
) {
157 synchronized (fListenerNotifierLock
) {
158 fListenerNotifier
= null;
160 if (!isInterrupted()) {
161 Display
.getDefault().asyncExec(new Runnable() {
164 if (fDataViewer
.isDisposed()) {
167 if (fSelectionChanged
) {
168 fireSelectionChanged(fSelectedEntry
);
170 if (fTimeRangeUpdated
) {
171 fireTimeRangeUpdated(fTime0
, fTime1
);
174 fireTimeSelected(fSelectionBegin
, fSelectionEnd
);
181 public void selectionChanged() {
182 fSelectionChanged
= true;
183 fLastUpdateTime
= System
.currentTimeMillis();
186 public void timeRangeUpdated() {
187 fTimeRangeUpdated
= true;
188 fLastUpdateTime
= System
.currentTimeMillis();
191 public void timeSelected() {
192 fTimeSelected
= true;
193 fLastUpdateTime
= System
.currentTimeMillis();
198 * Standard constructor.
200 * The default timegraph content provider accepts an ITimeGraphEntry[] as input element.
203 * The parent UI composite object
207 public TimeGraphViewer(Composite parent
, int style
) {
208 createDataViewer(parent
, style
);
209 fTimeGraphContentProvider
= new ITimeGraphContentProvider() {
211 public ITimeGraphEntry
[] getElements(Object inputElement
) {
212 if (inputElement
instanceof ITimeGraphEntry
[]) {
213 return (ITimeGraphEntry
[]) inputElement
;
215 return new ITimeGraphEntry
[0];
221 * Sets the timegraph content provider used by this timegraph viewer.
223 * @param timeGraphContentProvider
224 * the timegraph content provider
226 public void setTimeGraphContentProvider(ITimeGraphContentProvider timeGraphContentProvider
) {
227 fTimeGraphContentProvider
= timeGraphContentProvider
;
231 * Gets the timegraph content provider used by this timegraph viewer.
233 * @return the timegraph content provider
235 public ITimeGraphContentProvider
getTimeGraphContentProvider() {
236 return fTimeGraphContentProvider
;
240 * Sets the timegraph presentation provider used by this timegraph viewer.
242 * @param timeGraphProvider
243 * the timegraph provider
245 public void setTimeGraphProvider(ITimeGraphPresentationProvider timeGraphProvider
) {
246 fTimeGraphProvider
= timeGraphProvider
;
247 fTimeGraphCtrl
.setTimeGraphProvider(timeGraphProvider
);
248 fToolTipHandler
= new TimeGraphTooltipHandler(fTimeGraphProvider
, fTimeDataProvider
);
249 fToolTipHandler
.activateHoverHelp(fTimeGraphCtrl
);
253 * Sets or clears the input for this time graph viewer.
255 * @param inputElement
256 * The input of this time graph viewer, or <code>null</code> if
259 public void setInput(Object inputElement
) {
260 fInputElement
= inputElement
;
261 ITimeGraphEntry
[] input
= fTimeGraphContentProvider
.getElements(inputElement
);
263 if (fTimeGraphCtrl
!= null) {
266 fSelectionBegin
= SWT
.DEFAULT
;
267 fSelectionEnd
= SWT
.DEFAULT
;
268 fSelectedEntry
= null;
269 refreshAllData(input
);
274 * Gets the input for this time graph viewer.
276 * @return The input of this time graph viewer, or <code>null</code> if none
278 public Object
getInput() {
279 return fInputElement
;
283 * Sets (or clears if null) the list of links to display on this combo
286 * the links to display in this time graph combo
288 public void setLinks(List
<ILinkEvent
> links
) {
289 if (fTimeGraphCtrl
!= null) {
290 fTimeGraphCtrl
.refreshArrows(links
);
297 public void refresh() {
298 ITimeGraphEntry
[] input
= fTimeGraphContentProvider
.getElements(fInputElement
);
300 refreshAllData(input
);
304 * Callback for when the control is moved
309 public void controlMoved(ControlEvent e
) {
313 * Callback for when the control is resized
318 public void controlResized(ControlEvent e
) {
323 * @return The string representing the view type
325 protected String
getViewTypeStr() {
326 return "viewoption.threads"; //$NON-NLS-1$
329 int getMarginWidth() {
333 int getMarginHeight() {
338 fMinTimeInterval
= 1;
339 fSelectionBegin
= SWT
.DEFAULT
;
340 fSelectionEnd
= SWT
.DEFAULT
;
341 fNameWidth
= Utils
.loadIntOption(getPreferenceString("namewidth"), //$NON-NLS-1$
342 fNameWidthPref
, fMinNameWidth
, MAX_NAME_WIDTH
);
346 Utils
.saveIntOption(getPreferenceString("namewidth"), fNameWidth
); //$NON-NLS-1$
350 * Create a data viewer.
356 * @return The new data viewer
358 protected Control
createDataViewer(Composite parent
, int style
) {
360 fColorScheme
= new TimeGraphColorScheme();
361 fDataViewer
= new Composite(parent
, style
) {
363 public void redraw() {
364 fTimeScaleCtrl
.redraw();
365 fTimeGraphCtrl
.redraw();
369 GridLayout gl
= new GridLayout(2, false);
370 gl
.marginHeight
= fBorderWidth
;
372 gl
.verticalSpacing
= 0;
373 gl
.horizontalSpacing
= 0;
374 fDataViewer
.setLayout(gl
);
376 fTimeScaleCtrl
= new TimeGraphScale(fDataViewer
, fColorScheme
);
377 fTimeScaleCtrl
.setTimeProvider(fTimeDataProvider
);
378 fTimeScaleCtrl
.setLayoutData(new GridData(SWT
.FILL
, SWT
.DEFAULT
, true, false));
379 fTimeScaleCtrl
.setHeight(fTimeScaleHeight
);
380 fTimeScaleCtrl
.addMouseWheelListener(new MouseWheelListener() {
382 public void mouseScrolled(MouseEvent e
) {
383 fTimeGraphCtrl
.zoom(e
.count
> 0);
387 fVerticalScrollBar
= new Slider(fDataViewer
, SWT
.VERTICAL
| SWT
.NO_FOCUS
);
388 fVerticalScrollBar
.setLayoutData(new GridData(SWT
.DEFAULT
, SWT
.FILL
, false, true, 1, 2));
389 fVerticalScrollBar
.addSelectionListener(new SelectionAdapter() {
391 public void widgetSelected(SelectionEvent e
) {
392 setTopIndex(fVerticalScrollBar
.getSelection());
396 fTimeGraphCtrl
= createTimeGraphControl(fDataViewer
, fColorScheme
);
398 fTimeGraphCtrl
.setTimeProvider(this);
399 fTimeGraphCtrl
.setTimeGraphScale(fTimeScaleCtrl
);
400 fTimeGraphCtrl
.addSelectionListener(this);
401 fTimeGraphCtrl
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
402 fTimeGraphCtrl
.addMouseWheelListener(new MouseWheelListener() {
404 public void mouseScrolled(MouseEvent e
) {
405 adjustVerticalScrollBar();
408 fTimeGraphCtrl
.addKeyListener(new KeyAdapter() {
410 public void keyPressed(KeyEvent e
) {
411 if (e
.character
== '+') {
413 } else if (e
.character
== '-') {
416 adjustVerticalScrollBar();
420 fHorizontalScrollBar
= new Slider(fDataViewer
, SWT
.HORIZONTAL
| SWT
.NO_FOCUS
);
421 fHorizontalScrollBar
.setLayoutData(new GridData(SWT
.FILL
, SWT
.DEFAULT
, true, false));
422 fHorizontalScrollBar
.addListener(SWT
.MouseWheel
, new Listener() {
424 public void handleEvent(Event event
) {
425 if ((event
.stateMask
& SWT
.MODIFIER_MASK
) == SWT
.CTRL
) {
426 getTimeGraphControl().zoom(event
.count
> 0);
428 getTimeGraphControl().horizontalScroll(event
.count
> 0);
430 // don't handle the immediately following SWT.Selection event
434 fHorizontalScrollBar
.addListener(SWT
.Selection
, new Listener() {
436 public void handleEvent(Event event
) {
437 int start
= fHorizontalScrollBar
.getSelection();
438 long time0
= getTime0();
439 long time1
= getTime1();
440 long timeMin
= getMinTime();
441 long timeMax
= getMaxTime();
442 long delta
= timeMax
- timeMin
;
444 long range
= time1
- time0
;
445 time0
= timeMin
+ Math
.round(delta
* ((double) start
/ H_SCROLLBAR_MAX
));
446 time1
= time0
+ range
;
448 setStartFinishTimeNotify(time0
, time1
);
452 Composite filler
= new Composite(fDataViewer
, SWT
.NONE
);
453 GridData gd
= new GridData(SWT
.DEFAULT
, SWT
.DEFAULT
, false, false);
454 gd
.heightHint
= fHorizontalScrollBar
.getSize().y
;
455 filler
.setLayoutData(gd
);
456 filler
.setLayout(new FillLayout());
458 fTimeGraphCtrl
.addControlListener(new ControlAdapter() {
460 public void controlResized(ControlEvent event
) {
465 fDataViewer
.update();
466 adjustHorizontalScrollBar();
467 adjustVerticalScrollBar();
474 public void dispose() {
476 fTimeGraphCtrl
.dispose();
477 fDataViewer
.dispose();
478 fColorScheme
.dispose();
482 * Create a new time graph control.
485 * The parent composite
488 * @return The new TimeGraphControl
490 protected TimeGraphControl
createTimeGraphControl(Composite parent
,
491 TimeGraphColorScheme colors
) {
492 return new TimeGraphControl(parent
, colors
);
496 * Resize the controls
498 public void resizeControls() {
499 Rectangle r
= fDataViewer
.getClientArea();
505 if (fNameWidth
> width
- fMinNameWidth
) {
506 fNameWidth
= width
- fMinNameWidth
;
508 if (fNameWidth
< fMinNameWidth
) {
509 fNameWidth
= fMinNameWidth
;
511 adjustHorizontalScrollBar();
512 adjustVerticalScrollBar();
516 * Recalculate the time bounds based on the time graph entries,
517 * if the user-specified bound is set to SWT.DEFAULT.
520 * The root time graph entries in the model
522 public void setTimeRange(ITimeGraphEntry entries
[]) {
523 fTime0Bound
= (fBeginTime
!= SWT
.DEFAULT ? fBeginTime
: fEndTime
);
524 fTime1Bound
= (fEndTime
!= SWT
.DEFAULT ? fEndTime
: fBeginTime
);
525 if (fBeginTime
!= SWT
.DEFAULT
&& fEndTime
!= SWT
.DEFAULT
) {
528 if (entries
== null || entries
.length
== 0) {
531 if (fTime0Bound
== SWT
.DEFAULT
) {
532 fTime0Bound
= Long
.MAX_VALUE
;
534 if (fTime1Bound
== SWT
.DEFAULT
) {
535 fTime1Bound
= Long
.MIN_VALUE
;
537 for (ITimeGraphEntry entry
: entries
) {
542 private void setTimeRange(ITimeGraphEntry entry
) {
543 if (fBeginTime
== SWT
.DEFAULT
&& entry
.hasTimeEvents() && entry
.getStartTime() != SWT
.DEFAULT
) {
544 fTime0Bound
= Math
.min(entry
.getStartTime(), fTime0Bound
);
546 if (fEndTime
== SWT
.DEFAULT
&& entry
.hasTimeEvents() && entry
.getEndTime() != SWT
.DEFAULT
) {
547 fTime1Bound
= Math
.max(entry
.getEndTime(), fTime1Bound
);
549 if (entry
.hasChildren()) {
550 for (ITimeGraphEntry child
: entry
.getChildren()) {
557 * Set the time bounds to the provided values.
560 * The bounds begin time, or SWT.DEFAULT to use the input bounds
562 * The bounds end time, or SWT.DEFAULT to use the input bounds
564 public void setTimeBounds(long beginTime
, long endTime
) {
565 fBeginTime
= beginTime
;
567 fTime0Bound
= (fBeginTime
!= SWT
.DEFAULT ? fBeginTime
: fEndTime
);
568 fTime1Bound
= (fEndTime
!= SWT
.DEFAULT ? fEndTime
: fBeginTime
);
569 if (fTime0Bound
> fTime1Bound
) {
570 // only possible if both are not default
571 fBeginTime
= endTime
;
572 fEndTime
= beginTime
;
573 fTime0Bound
= fBeginTime
;
574 fTime1Bound
= fEndTime
;
576 adjustHorizontalScrollBar();
580 * Recalculate the current time window when bounds have changed.
582 public void setTimeBounds() {
583 if (!fTimeRangeFixed
) {
584 fTime0
= fTime0Bound
;
585 fTime1
= fTime1Bound
;
587 fTime0
= Math
.max(fTime0Bound
, Math
.min(fTime0
, fTime1Bound
));
588 fTime1
= Math
.max(fTime0Bound
, Math
.min(fTime1
, fTime1Bound
));
589 if (fTime1
- fTime0
< fMinTimeInterval
) {
590 fTime1
= Math
.min(fTime1Bound
, fTime0
+ fMinTimeInterval
);
597 private void refreshAllData(ITimeGraphEntry
[] traces
) {
599 if (fSelectionBegin
< fBeginTime
) {
600 fSelectionBegin
= fBeginTime
;
601 } else if (fSelectionBegin
> fEndTime
) {
602 fSelectionBegin
= fEndTime
;
604 if (fSelectionEnd
< fBeginTime
) {
605 fSelectionEnd
= fBeginTime
;
606 } else if (fSelectionEnd
> fEndTime
) {
607 fSelectionEnd
= fEndTime
;
609 fTimeGraphCtrl
.refreshData(traces
);
610 fTimeScaleCtrl
.redraw();
611 adjustVerticalScrollBar();
615 * Callback for when this view is focused
617 public void setFocus() {
618 if (null != fTimeGraphCtrl
) {
619 fTimeGraphCtrl
.setFocus();
624 * Get the current focus status of this view.
626 * @return If the view is currently focused, or not
628 public boolean isInFocus() {
629 return fTimeGraphCtrl
.isInFocus();
633 * Get the view's current selection
635 * @return The entry that is selected
637 public ITimeGraphEntry
getSelection() {
638 return fTimeGraphCtrl
.getSelectedTrace();
642 * Get the index of the current selection
646 public int getSelectionIndex() {
647 return fTimeGraphCtrl
.getSelectedIndex();
651 public long getTime0() {
656 public long getTime1() {
661 public long getMinTimeInterval() {
662 return fMinTimeInterval
;
666 public int getNameSpace() {
671 public void setNameSpace(int width
) {
673 int w
= fTimeGraphCtrl
.getClientArea().width
;
674 if (fNameWidth
> w
- MIN_NAME_WIDTH
) {
675 fNameWidth
= w
- MIN_NAME_WIDTH
;
677 if (fNameWidth
< MIN_NAME_WIDTH
) {
678 fNameWidth
= MIN_NAME_WIDTH
;
680 fTimeGraphCtrl
.redraw();
681 fTimeScaleCtrl
.redraw();
685 public int getTimeSpace() {
686 int w
= fTimeGraphCtrl
.getClientArea().width
;
687 return w
- fNameWidth
;
691 public long getBeginTime() {
696 public long getEndTime() {
701 public long getMaxTime() {
706 public long getMinTime() {
711 public long getSelectionBegin() {
712 return fSelectionBegin
;
716 public long getSelectionEnd() {
717 return fSelectionEnd
;
721 public void setStartFinishTimeNotify(long time0
, long time1
) {
722 setStartFinishTime(time0
, time1
);
723 notifyRangeListeners();
727 public void notifyStartFinishTime() {
728 notifyRangeListeners();
732 public void setStartFinishTime(long time0
, long time1
) {
734 if (fTime0
< fTime0Bound
) {
735 fTime0
= fTime0Bound
;
737 if (fTime0
> fTime1Bound
) {
738 fTime0
= fTime1Bound
;
741 if (fTime1
< fTime0Bound
) {
742 fTime1
= fTime0Bound
;
744 if (fTime1
> fTime1Bound
) {
745 fTime1
= fTime1Bound
;
747 if (fTime1
- fTime0
< fMinTimeInterval
) {
748 fTime1
= Math
.min(fTime1Bound
, fTime0
+ fMinTimeInterval
);
750 fTimeRangeFixed
= true;
751 adjustHorizontalScrollBar();
752 fTimeGraphCtrl
.redraw();
753 fTimeScaleCtrl
.redraw();
757 public void resetStartFinishTime() {
758 setStartFinishTime(fTime0Bound
, fTime1Bound
);
759 fTimeRangeFixed
= false;
763 public void setSelectedTimeNotify(long time
, boolean ensureVisible
) {
764 setSelectedTimeInt(time
, ensureVisible
, true);
768 public void setSelectedTime(long time
, boolean ensureVisible
) {
769 setSelectedTimeInt(time
, ensureVisible
, false);
773 public void setSelectionRangeNotify(long beginTime
, long endTime
) {
774 boolean changed
= (beginTime
!= fSelectionBegin
|| endTime
!= fSelectionEnd
);
775 fSelectionBegin
= Math
.max(fTime0Bound
, Math
.min(fTime1Bound
, beginTime
));
776 fSelectionEnd
= Math
.max(fTime0Bound
, Math
.min(fTime1Bound
, endTime
));
777 fTimeGraphCtrl
.redraw();
778 fTimeScaleCtrl
.redraw();
780 notifyTimeListeners();
785 public void setSelectionRange(long beginTime
, long endTime
) {
786 fSelectionBegin
= Math
.max(fTime0Bound
, Math
.min(fTime1Bound
, beginTime
));
787 fSelectionEnd
= Math
.max(fTime0Bound
, Math
.min(fTime1Bound
, endTime
));
788 fTimeGraphCtrl
.redraw();
789 fTimeScaleCtrl
.redraw();
792 private void setSelectedTimeInt(long time
, boolean ensureVisible
, boolean doNotify
) {
796 long timeSpace
= (fTime1
- fTime0
) / RECENTERING_MARGIN_FACTOR
;
797 long timeMid
= (fTime1
- fTime0
) / 2;
798 if (time
< fTime0
+ timeSpace
) {
799 long dt
= fTime0
- time
+ timeMid
;
802 } else if (time
> fTime1
- timeSpace
) {
803 long dt
= time
- fTime1
+ timeMid
;
807 if (fTime0
< fTime0Bound
) {
808 fTime1
= Math
.min(fTime1Bound
, fTime1
+ (fTime0Bound
- fTime0
));
809 fTime0
= fTime0Bound
;
810 } else if (fTime1
> fTime1Bound
) {
811 fTime0
= Math
.max(fTime0Bound
, fTime0
- (fTime1
- fTime1Bound
));
812 fTime1
= fTime1Bound
;
815 if (fTime1
- fTime0
< fMinTimeInterval
) {
816 fTime1
= Math
.min(fTime1Bound
, fTime0
+ fMinTimeInterval
);
818 adjustHorizontalScrollBar();
819 fTimeGraphCtrl
.redraw();
820 fTimeScaleCtrl
.redraw();
822 boolean notifySelectedTime
= (time
!= fSelectionBegin
|| time
!= fSelectionEnd
);
823 fSelectionBegin
= time
;
824 fSelectionEnd
= time
;
826 if (doNotify
&& ((time0
!= fTime0
) || (time1
!= fTime1
))) {
827 notifyRangeListeners();
830 if (doNotify
&& notifySelectedTime
) {
831 notifyTimeListeners();
836 public void widgetDefaultSelected(SelectionEvent e
) {
837 if (fSelectedEntry
!= getSelection()) {
838 fSelectedEntry
= getSelection();
839 notifySelectionListeners();
844 public void widgetSelected(SelectionEvent e
) {
845 if (fSelectedEntry
!= getSelection()) {
846 fSelectedEntry
= getSelection();
847 notifySelectionListeners();
852 * Callback for when the next event is selected
854 public void selectNextEvent() {
855 fTimeGraphCtrl
.selectNextEvent();
856 adjustVerticalScrollBar();
860 * Callback for when the previous event is selected
862 public void selectPrevEvent() {
863 fTimeGraphCtrl
.selectPrevEvent();
864 adjustVerticalScrollBar();
868 * Callback for when the next item is selected
870 public void selectNextItem() {
871 fTimeGraphCtrl
.selectNextTrace();
872 adjustVerticalScrollBar();
876 * Callback for when the previous item is selected
878 public void selectPrevItem() {
879 fTimeGraphCtrl
.selectPrevTrace();
880 adjustVerticalScrollBar();
884 * Callback for the show legend action
886 public void showLegend() {
887 if (fDataViewer
== null || fDataViewer
.isDisposed()) {
891 TimeGraphLegend
.open(fDataViewer
.getShell(), fTimeGraphProvider
);
895 * Callback for the Zoom In action
897 public void zoomIn() {
898 fTimeGraphCtrl
.zoomIn();
902 * Callback for the Zoom Out action
904 public void zoomOut() {
905 fTimeGraphCtrl
.zoomOut();
908 private String
getPreferenceString(String string
) {
909 return getViewTypeStr() + "." + string
; //$NON-NLS-1$
913 * Add a selection listener
916 * The listener to add
918 public void addSelectionListener(ITimeGraphSelectionListener listener
) {
919 fSelectionListeners
.add(listener
);
923 * Remove a selection listener
926 * The listener to remove
928 public void removeSelectionListener(ITimeGraphSelectionListener listener
) {
929 fSelectionListeners
.remove(listener
);
932 private void notifySelectionListeners() {
933 synchronized (fListenerNotifierLock
) {
934 if (fListenerNotifier
== null) {
935 fListenerNotifier
= new ListenerNotifier();
936 fListenerNotifier
.start();
938 fListenerNotifier
.selectionChanged();
942 private void fireSelectionChanged(ITimeGraphEntry selection
) {
943 TimeGraphSelectionEvent event
= new TimeGraphSelectionEvent(this, selection
);
945 for (ITimeGraphSelectionListener listener
: fSelectionListeners
) {
946 listener
.selectionChanged(event
);
951 * Add a time listener
954 * The listener to add
956 public void addTimeListener(ITimeGraphTimeListener listener
) {
957 fTimeListeners
.add(listener
);
961 * Remove a time listener
964 * The listener to remove
966 public void removeTimeListener(ITimeGraphTimeListener listener
) {
967 fTimeListeners
.remove(listener
);
970 private void notifyTimeListeners() {
971 synchronized (fListenerNotifierLock
) {
972 if (fListenerNotifier
== null) {
973 fListenerNotifier
= new ListenerNotifier();
974 fListenerNotifier
.start();
976 fListenerNotifier
.timeSelected();
980 private void fireTimeSelected(long startTime
, long endTime
) {
981 TimeGraphTimeEvent event
= new TimeGraphTimeEvent(this, startTime
, endTime
);
983 for (ITimeGraphTimeListener listener
: fTimeListeners
) {
984 listener
.timeSelected(event
);
989 * Add a range listener
992 * The listener to add
994 public void addRangeListener(ITimeGraphRangeListener listener
) {
995 fRangeListeners
.add(listener
);
999 * Remove a range listener
1002 * The listener to remove
1004 public void removeRangeListener(ITimeGraphRangeListener listener
) {
1005 fRangeListeners
.remove(listener
);
1008 private void notifyRangeListeners() {
1009 synchronized (fListenerNotifierLock
) {
1010 if (fListenerNotifier
== null) {
1011 fListenerNotifier
= new ListenerNotifier();
1012 fListenerNotifier
.start();
1014 fListenerNotifier
.timeRangeUpdated();
1018 private void fireTimeRangeUpdated(long startTime
, long endTime
) {
1019 // Check if the time has actually changed from last notification
1020 if (startTime
!= fTime0ExtSynch
|| endTime
!= fTime1ExtSynch
) {
1021 // Notify Time Scale Selection Listeners
1022 TimeGraphRangeUpdateEvent event
= new TimeGraphRangeUpdateEvent(this, startTime
, endTime
);
1024 for (ITimeGraphRangeListener listener
: fRangeListeners
) {
1025 listener
.timeRangeUpdated(event
);
1028 // update external synch timers
1029 updateExtSynchTimers();
1034 * Callback to set a selected event in the view
1037 * The event that was selected
1039 * The source of this selection event
1041 public void setSelectedEvent(ITimeEvent event
, Object source
) {
1042 if (event
== null || source
== this) {
1045 fSelectedEntry
= event
.getEntry();
1046 fTimeGraphCtrl
.selectItem(fSelectedEntry
, false);
1048 setSelectedTimeInt(event
.getTime(), true, true);
1049 adjustVerticalScrollBar();
1053 * Set the seeked time of a trace
1056 * The trace that was seeked
1060 * The source of this seek event
1062 public void setSelectedTraceTime(ITimeGraphEntry trace
, long time
, Object source
) {
1063 if (trace
== null || source
== this) {
1066 fSelectedEntry
= trace
;
1067 fTimeGraphCtrl
.selectItem(trace
, false);
1069 setSelectedTimeInt(time
, true, true);
1073 * Callback for a trace selection
1076 * The trace that was selected
1078 public void setSelection(ITimeGraphEntry trace
) {
1079 fSelectedEntry
= trace
;
1080 fTimeGraphCtrl
.selectItem(trace
, false);
1081 adjustVerticalScrollBar();
1085 * Callback for a time window selection
1088 * Start time of the range
1090 * End time of the range
1092 * Source of the event
1094 public void setSelectVisTimeWindow(long time0
, long time1
, Object source
) {
1095 if (source
== this) {
1099 setStartFinishTime(time0
, time1
);
1101 // update notification time values since we are now in synch with the
1102 // external application
1103 updateExtSynchTimers();
1107 * update the cache timers used to identify the need to send a time window
1108 * update to external registered listeners
1110 private void updateExtSynchTimers() {
1111 // last time notification cache
1112 fTime0ExtSynch
= fTime0
;
1113 fTime1ExtSynch
= fTime1
;
1117 public TimeFormat
getTimeFormat() {
1123 * the {@link TimeFormat} used to display timestamps
1125 public void setTimeFormat(TimeFormat tf
) {
1126 this.fTimeFormat
= tf
;
1127 if (tf
== TimeFormat
.CYCLES
) {
1128 fTimeDataProvider
= new TimeDataProviderCyclesConverter(this, fClockFrequency
);
1130 fTimeDataProvider
= this;
1132 fTimeScaleCtrl
.setTimeProvider(fTimeDataProvider
);
1133 if (fToolTipHandler
!= null) {
1134 fToolTipHandler
.setTimeProvider(fTimeDataProvider
);
1139 * Sets the clock frequency. Used when the time format is set to CYCLES.
1141 * @param clockFrequency
1142 * the clock frequency in Hz
1144 public void setClockFrequency(long clockFrequency
) {
1145 fClockFrequency
= clockFrequency
;
1146 if (fTimeFormat
== TimeFormat
.CYCLES
) {
1147 fTimeDataProvider
= new TimeDataProviderCyclesConverter(this, fClockFrequency
);
1148 fTimeScaleCtrl
.setTimeProvider(fTimeDataProvider
);
1149 if (fToolTipHandler
!= null) {
1150 fToolTipHandler
.setTimeProvider(fTimeDataProvider
);
1156 * Retrieve the border width
1160 public int getBorderWidth() {
1161 return fBorderWidth
;
1165 * Set the border width
1167 * @param borderWidth
1170 public void setBorderWidth(int borderWidth
) {
1171 if (borderWidth
> -1) {
1172 this.fBorderWidth
= borderWidth
;
1173 GridLayout gl
= (GridLayout
) fDataViewer
.getLayout();
1174 gl
.marginHeight
= borderWidth
;
1179 * Retrieve the height of the header
1181 * @return The height
1183 public int getHeaderHeight() {
1184 return fTimeScaleHeight
;
1188 * Set the height of the header
1190 * @param headerHeight
1193 public void setHeaderHeight(int headerHeight
) {
1194 if (headerHeight
> -1) {
1195 this.fTimeScaleHeight
= headerHeight
;
1196 fTimeScaleCtrl
.setHeight(headerHeight
);
1201 * Retrieve the height of an item row
1203 * @return The height
1205 public int getItemHeight() {
1206 if (fTimeGraphCtrl
!= null) {
1207 return fTimeGraphCtrl
.getItemHeight();
1213 * Set the height of an item row
1218 public void setItemHeight(int rowHeight
) {
1219 if (fTimeGraphCtrl
!= null) {
1220 fTimeGraphCtrl
.setItemHeight(rowHeight
);
1225 * Set the minimum item width
1230 public void setMinimumItemWidth(int width
) {
1231 if (fTimeGraphCtrl
!= null) {
1232 fTimeGraphCtrl
.setMinimumItemWidth(width
);
1237 * Set the width for the name column
1242 public void setNameWidthPref(int width
) {
1243 fNameWidthPref
= width
;
1251 * Retrieve the configure width for the name column
1257 public int getNameWidthPref(int width
) {
1258 return fNameWidthPref
;
1262 * Returns the primary control associated with this viewer.
1264 * @return the SWT control which displays this viewer's content
1266 public Control
getControl() {
1271 * Returns the time graph control associated with this viewer.
1273 * @return the time graph control
1275 public TimeGraphControl
getTimeGraphControl() {
1276 return fTimeGraphCtrl
;
1280 * Returns the time graph scale associated with this viewer.
1282 * @return the time graph scale
1284 public TimeGraphScale
getTimeGraphScale() {
1285 return fTimeScaleCtrl
;
1289 * Return the x coordinate corresponding to a time
1293 * @return the x coordinate corresponding to the time
1295 public int getXForTime(long time
) {
1296 return fTimeGraphCtrl
.getXForTime(time
);
1300 * Return the time corresponding to an x coordinate
1304 * @return the time corresponding to the x coordinate
1306 public long getTimeAtX(int x
) {
1307 return fTimeGraphCtrl
.getTimeAtX(x
);
1311 * Get the selection provider
1313 * @return the selection provider
1315 public ISelectionProvider
getSelectionProvider() {
1316 return fTimeGraphCtrl
;
1320 * Wait for the cursor
1323 * Wait indefinitely?
1325 public void waitCursor(boolean waitInd
) {
1326 fTimeGraphCtrl
.waitCursor(waitInd
);
1330 * Get the horizontal scroll bar object
1332 * @return The scroll bar
1334 public Slider
getHorizontalBar() {
1335 return fHorizontalScrollBar
;
1339 * Get the vertical scroll bar object
1341 * @return The scroll bar
1343 public Slider
getVerticalBar() {
1344 return fVerticalScrollBar
;
1348 * Set the given index as the top one
1351 * The index that will go to the top
1353 public void setTopIndex(int index
) {
1354 fTimeGraphCtrl
.setTopIndex(index
);
1355 adjustVerticalScrollBar();
1359 * Retrieve the current top index
1361 * @return The top index
1363 public int getTopIndex() {
1364 return fTimeGraphCtrl
.getTopIndex();
1368 * Sets the auto-expand level to be used when the input of the viewer is set
1369 * using {@link #setInput(Object)}. The value 0 means that there is no
1370 * auto-expand; 1 means that top-level elements are expanded, but not their
1371 * children; 2 means that top-level elements are expanded, and their
1372 * children, but not grand-children; and so on.
1374 * The value {@link #ALL_LEVELS} means that all subtrees should be expanded.
1377 * non-negative level, or <code>ALL_LEVELS</code> to expand all
1378 * levels of the tree
1380 public void setAutoExpandLevel(int level
) {
1381 fTimeGraphCtrl
.setAutoExpandLevel(level
);
1385 * Returns the auto-expand level.
1387 * @return non-negative level, or <code>ALL_LEVELS</code> if all levels of
1388 * the tree are expanded automatically
1389 * @see #setAutoExpandLevel
1391 public int getAutoExpandLevel() {
1392 return fTimeGraphCtrl
.getAutoExpandLevel();
1396 * Set the expanded state of an entry
1399 * The entry to expand/collapse
1401 * True for expanded, false for collapsed
1403 public void setExpandedState(ITimeGraphEntry entry
, boolean expanded
) {
1404 fTimeGraphCtrl
.setExpandedState(entry
, expanded
);
1405 adjustVerticalScrollBar();
1409 * Collapses all nodes of the viewer's tree, starting with the root.
1411 public void collapseAll() {
1412 fTimeGraphCtrl
.collapseAll();
1413 adjustVerticalScrollBar();
1417 * Expands all nodes of the viewer's tree, starting with the root.
1419 public void expandAll() {
1420 fTimeGraphCtrl
.expandAll();
1421 adjustVerticalScrollBar();
1425 * Get the number of sub-elements when expanded
1427 * @return The element count
1429 public int getExpandedElementCount() {
1430 return fTimeGraphCtrl
.getExpandedElementCount();
1434 * Get the sub-elements
1436 * @return The array of entries that are below this one
1438 public ITimeGraphEntry
[] getExpandedElements() {
1439 return fTimeGraphCtrl
.getExpandedElements();
1443 * Add a tree listener
1446 * The listener to add
1448 public void addTreeListener(ITimeGraphTreeListener listener
) {
1449 fTimeGraphCtrl
.addTreeListener(listener
);
1453 * Remove a tree listener
1456 * The listener to remove
1458 public void removeTreeListener(ITimeGraphTreeListener listener
) {
1459 fTimeGraphCtrl
.removeTreeListener(listener
);
1463 * Get the reset scale action.
1465 * @return The Action object
1467 public Action
getResetScaleAction() {
1468 if (fResetScaleAction
== null) {
1470 fResetScaleAction
= new Action() {
1473 resetStartFinishTime();
1474 notifyStartFinishTime();
1477 fResetScaleAction
.setText(Messages
.TmfTimeGraphViewer_ResetScaleActionNameText
);
1478 fResetScaleAction
.setToolTipText(Messages
.TmfTimeGraphViewer_ResetScaleActionToolTipText
);
1479 fResetScaleAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_HOME_MENU
));
1481 return fResetScaleAction
;
1485 * Get the show legend action.
1487 * @return The Action object
1489 public Action
getShowLegendAction() {
1490 if (fShowLegendAction
== null) {
1492 fShowLegendAction
= new Action() {
1498 fShowLegendAction
.setText(Messages
.TmfTimeGraphViewer_LegendActionNameText
);
1499 fShowLegendAction
.setToolTipText(Messages
.TmfTimeGraphViewer_LegendActionToolTipText
);
1500 fShowLegendAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_SHOW_LEGEND
));
1503 return fShowLegendAction
;
1507 * Get the the next event action.
1509 * @return The action object
1511 public Action
getNextEventAction() {
1512 if (fNextEventAction
== null) {
1513 fNextEventAction
= new Action() {
1520 fNextEventAction
.setText(Messages
.TmfTimeGraphViewer_NextEventActionNameText
);
1521 fNextEventAction
.setToolTipText(Messages
.TmfTimeGraphViewer_NextEventActionToolTipText
);
1522 fNextEventAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_NEXT_EVENT
));
1525 return fNextEventAction
;
1529 * Get the previous event action.
1531 * @return The Action object
1533 public Action
getPreviousEventAction() {
1534 if (fPrevEventAction
== null) {
1535 fPrevEventAction
= new Action() {
1542 fPrevEventAction
.setText(Messages
.TmfTimeGraphViewer_PreviousEventActionNameText
);
1543 fPrevEventAction
.setToolTipText(Messages
.TmfTimeGraphViewer_PreviousEventActionToolTipText
);
1544 fPrevEventAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_PREV_EVENT
));
1547 return fPrevEventAction
;
1551 * Get the next item action.
1553 * @return The Action object
1555 public Action
getNextItemAction() {
1556 if (fNextItemAction
== null) {
1558 fNextItemAction
= new Action() {
1564 fNextItemAction
.setText(Messages
.TmfTimeGraphViewer_NextItemActionNameText
);
1565 fNextItemAction
.setToolTipText(Messages
.TmfTimeGraphViewer_NextItemActionToolTipText
);
1566 fNextItemAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_NEXT_ITEM
));
1568 return fNextItemAction
;
1572 * Get the previous item action.
1574 * @return The Action object
1576 public Action
getPreviousItemAction() {
1577 if (fPreviousItemAction
== null) {
1579 fPreviousItemAction
= new Action() {
1585 fPreviousItemAction
.setText(Messages
.TmfTimeGraphViewer_PreviousItemActionNameText
);
1586 fPreviousItemAction
.setToolTipText(Messages
.TmfTimeGraphViewer_PreviousItemActionToolTipText
);
1587 fPreviousItemAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_PREV_ITEM
));
1589 return fPreviousItemAction
;
1593 * Get the zoom in action
1595 * @return The Action object
1597 public Action
getZoomInAction() {
1598 if (fZoomInAction
== null) {
1599 fZoomInAction
= new Action() {
1605 fZoomInAction
.setText(Messages
.TmfTimeGraphViewer_ZoomInActionNameText
);
1606 fZoomInAction
.setToolTipText(Messages
.TmfTimeGraphViewer_ZoomInActionToolTipText
);
1607 fZoomInAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_ZOOM_IN_MENU
));
1609 return fZoomInAction
;
1613 * Get the zoom out action
1615 * @return The Action object
1617 public Action
getZoomOutAction() {
1618 if (fZoomOutAction
== null) {
1619 fZoomOutAction
= new Action() {
1625 fZoomOutAction
.setText(Messages
.TmfTimeGraphViewer_ZoomOutActionNameText
);
1626 fZoomOutAction
.setToolTipText(Messages
.TmfTimeGraphViewer_ZoomOutActionToolTipText
);
1627 fZoomOutAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_ZOOM_OUT_MENU
));
1629 return fZoomOutAction
;
1633 * Get the hide arrows action
1635 * @param dialogSettings
1636 * The dialog settings section where the state should be stored,
1639 * @return The Action object
1641 public Action
getHideArrowsAction(final IDialogSettings dialogSettings
) {
1642 if (fHideArrowsAction
== null) {
1643 fHideArrowsAction
= new Action(Messages
.TmfTimeGraphViewer_HideArrowsActionNameText
, IAction
.AS_CHECK_BOX
) {
1646 boolean hideArrows
= fHideArrowsAction
.isChecked();
1647 fTimeGraphCtrl
.hideArrows(hideArrows
);
1649 if (dialogSettings
!= null) {
1650 dialogSettings
.put(HIDE_ARROWS_KEY
, hideArrows
);
1652 if (fFollowArrowFwdAction
!= null) {
1653 fFollowArrowFwdAction
.setEnabled(!hideArrows
);
1655 if (fFollowArrowBwdAction
!= null) {
1656 fFollowArrowBwdAction
.setEnabled(!hideArrows
);
1660 fHideArrowsAction
.setToolTipText(Messages
.TmfTimeGraphViewer_HideArrowsActionToolTipText
);
1661 fHideArrowsAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_HIDE_ARROWS
));
1662 if (dialogSettings
!= null) {
1663 boolean hideArrows
= dialogSettings
.getBoolean(HIDE_ARROWS_KEY
);
1664 fTimeGraphCtrl
.hideArrows(hideArrows
);
1665 fHideArrowsAction
.setChecked(hideArrows
);
1666 if (fFollowArrowFwdAction
!= null) {
1667 fFollowArrowFwdAction
.setEnabled(!hideArrows
);
1669 if (fFollowArrowBwdAction
!= null) {
1670 fFollowArrowBwdAction
.setEnabled(!hideArrows
);
1674 return fHideArrowsAction
;
1678 * Get the follow arrow forward action.
1680 * @return The Action object
1682 public Action
getFollowArrowFwdAction() {
1683 if (fFollowArrowFwdAction
== null) {
1684 fFollowArrowFwdAction
= new Action() {
1687 fTimeGraphCtrl
.followArrowFwd();
1688 adjustVerticalScrollBar();
1691 fFollowArrowFwdAction
.setText(Messages
.TmfTimeGraphViewer_FollowArrowForwardActionNameText
);
1692 fFollowArrowFwdAction
.setToolTipText(Messages
.TmfTimeGraphViewer_FollowArrowForwardActionToolTipText
);
1693 fFollowArrowFwdAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_FOLLOW_ARROW_FORWARD
));
1694 if (fHideArrowsAction
!= null) {
1695 fFollowArrowFwdAction
.setEnabled(!fHideArrowsAction
.isChecked());
1698 return fFollowArrowFwdAction
;
1702 * Get the follow arrow backward action.
1704 * @return The Action object
1706 public Action
getFollowArrowBwdAction() {
1707 if (fFollowArrowBwdAction
== null) {
1708 fFollowArrowBwdAction
= new Action() {
1711 fTimeGraphCtrl
.followArrowBwd();
1712 adjustVerticalScrollBar();
1715 fFollowArrowBwdAction
.setText(Messages
.TmfTimeGraphViewer_FollowArrowBackwardActionNameText
);
1716 fFollowArrowBwdAction
.setToolTipText(Messages
.TmfTimeGraphViewer_FollowArrowBackwardActionToolTipText
);
1717 fFollowArrowBwdAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_FOLLOW_ARROW_BACKWARD
));
1718 if (fHideArrowsAction
!= null) {
1719 fFollowArrowBwdAction
.setEnabled(!fHideArrowsAction
.isChecked());
1722 return fFollowArrowBwdAction
;
1725 private void adjustHorizontalScrollBar() {
1726 long time0
= getTime0();
1727 long time1
= getTime1();
1728 long timeMin
= getMinTime();
1729 long timeMax
= getMaxTime();
1730 long delta
= timeMax
- timeMin
;
1732 int thumb
= H_SCROLLBAR_MAX
;
1734 // Thumb size (page size)
1735 thumb
= Math
.max(1, (int) (H_SCROLLBAR_MAX
* ((double) (time1
- time0
) / delta
)));
1736 // At the beginning of visible window
1737 timePos
= (int) (H_SCROLLBAR_MAX
* ((double) (time0
- timeMin
) / delta
));
1739 fHorizontalScrollBar
.setValues(timePos
, 0, H_SCROLLBAR_MAX
, thumb
, Math
.max(1, thumb
/ 2), Math
.max(2, thumb
));
1742 private void adjustVerticalScrollBar() {
1743 int topIndex
= fTimeGraphCtrl
.getTopIndex();
1744 int countPerPage
= fTimeGraphCtrl
.countPerPage();
1745 int expandedElementCount
= fTimeGraphCtrl
.getExpandedElementCount();
1746 if (topIndex
+ countPerPage
> expandedElementCount
) {
1747 fTimeGraphCtrl
.setTopIndex(Math
.max(0, expandedElementCount
- countPerPage
));
1750 int selection
= fTimeGraphCtrl
.getTopIndex();
1752 int max
= Math
.max(1, expandedElementCount
- 1);
1753 int thumb
= Math
.min(max
, Math
.max(1, countPerPage
- 1));
1755 int pageIncrement
= Math
.max(1, countPerPage
);
1756 fVerticalScrollBar
.setValues(selection
, min
, max
, thumb
, increment
, pageIncrement
);
1761 * a {@link MenuDetectListener}
1762 * @see org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.TimeGraphControl#addTimeGraphEntryMenuListener(org.eclipse.swt.events.MenuDetectListener)
1764 public void addTimeGraphEntryMenuListener(MenuDetectListener listener
) {
1765 fTimeGraphCtrl
.addTimeGraphEntryMenuListener(listener
);
1770 * a {@link MenuDetectListener}
1771 * @see org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.TimeGraphControl#removeTimeGraphEntryMenuListener(org.eclipse.swt.events.MenuDetectListener)
1773 public void removeTimeGraphEntryMenuListener(MenuDetectListener listener
) {
1774 fTimeGraphCtrl
.removeTimeGraphEntryMenuListener(listener
);
1779 * a {@link MenuDetectListener}
1780 * @see org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.TimeGraphControl#addTimeEventMenuListener(org.eclipse.swt.events.MenuDetectListener)
1782 public void addTimeEventMenuListener(MenuDetectListener listener
) {
1783 fTimeGraphCtrl
.addTimeEventMenuListener(listener
);
1788 * a {@link MenuDetectListener}
1789 * @see org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.TimeGraphControl#removeTimeEventMenuListener(org.eclipse.swt.events.MenuDetectListener)
1791 public void removeTimeEventMenuListener(MenuDetectListener listener
) {
1792 fTimeGraphCtrl
.removeTimeEventMenuListener(listener
);
1797 * The filter object to be attached to the view
1799 public void addFilter(ViewerFilter filter
) {
1800 fTimeGraphCtrl
.addFilter(filter
);
1806 * The filter object to be attached to the view
1808 public void removeFilter(ViewerFilter filter
) {
1809 fTimeGraphCtrl
.removeFilter(filter
);