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
.Collections
;
21 import java
.util
.Comparator
;
22 import java
.util
.HashSet
;
23 import java
.util
.List
;
26 import org
.eclipse
.jface
.action
.Action
;
27 import org
.eclipse
.jface
.action
.ActionContributionItem
;
28 import org
.eclipse
.jface
.action
.IAction
;
29 import org
.eclipse
.jface
.action
.IMenuCreator
;
30 import org
.eclipse
.jface
.action
.IMenuListener
;
31 import org
.eclipse
.jface
.action
.IMenuManager
;
32 import org
.eclipse
.jface
.action
.MenuManager
;
33 import org
.eclipse
.jface
.dialogs
.IDialogSettings
;
34 import org
.eclipse
.jface
.resource
.ImageDescriptor
;
35 import org
.eclipse
.jface
.viewers
.AbstractTreeViewer
;
36 import org
.eclipse
.jface
.viewers
.ISelectionProvider
;
37 import org
.eclipse
.jface
.viewers
.ITableLabelProvider
;
38 import org
.eclipse
.jface
.viewers
.ITreeContentProvider
;
39 import org
.eclipse
.jface
.viewers
.ViewerFilter
;
40 import org
.eclipse
.jface
.window
.Window
;
41 import org
.eclipse
.swt
.SWT
;
42 import org
.eclipse
.swt
.events
.ControlAdapter
;
43 import org
.eclipse
.swt
.events
.ControlEvent
;
44 import org
.eclipse
.swt
.events
.DisposeEvent
;
45 import org
.eclipse
.swt
.events
.DisposeListener
;
46 import org
.eclipse
.swt
.events
.KeyAdapter
;
47 import org
.eclipse
.swt
.events
.KeyEvent
;
48 import org
.eclipse
.swt
.events
.MenuDetectListener
;
49 import org
.eclipse
.swt
.events
.MouseEvent
;
50 import org
.eclipse
.swt
.events
.MouseWheelListener
;
51 import org
.eclipse
.swt
.events
.SelectionAdapter
;
52 import org
.eclipse
.swt
.events
.SelectionEvent
;
53 import org
.eclipse
.swt
.events
.SelectionListener
;
54 import org
.eclipse
.swt
.graphics
.Color
;
55 import org
.eclipse
.swt
.graphics
.RGBA
;
56 import org
.eclipse
.swt
.graphics
.Rectangle
;
57 import org
.eclipse
.swt
.layout
.FillLayout
;
58 import org
.eclipse
.swt
.layout
.GridData
;
59 import org
.eclipse
.swt
.layout
.GridLayout
;
60 import org
.eclipse
.swt
.widgets
.Composite
;
61 import org
.eclipse
.swt
.widgets
.Control
;
62 import org
.eclipse
.swt
.widgets
.Display
;
63 import org
.eclipse
.swt
.widgets
.Event
;
64 import org
.eclipse
.swt
.widgets
.Listener
;
65 import org
.eclipse
.swt
.widgets
.Menu
;
66 import org
.eclipse
.swt
.widgets
.Slider
;
67 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.Activator
;
68 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.ITmfImageConstants
;
69 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.Messages
;
70 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.dialogs
.AddBookmarkDialog
;
71 import org
.eclipse
.tracecompass
.tmf
.ui
.signal
.TmfTimeViewAlignmentInfo
;
72 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.ITmfTimeAligned
;
73 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.dialogs
.ShowFilterDialogAction
;
74 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.dialogs
.TimeGraphLegend
;
75 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.ILinkEvent
;
76 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.IMarkerEvent
;
77 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.ITimeEvent
;
78 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.ITimeGraphEntry
;
79 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.MarkerEvent
;
80 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.widgets
.ITimeDataProvider
;
81 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.widgets
.TimeDataProviderCyclesConverter
;
82 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.widgets
.TimeGraphColorScheme
;
83 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.widgets
.TimeGraphControl
;
84 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.widgets
.TimeGraphScale
;
85 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.widgets
.TimeGraphTooltipHandler
;
86 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.widgets
.Utils
;
87 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.widgets
.Utils
.TimeFormat
;
88 import org
.eclipse
.ui
.PlatformUI
;
91 * Generic time graph viewer implementation
93 * @author Patrick Tasse, and others
95 public class TimeGraphViewer
implements ITimeDataProvider
, SelectionListener
{
97 /** Constant indicating that all levels of the time graph should be expanded */
98 public static final int ALL_LEVELS
= AbstractTreeViewer
.ALL_LEVELS
;
100 private static final int DEFAULT_NAME_WIDTH
= 200;
101 private static final int MIN_NAME_WIDTH
= 6;
102 private static final int MAX_NAME_WIDTH
= 1000;
103 private static final int DEFAULT_HEIGHT
= 22;
104 private static final String HIDE_ARROWS_KEY
= "hide.arrows"; //$NON-NLS-1$
105 private static final long DEFAULT_FREQUENCY
= 1000000000L;
106 private static final int H_SCROLLBAR_MAX
= Integer
.MAX_VALUE
- 1;
108 private static ImageDescriptor ADD_BOOKMARK
= Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_ADD_BOOKMARK
);
109 private static ImageDescriptor NEXT_BOOKMARK
= Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_NEXT_BOOKMARK
);
110 private static ImageDescriptor PREVIOUS_BOOKMARK
= Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_PREVIOUS_BOOKMARK
);
111 private static ImageDescriptor REMOVE_BOOKMARK
= Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_REMOVE_BOOKMARK
);
113 private long fMinTimeInterval
;
114 private ITimeGraphEntry fSelectedEntry
;
115 private long fBeginTime
= SWT
.DEFAULT
; // The user-specified bounds start time
116 private long fEndTime
= SWT
.DEFAULT
; // The user-specified bounds end time
117 private long fTime0
= SWT
.DEFAULT
; // The current window start time
118 private long fTime1
= SWT
.DEFAULT
; // The current window end time
119 private long fSelectionBegin
= SWT
.DEFAULT
;
120 private long fSelectionEnd
= SWT
.DEFAULT
;
121 private long fTime0Bound
= SWT
.DEFAULT
; // The bounds start time
122 private long fTime1Bound
= SWT
.DEFAULT
; // The bounds end time
123 private long fTime0ExtSynch
= SWT
.DEFAULT
;
124 private long fTime1ExtSynch
= SWT
.DEFAULT
;
125 private boolean fTimeRangeFixed
;
126 private int fNameWidthPref
= DEFAULT_NAME_WIDTH
;
127 private int fMinNameWidth
= MIN_NAME_WIDTH
;
128 private int fNameWidth
;
129 private Composite fDataViewer
;
131 private TimeGraphControl fTimeGraphCtrl
;
132 private TimeGraphScale fTimeScaleCtrl
;
133 private Slider fHorizontalScrollBar
;
134 private Slider fVerticalScrollBar
;
135 private TimeGraphColorScheme fColorScheme
;
136 private Object fInputElement
;
137 private ITimeGraphContentProvider fTimeGraphContentProvider
;
138 private ITimeGraphPresentationProvider fTimeGraphProvider
;
139 private ITimeDataProvider fTimeDataProvider
= this;
140 private TimeGraphTooltipHandler fToolTipHandler
;
142 private List
<ITimeGraphSelectionListener
> fSelectionListeners
= new ArrayList
<>();
143 private List
<ITimeGraphTimeListener
> fTimeListeners
= new ArrayList
<>();
144 private List
<ITimeGraphRangeListener
> fRangeListeners
= new ArrayList
<>();
145 private List
<ITimeGraphBookmarkListener
> fBookmarkListeners
= new ArrayList
<>();
147 // Time format, using Epoch reference, Relative time format(default),
149 private TimeFormat fTimeFormat
= TimeFormat
.RELATIVE
;
150 // Clock frequency to use for Cycles time format
151 private long fClockFrequency
= DEFAULT_FREQUENCY
;
152 private int fBorderWidth
= 0;
153 private int fTimeScaleHeight
= DEFAULT_HEIGHT
;
155 private Action fResetScaleAction
;
156 private Action fShowLegendAction
;
157 private Action fNextEventAction
;
158 private Action fPrevEventAction
;
159 private Action fNextItemAction
;
160 private Action fPreviousItemAction
;
161 private Action fZoomInAction
;
162 private Action fZoomOutAction
;
163 private Action fHideArrowsAction
;
164 private Action fFollowArrowFwdAction
;
165 private Action fFollowArrowBwdAction
;
166 private ShowFilterDialogAction fShowFilterDialogAction
;
167 private Action fToggleBookmarkAction
;
168 private Action fNextMarkerAction
;
169 private Action fPreviousMarkerAction
;
170 private MenuManager fMarkersMenu
;
172 /** The list of bookmarks */
173 private final List
<IMarkerEvent
> fBookmarks
= new ArrayList
<>();
175 /** The list of marker categories */
176 private final List
<String
> fMarkerCategories
= new ArrayList
<>();
178 /** The set of hidden marker categories */
179 private final Set
<String
> fHiddenMarkerCategories
= new HashSet
<>();
181 /** The set of skipped marker categories */
182 private final Set
<String
> fSkippedMarkerCategories
= new HashSet
<>();
184 /** The list of markers */
185 private final List
<IMarkerEvent
> fMarkers
= new ArrayList
<>();
187 /** The list of color resources created by this viewer */
188 private final List
<Color
> fColors
= new ArrayList
<>();
190 private ListenerNotifier fListenerNotifier
;
192 private Composite fTimeAlignedComposite
;
194 private class ListenerNotifier
extends Thread
{
195 private static final long DELAY
= 400L;
196 private static final long POLLING_INTERVAL
= 10L;
197 private long fLastUpdateTime
= Long
.MAX_VALUE
;
198 private boolean fSelectionChanged
= false;
199 private boolean fTimeRangeUpdated
= false;
200 private boolean fTimeSelected
= false;
204 while ((System
.currentTimeMillis() - fLastUpdateTime
) < DELAY
) {
206 Thread
.sleep(POLLING_INTERVAL
);
207 } catch (Exception e
) {
211 Display
.getDefault().asyncExec(new Runnable() {
214 if (fListenerNotifier
!= ListenerNotifier
.this) {
217 fListenerNotifier
= null;
218 if (ListenerNotifier
.this.isInterrupted() || fDataViewer
.isDisposed()) {
221 if (fSelectionChanged
) {
222 fireSelectionChanged(fSelectedEntry
);
224 if (fTimeRangeUpdated
) {
225 fireTimeRangeUpdated(fTime0
, fTime1
);
228 fireTimeSelected(fSelectionBegin
, fSelectionEnd
);
234 public void selectionChanged() {
235 fSelectionChanged
= true;
236 fLastUpdateTime
= System
.currentTimeMillis();
239 public void timeRangeUpdated() {
240 fTimeRangeUpdated
= true;
241 fLastUpdateTime
= System
.currentTimeMillis();
244 public void timeSelected() {
245 fTimeSelected
= true;
246 fLastUpdateTime
= System
.currentTimeMillis();
249 public boolean hasSelectionChanged() {
250 return fSelectionChanged
;
253 public boolean hasTimeRangeUpdated() {
254 return fTimeRangeUpdated
;
257 public boolean hasTimeSelected() {
258 return fTimeSelected
;
262 private final static class MarkerComparator
implements Comparator
<IMarkerEvent
> {
264 public int compare(IMarkerEvent o1
, IMarkerEvent o2
) {
265 int res
= Long
.compare(o1
.getTime(), o2
.getTime());
269 return Long
.compare(o1
.getDuration(), o2
.getDuration());
274 * Standard constructor.
276 * The default timegraph content provider accepts an ITimeGraphEntry[] as input element.
279 * The parent UI composite object
283 public TimeGraphViewer(Composite parent
, int style
) {
284 createDataViewer(parent
, style
);
285 fTimeGraphContentProvider
= new TimeGraphContentProvider();
289 * Sets the timegraph content provider used by this timegraph viewer.
291 * @param timeGraphContentProvider
292 * the timegraph content provider
294 public void setTimeGraphContentProvider(ITimeGraphContentProvider timeGraphContentProvider
) {
295 fTimeGraphContentProvider
= timeGraphContentProvider
;
299 * Gets the timegraph content provider used by this timegraph viewer.
301 * @return the timegraph content provider
303 public ITimeGraphContentProvider
getTimeGraphContentProvider() {
304 return fTimeGraphContentProvider
;
308 * Sets the timegraph presentation provider used by this timegraph viewer.
310 * @param timeGraphProvider
311 * the timegraph provider
313 public void setTimeGraphProvider(ITimeGraphPresentationProvider timeGraphProvider
) {
314 fTimeGraphProvider
= timeGraphProvider
;
315 fTimeGraphCtrl
.setTimeGraphProvider(timeGraphProvider
);
316 fToolTipHandler
= new TimeGraphTooltipHandler(fTimeGraphProvider
, fTimeDataProvider
);
317 fToolTipHandler
.activateHoverHelp(fTimeGraphCtrl
);
321 * Sets the tree columns for this time graph combo's filter dialog.
323 * @param columnNames the tree column names
326 public void setFilterColumns(String
[] columnNames
) {
327 getShowFilterDialogAction().getFilterDialog().setColumnNames(columnNames
);
331 * Sets the tree content provider used by the filter dialog
333 * @param contentProvider the tree content provider
336 public void setFilterContentProvider(ITreeContentProvider contentProvider
) {
337 getShowFilterDialogAction().getFilterDialog().setContentProvider(contentProvider
);
341 * Sets the tree label provider used by the filter dialog
343 * @param labelProvider the tree label provider
346 public void setFilterLabelProvider(ITableLabelProvider labelProvider
) {
347 getShowFilterDialogAction().getFilterDialog().setLabelProvider(labelProvider
);
351 * Sets or clears the input for this time graph viewer.
353 * @param inputElement
354 * The input of this time graph viewer, or <code>null</code> if
357 public void setInput(Object inputElement
) {
358 fInputElement
= inputElement
;
359 ITimeGraphEntry
[] input
= fTimeGraphContentProvider
.getElements(inputElement
);
360 fListenerNotifier
= null;
361 if (fTimeGraphCtrl
!= null) {
364 fSelectionBegin
= SWT
.DEFAULT
;
365 fSelectionEnd
= SWT
.DEFAULT
;
366 updateMarkerActions();
367 fSelectedEntry
= null;
368 refreshAllData(input
);
373 * Gets the input for this time graph viewer.
375 * @return The input of this time graph viewer, or <code>null</code> if none
377 public Object
getInput() {
378 return fInputElement
;
382 * Sets (or clears if null) the list of links to display on this combo
385 * the links to display in this time graph combo
387 public void setLinks(List
<ILinkEvent
> links
) {
388 if (fTimeGraphCtrl
!= null) {
389 fTimeGraphCtrl
.refreshArrows(links
);
396 public void refresh() {
397 ITimeGraphEntry
[] input
= fTimeGraphContentProvider
.getElements(fInputElement
);
399 refreshAllData(input
);
403 * Callback for when the control is moved
408 public void controlMoved(ControlEvent e
) {
412 * Callback for when the control is resized
417 public void controlResized(ControlEvent e
) {
422 * @return The string representing the view type
424 protected String
getViewTypeStr() {
425 return "viewoption.threads"; //$NON-NLS-1$
428 int getMarginWidth() {
432 int getMarginHeight() {
437 fMinTimeInterval
= 1;
438 fSelectionBegin
= SWT
.DEFAULT
;
439 fSelectionEnd
= SWT
.DEFAULT
;
440 fNameWidth
= Utils
.loadIntOption(getPreferenceString("namewidth"), //$NON-NLS-1$
441 fNameWidthPref
, fMinNameWidth
, MAX_NAME_WIDTH
);
445 Utils
.saveIntOption(getPreferenceString("namewidth"), fNameWidth
); //$NON-NLS-1$
449 * Create a data viewer.
455 * @return The new data viewer
457 protected Control
createDataViewer(Composite parent
, int style
) {
459 fColorScheme
= new TimeGraphColorScheme();
460 fDataViewer
= new Composite(parent
, style
) {
462 public void redraw() {
463 fTimeScaleCtrl
.redraw();
464 fTimeGraphCtrl
.redraw();
468 fDataViewer
.addDisposeListener(new DisposeListener() {
470 public void widgetDisposed(DisposeEvent e
) {
471 for (Color color
: fColors
) {
474 if (fMarkersMenu
!= null) {
475 fMarkersMenu
.dispose();
479 GridLayout gl
= new GridLayout(2, false);
480 gl
.marginHeight
= fBorderWidth
;
482 gl
.verticalSpacing
= 0;
483 gl
.horizontalSpacing
= 0;
484 fDataViewer
.setLayout(gl
);
486 fTimeAlignedComposite
= new Composite(fDataViewer
, style
) {
488 public void redraw() {
489 fDataViewer
.redraw();
493 GridLayout gl2
= new GridLayout(1, false);
494 gl2
.marginHeight
= fBorderWidth
;
496 gl2
.verticalSpacing
= 0;
497 gl2
.horizontalSpacing
= 0;
498 fTimeAlignedComposite
.setLayout(gl2
);
499 fTimeAlignedComposite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
501 fTimeScaleCtrl
= new TimeGraphScale(fTimeAlignedComposite
, fColorScheme
);
502 fTimeScaleCtrl
.setTimeProvider(fTimeDataProvider
);
503 fTimeScaleCtrl
.setLayoutData(new GridData(SWT
.FILL
, SWT
.DEFAULT
, true, false));
504 fTimeScaleCtrl
.setHeight(fTimeScaleHeight
);
505 fTimeScaleCtrl
.addMouseWheelListener(new MouseWheelListener() {
507 public void mouseScrolled(MouseEvent e
) {
508 fTimeGraphCtrl
.zoom(e
.count
> 0);
512 fTimeGraphCtrl
= createTimeGraphControl(fTimeAlignedComposite
, fColorScheme
);
514 fTimeGraphCtrl
.setTimeProvider(this);
515 fTimeGraphCtrl
.setTimeGraphScale(fTimeScaleCtrl
);
516 fTimeGraphCtrl
.addSelectionListener(this);
517 fTimeGraphCtrl
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
518 fTimeGraphCtrl
.addMouseWheelListener(new MouseWheelListener() {
520 public void mouseScrolled(MouseEvent e
) {
521 adjustVerticalScrollBar();
524 fTimeGraphCtrl
.addKeyListener(new KeyAdapter() {
526 public void keyPressed(KeyEvent e
) {
527 if (e
.character
== '+') {
529 } else if (e
.character
== '-') {
532 adjustVerticalScrollBar();
536 fVerticalScrollBar
= new Slider(fDataViewer
, SWT
.VERTICAL
| SWT
.NO_FOCUS
);
537 fVerticalScrollBar
.setLayoutData(new GridData(SWT
.DEFAULT
, SWT
.FILL
, false, true, 1, 1));
538 fVerticalScrollBar
.addSelectionListener(new SelectionAdapter() {
540 public void widgetSelected(SelectionEvent e
) {
541 setTopIndex(fVerticalScrollBar
.getSelection());
545 fHorizontalScrollBar
= new Slider(fDataViewer
, SWT
.HORIZONTAL
| SWT
.NO_FOCUS
);
546 fHorizontalScrollBar
.setLayoutData(new GridData(SWT
.FILL
, SWT
.DEFAULT
, true, false));
547 fHorizontalScrollBar
.addListener(SWT
.MouseWheel
, new Listener() {
549 public void handleEvent(Event event
) {
550 if ((event
.stateMask
& SWT
.MODIFIER_MASK
) == SWT
.CTRL
) {
551 getTimeGraphControl().zoom(event
.count
> 0);
553 getTimeGraphControl().horizontalScroll(event
.count
> 0);
555 // don't handle the immediately following SWT.Selection event
559 fHorizontalScrollBar
.addListener(SWT
.Selection
, new Listener() {
561 public void handleEvent(Event event
) {
562 int start
= fHorizontalScrollBar
.getSelection();
563 long time0
= getTime0();
564 long time1
= getTime1();
565 long timeMin
= getMinTime();
566 long timeMax
= getMaxTime();
567 long delta
= timeMax
- timeMin
;
569 long range
= time1
- time0
;
570 time0
= timeMin
+ Math
.round(delta
* ((double) start
/ H_SCROLLBAR_MAX
));
571 time1
= time0
+ range
;
573 setStartFinishTimeNotify(time0
, time1
);
577 Composite filler
= new Composite(fDataViewer
, SWT
.NONE
);
578 GridData gd
= new GridData(SWT
.DEFAULT
, SWT
.DEFAULT
, false, false);
579 gd
.heightHint
= fHorizontalScrollBar
.getSize().y
;
580 filler
.setLayoutData(gd
);
581 filler
.setLayout(new FillLayout());
583 fTimeGraphCtrl
.addControlListener(new ControlAdapter() {
585 public void controlResized(ControlEvent event
) {
590 fDataViewer
.update();
591 adjustHorizontalScrollBar();
592 adjustVerticalScrollBar();
599 public void dispose() {
601 fTimeGraphCtrl
.dispose();
602 fDataViewer
.dispose();
603 fColorScheme
.dispose();
607 * Create a new time graph control.
610 * The parent composite
613 * @return The new TimeGraphControl
615 protected TimeGraphControl
createTimeGraphControl(Composite parent
,
616 TimeGraphColorScheme colors
) {
617 return new TimeGraphControl(parent
, colors
);
621 * Resize the controls
623 public void resizeControls() {
624 Rectangle r
= fDataViewer
.getClientArea();
630 if (fNameWidth
> width
- fMinNameWidth
) {
631 fNameWidth
= width
- fMinNameWidth
;
633 if (fNameWidth
< fMinNameWidth
) {
634 fNameWidth
= fMinNameWidth
;
636 adjustHorizontalScrollBar();
637 adjustVerticalScrollBar();
641 * Recalculate the time bounds based on the time graph entries,
642 * if the user-specified bound is set to SWT.DEFAULT.
645 * The root time graph entries in the model
647 public void setTimeRange(ITimeGraphEntry entries
[]) {
648 fTime0Bound
= (fBeginTime
!= SWT
.DEFAULT ? fBeginTime
: fEndTime
);
649 fTime1Bound
= (fEndTime
!= SWT
.DEFAULT ? fEndTime
: fBeginTime
);
650 if (fBeginTime
!= SWT
.DEFAULT
&& fEndTime
!= SWT
.DEFAULT
) {
653 if (entries
== null || entries
.length
== 0) {
656 if (fTime0Bound
== SWT
.DEFAULT
) {
657 fTime0Bound
= Long
.MAX_VALUE
;
659 if (fTime1Bound
== SWT
.DEFAULT
) {
660 fTime1Bound
= Long
.MIN_VALUE
;
662 for (ITimeGraphEntry entry
: entries
) {
667 private void setTimeRange(ITimeGraphEntry entry
) {
668 if (fBeginTime
== SWT
.DEFAULT
&& entry
.hasTimeEvents() && entry
.getStartTime() != SWT
.DEFAULT
) {
669 fTime0Bound
= Math
.min(entry
.getStartTime(), fTime0Bound
);
671 if (fEndTime
== SWT
.DEFAULT
&& entry
.hasTimeEvents() && entry
.getEndTime() != SWT
.DEFAULT
) {
672 fTime1Bound
= Math
.max(entry
.getEndTime(), fTime1Bound
);
674 if (entry
.hasChildren()) {
675 for (ITimeGraphEntry child
: entry
.getChildren()) {
682 * Set the time bounds to the provided values.
685 * The bounds begin time, or SWT.DEFAULT to use the input bounds
687 * The bounds end time, or SWT.DEFAULT to use the input bounds
689 public void setTimeBounds(long beginTime
, long endTime
) {
690 fBeginTime
= beginTime
;
692 fTime0Bound
= (fBeginTime
!= SWT
.DEFAULT ? fBeginTime
: fEndTime
);
693 fTime1Bound
= (fEndTime
!= SWT
.DEFAULT ? fEndTime
: fBeginTime
);
694 if (fTime0Bound
> fTime1Bound
) {
695 // only possible if both are not default
696 fBeginTime
= endTime
;
697 fEndTime
= beginTime
;
698 fTime0Bound
= fBeginTime
;
699 fTime1Bound
= fEndTime
;
701 adjustHorizontalScrollBar();
705 * Recalculate the current time window when bounds have changed.
707 public void setTimeBounds() {
708 if (!fTimeRangeFixed
) {
709 fTime0
= fTime0Bound
;
710 fTime1
= fTime1Bound
;
712 fTime0
= Math
.max(fTime0Bound
, Math
.min(fTime0
, fTime1Bound
));
713 fTime1
= Math
.max(fTime0Bound
, Math
.min(fTime1
, fTime1Bound
));
714 if (fTime1
- fTime0
< fMinTimeInterval
) {
715 fTime1
= Math
.min(fTime1Bound
, fTime0
+ fMinTimeInterval
);
722 private void refreshAllData(ITimeGraphEntry
[] traces
) {
724 if (fSelectionBegin
< fBeginTime
) {
725 fSelectionBegin
= fBeginTime
;
726 } else if (fSelectionBegin
> fEndTime
) {
727 fSelectionBegin
= fEndTime
;
729 if (fSelectionEnd
< fBeginTime
) {
730 fSelectionEnd
= fBeginTime
;
731 } else if (fSelectionEnd
> fEndTime
) {
732 fSelectionEnd
= fEndTime
;
734 fTimeGraphCtrl
.refreshData(traces
);
735 fTimeScaleCtrl
.redraw();
736 updateMarkerActions();
737 adjustVerticalScrollBar();
741 * Callback for when this view is focused
743 public void setFocus() {
744 if (null != fTimeGraphCtrl
) {
745 fTimeGraphCtrl
.setFocus();
750 * Get the current focus status of this view.
752 * @return If the view is currently focused, or not
754 public boolean isInFocus() {
755 return fTimeGraphCtrl
.isInFocus();
759 * Get the view's current selection
761 * @return The entry that is selected
763 public ITimeGraphEntry
getSelection() {
764 return fTimeGraphCtrl
.getSelectedTrace();
768 * Get the index of the current selection
772 public int getSelectionIndex() {
773 return fTimeGraphCtrl
.getSelectedIndex();
777 public long getTime0() {
782 public long getTime1() {
787 public long getMinTimeInterval() {
788 return fMinTimeInterval
;
792 public int getNameSpace() {
797 public void setNameSpace(int width
) {
799 int w
= fTimeGraphCtrl
.getClientArea().width
;
800 if (fNameWidth
> w
- MIN_NAME_WIDTH
) {
801 fNameWidth
= w
- MIN_NAME_WIDTH
;
803 if (fNameWidth
< MIN_NAME_WIDTH
) {
804 fNameWidth
= MIN_NAME_WIDTH
;
806 fTimeGraphCtrl
.redraw();
807 fTimeScaleCtrl
.redraw();
811 public int getTimeSpace() {
812 int w
= fTimeGraphCtrl
.getClientArea().width
;
813 return w
- fNameWidth
;
817 public long getBeginTime() {
822 public long getEndTime() {
827 public long getMaxTime() {
832 public long getMinTime() {
837 public long getSelectionBegin() {
838 return fSelectionBegin
;
842 public long getSelectionEnd() {
843 return fSelectionEnd
;
847 public void setStartFinishTimeNotify(long time0
, long time1
) {
848 setStartFinishTimeInt(time0
, time1
);
849 notifyRangeListeners();
853 public void notifyStartFinishTime() {
854 notifyRangeListeners();
858 public void setStartFinishTime(long time0
, long time1
) {
859 /* if there is a pending time range, ignore this one */
860 if (fListenerNotifier
!= null && fListenerNotifier
.hasTimeRangeUpdated()) {
863 setStartFinishTimeInt(time0
, time1
);
864 updateExtSynchValues();
867 private void setStartFinishTimeInt(long time0
, long time1
) {
869 if (fTime0
< fTime0Bound
) {
870 fTime0
= fTime0Bound
;
872 if (fTime0
> fTime1Bound
) {
873 fTime0
= fTime1Bound
;
876 if (fTime1
< fTime0Bound
) {
877 fTime1
= fTime0Bound
;
879 if (fTime1
> fTime1Bound
) {
880 fTime1
= fTime1Bound
;
882 if (fTime1
- fTime0
< fMinTimeInterval
) {
883 fTime1
= Math
.min(fTime1Bound
, fTime0
+ fMinTimeInterval
);
885 fTimeRangeFixed
= true;
886 adjustHorizontalScrollBar();
887 fTimeGraphCtrl
.redraw();
888 fTimeScaleCtrl
.redraw();
892 public void resetStartFinishTime() {
893 setStartFinishTimeNotify(fTime0Bound
, fTime1Bound
);
894 fTimeRangeFixed
= false;
898 public void setSelectedTimeNotify(long time
, boolean ensureVisible
) {
899 setSelectedTimeInt(time
, ensureVisible
, true);
903 public void setSelectedTime(long time
, boolean ensureVisible
) {
904 /* if there is a pending time selection, ignore this one */
905 if (fListenerNotifier
!= null && fListenerNotifier
.hasTimeSelected()) {
908 setSelectedTimeInt(time
, ensureVisible
, false);
912 public void setSelectionRangeNotify(long beginTime
, long endTime
) {
915 long selectionBegin
= fSelectionBegin
;
916 long selectionEnd
= fSelectionEnd
;
917 fSelectionBegin
= Math
.max(fTime0Bound
, Math
.min(fTime1Bound
, beginTime
));
918 fSelectionEnd
= Math
.max(fTime0Bound
, Math
.min(fTime1Bound
, endTime
));
919 boolean changed
= (selectionBegin
!= fSelectionBegin
|| selectionEnd
!= fSelectionEnd
);
920 ensureVisible(fSelectionEnd
);
921 fTimeGraphCtrl
.redraw();
922 fTimeScaleCtrl
.redraw();
923 updateMarkerActions();
924 if ((time0
!= fTime0
) || (time1
!= fTime1
)) {
925 notifyRangeListeners();
928 notifyTimeListeners();
933 public void setSelectionRange(long beginTime
, long endTime
) {
934 /* if there is a pending time selection, ignore this one */
935 if (fListenerNotifier
!= null && fListenerNotifier
.hasTimeSelected()) {
938 fSelectionBegin
= Math
.max(fTime0Bound
, Math
.min(fTime1Bound
, beginTime
));
939 fSelectionEnd
= Math
.max(fTime0Bound
, Math
.min(fTime1Bound
, endTime
));
940 fTimeGraphCtrl
.redraw();
941 fTimeScaleCtrl
.redraw();
942 updateMarkerActions();
945 private void setSelectedTimeInt(long time
, boolean ensureVisible
, boolean doNotify
) {
946 long selection
= Math
.max(fTime0Bound
, Math
.min(fTime1Bound
, time
));
950 ensureVisible(selection
);
952 fTimeGraphCtrl
.redraw();
953 fTimeScaleCtrl
.redraw();
955 boolean notifySelectedTime
= (selection
!= fSelectionBegin
|| selection
!= fSelectionEnd
);
956 fSelectionBegin
= selection
;
957 fSelectionEnd
= selection
;
958 updateMarkerActions();
960 if ((time0
!= fTime0
) || (time1
!= fTime1
)) {
961 notifyRangeListeners();
964 if (doNotify
&& notifySelectedTime
) {
965 notifyTimeListeners();
969 private void ensureVisible(long time
) {
970 long timeMid
= (fTime1
- fTime0
) / 2;
972 long dt
= fTime0
- time
+ timeMid
;
975 } else if (time
> fTime1
) {
976 long dt
= time
- fTime1
+ timeMid
;
980 if (fTime0
< fTime0Bound
) {
981 fTime1
= Math
.min(fTime1Bound
, fTime1
+ (fTime0Bound
- fTime0
));
982 fTime0
= fTime0Bound
;
983 } else if (fTime1
> fTime1Bound
) {
984 fTime0
= Math
.max(fTime0Bound
, fTime0
- (fTime1
- fTime1Bound
));
985 fTime1
= fTime1Bound
;
987 if (fTime1
- fTime0
< fMinTimeInterval
) {
988 fTime1
= Math
.min(fTime1Bound
, fTime0
+ fMinTimeInterval
);
990 adjustHorizontalScrollBar();
994 public void widgetDefaultSelected(SelectionEvent e
) {
995 if (fSelectedEntry
!= getSelection()) {
996 fSelectedEntry
= getSelection();
997 notifySelectionListeners();
1002 public void widgetSelected(SelectionEvent e
) {
1003 if (fSelectedEntry
!= getSelection()) {
1004 fSelectedEntry
= getSelection();
1005 notifySelectionListeners();
1010 * Callback for when the next event is selected
1013 * true to extend selection range, false for single selection
1016 public void selectNextEvent(boolean extend
) {
1017 fTimeGraphCtrl
.selectNextEvent(extend
);
1018 adjustVerticalScrollBar();
1022 * Callback for when the previous event is selected
1025 * true to extend selection range, false for single selection
1028 public void selectPrevEvent(boolean extend
) {
1029 fTimeGraphCtrl
.selectPrevEvent(extend
);
1030 adjustVerticalScrollBar();
1034 * Callback for when the next item is selected
1036 public void selectNextItem() {
1037 fTimeGraphCtrl
.selectNextTrace();
1038 adjustVerticalScrollBar();
1042 * Callback for when the previous item is selected
1044 public void selectPrevItem() {
1045 fTimeGraphCtrl
.selectPrevTrace();
1046 adjustVerticalScrollBar();
1050 * Callback for the show legend action
1052 public void showLegend() {
1053 if (fDataViewer
== null || fDataViewer
.isDisposed()) {
1057 TimeGraphLegend
.open(fDataViewer
.getShell(), fTimeGraphProvider
);
1061 * Callback for the Zoom In action
1063 public void zoomIn() {
1064 fTimeGraphCtrl
.zoomIn();
1068 * Callback for the Zoom Out action
1070 public void zoomOut() {
1071 fTimeGraphCtrl
.zoomOut();
1074 private String
getPreferenceString(String string
) {
1075 return getViewTypeStr() + "." + string
; //$NON-NLS-1$
1079 * Add a selection listener
1082 * The listener to add
1084 public void addSelectionListener(ITimeGraphSelectionListener listener
) {
1085 fSelectionListeners
.add(listener
);
1089 * Remove a selection listener
1092 * The listener to remove
1094 public void removeSelectionListener(ITimeGraphSelectionListener listener
) {
1095 fSelectionListeners
.remove(listener
);
1098 private void notifySelectionListeners() {
1099 if (fListenerNotifier
== null) {
1100 fListenerNotifier
= new ListenerNotifier();
1101 fListenerNotifier
.start();
1103 fListenerNotifier
.selectionChanged();
1106 private void fireSelectionChanged(ITimeGraphEntry selection
) {
1107 TimeGraphSelectionEvent event
= new TimeGraphSelectionEvent(this, selection
);
1109 for (ITimeGraphSelectionListener listener
: fSelectionListeners
) {
1110 listener
.selectionChanged(event
);
1115 * Add a time listener
1118 * The listener to add
1120 public void addTimeListener(ITimeGraphTimeListener listener
) {
1121 fTimeListeners
.add(listener
);
1125 * Remove a time listener
1128 * The listener to remove
1130 public void removeTimeListener(ITimeGraphTimeListener listener
) {
1131 fTimeListeners
.remove(listener
);
1134 private void notifyTimeListeners() {
1135 if (fListenerNotifier
== null) {
1136 fListenerNotifier
= new ListenerNotifier();
1137 fListenerNotifier
.start();
1139 fListenerNotifier
.timeSelected();
1142 private void fireTimeSelected(long startTime
, long endTime
) {
1143 TimeGraphTimeEvent event
= new TimeGraphTimeEvent(this, startTime
, endTime
);
1145 for (ITimeGraphTimeListener listener
: fTimeListeners
) {
1146 listener
.timeSelected(event
);
1151 * Add a range listener
1154 * The listener to add
1156 public void addRangeListener(ITimeGraphRangeListener listener
) {
1157 fRangeListeners
.add(listener
);
1161 * Remove a range listener
1164 * The listener to remove
1166 public void removeRangeListener(ITimeGraphRangeListener listener
) {
1167 fRangeListeners
.remove(listener
);
1170 private void notifyRangeListeners() {
1171 if (fListenerNotifier
== null) {
1172 fListenerNotifier
= new ListenerNotifier();
1173 fListenerNotifier
.start();
1175 fListenerNotifier
.timeRangeUpdated();
1178 private void fireTimeRangeUpdated(long startTime
, long endTime
) {
1179 // Check if the time has actually changed from last notification
1180 if (startTime
!= fTime0ExtSynch
|| endTime
!= fTime1ExtSynch
) {
1181 // Notify Time Scale Selection Listeners
1182 TimeGraphRangeUpdateEvent event
= new TimeGraphRangeUpdateEvent(this, startTime
, endTime
);
1184 for (ITimeGraphRangeListener listener
: fRangeListeners
) {
1185 listener
.timeRangeUpdated(event
);
1188 // update external synch values
1189 updateExtSynchValues();
1194 * Add a bookmark listener
1197 * The listener to add
1200 public void addBookmarkListener(ITimeGraphBookmarkListener listener
) {
1201 fBookmarkListeners
.add(listener
);
1205 * Remove a bookmark listener
1208 * The listener to remove
1211 public void removeBookmarkListener(ITimeGraphBookmarkListener listener
) {
1212 fBookmarkListeners
.remove(listener
);
1215 private void fireBookmarkAdded(IMarkerEvent bookmark
) {
1216 TimeGraphBookmarkEvent event
= new TimeGraphBookmarkEvent(this, bookmark
);
1218 for (ITimeGraphBookmarkListener listener
: fBookmarkListeners
) {
1219 listener
.bookmarkAdded(event
);
1223 private void fireBookmarkRemoved(IMarkerEvent bookmark
) {
1224 TimeGraphBookmarkEvent event
= new TimeGraphBookmarkEvent(this, bookmark
);
1226 for (ITimeGraphBookmarkListener listener
: fBookmarkListeners
) {
1227 listener
.bookmarkRemoved(event
);
1232 * Set the bookmarks list.
1235 * The bookmarks list, or null
1238 public void setBookmarks(List
<IMarkerEvent
> bookmarks
) {
1239 for (IMarkerEvent bookmark
: fBookmarks
) {
1240 checkDisposeColor(bookmark
.getColor());
1243 if (bookmarks
!= null) {
1244 fBookmarks
.addAll(bookmarks
);
1247 updateMarkerActions();
1251 * Get the bookmarks list.
1253 * @return The bookmarks list
1256 public List
<IMarkerEvent
> getBookmarks() {
1257 return Collections
.unmodifiableList(fBookmarks
);
1261 * Set the list of marker categories.
1264 * The list of marker categories, or null
1267 public void setMarkerCategories(List
<String
> categories
) {
1268 fMarkerCategories
.clear();
1269 fMarkerCategories
.add(IMarkerEvent
.BOOKMARKS
);
1270 if (categories
!= null) {
1271 fMarkerCategories
.addAll(categories
);
1273 Collections
.sort(fMarkerCategories
);
1277 * Set the markers list.
1280 * The markers list, or null
1283 public void setMarkers(List
<IMarkerEvent
> markers
) {
1285 if (markers
!= null) {
1286 fMarkers
.addAll(markers
);
1289 updateMarkerActions();
1293 * Get the markers list.
1295 * @return The markers list, or null
1298 public List
<IMarkerEvent
> getMarkers() {
1299 return Collections
.unmodifiableList(fMarkers
);
1303 * Dispose the color resource if and only if it was created by this viewer.
1308 private void checkDisposeColor(Color color
) {
1309 for (int i
= 0; i
< fColors
.size(); i
++) {
1310 /* check for identity, not equality */
1311 if (fColors
.get(i
) == color
) {
1320 * Callback to set a selected event in the view
1323 * The event that was selected
1325 * The source of this selection event
1327 public void setSelectedEvent(ITimeEvent event
, Object source
) {
1328 if (event
== null || source
== this) {
1331 fSelectedEntry
= event
.getEntry();
1332 fTimeGraphCtrl
.selectItem(fSelectedEntry
, false);
1334 setSelectedTimeInt(event
.getTime(), true, true);
1335 adjustVerticalScrollBar();
1339 * Set the seeked time of a trace
1342 * The trace that was seeked
1346 * The source of this seek event
1348 public void setSelectedTraceTime(ITimeGraphEntry trace
, long time
, Object source
) {
1349 if (trace
== null || source
== this) {
1352 fSelectedEntry
= trace
;
1353 fTimeGraphCtrl
.selectItem(trace
, false);
1355 setSelectedTimeInt(time
, true, true);
1359 * Callback for a trace selection
1362 * The trace that was selected
1364 public void setSelection(ITimeGraphEntry trace
) {
1365 /* if there is a pending selection, ignore this one */
1366 if (fListenerNotifier
!= null && fListenerNotifier
.hasSelectionChanged()) {
1369 fSelectedEntry
= trace
;
1370 fTimeGraphCtrl
.selectItem(trace
, false);
1371 adjustVerticalScrollBar();
1375 * Callback for a time window selection
1378 * Start time of the range
1380 * End time of the range
1382 * Source of the event
1384 public void setSelectVisTimeWindow(long time0
, long time1
, Object source
) {
1385 if (source
== this) {
1389 setStartFinishTimeInt(time0
, time1
);
1391 // update notification time values since we are now in synch with the
1392 // external application
1393 updateExtSynchValues();
1397 * update the cache values used to identify the need to send a time window
1398 * update to external registered listeners
1400 private void updateExtSynchValues() {
1401 // last time notification cache
1402 fTime0ExtSynch
= fTime0
;
1403 fTime1ExtSynch
= fTime1
;
1407 public TimeFormat
getTimeFormat() {
1413 * the {@link TimeFormat} used to display timestamps
1415 public void setTimeFormat(TimeFormat tf
) {
1416 this.fTimeFormat
= tf
;
1417 if (tf
== TimeFormat
.CYCLES
) {
1418 fTimeDataProvider
= new TimeDataProviderCyclesConverter(this, fClockFrequency
);
1420 fTimeDataProvider
= this;
1422 fTimeScaleCtrl
.setTimeProvider(fTimeDataProvider
);
1423 if (fToolTipHandler
!= null) {
1424 fToolTipHandler
.setTimeProvider(fTimeDataProvider
);
1429 * Sets the clock frequency. Used when the time format is set to CYCLES.
1431 * @param clockFrequency
1432 * the clock frequency in Hz
1434 public void setClockFrequency(long clockFrequency
) {
1435 fClockFrequency
= clockFrequency
;
1436 if (fTimeFormat
== TimeFormat
.CYCLES
) {
1437 fTimeDataProvider
= new TimeDataProviderCyclesConverter(this, fClockFrequency
);
1438 fTimeScaleCtrl
.setTimeProvider(fTimeDataProvider
);
1439 if (fToolTipHandler
!= null) {
1440 fToolTipHandler
.setTimeProvider(fTimeDataProvider
);
1446 * Retrieve the border width
1450 public int getBorderWidth() {
1451 return fBorderWidth
;
1455 * Set the border width
1457 * @param borderWidth
1460 public void setBorderWidth(int borderWidth
) {
1461 if (borderWidth
> -1) {
1462 this.fBorderWidth
= borderWidth
;
1463 GridLayout gl
= (GridLayout
) fDataViewer
.getLayout();
1464 gl
.marginHeight
= borderWidth
;
1469 * Retrieve the height of the header
1471 * @return The height
1473 public int getHeaderHeight() {
1474 return fTimeScaleHeight
;
1478 * Set the height of the header
1480 * @param headerHeight
1483 public void setHeaderHeight(int headerHeight
) {
1484 if (headerHeight
> -1) {
1485 this.fTimeScaleHeight
= headerHeight
;
1486 fTimeScaleCtrl
.setHeight(headerHeight
);
1491 * Retrieve the height of an item row
1493 * @return The height
1495 public int getItemHeight() {
1496 if (fTimeGraphCtrl
!= null) {
1497 return fTimeGraphCtrl
.getItemHeight();
1503 * Set the height of an item row
1508 public void setItemHeight(int rowHeight
) {
1509 if (fTimeGraphCtrl
!= null) {
1510 fTimeGraphCtrl
.setItemHeight(rowHeight
);
1515 * Set the minimum item width
1520 public void setMinimumItemWidth(int width
) {
1521 if (fTimeGraphCtrl
!= null) {
1522 fTimeGraphCtrl
.setMinimumItemWidth(width
);
1527 * Set the width for the name column
1532 public void setNameWidthPref(int width
) {
1533 fNameWidthPref
= width
;
1541 * Retrieve the configure width for the name column
1547 public int getNameWidthPref(int width
) {
1548 return fNameWidthPref
;
1552 * Returns the primary control associated with this viewer.
1554 * @return the SWT control which displays this viewer's content
1556 public Control
getControl() {
1561 * Returns the time graph control associated with this viewer.
1563 * @return the time graph control
1565 public TimeGraphControl
getTimeGraphControl() {
1566 return fTimeGraphCtrl
;
1570 * Returns the time graph scale associated with this viewer.
1572 * @return the time graph scale
1574 public TimeGraphScale
getTimeGraphScale() {
1575 return fTimeScaleCtrl
;
1579 * Returns the composite containing all the controls that are time aligned,
1580 * i.e. TimeGraphScale, TimeGraphControl.
1582 * @return the time based composite
1585 public Composite
getTimeAlignedComposite() {
1586 return fTimeAlignedComposite
;
1590 * Return the x coordinate corresponding to a time
1594 * @return the x coordinate corresponding to the time
1596 public int getXForTime(long time
) {
1597 return fTimeGraphCtrl
.getXForTime(time
);
1601 * Return the time corresponding to an x coordinate
1605 * @return the time corresponding to the x coordinate
1607 public long getTimeAtX(int x
) {
1608 return fTimeGraphCtrl
.getTimeAtX(x
);
1612 * Get the selection provider
1614 * @return the selection provider
1616 public ISelectionProvider
getSelectionProvider() {
1617 return fTimeGraphCtrl
;
1621 * Wait for the cursor
1624 * Wait indefinitely?
1626 public void waitCursor(boolean waitInd
) {
1627 fTimeGraphCtrl
.waitCursor(waitInd
);
1631 * Get the horizontal scroll bar object
1633 * @return The scroll bar
1635 public Slider
getHorizontalBar() {
1636 return fHorizontalScrollBar
;
1640 * Get the vertical scroll bar object
1642 * @return The scroll bar
1644 public Slider
getVerticalBar() {
1645 return fVerticalScrollBar
;
1649 * Set the given index as the top one
1652 * The index that will go to the top
1654 public void setTopIndex(int index
) {
1655 fTimeGraphCtrl
.setTopIndex(index
);
1656 adjustVerticalScrollBar();
1660 * Retrieve the current top index
1662 * @return The top index
1664 public int getTopIndex() {
1665 return fTimeGraphCtrl
.getTopIndex();
1669 * Sets the auto-expand level to be used for new entries discovered when
1670 * calling {@link #setInput(Object)} or {@link #refresh()}. The value 0
1671 * means that there is no auto-expand; 1 means that top-level entries are
1672 * expanded, but not their children; 2 means that top-level entries are
1673 * expanded, and their children, but not grand-children; and so on.
1675 * The value {@link #ALL_LEVELS} means that all subtrees should be expanded.
1679 * non-negative level, or <code>ALL_LEVELS</code> to expand all
1680 * levels of the tree
1682 public void setAutoExpandLevel(int level
) {
1683 fTimeGraphCtrl
.setAutoExpandLevel(level
);
1687 * Returns the auto-expand level.
1689 * @return non-negative level, or <code>ALL_LEVELS</code> if all levels of
1690 * the tree are expanded automatically
1691 * @see #setAutoExpandLevel
1693 public int getAutoExpandLevel() {
1694 return fTimeGraphCtrl
.getAutoExpandLevel();
1698 * Get the expanded state of an entry.
1702 * @return true if the entry is expanded, false if collapsed
1705 public boolean getExpandedState(ITimeGraphEntry entry
) {
1706 return fTimeGraphCtrl
.getExpandedState(entry
);
1710 * Set the expanded state of an entry
1713 * The entry to expand/collapse
1715 * True for expanded, false for collapsed
1717 public void setExpandedState(ITimeGraphEntry entry
, boolean expanded
) {
1718 fTimeGraphCtrl
.setExpandedState(entry
, expanded
);
1719 adjustVerticalScrollBar();
1723 * Collapses all nodes of the viewer's tree, starting with the root.
1725 public void collapseAll() {
1726 fTimeGraphCtrl
.collapseAll();
1727 adjustVerticalScrollBar();
1731 * Expands all entries of the viewer's tree, starting with the root.
1733 public void expandAll() {
1734 fTimeGraphCtrl
.expandAll();
1735 adjustVerticalScrollBar();
1739 * Get the number of expanded (visible) time graph entries. This includes
1740 * leafs and does not include filtered-out entries.
1742 * @return The number of expanded (visible) time graph entries
1744 public int getExpandedElementCount() {
1745 return fTimeGraphCtrl
.getExpandedElementCount();
1749 * Get the expanded (visible) time graph entries. This includes leafs and
1750 * does not include filtered-out entries.
1752 * @return The array of expanded (visible) time graph entries
1754 public ITimeGraphEntry
[] getExpandedElements() {
1755 return fTimeGraphCtrl
.getExpandedElements();
1759 * Add a tree listener
1762 * The listener to add
1764 public void addTreeListener(ITimeGraphTreeListener listener
) {
1765 fTimeGraphCtrl
.addTreeListener(listener
);
1769 * Remove a tree listener
1772 * The listener to remove
1774 public void removeTreeListener(ITimeGraphTreeListener listener
) {
1775 fTimeGraphCtrl
.removeTreeListener(listener
);
1779 * Get the reset scale action.
1781 * @return The Action object
1783 public Action
getResetScaleAction() {
1784 if (fResetScaleAction
== null) {
1786 fResetScaleAction
= new Action() {
1789 resetStartFinishTime();
1792 fResetScaleAction
.setText(Messages
.TmfTimeGraphViewer_ResetScaleActionNameText
);
1793 fResetScaleAction
.setToolTipText(Messages
.TmfTimeGraphViewer_ResetScaleActionToolTipText
);
1794 fResetScaleAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_HOME_MENU
));
1796 return fResetScaleAction
;
1800 * Get the show legend action.
1802 * @return The Action object
1804 public Action
getShowLegendAction() {
1805 if (fShowLegendAction
== null) {
1807 fShowLegendAction
= new Action() {
1813 fShowLegendAction
.setText(Messages
.TmfTimeGraphViewer_LegendActionNameText
);
1814 fShowLegendAction
.setToolTipText(Messages
.TmfTimeGraphViewer_LegendActionToolTipText
);
1815 fShowLegendAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_SHOW_LEGEND
));
1818 return fShowLegendAction
;
1822 * Get the the next event action.
1824 * @return The action object
1826 public Action
getNextEventAction() {
1827 if (fNextEventAction
== null) {
1828 fNextEventAction
= new Action() {
1830 public void runWithEvent(Event event
) {
1831 boolean extend
= (event
.stateMask
& SWT
.SHIFT
) != 0;
1832 selectNextEvent(extend
);
1836 fNextEventAction
.setText(Messages
.TmfTimeGraphViewer_NextEventActionNameText
);
1837 fNextEventAction
.setToolTipText(Messages
.TmfTimeGraphViewer_NextEventActionToolTipText
);
1838 fNextEventAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_NEXT_EVENT
));
1841 return fNextEventAction
;
1845 * Get the previous event action.
1847 * @return The Action object
1849 public Action
getPreviousEventAction() {
1850 if (fPrevEventAction
== null) {
1851 fPrevEventAction
= new Action() {
1853 public void runWithEvent(Event event
) {
1854 boolean extend
= (event
.stateMask
& SWT
.SHIFT
) != 0;
1855 selectPrevEvent(extend
);
1859 fPrevEventAction
.setText(Messages
.TmfTimeGraphViewer_PreviousEventActionNameText
);
1860 fPrevEventAction
.setToolTipText(Messages
.TmfTimeGraphViewer_PreviousEventActionToolTipText
);
1861 fPrevEventAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_PREV_EVENT
));
1864 return fPrevEventAction
;
1868 * Get the next item action.
1870 * @return The Action object
1872 public Action
getNextItemAction() {
1873 if (fNextItemAction
== null) {
1875 fNextItemAction
= new Action() {
1881 fNextItemAction
.setText(Messages
.TmfTimeGraphViewer_NextItemActionNameText
);
1882 fNextItemAction
.setToolTipText(Messages
.TmfTimeGraphViewer_NextItemActionToolTipText
);
1883 fNextItemAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_NEXT_ITEM
));
1885 return fNextItemAction
;
1889 * Get the previous item action.
1891 * @return The Action object
1893 public Action
getPreviousItemAction() {
1894 if (fPreviousItemAction
== null) {
1896 fPreviousItemAction
= new Action() {
1902 fPreviousItemAction
.setText(Messages
.TmfTimeGraphViewer_PreviousItemActionNameText
);
1903 fPreviousItemAction
.setToolTipText(Messages
.TmfTimeGraphViewer_PreviousItemActionToolTipText
);
1904 fPreviousItemAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_PREV_ITEM
));
1906 return fPreviousItemAction
;
1910 * Get the zoom in action
1912 * @return The Action object
1914 public Action
getZoomInAction() {
1915 if (fZoomInAction
== null) {
1916 fZoomInAction
= new Action() {
1922 fZoomInAction
.setText(Messages
.TmfTimeGraphViewer_ZoomInActionNameText
);
1923 fZoomInAction
.setToolTipText(Messages
.TmfTimeGraphViewer_ZoomInActionToolTipText
);
1924 fZoomInAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_ZOOM_IN_MENU
));
1926 return fZoomInAction
;
1930 * Get the zoom out action
1932 * @return The Action object
1934 public Action
getZoomOutAction() {
1935 if (fZoomOutAction
== null) {
1936 fZoomOutAction
= new Action() {
1942 fZoomOutAction
.setText(Messages
.TmfTimeGraphViewer_ZoomOutActionNameText
);
1943 fZoomOutAction
.setToolTipText(Messages
.TmfTimeGraphViewer_ZoomOutActionToolTipText
);
1944 fZoomOutAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_ZOOM_OUT_MENU
));
1946 return fZoomOutAction
;
1950 * Get the hide arrows action
1952 * @param dialogSettings
1953 * The dialog settings section where the state should be stored,
1956 * @return The Action object
1958 public Action
getHideArrowsAction(final IDialogSettings dialogSettings
) {
1959 if (fHideArrowsAction
== null) {
1960 fHideArrowsAction
= new Action(Messages
.TmfTimeGraphViewer_HideArrowsActionNameText
, IAction
.AS_CHECK_BOX
) {
1963 boolean hideArrows
= fHideArrowsAction
.isChecked();
1964 fTimeGraphCtrl
.hideArrows(hideArrows
);
1966 if (dialogSettings
!= null) {
1967 dialogSettings
.put(HIDE_ARROWS_KEY
, hideArrows
);
1969 if (fFollowArrowFwdAction
!= null) {
1970 fFollowArrowFwdAction
.setEnabled(!hideArrows
);
1972 if (fFollowArrowBwdAction
!= null) {
1973 fFollowArrowBwdAction
.setEnabled(!hideArrows
);
1977 fHideArrowsAction
.setToolTipText(Messages
.TmfTimeGraphViewer_HideArrowsActionToolTipText
);
1978 fHideArrowsAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_HIDE_ARROWS
));
1979 if (dialogSettings
!= null) {
1980 boolean hideArrows
= dialogSettings
.getBoolean(HIDE_ARROWS_KEY
);
1981 fTimeGraphCtrl
.hideArrows(hideArrows
);
1982 fHideArrowsAction
.setChecked(hideArrows
);
1983 if (fFollowArrowFwdAction
!= null) {
1984 fFollowArrowFwdAction
.setEnabled(!hideArrows
);
1986 if (fFollowArrowBwdAction
!= null) {
1987 fFollowArrowBwdAction
.setEnabled(!hideArrows
);
1991 return fHideArrowsAction
;
1995 * Get the follow arrow forward action.
1997 * @return The Action object
1999 public Action
getFollowArrowFwdAction() {
2000 if (fFollowArrowFwdAction
== null) {
2001 fFollowArrowFwdAction
= new Action() {
2003 public void runWithEvent(Event event
) {
2004 boolean extend
= (event
.stateMask
& SWT
.SHIFT
) != 0;
2005 fTimeGraphCtrl
.followArrowFwd(extend
);
2006 adjustVerticalScrollBar();
2009 fFollowArrowFwdAction
.setText(Messages
.TmfTimeGraphViewer_FollowArrowForwardActionNameText
);
2010 fFollowArrowFwdAction
.setToolTipText(Messages
.TmfTimeGraphViewer_FollowArrowForwardActionToolTipText
);
2011 fFollowArrowFwdAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_FOLLOW_ARROW_FORWARD
));
2012 if (fHideArrowsAction
!= null) {
2013 fFollowArrowFwdAction
.setEnabled(!fHideArrowsAction
.isChecked());
2016 return fFollowArrowFwdAction
;
2020 * Get the follow arrow backward action.
2022 * @return The Action object
2024 public Action
getFollowArrowBwdAction() {
2025 if (fFollowArrowBwdAction
== null) {
2026 fFollowArrowBwdAction
= new Action() {
2028 public void runWithEvent(Event event
) {
2029 boolean extend
= (event
.stateMask
& SWT
.SHIFT
) != 0;
2030 fTimeGraphCtrl
.followArrowBwd(extend
);
2031 adjustVerticalScrollBar();
2034 fFollowArrowBwdAction
.setText(Messages
.TmfTimeGraphViewer_FollowArrowBackwardActionNameText
);
2035 fFollowArrowBwdAction
.setToolTipText(Messages
.TmfTimeGraphViewer_FollowArrowBackwardActionToolTipText
);
2036 fFollowArrowBwdAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_FOLLOW_ARROW_BACKWARD
));
2037 if (fHideArrowsAction
!= null) {
2038 fFollowArrowBwdAction
.setEnabled(!fHideArrowsAction
.isChecked());
2041 return fFollowArrowBwdAction
;
2045 * Get the show filter dialog action.
2047 * @return The Action object
2050 public ShowFilterDialogAction
getShowFilterDialogAction() {
2051 if (fShowFilterDialogAction
== null) {
2052 fShowFilterDialogAction
= new ShowFilterDialogAction(this);
2054 return fShowFilterDialogAction
;
2058 * Get the toggle bookmark action.
2060 * @return The Action object
2063 public Action
getToggleBookmarkAction() {
2064 if (fToggleBookmarkAction
== null) {
2065 fToggleBookmarkAction
= new Action() {
2067 public void runWithEvent(Event event
) {
2068 IMarkerEvent selectedBookmark
= getBookmarkAtSelection();
2069 if (selectedBookmark
== null) {
2070 final long time
= Math
.min(fSelectionBegin
, fSelectionEnd
);
2071 final long duration
= Math
.max(fSelectionBegin
, fSelectionEnd
) - time
;
2072 final AddBookmarkDialog dialog
= new AddBookmarkDialog(PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getShell(), null);
2073 if (dialog
.open() == Window
.OK
) {
2074 final String label
= dialog
.getValue();
2075 final RGBA rgba
= dialog
.getColorValue();
2076 Color color
= new Color(Display
.getDefault(), rgba
.rgb
.red
, rgba
.rgb
.green
, rgba
.rgb
.blue
, rgba
.alpha
);
2078 IMarkerEvent bookmark
= new MarkerEvent(null, time
, duration
, IMarkerEvent
.BOOKMARKS
, color
, label
, true);
2079 fBookmarks
.add(bookmark
);
2081 updateMarkerActions();
2082 getControl().redraw();
2083 fireBookmarkAdded(bookmark
);
2086 checkDisposeColor(selectedBookmark
.getColor());
2087 fBookmarks
.remove(selectedBookmark
);
2089 updateMarkerActions();
2090 getControl().redraw();
2091 fireBookmarkRemoved(selectedBookmark
);
2095 fToggleBookmarkAction
.setText(Messages
.TmfTimeGraphViewer_BookmarkActionAddText
);
2096 fToggleBookmarkAction
.setToolTipText(Messages
.TmfTimeGraphViewer_BookmarkActionAddText
);
2097 fToggleBookmarkAction
.setImageDescriptor(ADD_BOOKMARK
);
2099 return fToggleBookmarkAction
;
2103 * Get the next marker action.
2105 * @return The Action object
2108 public Action
getNextMarkerAction() {
2109 if (fNextMarkerAction
== null) {
2110 fNextMarkerAction
= new Action(Messages
.TmfTimeGraphViewer_NextMarkerActionText
, IAction
.AS_DROP_DOWN_MENU
) {
2112 public void runWithEvent(Event event
) {
2113 final long time
= Math
.min(fSelectionBegin
, fSelectionEnd
);
2114 final long duration
= Math
.max(fSelectionBegin
, fSelectionEnd
) - time
;
2115 List
<IMarkerEvent
> markers
= getTimeGraphControl().getMarkers();
2116 if (markers
== null) {
2119 for (IMarkerEvent marker
: markers
) {
2120 if ((marker
.getTime() > time
||
2121 (marker
.getTime() == time
&& marker
.getDuration() > duration
))
2122 && !fSkippedMarkerCategories
.contains(marker
.getCategory())) {
2123 setSelectionRangeNotify(marker
.getTime(), marker
.getTime() + marker
.getDuration());
2129 fNextMarkerAction
.setToolTipText(Messages
.TmfTimeGraphViewer_NextMarkerActionText
);
2130 fNextMarkerAction
.setImageDescriptor(NEXT_BOOKMARK
);
2131 fNextMarkerAction
.setMenuCreator(new IMenuCreator () {
2134 public void dispose() {
2142 public Menu
getMenu(Control parent
) {
2146 menu
= new Menu(parent
);
2147 for (String category
: fMarkerCategories
) {
2148 final Action action
= new Action(category
, IAction
.AS_CHECK_BOX
) {
2150 public void runWithEvent(Event event
) {
2152 fSkippedMarkerCategories
.remove(getText());
2154 fSkippedMarkerCategories
.add(getText());
2156 updateMarkerActions();
2159 action
.setEnabled(!fHiddenMarkerCategories
.contains(category
));
2160 action
.setChecked(action
.isEnabled() && !fSkippedMarkerCategories
.contains(category
));
2161 new ActionContributionItem(action
).fill(menu
, -1);
2167 public Menu
getMenu(Menu parent
) {
2172 return fNextMarkerAction
;
2176 * Get the previous marker action.
2178 * @return The Action object
2181 public Action
getPreviousMarkerAction() {
2182 if (fPreviousMarkerAction
== null) {
2183 fPreviousMarkerAction
= new Action() {
2185 public void runWithEvent(Event event
) {
2186 final long time
= Math
.min(fSelectionBegin
, fSelectionEnd
);
2187 final long duration
= Math
.max(fSelectionBegin
, fSelectionEnd
) - time
;
2188 List
<IMarkerEvent
> markers
= getTimeGraphControl().getMarkers();
2189 if (markers
== null) {
2192 for (int i
= markers
.size() - 1; i
>= 0; i
--) {
2193 IMarkerEvent marker
= markers
.get(i
);
2194 if ((marker
.getTime() < time
||
2195 (marker
.getTime() == time
&& marker
.getDuration() < duration
))
2196 && !fSkippedMarkerCategories
.contains(marker
.getCategory())) {
2197 setSelectionRangeNotify(marker
.getTime(), marker
.getTime() + marker
.getDuration());
2203 fPreviousMarkerAction
.setText(Messages
.TmfTimeGraphViewer_PreviousMarkerActionText
);
2204 fPreviousMarkerAction
.setToolTipText(Messages
.TmfTimeGraphViewer_PreviousMarkerActionText
);
2205 fPreviousMarkerAction
.setImageDescriptor(PREVIOUS_BOOKMARK
);
2207 return fPreviousMarkerAction
;
2211 * Get the show markers menu.
2213 * @return The menu manager object
2216 public MenuManager
getMarkersMenu() {
2217 if (fMarkersMenu
== null) {
2218 fMarkersMenu
= new MenuManager(Messages
.TmfTimeGraphViewer_ShowMarkersMenuText
);
2219 fMarkersMenu
.setRemoveAllWhenShown(true);
2220 fMarkersMenu
.addMenuListener(new IMenuListener() {
2222 public void menuAboutToShow(IMenuManager manager
) {
2223 for (String category
: fMarkerCategories
) {
2224 final Action action
= new Action(category
, IAction
.AS_CHECK_BOX
) {
2226 public void runWithEvent(Event event
) {
2228 fHiddenMarkerCategories
.remove(getText());
2230 fHiddenMarkerCategories
.add(getText());
2233 updateMarkerActions();
2234 getControl().redraw();
2237 action
.setChecked(!fHiddenMarkerCategories
.contains(category
));
2238 manager
.add(action
);
2243 return fMarkersMenu
;
2246 private IMarkerEvent
getBookmarkAtSelection() {
2247 final long time
= Math
.min(fSelectionBegin
, fSelectionEnd
);
2248 final long duration
= Math
.max(fSelectionBegin
, fSelectionEnd
) - time
;
2249 for (IMarkerEvent bookmark
: fBookmarks
) {
2250 if (bookmark
.getTime() == time
&& bookmark
.getDuration() == duration
) {
2257 private void updateMarkerActions() {
2258 boolean enabled
= fTime0Bound
!= SWT
.DEFAULT
|| fTime1Bound
!= SWT
.DEFAULT
;
2259 if (fToggleBookmarkAction
!= null) {
2260 if (getBookmarkAtSelection() != null) {
2261 fToggleBookmarkAction
.setText(Messages
.TmfTimeGraphViewer_BookmarkActionRemoveText
);
2262 fToggleBookmarkAction
.setToolTipText(Messages
.TmfTimeGraphViewer_BookmarkActionRemoveText
);
2263 fToggleBookmarkAction
.setImageDescriptor(REMOVE_BOOKMARK
);
2265 fToggleBookmarkAction
.setText(Messages
.TmfTimeGraphViewer_BookmarkActionAddText
);
2266 fToggleBookmarkAction
.setToolTipText(Messages
.TmfTimeGraphViewer_BookmarkActionAddText
);
2267 fToggleBookmarkAction
.setImageDescriptor(ADD_BOOKMARK
);
2269 fToggleBookmarkAction
.setEnabled(enabled
);
2271 List
<IMarkerEvent
> markers
= getTimeGraphControl().getMarkers();
2272 if (markers
== null) {
2273 markers
= Collections
.emptyList();
2275 if (fPreviousMarkerAction
!= null) {
2276 fPreviousMarkerAction
.setEnabled(enabled
&& !markers
.isEmpty());
2278 if (fNextMarkerAction
!= null) {
2279 fNextMarkerAction
.setEnabled(enabled
&& !markers
.isEmpty());
2283 private void updateMarkerList() {
2284 List
<IMarkerEvent
> markers
= new ArrayList
<>();
2285 for (IMarkerEvent marker
: fMarkers
) {
2286 if (!fHiddenMarkerCategories
.contains(marker
.getCategory())) {
2287 markers
.add(marker
);
2290 if (!fHiddenMarkerCategories
.contains(IMarkerEvent
.BOOKMARKS
)) {
2291 markers
.addAll(fBookmarks
);
2293 Collections
.sort(markers
, new MarkerComparator());
2294 getTimeGraphControl().setMarkers(markers
);
2297 private void adjustHorizontalScrollBar() {
2298 long time0
= getTime0();
2299 long time1
= getTime1();
2300 long timeMin
= getMinTime();
2301 long timeMax
= getMaxTime();
2302 long delta
= timeMax
- timeMin
;
2304 int thumb
= H_SCROLLBAR_MAX
;
2306 // Thumb size (page size)
2307 thumb
= Math
.max(1, (int) (H_SCROLLBAR_MAX
* ((double) (time1
- time0
) / delta
)));
2308 // At the beginning of visible window
2309 timePos
= (int) (H_SCROLLBAR_MAX
* ((double) (time0
- timeMin
) / delta
));
2311 fHorizontalScrollBar
.setValues(timePos
, 0, H_SCROLLBAR_MAX
, thumb
, Math
.max(1, thumb
/ 2), Math
.max(2, thumb
));
2314 private void adjustVerticalScrollBar() {
2315 int topIndex
= fTimeGraphCtrl
.getTopIndex();
2316 int countPerPage
= fTimeGraphCtrl
.countPerPage();
2317 int expandedElementCount
= fTimeGraphCtrl
.getExpandedElementCount();
2318 if (topIndex
+ countPerPage
> expandedElementCount
) {
2319 fTimeGraphCtrl
.setTopIndex(Math
.max(0, expandedElementCount
- countPerPage
));
2322 int selection
= fTimeGraphCtrl
.getTopIndex();
2324 int max
= Math
.max(1, expandedElementCount
- 1);
2325 int thumb
= Math
.min(max
, Math
.max(1, countPerPage
- 1));
2327 int pageIncrement
= Math
.max(1, countPerPage
);
2328 fVerticalScrollBar
.setValues(selection
, min
, max
, thumb
, increment
, pageIncrement
);
2333 * a {@link MenuDetectListener}
2334 * @see org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.TimeGraphControl#addTimeGraphEntryMenuListener(org.eclipse.swt.events.MenuDetectListener)
2336 public void addTimeGraphEntryMenuListener(MenuDetectListener listener
) {
2337 fTimeGraphCtrl
.addTimeGraphEntryMenuListener(listener
);
2342 * a {@link MenuDetectListener}
2343 * @see org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.TimeGraphControl#removeTimeGraphEntryMenuListener(org.eclipse.swt.events.MenuDetectListener)
2345 public void removeTimeGraphEntryMenuListener(MenuDetectListener listener
) {
2346 fTimeGraphCtrl
.removeTimeGraphEntryMenuListener(listener
);
2351 * a {@link MenuDetectListener}
2352 * @see org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.TimeGraphControl#addTimeEventMenuListener(org.eclipse.swt.events.MenuDetectListener)
2354 public void addTimeEventMenuListener(MenuDetectListener listener
) {
2355 fTimeGraphCtrl
.addTimeEventMenuListener(listener
);
2360 * a {@link MenuDetectListener}
2361 * @see org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.TimeGraphControl#removeTimeEventMenuListener(org.eclipse.swt.events.MenuDetectListener)
2363 public void removeTimeEventMenuListener(MenuDetectListener listener
) {
2364 fTimeGraphCtrl
.removeTimeEventMenuListener(listener
);
2369 * The filter object to be attached to the view
2371 public void addFilter(ViewerFilter filter
) {
2372 fTimeGraphCtrl
.addFilter(filter
);
2378 * The filter object to be attached to the view
2380 public void removeFilter(ViewerFilter filter
) {
2381 fTimeGraphCtrl
.removeFilter(filter
);
2386 * Returns this viewer's filters.
2388 * @return an array of viewer filters
2391 public ViewerFilter
[] getFilters() {
2392 return fTimeGraphCtrl
.getFilters();
2396 * Sets the filters, replacing any previous filters, and triggers
2397 * refiltering of the elements.
2400 * an array of viewer filters, or null
2403 public void setFilters(ViewerFilter
[] filters
) {
2404 fTimeGraphCtrl
.setFilters(filters
);
2409 * Return the time alignment information
2411 * @return the time alignment information
2413 * @see ITmfTimeAligned
2417 public TmfTimeViewAlignmentInfo
getTimeViewAlignmentInfo() {
2418 return fTimeGraphCtrl
.getTimeViewAlignmentInfo();
2422 * Return the available width for the time-axis.
2424 * @see ITmfTimeAligned
2426 * @param requestedOffset
2427 * the requested offset
2428 * @return the available width for the time-axis
2432 public int getAvailableWidth(int requestedOffset
) {
2433 int totalWidth
= fTimeAlignedComposite
.getSize().x
;
2434 return Math
.min(totalWidth
, Math
.max(0, totalWidth
- requestedOffset
));
2438 * Perform the alignment operation.
2441 * the alignment offset
2443 * the alignment width
2445 * @see ITmfTimeAligned
2449 public void performAlign(int offset
, int width
) {
2450 fTimeGraphCtrl
.performAlign(offset
);
2451 int alignmentWidth
= width
;
2452 int size
= fTimeAlignedComposite
.getSize().x
;
2453 GridLayout layout
= (GridLayout
) fTimeAlignedComposite
.getLayout();
2454 int marginSize
= size
- alignmentWidth
- offset
;
2455 layout
.marginRight
= Math
.max(0, marginSize
);
2456 fTimeAlignedComposite
.layout();