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
.signal
.TmfTimeViewAlignmentInfo
;
53 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.ITmfTimeAligned
;
54 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.dialogs
.TimeGraphLegend
;
55 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.ILinkEvent
;
56 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.ITimeEvent
;
57 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.ITimeGraphEntry
;
58 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.widgets
.ITimeDataProvider
;
59 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.widgets
.TimeDataProviderCyclesConverter
;
60 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.widgets
.TimeGraphColorScheme
;
61 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.widgets
.TimeGraphControl
;
62 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.widgets
.TimeGraphScale
;
63 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.widgets
.TimeGraphTooltipHandler
;
64 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.widgets
.Utils
;
65 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.widgets
.Utils
.TimeFormat
;
68 * Generic time graph viewer implementation
70 * @author Patrick Tasse, and others
72 public class TimeGraphViewer
implements ITimeDataProvider
, SelectionListener
{
74 /** Constant indicating that all levels of the time graph should be expanded */
75 public static final int ALL_LEVELS
= AbstractTreeViewer
.ALL_LEVELS
;
77 private static final int DEFAULT_NAME_WIDTH
= 200;
78 private static final int MIN_NAME_WIDTH
= 6;
79 private static final int MAX_NAME_WIDTH
= 1000;
80 private static final int DEFAULT_HEIGHT
= 22;
81 private static final String HIDE_ARROWS_KEY
= "hide.arrows"; //$NON-NLS-1$
82 private static final long DEFAULT_FREQUENCY
= 1000000000L;
83 private static final int H_SCROLLBAR_MAX
= Integer
.MAX_VALUE
- 1;
85 private long fMinTimeInterval
;
86 private ITimeGraphEntry fSelectedEntry
;
87 private long fBeginTime
= SWT
.DEFAULT
; // The user-specified bounds start time
88 private long fEndTime
= SWT
.DEFAULT
; // The user-specified bounds end time
89 private long fTime0
= SWT
.DEFAULT
; // The current window start time
90 private long fTime1
= SWT
.DEFAULT
; // The current window end time
91 private long fSelectionBegin
= SWT
.DEFAULT
;
92 private long fSelectionEnd
= SWT
.DEFAULT
;
93 private long fTime0Bound
= SWT
.DEFAULT
; // The bounds start time
94 private long fTime1Bound
= SWT
.DEFAULT
; // The bounds end time
95 private long fTime0ExtSynch
= SWT
.DEFAULT
;
96 private long fTime1ExtSynch
= SWT
.DEFAULT
;
97 private boolean fTimeRangeFixed
;
98 private int fNameWidthPref
= DEFAULT_NAME_WIDTH
;
99 private int fMinNameWidth
= MIN_NAME_WIDTH
;
100 private int fNameWidth
;
101 private Composite fDataViewer
;
103 private TimeGraphControl fTimeGraphCtrl
;
104 private TimeGraphScale fTimeScaleCtrl
;
105 private Slider fHorizontalScrollBar
;
106 private Slider fVerticalScrollBar
;
107 private TimeGraphColorScheme fColorScheme
;
108 private Object fInputElement
;
109 private ITimeGraphContentProvider fTimeGraphContentProvider
;
110 private ITimeGraphPresentationProvider fTimeGraphProvider
;
111 private ITimeDataProvider fTimeDataProvider
= this;
112 private TimeGraphTooltipHandler fToolTipHandler
;
114 private List
<ITimeGraphSelectionListener
> fSelectionListeners
= new ArrayList
<>();
115 private List
<ITimeGraphTimeListener
> fTimeListeners
= new ArrayList
<>();
116 private List
<ITimeGraphRangeListener
> fRangeListeners
= new ArrayList
<>();
118 // Time format, using Epoch reference, Relative time format(default),
120 private TimeFormat fTimeFormat
= TimeFormat
.RELATIVE
;
121 // Clock frequency to use for Cycles time format
122 private long fClockFrequency
= DEFAULT_FREQUENCY
;
123 private int fBorderWidth
= 0;
124 private int fTimeScaleHeight
= DEFAULT_HEIGHT
;
126 private Action fResetScaleAction
;
127 private Action fShowLegendAction
;
128 private Action fNextEventAction
;
129 private Action fPrevEventAction
;
130 private Action fNextItemAction
;
131 private Action fPreviousItemAction
;
132 private Action fZoomInAction
;
133 private Action fZoomOutAction
;
134 private Action fHideArrowsAction
;
135 private Action fFollowArrowFwdAction
;
136 private Action fFollowArrowBwdAction
;
138 private ListenerNotifier fListenerNotifier
;
139 private final Object fListenerNotifierLock
= new Object();
141 private Composite fTimeAlignedComposite
;
143 private class ListenerNotifier
extends Thread
{
144 private static final long DELAY
= 400L;
145 private static final long POLLING_INTERVAL
= 10L;
146 private long fLastUpdateTime
= Long
.MAX_VALUE
;
147 private boolean fSelectionChanged
= false;
148 private boolean fTimeRangeUpdated
= false;
149 private boolean fTimeSelected
= false;
153 while ((System
.currentTimeMillis() - fLastUpdateTime
) < DELAY
) {
155 Thread
.sleep(POLLING_INTERVAL
);
156 } catch (Exception e
) {
160 synchronized (fListenerNotifierLock
) {
161 fListenerNotifier
= null;
163 if (!isInterrupted()) {
164 Display
.getDefault().asyncExec(new Runnable() {
167 if (fDataViewer
.isDisposed()) {
170 if (fSelectionChanged
) {
171 fireSelectionChanged(fSelectedEntry
);
173 if (fTimeRangeUpdated
) {
174 fireTimeRangeUpdated(fTime0
, fTime1
);
177 fireTimeSelected(fSelectionBegin
, fSelectionEnd
);
184 public void selectionChanged() {
185 fSelectionChanged
= true;
186 fLastUpdateTime
= System
.currentTimeMillis();
189 public void timeRangeUpdated() {
190 fTimeRangeUpdated
= true;
191 fLastUpdateTime
= System
.currentTimeMillis();
194 public void timeSelected() {
195 fTimeSelected
= true;
196 fLastUpdateTime
= System
.currentTimeMillis();
201 * Standard constructor.
203 * The default timegraph content provider accepts an ITimeGraphEntry[] as input element.
206 * The parent UI composite object
210 public TimeGraphViewer(Composite parent
, int style
) {
211 createDataViewer(parent
, style
);
212 fTimeGraphContentProvider
= new TimeGraphContentProvider();
216 * Sets the timegraph content provider used by this timegraph viewer.
218 * @param timeGraphContentProvider
219 * the timegraph content provider
221 public void setTimeGraphContentProvider(ITimeGraphContentProvider timeGraphContentProvider
) {
222 fTimeGraphContentProvider
= timeGraphContentProvider
;
226 * Gets the timegraph content provider used by this timegraph viewer.
228 * @return the timegraph content provider
230 public ITimeGraphContentProvider
getTimeGraphContentProvider() {
231 return fTimeGraphContentProvider
;
235 * Sets the timegraph presentation provider used by this timegraph viewer.
237 * @param timeGraphProvider
238 * the timegraph provider
240 public void setTimeGraphProvider(ITimeGraphPresentationProvider timeGraphProvider
) {
241 fTimeGraphProvider
= timeGraphProvider
;
242 fTimeGraphCtrl
.setTimeGraphProvider(timeGraphProvider
);
243 fToolTipHandler
= new TimeGraphTooltipHandler(fTimeGraphProvider
, fTimeDataProvider
);
244 fToolTipHandler
.activateHoverHelp(fTimeGraphCtrl
);
248 * Sets or clears the input for this time graph viewer.
250 * @param inputElement
251 * The input of this time graph viewer, or <code>null</code> if
254 public void setInput(Object inputElement
) {
255 fInputElement
= inputElement
;
256 ITimeGraphEntry
[] input
= fTimeGraphContentProvider
.getElements(inputElement
);
258 if (fTimeGraphCtrl
!= null) {
261 fSelectionBegin
= SWT
.DEFAULT
;
262 fSelectionEnd
= SWT
.DEFAULT
;
263 fSelectedEntry
= null;
264 refreshAllData(input
);
269 * Gets the input for this time graph viewer.
271 * @return The input of this time graph viewer, or <code>null</code> if none
273 public Object
getInput() {
274 return fInputElement
;
278 * Sets (or clears if null) the list of links to display on this combo
281 * the links to display in this time graph combo
283 public void setLinks(List
<ILinkEvent
> links
) {
284 if (fTimeGraphCtrl
!= null) {
285 fTimeGraphCtrl
.refreshArrows(links
);
292 public void refresh() {
293 ITimeGraphEntry
[] input
= fTimeGraphContentProvider
.getElements(fInputElement
);
295 refreshAllData(input
);
299 * Callback for when the control is moved
304 public void controlMoved(ControlEvent e
) {
308 * Callback for when the control is resized
313 public void controlResized(ControlEvent e
) {
318 * @return The string representing the view type
320 protected String
getViewTypeStr() {
321 return "viewoption.threads"; //$NON-NLS-1$
324 int getMarginWidth() {
328 int getMarginHeight() {
333 fMinTimeInterval
= 1;
334 fSelectionBegin
= SWT
.DEFAULT
;
335 fSelectionEnd
= SWT
.DEFAULT
;
336 fNameWidth
= Utils
.loadIntOption(getPreferenceString("namewidth"), //$NON-NLS-1$
337 fNameWidthPref
, fMinNameWidth
, MAX_NAME_WIDTH
);
341 Utils
.saveIntOption(getPreferenceString("namewidth"), fNameWidth
); //$NON-NLS-1$
345 * Create a data viewer.
351 * @return The new data viewer
353 protected Control
createDataViewer(Composite parent
, int style
) {
355 fColorScheme
= new TimeGraphColorScheme();
356 fDataViewer
= new Composite(parent
, style
) {
358 public void redraw() {
359 fTimeScaleCtrl
.redraw();
360 fTimeGraphCtrl
.redraw();
364 GridLayout gl
= new GridLayout(2, false);
365 gl
.marginHeight
= fBorderWidth
;
367 gl
.verticalSpacing
= 0;
368 gl
.horizontalSpacing
= 0;
369 fDataViewer
.setLayout(gl
);
371 fTimeAlignedComposite
= new Composite(fDataViewer
, style
) {
373 public void redraw() {
374 fDataViewer
.redraw();
378 GridLayout gl2
= new GridLayout(1, false);
379 gl2
.marginHeight
= fBorderWidth
;
381 gl2
.verticalSpacing
= 0;
382 gl2
.horizontalSpacing
= 0;
383 fTimeAlignedComposite
.setLayout(gl2
);
384 fTimeAlignedComposite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
386 fTimeScaleCtrl
= new TimeGraphScale(fTimeAlignedComposite
, fColorScheme
);
387 fTimeScaleCtrl
.setTimeProvider(fTimeDataProvider
);
388 fTimeScaleCtrl
.setLayoutData(new GridData(SWT
.FILL
, SWT
.DEFAULT
, true, false));
389 fTimeScaleCtrl
.setHeight(fTimeScaleHeight
);
390 fTimeScaleCtrl
.addMouseWheelListener(new MouseWheelListener() {
392 public void mouseScrolled(MouseEvent e
) {
393 fTimeGraphCtrl
.zoom(e
.count
> 0);
397 fTimeGraphCtrl
= createTimeGraphControl(fTimeAlignedComposite
, fColorScheme
);
399 fTimeGraphCtrl
.setTimeProvider(this);
400 fTimeGraphCtrl
.setTimeGraphScale(fTimeScaleCtrl
);
401 fTimeGraphCtrl
.addSelectionListener(this);
402 fTimeGraphCtrl
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
403 fTimeGraphCtrl
.addMouseWheelListener(new MouseWheelListener() {
405 public void mouseScrolled(MouseEvent e
) {
406 adjustVerticalScrollBar();
409 fTimeGraphCtrl
.addKeyListener(new KeyAdapter() {
411 public void keyPressed(KeyEvent e
) {
412 if (e
.character
== '+') {
414 } else if (e
.character
== '-') {
417 adjustVerticalScrollBar();
421 fVerticalScrollBar
= new Slider(fDataViewer
, SWT
.VERTICAL
| SWT
.NO_FOCUS
);
422 fVerticalScrollBar
.setLayoutData(new GridData(SWT
.DEFAULT
, SWT
.FILL
, false, true, 1, 1));
423 fVerticalScrollBar
.addSelectionListener(new SelectionAdapter() {
425 public void widgetSelected(SelectionEvent e
) {
426 setTopIndex(fVerticalScrollBar
.getSelection());
430 fHorizontalScrollBar
= new Slider(fDataViewer
, SWT
.HORIZONTAL
| SWT
.NO_FOCUS
);
431 fHorizontalScrollBar
.setLayoutData(new GridData(SWT
.FILL
, SWT
.DEFAULT
, true, false));
432 fHorizontalScrollBar
.addListener(SWT
.MouseWheel
, new Listener() {
434 public void handleEvent(Event event
) {
435 if ((event
.stateMask
& SWT
.MODIFIER_MASK
) == SWT
.CTRL
) {
436 getTimeGraphControl().zoom(event
.count
> 0);
438 getTimeGraphControl().horizontalScroll(event
.count
> 0);
440 // don't handle the immediately following SWT.Selection event
444 fHorizontalScrollBar
.addListener(SWT
.Selection
, new Listener() {
446 public void handleEvent(Event event
) {
447 int start
= fHorizontalScrollBar
.getSelection();
448 long time0
= getTime0();
449 long time1
= getTime1();
450 long timeMin
= getMinTime();
451 long timeMax
= getMaxTime();
452 long delta
= timeMax
- timeMin
;
454 long range
= time1
- time0
;
455 time0
= timeMin
+ Math
.round(delta
* ((double) start
/ H_SCROLLBAR_MAX
));
456 time1
= time0
+ range
;
458 setStartFinishTimeNotify(time0
, time1
);
462 Composite filler
= new Composite(fDataViewer
, SWT
.NONE
);
463 GridData gd
= new GridData(SWT
.DEFAULT
, SWT
.DEFAULT
, false, false);
464 gd
.heightHint
= fHorizontalScrollBar
.getSize().y
;
465 filler
.setLayoutData(gd
);
466 filler
.setLayout(new FillLayout());
468 fTimeGraphCtrl
.addControlListener(new ControlAdapter() {
470 public void controlResized(ControlEvent event
) {
475 fDataViewer
.update();
476 adjustHorizontalScrollBar();
477 adjustVerticalScrollBar();
484 public void dispose() {
486 fTimeGraphCtrl
.dispose();
487 fDataViewer
.dispose();
488 fColorScheme
.dispose();
492 * Create a new time graph control.
495 * The parent composite
498 * @return The new TimeGraphControl
500 protected TimeGraphControl
createTimeGraphControl(Composite parent
,
501 TimeGraphColorScheme colors
) {
502 return new TimeGraphControl(parent
, colors
);
506 * Resize the controls
508 public void resizeControls() {
509 Rectangle r
= fDataViewer
.getClientArea();
515 if (fNameWidth
> width
- fMinNameWidth
) {
516 fNameWidth
= width
- fMinNameWidth
;
518 if (fNameWidth
< fMinNameWidth
) {
519 fNameWidth
= fMinNameWidth
;
521 adjustHorizontalScrollBar();
522 adjustVerticalScrollBar();
526 * Recalculate the time bounds based on the time graph entries,
527 * if the user-specified bound is set to SWT.DEFAULT.
530 * The root time graph entries in the model
532 public void setTimeRange(ITimeGraphEntry entries
[]) {
533 fTime0Bound
= (fBeginTime
!= SWT
.DEFAULT ? fBeginTime
: fEndTime
);
534 fTime1Bound
= (fEndTime
!= SWT
.DEFAULT ? fEndTime
: fBeginTime
);
535 if (fBeginTime
!= SWT
.DEFAULT
&& fEndTime
!= SWT
.DEFAULT
) {
538 if (entries
== null || entries
.length
== 0) {
541 if (fTime0Bound
== SWT
.DEFAULT
) {
542 fTime0Bound
= Long
.MAX_VALUE
;
544 if (fTime1Bound
== SWT
.DEFAULT
) {
545 fTime1Bound
= Long
.MIN_VALUE
;
547 for (ITimeGraphEntry entry
: entries
) {
552 private void setTimeRange(ITimeGraphEntry entry
) {
553 if (fBeginTime
== SWT
.DEFAULT
&& entry
.hasTimeEvents() && entry
.getStartTime() != SWT
.DEFAULT
) {
554 fTime0Bound
= Math
.min(entry
.getStartTime(), fTime0Bound
);
556 if (fEndTime
== SWT
.DEFAULT
&& entry
.hasTimeEvents() && entry
.getEndTime() != SWT
.DEFAULT
) {
557 fTime1Bound
= Math
.max(entry
.getEndTime(), fTime1Bound
);
559 if (entry
.hasChildren()) {
560 for (ITimeGraphEntry child
: entry
.getChildren()) {
567 * Set the time bounds to the provided values.
570 * The bounds begin time, or SWT.DEFAULT to use the input bounds
572 * The bounds end time, or SWT.DEFAULT to use the input bounds
574 public void setTimeBounds(long beginTime
, long endTime
) {
575 fBeginTime
= beginTime
;
577 fTime0Bound
= (fBeginTime
!= SWT
.DEFAULT ? fBeginTime
: fEndTime
);
578 fTime1Bound
= (fEndTime
!= SWT
.DEFAULT ? fEndTime
: fBeginTime
);
579 if (fTime0Bound
> fTime1Bound
) {
580 // only possible if both are not default
581 fBeginTime
= endTime
;
582 fEndTime
= beginTime
;
583 fTime0Bound
= fBeginTime
;
584 fTime1Bound
= fEndTime
;
586 adjustHorizontalScrollBar();
590 * Recalculate the current time window when bounds have changed.
592 public void setTimeBounds() {
593 if (!fTimeRangeFixed
) {
594 fTime0
= fTime0Bound
;
595 fTime1
= fTime1Bound
;
597 fTime0
= Math
.max(fTime0Bound
, Math
.min(fTime0
, fTime1Bound
));
598 fTime1
= Math
.max(fTime0Bound
, Math
.min(fTime1
, fTime1Bound
));
599 if (fTime1
- fTime0
< fMinTimeInterval
) {
600 fTime1
= Math
.min(fTime1Bound
, fTime0
+ fMinTimeInterval
);
607 private void refreshAllData(ITimeGraphEntry
[] traces
) {
609 if (fSelectionBegin
< fBeginTime
) {
610 fSelectionBegin
= fBeginTime
;
611 } else if (fSelectionBegin
> fEndTime
) {
612 fSelectionBegin
= fEndTime
;
614 if (fSelectionEnd
< fBeginTime
) {
615 fSelectionEnd
= fBeginTime
;
616 } else if (fSelectionEnd
> fEndTime
) {
617 fSelectionEnd
= fEndTime
;
619 fTimeGraphCtrl
.refreshData(traces
);
620 fTimeScaleCtrl
.redraw();
621 adjustVerticalScrollBar();
625 * Callback for when this view is focused
627 public void setFocus() {
628 if (null != fTimeGraphCtrl
) {
629 fTimeGraphCtrl
.setFocus();
634 * Get the current focus status of this view.
636 * @return If the view is currently focused, or not
638 public boolean isInFocus() {
639 return fTimeGraphCtrl
.isInFocus();
643 * Get the view's current selection
645 * @return The entry that is selected
647 public ITimeGraphEntry
getSelection() {
648 return fTimeGraphCtrl
.getSelectedTrace();
652 * Get the index of the current selection
656 public int getSelectionIndex() {
657 return fTimeGraphCtrl
.getSelectedIndex();
661 public long getTime0() {
666 public long getTime1() {
671 public long getMinTimeInterval() {
672 return fMinTimeInterval
;
676 public int getNameSpace() {
681 public void setNameSpace(int width
) {
683 int w
= fTimeGraphCtrl
.getClientArea().width
;
684 if (fNameWidth
> w
- MIN_NAME_WIDTH
) {
685 fNameWidth
= w
- MIN_NAME_WIDTH
;
687 if (fNameWidth
< MIN_NAME_WIDTH
) {
688 fNameWidth
= MIN_NAME_WIDTH
;
690 fTimeGraphCtrl
.redraw();
691 fTimeScaleCtrl
.redraw();
695 public int getTimeSpace() {
696 int w
= fTimeGraphCtrl
.getClientArea().width
;
697 return w
- fNameWidth
;
701 public long getBeginTime() {
706 public long getEndTime() {
711 public long getMaxTime() {
716 public long getMinTime() {
721 public long getSelectionBegin() {
722 return fSelectionBegin
;
726 public long getSelectionEnd() {
727 return fSelectionEnd
;
731 public void setStartFinishTimeNotify(long time0
, long time1
) {
732 setStartFinishTime(time0
, time1
);
733 notifyRangeListeners();
737 public void notifyStartFinishTime() {
738 notifyRangeListeners();
742 public void setStartFinishTime(long time0
, long time1
) {
744 if (fTime0
< fTime0Bound
) {
745 fTime0
= fTime0Bound
;
747 if (fTime0
> fTime1Bound
) {
748 fTime0
= fTime1Bound
;
751 if (fTime1
< fTime0Bound
) {
752 fTime1
= fTime0Bound
;
754 if (fTime1
> fTime1Bound
) {
755 fTime1
= fTime1Bound
;
757 if (fTime1
- fTime0
< fMinTimeInterval
) {
758 fTime1
= Math
.min(fTime1Bound
, fTime0
+ fMinTimeInterval
);
760 fTimeRangeFixed
= true;
761 adjustHorizontalScrollBar();
762 fTimeGraphCtrl
.redraw();
763 fTimeScaleCtrl
.redraw();
767 public void resetStartFinishTime() {
768 setStartFinishTime(fTime0Bound
, fTime1Bound
);
769 fTimeRangeFixed
= false;
773 public void setSelectedTimeNotify(long time
, boolean ensureVisible
) {
774 setSelectedTimeInt(time
, ensureVisible
, true);
778 public void setSelectedTime(long time
, boolean ensureVisible
) {
779 setSelectedTimeInt(time
, ensureVisible
, false);
783 public void setSelectionRangeNotify(long beginTime
, long endTime
) {
786 boolean changed
= (beginTime
!= fSelectionBegin
|| endTime
!= fSelectionEnd
);
787 fSelectionBegin
= Math
.max(fTime0Bound
, Math
.min(fTime1Bound
, beginTime
));
788 fSelectionEnd
= Math
.max(fTime0Bound
, Math
.min(fTime1Bound
, endTime
));
789 ensureVisible(fSelectionEnd
);
790 fTimeGraphCtrl
.redraw();
791 fTimeScaleCtrl
.redraw();
792 if ((time0
!= fTime0
) || (time1
!= fTime1
)) {
793 notifyRangeListeners();
796 notifyTimeListeners();
801 public void setSelectionRange(long beginTime
, long endTime
) {
802 fSelectionBegin
= Math
.max(fTime0Bound
, Math
.min(fTime1Bound
, beginTime
));
803 fSelectionEnd
= Math
.max(fTime0Bound
, Math
.min(fTime1Bound
, endTime
));
804 fTimeGraphCtrl
.redraw();
805 fTimeScaleCtrl
.redraw();
808 private void setSelectedTimeInt(long time
, boolean ensureVisible
, boolean doNotify
) {
814 fTimeGraphCtrl
.redraw();
815 fTimeScaleCtrl
.redraw();
817 boolean notifySelectedTime
= (time
!= fSelectionBegin
|| time
!= fSelectionEnd
);
818 fSelectionBegin
= time
;
819 fSelectionEnd
= time
;
821 if (doNotify
&& ((time0
!= fTime0
) || (time1
!= fTime1
))) {
822 notifyRangeListeners();
825 if (doNotify
&& notifySelectedTime
) {
826 notifyTimeListeners();
830 private void ensureVisible(long time
) {
831 long timeMid
= (fTime1
- fTime0
) / 2;
833 long dt
= fTime0
- time
+ timeMid
;
836 } else if (time
> fTime1
) {
837 long dt
= time
- fTime1
+ timeMid
;
841 if (fTime0
< fTime0Bound
) {
842 fTime1
= Math
.min(fTime1Bound
, fTime1
+ (fTime0Bound
- fTime0
));
843 fTime0
= fTime0Bound
;
844 } else if (fTime1
> fTime1Bound
) {
845 fTime0
= Math
.max(fTime0Bound
, fTime0
- (fTime1
- fTime1Bound
));
846 fTime1
= fTime1Bound
;
848 if (fTime1
- fTime0
< fMinTimeInterval
) {
849 fTime1
= Math
.min(fTime1Bound
, fTime0
+ fMinTimeInterval
);
851 adjustHorizontalScrollBar();
855 public void widgetDefaultSelected(SelectionEvent e
) {
856 if (fSelectedEntry
!= getSelection()) {
857 fSelectedEntry
= getSelection();
858 notifySelectionListeners();
863 public void widgetSelected(SelectionEvent e
) {
864 if (fSelectedEntry
!= getSelection()) {
865 fSelectedEntry
= getSelection();
866 notifySelectionListeners();
871 * Callback for when the next event is selected
874 * true to extend selection range, false for single selection
877 public void selectNextEvent(boolean extend
) {
878 fTimeGraphCtrl
.selectNextEvent(extend
);
879 adjustVerticalScrollBar();
883 * Callback for when the previous event is selected
886 * true to extend selection range, false for single selection
889 public void selectPrevEvent(boolean extend
) {
890 fTimeGraphCtrl
.selectPrevEvent(extend
);
891 adjustVerticalScrollBar();
895 * Callback for when the next item is selected
897 public void selectNextItem() {
898 fTimeGraphCtrl
.selectNextTrace();
899 adjustVerticalScrollBar();
903 * Callback for when the previous item is selected
905 public void selectPrevItem() {
906 fTimeGraphCtrl
.selectPrevTrace();
907 adjustVerticalScrollBar();
911 * Callback for the show legend action
913 public void showLegend() {
914 if (fDataViewer
== null || fDataViewer
.isDisposed()) {
918 TimeGraphLegend
.open(fDataViewer
.getShell(), fTimeGraphProvider
);
922 * Callback for the Zoom In action
924 public void zoomIn() {
925 fTimeGraphCtrl
.zoomIn();
929 * Callback for the Zoom Out action
931 public void zoomOut() {
932 fTimeGraphCtrl
.zoomOut();
935 private String
getPreferenceString(String string
) {
936 return getViewTypeStr() + "." + string
; //$NON-NLS-1$
940 * Add a selection listener
943 * The listener to add
945 public void addSelectionListener(ITimeGraphSelectionListener listener
) {
946 fSelectionListeners
.add(listener
);
950 * Remove a selection listener
953 * The listener to remove
955 public void removeSelectionListener(ITimeGraphSelectionListener listener
) {
956 fSelectionListeners
.remove(listener
);
959 private void notifySelectionListeners() {
960 synchronized (fListenerNotifierLock
) {
961 if (fListenerNotifier
== null) {
962 fListenerNotifier
= new ListenerNotifier();
963 fListenerNotifier
.start();
965 fListenerNotifier
.selectionChanged();
969 private void fireSelectionChanged(ITimeGraphEntry selection
) {
970 TimeGraphSelectionEvent event
= new TimeGraphSelectionEvent(this, selection
);
972 for (ITimeGraphSelectionListener listener
: fSelectionListeners
) {
973 listener
.selectionChanged(event
);
978 * Add a time listener
981 * The listener to add
983 public void addTimeListener(ITimeGraphTimeListener listener
) {
984 fTimeListeners
.add(listener
);
988 * Remove a time listener
991 * The listener to remove
993 public void removeTimeListener(ITimeGraphTimeListener listener
) {
994 fTimeListeners
.remove(listener
);
997 private void notifyTimeListeners() {
998 synchronized (fListenerNotifierLock
) {
999 if (fListenerNotifier
== null) {
1000 fListenerNotifier
= new ListenerNotifier();
1001 fListenerNotifier
.start();
1003 fListenerNotifier
.timeSelected();
1007 private void fireTimeSelected(long startTime
, long endTime
) {
1008 TimeGraphTimeEvent event
= new TimeGraphTimeEvent(this, startTime
, endTime
);
1010 for (ITimeGraphTimeListener listener
: fTimeListeners
) {
1011 listener
.timeSelected(event
);
1016 * Add a range listener
1019 * The listener to add
1021 public void addRangeListener(ITimeGraphRangeListener listener
) {
1022 fRangeListeners
.add(listener
);
1026 * Remove a range listener
1029 * The listener to remove
1031 public void removeRangeListener(ITimeGraphRangeListener listener
) {
1032 fRangeListeners
.remove(listener
);
1035 private void notifyRangeListeners() {
1036 synchronized (fListenerNotifierLock
) {
1037 if (fListenerNotifier
== null) {
1038 fListenerNotifier
= new ListenerNotifier();
1039 fListenerNotifier
.start();
1041 fListenerNotifier
.timeRangeUpdated();
1045 private void fireTimeRangeUpdated(long startTime
, long endTime
) {
1046 // Check if the time has actually changed from last notification
1047 if (startTime
!= fTime0ExtSynch
|| endTime
!= fTime1ExtSynch
) {
1048 // Notify Time Scale Selection Listeners
1049 TimeGraphRangeUpdateEvent event
= new TimeGraphRangeUpdateEvent(this, startTime
, endTime
);
1051 for (ITimeGraphRangeListener listener
: fRangeListeners
) {
1052 listener
.timeRangeUpdated(event
);
1055 // update external synch timers
1056 updateExtSynchTimers();
1061 * Callback to set a selected event in the view
1064 * The event that was selected
1066 * The source of this selection event
1068 public void setSelectedEvent(ITimeEvent event
, Object source
) {
1069 if (event
== null || source
== this) {
1072 fSelectedEntry
= event
.getEntry();
1073 fTimeGraphCtrl
.selectItem(fSelectedEntry
, false);
1075 setSelectedTimeInt(event
.getTime(), true, true);
1076 adjustVerticalScrollBar();
1080 * Set the seeked time of a trace
1083 * The trace that was seeked
1087 * The source of this seek event
1089 public void setSelectedTraceTime(ITimeGraphEntry trace
, long time
, Object source
) {
1090 if (trace
== null || source
== this) {
1093 fSelectedEntry
= trace
;
1094 fTimeGraphCtrl
.selectItem(trace
, false);
1096 setSelectedTimeInt(time
, true, true);
1100 * Callback for a trace selection
1103 * The trace that was selected
1105 public void setSelection(ITimeGraphEntry trace
) {
1106 fSelectedEntry
= trace
;
1107 fTimeGraphCtrl
.selectItem(trace
, false);
1108 adjustVerticalScrollBar();
1112 * Callback for a time window selection
1115 * Start time of the range
1117 * End time of the range
1119 * Source of the event
1121 public void setSelectVisTimeWindow(long time0
, long time1
, Object source
) {
1122 if (source
== this) {
1126 setStartFinishTime(time0
, time1
);
1128 // update notification time values since we are now in synch with the
1129 // external application
1130 updateExtSynchTimers();
1134 * update the cache timers used to identify the need to send a time window
1135 * update to external registered listeners
1137 private void updateExtSynchTimers() {
1138 // last time notification cache
1139 fTime0ExtSynch
= fTime0
;
1140 fTime1ExtSynch
= fTime1
;
1144 public TimeFormat
getTimeFormat() {
1150 * the {@link TimeFormat} used to display timestamps
1152 public void setTimeFormat(TimeFormat tf
) {
1153 this.fTimeFormat
= tf
;
1154 if (tf
== TimeFormat
.CYCLES
) {
1155 fTimeDataProvider
= new TimeDataProviderCyclesConverter(this, fClockFrequency
);
1157 fTimeDataProvider
= this;
1159 fTimeScaleCtrl
.setTimeProvider(fTimeDataProvider
);
1160 if (fToolTipHandler
!= null) {
1161 fToolTipHandler
.setTimeProvider(fTimeDataProvider
);
1166 * Sets the clock frequency. Used when the time format is set to CYCLES.
1168 * @param clockFrequency
1169 * the clock frequency in Hz
1171 public void setClockFrequency(long clockFrequency
) {
1172 fClockFrequency
= clockFrequency
;
1173 if (fTimeFormat
== TimeFormat
.CYCLES
) {
1174 fTimeDataProvider
= new TimeDataProviderCyclesConverter(this, fClockFrequency
);
1175 fTimeScaleCtrl
.setTimeProvider(fTimeDataProvider
);
1176 if (fToolTipHandler
!= null) {
1177 fToolTipHandler
.setTimeProvider(fTimeDataProvider
);
1183 * Retrieve the border width
1187 public int getBorderWidth() {
1188 return fBorderWidth
;
1192 * Set the border width
1194 * @param borderWidth
1197 public void setBorderWidth(int borderWidth
) {
1198 if (borderWidth
> -1) {
1199 this.fBorderWidth
= borderWidth
;
1200 GridLayout gl
= (GridLayout
) fDataViewer
.getLayout();
1201 gl
.marginHeight
= borderWidth
;
1206 * Retrieve the height of the header
1208 * @return The height
1210 public int getHeaderHeight() {
1211 return fTimeScaleHeight
;
1215 * Set the height of the header
1217 * @param headerHeight
1220 public void setHeaderHeight(int headerHeight
) {
1221 if (headerHeight
> -1) {
1222 this.fTimeScaleHeight
= headerHeight
;
1223 fTimeScaleCtrl
.setHeight(headerHeight
);
1228 * Retrieve the height of an item row
1230 * @return The height
1232 public int getItemHeight() {
1233 if (fTimeGraphCtrl
!= null) {
1234 return fTimeGraphCtrl
.getItemHeight();
1240 * Set the height of an item row
1245 public void setItemHeight(int rowHeight
) {
1246 if (fTimeGraphCtrl
!= null) {
1247 fTimeGraphCtrl
.setItemHeight(rowHeight
);
1252 * Set the minimum item width
1257 public void setMinimumItemWidth(int width
) {
1258 if (fTimeGraphCtrl
!= null) {
1259 fTimeGraphCtrl
.setMinimumItemWidth(width
);
1264 * Set the width for the name column
1269 public void setNameWidthPref(int width
) {
1270 fNameWidthPref
= width
;
1278 * Retrieve the configure width for the name column
1284 public int getNameWidthPref(int width
) {
1285 return fNameWidthPref
;
1289 * Returns the primary control associated with this viewer.
1291 * @return the SWT control which displays this viewer's content
1293 public Control
getControl() {
1298 * Returns the time graph control associated with this viewer.
1300 * @return the time graph control
1302 public TimeGraphControl
getTimeGraphControl() {
1303 return fTimeGraphCtrl
;
1307 * Returns the time graph scale associated with this viewer.
1309 * @return the time graph scale
1311 public TimeGraphScale
getTimeGraphScale() {
1312 return fTimeScaleCtrl
;
1316 * Returns the composite containing all the controls that are time aligned,
1317 * i.e. TimeGraphScale, TimeGraphControl.
1319 * @return the time based composite
1322 public Composite
getTimeAlignedComposite() {
1323 return fTimeAlignedComposite
;
1327 * Return the x coordinate corresponding to a time
1331 * @return the x coordinate corresponding to the time
1333 public int getXForTime(long time
) {
1334 return fTimeGraphCtrl
.getXForTime(time
);
1338 * Return the time corresponding to an x coordinate
1342 * @return the time corresponding to the x coordinate
1344 public long getTimeAtX(int x
) {
1345 return fTimeGraphCtrl
.getTimeAtX(x
);
1349 * Get the selection provider
1351 * @return the selection provider
1353 public ISelectionProvider
getSelectionProvider() {
1354 return fTimeGraphCtrl
;
1358 * Wait for the cursor
1361 * Wait indefinitely?
1363 public void waitCursor(boolean waitInd
) {
1364 fTimeGraphCtrl
.waitCursor(waitInd
);
1368 * Get the horizontal scroll bar object
1370 * @return The scroll bar
1372 public Slider
getHorizontalBar() {
1373 return fHorizontalScrollBar
;
1377 * Get the vertical scroll bar object
1379 * @return The scroll bar
1381 public Slider
getVerticalBar() {
1382 return fVerticalScrollBar
;
1386 * Set the given index as the top one
1389 * The index that will go to the top
1391 public void setTopIndex(int index
) {
1392 fTimeGraphCtrl
.setTopIndex(index
);
1393 adjustVerticalScrollBar();
1397 * Retrieve the current top index
1399 * @return The top index
1401 public int getTopIndex() {
1402 return fTimeGraphCtrl
.getTopIndex();
1406 * Sets the auto-expand level to be used when the input of the viewer is set
1407 * using {@link #setInput(Object)}. The value 0 means that there is no
1408 * auto-expand; 1 means that top-level elements are expanded, but not their
1409 * children; 2 means that top-level elements are expanded, and their
1410 * children, but not grand-children; and so on.
1412 * The value {@link #ALL_LEVELS} means that all subtrees should be expanded.
1415 * non-negative level, or <code>ALL_LEVELS</code> to expand all
1416 * levels of the tree
1418 public void setAutoExpandLevel(int level
) {
1419 fTimeGraphCtrl
.setAutoExpandLevel(level
);
1423 * Returns the auto-expand level.
1425 * @return non-negative level, or <code>ALL_LEVELS</code> if all levels of
1426 * the tree are expanded automatically
1427 * @see #setAutoExpandLevel
1429 public int getAutoExpandLevel() {
1430 return fTimeGraphCtrl
.getAutoExpandLevel();
1434 * Set the expanded state of an entry
1437 * The entry to expand/collapse
1439 * True for expanded, false for collapsed
1441 public void setExpandedState(ITimeGraphEntry entry
, boolean expanded
) {
1442 fTimeGraphCtrl
.setExpandedState(entry
, expanded
);
1443 adjustVerticalScrollBar();
1447 * Collapses all nodes of the viewer's tree, starting with the root.
1449 public void collapseAll() {
1450 fTimeGraphCtrl
.collapseAll();
1451 adjustVerticalScrollBar();
1455 * Expands all nodes of the viewer's tree, starting with the root.
1457 public void expandAll() {
1458 fTimeGraphCtrl
.expandAll();
1459 adjustVerticalScrollBar();
1463 * Get the number of sub-elements when expanded
1465 * @return The element count
1467 public int getExpandedElementCount() {
1468 return fTimeGraphCtrl
.getExpandedElementCount();
1472 * Get the sub-elements
1474 * @return The array of entries that are below this one
1476 public ITimeGraphEntry
[] getExpandedElements() {
1477 return fTimeGraphCtrl
.getExpandedElements();
1481 * Add a tree listener
1484 * The listener to add
1486 public void addTreeListener(ITimeGraphTreeListener listener
) {
1487 fTimeGraphCtrl
.addTreeListener(listener
);
1491 * Remove a tree listener
1494 * The listener to remove
1496 public void removeTreeListener(ITimeGraphTreeListener listener
) {
1497 fTimeGraphCtrl
.removeTreeListener(listener
);
1501 * Get the reset scale action.
1503 * @return The Action object
1505 public Action
getResetScaleAction() {
1506 if (fResetScaleAction
== null) {
1508 fResetScaleAction
= new Action() {
1511 resetStartFinishTime();
1512 notifyStartFinishTime();
1515 fResetScaleAction
.setText(Messages
.TmfTimeGraphViewer_ResetScaleActionNameText
);
1516 fResetScaleAction
.setToolTipText(Messages
.TmfTimeGraphViewer_ResetScaleActionToolTipText
);
1517 fResetScaleAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_HOME_MENU
));
1519 return fResetScaleAction
;
1523 * Get the show legend action.
1525 * @return The Action object
1527 public Action
getShowLegendAction() {
1528 if (fShowLegendAction
== null) {
1530 fShowLegendAction
= new Action() {
1536 fShowLegendAction
.setText(Messages
.TmfTimeGraphViewer_LegendActionNameText
);
1537 fShowLegendAction
.setToolTipText(Messages
.TmfTimeGraphViewer_LegendActionToolTipText
);
1538 fShowLegendAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_SHOW_LEGEND
));
1541 return fShowLegendAction
;
1545 * Get the the next event action.
1547 * @return The action object
1549 public Action
getNextEventAction() {
1550 if (fNextEventAction
== null) {
1551 fNextEventAction
= new Action() {
1553 public void runWithEvent(Event event
) {
1554 boolean extend
= (event
.stateMask
& SWT
.SHIFT
) != 0;
1555 selectNextEvent(extend
);
1559 fNextEventAction
.setText(Messages
.TmfTimeGraphViewer_NextEventActionNameText
);
1560 fNextEventAction
.setToolTipText(Messages
.TmfTimeGraphViewer_NextEventActionToolTipText
);
1561 fNextEventAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_NEXT_EVENT
));
1564 return fNextEventAction
;
1568 * Get the previous event action.
1570 * @return The Action object
1572 public Action
getPreviousEventAction() {
1573 if (fPrevEventAction
== null) {
1574 fPrevEventAction
= new Action() {
1576 public void runWithEvent(Event event
) {
1577 boolean extend
= (event
.stateMask
& SWT
.SHIFT
) != 0;
1578 selectPrevEvent(extend
);
1582 fPrevEventAction
.setText(Messages
.TmfTimeGraphViewer_PreviousEventActionNameText
);
1583 fPrevEventAction
.setToolTipText(Messages
.TmfTimeGraphViewer_PreviousEventActionToolTipText
);
1584 fPrevEventAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_PREV_EVENT
));
1587 return fPrevEventAction
;
1591 * Get the next item action.
1593 * @return The Action object
1595 public Action
getNextItemAction() {
1596 if (fNextItemAction
== null) {
1598 fNextItemAction
= new Action() {
1604 fNextItemAction
.setText(Messages
.TmfTimeGraphViewer_NextItemActionNameText
);
1605 fNextItemAction
.setToolTipText(Messages
.TmfTimeGraphViewer_NextItemActionToolTipText
);
1606 fNextItemAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_NEXT_ITEM
));
1608 return fNextItemAction
;
1612 * Get the previous item action.
1614 * @return The Action object
1616 public Action
getPreviousItemAction() {
1617 if (fPreviousItemAction
== null) {
1619 fPreviousItemAction
= new Action() {
1625 fPreviousItemAction
.setText(Messages
.TmfTimeGraphViewer_PreviousItemActionNameText
);
1626 fPreviousItemAction
.setToolTipText(Messages
.TmfTimeGraphViewer_PreviousItemActionToolTipText
);
1627 fPreviousItemAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_PREV_ITEM
));
1629 return fPreviousItemAction
;
1633 * Get the zoom in action
1635 * @return The Action object
1637 public Action
getZoomInAction() {
1638 if (fZoomInAction
== null) {
1639 fZoomInAction
= new Action() {
1645 fZoomInAction
.setText(Messages
.TmfTimeGraphViewer_ZoomInActionNameText
);
1646 fZoomInAction
.setToolTipText(Messages
.TmfTimeGraphViewer_ZoomInActionToolTipText
);
1647 fZoomInAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_ZOOM_IN_MENU
));
1649 return fZoomInAction
;
1653 * Get the zoom out action
1655 * @return The Action object
1657 public Action
getZoomOutAction() {
1658 if (fZoomOutAction
== null) {
1659 fZoomOutAction
= new Action() {
1665 fZoomOutAction
.setText(Messages
.TmfTimeGraphViewer_ZoomOutActionNameText
);
1666 fZoomOutAction
.setToolTipText(Messages
.TmfTimeGraphViewer_ZoomOutActionToolTipText
);
1667 fZoomOutAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_ZOOM_OUT_MENU
));
1669 return fZoomOutAction
;
1673 * Get the hide arrows action
1675 * @param dialogSettings
1676 * The dialog settings section where the state should be stored,
1679 * @return The Action object
1681 public Action
getHideArrowsAction(final IDialogSettings dialogSettings
) {
1682 if (fHideArrowsAction
== null) {
1683 fHideArrowsAction
= new Action(Messages
.TmfTimeGraphViewer_HideArrowsActionNameText
, IAction
.AS_CHECK_BOX
) {
1686 boolean hideArrows
= fHideArrowsAction
.isChecked();
1687 fTimeGraphCtrl
.hideArrows(hideArrows
);
1689 if (dialogSettings
!= null) {
1690 dialogSettings
.put(HIDE_ARROWS_KEY
, hideArrows
);
1692 if (fFollowArrowFwdAction
!= null) {
1693 fFollowArrowFwdAction
.setEnabled(!hideArrows
);
1695 if (fFollowArrowBwdAction
!= null) {
1696 fFollowArrowBwdAction
.setEnabled(!hideArrows
);
1700 fHideArrowsAction
.setToolTipText(Messages
.TmfTimeGraphViewer_HideArrowsActionToolTipText
);
1701 fHideArrowsAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_HIDE_ARROWS
));
1702 if (dialogSettings
!= null) {
1703 boolean hideArrows
= dialogSettings
.getBoolean(HIDE_ARROWS_KEY
);
1704 fTimeGraphCtrl
.hideArrows(hideArrows
);
1705 fHideArrowsAction
.setChecked(hideArrows
);
1706 if (fFollowArrowFwdAction
!= null) {
1707 fFollowArrowFwdAction
.setEnabled(!hideArrows
);
1709 if (fFollowArrowBwdAction
!= null) {
1710 fFollowArrowBwdAction
.setEnabled(!hideArrows
);
1714 return fHideArrowsAction
;
1718 * Get the follow arrow forward action.
1720 * @return The Action object
1722 public Action
getFollowArrowFwdAction() {
1723 if (fFollowArrowFwdAction
== null) {
1724 fFollowArrowFwdAction
= new Action() {
1726 public void runWithEvent(Event event
) {
1727 boolean extend
= (event
.stateMask
& SWT
.SHIFT
) != 0;
1728 fTimeGraphCtrl
.followArrowFwd(extend
);
1729 adjustVerticalScrollBar();
1732 fFollowArrowFwdAction
.setText(Messages
.TmfTimeGraphViewer_FollowArrowForwardActionNameText
);
1733 fFollowArrowFwdAction
.setToolTipText(Messages
.TmfTimeGraphViewer_FollowArrowForwardActionToolTipText
);
1734 fFollowArrowFwdAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_FOLLOW_ARROW_FORWARD
));
1735 if (fHideArrowsAction
!= null) {
1736 fFollowArrowFwdAction
.setEnabled(!fHideArrowsAction
.isChecked());
1739 return fFollowArrowFwdAction
;
1743 * Get the follow arrow backward action.
1745 * @return The Action object
1747 public Action
getFollowArrowBwdAction() {
1748 if (fFollowArrowBwdAction
== null) {
1749 fFollowArrowBwdAction
= new Action() {
1751 public void runWithEvent(Event event
) {
1752 boolean extend
= (event
.stateMask
& SWT
.SHIFT
) != 0;
1753 fTimeGraphCtrl
.followArrowBwd(extend
);
1754 adjustVerticalScrollBar();
1757 fFollowArrowBwdAction
.setText(Messages
.TmfTimeGraphViewer_FollowArrowBackwardActionNameText
);
1758 fFollowArrowBwdAction
.setToolTipText(Messages
.TmfTimeGraphViewer_FollowArrowBackwardActionToolTipText
);
1759 fFollowArrowBwdAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_FOLLOW_ARROW_BACKWARD
));
1760 if (fHideArrowsAction
!= null) {
1761 fFollowArrowBwdAction
.setEnabled(!fHideArrowsAction
.isChecked());
1764 return fFollowArrowBwdAction
;
1767 private void adjustHorizontalScrollBar() {
1768 long time0
= getTime0();
1769 long time1
= getTime1();
1770 long timeMin
= getMinTime();
1771 long timeMax
= getMaxTime();
1772 long delta
= timeMax
- timeMin
;
1774 int thumb
= H_SCROLLBAR_MAX
;
1776 // Thumb size (page size)
1777 thumb
= Math
.max(1, (int) (H_SCROLLBAR_MAX
* ((double) (time1
- time0
) / delta
)));
1778 // At the beginning of visible window
1779 timePos
= (int) (H_SCROLLBAR_MAX
* ((double) (time0
- timeMin
) / delta
));
1781 fHorizontalScrollBar
.setValues(timePos
, 0, H_SCROLLBAR_MAX
, thumb
, Math
.max(1, thumb
/ 2), Math
.max(2, thumb
));
1784 private void adjustVerticalScrollBar() {
1785 int topIndex
= fTimeGraphCtrl
.getTopIndex();
1786 int countPerPage
= fTimeGraphCtrl
.countPerPage();
1787 int expandedElementCount
= fTimeGraphCtrl
.getExpandedElementCount();
1788 if (topIndex
+ countPerPage
> expandedElementCount
) {
1789 fTimeGraphCtrl
.setTopIndex(Math
.max(0, expandedElementCount
- countPerPage
));
1792 int selection
= fTimeGraphCtrl
.getTopIndex();
1794 int max
= Math
.max(1, expandedElementCount
- 1);
1795 int thumb
= Math
.min(max
, Math
.max(1, countPerPage
- 1));
1797 int pageIncrement
= Math
.max(1, countPerPage
);
1798 fVerticalScrollBar
.setValues(selection
, min
, max
, thumb
, increment
, pageIncrement
);
1803 * a {@link MenuDetectListener}
1804 * @see org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.TimeGraphControl#addTimeGraphEntryMenuListener(org.eclipse.swt.events.MenuDetectListener)
1806 public void addTimeGraphEntryMenuListener(MenuDetectListener listener
) {
1807 fTimeGraphCtrl
.addTimeGraphEntryMenuListener(listener
);
1812 * a {@link MenuDetectListener}
1813 * @see org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.TimeGraphControl#removeTimeGraphEntryMenuListener(org.eclipse.swt.events.MenuDetectListener)
1815 public void removeTimeGraphEntryMenuListener(MenuDetectListener listener
) {
1816 fTimeGraphCtrl
.removeTimeGraphEntryMenuListener(listener
);
1821 * a {@link MenuDetectListener}
1822 * @see org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.TimeGraphControl#addTimeEventMenuListener(org.eclipse.swt.events.MenuDetectListener)
1824 public void addTimeEventMenuListener(MenuDetectListener listener
) {
1825 fTimeGraphCtrl
.addTimeEventMenuListener(listener
);
1830 * a {@link MenuDetectListener}
1831 * @see org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.TimeGraphControl#removeTimeEventMenuListener(org.eclipse.swt.events.MenuDetectListener)
1833 public void removeTimeEventMenuListener(MenuDetectListener listener
) {
1834 fTimeGraphCtrl
.removeTimeEventMenuListener(listener
);
1839 * The filter object to be attached to the view
1841 public void addFilter(ViewerFilter filter
) {
1842 fTimeGraphCtrl
.addFilter(filter
);
1848 * The filter object to be attached to the view
1850 public void removeFilter(ViewerFilter filter
) {
1851 fTimeGraphCtrl
.removeFilter(filter
);
1856 * Return the time alignment information
1858 * @return the time alignment information
1860 * @see ITmfTimeAligned
1864 public TmfTimeViewAlignmentInfo
getTimeViewAlignmentInfo() {
1865 return fTimeGraphCtrl
.getTimeViewAlignmentInfo();
1869 * Return the available width for the time-axis.
1871 * @see ITmfTimeAligned
1873 * @param requestedOffset
1874 * the requested offset
1875 * @return the available width for the time-axis
1879 public int getAvailableWidth(int requestedOffset
) {
1880 int totalWidth
= fTimeAlignedComposite
.getSize().x
;
1881 return Math
.min(totalWidth
, Math
.max(0, totalWidth
- requestedOffset
));
1885 * Perform the alignment operation.
1888 * the alignment offset
1890 * the alignment width
1892 * @see ITmfTimeAligned
1896 public void performAlign(int offset
, int width
) {
1897 fTimeGraphCtrl
.performAlign(offset
);
1898 int alignmentWidth
= width
;
1899 int size
= fTimeAlignedComposite
.getSize().x
;
1900 GridLayout layout
= (GridLayout
) fTimeAlignedComposite
.getLayout();
1901 int marginSize
= size
- alignmentWidth
- offset
;
1902 layout
.marginRight
= Math
.max(0, marginSize
);
1903 fTimeAlignedComposite
.layout();