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
.IAction
;
28 import org
.eclipse
.jface
.action
.IMenuListener
;
29 import org
.eclipse
.jface
.action
.IMenuManager
;
30 import org
.eclipse
.jface
.action
.MenuManager
;
31 import org
.eclipse
.jface
.dialogs
.IDialogSettings
;
32 import org
.eclipse
.jface
.resource
.ImageDescriptor
;
33 import org
.eclipse
.jface
.viewers
.AbstractTreeViewer
;
34 import org
.eclipse
.jface
.viewers
.ISelectionProvider
;
35 import org
.eclipse
.jface
.viewers
.ITableLabelProvider
;
36 import org
.eclipse
.jface
.viewers
.ITreeContentProvider
;
37 import org
.eclipse
.jface
.viewers
.ViewerFilter
;
38 import org
.eclipse
.jface
.window
.Window
;
39 import org
.eclipse
.swt
.SWT
;
40 import org
.eclipse
.swt
.events
.ControlAdapter
;
41 import org
.eclipse
.swt
.events
.ControlEvent
;
42 import org
.eclipse
.swt
.events
.DisposeEvent
;
43 import org
.eclipse
.swt
.events
.DisposeListener
;
44 import org
.eclipse
.swt
.events
.KeyAdapter
;
45 import org
.eclipse
.swt
.events
.KeyEvent
;
46 import org
.eclipse
.swt
.events
.MenuDetectListener
;
47 import org
.eclipse
.swt
.events
.MouseEvent
;
48 import org
.eclipse
.swt
.events
.MouseWheelListener
;
49 import org
.eclipse
.swt
.events
.SelectionAdapter
;
50 import org
.eclipse
.swt
.events
.SelectionEvent
;
51 import org
.eclipse
.swt
.events
.SelectionListener
;
52 import org
.eclipse
.swt
.graphics
.Color
;
53 import org
.eclipse
.swt
.graphics
.RGBA
;
54 import org
.eclipse
.swt
.graphics
.Rectangle
;
55 import org
.eclipse
.swt
.layout
.FillLayout
;
56 import org
.eclipse
.swt
.layout
.GridData
;
57 import org
.eclipse
.swt
.layout
.GridLayout
;
58 import org
.eclipse
.swt
.widgets
.Composite
;
59 import org
.eclipse
.swt
.widgets
.Control
;
60 import org
.eclipse
.swt
.widgets
.Display
;
61 import org
.eclipse
.swt
.widgets
.Event
;
62 import org
.eclipse
.swt
.widgets
.Listener
;
63 import org
.eclipse
.swt
.widgets
.Slider
;
64 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.Activator
;
65 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.ITmfImageConstants
;
66 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.Messages
;
67 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.dialogs
.AddBookmarkDialog
;
68 import org
.eclipse
.tracecompass
.tmf
.ui
.signal
.TmfTimeViewAlignmentInfo
;
69 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.ITmfTimeAligned
;
70 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.dialogs
.ShowFilterDialogAction
;
71 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.dialogs
.TimeGraphLegend
;
72 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.ILinkEvent
;
73 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.IMarkerEvent
;
74 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.ITimeEvent
;
75 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.ITimeGraphEntry
;
76 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.MarkerEvent
;
77 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.widgets
.ITimeDataProvider
;
78 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.widgets
.TimeDataProviderCyclesConverter
;
79 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.widgets
.TimeGraphColorScheme
;
80 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.widgets
.TimeGraphControl
;
81 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.widgets
.TimeGraphScale
;
82 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.widgets
.TimeGraphTooltipHandler
;
83 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.widgets
.Utils
;
84 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.widgets
.Utils
.TimeFormat
;
85 import org
.eclipse
.ui
.PlatformUI
;
88 * Generic time graph viewer implementation
90 * @author Patrick Tasse, and others
92 public class TimeGraphViewer
implements ITimeDataProvider
, SelectionListener
{
94 /** Constant indicating that all levels of the time graph should be expanded */
95 public static final int ALL_LEVELS
= AbstractTreeViewer
.ALL_LEVELS
;
97 private static final int DEFAULT_NAME_WIDTH
= 200;
98 private static final int MIN_NAME_WIDTH
= 6;
99 private static final int MAX_NAME_WIDTH
= 1000;
100 private static final int DEFAULT_HEIGHT
= 22;
101 private static final String HIDE_ARROWS_KEY
= "hide.arrows"; //$NON-NLS-1$
102 private static final long DEFAULT_FREQUENCY
= 1000000000L;
103 private static final int H_SCROLLBAR_MAX
= Integer
.MAX_VALUE
- 1;
105 private static ImageDescriptor ADD_BOOKMARK
= Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_ADD_BOOKMARK
);
106 private static ImageDescriptor NEXT_BOOKMARK
= Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_NEXT_BOOKMARK
);
107 private static ImageDescriptor PREVIOUS_BOOKMARK
= Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_PREVIOUS_BOOKMARK
);
108 private static ImageDescriptor REMOVE_BOOKMARK
= Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_REMOVE_BOOKMARK
);
110 private long fMinTimeInterval
;
111 private ITimeGraphEntry fSelectedEntry
;
112 private long fBeginTime
= SWT
.DEFAULT
; // The user-specified bounds start time
113 private long fEndTime
= SWT
.DEFAULT
; // The user-specified bounds end time
114 private long fTime0
= SWT
.DEFAULT
; // The current window start time
115 private long fTime1
= SWT
.DEFAULT
; // The current window end time
116 private long fSelectionBegin
= SWT
.DEFAULT
;
117 private long fSelectionEnd
= SWT
.DEFAULT
;
118 private long fTime0Bound
= SWT
.DEFAULT
; // The bounds start time
119 private long fTime1Bound
= SWT
.DEFAULT
; // The bounds end time
120 private long fTime0ExtSynch
= SWT
.DEFAULT
;
121 private long fTime1ExtSynch
= SWT
.DEFAULT
;
122 private boolean fTimeRangeFixed
;
123 private int fNameWidthPref
= DEFAULT_NAME_WIDTH
;
124 private int fMinNameWidth
= MIN_NAME_WIDTH
;
125 private int fNameWidth
;
126 private Composite fDataViewer
;
128 private TimeGraphControl fTimeGraphCtrl
;
129 private TimeGraphScale fTimeScaleCtrl
;
130 private Slider fHorizontalScrollBar
;
131 private Slider fVerticalScrollBar
;
132 private TimeGraphColorScheme fColorScheme
;
133 private Object fInputElement
;
134 private ITimeGraphContentProvider fTimeGraphContentProvider
;
135 private ITimeGraphPresentationProvider fTimeGraphProvider
;
136 private ITimeDataProvider fTimeDataProvider
= this;
137 private TimeGraphTooltipHandler fToolTipHandler
;
139 private List
<ITimeGraphSelectionListener
> fSelectionListeners
= new ArrayList
<>();
140 private List
<ITimeGraphTimeListener
> fTimeListeners
= new ArrayList
<>();
141 private List
<ITimeGraphRangeListener
> fRangeListeners
= new ArrayList
<>();
142 private List
<ITimeGraphBookmarkListener
> fBookmarkListeners
= new ArrayList
<>();
144 // Time format, using Epoch reference, Relative time format(default),
146 private TimeFormat fTimeFormat
= TimeFormat
.RELATIVE
;
147 // Clock frequency to use for Cycles time format
148 private long fClockFrequency
= DEFAULT_FREQUENCY
;
149 private int fBorderWidth
= 0;
150 private int fTimeScaleHeight
= DEFAULT_HEIGHT
;
152 private Action fResetScaleAction
;
153 private Action fShowLegendAction
;
154 private Action fNextEventAction
;
155 private Action fPrevEventAction
;
156 private Action fNextItemAction
;
157 private Action fPreviousItemAction
;
158 private Action fZoomInAction
;
159 private Action fZoomOutAction
;
160 private Action fHideArrowsAction
;
161 private Action fFollowArrowFwdAction
;
162 private Action fFollowArrowBwdAction
;
163 private ShowFilterDialogAction fShowFilterDialogAction
;
164 private Action fToggleBookmarkAction
;
165 private Action fNextMarkerAction
;
166 private Action fPreviousMarkerAction
;
167 private MenuManager fMarkersMenu
;
169 /** The list of bookmarks */
170 private final List
<IMarkerEvent
> fBookmarks
= new ArrayList
<>();
172 /** The list of marker categories */
173 private final List
<String
> fMarkerCategories
= new ArrayList
<>();
175 /** The set of hidden marker categories */
176 private final Set
<String
> fHiddenMarkerCategories
= new HashSet
<>();
178 /** The list of markers */
179 private final List
<IMarkerEvent
> fMarkers
= new ArrayList
<>();
181 /** The list of color resources created by this viewer */
182 private final List
<Color
> fColors
= new ArrayList
<>();
184 private ListenerNotifier fListenerNotifier
;
186 private Composite fTimeAlignedComposite
;
188 private class ListenerNotifier
extends Thread
{
189 private static final long DELAY
= 400L;
190 private static final long POLLING_INTERVAL
= 10L;
191 private long fLastUpdateTime
= Long
.MAX_VALUE
;
192 private boolean fSelectionChanged
= false;
193 private boolean fTimeRangeUpdated
= false;
194 private boolean fTimeSelected
= false;
198 while ((System
.currentTimeMillis() - fLastUpdateTime
) < DELAY
) {
200 Thread
.sleep(POLLING_INTERVAL
);
201 } catch (Exception e
) {
205 Display
.getDefault().asyncExec(new Runnable() {
208 if (fListenerNotifier
!= ListenerNotifier
.this) {
211 fListenerNotifier
= null;
212 if (ListenerNotifier
.this.isInterrupted() || fDataViewer
.isDisposed()) {
215 if (fSelectionChanged
) {
216 fireSelectionChanged(fSelectedEntry
);
218 if (fTimeRangeUpdated
) {
219 fireTimeRangeUpdated(fTime0
, fTime1
);
222 fireTimeSelected(fSelectionBegin
, fSelectionEnd
);
228 public void selectionChanged() {
229 fSelectionChanged
= true;
230 fLastUpdateTime
= System
.currentTimeMillis();
233 public void timeRangeUpdated() {
234 fTimeRangeUpdated
= true;
235 fLastUpdateTime
= System
.currentTimeMillis();
238 public void timeSelected() {
239 fTimeSelected
= true;
240 fLastUpdateTime
= System
.currentTimeMillis();
243 public boolean hasSelectionChanged() {
244 return fSelectionChanged
;
247 public boolean hasTimeRangeUpdated() {
248 return fTimeRangeUpdated
;
251 public boolean hasTimeSelected() {
252 return fTimeSelected
;
256 private final static class MarkerComparator
implements Comparator
<IMarkerEvent
> {
258 public int compare(IMarkerEvent o1
, IMarkerEvent o2
) {
259 int res
= Long
.compare(o1
.getTime(), o2
.getTime());
263 return Long
.compare(o1
.getDuration(), o2
.getDuration());
268 * Standard constructor.
270 * The default timegraph content provider accepts an ITimeGraphEntry[] as input element.
273 * The parent UI composite object
277 public TimeGraphViewer(Composite parent
, int style
) {
278 createDataViewer(parent
, style
);
279 fTimeGraphContentProvider
= new TimeGraphContentProvider();
283 * Sets the timegraph content provider used by this timegraph viewer.
285 * @param timeGraphContentProvider
286 * the timegraph content provider
288 public void setTimeGraphContentProvider(ITimeGraphContentProvider timeGraphContentProvider
) {
289 fTimeGraphContentProvider
= timeGraphContentProvider
;
293 * Gets the timegraph content provider used by this timegraph viewer.
295 * @return the timegraph content provider
297 public ITimeGraphContentProvider
getTimeGraphContentProvider() {
298 return fTimeGraphContentProvider
;
302 * Sets the timegraph presentation provider used by this timegraph viewer.
304 * @param timeGraphProvider
305 * the timegraph provider
307 public void setTimeGraphProvider(ITimeGraphPresentationProvider timeGraphProvider
) {
308 fTimeGraphProvider
= timeGraphProvider
;
309 fTimeGraphCtrl
.setTimeGraphProvider(timeGraphProvider
);
310 fToolTipHandler
= new TimeGraphTooltipHandler(fTimeGraphProvider
, fTimeDataProvider
);
311 fToolTipHandler
.activateHoverHelp(fTimeGraphCtrl
);
315 * Sets the tree columns for this time graph combo's filter dialog.
317 * @param columnNames the tree column names
320 public void setFilterColumns(String
[] columnNames
) {
321 getShowFilterDialogAction().getFilterDialog().setColumnNames(columnNames
);
325 * Sets the tree content provider used by the filter dialog
327 * @param contentProvider the tree content provider
330 public void setFilterContentProvider(ITreeContentProvider contentProvider
) {
331 getShowFilterDialogAction().getFilterDialog().setContentProvider(contentProvider
);
335 * Sets the tree label provider used by the filter dialog
337 * @param labelProvider the tree label provider
340 public void setFilterLabelProvider(ITableLabelProvider labelProvider
) {
341 getShowFilterDialogAction().getFilterDialog().setLabelProvider(labelProvider
);
345 * Sets or clears the input for this time graph viewer.
347 * @param inputElement
348 * The input of this time graph viewer, or <code>null</code> if
351 public void setInput(Object inputElement
) {
352 fInputElement
= inputElement
;
353 ITimeGraphEntry
[] input
= fTimeGraphContentProvider
.getElements(inputElement
);
354 fListenerNotifier
= null;
355 if (fTimeGraphCtrl
!= null) {
358 fSelectionBegin
= SWT
.DEFAULT
;
359 fSelectionEnd
= SWT
.DEFAULT
;
360 updateMarkerActions();
361 fSelectedEntry
= null;
362 refreshAllData(input
);
367 * Gets the input for this time graph viewer.
369 * @return The input of this time graph viewer, or <code>null</code> if none
371 public Object
getInput() {
372 return fInputElement
;
376 * Sets (or clears if null) the list of links to display on this combo
379 * the links to display in this time graph combo
381 public void setLinks(List
<ILinkEvent
> links
) {
382 if (fTimeGraphCtrl
!= null) {
383 fTimeGraphCtrl
.refreshArrows(links
);
390 public void refresh() {
391 ITimeGraphEntry
[] input
= fTimeGraphContentProvider
.getElements(fInputElement
);
393 refreshAllData(input
);
397 * Callback for when the control is moved
402 public void controlMoved(ControlEvent e
) {
406 * Callback for when the control is resized
411 public void controlResized(ControlEvent e
) {
416 * @return The string representing the view type
418 protected String
getViewTypeStr() {
419 return "viewoption.threads"; //$NON-NLS-1$
422 int getMarginWidth() {
426 int getMarginHeight() {
431 fMinTimeInterval
= 1;
432 fSelectionBegin
= SWT
.DEFAULT
;
433 fSelectionEnd
= SWT
.DEFAULT
;
434 fNameWidth
= Utils
.loadIntOption(getPreferenceString("namewidth"), //$NON-NLS-1$
435 fNameWidthPref
, fMinNameWidth
, MAX_NAME_WIDTH
);
439 Utils
.saveIntOption(getPreferenceString("namewidth"), fNameWidth
); //$NON-NLS-1$
443 * Create a data viewer.
449 * @return The new data viewer
451 protected Control
createDataViewer(Composite parent
, int style
) {
453 fColorScheme
= new TimeGraphColorScheme();
454 fDataViewer
= new Composite(parent
, style
) {
456 public void redraw() {
457 fTimeScaleCtrl
.redraw();
458 fTimeGraphCtrl
.redraw();
462 fDataViewer
.addDisposeListener(new DisposeListener() {
464 public void widgetDisposed(DisposeEvent e
) {
465 for (Color color
: fColors
) {
468 if (fMarkersMenu
!= null) {
469 fMarkersMenu
.dispose();
473 GridLayout gl
= new GridLayout(2, false);
474 gl
.marginHeight
= fBorderWidth
;
476 gl
.verticalSpacing
= 0;
477 gl
.horizontalSpacing
= 0;
478 fDataViewer
.setLayout(gl
);
480 fTimeAlignedComposite
= new Composite(fDataViewer
, style
) {
482 public void redraw() {
483 fDataViewer
.redraw();
487 GridLayout gl2
= new GridLayout(1, false);
488 gl2
.marginHeight
= fBorderWidth
;
490 gl2
.verticalSpacing
= 0;
491 gl2
.horizontalSpacing
= 0;
492 fTimeAlignedComposite
.setLayout(gl2
);
493 fTimeAlignedComposite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
495 fTimeScaleCtrl
= new TimeGraphScale(fTimeAlignedComposite
, fColorScheme
);
496 fTimeScaleCtrl
.setTimeProvider(fTimeDataProvider
);
497 fTimeScaleCtrl
.setLayoutData(new GridData(SWT
.FILL
, SWT
.DEFAULT
, true, false));
498 fTimeScaleCtrl
.setHeight(fTimeScaleHeight
);
499 fTimeScaleCtrl
.addMouseWheelListener(new MouseWheelListener() {
501 public void mouseScrolled(MouseEvent e
) {
502 fTimeGraphCtrl
.zoom(e
.count
> 0);
506 fTimeGraphCtrl
= createTimeGraphControl(fTimeAlignedComposite
, fColorScheme
);
508 fTimeGraphCtrl
.setTimeProvider(this);
509 fTimeGraphCtrl
.setTimeGraphScale(fTimeScaleCtrl
);
510 fTimeGraphCtrl
.addSelectionListener(this);
511 fTimeGraphCtrl
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
512 fTimeGraphCtrl
.addMouseWheelListener(new MouseWheelListener() {
514 public void mouseScrolled(MouseEvent e
) {
515 adjustVerticalScrollBar();
518 fTimeGraphCtrl
.addKeyListener(new KeyAdapter() {
520 public void keyPressed(KeyEvent e
) {
521 if (e
.character
== '+') {
523 } else if (e
.character
== '-') {
526 adjustVerticalScrollBar();
530 fVerticalScrollBar
= new Slider(fDataViewer
, SWT
.VERTICAL
| SWT
.NO_FOCUS
);
531 fVerticalScrollBar
.setLayoutData(new GridData(SWT
.DEFAULT
, SWT
.FILL
, false, true, 1, 1));
532 fVerticalScrollBar
.addSelectionListener(new SelectionAdapter() {
534 public void widgetSelected(SelectionEvent e
) {
535 setTopIndex(fVerticalScrollBar
.getSelection());
539 fHorizontalScrollBar
= new Slider(fDataViewer
, SWT
.HORIZONTAL
| SWT
.NO_FOCUS
);
540 fHorizontalScrollBar
.setLayoutData(new GridData(SWT
.FILL
, SWT
.DEFAULT
, true, false));
541 fHorizontalScrollBar
.addListener(SWT
.MouseWheel
, new Listener() {
543 public void handleEvent(Event event
) {
544 if ((event
.stateMask
& SWT
.MODIFIER_MASK
) == SWT
.CTRL
) {
545 getTimeGraphControl().zoom(event
.count
> 0);
547 getTimeGraphControl().horizontalScroll(event
.count
> 0);
549 // don't handle the immediately following SWT.Selection event
553 fHorizontalScrollBar
.addListener(SWT
.Selection
, new Listener() {
555 public void handleEvent(Event event
) {
556 int start
= fHorizontalScrollBar
.getSelection();
557 long time0
= getTime0();
558 long time1
= getTime1();
559 long timeMin
= getMinTime();
560 long timeMax
= getMaxTime();
561 long delta
= timeMax
- timeMin
;
563 long range
= time1
- time0
;
564 time0
= timeMin
+ Math
.round(delta
* ((double) start
/ H_SCROLLBAR_MAX
));
565 time1
= time0
+ range
;
567 setStartFinishTimeNotify(time0
, time1
);
571 Composite filler
= new Composite(fDataViewer
, SWT
.NONE
);
572 GridData gd
= new GridData(SWT
.DEFAULT
, SWT
.DEFAULT
, false, false);
573 gd
.heightHint
= fHorizontalScrollBar
.getSize().y
;
574 filler
.setLayoutData(gd
);
575 filler
.setLayout(new FillLayout());
577 fTimeGraphCtrl
.addControlListener(new ControlAdapter() {
579 public void controlResized(ControlEvent event
) {
584 fDataViewer
.update();
585 adjustHorizontalScrollBar();
586 adjustVerticalScrollBar();
593 public void dispose() {
595 fTimeGraphCtrl
.dispose();
596 fDataViewer
.dispose();
597 fColorScheme
.dispose();
601 * Create a new time graph control.
604 * The parent composite
607 * @return The new TimeGraphControl
609 protected TimeGraphControl
createTimeGraphControl(Composite parent
,
610 TimeGraphColorScheme colors
) {
611 return new TimeGraphControl(parent
, colors
);
615 * Resize the controls
617 public void resizeControls() {
618 Rectangle r
= fDataViewer
.getClientArea();
624 if (fNameWidth
> width
- fMinNameWidth
) {
625 fNameWidth
= width
- fMinNameWidth
;
627 if (fNameWidth
< fMinNameWidth
) {
628 fNameWidth
= fMinNameWidth
;
630 adjustHorizontalScrollBar();
631 adjustVerticalScrollBar();
635 * Recalculate the time bounds based on the time graph entries,
636 * if the user-specified bound is set to SWT.DEFAULT.
639 * The root time graph entries in the model
641 public void setTimeRange(ITimeGraphEntry entries
[]) {
642 fTime0Bound
= (fBeginTime
!= SWT
.DEFAULT ? fBeginTime
: fEndTime
);
643 fTime1Bound
= (fEndTime
!= SWT
.DEFAULT ? fEndTime
: fBeginTime
);
644 if (fBeginTime
!= SWT
.DEFAULT
&& fEndTime
!= SWT
.DEFAULT
) {
647 if (entries
== null || entries
.length
== 0) {
650 if (fTime0Bound
== SWT
.DEFAULT
) {
651 fTime0Bound
= Long
.MAX_VALUE
;
653 if (fTime1Bound
== SWT
.DEFAULT
) {
654 fTime1Bound
= Long
.MIN_VALUE
;
656 for (ITimeGraphEntry entry
: entries
) {
661 private void setTimeRange(ITimeGraphEntry entry
) {
662 if (fBeginTime
== SWT
.DEFAULT
&& entry
.hasTimeEvents() && entry
.getStartTime() != SWT
.DEFAULT
) {
663 fTime0Bound
= Math
.min(entry
.getStartTime(), fTime0Bound
);
665 if (fEndTime
== SWT
.DEFAULT
&& entry
.hasTimeEvents() && entry
.getEndTime() != SWT
.DEFAULT
) {
666 fTime1Bound
= Math
.max(entry
.getEndTime(), fTime1Bound
);
668 if (entry
.hasChildren()) {
669 for (ITimeGraphEntry child
: entry
.getChildren()) {
676 * Set the time bounds to the provided values.
679 * The bounds begin time, or SWT.DEFAULT to use the input bounds
681 * The bounds end time, or SWT.DEFAULT to use the input bounds
683 public void setTimeBounds(long beginTime
, long endTime
) {
684 fBeginTime
= beginTime
;
686 fTime0Bound
= (fBeginTime
!= SWT
.DEFAULT ? fBeginTime
: fEndTime
);
687 fTime1Bound
= (fEndTime
!= SWT
.DEFAULT ? fEndTime
: fBeginTime
);
688 if (fTime0Bound
> fTime1Bound
) {
689 // only possible if both are not default
690 fBeginTime
= endTime
;
691 fEndTime
= beginTime
;
692 fTime0Bound
= fBeginTime
;
693 fTime1Bound
= fEndTime
;
695 adjustHorizontalScrollBar();
699 * Recalculate the current time window when bounds have changed.
701 public void setTimeBounds() {
702 if (!fTimeRangeFixed
) {
703 fTime0
= fTime0Bound
;
704 fTime1
= fTime1Bound
;
706 fTime0
= Math
.max(fTime0Bound
, Math
.min(fTime0
, fTime1Bound
));
707 fTime1
= Math
.max(fTime0Bound
, Math
.min(fTime1
, fTime1Bound
));
708 if (fTime1
- fTime0
< fMinTimeInterval
) {
709 fTime1
= Math
.min(fTime1Bound
, fTime0
+ fMinTimeInterval
);
716 private void refreshAllData(ITimeGraphEntry
[] traces
) {
718 if (fSelectionBegin
< fBeginTime
) {
719 fSelectionBegin
= fBeginTime
;
720 } else if (fSelectionBegin
> fEndTime
) {
721 fSelectionBegin
= fEndTime
;
723 if (fSelectionEnd
< fBeginTime
) {
724 fSelectionEnd
= fBeginTime
;
725 } else if (fSelectionEnd
> fEndTime
) {
726 fSelectionEnd
= fEndTime
;
728 fTimeGraphCtrl
.refreshData(traces
);
729 fTimeScaleCtrl
.redraw();
730 updateMarkerActions();
731 adjustVerticalScrollBar();
735 * Callback for when this view is focused
737 public void setFocus() {
738 if (null != fTimeGraphCtrl
) {
739 fTimeGraphCtrl
.setFocus();
744 * Get the current focus status of this view.
746 * @return If the view is currently focused, or not
748 public boolean isInFocus() {
749 return fTimeGraphCtrl
.isInFocus();
753 * Get the view's current selection
755 * @return The entry that is selected
757 public ITimeGraphEntry
getSelection() {
758 return fTimeGraphCtrl
.getSelectedTrace();
762 * Get the index of the current selection
766 public int getSelectionIndex() {
767 return fTimeGraphCtrl
.getSelectedIndex();
771 public long getTime0() {
776 public long getTime1() {
781 public long getMinTimeInterval() {
782 return fMinTimeInterval
;
786 public int getNameSpace() {
791 public void setNameSpace(int width
) {
793 int w
= fTimeGraphCtrl
.getClientArea().width
;
794 if (fNameWidth
> w
- MIN_NAME_WIDTH
) {
795 fNameWidth
= w
- MIN_NAME_WIDTH
;
797 if (fNameWidth
< MIN_NAME_WIDTH
) {
798 fNameWidth
= MIN_NAME_WIDTH
;
800 fTimeGraphCtrl
.redraw();
801 fTimeScaleCtrl
.redraw();
805 public int getTimeSpace() {
806 int w
= fTimeGraphCtrl
.getClientArea().width
;
807 return w
- fNameWidth
;
811 public long getBeginTime() {
816 public long getEndTime() {
821 public long getMaxTime() {
826 public long getMinTime() {
831 public long getSelectionBegin() {
832 return fSelectionBegin
;
836 public long getSelectionEnd() {
837 return fSelectionEnd
;
841 public void setStartFinishTimeNotify(long time0
, long time1
) {
842 setStartFinishTimeInt(time0
, time1
);
843 notifyRangeListeners();
847 public void notifyStartFinishTime() {
848 notifyRangeListeners();
852 public void setStartFinishTime(long time0
, long time1
) {
853 /* if there is a pending time range, ignore this one */
854 if (fListenerNotifier
!= null && fListenerNotifier
.hasTimeRangeUpdated()) {
857 setStartFinishTimeInt(time0
, time1
);
858 updateExtSynchValues();
861 private void setStartFinishTimeInt(long time0
, long time1
) {
863 if (fTime0
< fTime0Bound
) {
864 fTime0
= fTime0Bound
;
866 if (fTime0
> fTime1Bound
) {
867 fTime0
= fTime1Bound
;
870 if (fTime1
< fTime0Bound
) {
871 fTime1
= fTime0Bound
;
873 if (fTime1
> fTime1Bound
) {
874 fTime1
= fTime1Bound
;
876 if (fTime1
- fTime0
< fMinTimeInterval
) {
877 fTime1
= Math
.min(fTime1Bound
, fTime0
+ fMinTimeInterval
);
879 fTimeRangeFixed
= true;
880 adjustHorizontalScrollBar();
881 fTimeGraphCtrl
.redraw();
882 fTimeScaleCtrl
.redraw();
886 public void resetStartFinishTime() {
887 setStartFinishTimeNotify(fTime0Bound
, fTime1Bound
);
888 fTimeRangeFixed
= false;
892 public void setSelectedTimeNotify(long time
, boolean ensureVisible
) {
893 setSelectedTimeInt(time
, ensureVisible
, true);
897 public void setSelectedTime(long time
, boolean ensureVisible
) {
898 /* if there is a pending time selection, ignore this one */
899 if (fListenerNotifier
!= null && fListenerNotifier
.hasTimeSelected()) {
902 setSelectedTimeInt(time
, ensureVisible
, false);
906 public void setSelectionRangeNotify(long beginTime
, long endTime
) {
909 long selectionBegin
= fSelectionBegin
;
910 long selectionEnd
= fSelectionEnd
;
911 fSelectionBegin
= Math
.max(fTime0Bound
, Math
.min(fTime1Bound
, beginTime
));
912 fSelectionEnd
= Math
.max(fTime0Bound
, Math
.min(fTime1Bound
, endTime
));
913 boolean changed
= (selectionBegin
!= fSelectionBegin
|| selectionEnd
!= fSelectionEnd
);
914 ensureVisible(fSelectionEnd
);
915 fTimeGraphCtrl
.redraw();
916 fTimeScaleCtrl
.redraw();
917 updateMarkerActions();
918 if ((time0
!= fTime0
) || (time1
!= fTime1
)) {
919 notifyRangeListeners();
922 notifyTimeListeners();
927 public void setSelectionRange(long beginTime
, long endTime
) {
928 /* if there is a pending time selection, ignore this one */
929 if (fListenerNotifier
!= null && fListenerNotifier
.hasTimeSelected()) {
932 fSelectionBegin
= Math
.max(fTime0Bound
, Math
.min(fTime1Bound
, beginTime
));
933 fSelectionEnd
= Math
.max(fTime0Bound
, Math
.min(fTime1Bound
, endTime
));
934 fTimeGraphCtrl
.redraw();
935 fTimeScaleCtrl
.redraw();
936 updateMarkerActions();
939 private void setSelectedTimeInt(long time
, boolean ensureVisible
, boolean doNotify
) {
940 long selection
= Math
.max(fTime0Bound
, Math
.min(fTime1Bound
, time
));
944 ensureVisible(selection
);
946 fTimeGraphCtrl
.redraw();
947 fTimeScaleCtrl
.redraw();
949 boolean notifySelectedTime
= (selection
!= fSelectionBegin
|| selection
!= fSelectionEnd
);
950 fSelectionBegin
= selection
;
951 fSelectionEnd
= selection
;
952 updateMarkerActions();
954 if ((time0
!= fTime0
) || (time1
!= fTime1
)) {
955 notifyRangeListeners();
958 if (doNotify
&& notifySelectedTime
) {
959 notifyTimeListeners();
963 private void ensureVisible(long time
) {
964 long timeMid
= (fTime1
- fTime0
) / 2;
966 long dt
= fTime0
- time
+ timeMid
;
969 } else if (time
> fTime1
) {
970 long dt
= time
- fTime1
+ timeMid
;
974 if (fTime0
< fTime0Bound
) {
975 fTime1
= Math
.min(fTime1Bound
, fTime1
+ (fTime0Bound
- fTime0
));
976 fTime0
= fTime0Bound
;
977 } else if (fTime1
> fTime1Bound
) {
978 fTime0
= Math
.max(fTime0Bound
, fTime0
- (fTime1
- fTime1Bound
));
979 fTime1
= fTime1Bound
;
981 if (fTime1
- fTime0
< fMinTimeInterval
) {
982 fTime1
= Math
.min(fTime1Bound
, fTime0
+ fMinTimeInterval
);
984 adjustHorizontalScrollBar();
988 public void widgetDefaultSelected(SelectionEvent e
) {
989 if (fSelectedEntry
!= getSelection()) {
990 fSelectedEntry
= getSelection();
991 notifySelectionListeners();
996 public void widgetSelected(SelectionEvent e
) {
997 if (fSelectedEntry
!= getSelection()) {
998 fSelectedEntry
= getSelection();
999 notifySelectionListeners();
1004 * Callback for when the next event is selected
1007 * true to extend selection range, false for single selection
1010 public void selectNextEvent(boolean extend
) {
1011 fTimeGraphCtrl
.selectNextEvent(extend
);
1012 adjustVerticalScrollBar();
1016 * Callback for when the previous event is selected
1019 * true to extend selection range, false for single selection
1022 public void selectPrevEvent(boolean extend
) {
1023 fTimeGraphCtrl
.selectPrevEvent(extend
);
1024 adjustVerticalScrollBar();
1028 * Callback for when the next item is selected
1030 public void selectNextItem() {
1031 fTimeGraphCtrl
.selectNextTrace();
1032 adjustVerticalScrollBar();
1036 * Callback for when the previous item is selected
1038 public void selectPrevItem() {
1039 fTimeGraphCtrl
.selectPrevTrace();
1040 adjustVerticalScrollBar();
1044 * Callback for the show legend action
1046 public void showLegend() {
1047 if (fDataViewer
== null || fDataViewer
.isDisposed()) {
1051 TimeGraphLegend
.open(fDataViewer
.getShell(), fTimeGraphProvider
);
1055 * Callback for the Zoom In action
1057 public void zoomIn() {
1058 fTimeGraphCtrl
.zoomIn();
1062 * Callback for the Zoom Out action
1064 public void zoomOut() {
1065 fTimeGraphCtrl
.zoomOut();
1068 private String
getPreferenceString(String string
) {
1069 return getViewTypeStr() + "." + string
; //$NON-NLS-1$
1073 * Add a selection listener
1076 * The listener to add
1078 public void addSelectionListener(ITimeGraphSelectionListener listener
) {
1079 fSelectionListeners
.add(listener
);
1083 * Remove a selection listener
1086 * The listener to remove
1088 public void removeSelectionListener(ITimeGraphSelectionListener listener
) {
1089 fSelectionListeners
.remove(listener
);
1092 private void notifySelectionListeners() {
1093 if (fListenerNotifier
== null) {
1094 fListenerNotifier
= new ListenerNotifier();
1095 fListenerNotifier
.start();
1097 fListenerNotifier
.selectionChanged();
1100 private void fireSelectionChanged(ITimeGraphEntry selection
) {
1101 TimeGraphSelectionEvent event
= new TimeGraphSelectionEvent(this, selection
);
1103 for (ITimeGraphSelectionListener listener
: fSelectionListeners
) {
1104 listener
.selectionChanged(event
);
1109 * Add a time listener
1112 * The listener to add
1114 public void addTimeListener(ITimeGraphTimeListener listener
) {
1115 fTimeListeners
.add(listener
);
1119 * Remove a time listener
1122 * The listener to remove
1124 public void removeTimeListener(ITimeGraphTimeListener listener
) {
1125 fTimeListeners
.remove(listener
);
1128 private void notifyTimeListeners() {
1129 if (fListenerNotifier
== null) {
1130 fListenerNotifier
= new ListenerNotifier();
1131 fListenerNotifier
.start();
1133 fListenerNotifier
.timeSelected();
1136 private void fireTimeSelected(long startTime
, long endTime
) {
1137 TimeGraphTimeEvent event
= new TimeGraphTimeEvent(this, startTime
, endTime
);
1139 for (ITimeGraphTimeListener listener
: fTimeListeners
) {
1140 listener
.timeSelected(event
);
1145 * Add a range listener
1148 * The listener to add
1150 public void addRangeListener(ITimeGraphRangeListener listener
) {
1151 fRangeListeners
.add(listener
);
1155 * Remove a range listener
1158 * The listener to remove
1160 public void removeRangeListener(ITimeGraphRangeListener listener
) {
1161 fRangeListeners
.remove(listener
);
1164 private void notifyRangeListeners() {
1165 if (fListenerNotifier
== null) {
1166 fListenerNotifier
= new ListenerNotifier();
1167 fListenerNotifier
.start();
1169 fListenerNotifier
.timeRangeUpdated();
1172 private void fireTimeRangeUpdated(long startTime
, long endTime
) {
1173 // Check if the time has actually changed from last notification
1174 if (startTime
!= fTime0ExtSynch
|| endTime
!= fTime1ExtSynch
) {
1175 // Notify Time Scale Selection Listeners
1176 TimeGraphRangeUpdateEvent event
= new TimeGraphRangeUpdateEvent(this, startTime
, endTime
);
1178 for (ITimeGraphRangeListener listener
: fRangeListeners
) {
1179 listener
.timeRangeUpdated(event
);
1182 // update external synch values
1183 updateExtSynchValues();
1188 * Add a bookmark listener
1191 * The listener to add
1194 public void addBookmarkListener(ITimeGraphBookmarkListener listener
) {
1195 fBookmarkListeners
.add(listener
);
1199 * Remove a bookmark listener
1202 * The listener to remove
1205 public void removeBookmarkListener(ITimeGraphBookmarkListener listener
) {
1206 fBookmarkListeners
.remove(listener
);
1209 private void fireBookmarkAdded(IMarkerEvent bookmark
) {
1210 TimeGraphBookmarkEvent event
= new TimeGraphBookmarkEvent(this, bookmark
);
1212 for (ITimeGraphBookmarkListener listener
: fBookmarkListeners
) {
1213 listener
.bookmarkAdded(event
);
1217 private void fireBookmarkRemoved(IMarkerEvent bookmark
) {
1218 TimeGraphBookmarkEvent event
= new TimeGraphBookmarkEvent(this, bookmark
);
1220 for (ITimeGraphBookmarkListener listener
: fBookmarkListeners
) {
1221 listener
.bookmarkRemoved(event
);
1226 * Set the bookmarks list.
1229 * The bookmarks list, or null
1232 public void setBookmarks(List
<IMarkerEvent
> bookmarks
) {
1233 for (IMarkerEvent bookmark
: fBookmarks
) {
1234 checkDisposeColor(bookmark
.getColor());
1237 if (bookmarks
!= null) {
1238 fBookmarks
.addAll(bookmarks
);
1241 updateMarkerActions();
1245 * Get the bookmarks list.
1247 * @return The bookmarks list
1250 public List
<IMarkerEvent
> getBookmarks() {
1251 return Collections
.unmodifiableList(fBookmarks
);
1255 * Set the list of marker categories.
1258 * The list of marker categories, or null
1261 public void setMarkerCategories(List
<String
> categories
) {
1262 fMarkerCategories
.clear();
1263 fMarkerCategories
.add(IMarkerEvent
.BOOKMARKS
);
1264 if (categories
!= null) {
1265 fMarkerCategories
.addAll(categories
);
1267 Collections
.sort(fMarkerCategories
);
1271 * Set the markers list.
1274 * The markers list, or null
1277 public void setMarkers(List
<IMarkerEvent
> markers
) {
1279 if (markers
!= null) {
1280 fMarkers
.addAll(markers
);
1283 updateMarkerActions();
1287 * Get the markers list.
1289 * @return The markers list, or null
1292 public List
<IMarkerEvent
> getMarkers() {
1293 return Collections
.unmodifiableList(fMarkers
);
1297 * Dispose the color resource if and only if it was created by this viewer.
1302 private void checkDisposeColor(Color color
) {
1303 for (int i
= 0; i
< fColors
.size(); i
++) {
1304 /* check for identity, not equality */
1305 if (fColors
.get(i
) == color
) {
1314 * Callback to set a selected event in the view
1317 * The event that was selected
1319 * The source of this selection event
1321 public void setSelectedEvent(ITimeEvent event
, Object source
) {
1322 if (event
== null || source
== this) {
1325 fSelectedEntry
= event
.getEntry();
1326 fTimeGraphCtrl
.selectItem(fSelectedEntry
, false);
1328 setSelectedTimeInt(event
.getTime(), true, true);
1329 adjustVerticalScrollBar();
1333 * Set the seeked time of a trace
1336 * The trace that was seeked
1340 * The source of this seek event
1342 public void setSelectedTraceTime(ITimeGraphEntry trace
, long time
, Object source
) {
1343 if (trace
== null || source
== this) {
1346 fSelectedEntry
= trace
;
1347 fTimeGraphCtrl
.selectItem(trace
, false);
1349 setSelectedTimeInt(time
, true, true);
1353 * Callback for a trace selection
1356 * The trace that was selected
1358 public void setSelection(ITimeGraphEntry trace
) {
1359 /* if there is a pending selection, ignore this one */
1360 if (fListenerNotifier
!= null && fListenerNotifier
.hasSelectionChanged()) {
1363 fSelectedEntry
= trace
;
1364 fTimeGraphCtrl
.selectItem(trace
, false);
1365 adjustVerticalScrollBar();
1369 * Callback for a time window selection
1372 * Start time of the range
1374 * End time of the range
1376 * Source of the event
1378 public void setSelectVisTimeWindow(long time0
, long time1
, Object source
) {
1379 if (source
== this) {
1383 setStartFinishTimeInt(time0
, time1
);
1385 // update notification time values since we are now in synch with the
1386 // external application
1387 updateExtSynchValues();
1391 * update the cache values used to identify the need to send a time window
1392 * update to external registered listeners
1394 private void updateExtSynchValues() {
1395 // last time notification cache
1396 fTime0ExtSynch
= fTime0
;
1397 fTime1ExtSynch
= fTime1
;
1401 public TimeFormat
getTimeFormat() {
1407 * the {@link TimeFormat} used to display timestamps
1409 public void setTimeFormat(TimeFormat tf
) {
1410 this.fTimeFormat
= tf
;
1411 if (tf
== TimeFormat
.CYCLES
) {
1412 fTimeDataProvider
= new TimeDataProviderCyclesConverter(this, fClockFrequency
);
1414 fTimeDataProvider
= this;
1416 fTimeScaleCtrl
.setTimeProvider(fTimeDataProvider
);
1417 if (fToolTipHandler
!= null) {
1418 fToolTipHandler
.setTimeProvider(fTimeDataProvider
);
1423 * Sets the clock frequency. Used when the time format is set to CYCLES.
1425 * @param clockFrequency
1426 * the clock frequency in Hz
1428 public void setClockFrequency(long clockFrequency
) {
1429 fClockFrequency
= clockFrequency
;
1430 if (fTimeFormat
== TimeFormat
.CYCLES
) {
1431 fTimeDataProvider
= new TimeDataProviderCyclesConverter(this, fClockFrequency
);
1432 fTimeScaleCtrl
.setTimeProvider(fTimeDataProvider
);
1433 if (fToolTipHandler
!= null) {
1434 fToolTipHandler
.setTimeProvider(fTimeDataProvider
);
1440 * Retrieve the border width
1444 public int getBorderWidth() {
1445 return fBorderWidth
;
1449 * Set the border width
1451 * @param borderWidth
1454 public void setBorderWidth(int borderWidth
) {
1455 if (borderWidth
> -1) {
1456 this.fBorderWidth
= borderWidth
;
1457 GridLayout gl
= (GridLayout
) fDataViewer
.getLayout();
1458 gl
.marginHeight
= borderWidth
;
1463 * Retrieve the height of the header
1465 * @return The height
1467 public int getHeaderHeight() {
1468 return fTimeScaleHeight
;
1472 * Set the height of the header
1474 * @param headerHeight
1477 public void setHeaderHeight(int headerHeight
) {
1478 if (headerHeight
> -1) {
1479 this.fTimeScaleHeight
= headerHeight
;
1480 fTimeScaleCtrl
.setHeight(headerHeight
);
1485 * Retrieve the height of an item row
1487 * @return The height
1489 public int getItemHeight() {
1490 if (fTimeGraphCtrl
!= null) {
1491 return fTimeGraphCtrl
.getItemHeight();
1497 * Set the height of an item row
1502 public void setItemHeight(int rowHeight
) {
1503 if (fTimeGraphCtrl
!= null) {
1504 fTimeGraphCtrl
.setItemHeight(rowHeight
);
1509 * Set the minimum item width
1514 public void setMinimumItemWidth(int width
) {
1515 if (fTimeGraphCtrl
!= null) {
1516 fTimeGraphCtrl
.setMinimumItemWidth(width
);
1521 * Set the width for the name column
1526 public void setNameWidthPref(int width
) {
1527 fNameWidthPref
= width
;
1535 * Retrieve the configure width for the name column
1541 public int getNameWidthPref(int width
) {
1542 return fNameWidthPref
;
1546 * Returns the primary control associated with this viewer.
1548 * @return the SWT control which displays this viewer's content
1550 public Control
getControl() {
1555 * Returns the time graph control associated with this viewer.
1557 * @return the time graph control
1559 public TimeGraphControl
getTimeGraphControl() {
1560 return fTimeGraphCtrl
;
1564 * Returns the time graph scale associated with this viewer.
1566 * @return the time graph scale
1568 public TimeGraphScale
getTimeGraphScale() {
1569 return fTimeScaleCtrl
;
1573 * Returns the composite containing all the controls that are time aligned,
1574 * i.e. TimeGraphScale, TimeGraphControl.
1576 * @return the time based composite
1579 public Composite
getTimeAlignedComposite() {
1580 return fTimeAlignedComposite
;
1584 * Return the x coordinate corresponding to a time
1588 * @return the x coordinate corresponding to the time
1590 public int getXForTime(long time
) {
1591 return fTimeGraphCtrl
.getXForTime(time
);
1595 * Return the time corresponding to an x coordinate
1599 * @return the time corresponding to the x coordinate
1601 public long getTimeAtX(int x
) {
1602 return fTimeGraphCtrl
.getTimeAtX(x
);
1606 * Get the selection provider
1608 * @return the selection provider
1610 public ISelectionProvider
getSelectionProvider() {
1611 return fTimeGraphCtrl
;
1615 * Wait for the cursor
1618 * Wait indefinitely?
1620 public void waitCursor(boolean waitInd
) {
1621 fTimeGraphCtrl
.waitCursor(waitInd
);
1625 * Get the horizontal scroll bar object
1627 * @return The scroll bar
1629 public Slider
getHorizontalBar() {
1630 return fHorizontalScrollBar
;
1634 * Get the vertical scroll bar object
1636 * @return The scroll bar
1638 public Slider
getVerticalBar() {
1639 return fVerticalScrollBar
;
1643 * Set the given index as the top one
1646 * The index that will go to the top
1648 public void setTopIndex(int index
) {
1649 fTimeGraphCtrl
.setTopIndex(index
);
1650 adjustVerticalScrollBar();
1654 * Retrieve the current top index
1656 * @return The top index
1658 public int getTopIndex() {
1659 return fTimeGraphCtrl
.getTopIndex();
1663 * Sets the auto-expand level to be used for new entries discovered when
1664 * calling {@link #setInput(Object)} or {@link #refresh()}. The value 0
1665 * means that there is no auto-expand; 1 means that top-level entries are
1666 * expanded, but not their children; 2 means that top-level entries are
1667 * expanded, and their children, but not grand-children; and so on.
1669 * The value {@link #ALL_LEVELS} means that all subtrees should be expanded.
1673 * non-negative level, or <code>ALL_LEVELS</code> to expand all
1674 * levels of the tree
1676 public void setAutoExpandLevel(int level
) {
1677 fTimeGraphCtrl
.setAutoExpandLevel(level
);
1681 * Returns the auto-expand level.
1683 * @return non-negative level, or <code>ALL_LEVELS</code> if all levels of
1684 * the tree are expanded automatically
1685 * @see #setAutoExpandLevel
1687 public int getAutoExpandLevel() {
1688 return fTimeGraphCtrl
.getAutoExpandLevel();
1692 * Get the expanded state of an entry.
1696 * @return true if the entry is expanded, false if collapsed
1699 public boolean getExpandedState(ITimeGraphEntry entry
) {
1700 return fTimeGraphCtrl
.getExpandedState(entry
);
1704 * Set the expanded state of an entry
1707 * The entry to expand/collapse
1709 * True for expanded, false for collapsed
1711 public void setExpandedState(ITimeGraphEntry entry
, boolean expanded
) {
1712 fTimeGraphCtrl
.setExpandedState(entry
, expanded
);
1713 adjustVerticalScrollBar();
1717 * Collapses all nodes of the viewer's tree, starting with the root.
1719 public void collapseAll() {
1720 fTimeGraphCtrl
.collapseAll();
1721 adjustVerticalScrollBar();
1725 * Expands all entries of the viewer's tree, starting with the root.
1727 public void expandAll() {
1728 fTimeGraphCtrl
.expandAll();
1729 adjustVerticalScrollBar();
1733 * Get the number of expanded (visible) time graph entries. This includes
1734 * leafs and does not include filtered-out entries.
1736 * @return The number of expanded (visible) time graph entries
1738 public int getExpandedElementCount() {
1739 return fTimeGraphCtrl
.getExpandedElementCount();
1743 * Get the expanded (visible) time graph entries. This includes leafs and
1744 * does not include filtered-out entries.
1746 * @return The array of expanded (visible) time graph entries
1748 public ITimeGraphEntry
[] getExpandedElements() {
1749 return fTimeGraphCtrl
.getExpandedElements();
1753 * Add a tree listener
1756 * The listener to add
1758 public void addTreeListener(ITimeGraphTreeListener listener
) {
1759 fTimeGraphCtrl
.addTreeListener(listener
);
1763 * Remove a tree listener
1766 * The listener to remove
1768 public void removeTreeListener(ITimeGraphTreeListener listener
) {
1769 fTimeGraphCtrl
.removeTreeListener(listener
);
1773 * Get the reset scale action.
1775 * @return The Action object
1777 public Action
getResetScaleAction() {
1778 if (fResetScaleAction
== null) {
1780 fResetScaleAction
= new Action() {
1783 resetStartFinishTime();
1786 fResetScaleAction
.setText(Messages
.TmfTimeGraphViewer_ResetScaleActionNameText
);
1787 fResetScaleAction
.setToolTipText(Messages
.TmfTimeGraphViewer_ResetScaleActionToolTipText
);
1788 fResetScaleAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_HOME_MENU
));
1790 return fResetScaleAction
;
1794 * Get the show legend action.
1796 * @return The Action object
1798 public Action
getShowLegendAction() {
1799 if (fShowLegendAction
== null) {
1801 fShowLegendAction
= new Action() {
1807 fShowLegendAction
.setText(Messages
.TmfTimeGraphViewer_LegendActionNameText
);
1808 fShowLegendAction
.setToolTipText(Messages
.TmfTimeGraphViewer_LegendActionToolTipText
);
1809 fShowLegendAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_SHOW_LEGEND
));
1812 return fShowLegendAction
;
1816 * Get the the next event action.
1818 * @return The action object
1820 public Action
getNextEventAction() {
1821 if (fNextEventAction
== null) {
1822 fNextEventAction
= new Action() {
1824 public void runWithEvent(Event event
) {
1825 boolean extend
= (event
.stateMask
& SWT
.SHIFT
) != 0;
1826 selectNextEvent(extend
);
1830 fNextEventAction
.setText(Messages
.TmfTimeGraphViewer_NextEventActionNameText
);
1831 fNextEventAction
.setToolTipText(Messages
.TmfTimeGraphViewer_NextEventActionToolTipText
);
1832 fNextEventAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_NEXT_EVENT
));
1835 return fNextEventAction
;
1839 * Get the previous event action.
1841 * @return The Action object
1843 public Action
getPreviousEventAction() {
1844 if (fPrevEventAction
== null) {
1845 fPrevEventAction
= new Action() {
1847 public void runWithEvent(Event event
) {
1848 boolean extend
= (event
.stateMask
& SWT
.SHIFT
) != 0;
1849 selectPrevEvent(extend
);
1853 fPrevEventAction
.setText(Messages
.TmfTimeGraphViewer_PreviousEventActionNameText
);
1854 fPrevEventAction
.setToolTipText(Messages
.TmfTimeGraphViewer_PreviousEventActionToolTipText
);
1855 fPrevEventAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_PREV_EVENT
));
1858 return fPrevEventAction
;
1862 * Get the next item action.
1864 * @return The Action object
1866 public Action
getNextItemAction() {
1867 if (fNextItemAction
== null) {
1869 fNextItemAction
= new Action() {
1875 fNextItemAction
.setText(Messages
.TmfTimeGraphViewer_NextItemActionNameText
);
1876 fNextItemAction
.setToolTipText(Messages
.TmfTimeGraphViewer_NextItemActionToolTipText
);
1877 fNextItemAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_NEXT_ITEM
));
1879 return fNextItemAction
;
1883 * Get the previous item action.
1885 * @return The Action object
1887 public Action
getPreviousItemAction() {
1888 if (fPreviousItemAction
== null) {
1890 fPreviousItemAction
= new Action() {
1896 fPreviousItemAction
.setText(Messages
.TmfTimeGraphViewer_PreviousItemActionNameText
);
1897 fPreviousItemAction
.setToolTipText(Messages
.TmfTimeGraphViewer_PreviousItemActionToolTipText
);
1898 fPreviousItemAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_PREV_ITEM
));
1900 return fPreviousItemAction
;
1904 * Get the zoom in action
1906 * @return The Action object
1908 public Action
getZoomInAction() {
1909 if (fZoomInAction
== null) {
1910 fZoomInAction
= new Action() {
1916 fZoomInAction
.setText(Messages
.TmfTimeGraphViewer_ZoomInActionNameText
);
1917 fZoomInAction
.setToolTipText(Messages
.TmfTimeGraphViewer_ZoomInActionToolTipText
);
1918 fZoomInAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_ZOOM_IN_MENU
));
1920 return fZoomInAction
;
1924 * Get the zoom out action
1926 * @return The Action object
1928 public Action
getZoomOutAction() {
1929 if (fZoomOutAction
== null) {
1930 fZoomOutAction
= new Action() {
1936 fZoomOutAction
.setText(Messages
.TmfTimeGraphViewer_ZoomOutActionNameText
);
1937 fZoomOutAction
.setToolTipText(Messages
.TmfTimeGraphViewer_ZoomOutActionToolTipText
);
1938 fZoomOutAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_ZOOM_OUT_MENU
));
1940 return fZoomOutAction
;
1944 * Get the hide arrows action
1946 * @param dialogSettings
1947 * The dialog settings section where the state should be stored,
1950 * @return The Action object
1952 public Action
getHideArrowsAction(final IDialogSettings dialogSettings
) {
1953 if (fHideArrowsAction
== null) {
1954 fHideArrowsAction
= new Action(Messages
.TmfTimeGraphViewer_HideArrowsActionNameText
, IAction
.AS_CHECK_BOX
) {
1957 boolean hideArrows
= fHideArrowsAction
.isChecked();
1958 fTimeGraphCtrl
.hideArrows(hideArrows
);
1960 if (dialogSettings
!= null) {
1961 dialogSettings
.put(HIDE_ARROWS_KEY
, hideArrows
);
1963 if (fFollowArrowFwdAction
!= null) {
1964 fFollowArrowFwdAction
.setEnabled(!hideArrows
);
1966 if (fFollowArrowBwdAction
!= null) {
1967 fFollowArrowBwdAction
.setEnabled(!hideArrows
);
1971 fHideArrowsAction
.setToolTipText(Messages
.TmfTimeGraphViewer_HideArrowsActionToolTipText
);
1972 fHideArrowsAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_HIDE_ARROWS
));
1973 if (dialogSettings
!= null) {
1974 boolean hideArrows
= dialogSettings
.getBoolean(HIDE_ARROWS_KEY
);
1975 fTimeGraphCtrl
.hideArrows(hideArrows
);
1976 fHideArrowsAction
.setChecked(hideArrows
);
1977 if (fFollowArrowFwdAction
!= null) {
1978 fFollowArrowFwdAction
.setEnabled(!hideArrows
);
1980 if (fFollowArrowBwdAction
!= null) {
1981 fFollowArrowBwdAction
.setEnabled(!hideArrows
);
1985 return fHideArrowsAction
;
1989 * Get the follow arrow forward action.
1991 * @return The Action object
1993 public Action
getFollowArrowFwdAction() {
1994 if (fFollowArrowFwdAction
== null) {
1995 fFollowArrowFwdAction
= new Action() {
1997 public void runWithEvent(Event event
) {
1998 boolean extend
= (event
.stateMask
& SWT
.SHIFT
) != 0;
1999 fTimeGraphCtrl
.followArrowFwd(extend
);
2000 adjustVerticalScrollBar();
2003 fFollowArrowFwdAction
.setText(Messages
.TmfTimeGraphViewer_FollowArrowForwardActionNameText
);
2004 fFollowArrowFwdAction
.setToolTipText(Messages
.TmfTimeGraphViewer_FollowArrowForwardActionToolTipText
);
2005 fFollowArrowFwdAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_FOLLOW_ARROW_FORWARD
));
2006 if (fHideArrowsAction
!= null) {
2007 fFollowArrowFwdAction
.setEnabled(!fHideArrowsAction
.isChecked());
2010 return fFollowArrowFwdAction
;
2014 * Get the follow arrow backward action.
2016 * @return The Action object
2018 public Action
getFollowArrowBwdAction() {
2019 if (fFollowArrowBwdAction
== null) {
2020 fFollowArrowBwdAction
= new Action() {
2022 public void runWithEvent(Event event
) {
2023 boolean extend
= (event
.stateMask
& SWT
.SHIFT
) != 0;
2024 fTimeGraphCtrl
.followArrowBwd(extend
);
2025 adjustVerticalScrollBar();
2028 fFollowArrowBwdAction
.setText(Messages
.TmfTimeGraphViewer_FollowArrowBackwardActionNameText
);
2029 fFollowArrowBwdAction
.setToolTipText(Messages
.TmfTimeGraphViewer_FollowArrowBackwardActionToolTipText
);
2030 fFollowArrowBwdAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_FOLLOW_ARROW_BACKWARD
));
2031 if (fHideArrowsAction
!= null) {
2032 fFollowArrowBwdAction
.setEnabled(!fHideArrowsAction
.isChecked());
2035 return fFollowArrowBwdAction
;
2039 * Get the show filter dialog action.
2041 * @return The Action object
2044 public ShowFilterDialogAction
getShowFilterDialogAction() {
2045 if (fShowFilterDialogAction
== null) {
2046 fShowFilterDialogAction
= new ShowFilterDialogAction(this);
2048 return fShowFilterDialogAction
;
2052 * Get the toggle bookmark action.
2054 * @return The Action object
2057 public Action
getToggleBookmarkAction() {
2058 if (fToggleBookmarkAction
== null) {
2059 fToggleBookmarkAction
= new Action() {
2061 public void runWithEvent(Event event
) {
2062 IMarkerEvent selectedBookmark
= getBookmarkAtSelection();
2063 if (selectedBookmark
== null) {
2064 final long time
= Math
.min(fSelectionBegin
, fSelectionEnd
);
2065 final long duration
= Math
.max(fSelectionBegin
, fSelectionEnd
) - time
;
2066 final AddBookmarkDialog dialog
= new AddBookmarkDialog(PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getShell(), null);
2067 if (dialog
.open() == Window
.OK
) {
2068 final String label
= dialog
.getValue();
2069 final RGBA rgba
= dialog
.getColorValue();
2070 Color color
= new Color(Display
.getDefault(), rgba
.rgb
.red
, rgba
.rgb
.green
, rgba
.rgb
.blue
, rgba
.alpha
);
2072 IMarkerEvent bookmark
= new MarkerEvent(null, time
, duration
, IMarkerEvent
.BOOKMARKS
, color
, label
, true);
2073 fBookmarks
.add(bookmark
);
2075 updateMarkerActions();
2076 getControl().redraw();
2077 fireBookmarkAdded(bookmark
);
2080 checkDisposeColor(selectedBookmark
.getColor());
2081 fBookmarks
.remove(selectedBookmark
);
2083 updateMarkerActions();
2084 getControl().redraw();
2085 fireBookmarkRemoved(selectedBookmark
);
2089 fToggleBookmarkAction
.setText(Messages
.TmfTimeGraphViewer_BookmarkActionAddText
);
2090 fToggleBookmarkAction
.setToolTipText(Messages
.TmfTimeGraphViewer_BookmarkActionAddText
);
2091 fToggleBookmarkAction
.setImageDescriptor(ADD_BOOKMARK
);
2093 return fToggleBookmarkAction
;
2097 * Get the next marker action.
2099 * @return The Action object
2102 public Action
getNextMarkerAction() {
2103 if (fNextMarkerAction
== null) {
2104 fNextMarkerAction
= new Action() {
2106 public void runWithEvent(Event event
) {
2107 final long time
= Math
.min(fSelectionBegin
, fSelectionEnd
);
2108 final long duration
= Math
.max(fSelectionBegin
, fSelectionEnd
) - time
;
2109 List
<IMarkerEvent
> markers
= getTimeGraphControl().getMarkers();
2110 if (markers
== null) {
2113 for (IMarkerEvent marker
: markers
) {
2114 if (marker
.getTime() > time
||
2115 (marker
.getTime() == time
&& marker
.getDuration() > duration
)) {
2116 setSelectionRangeNotify(marker
.getTime(), marker
.getTime() + marker
.getDuration());
2122 fNextMarkerAction
.setText(Messages
.TmfTimeGraphViewer_NextMarkerActionText
);
2123 fNextMarkerAction
.setToolTipText(Messages
.TmfTimeGraphViewer_NextMarkerActionText
);
2124 fNextMarkerAction
.setImageDescriptor(NEXT_BOOKMARK
);
2126 return fNextMarkerAction
;
2130 * Get the previous marker action.
2132 * @return The Action object
2135 public Action
getPreviousMarkerAction() {
2136 if (fPreviousMarkerAction
== null) {
2137 fPreviousMarkerAction
= new Action() {
2139 public void runWithEvent(Event event
) {
2140 final long time
= Math
.min(fSelectionBegin
, fSelectionEnd
);
2141 final long duration
= Math
.max(fSelectionBegin
, fSelectionEnd
) - time
;
2142 List
<IMarkerEvent
> markers
= getTimeGraphControl().getMarkers();
2143 if (markers
== null) {
2146 for (int i
= markers
.size() - 1; i
>= 0; i
--) {
2147 IMarkerEvent marker
= markers
.get(i
);
2148 if (marker
.getTime() < time
||
2149 (marker
.getTime() == time
&& marker
.getDuration() < duration
)) {
2150 setSelectionRangeNotify(marker
.getTime(), marker
.getTime() + marker
.getDuration());
2156 fPreviousMarkerAction
.setText(Messages
.TmfTimeGraphViewer_PreviousMarkerActionText
);
2157 fPreviousMarkerAction
.setToolTipText(Messages
.TmfTimeGraphViewer_PreviousMarkerActionText
);
2158 fPreviousMarkerAction
.setImageDescriptor(PREVIOUS_BOOKMARK
);
2160 return fPreviousMarkerAction
;
2164 * Get the show markers menu.
2166 * @return The menu manager object
2169 public MenuManager
getMarkersMenu() {
2170 if (fMarkersMenu
== null) {
2171 fMarkersMenu
= new MenuManager(Messages
.TmfTimeGraphViewer_ShowMarkersMenuText
);
2172 fMarkersMenu
.setRemoveAllWhenShown(true);
2173 fMarkersMenu
.addMenuListener(new IMenuListener() {
2175 public void menuAboutToShow(IMenuManager manager
) {
2176 for (String category
: fMarkerCategories
) {
2177 final Action action
= new Action(category
, IAction
.AS_CHECK_BOX
) {
2179 public void runWithEvent(Event event
) {
2181 fHiddenMarkerCategories
.remove(getText());
2183 fHiddenMarkerCategories
.add(getText());
2186 updateMarkerActions();
2187 getControl().redraw();
2190 action
.setChecked(!fHiddenMarkerCategories
.contains(category
));
2191 manager
.add(action
);
2196 return fMarkersMenu
;
2199 private IMarkerEvent
getBookmarkAtSelection() {
2200 final long time
= Math
.min(fSelectionBegin
, fSelectionEnd
);
2201 final long duration
= Math
.max(fSelectionBegin
, fSelectionEnd
) - time
;
2202 for (IMarkerEvent bookmark
: fBookmarks
) {
2203 if (bookmark
.getTime() == time
&& bookmark
.getDuration() == duration
) {
2210 private void updateMarkerActions() {
2211 if (fToggleBookmarkAction
!= null) {
2212 if (getBookmarkAtSelection() != null) {
2213 fToggleBookmarkAction
.setText(Messages
.TmfTimeGraphViewer_BookmarkActionRemoveText
);
2214 fToggleBookmarkAction
.setToolTipText(Messages
.TmfTimeGraphViewer_BookmarkActionRemoveText
);
2215 fToggleBookmarkAction
.setImageDescriptor(REMOVE_BOOKMARK
);
2217 fToggleBookmarkAction
.setText(Messages
.TmfTimeGraphViewer_BookmarkActionAddText
);
2218 fToggleBookmarkAction
.setToolTipText(Messages
.TmfTimeGraphViewer_BookmarkActionAddText
);
2219 fToggleBookmarkAction
.setImageDescriptor(ADD_BOOKMARK
);
2222 final long time
= Math
.min(fSelectionBegin
, fSelectionEnd
);
2223 final long duration
= Math
.max(fSelectionBegin
, fSelectionEnd
) - time
;
2224 List
<IMarkerEvent
> markers
= getTimeGraphControl().getMarkers();
2225 if (markers
== null) {
2226 markers
= Collections
.emptyList();
2228 if (fPreviousMarkerAction
!= null) {
2229 fPreviousMarkerAction
.setEnabled(!markers
.isEmpty() &&
2230 (time
> markers
.get(0).getTime() || (time
== markers
.get(0).getTime() && duration
> markers
.get(0).getDuration())));
2232 if (fNextMarkerAction
!= null) {
2233 int last
= markers
.size() - 1;
2234 fNextMarkerAction
.setEnabled(!markers
.isEmpty() &&
2235 (time
< markers
.get(last
).getTime() || (time
== markers
.get(last
).getTime() && duration
< markers
.get(last
).getDuration())));
2239 private void updateMarkerList() {
2240 List
<IMarkerEvent
> markers
= new ArrayList
<>();
2241 for (IMarkerEvent marker
: fMarkers
) {
2242 if (!fHiddenMarkerCategories
.contains(marker
.getCategory())) {
2243 markers
.add(marker
);
2246 if (!fHiddenMarkerCategories
.contains(IMarkerEvent
.BOOKMARKS
)) {
2247 markers
.addAll(fBookmarks
);
2249 Collections
.sort(markers
, new MarkerComparator());
2250 getTimeGraphControl().setMarkers(markers
);
2253 private void adjustHorizontalScrollBar() {
2254 long time0
= getTime0();
2255 long time1
= getTime1();
2256 long timeMin
= getMinTime();
2257 long timeMax
= getMaxTime();
2258 long delta
= timeMax
- timeMin
;
2260 int thumb
= H_SCROLLBAR_MAX
;
2262 // Thumb size (page size)
2263 thumb
= Math
.max(1, (int) (H_SCROLLBAR_MAX
* ((double) (time1
- time0
) / delta
)));
2264 // At the beginning of visible window
2265 timePos
= (int) (H_SCROLLBAR_MAX
* ((double) (time0
- timeMin
) / delta
));
2267 fHorizontalScrollBar
.setValues(timePos
, 0, H_SCROLLBAR_MAX
, thumb
, Math
.max(1, thumb
/ 2), Math
.max(2, thumb
));
2270 private void adjustVerticalScrollBar() {
2271 int topIndex
= fTimeGraphCtrl
.getTopIndex();
2272 int countPerPage
= fTimeGraphCtrl
.countPerPage();
2273 int expandedElementCount
= fTimeGraphCtrl
.getExpandedElementCount();
2274 if (topIndex
+ countPerPage
> expandedElementCount
) {
2275 fTimeGraphCtrl
.setTopIndex(Math
.max(0, expandedElementCount
- countPerPage
));
2278 int selection
= fTimeGraphCtrl
.getTopIndex();
2280 int max
= Math
.max(1, expandedElementCount
- 1);
2281 int thumb
= Math
.min(max
, Math
.max(1, countPerPage
- 1));
2283 int pageIncrement
= Math
.max(1, countPerPage
);
2284 fVerticalScrollBar
.setValues(selection
, min
, max
, thumb
, increment
, pageIncrement
);
2289 * a {@link MenuDetectListener}
2290 * @see org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.TimeGraphControl#addTimeGraphEntryMenuListener(org.eclipse.swt.events.MenuDetectListener)
2292 public void addTimeGraphEntryMenuListener(MenuDetectListener listener
) {
2293 fTimeGraphCtrl
.addTimeGraphEntryMenuListener(listener
);
2298 * a {@link MenuDetectListener}
2299 * @see org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.TimeGraphControl#removeTimeGraphEntryMenuListener(org.eclipse.swt.events.MenuDetectListener)
2301 public void removeTimeGraphEntryMenuListener(MenuDetectListener listener
) {
2302 fTimeGraphCtrl
.removeTimeGraphEntryMenuListener(listener
);
2307 * a {@link MenuDetectListener}
2308 * @see org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.TimeGraphControl#addTimeEventMenuListener(org.eclipse.swt.events.MenuDetectListener)
2310 public void addTimeEventMenuListener(MenuDetectListener listener
) {
2311 fTimeGraphCtrl
.addTimeEventMenuListener(listener
);
2316 * a {@link MenuDetectListener}
2317 * @see org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.TimeGraphControl#removeTimeEventMenuListener(org.eclipse.swt.events.MenuDetectListener)
2319 public void removeTimeEventMenuListener(MenuDetectListener listener
) {
2320 fTimeGraphCtrl
.removeTimeEventMenuListener(listener
);
2325 * The filter object to be attached to the view
2327 public void addFilter(ViewerFilter filter
) {
2328 fTimeGraphCtrl
.addFilter(filter
);
2334 * The filter object to be attached to the view
2336 public void removeFilter(ViewerFilter filter
) {
2337 fTimeGraphCtrl
.removeFilter(filter
);
2342 * Returns this viewer's filters.
2344 * @return an array of viewer filters
2347 public ViewerFilter
[] getFilters() {
2348 return fTimeGraphCtrl
.getFilters();
2352 * Sets the filters, replacing any previous filters, and triggers
2353 * refiltering of the elements.
2356 * an array of viewer filters, or null
2359 public void setFilters(ViewerFilter
[] filters
) {
2360 fTimeGraphCtrl
.setFilters(filters
);
2365 * Return the time alignment information
2367 * @return the time alignment information
2369 * @see ITmfTimeAligned
2373 public TmfTimeViewAlignmentInfo
getTimeViewAlignmentInfo() {
2374 return fTimeGraphCtrl
.getTimeViewAlignmentInfo();
2378 * Return the available width for the time-axis.
2380 * @see ITmfTimeAligned
2382 * @param requestedOffset
2383 * the requested offset
2384 * @return the available width for the time-axis
2388 public int getAvailableWidth(int requestedOffset
) {
2389 int totalWidth
= fTimeAlignedComposite
.getSize().x
;
2390 return Math
.min(totalWidth
, Math
.max(0, totalWidth
- requestedOffset
));
2394 * Perform the alignment operation.
2397 * the alignment offset
2399 * the alignment width
2401 * @see ITmfTimeAligned
2405 public void performAlign(int offset
, int width
) {
2406 fTimeGraphCtrl
.performAlign(offset
);
2407 int alignmentWidth
= width
;
2408 int size
= fTimeAlignedComposite
.getSize().x
;
2409 GridLayout layout
= (GridLayout
) fTimeAlignedComposite
.getLayout();
2410 int marginSize
= size
- alignmentWidth
- offset
;
2411 layout
.marginRight
= Math
.max(0, marginSize
);
2412 fTimeAlignedComposite
.layout();