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
.ITableLabelProvider
;
28 import org
.eclipse
.jface
.viewers
.ITreeContentProvider
;
29 import org
.eclipse
.jface
.viewers
.ViewerFilter
;
30 import org
.eclipse
.swt
.SWT
;
31 import org
.eclipse
.swt
.events
.ControlAdapter
;
32 import org
.eclipse
.swt
.events
.ControlEvent
;
33 import org
.eclipse
.swt
.events
.KeyAdapter
;
34 import org
.eclipse
.swt
.events
.KeyEvent
;
35 import org
.eclipse
.swt
.events
.MenuDetectListener
;
36 import org
.eclipse
.swt
.events
.MouseEvent
;
37 import org
.eclipse
.swt
.events
.MouseWheelListener
;
38 import org
.eclipse
.swt
.events
.SelectionAdapter
;
39 import org
.eclipse
.swt
.events
.SelectionEvent
;
40 import org
.eclipse
.swt
.events
.SelectionListener
;
41 import org
.eclipse
.swt
.graphics
.Rectangle
;
42 import org
.eclipse
.swt
.layout
.FillLayout
;
43 import org
.eclipse
.swt
.layout
.GridData
;
44 import org
.eclipse
.swt
.layout
.GridLayout
;
45 import org
.eclipse
.swt
.widgets
.Composite
;
46 import org
.eclipse
.swt
.widgets
.Control
;
47 import org
.eclipse
.swt
.widgets
.Display
;
48 import org
.eclipse
.swt
.widgets
.Event
;
49 import org
.eclipse
.swt
.widgets
.Listener
;
50 import org
.eclipse
.swt
.widgets
.Slider
;
51 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.Activator
;
52 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.ITmfImageConstants
;
53 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.Messages
;
54 import org
.eclipse
.tracecompass
.tmf
.ui
.signal
.TmfTimeViewAlignmentInfo
;
55 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.ITmfTimeAligned
;
56 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.dialogs
.ShowFilterDialogAction
;
57 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.dialogs
.TimeGraphLegend
;
58 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.ILinkEvent
;
59 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.ITimeEvent
;
60 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.ITimeGraphEntry
;
61 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.widgets
.ITimeDataProvider
;
62 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.widgets
.TimeDataProviderCyclesConverter
;
63 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.widgets
.TimeGraphColorScheme
;
64 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.widgets
.TimeGraphControl
;
65 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.widgets
.TimeGraphScale
;
66 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.widgets
.TimeGraphTooltipHandler
;
67 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.widgets
.Utils
;
68 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.widgets
.Utils
.TimeFormat
;
71 * Generic time graph viewer implementation
73 * @author Patrick Tasse, and others
75 public class TimeGraphViewer
implements ITimeDataProvider
, SelectionListener
{
77 /** Constant indicating that all levels of the time graph should be expanded */
78 public static final int ALL_LEVELS
= AbstractTreeViewer
.ALL_LEVELS
;
80 private static final int DEFAULT_NAME_WIDTH
= 200;
81 private static final int MIN_NAME_WIDTH
= 6;
82 private static final int MAX_NAME_WIDTH
= 1000;
83 private static final int DEFAULT_HEIGHT
= 22;
84 private static final String HIDE_ARROWS_KEY
= "hide.arrows"; //$NON-NLS-1$
85 private static final long DEFAULT_FREQUENCY
= 1000000000L;
86 private static final int H_SCROLLBAR_MAX
= Integer
.MAX_VALUE
- 1;
88 private long fMinTimeInterval
;
89 private ITimeGraphEntry fSelectedEntry
;
90 private long fBeginTime
= SWT
.DEFAULT
; // The user-specified bounds start time
91 private long fEndTime
= SWT
.DEFAULT
; // The user-specified bounds end time
92 private long fTime0
= SWT
.DEFAULT
; // The current window start time
93 private long fTime1
= SWT
.DEFAULT
; // The current window end time
94 private long fSelectionBegin
= SWT
.DEFAULT
;
95 private long fSelectionEnd
= SWT
.DEFAULT
;
96 private long fTime0Bound
= SWT
.DEFAULT
; // The bounds start time
97 private long fTime1Bound
= SWT
.DEFAULT
; // The bounds end time
98 private long fTime0ExtSynch
= SWT
.DEFAULT
;
99 private long fTime1ExtSynch
= SWT
.DEFAULT
;
100 private boolean fTimeRangeFixed
;
101 private int fNameWidthPref
= DEFAULT_NAME_WIDTH
;
102 private int fMinNameWidth
= MIN_NAME_WIDTH
;
103 private int fNameWidth
;
104 private Composite fDataViewer
;
106 private TimeGraphControl fTimeGraphCtrl
;
107 private TimeGraphScale fTimeScaleCtrl
;
108 private Slider fHorizontalScrollBar
;
109 private Slider fVerticalScrollBar
;
110 private TimeGraphColorScheme fColorScheme
;
111 private Object fInputElement
;
112 private ITimeGraphContentProvider fTimeGraphContentProvider
;
113 private ITimeGraphPresentationProvider fTimeGraphProvider
;
114 private ITimeDataProvider fTimeDataProvider
= this;
115 private TimeGraphTooltipHandler fToolTipHandler
;
117 private List
<ITimeGraphSelectionListener
> fSelectionListeners
= new ArrayList
<>();
118 private List
<ITimeGraphTimeListener
> fTimeListeners
= new ArrayList
<>();
119 private List
<ITimeGraphRangeListener
> fRangeListeners
= new ArrayList
<>();
121 // Time format, using Epoch reference, Relative time format(default),
123 private TimeFormat fTimeFormat
= TimeFormat
.RELATIVE
;
124 // Clock frequency to use for Cycles time format
125 private long fClockFrequency
= DEFAULT_FREQUENCY
;
126 private int fBorderWidth
= 0;
127 private int fTimeScaleHeight
= DEFAULT_HEIGHT
;
129 private Action fResetScaleAction
;
130 private Action fShowLegendAction
;
131 private Action fNextEventAction
;
132 private Action fPrevEventAction
;
133 private Action fNextItemAction
;
134 private Action fPreviousItemAction
;
135 private Action fZoomInAction
;
136 private Action fZoomOutAction
;
137 private Action fHideArrowsAction
;
138 private Action fFollowArrowFwdAction
;
139 private Action fFollowArrowBwdAction
;
140 private ShowFilterDialogAction fShowFilterDialogAction
;
142 private ListenerNotifier fListenerNotifier
;
144 private Composite fTimeAlignedComposite
;
146 private class ListenerNotifier
extends Thread
{
147 private static final long DELAY
= 400L;
148 private static final long POLLING_INTERVAL
= 10L;
149 private long fLastUpdateTime
= Long
.MAX_VALUE
;
150 private boolean fSelectionChanged
= false;
151 private boolean fTimeRangeUpdated
= false;
152 private boolean fTimeSelected
= false;
156 while ((System
.currentTimeMillis() - fLastUpdateTime
) < DELAY
) {
158 Thread
.sleep(POLLING_INTERVAL
);
159 } catch (Exception e
) {
163 Display
.getDefault().asyncExec(new Runnable() {
166 if (fListenerNotifier
!= ListenerNotifier
.this) {
169 fListenerNotifier
= null;
170 if (ListenerNotifier
.this.isInterrupted() || fDataViewer
.isDisposed()) {
173 if (fSelectionChanged
) {
174 fireSelectionChanged(fSelectedEntry
);
176 if (fTimeRangeUpdated
) {
177 fireTimeRangeUpdated(fTime0
, fTime1
);
180 fireTimeSelected(fSelectionBegin
, fSelectionEnd
);
186 public void selectionChanged() {
187 fSelectionChanged
= true;
188 fLastUpdateTime
= System
.currentTimeMillis();
191 public void timeRangeUpdated() {
192 fTimeRangeUpdated
= true;
193 fLastUpdateTime
= System
.currentTimeMillis();
196 public void timeSelected() {
197 fTimeSelected
= true;
198 fLastUpdateTime
= System
.currentTimeMillis();
201 public boolean hasSelectionChanged() {
202 return fSelectionChanged
;
205 public boolean hasTimeRangeUpdated() {
206 return fTimeRangeUpdated
;
209 public boolean hasTimeSelected() {
210 return fTimeSelected
;
215 * Standard constructor.
217 * The default timegraph content provider accepts an ITimeGraphEntry[] as input element.
220 * The parent UI composite object
224 public TimeGraphViewer(Composite parent
, int style
) {
225 createDataViewer(parent
, style
);
226 fTimeGraphContentProvider
= new TimeGraphContentProvider();
230 * Sets the timegraph content provider used by this timegraph viewer.
232 * @param timeGraphContentProvider
233 * the timegraph content provider
235 public void setTimeGraphContentProvider(ITimeGraphContentProvider timeGraphContentProvider
) {
236 fTimeGraphContentProvider
= timeGraphContentProvider
;
240 * Gets the timegraph content provider used by this timegraph viewer.
242 * @return the timegraph content provider
244 public ITimeGraphContentProvider
getTimeGraphContentProvider() {
245 return fTimeGraphContentProvider
;
249 * Sets the timegraph presentation provider used by this timegraph viewer.
251 * @param timeGraphProvider
252 * the timegraph provider
254 public void setTimeGraphProvider(ITimeGraphPresentationProvider timeGraphProvider
) {
255 fTimeGraphProvider
= timeGraphProvider
;
256 fTimeGraphCtrl
.setTimeGraphProvider(timeGraphProvider
);
257 fToolTipHandler
= new TimeGraphTooltipHandler(fTimeGraphProvider
, fTimeDataProvider
);
258 fToolTipHandler
.activateHoverHelp(fTimeGraphCtrl
);
262 * Sets the tree columns for this time graph combo's filter dialog.
264 * @param columnNames the tree column names
267 public void setFilterColumns(String
[] columnNames
) {
268 getShowFilterDialogAction().getFilterDialog().setColumnNames(columnNames
);
272 * Sets the tree content provider used by the filter dialog
274 * @param contentProvider the tree content provider
277 public void setFilterContentProvider(ITreeContentProvider contentProvider
) {
278 getShowFilterDialogAction().getFilterDialog().setContentProvider(contentProvider
);
282 * Sets the tree label provider used by the filter dialog
284 * @param labelProvider the tree label provider
287 public void setFilterLabelProvider(ITableLabelProvider labelProvider
) {
288 getShowFilterDialogAction().getFilterDialog().setLabelProvider(labelProvider
);
292 * Sets or clears the input for this time graph viewer.
294 * @param inputElement
295 * The input of this time graph viewer, or <code>null</code> if
298 public void setInput(Object inputElement
) {
299 fInputElement
= inputElement
;
300 ITimeGraphEntry
[] input
= fTimeGraphContentProvider
.getElements(inputElement
);
301 fListenerNotifier
= null;
302 if (fTimeGraphCtrl
!= null) {
305 fSelectionBegin
= SWT
.DEFAULT
;
306 fSelectionEnd
= SWT
.DEFAULT
;
307 fSelectedEntry
= null;
308 refreshAllData(input
);
313 * Gets the input for this time graph viewer.
315 * @return The input of this time graph viewer, or <code>null</code> if none
317 public Object
getInput() {
318 return fInputElement
;
322 * Sets (or clears if null) the list of links to display on this combo
325 * the links to display in this time graph combo
327 public void setLinks(List
<ILinkEvent
> links
) {
328 if (fTimeGraphCtrl
!= null) {
329 fTimeGraphCtrl
.refreshArrows(links
);
336 public void refresh() {
337 ITimeGraphEntry
[] input
= fTimeGraphContentProvider
.getElements(fInputElement
);
339 refreshAllData(input
);
343 * Callback for when the control is moved
348 public void controlMoved(ControlEvent e
) {
352 * Callback for when the control is resized
357 public void controlResized(ControlEvent e
) {
362 * @return The string representing the view type
364 protected String
getViewTypeStr() {
365 return "viewoption.threads"; //$NON-NLS-1$
368 int getMarginWidth() {
372 int getMarginHeight() {
377 fMinTimeInterval
= 1;
378 fSelectionBegin
= SWT
.DEFAULT
;
379 fSelectionEnd
= SWT
.DEFAULT
;
380 fNameWidth
= Utils
.loadIntOption(getPreferenceString("namewidth"), //$NON-NLS-1$
381 fNameWidthPref
, fMinNameWidth
, MAX_NAME_WIDTH
);
385 Utils
.saveIntOption(getPreferenceString("namewidth"), fNameWidth
); //$NON-NLS-1$
389 * Create a data viewer.
395 * @return The new data viewer
397 protected Control
createDataViewer(Composite parent
, int style
) {
399 fColorScheme
= new TimeGraphColorScheme();
400 fDataViewer
= new Composite(parent
, style
) {
402 public void redraw() {
403 fTimeScaleCtrl
.redraw();
404 fTimeGraphCtrl
.redraw();
408 GridLayout gl
= new GridLayout(2, false);
409 gl
.marginHeight
= fBorderWidth
;
411 gl
.verticalSpacing
= 0;
412 gl
.horizontalSpacing
= 0;
413 fDataViewer
.setLayout(gl
);
415 fTimeAlignedComposite
= new Composite(fDataViewer
, style
) {
417 public void redraw() {
418 fDataViewer
.redraw();
422 GridLayout gl2
= new GridLayout(1, false);
423 gl2
.marginHeight
= fBorderWidth
;
425 gl2
.verticalSpacing
= 0;
426 gl2
.horizontalSpacing
= 0;
427 fTimeAlignedComposite
.setLayout(gl2
);
428 fTimeAlignedComposite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
430 fTimeScaleCtrl
= new TimeGraphScale(fTimeAlignedComposite
, fColorScheme
);
431 fTimeScaleCtrl
.setTimeProvider(fTimeDataProvider
);
432 fTimeScaleCtrl
.setLayoutData(new GridData(SWT
.FILL
, SWT
.DEFAULT
, true, false));
433 fTimeScaleCtrl
.setHeight(fTimeScaleHeight
);
434 fTimeScaleCtrl
.addMouseWheelListener(new MouseWheelListener() {
436 public void mouseScrolled(MouseEvent e
) {
437 fTimeGraphCtrl
.zoom(e
.count
> 0);
441 fTimeGraphCtrl
= createTimeGraphControl(fTimeAlignedComposite
, fColorScheme
);
443 fTimeGraphCtrl
.setTimeProvider(this);
444 fTimeGraphCtrl
.setTimeGraphScale(fTimeScaleCtrl
);
445 fTimeGraphCtrl
.addSelectionListener(this);
446 fTimeGraphCtrl
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
447 fTimeGraphCtrl
.addMouseWheelListener(new MouseWheelListener() {
449 public void mouseScrolled(MouseEvent e
) {
450 adjustVerticalScrollBar();
453 fTimeGraphCtrl
.addKeyListener(new KeyAdapter() {
455 public void keyPressed(KeyEvent e
) {
456 if (e
.character
== '+') {
458 } else if (e
.character
== '-') {
461 adjustVerticalScrollBar();
465 fVerticalScrollBar
= new Slider(fDataViewer
, SWT
.VERTICAL
| SWT
.NO_FOCUS
);
466 fVerticalScrollBar
.setLayoutData(new GridData(SWT
.DEFAULT
, SWT
.FILL
, false, true, 1, 1));
467 fVerticalScrollBar
.addSelectionListener(new SelectionAdapter() {
469 public void widgetSelected(SelectionEvent e
) {
470 setTopIndex(fVerticalScrollBar
.getSelection());
474 fHorizontalScrollBar
= new Slider(fDataViewer
, SWT
.HORIZONTAL
| SWT
.NO_FOCUS
);
475 fHorizontalScrollBar
.setLayoutData(new GridData(SWT
.FILL
, SWT
.DEFAULT
, true, false));
476 fHorizontalScrollBar
.addListener(SWT
.MouseWheel
, new Listener() {
478 public void handleEvent(Event event
) {
479 if ((event
.stateMask
& SWT
.MODIFIER_MASK
) == SWT
.CTRL
) {
480 getTimeGraphControl().zoom(event
.count
> 0);
482 getTimeGraphControl().horizontalScroll(event
.count
> 0);
484 // don't handle the immediately following SWT.Selection event
488 fHorizontalScrollBar
.addListener(SWT
.Selection
, new Listener() {
490 public void handleEvent(Event event
) {
491 int start
= fHorizontalScrollBar
.getSelection();
492 long time0
= getTime0();
493 long time1
= getTime1();
494 long timeMin
= getMinTime();
495 long timeMax
= getMaxTime();
496 long delta
= timeMax
- timeMin
;
498 long range
= time1
- time0
;
499 time0
= timeMin
+ Math
.round(delta
* ((double) start
/ H_SCROLLBAR_MAX
));
500 time1
= time0
+ range
;
502 setStartFinishTimeNotify(time0
, time1
);
506 Composite filler
= new Composite(fDataViewer
, SWT
.NONE
);
507 GridData gd
= new GridData(SWT
.DEFAULT
, SWT
.DEFAULT
, false, false);
508 gd
.heightHint
= fHorizontalScrollBar
.getSize().y
;
509 filler
.setLayoutData(gd
);
510 filler
.setLayout(new FillLayout());
512 fTimeGraphCtrl
.addControlListener(new ControlAdapter() {
514 public void controlResized(ControlEvent event
) {
519 fDataViewer
.update();
520 adjustHorizontalScrollBar();
521 adjustVerticalScrollBar();
528 public void dispose() {
530 fTimeGraphCtrl
.dispose();
531 fDataViewer
.dispose();
532 fColorScheme
.dispose();
536 * Create a new time graph control.
539 * The parent composite
542 * @return The new TimeGraphControl
544 protected TimeGraphControl
createTimeGraphControl(Composite parent
,
545 TimeGraphColorScheme colors
) {
546 return new TimeGraphControl(parent
, colors
);
550 * Resize the controls
552 public void resizeControls() {
553 Rectangle r
= fDataViewer
.getClientArea();
559 if (fNameWidth
> width
- fMinNameWidth
) {
560 fNameWidth
= width
- fMinNameWidth
;
562 if (fNameWidth
< fMinNameWidth
) {
563 fNameWidth
= fMinNameWidth
;
565 adjustHorizontalScrollBar();
566 adjustVerticalScrollBar();
570 * Recalculate the time bounds based on the time graph entries,
571 * if the user-specified bound is set to SWT.DEFAULT.
574 * The root time graph entries in the model
576 public void setTimeRange(ITimeGraphEntry entries
[]) {
577 fTime0Bound
= (fBeginTime
!= SWT
.DEFAULT ? fBeginTime
: fEndTime
);
578 fTime1Bound
= (fEndTime
!= SWT
.DEFAULT ? fEndTime
: fBeginTime
);
579 if (fBeginTime
!= SWT
.DEFAULT
&& fEndTime
!= SWT
.DEFAULT
) {
582 if (entries
== null || entries
.length
== 0) {
585 if (fTime0Bound
== SWT
.DEFAULT
) {
586 fTime0Bound
= Long
.MAX_VALUE
;
588 if (fTime1Bound
== SWT
.DEFAULT
) {
589 fTime1Bound
= Long
.MIN_VALUE
;
591 for (ITimeGraphEntry entry
: entries
) {
596 private void setTimeRange(ITimeGraphEntry entry
) {
597 if (fBeginTime
== SWT
.DEFAULT
&& entry
.hasTimeEvents() && entry
.getStartTime() != SWT
.DEFAULT
) {
598 fTime0Bound
= Math
.min(entry
.getStartTime(), fTime0Bound
);
600 if (fEndTime
== SWT
.DEFAULT
&& entry
.hasTimeEvents() && entry
.getEndTime() != SWT
.DEFAULT
) {
601 fTime1Bound
= Math
.max(entry
.getEndTime(), fTime1Bound
);
603 if (entry
.hasChildren()) {
604 for (ITimeGraphEntry child
: entry
.getChildren()) {
611 * Set the time bounds to the provided values.
614 * The bounds begin time, or SWT.DEFAULT to use the input bounds
616 * The bounds end time, or SWT.DEFAULT to use the input bounds
618 public void setTimeBounds(long beginTime
, long endTime
) {
619 fBeginTime
= beginTime
;
621 fTime0Bound
= (fBeginTime
!= SWT
.DEFAULT ? fBeginTime
: fEndTime
);
622 fTime1Bound
= (fEndTime
!= SWT
.DEFAULT ? fEndTime
: fBeginTime
);
623 if (fTime0Bound
> fTime1Bound
) {
624 // only possible if both are not default
625 fBeginTime
= endTime
;
626 fEndTime
= beginTime
;
627 fTime0Bound
= fBeginTime
;
628 fTime1Bound
= fEndTime
;
630 adjustHorizontalScrollBar();
634 * Recalculate the current time window when bounds have changed.
636 public void setTimeBounds() {
637 if (!fTimeRangeFixed
) {
638 fTime0
= fTime0Bound
;
639 fTime1
= fTime1Bound
;
641 fTime0
= Math
.max(fTime0Bound
, Math
.min(fTime0
, fTime1Bound
));
642 fTime1
= Math
.max(fTime0Bound
, Math
.min(fTime1
, fTime1Bound
));
643 if (fTime1
- fTime0
< fMinTimeInterval
) {
644 fTime1
= Math
.min(fTime1Bound
, fTime0
+ fMinTimeInterval
);
651 private void refreshAllData(ITimeGraphEntry
[] traces
) {
653 if (fSelectionBegin
< fBeginTime
) {
654 fSelectionBegin
= fBeginTime
;
655 } else if (fSelectionBegin
> fEndTime
) {
656 fSelectionBegin
= fEndTime
;
658 if (fSelectionEnd
< fBeginTime
) {
659 fSelectionEnd
= fBeginTime
;
660 } else if (fSelectionEnd
> fEndTime
) {
661 fSelectionEnd
= fEndTime
;
663 fTimeGraphCtrl
.refreshData(traces
);
664 fTimeScaleCtrl
.redraw();
665 adjustVerticalScrollBar();
669 * Callback for when this view is focused
671 public void setFocus() {
672 if (null != fTimeGraphCtrl
) {
673 fTimeGraphCtrl
.setFocus();
678 * Get the current focus status of this view.
680 * @return If the view is currently focused, or not
682 public boolean isInFocus() {
683 return fTimeGraphCtrl
.isInFocus();
687 * Get the view's current selection
689 * @return The entry that is selected
691 public ITimeGraphEntry
getSelection() {
692 return fTimeGraphCtrl
.getSelectedTrace();
696 * Get the index of the current selection
700 public int getSelectionIndex() {
701 return fTimeGraphCtrl
.getSelectedIndex();
705 public long getTime0() {
710 public long getTime1() {
715 public long getMinTimeInterval() {
716 return fMinTimeInterval
;
720 public int getNameSpace() {
725 public void setNameSpace(int width
) {
727 int w
= fTimeGraphCtrl
.getClientArea().width
;
728 if (fNameWidth
> w
- MIN_NAME_WIDTH
) {
729 fNameWidth
= w
- MIN_NAME_WIDTH
;
731 if (fNameWidth
< MIN_NAME_WIDTH
) {
732 fNameWidth
= MIN_NAME_WIDTH
;
734 fTimeGraphCtrl
.redraw();
735 fTimeScaleCtrl
.redraw();
739 public int getTimeSpace() {
740 int w
= fTimeGraphCtrl
.getClientArea().width
;
741 return w
- fNameWidth
;
745 public long getBeginTime() {
750 public long getEndTime() {
755 public long getMaxTime() {
760 public long getMinTime() {
765 public long getSelectionBegin() {
766 return fSelectionBegin
;
770 public long getSelectionEnd() {
771 return fSelectionEnd
;
775 public void setStartFinishTimeNotify(long time0
, long time1
) {
776 setStartFinishTimeInt(time0
, time1
);
777 notifyRangeListeners();
781 public void notifyStartFinishTime() {
782 notifyRangeListeners();
786 public void setStartFinishTime(long time0
, long time1
) {
787 /* if there is a pending time range, ignore this one */
788 if (fListenerNotifier
!= null && fListenerNotifier
.hasTimeRangeUpdated()) {
791 setStartFinishTimeInt(time0
, time1
);
792 updateExtSynchValues();
795 private void setStartFinishTimeInt(long time0
, long time1
) {
797 if (fTime0
< fTime0Bound
) {
798 fTime0
= fTime0Bound
;
800 if (fTime0
> fTime1Bound
) {
801 fTime0
= fTime1Bound
;
804 if (fTime1
< fTime0Bound
) {
805 fTime1
= fTime0Bound
;
807 if (fTime1
> fTime1Bound
) {
808 fTime1
= fTime1Bound
;
810 if (fTime1
- fTime0
< fMinTimeInterval
) {
811 fTime1
= Math
.min(fTime1Bound
, fTime0
+ fMinTimeInterval
);
813 fTimeRangeFixed
= true;
814 adjustHorizontalScrollBar();
815 fTimeGraphCtrl
.redraw();
816 fTimeScaleCtrl
.redraw();
820 public void resetStartFinishTime() {
821 setStartFinishTimeNotify(fTime0Bound
, fTime1Bound
);
822 fTimeRangeFixed
= false;
826 public void setSelectedTimeNotify(long time
, boolean ensureVisible
) {
827 setSelectedTimeInt(time
, ensureVisible
, true);
831 public void setSelectedTime(long time
, boolean ensureVisible
) {
832 /* if there is a pending time selection, ignore this one */
833 if (fListenerNotifier
!= null && fListenerNotifier
.hasTimeSelected()) {
836 setSelectedTimeInt(time
, ensureVisible
, false);
840 public void setSelectionRangeNotify(long beginTime
, long endTime
) {
843 long selectionBegin
= fSelectionBegin
;
844 long selectionEnd
= fSelectionEnd
;
845 fSelectionBegin
= Math
.max(fTime0Bound
, Math
.min(fTime1Bound
, beginTime
));
846 fSelectionEnd
= Math
.max(fTime0Bound
, Math
.min(fTime1Bound
, endTime
));
847 boolean changed
= (selectionBegin
!= fSelectionBegin
|| selectionEnd
!= fSelectionEnd
);
848 ensureVisible(fSelectionEnd
);
849 fTimeGraphCtrl
.redraw();
850 fTimeScaleCtrl
.redraw();
851 if ((time0
!= fTime0
) || (time1
!= fTime1
)) {
852 notifyRangeListeners();
855 notifyTimeListeners();
860 public void setSelectionRange(long beginTime
, long endTime
) {
861 /* if there is a pending time selection, ignore this one */
862 if (fListenerNotifier
!= null && fListenerNotifier
.hasTimeSelected()) {
865 fSelectionBegin
= Math
.max(fTime0Bound
, Math
.min(fTime1Bound
, beginTime
));
866 fSelectionEnd
= Math
.max(fTime0Bound
, Math
.min(fTime1Bound
, endTime
));
867 fTimeGraphCtrl
.redraw();
868 fTimeScaleCtrl
.redraw();
871 private void setSelectedTimeInt(long time
, boolean ensureVisible
, boolean doNotify
) {
872 long selection
= Math
.max(fTime0Bound
, Math
.min(fTime1Bound
, time
));
876 ensureVisible(selection
);
878 fTimeGraphCtrl
.redraw();
879 fTimeScaleCtrl
.redraw();
881 boolean notifySelectedTime
= (selection
!= fSelectionBegin
|| selection
!= fSelectionEnd
);
882 fSelectionBegin
= selection
;
883 fSelectionEnd
= selection
;
885 if ((time0
!= fTime0
) || (time1
!= fTime1
)) {
886 notifyRangeListeners();
889 if (doNotify
&& notifySelectedTime
) {
890 notifyTimeListeners();
894 private void ensureVisible(long time
) {
895 long timeMid
= (fTime1
- fTime0
) / 2;
897 long dt
= fTime0
- time
+ timeMid
;
900 } else if (time
> fTime1
) {
901 long dt
= time
- fTime1
+ timeMid
;
905 if (fTime0
< fTime0Bound
) {
906 fTime1
= Math
.min(fTime1Bound
, fTime1
+ (fTime0Bound
- fTime0
));
907 fTime0
= fTime0Bound
;
908 } else if (fTime1
> fTime1Bound
) {
909 fTime0
= Math
.max(fTime0Bound
, fTime0
- (fTime1
- fTime1Bound
));
910 fTime1
= fTime1Bound
;
912 if (fTime1
- fTime0
< fMinTimeInterval
) {
913 fTime1
= Math
.min(fTime1Bound
, fTime0
+ fMinTimeInterval
);
915 adjustHorizontalScrollBar();
919 public void widgetDefaultSelected(SelectionEvent e
) {
920 if (fSelectedEntry
!= getSelection()) {
921 fSelectedEntry
= getSelection();
922 notifySelectionListeners();
927 public void widgetSelected(SelectionEvent e
) {
928 if (fSelectedEntry
!= getSelection()) {
929 fSelectedEntry
= getSelection();
930 notifySelectionListeners();
935 * Callback for when the next event is selected
938 * true to extend selection range, false for single selection
941 public void selectNextEvent(boolean extend
) {
942 fTimeGraphCtrl
.selectNextEvent(extend
);
943 adjustVerticalScrollBar();
947 * Callback for when the previous event is selected
950 * true to extend selection range, false for single selection
953 public void selectPrevEvent(boolean extend
) {
954 fTimeGraphCtrl
.selectPrevEvent(extend
);
955 adjustVerticalScrollBar();
959 * Callback for when the next item is selected
961 public void selectNextItem() {
962 fTimeGraphCtrl
.selectNextTrace();
963 adjustVerticalScrollBar();
967 * Callback for when the previous item is selected
969 public void selectPrevItem() {
970 fTimeGraphCtrl
.selectPrevTrace();
971 adjustVerticalScrollBar();
975 * Callback for the show legend action
977 public void showLegend() {
978 if (fDataViewer
== null || fDataViewer
.isDisposed()) {
982 TimeGraphLegend
.open(fDataViewer
.getShell(), fTimeGraphProvider
);
986 * Callback for the Zoom In action
988 public void zoomIn() {
989 fTimeGraphCtrl
.zoomIn();
993 * Callback for the Zoom Out action
995 public void zoomOut() {
996 fTimeGraphCtrl
.zoomOut();
999 private String
getPreferenceString(String string
) {
1000 return getViewTypeStr() + "." + string
; //$NON-NLS-1$
1004 * Add a selection listener
1007 * The listener to add
1009 public void addSelectionListener(ITimeGraphSelectionListener listener
) {
1010 fSelectionListeners
.add(listener
);
1014 * Remove a selection listener
1017 * The listener to remove
1019 public void removeSelectionListener(ITimeGraphSelectionListener listener
) {
1020 fSelectionListeners
.remove(listener
);
1023 private void notifySelectionListeners() {
1024 if (fListenerNotifier
== null) {
1025 fListenerNotifier
= new ListenerNotifier();
1026 fListenerNotifier
.start();
1028 fListenerNotifier
.selectionChanged();
1031 private void fireSelectionChanged(ITimeGraphEntry selection
) {
1032 TimeGraphSelectionEvent event
= new TimeGraphSelectionEvent(this, selection
);
1034 for (ITimeGraphSelectionListener listener
: fSelectionListeners
) {
1035 listener
.selectionChanged(event
);
1040 * Add a time listener
1043 * The listener to add
1045 public void addTimeListener(ITimeGraphTimeListener listener
) {
1046 fTimeListeners
.add(listener
);
1050 * Remove a time listener
1053 * The listener to remove
1055 public void removeTimeListener(ITimeGraphTimeListener listener
) {
1056 fTimeListeners
.remove(listener
);
1059 private void notifyTimeListeners() {
1060 if (fListenerNotifier
== null) {
1061 fListenerNotifier
= new ListenerNotifier();
1062 fListenerNotifier
.start();
1064 fListenerNotifier
.timeSelected();
1067 private void fireTimeSelected(long startTime
, long endTime
) {
1068 TimeGraphTimeEvent event
= new TimeGraphTimeEvent(this, startTime
, endTime
);
1070 for (ITimeGraphTimeListener listener
: fTimeListeners
) {
1071 listener
.timeSelected(event
);
1076 * Add a range listener
1079 * The listener to add
1081 public void addRangeListener(ITimeGraphRangeListener listener
) {
1082 fRangeListeners
.add(listener
);
1086 * Remove a range listener
1089 * The listener to remove
1091 public void removeRangeListener(ITimeGraphRangeListener listener
) {
1092 fRangeListeners
.remove(listener
);
1095 private void notifyRangeListeners() {
1096 if (fListenerNotifier
== null) {
1097 fListenerNotifier
= new ListenerNotifier();
1098 fListenerNotifier
.start();
1100 fListenerNotifier
.timeRangeUpdated();
1103 private void fireTimeRangeUpdated(long startTime
, long endTime
) {
1104 // Check if the time has actually changed from last notification
1105 if (startTime
!= fTime0ExtSynch
|| endTime
!= fTime1ExtSynch
) {
1106 // Notify Time Scale Selection Listeners
1107 TimeGraphRangeUpdateEvent event
= new TimeGraphRangeUpdateEvent(this, startTime
, endTime
);
1109 for (ITimeGraphRangeListener listener
: fRangeListeners
) {
1110 listener
.timeRangeUpdated(event
);
1113 // update external synch values
1114 updateExtSynchValues();
1119 * Callback to set a selected event in the view
1122 * The event that was selected
1124 * The source of this selection event
1126 public void setSelectedEvent(ITimeEvent event
, Object source
) {
1127 if (event
== null || source
== this) {
1130 fSelectedEntry
= event
.getEntry();
1131 fTimeGraphCtrl
.selectItem(fSelectedEntry
, false);
1133 setSelectedTimeInt(event
.getTime(), true, true);
1134 adjustVerticalScrollBar();
1138 * Set the seeked time of a trace
1141 * The trace that was seeked
1145 * The source of this seek event
1147 public void setSelectedTraceTime(ITimeGraphEntry trace
, long time
, Object source
) {
1148 if (trace
== null || source
== this) {
1151 fSelectedEntry
= trace
;
1152 fTimeGraphCtrl
.selectItem(trace
, false);
1154 setSelectedTimeInt(time
, true, true);
1158 * Callback for a trace selection
1161 * The trace that was selected
1163 public void setSelection(ITimeGraphEntry trace
) {
1164 /* if there is a pending selection, ignore this one */
1165 if (fListenerNotifier
!= null && fListenerNotifier
.hasSelectionChanged()) {
1168 fSelectedEntry
= trace
;
1169 fTimeGraphCtrl
.selectItem(trace
, false);
1170 adjustVerticalScrollBar();
1174 * Callback for a time window selection
1177 * Start time of the range
1179 * End time of the range
1181 * Source of the event
1183 public void setSelectVisTimeWindow(long time0
, long time1
, Object source
) {
1184 if (source
== this) {
1188 setStartFinishTimeInt(time0
, time1
);
1190 // update notification time values since we are now in synch with the
1191 // external application
1192 updateExtSynchValues();
1196 * update the cache values used to identify the need to send a time window
1197 * update to external registered listeners
1199 private void updateExtSynchValues() {
1200 // last time notification cache
1201 fTime0ExtSynch
= fTime0
;
1202 fTime1ExtSynch
= fTime1
;
1206 public TimeFormat
getTimeFormat() {
1212 * the {@link TimeFormat} used to display timestamps
1214 public void setTimeFormat(TimeFormat tf
) {
1215 this.fTimeFormat
= tf
;
1216 if (tf
== TimeFormat
.CYCLES
) {
1217 fTimeDataProvider
= new TimeDataProviderCyclesConverter(this, fClockFrequency
);
1219 fTimeDataProvider
= this;
1221 fTimeScaleCtrl
.setTimeProvider(fTimeDataProvider
);
1222 if (fToolTipHandler
!= null) {
1223 fToolTipHandler
.setTimeProvider(fTimeDataProvider
);
1228 * Sets the clock frequency. Used when the time format is set to CYCLES.
1230 * @param clockFrequency
1231 * the clock frequency in Hz
1233 public void setClockFrequency(long clockFrequency
) {
1234 fClockFrequency
= clockFrequency
;
1235 if (fTimeFormat
== TimeFormat
.CYCLES
) {
1236 fTimeDataProvider
= new TimeDataProviderCyclesConverter(this, fClockFrequency
);
1237 fTimeScaleCtrl
.setTimeProvider(fTimeDataProvider
);
1238 if (fToolTipHandler
!= null) {
1239 fToolTipHandler
.setTimeProvider(fTimeDataProvider
);
1245 * Retrieve the border width
1249 public int getBorderWidth() {
1250 return fBorderWidth
;
1254 * Set the border width
1256 * @param borderWidth
1259 public void setBorderWidth(int borderWidth
) {
1260 if (borderWidth
> -1) {
1261 this.fBorderWidth
= borderWidth
;
1262 GridLayout gl
= (GridLayout
) fDataViewer
.getLayout();
1263 gl
.marginHeight
= borderWidth
;
1268 * Retrieve the height of the header
1270 * @return The height
1272 public int getHeaderHeight() {
1273 return fTimeScaleHeight
;
1277 * Set the height of the header
1279 * @param headerHeight
1282 public void setHeaderHeight(int headerHeight
) {
1283 if (headerHeight
> -1) {
1284 this.fTimeScaleHeight
= headerHeight
;
1285 fTimeScaleCtrl
.setHeight(headerHeight
);
1290 * Retrieve the height of an item row
1292 * @return The height
1294 public int getItemHeight() {
1295 if (fTimeGraphCtrl
!= null) {
1296 return fTimeGraphCtrl
.getItemHeight();
1302 * Set the height of an item row
1307 public void setItemHeight(int rowHeight
) {
1308 if (fTimeGraphCtrl
!= null) {
1309 fTimeGraphCtrl
.setItemHeight(rowHeight
);
1314 * Set the minimum item width
1319 public void setMinimumItemWidth(int width
) {
1320 if (fTimeGraphCtrl
!= null) {
1321 fTimeGraphCtrl
.setMinimumItemWidth(width
);
1326 * Set the width for the name column
1331 public void setNameWidthPref(int width
) {
1332 fNameWidthPref
= width
;
1340 * Retrieve the configure width for the name column
1346 public int getNameWidthPref(int width
) {
1347 return fNameWidthPref
;
1351 * Returns the primary control associated with this viewer.
1353 * @return the SWT control which displays this viewer's content
1355 public Control
getControl() {
1360 * Returns the time graph control associated with this viewer.
1362 * @return the time graph control
1364 public TimeGraphControl
getTimeGraphControl() {
1365 return fTimeGraphCtrl
;
1369 * Returns the time graph scale associated with this viewer.
1371 * @return the time graph scale
1373 public TimeGraphScale
getTimeGraphScale() {
1374 return fTimeScaleCtrl
;
1378 * Returns the composite containing all the controls that are time aligned,
1379 * i.e. TimeGraphScale, TimeGraphControl.
1381 * @return the time based composite
1384 public Composite
getTimeAlignedComposite() {
1385 return fTimeAlignedComposite
;
1389 * Return the x coordinate corresponding to a time
1393 * @return the x coordinate corresponding to the time
1395 public int getXForTime(long time
) {
1396 return fTimeGraphCtrl
.getXForTime(time
);
1400 * Return the time corresponding to an x coordinate
1404 * @return the time corresponding to the x coordinate
1406 public long getTimeAtX(int x
) {
1407 return fTimeGraphCtrl
.getTimeAtX(x
);
1411 * Get the selection provider
1413 * @return the selection provider
1415 public ISelectionProvider
getSelectionProvider() {
1416 return fTimeGraphCtrl
;
1420 * Wait for the cursor
1423 * Wait indefinitely?
1425 public void waitCursor(boolean waitInd
) {
1426 fTimeGraphCtrl
.waitCursor(waitInd
);
1430 * Get the horizontal scroll bar object
1432 * @return The scroll bar
1434 public Slider
getHorizontalBar() {
1435 return fHorizontalScrollBar
;
1439 * Get the vertical scroll bar object
1441 * @return The scroll bar
1443 public Slider
getVerticalBar() {
1444 return fVerticalScrollBar
;
1448 * Set the given index as the top one
1451 * The index that will go to the top
1453 public void setTopIndex(int index
) {
1454 fTimeGraphCtrl
.setTopIndex(index
);
1455 adjustVerticalScrollBar();
1459 * Retrieve the current top index
1461 * @return The top index
1463 public int getTopIndex() {
1464 return fTimeGraphCtrl
.getTopIndex();
1468 * Sets the auto-expand level to be used for new entries discovered when
1469 * calling {@link #setInput(Object)} or {@link #refresh()}. The value 0
1470 * means that there is no auto-expand; 1 means that top-level entries are
1471 * expanded, but not their children; 2 means that top-level entries are
1472 * expanded, and their children, but not grand-children; and so on.
1474 * The value {@link #ALL_LEVELS} means that all subtrees should be expanded.
1478 * non-negative level, or <code>ALL_LEVELS</code> to expand all
1479 * levels of the tree
1481 public void setAutoExpandLevel(int level
) {
1482 fTimeGraphCtrl
.setAutoExpandLevel(level
);
1486 * Returns the auto-expand level.
1488 * @return non-negative level, or <code>ALL_LEVELS</code> if all levels of
1489 * the tree are expanded automatically
1490 * @see #setAutoExpandLevel
1492 public int getAutoExpandLevel() {
1493 return fTimeGraphCtrl
.getAutoExpandLevel();
1497 * Get the expanded state of an entry.
1501 * @return true if the entry is expanded, false if collapsed
1504 public boolean getExpandedState(ITimeGraphEntry entry
) {
1505 return fTimeGraphCtrl
.getExpandedState(entry
);
1509 * Set the expanded state of an entry
1512 * The entry to expand/collapse
1514 * True for expanded, false for collapsed
1516 public void setExpandedState(ITimeGraphEntry entry
, boolean expanded
) {
1517 fTimeGraphCtrl
.setExpandedState(entry
, expanded
);
1518 adjustVerticalScrollBar();
1522 * Collapses all nodes of the viewer's tree, starting with the root.
1524 public void collapseAll() {
1525 fTimeGraphCtrl
.collapseAll();
1526 adjustVerticalScrollBar();
1530 * Expands all entries of the viewer's tree, starting with the root.
1532 public void expandAll() {
1533 fTimeGraphCtrl
.expandAll();
1534 adjustVerticalScrollBar();
1538 * Get the number of expanded (visible) time graph entries. This includes
1539 * leafs and does not include filtered-out entries.
1541 * @return The number of expanded (visible) time graph entries
1543 public int getExpandedElementCount() {
1544 return fTimeGraphCtrl
.getExpandedElementCount();
1548 * Get the expanded (visible) time graph entries. This includes leafs and
1549 * does not include filtered-out entries.
1551 * @return The array of expanded (visible) time graph entries
1553 public ITimeGraphEntry
[] getExpandedElements() {
1554 return fTimeGraphCtrl
.getExpandedElements();
1558 * Add a tree listener
1561 * The listener to add
1563 public void addTreeListener(ITimeGraphTreeListener listener
) {
1564 fTimeGraphCtrl
.addTreeListener(listener
);
1568 * Remove a tree listener
1571 * The listener to remove
1573 public void removeTreeListener(ITimeGraphTreeListener listener
) {
1574 fTimeGraphCtrl
.removeTreeListener(listener
);
1578 * Get the reset scale action.
1580 * @return The Action object
1582 public Action
getResetScaleAction() {
1583 if (fResetScaleAction
== null) {
1585 fResetScaleAction
= new Action() {
1588 resetStartFinishTime();
1591 fResetScaleAction
.setText(Messages
.TmfTimeGraphViewer_ResetScaleActionNameText
);
1592 fResetScaleAction
.setToolTipText(Messages
.TmfTimeGraphViewer_ResetScaleActionToolTipText
);
1593 fResetScaleAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_HOME_MENU
));
1595 return fResetScaleAction
;
1599 * Get the show legend action.
1601 * @return The Action object
1603 public Action
getShowLegendAction() {
1604 if (fShowLegendAction
== null) {
1606 fShowLegendAction
= new Action() {
1612 fShowLegendAction
.setText(Messages
.TmfTimeGraphViewer_LegendActionNameText
);
1613 fShowLegendAction
.setToolTipText(Messages
.TmfTimeGraphViewer_LegendActionToolTipText
);
1614 fShowLegendAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_SHOW_LEGEND
));
1617 return fShowLegendAction
;
1621 * Get the the next event action.
1623 * @return The action object
1625 public Action
getNextEventAction() {
1626 if (fNextEventAction
== null) {
1627 fNextEventAction
= new Action() {
1629 public void runWithEvent(Event event
) {
1630 boolean extend
= (event
.stateMask
& SWT
.SHIFT
) != 0;
1631 selectNextEvent(extend
);
1635 fNextEventAction
.setText(Messages
.TmfTimeGraphViewer_NextEventActionNameText
);
1636 fNextEventAction
.setToolTipText(Messages
.TmfTimeGraphViewer_NextEventActionToolTipText
);
1637 fNextEventAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_NEXT_EVENT
));
1640 return fNextEventAction
;
1644 * Get the previous event action.
1646 * @return The Action object
1648 public Action
getPreviousEventAction() {
1649 if (fPrevEventAction
== null) {
1650 fPrevEventAction
= new Action() {
1652 public void runWithEvent(Event event
) {
1653 boolean extend
= (event
.stateMask
& SWT
.SHIFT
) != 0;
1654 selectPrevEvent(extend
);
1658 fPrevEventAction
.setText(Messages
.TmfTimeGraphViewer_PreviousEventActionNameText
);
1659 fPrevEventAction
.setToolTipText(Messages
.TmfTimeGraphViewer_PreviousEventActionToolTipText
);
1660 fPrevEventAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_PREV_EVENT
));
1663 return fPrevEventAction
;
1667 * Get the next item action.
1669 * @return The Action object
1671 public Action
getNextItemAction() {
1672 if (fNextItemAction
== null) {
1674 fNextItemAction
= new Action() {
1680 fNextItemAction
.setText(Messages
.TmfTimeGraphViewer_NextItemActionNameText
);
1681 fNextItemAction
.setToolTipText(Messages
.TmfTimeGraphViewer_NextItemActionToolTipText
);
1682 fNextItemAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_NEXT_ITEM
));
1684 return fNextItemAction
;
1688 * Get the previous item action.
1690 * @return The Action object
1692 public Action
getPreviousItemAction() {
1693 if (fPreviousItemAction
== null) {
1695 fPreviousItemAction
= new Action() {
1701 fPreviousItemAction
.setText(Messages
.TmfTimeGraphViewer_PreviousItemActionNameText
);
1702 fPreviousItemAction
.setToolTipText(Messages
.TmfTimeGraphViewer_PreviousItemActionToolTipText
);
1703 fPreviousItemAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_PREV_ITEM
));
1705 return fPreviousItemAction
;
1709 * Get the zoom in action
1711 * @return The Action object
1713 public Action
getZoomInAction() {
1714 if (fZoomInAction
== null) {
1715 fZoomInAction
= new Action() {
1721 fZoomInAction
.setText(Messages
.TmfTimeGraphViewer_ZoomInActionNameText
);
1722 fZoomInAction
.setToolTipText(Messages
.TmfTimeGraphViewer_ZoomInActionToolTipText
);
1723 fZoomInAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_ZOOM_IN_MENU
));
1725 return fZoomInAction
;
1729 * Get the zoom out action
1731 * @return The Action object
1733 public Action
getZoomOutAction() {
1734 if (fZoomOutAction
== null) {
1735 fZoomOutAction
= new Action() {
1741 fZoomOutAction
.setText(Messages
.TmfTimeGraphViewer_ZoomOutActionNameText
);
1742 fZoomOutAction
.setToolTipText(Messages
.TmfTimeGraphViewer_ZoomOutActionToolTipText
);
1743 fZoomOutAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_ZOOM_OUT_MENU
));
1745 return fZoomOutAction
;
1749 * Get the hide arrows action
1751 * @param dialogSettings
1752 * The dialog settings section where the state should be stored,
1755 * @return The Action object
1757 public Action
getHideArrowsAction(final IDialogSettings dialogSettings
) {
1758 if (fHideArrowsAction
== null) {
1759 fHideArrowsAction
= new Action(Messages
.TmfTimeGraphViewer_HideArrowsActionNameText
, IAction
.AS_CHECK_BOX
) {
1762 boolean hideArrows
= fHideArrowsAction
.isChecked();
1763 fTimeGraphCtrl
.hideArrows(hideArrows
);
1765 if (dialogSettings
!= null) {
1766 dialogSettings
.put(HIDE_ARROWS_KEY
, hideArrows
);
1768 if (fFollowArrowFwdAction
!= null) {
1769 fFollowArrowFwdAction
.setEnabled(!hideArrows
);
1771 if (fFollowArrowBwdAction
!= null) {
1772 fFollowArrowBwdAction
.setEnabled(!hideArrows
);
1776 fHideArrowsAction
.setToolTipText(Messages
.TmfTimeGraphViewer_HideArrowsActionToolTipText
);
1777 fHideArrowsAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_HIDE_ARROWS
));
1778 if (dialogSettings
!= null) {
1779 boolean hideArrows
= dialogSettings
.getBoolean(HIDE_ARROWS_KEY
);
1780 fTimeGraphCtrl
.hideArrows(hideArrows
);
1781 fHideArrowsAction
.setChecked(hideArrows
);
1782 if (fFollowArrowFwdAction
!= null) {
1783 fFollowArrowFwdAction
.setEnabled(!hideArrows
);
1785 if (fFollowArrowBwdAction
!= null) {
1786 fFollowArrowBwdAction
.setEnabled(!hideArrows
);
1790 return fHideArrowsAction
;
1794 * Get the follow arrow forward action.
1796 * @return The Action object
1798 public Action
getFollowArrowFwdAction() {
1799 if (fFollowArrowFwdAction
== null) {
1800 fFollowArrowFwdAction
= new Action() {
1802 public void runWithEvent(Event event
) {
1803 boolean extend
= (event
.stateMask
& SWT
.SHIFT
) != 0;
1804 fTimeGraphCtrl
.followArrowFwd(extend
);
1805 adjustVerticalScrollBar();
1808 fFollowArrowFwdAction
.setText(Messages
.TmfTimeGraphViewer_FollowArrowForwardActionNameText
);
1809 fFollowArrowFwdAction
.setToolTipText(Messages
.TmfTimeGraphViewer_FollowArrowForwardActionToolTipText
);
1810 fFollowArrowFwdAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_FOLLOW_ARROW_FORWARD
));
1811 if (fHideArrowsAction
!= null) {
1812 fFollowArrowFwdAction
.setEnabled(!fHideArrowsAction
.isChecked());
1815 return fFollowArrowFwdAction
;
1819 * Get the follow arrow backward action.
1821 * @return The Action object
1823 public Action
getFollowArrowBwdAction() {
1824 if (fFollowArrowBwdAction
== null) {
1825 fFollowArrowBwdAction
= new Action() {
1827 public void runWithEvent(Event event
) {
1828 boolean extend
= (event
.stateMask
& SWT
.SHIFT
) != 0;
1829 fTimeGraphCtrl
.followArrowBwd(extend
);
1830 adjustVerticalScrollBar();
1833 fFollowArrowBwdAction
.setText(Messages
.TmfTimeGraphViewer_FollowArrowBackwardActionNameText
);
1834 fFollowArrowBwdAction
.setToolTipText(Messages
.TmfTimeGraphViewer_FollowArrowBackwardActionToolTipText
);
1835 fFollowArrowBwdAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_FOLLOW_ARROW_BACKWARD
));
1836 if (fHideArrowsAction
!= null) {
1837 fFollowArrowBwdAction
.setEnabled(!fHideArrowsAction
.isChecked());
1840 return fFollowArrowBwdAction
;
1844 * Get the show filter dialog action.
1846 * @return The Action object
1849 public ShowFilterDialogAction
getShowFilterDialogAction() {
1850 if (fShowFilterDialogAction
== null) {
1851 fShowFilterDialogAction
= new ShowFilterDialogAction(this);
1853 return fShowFilterDialogAction
;
1856 private void adjustHorizontalScrollBar() {
1857 long time0
= getTime0();
1858 long time1
= getTime1();
1859 long timeMin
= getMinTime();
1860 long timeMax
= getMaxTime();
1861 long delta
= timeMax
- timeMin
;
1863 int thumb
= H_SCROLLBAR_MAX
;
1865 // Thumb size (page size)
1866 thumb
= Math
.max(1, (int) (H_SCROLLBAR_MAX
* ((double) (time1
- time0
) / delta
)));
1867 // At the beginning of visible window
1868 timePos
= (int) (H_SCROLLBAR_MAX
* ((double) (time0
- timeMin
) / delta
));
1870 fHorizontalScrollBar
.setValues(timePos
, 0, H_SCROLLBAR_MAX
, thumb
, Math
.max(1, thumb
/ 2), Math
.max(2, thumb
));
1873 private void adjustVerticalScrollBar() {
1874 int topIndex
= fTimeGraphCtrl
.getTopIndex();
1875 int countPerPage
= fTimeGraphCtrl
.countPerPage();
1876 int expandedElementCount
= fTimeGraphCtrl
.getExpandedElementCount();
1877 if (topIndex
+ countPerPage
> expandedElementCount
) {
1878 fTimeGraphCtrl
.setTopIndex(Math
.max(0, expandedElementCount
- countPerPage
));
1881 int selection
= fTimeGraphCtrl
.getTopIndex();
1883 int max
= Math
.max(1, expandedElementCount
- 1);
1884 int thumb
= Math
.min(max
, Math
.max(1, countPerPage
- 1));
1886 int pageIncrement
= Math
.max(1, countPerPage
);
1887 fVerticalScrollBar
.setValues(selection
, min
, max
, thumb
, increment
, pageIncrement
);
1892 * a {@link MenuDetectListener}
1893 * @see org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.TimeGraphControl#addTimeGraphEntryMenuListener(org.eclipse.swt.events.MenuDetectListener)
1895 public void addTimeGraphEntryMenuListener(MenuDetectListener listener
) {
1896 fTimeGraphCtrl
.addTimeGraphEntryMenuListener(listener
);
1901 * a {@link MenuDetectListener}
1902 * @see org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.TimeGraphControl#removeTimeGraphEntryMenuListener(org.eclipse.swt.events.MenuDetectListener)
1904 public void removeTimeGraphEntryMenuListener(MenuDetectListener listener
) {
1905 fTimeGraphCtrl
.removeTimeGraphEntryMenuListener(listener
);
1910 * a {@link MenuDetectListener}
1911 * @see org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.TimeGraphControl#addTimeEventMenuListener(org.eclipse.swt.events.MenuDetectListener)
1913 public void addTimeEventMenuListener(MenuDetectListener listener
) {
1914 fTimeGraphCtrl
.addTimeEventMenuListener(listener
);
1919 * a {@link MenuDetectListener}
1920 * @see org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.TimeGraphControl#removeTimeEventMenuListener(org.eclipse.swt.events.MenuDetectListener)
1922 public void removeTimeEventMenuListener(MenuDetectListener listener
) {
1923 fTimeGraphCtrl
.removeTimeEventMenuListener(listener
);
1928 * The filter object to be attached to the view
1930 public void addFilter(ViewerFilter filter
) {
1931 fTimeGraphCtrl
.addFilter(filter
);
1937 * The filter object to be attached to the view
1939 public void removeFilter(ViewerFilter filter
) {
1940 fTimeGraphCtrl
.removeFilter(filter
);
1945 * Returns this viewer's filters.
1947 * @return an array of viewer filters
1950 public ViewerFilter
[] getFilters() {
1951 return fTimeGraphCtrl
.getFilters();
1955 * Sets the filters, replacing any previous filters, and triggers
1956 * refiltering of the elements.
1959 * an array of viewer filters, or null
1962 public void setFilters(ViewerFilter
[] filters
) {
1963 fTimeGraphCtrl
.setFilters(filters
);
1968 * Return the time alignment information
1970 * @return the time alignment information
1972 * @see ITmfTimeAligned
1976 public TmfTimeViewAlignmentInfo
getTimeViewAlignmentInfo() {
1977 return fTimeGraphCtrl
.getTimeViewAlignmentInfo();
1981 * Return the available width for the time-axis.
1983 * @see ITmfTimeAligned
1985 * @param requestedOffset
1986 * the requested offset
1987 * @return the available width for the time-axis
1991 public int getAvailableWidth(int requestedOffset
) {
1992 int totalWidth
= fTimeAlignedComposite
.getSize().x
;
1993 return Math
.min(totalWidth
, Math
.max(0, totalWidth
- requestedOffset
));
1997 * Perform the alignment operation.
2000 * the alignment offset
2002 * the alignment width
2004 * @see ITmfTimeAligned
2008 public void performAlign(int offset
, int width
) {
2009 fTimeGraphCtrl
.performAlign(offset
);
2010 int alignmentWidth
= width
;
2011 int size
= fTimeAlignedComposite
.getSize().x
;
2012 GridLayout layout
= (GridLayout
) fTimeAlignedComposite
.getLayout();
2013 int marginSize
= size
- alignmentWidth
- offset
;
2014 layout
.marginRight
= Math
.max(0, marginSize
);
2015 fTimeAlignedComposite
.layout();