1 /*****************************************************************************
2 * Copyright (c) 2007, 2016 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
.jdt
.annotation
.NonNull
;
27 import org
.eclipse
.jface
.action
.Action
;
28 import org
.eclipse
.jface
.action
.ActionContributionItem
;
29 import org
.eclipse
.jface
.action
.IAction
;
30 import org
.eclipse
.jface
.action
.IMenuCreator
;
31 import org
.eclipse
.jface
.action
.IMenuListener
;
32 import org
.eclipse
.jface
.action
.IMenuManager
;
33 import org
.eclipse
.jface
.action
.MenuManager
;
34 import org
.eclipse
.jface
.dialogs
.IDialogSettings
;
35 import org
.eclipse
.jface
.resource
.ImageDescriptor
;
36 import org
.eclipse
.jface
.viewers
.AbstractTreeViewer
;
37 import org
.eclipse
.jface
.viewers
.ISelectionProvider
;
38 import org
.eclipse
.jface
.viewers
.ITableLabelProvider
;
39 import org
.eclipse
.jface
.viewers
.ITreeContentProvider
;
40 import org
.eclipse
.jface
.viewers
.ViewerFilter
;
41 import org
.eclipse
.jface
.window
.Window
;
42 import org
.eclipse
.swt
.SWT
;
43 import org
.eclipse
.swt
.events
.ControlAdapter
;
44 import org
.eclipse
.swt
.events
.ControlEvent
;
45 import org
.eclipse
.swt
.events
.DisposeEvent
;
46 import org
.eclipse
.swt
.events
.DisposeListener
;
47 import org
.eclipse
.swt
.events
.KeyAdapter
;
48 import org
.eclipse
.swt
.events
.KeyEvent
;
49 import org
.eclipse
.swt
.events
.MenuDetectListener
;
50 import org
.eclipse
.swt
.events
.MouseEvent
;
51 import org
.eclipse
.swt
.events
.MouseWheelListener
;
52 import org
.eclipse
.swt
.events
.SelectionAdapter
;
53 import org
.eclipse
.swt
.events
.SelectionEvent
;
54 import org
.eclipse
.swt
.events
.SelectionListener
;
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
.IMarkerAxisListener
;
81 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.widgets
.ITimeDataProvider
;
82 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.widgets
.TimeDataProviderCyclesConverter
;
83 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.widgets
.TimeGraphColorScheme
;
84 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.widgets
.TimeGraphControl
;
85 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.widgets
.TimeGraphMarkerAxis
;
86 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.widgets
.TimeGraphScale
;
87 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.widgets
.TimeGraphTooltipHandler
;
88 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.widgets
.Utils
;
89 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.widgets
.Utils
.TimeFormat
;
90 import org
.eclipse
.ui
.PlatformUI
;
93 * Generic time graph viewer implementation
95 * @author Patrick Tasse, and others
97 public class TimeGraphViewer
implements ITimeDataProvider
, IMarkerAxisListener
, SelectionListener
{
99 /** Constant indicating that all levels of the time graph should be expanded */
100 public static final int ALL_LEVELS
= AbstractTreeViewer
.ALL_LEVELS
;
102 private static final int DEFAULT_NAME_WIDTH
= 200;
103 private static final int MIN_NAME_WIDTH
= 6;
104 private static final int MAX_NAME_WIDTH
= 1000;
105 private static final int DEFAULT_HEIGHT
= 22;
106 private static final String HIDE_ARROWS_KEY
= "hide.arrows"; //$NON-NLS-1$
107 private static final long DEFAULT_FREQUENCY
= 1000000000L;
108 private static final int H_SCROLLBAR_MAX
= Integer
.MAX_VALUE
- 1;
110 private static final ImageDescriptor ADD_BOOKMARK
= Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_ADD_BOOKMARK
);
111 private static final ImageDescriptor NEXT_BOOKMARK
= Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_NEXT_BOOKMARK
);
112 private static final ImageDescriptor PREVIOUS_BOOKMARK
= Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_PREVIOUS_BOOKMARK
);
113 private static final ImageDescriptor REMOVE_BOOKMARK
= Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_REMOVE_BOOKMARK
);
115 private long fMinTimeInterval
;
116 private ITimeGraphEntry fSelectedEntry
;
117 private long fBeginTime
= SWT
.DEFAULT
; // The user-specified bounds start time
118 private long fEndTime
= SWT
.DEFAULT
; // The user-specified bounds end time
119 private long fTime0
= SWT
.DEFAULT
; // The current window start time
120 private long fTime1
= SWT
.DEFAULT
; // The current window end time
121 private long fSelectionBegin
= SWT
.DEFAULT
;
122 private long fSelectionEnd
= SWT
.DEFAULT
;
123 private long fTime0Bound
= SWT
.DEFAULT
; // The bounds start time
124 private long fTime1Bound
= SWT
.DEFAULT
; // The bounds end time
125 private long fTime0ExtSynch
= SWT
.DEFAULT
;
126 private long fTime1ExtSynch
= SWT
.DEFAULT
;
127 private boolean fTimeRangeFixed
;
128 private int fNameWidthPref
= DEFAULT_NAME_WIDTH
;
129 private int fMinNameWidth
= MIN_NAME_WIDTH
;
130 private int fNameWidth
;
131 private Composite fDataViewer
;
133 private TimeGraphControl fTimeGraphCtrl
;
134 private TimeGraphScale fTimeScaleCtrl
;
135 private TimeGraphMarkerAxis fMarkerAxisCtrl
;
136 private Slider fHorizontalScrollBar
;
137 private Slider fVerticalScrollBar
;
138 private @NonNull TimeGraphColorScheme fColorScheme
= new TimeGraphColorScheme();
139 private Object fInputElement
;
140 private ITimeGraphContentProvider fTimeGraphContentProvider
;
141 private ITimeGraphPresentationProvider fTimeGraphProvider
;
142 private @NonNull ITimeDataProvider fTimeDataProvider
= this;
143 private TimeGraphTooltipHandler fToolTipHandler
;
145 private List
<ITimeGraphSelectionListener
> fSelectionListeners
= new ArrayList
<>();
146 private List
<ITimeGraphTimeListener
> fTimeListeners
= new ArrayList
<>();
147 private List
<ITimeGraphRangeListener
> fRangeListeners
= new ArrayList
<>();
148 private List
<ITimeGraphBookmarkListener
> fBookmarkListeners
= new ArrayList
<>();
150 // Time format, using Epoch reference, Relative time format(default),
152 private TimeFormat fTimeFormat
= TimeFormat
.RELATIVE
;
153 // Clock frequency to use for Cycles time format
154 private long fClockFrequency
= DEFAULT_FREQUENCY
;
155 private int fBorderWidth
= 0;
156 private int fTimeScaleHeight
= DEFAULT_HEIGHT
;
158 private Action fResetScaleAction
;
159 private Action fShowLegendAction
;
160 private Action fNextEventAction
;
161 private Action fPrevEventAction
;
162 private Action fNextItemAction
;
163 private Action fPreviousItemAction
;
164 private Action fZoomInAction
;
165 private Action fZoomOutAction
;
166 private Action fHideArrowsAction
;
167 private Action fFollowArrowFwdAction
;
168 private Action fFollowArrowBwdAction
;
169 private ShowFilterDialogAction fShowFilterDialogAction
;
170 private Action fToggleBookmarkAction
;
171 private Action fNextMarkerAction
;
172 private Action fPreviousMarkerAction
;
173 private MenuManager fMarkersMenu
;
175 /** The list of bookmarks */
176 private final List
<IMarkerEvent
> fBookmarks
= new ArrayList
<>();
178 /** The list of marker categories */
179 private final List
<String
> fMarkerCategories
= new ArrayList
<>();
181 /** The set of hidden marker categories */
182 private final Set
<String
> fHiddenMarkerCategories
= new HashSet
<>();
184 /** The set of skipped marker categories */
185 private final Set
<String
> fSkippedMarkerCategories
= new HashSet
<>();
187 /** The list of markers */
188 private final List
<IMarkerEvent
> fMarkers
= 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 fDataViewer
= new Composite(parent
, style
) {
461 public void redraw() {
462 fTimeScaleCtrl
.redraw();
463 fTimeGraphCtrl
.redraw();
464 fMarkerAxisCtrl
.redraw();
468 fDataViewer
.addDisposeListener(new DisposeListener() {
470 public void widgetDisposed(DisposeEvent e
) {
471 if (fMarkersMenu
!= null) {
472 fMarkersMenu
.dispose();
476 GridLayout gl
= new GridLayout(2, false);
477 gl
.marginHeight
= fBorderWidth
;
479 gl
.verticalSpacing
= 0;
480 gl
.horizontalSpacing
= 0;
481 fDataViewer
.setLayout(gl
);
483 fTimeAlignedComposite
= new Composite(fDataViewer
, style
) {
485 public void redraw() {
486 fDataViewer
.redraw();
490 GridLayout gl2
= new GridLayout(1, false);
491 gl2
.marginHeight
= fBorderWidth
;
493 gl2
.verticalSpacing
= 0;
494 gl2
.horizontalSpacing
= 0;
495 fTimeAlignedComposite
.setLayout(gl2
);
496 fTimeAlignedComposite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
498 fTimeScaleCtrl
= new TimeGraphScale(fTimeAlignedComposite
, fColorScheme
);
499 fTimeScaleCtrl
.setTimeProvider(fTimeDataProvider
);
500 fTimeScaleCtrl
.setLayoutData(new GridData(SWT
.FILL
, SWT
.DEFAULT
, true, false));
501 fTimeScaleCtrl
.setHeight(fTimeScaleHeight
);
502 fTimeScaleCtrl
.addMouseWheelListener(new MouseWheelListener() {
504 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
) {
524 adjustVerticalScrollBar();
527 fTimeGraphCtrl
.addKeyListener(new KeyAdapter() {
529 public void keyPressed(KeyEvent e
) {
530 if ((e
.character
== '+' || e
.character
== '=') && ((e
.stateMask
& SWT
.CTRL
) == 0)) {
532 } else if (e
.character
== '-' && ((e
.stateMask
& SWT
.CTRL
) == 0)) {
534 } else if (e
.keyCode
== '.') {
535 boolean extend
= (e
.stateMask
& SWT
.SHIFT
) != 0;
537 extendToNextMarker();
541 } else if (e
.keyCode
== ',') {
542 boolean extend
= (e
.stateMask
& SWT
.SHIFT
) != 0;
544 extendToPrevMarker();
549 adjustVerticalScrollBar();
553 fMarkerAxisCtrl
= createTimeGraphMarkerAxis(fTimeAlignedComposite
, fColorScheme
, this);
554 fMarkerAxisCtrl
.setLayoutData(new GridData(SWT
.FILL
, SWT
.DEFAULT
, true, false));
555 fMarkerAxisCtrl
.addMarkerAxisListener(this);
556 fMarkerAxisCtrl
.addMouseWheelListener(new MouseWheelListener() {
558 public void mouseScrolled(MouseEvent e
) {
562 fTimeGraphCtrl
.zoom(e
.count
> 0);
566 fVerticalScrollBar
= new Slider(fDataViewer
, SWT
.VERTICAL
| SWT
.NO_FOCUS
);
567 fVerticalScrollBar
.setLayoutData(new GridData(SWT
.DEFAULT
, SWT
.FILL
, false, true, 1, 1));
568 fVerticalScrollBar
.addSelectionListener(new SelectionAdapter() {
570 public void widgetSelected(SelectionEvent e
) {
571 setTopIndex(fVerticalScrollBar
.getSelection());
575 fHorizontalScrollBar
= new Slider(fDataViewer
, SWT
.HORIZONTAL
| SWT
.NO_FOCUS
);
576 fHorizontalScrollBar
.setLayoutData(new GridData(SWT
.FILL
, SWT
.DEFAULT
, true, false));
577 fHorizontalScrollBar
.addListener(SWT
.MouseWheel
, new Listener() {
579 public void handleEvent(Event event
) {
580 // don't handle the immediately following SWT.Selection event
582 if (event
.count
== 0) {
585 if ((event
.stateMask
& SWT
.MODIFIER_MASK
) == SWT
.CTRL
) {
586 getTimeGraphControl().zoom(event
.count
> 0);
588 getTimeGraphControl().horizontalScroll(event
.count
> 0);
592 fHorizontalScrollBar
.addListener(SWT
.Selection
, new Listener() {
594 public void handleEvent(Event event
) {
595 int start
= fHorizontalScrollBar
.getSelection();
596 long time0
= getTime0();
597 long time1
= getTime1();
598 long timeMin
= getMinTime();
599 long timeMax
= getMaxTime();
600 long delta
= timeMax
- timeMin
;
602 long range
= time1
- time0
;
603 time0
= timeMin
+ Math
.round(delta
* ((double) start
/ H_SCROLLBAR_MAX
));
604 time1
= time0
+ range
;
606 setStartFinishTimeNotify(time0
, time1
);
610 Composite filler
= new Composite(fDataViewer
, SWT
.NONE
);
611 GridData gd
= new GridData(SWT
.DEFAULT
, SWT
.DEFAULT
, false, false);
612 gd
.heightHint
= fHorizontalScrollBar
.getSize().y
;
613 filler
.setLayoutData(gd
);
614 filler
.setLayout(new FillLayout());
616 fTimeGraphCtrl
.addControlListener(new ControlAdapter() {
618 public void controlResized(ControlEvent event
) {
623 fDataViewer
.update();
624 adjustHorizontalScrollBar();
625 adjustVerticalScrollBar();
632 public void dispose() {
634 fTimeGraphCtrl
.dispose();
635 fDataViewer
.dispose();
636 fColorScheme
.dispose();
640 * Create a new time graph control.
643 * The parent composite
646 * @return The new TimeGraphControl
648 protected TimeGraphControl
createTimeGraphControl(Composite parent
,
649 TimeGraphColorScheme colors
) {
650 return new TimeGraphControl(parent
, colors
);
654 * Create a new time graph marker axis.
657 * The parent composite object
659 * The color scheme to use
660 * @param timeProvider
661 * The time data provider
662 * @return The new TimeGraphMarkerAxis
665 protected TimeGraphMarkerAxis
createTimeGraphMarkerAxis(Composite parent
,
666 @NonNull TimeGraphColorScheme colorScheme
, @NonNull ITimeDataProvider timeProvider
) {
667 return new TimeGraphMarkerAxis(parent
, colorScheme
, timeProvider
);
671 * Resize the controls
673 public void resizeControls() {
674 Rectangle r
= fDataViewer
.getClientArea();
680 if (fNameWidth
> width
- fMinNameWidth
) {
681 fNameWidth
= width
- fMinNameWidth
;
683 if (fNameWidth
< fMinNameWidth
) {
684 fNameWidth
= fMinNameWidth
;
686 adjustHorizontalScrollBar();
687 adjustVerticalScrollBar();
691 * Recalculate the time bounds based on the time graph entries,
692 * if the user-specified bound is set to SWT.DEFAULT.
695 * The root time graph entries in the model
697 public void setTimeRange(ITimeGraphEntry entries
[]) {
698 fTime0Bound
= (fBeginTime
!= SWT
.DEFAULT ? fBeginTime
: fEndTime
);
699 fTime1Bound
= (fEndTime
!= SWT
.DEFAULT ? fEndTime
: fBeginTime
);
700 if (fBeginTime
!= SWT
.DEFAULT
&& fEndTime
!= SWT
.DEFAULT
) {
703 if (entries
== null || entries
.length
== 0) {
706 if (fTime0Bound
== SWT
.DEFAULT
) {
707 fTime0Bound
= Long
.MAX_VALUE
;
709 if (fTime1Bound
== SWT
.DEFAULT
) {
710 fTime1Bound
= Long
.MIN_VALUE
;
712 for (ITimeGraphEntry entry
: entries
) {
717 private void setTimeRange(ITimeGraphEntry entry
) {
718 if (fBeginTime
== SWT
.DEFAULT
&& entry
.hasTimeEvents() && entry
.getStartTime() != SWT
.DEFAULT
) {
719 fTime0Bound
= Math
.min(entry
.getStartTime(), fTime0Bound
);
721 if (fEndTime
== SWT
.DEFAULT
&& entry
.hasTimeEvents() && entry
.getEndTime() != SWT
.DEFAULT
) {
722 fTime1Bound
= Math
.max(entry
.getEndTime(), fTime1Bound
);
724 if (entry
.hasChildren()) {
725 for (ITimeGraphEntry child
: entry
.getChildren()) {
732 * Set the time bounds to the provided values.
735 * The bounds begin time, or SWT.DEFAULT to use the input bounds
737 * The bounds end time, or SWT.DEFAULT to use the input bounds
739 public void setTimeBounds(long beginTime
, long endTime
) {
740 fBeginTime
= beginTime
;
742 fTime0Bound
= (fBeginTime
!= SWT
.DEFAULT ? fBeginTime
: fEndTime
);
743 fTime1Bound
= (fEndTime
!= SWT
.DEFAULT ? fEndTime
: fBeginTime
);
744 if (fTime0Bound
> fTime1Bound
) {
745 // only possible if both are not default
746 fBeginTime
= endTime
;
747 fEndTime
= beginTime
;
748 fTime0Bound
= fBeginTime
;
749 fTime1Bound
= fEndTime
;
751 adjustHorizontalScrollBar();
755 * Recalculate the current time window when bounds have changed.
757 public void setTimeBounds() {
758 if (!fTimeRangeFixed
) {
759 fTime0
= fTime0Bound
;
760 fTime1
= fTime1Bound
;
762 fTime0
= Math
.max(fTime0Bound
, Math
.min(fTime0
, fTime1Bound
));
763 fTime1
= Math
.max(fTime0Bound
, Math
.min(fTime1
, fTime1Bound
));
764 if (fTime1
- fTime0
< fMinTimeInterval
) {
765 fTime1
= Math
.min(fTime1Bound
, fTime0
+ fMinTimeInterval
);
772 private void refreshAllData(ITimeGraphEntry
[] traces
) {
774 if (fSelectionBegin
< fBeginTime
) {
775 fSelectionBegin
= fBeginTime
;
776 } else if (fSelectionBegin
> fEndTime
) {
777 fSelectionBegin
= fEndTime
;
779 if (fSelectionEnd
< fBeginTime
) {
780 fSelectionEnd
= fBeginTime
;
781 } else if (fSelectionEnd
> fEndTime
) {
782 fSelectionEnd
= fEndTime
;
784 fTimeGraphCtrl
.refreshData(traces
);
785 fTimeScaleCtrl
.redraw();
786 fMarkerAxisCtrl
.redraw();
787 updateMarkerActions();
788 adjustVerticalScrollBar();
792 * Callback for when this view is focused
794 public void setFocus() {
795 if (null != fTimeGraphCtrl
) {
796 fTimeGraphCtrl
.setFocus();
801 * Get the current focus status of this view.
803 * @return If the view is currently focused, or not
805 public boolean isInFocus() {
806 return fTimeGraphCtrl
.isInFocus();
810 * Get the view's current selection
812 * @return The entry that is selected
814 public ITimeGraphEntry
getSelection() {
815 return fTimeGraphCtrl
.getSelectedTrace();
819 * Get the index of the current selection
823 public int getSelectionIndex() {
824 return fTimeGraphCtrl
.getSelectedIndex();
828 public long getTime0() {
833 public long getTime1() {
838 public long getMinTimeInterval() {
839 return fMinTimeInterval
;
843 public int getNameSpace() {
848 public void setNameSpace(int width
) {
850 int w
= fTimeGraphCtrl
.getClientArea().width
;
851 if (fNameWidth
> w
- MIN_NAME_WIDTH
) {
852 fNameWidth
= w
- MIN_NAME_WIDTH
;
854 if (fNameWidth
< MIN_NAME_WIDTH
) {
855 fNameWidth
= MIN_NAME_WIDTH
;
857 fTimeGraphCtrl
.redraw();
858 fTimeScaleCtrl
.redraw();
859 fMarkerAxisCtrl
.redraw();
860 /* force update the controls to keep them aligned */
861 fTimeScaleCtrl
.update();
862 fMarkerAxisCtrl
.update();
863 fTimeGraphCtrl
.update();
867 public int getTimeSpace() {
868 int w
= fTimeGraphCtrl
.getClientArea().width
;
869 return w
- fNameWidth
;
873 public long getBeginTime() {
878 public long getEndTime() {
883 public long getMaxTime() {
888 public long getMinTime() {
893 public long getSelectionBegin() {
894 return fSelectionBegin
;
898 public long getSelectionEnd() {
899 return fSelectionEnd
;
903 public void setStartFinishTimeNotify(long time0
, long time1
) {
904 setStartFinishTimeInt(time0
, time1
);
905 notifyRangeListeners();
909 public void notifyStartFinishTime() {
910 notifyRangeListeners();
914 public void setStartFinishTime(long time0
, long time1
) {
915 /* if there is a pending time range, ignore this one */
916 if (fListenerNotifier
!= null && fListenerNotifier
.hasTimeRangeUpdated()) {
919 setStartFinishTimeInt(time0
, time1
);
920 updateExtSynchValues();
923 private void setStartFinishTimeInt(long time0
, long time1
) {
925 if (fTime0
< fTime0Bound
) {
926 fTime0
= fTime0Bound
;
928 if (fTime0
> fTime1Bound
) {
929 fTime0
= fTime1Bound
;
932 if (fTime1
< fTime0Bound
) {
933 fTime1
= fTime0Bound
;
935 if (fTime1
> fTime1Bound
) {
936 fTime1
= fTime1Bound
;
938 if (fTime1
- fTime0
< fMinTimeInterval
) {
939 fTime1
= Math
.min(fTime1Bound
, fTime0
+ fMinTimeInterval
);
941 fTimeRangeFixed
= true;
942 adjustHorizontalScrollBar();
943 fTimeGraphCtrl
.redraw();
944 fTimeScaleCtrl
.redraw();
945 fMarkerAxisCtrl
.redraw();
946 /* force update the controls to keep them aligned */
947 fTimeScaleCtrl
.update();
948 fMarkerAxisCtrl
.update();
949 fTimeGraphCtrl
.update();
953 public void resetStartFinishTime() {
954 setStartFinishTimeNotify(fTime0Bound
, fTime1Bound
);
955 fTimeRangeFixed
= false;
959 public void setSelectedTimeNotify(long time
, boolean ensureVisible
) {
960 setSelectedTimeInt(time
, ensureVisible
, true);
964 public void setSelectedTime(long time
, boolean ensureVisible
) {
965 /* if there is a pending time selection, ignore this one */
966 if (fListenerNotifier
!= null && fListenerNotifier
.hasTimeSelected()) {
969 setSelectedTimeInt(time
, ensureVisible
, false);
972 private void setSelectedTimeInt(long time
, boolean ensureVisible
, boolean doNotify
) {
973 setSelectionRangeInt(time
, time
, ensureVisible
, doNotify
);
980 public void setSelectionRangeNotify(long beginTime
, long endTime
, boolean ensureVisible
) {
981 setSelectionRangeInt(beginTime
, endTime
, ensureVisible
, true);
988 public void setSelectionRange(long beginTime
, long endTime
, boolean ensureVisible
) {
989 /* if there is a pending time selection, ignore this one */
990 if (fListenerNotifier
!= null && fListenerNotifier
.hasTimeSelected()) {
993 setSelectionRangeInt(beginTime
, endTime
, ensureVisible
, false);
996 private void setSelectionRangeInt(long beginTime
, long endTime
, boolean ensureVisible
, boolean doNotify
) {
999 long selectionBegin
= fSelectionBegin
;
1000 long selectionEnd
= fSelectionEnd
;
1001 fSelectionBegin
= Math
.max(fTime0Bound
, Math
.min(fTime1Bound
, beginTime
));
1002 fSelectionEnd
= Math
.max(fTime0Bound
, Math
.min(fTime1Bound
, endTime
));
1003 boolean changed
= (selectionBegin
!= fSelectionBegin
|| selectionEnd
!= fSelectionEnd
);
1005 if (ensureVisible
) {
1006 ensureVisible(selectionBegin
!= fSelectionBegin ? fSelectionBegin
: fSelectionEnd
);
1009 fTimeGraphCtrl
.redraw();
1010 fTimeScaleCtrl
.redraw();
1011 fMarkerAxisCtrl
.redraw();
1012 updateMarkerActions();
1014 if ((time0
!= fTime0
) || (time1
!= fTime1
)) {
1015 notifyRangeListeners();
1018 if (doNotify
&& changed
) {
1019 notifyTimeListeners();
1023 private void ensureVisible(long time
) {
1024 long timeMid
= (fTime1
- fTime0
) / 2;
1025 if (time
< fTime0
) {
1026 long dt
= fTime0
- time
+ timeMid
;
1029 } else if (time
> fTime1
) {
1030 long dt
= time
- fTime1
+ timeMid
;
1034 if (fTime0
< fTime0Bound
) {
1035 fTime1
= Math
.min(fTime1Bound
, fTime1
+ (fTime0Bound
- fTime0
));
1036 fTime0
= fTime0Bound
;
1037 } else if (fTime1
> fTime1Bound
) {
1038 fTime0
= Math
.max(fTime0Bound
, fTime0
- (fTime1
- fTime1Bound
));
1039 fTime1
= fTime1Bound
;
1041 if (fTime1
- fTime0
< fMinTimeInterval
) {
1042 fTime1
= Math
.min(fTime1Bound
, fTime0
+ fMinTimeInterval
);
1044 adjustHorizontalScrollBar();
1048 public void widgetDefaultSelected(SelectionEvent e
) {
1049 if (fSelectedEntry
!= getSelection()) {
1050 fSelectedEntry
= getSelection();
1051 notifySelectionListeners();
1056 public void widgetSelected(SelectionEvent e
) {
1057 if (fSelectedEntry
!= getSelection()) {
1058 fSelectedEntry
= getSelection();
1059 notifySelectionListeners();
1064 * Callback for when the next event is selected
1067 * true to extend selection range, false for single selection
1070 public void selectNextEvent(boolean extend
) {
1071 fTimeGraphCtrl
.selectNextEvent(extend
);
1072 adjustVerticalScrollBar();
1076 * Callback for when the previous event is selected
1079 * true to extend selection range, false for single selection
1082 public void selectPrevEvent(boolean extend
) {
1083 fTimeGraphCtrl
.selectPrevEvent(extend
);
1084 adjustVerticalScrollBar();
1088 * Callback for when the next item is selected
1090 public void selectNextItem() {
1091 fTimeGraphCtrl
.selectNextTrace();
1092 adjustVerticalScrollBar();
1096 * Callback for when the previous item is selected
1098 public void selectPrevItem() {
1099 fTimeGraphCtrl
.selectPrevTrace();
1100 adjustVerticalScrollBar();
1104 * Callback for the show legend action
1106 public void showLegend() {
1107 if (fDataViewer
== null || fDataViewer
.isDisposed()) {
1111 TimeGraphLegend
.open(fDataViewer
.getShell(), fTimeGraphProvider
);
1115 * Callback for the Zoom In action
1117 public void zoomIn() {
1118 fTimeGraphCtrl
.zoomIn();
1122 * Callback for the Zoom Out action
1124 public void zoomOut() {
1125 fTimeGraphCtrl
.zoomOut();
1128 private String
getPreferenceString(String string
) {
1129 return getViewTypeStr() + "." + string
; //$NON-NLS-1$
1133 * Add a selection listener
1136 * The listener to add
1138 public void addSelectionListener(ITimeGraphSelectionListener listener
) {
1139 fSelectionListeners
.add(listener
);
1143 * Remove a selection listener
1146 * The listener to remove
1148 public void removeSelectionListener(ITimeGraphSelectionListener listener
) {
1149 fSelectionListeners
.remove(listener
);
1152 private void notifySelectionListeners() {
1153 if (fListenerNotifier
== null) {
1154 fListenerNotifier
= new ListenerNotifier();
1155 fListenerNotifier
.start();
1157 fListenerNotifier
.selectionChanged();
1160 private void fireSelectionChanged(ITimeGraphEntry selection
) {
1161 TimeGraphSelectionEvent event
= new TimeGraphSelectionEvent(this, selection
);
1163 for (ITimeGraphSelectionListener listener
: fSelectionListeners
) {
1164 listener
.selectionChanged(event
);
1169 * Add a time listener
1172 * The listener to add
1174 public void addTimeListener(ITimeGraphTimeListener listener
) {
1175 fTimeListeners
.add(listener
);
1179 * Remove a time listener
1182 * The listener to remove
1184 public void removeTimeListener(ITimeGraphTimeListener listener
) {
1185 fTimeListeners
.remove(listener
);
1188 private void notifyTimeListeners() {
1189 if (fListenerNotifier
== null) {
1190 fListenerNotifier
= new ListenerNotifier();
1191 fListenerNotifier
.start();
1193 fListenerNotifier
.timeSelected();
1196 private void fireTimeSelected(long startTime
, long endTime
) {
1197 TimeGraphTimeEvent event
= new TimeGraphTimeEvent(this, startTime
, endTime
);
1199 for (ITimeGraphTimeListener listener
: fTimeListeners
) {
1200 listener
.timeSelected(event
);
1205 * Add a range listener
1208 * The listener to add
1210 public void addRangeListener(ITimeGraphRangeListener listener
) {
1211 fRangeListeners
.add(listener
);
1215 * Remove a range listener
1218 * The listener to remove
1220 public void removeRangeListener(ITimeGraphRangeListener listener
) {
1221 fRangeListeners
.remove(listener
);
1224 private void notifyRangeListeners() {
1225 if (fListenerNotifier
== null) {
1226 fListenerNotifier
= new ListenerNotifier();
1227 fListenerNotifier
.start();
1229 fListenerNotifier
.timeRangeUpdated();
1232 private void fireTimeRangeUpdated(long startTime
, long endTime
) {
1233 // Check if the time has actually changed from last notification
1234 if (startTime
!= fTime0ExtSynch
|| endTime
!= fTime1ExtSynch
) {
1235 // Notify Time Scale Selection Listeners
1236 TimeGraphRangeUpdateEvent event
= new TimeGraphRangeUpdateEvent(this, startTime
, endTime
);
1238 for (ITimeGraphRangeListener listener
: fRangeListeners
) {
1239 listener
.timeRangeUpdated(event
);
1242 // update external synch values
1243 updateExtSynchValues();
1248 * Add a bookmark listener
1251 * The listener to add
1254 public void addBookmarkListener(ITimeGraphBookmarkListener listener
) {
1255 fBookmarkListeners
.add(listener
);
1259 * Remove a bookmark listener
1262 * The listener to remove
1265 public void removeBookmarkListener(ITimeGraphBookmarkListener listener
) {
1266 fBookmarkListeners
.remove(listener
);
1269 private void fireBookmarkAdded(IMarkerEvent bookmark
) {
1270 TimeGraphBookmarkEvent event
= new TimeGraphBookmarkEvent(this, bookmark
);
1272 for (ITimeGraphBookmarkListener listener
: fBookmarkListeners
) {
1273 listener
.bookmarkAdded(event
);
1277 private void fireBookmarkRemoved(IMarkerEvent bookmark
) {
1278 TimeGraphBookmarkEvent event
= new TimeGraphBookmarkEvent(this, bookmark
);
1280 for (ITimeGraphBookmarkListener listener
: fBookmarkListeners
) {
1281 listener
.bookmarkRemoved(event
);
1286 * Set the bookmarks list.
1289 * The bookmarks list, or null
1292 public void setBookmarks(List
<IMarkerEvent
> bookmarks
) {
1294 if (bookmarks
!= null) {
1295 fBookmarks
.addAll(bookmarks
);
1298 updateMarkerActions();
1302 * Get the bookmarks list.
1304 * @return The bookmarks list
1307 public List
<IMarkerEvent
> getBookmarks() {
1308 return Collections
.unmodifiableList(fBookmarks
);
1312 * Set the list of marker categories.
1315 * The list of marker categories, or null
1318 public void setMarkerCategories(List
<String
> categories
) {
1319 fMarkerCategories
.clear();
1320 if (categories
!= null) {
1321 fMarkerCategories
.addAll(categories
);
1323 fMarkerCategories
.add(IMarkerEvent
.BOOKMARKS
);
1324 fMarkerAxisCtrl
.setMarkerCategories(fMarkerCategories
);
1331 public void setMarkerCategoryVisible(String category
, boolean visible
) {
1332 boolean changed
= false;
1334 changed
= fHiddenMarkerCategories
.remove(category
);
1336 changed
= fHiddenMarkerCategories
.add(category
);
1340 updateMarkerActions();
1341 getControl().redraw();
1346 * Set the markers list.
1349 * The markers list, or null
1352 public void setMarkers(List
<IMarkerEvent
> markers
) {
1354 if (markers
!= null) {
1355 fMarkers
.addAll(markers
);
1358 updateMarkerActions();
1362 * Get the markers list.
1364 * @return The markers list, or null
1367 public List
<IMarkerEvent
> getMarkers() {
1368 return Collections
.unmodifiableList(fMarkers
);
1372 * Callback to set a selected event in the view
1375 * The event that was selected
1377 * The source of this selection event
1379 public void setSelectedEvent(ITimeEvent event
, Object source
) {
1380 if (event
== null || source
== this) {
1383 fSelectedEntry
= event
.getEntry();
1384 fTimeGraphCtrl
.selectItem(fSelectedEntry
, false);
1386 setSelectedTimeInt(event
.getTime(), true, true);
1387 adjustVerticalScrollBar();
1391 * Set the seeked time of a trace
1394 * The trace that was seeked
1398 * The source of this seek event
1400 public void setSelectedTraceTime(ITimeGraphEntry trace
, long time
, Object source
) {
1401 if (trace
== null || source
== this) {
1404 fSelectedEntry
= trace
;
1405 fTimeGraphCtrl
.selectItem(trace
, false);
1407 setSelectedTimeInt(time
, true, true);
1411 * Callback for a trace selection
1414 * The trace that was selected
1416 public void setSelection(ITimeGraphEntry trace
) {
1417 /* if there is a pending selection, ignore this one */
1418 if (fListenerNotifier
!= null && fListenerNotifier
.hasSelectionChanged()) {
1421 fSelectedEntry
= trace
;
1422 fTimeGraphCtrl
.selectItem(trace
, false);
1423 adjustVerticalScrollBar();
1427 * Callback for a time window selection
1430 * Start time of the range
1432 * End time of the range
1434 * Source of the event
1436 public void setSelectVisTimeWindow(long time0
, long time1
, Object source
) {
1437 if (source
== this) {
1441 setStartFinishTimeInt(time0
, time1
);
1443 // update notification time values since we are now in synch with the
1444 // external application
1445 updateExtSynchValues();
1449 * update the cache values used to identify the need to send a time window
1450 * update to external registered listeners
1452 private void updateExtSynchValues() {
1453 // last time notification cache
1454 fTime0ExtSynch
= fTime0
;
1455 fTime1ExtSynch
= fTime1
;
1459 public TimeFormat
getTimeFormat() {
1465 * the {@link TimeFormat} used to display timestamps
1467 public void setTimeFormat(TimeFormat tf
) {
1468 this.fTimeFormat
= tf
;
1469 if (tf
== TimeFormat
.CYCLES
) {
1470 fTimeDataProvider
= new TimeDataProviderCyclesConverter(this, fClockFrequency
);
1472 fTimeDataProvider
= this;
1474 fTimeScaleCtrl
.setTimeProvider(fTimeDataProvider
);
1475 if (fToolTipHandler
!= null) {
1476 fToolTipHandler
.setTimeProvider(fTimeDataProvider
);
1481 * Sets the clock frequency. Used when the time format is set to CYCLES.
1483 * @param clockFrequency
1484 * the clock frequency in Hz
1486 public void setClockFrequency(long clockFrequency
) {
1487 fClockFrequency
= clockFrequency
;
1488 if (fTimeFormat
== TimeFormat
.CYCLES
) {
1489 fTimeDataProvider
= new TimeDataProviderCyclesConverter(this, fClockFrequency
);
1490 fTimeScaleCtrl
.setTimeProvider(fTimeDataProvider
);
1491 if (fToolTipHandler
!= null) {
1492 fToolTipHandler
.setTimeProvider(fTimeDataProvider
);
1498 * Retrieve the border width
1502 public int getBorderWidth() {
1503 return fBorderWidth
;
1507 * Set the border width
1509 * @param borderWidth
1512 public void setBorderWidth(int borderWidth
) {
1513 if (borderWidth
> -1) {
1514 this.fBorderWidth
= borderWidth
;
1515 GridLayout gl
= (GridLayout
) fDataViewer
.getLayout();
1516 gl
.marginHeight
= borderWidth
;
1521 * Retrieve the height of the header
1523 * @return The height
1525 public int getHeaderHeight() {
1526 return fTimeScaleHeight
;
1530 * Set the height of the header
1532 * @param headerHeight
1535 public void setHeaderHeight(int headerHeight
) {
1536 if (headerHeight
> -1) {
1537 this.fTimeScaleHeight
= headerHeight
;
1538 fTimeScaleCtrl
.setHeight(headerHeight
);
1543 * Retrieve the height of an item row
1545 * @return The height
1547 public int getItemHeight() {
1548 if (fTimeGraphCtrl
!= null) {
1549 return fTimeGraphCtrl
.getItemHeight();
1555 * Set the height of an item row
1560 public void setItemHeight(int rowHeight
) {
1561 if (fTimeGraphCtrl
!= null) {
1562 fTimeGraphCtrl
.setItemHeight(rowHeight
);
1567 * Set the minimum item width
1572 public void setMinimumItemWidth(int width
) {
1573 if (fTimeGraphCtrl
!= null) {
1574 fTimeGraphCtrl
.setMinimumItemWidth(width
);
1579 * Set the width for the name column
1584 public void setNameWidthPref(int width
) {
1585 fNameWidthPref
= width
;
1593 * Retrieve the configure width for the name column
1599 public int getNameWidthPref(int width
) {
1600 return fNameWidthPref
;
1604 * Returns the primary control associated with this viewer.
1606 * @return the SWT control which displays this viewer's content
1608 public Control
getControl() {
1613 * Returns the time graph control associated with this viewer.
1615 * @return the time graph control
1617 public TimeGraphControl
getTimeGraphControl() {
1618 return fTimeGraphCtrl
;
1622 * Returns the time graph scale associated with this viewer.
1624 * @return the time graph scale
1626 public TimeGraphScale
getTimeGraphScale() {
1627 return fTimeScaleCtrl
;
1631 * Returns the composite containing all the controls that are time aligned,
1632 * i.e. TimeGraphScale, TimeGraphControl.
1634 * @return the time based composite
1637 public Composite
getTimeAlignedComposite() {
1638 return fTimeAlignedComposite
;
1642 * Return the x coordinate corresponding to a time
1646 * @return the x coordinate corresponding to the time
1648 public int getXForTime(long time
) {
1649 return fTimeGraphCtrl
.getXForTime(time
);
1653 * Return the time corresponding to an x coordinate
1657 * @return the time corresponding to the x coordinate
1659 public long getTimeAtX(int x
) {
1660 return fTimeGraphCtrl
.getTimeAtX(x
);
1664 * Get the selection provider
1666 * @return the selection provider
1668 public ISelectionProvider
getSelectionProvider() {
1669 return fTimeGraphCtrl
;
1673 * Wait for the cursor
1676 * Wait indefinitely?
1678 public void waitCursor(boolean waitInd
) {
1679 fTimeGraphCtrl
.waitCursor(waitInd
);
1683 * Get the horizontal scroll bar object
1685 * @return The scroll bar
1687 public Slider
getHorizontalBar() {
1688 return fHorizontalScrollBar
;
1692 * Get the vertical scroll bar object
1694 * @return The scroll bar
1696 public Slider
getVerticalBar() {
1697 return fVerticalScrollBar
;
1701 * Set the given index as the top one
1704 * The index that will go to the top
1706 public void setTopIndex(int index
) {
1707 fTimeGraphCtrl
.setTopIndex(index
);
1708 adjustVerticalScrollBar();
1712 * Retrieve the current top index
1714 * @return The top index
1716 public int getTopIndex() {
1717 return fTimeGraphCtrl
.getTopIndex();
1721 * Sets the auto-expand level to be used for new entries discovered when
1722 * calling {@link #setInput(Object)} or {@link #refresh()}. The value 0
1723 * means that there is no auto-expand; 1 means that top-level entries are
1724 * expanded, but not their children; 2 means that top-level entries are
1725 * expanded, and their children, but not grand-children; and so on.
1727 * The value {@link #ALL_LEVELS} means that all subtrees should be expanded.
1731 * non-negative level, or <code>ALL_LEVELS</code> to expand all
1732 * levels of the tree
1734 public void setAutoExpandLevel(int level
) {
1735 fTimeGraphCtrl
.setAutoExpandLevel(level
);
1739 * Returns the auto-expand level.
1741 * @return non-negative level, or <code>ALL_LEVELS</code> if all levels of
1742 * the tree are expanded automatically
1743 * @see #setAutoExpandLevel
1745 public int getAutoExpandLevel() {
1746 return fTimeGraphCtrl
.getAutoExpandLevel();
1750 * Get the expanded state of an entry.
1754 * @return true if the entry is expanded, false if collapsed
1757 public boolean getExpandedState(ITimeGraphEntry entry
) {
1758 return fTimeGraphCtrl
.getExpandedState(entry
);
1762 * Set the expanded state of an entry
1765 * The entry to expand/collapse
1767 * True for expanded, false for collapsed
1769 public void setExpandedState(ITimeGraphEntry entry
, boolean expanded
) {
1770 fTimeGraphCtrl
.setExpandedState(entry
, expanded
);
1771 adjustVerticalScrollBar();
1775 * Collapses all nodes of the viewer's tree, starting with the root.
1777 public void collapseAll() {
1778 fTimeGraphCtrl
.collapseAll();
1779 adjustVerticalScrollBar();
1783 * Expands all entries of the viewer's tree, starting with the root.
1785 public void expandAll() {
1786 fTimeGraphCtrl
.expandAll();
1787 adjustVerticalScrollBar();
1791 * Get the number of expanded (visible) time graph entries. This includes
1792 * leafs and does not include filtered-out entries.
1794 * @return The number of expanded (visible) time graph entries
1796 public int getExpandedElementCount() {
1797 return fTimeGraphCtrl
.getExpandedElementCount();
1801 * Get the expanded (visible) time graph entries. This includes leafs and
1802 * does not include filtered-out entries.
1804 * @return The array of expanded (visible) time graph entries
1806 public ITimeGraphEntry
[] getExpandedElements() {
1807 return fTimeGraphCtrl
.getExpandedElements();
1811 * Add a tree listener
1814 * The listener to add
1816 public void addTreeListener(ITimeGraphTreeListener listener
) {
1817 fTimeGraphCtrl
.addTreeListener(listener
);
1821 * Remove a tree listener
1824 * The listener to remove
1826 public void removeTreeListener(ITimeGraphTreeListener listener
) {
1827 fTimeGraphCtrl
.removeTreeListener(listener
);
1831 * Get the reset scale action.
1833 * @return The Action object
1835 public Action
getResetScaleAction() {
1836 if (fResetScaleAction
== null) {
1838 fResetScaleAction
= new Action() {
1841 resetStartFinishTime();
1844 fResetScaleAction
.setText(Messages
.TmfTimeGraphViewer_ResetScaleActionNameText
);
1845 fResetScaleAction
.setToolTipText(Messages
.TmfTimeGraphViewer_ResetScaleActionToolTipText
);
1846 fResetScaleAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_HOME_MENU
));
1848 return fResetScaleAction
;
1852 * Get the show legend action.
1854 * @return The Action object
1856 public Action
getShowLegendAction() {
1857 if (fShowLegendAction
== null) {
1859 fShowLegendAction
= new Action() {
1865 fShowLegendAction
.setText(Messages
.TmfTimeGraphViewer_LegendActionNameText
);
1866 fShowLegendAction
.setToolTipText(Messages
.TmfTimeGraphViewer_LegendActionToolTipText
);
1867 fShowLegendAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_SHOW_LEGEND
));
1870 return fShowLegendAction
;
1874 * Get the the next event action.
1876 * @return The action object
1878 public Action
getNextEventAction() {
1879 if (fNextEventAction
== null) {
1880 fNextEventAction
= new Action() {
1882 public void runWithEvent(Event event
) {
1883 boolean extend
= (event
.stateMask
& SWT
.SHIFT
) != 0;
1884 selectNextEvent(extend
);
1888 fNextEventAction
.setText(Messages
.TmfTimeGraphViewer_NextEventActionNameText
);
1889 fNextEventAction
.setToolTipText(Messages
.TmfTimeGraphViewer_NextEventActionToolTipText
);
1890 fNextEventAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_NEXT_EVENT
));
1893 return fNextEventAction
;
1897 * Get the previous event action.
1899 * @return The Action object
1901 public Action
getPreviousEventAction() {
1902 if (fPrevEventAction
== null) {
1903 fPrevEventAction
= new Action() {
1905 public void runWithEvent(Event event
) {
1906 boolean extend
= (event
.stateMask
& SWT
.SHIFT
) != 0;
1907 selectPrevEvent(extend
);
1911 fPrevEventAction
.setText(Messages
.TmfTimeGraphViewer_PreviousEventActionNameText
);
1912 fPrevEventAction
.setToolTipText(Messages
.TmfTimeGraphViewer_PreviousEventActionToolTipText
);
1913 fPrevEventAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_PREV_EVENT
));
1916 return fPrevEventAction
;
1920 * Get the next item action.
1922 * @return The Action object
1924 public Action
getNextItemAction() {
1925 if (fNextItemAction
== null) {
1927 fNextItemAction
= new Action() {
1933 fNextItemAction
.setText(Messages
.TmfTimeGraphViewer_NextItemActionNameText
);
1934 fNextItemAction
.setToolTipText(Messages
.TmfTimeGraphViewer_NextItemActionToolTipText
);
1935 fNextItemAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_NEXT_ITEM
));
1937 return fNextItemAction
;
1941 * Get the previous item action.
1943 * @return The Action object
1945 public Action
getPreviousItemAction() {
1946 if (fPreviousItemAction
== null) {
1948 fPreviousItemAction
= new Action() {
1954 fPreviousItemAction
.setText(Messages
.TmfTimeGraphViewer_PreviousItemActionNameText
);
1955 fPreviousItemAction
.setToolTipText(Messages
.TmfTimeGraphViewer_PreviousItemActionToolTipText
);
1956 fPreviousItemAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_PREV_ITEM
));
1958 return fPreviousItemAction
;
1962 * Get the zoom in action
1964 * @return The Action object
1966 public Action
getZoomInAction() {
1967 if (fZoomInAction
== null) {
1968 fZoomInAction
= new Action() {
1974 fZoomInAction
.setText(Messages
.TmfTimeGraphViewer_ZoomInActionNameText
);
1975 fZoomInAction
.setToolTipText(Messages
.TmfTimeGraphViewer_ZoomInActionToolTipText
);
1976 fZoomInAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_ZOOM_IN_MENU
));
1978 return fZoomInAction
;
1982 * Get the zoom out action
1984 * @return The Action object
1986 public Action
getZoomOutAction() {
1987 if (fZoomOutAction
== null) {
1988 fZoomOutAction
= new Action() {
1994 fZoomOutAction
.setText(Messages
.TmfTimeGraphViewer_ZoomOutActionNameText
);
1995 fZoomOutAction
.setToolTipText(Messages
.TmfTimeGraphViewer_ZoomOutActionToolTipText
);
1996 fZoomOutAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_ZOOM_OUT_MENU
));
1998 return fZoomOutAction
;
2002 * Get the hide arrows action
2004 * @param dialogSettings
2005 * The dialog settings section where the state should be stored,
2008 * @return The Action object
2010 public Action
getHideArrowsAction(final IDialogSettings dialogSettings
) {
2011 if (fHideArrowsAction
== null) {
2012 fHideArrowsAction
= new Action(Messages
.TmfTimeGraphViewer_HideArrowsActionNameText
, IAction
.AS_CHECK_BOX
) {
2015 boolean hideArrows
= fHideArrowsAction
.isChecked();
2016 fTimeGraphCtrl
.hideArrows(hideArrows
);
2018 if (dialogSettings
!= null) {
2019 dialogSettings
.put(HIDE_ARROWS_KEY
, hideArrows
);
2021 if (fFollowArrowFwdAction
!= null) {
2022 fFollowArrowFwdAction
.setEnabled(!hideArrows
);
2024 if (fFollowArrowBwdAction
!= null) {
2025 fFollowArrowBwdAction
.setEnabled(!hideArrows
);
2029 fHideArrowsAction
.setToolTipText(Messages
.TmfTimeGraphViewer_HideArrowsActionToolTipText
);
2030 fHideArrowsAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_HIDE_ARROWS
));
2031 if (dialogSettings
!= null) {
2032 boolean hideArrows
= dialogSettings
.getBoolean(HIDE_ARROWS_KEY
);
2033 fTimeGraphCtrl
.hideArrows(hideArrows
);
2034 fHideArrowsAction
.setChecked(hideArrows
);
2035 if (fFollowArrowFwdAction
!= null) {
2036 fFollowArrowFwdAction
.setEnabled(!hideArrows
);
2038 if (fFollowArrowBwdAction
!= null) {
2039 fFollowArrowBwdAction
.setEnabled(!hideArrows
);
2043 return fHideArrowsAction
;
2047 * Get the follow arrow forward action.
2049 * @return The Action object
2051 public Action
getFollowArrowFwdAction() {
2052 if (fFollowArrowFwdAction
== null) {
2053 fFollowArrowFwdAction
= new Action() {
2055 public void runWithEvent(Event event
) {
2056 boolean extend
= (event
.stateMask
& SWT
.SHIFT
) != 0;
2057 fTimeGraphCtrl
.followArrowFwd(extend
);
2058 adjustVerticalScrollBar();
2061 fFollowArrowFwdAction
.setText(Messages
.TmfTimeGraphViewer_FollowArrowForwardActionNameText
);
2062 fFollowArrowFwdAction
.setToolTipText(Messages
.TmfTimeGraphViewer_FollowArrowForwardActionToolTipText
);
2063 fFollowArrowFwdAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_FOLLOW_ARROW_FORWARD
));
2064 if (fHideArrowsAction
!= null) {
2065 fFollowArrowFwdAction
.setEnabled(!fHideArrowsAction
.isChecked());
2068 return fFollowArrowFwdAction
;
2072 * Get the follow arrow backward action.
2074 * @return The Action object
2076 public Action
getFollowArrowBwdAction() {
2077 if (fFollowArrowBwdAction
== null) {
2078 fFollowArrowBwdAction
= new Action() {
2080 public void runWithEvent(Event event
) {
2081 boolean extend
= (event
.stateMask
& SWT
.SHIFT
) != 0;
2082 fTimeGraphCtrl
.followArrowBwd(extend
);
2083 adjustVerticalScrollBar();
2086 fFollowArrowBwdAction
.setText(Messages
.TmfTimeGraphViewer_FollowArrowBackwardActionNameText
);
2087 fFollowArrowBwdAction
.setToolTipText(Messages
.TmfTimeGraphViewer_FollowArrowBackwardActionToolTipText
);
2088 fFollowArrowBwdAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_FOLLOW_ARROW_BACKWARD
));
2089 if (fHideArrowsAction
!= null) {
2090 fFollowArrowBwdAction
.setEnabled(!fHideArrowsAction
.isChecked());
2093 return fFollowArrowBwdAction
;
2097 * Get the show filter dialog action.
2099 * @return The Action object
2102 public ShowFilterDialogAction
getShowFilterDialogAction() {
2103 if (fShowFilterDialogAction
== null) {
2104 fShowFilterDialogAction
= new ShowFilterDialogAction(this);
2106 return fShowFilterDialogAction
;
2110 * Get the toggle bookmark action.
2112 * @return The Action object
2115 public Action
getToggleBookmarkAction() {
2116 if (fToggleBookmarkAction
== null) {
2117 fToggleBookmarkAction
= new Action() {
2119 public void runWithEvent(Event event
) {
2120 IMarkerEvent selectedBookmark
= getBookmarkAtSelection();
2121 if (selectedBookmark
== null) {
2122 final long time
= Math
.min(fSelectionBegin
, fSelectionEnd
);
2123 final long duration
= Math
.max(fSelectionBegin
, fSelectionEnd
) - time
;
2124 final AddBookmarkDialog dialog
= new AddBookmarkDialog(PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getShell(), null);
2125 if (dialog
.open() == Window
.OK
) {
2126 final String label
= dialog
.getValue();
2127 final RGBA rgba
= dialog
.getColorValue();
2128 IMarkerEvent bookmark
= new MarkerEvent(null, time
, duration
, IMarkerEvent
.BOOKMARKS
, rgba
, label
, true);
2129 fBookmarks
.add(bookmark
);
2131 updateMarkerActions();
2132 getControl().redraw();
2133 fireBookmarkAdded(bookmark
);
2136 fBookmarks
.remove(selectedBookmark
);
2138 updateMarkerActions();
2139 getControl().redraw();
2140 fireBookmarkRemoved(selectedBookmark
);
2144 fToggleBookmarkAction
.setText(Messages
.TmfTimeGraphViewer_BookmarkActionAddText
);
2145 fToggleBookmarkAction
.setToolTipText(Messages
.TmfTimeGraphViewer_BookmarkActionAddText
);
2146 fToggleBookmarkAction
.setImageDescriptor(ADD_BOOKMARK
);
2148 return fToggleBookmarkAction
;
2152 * Get the next marker action.
2154 * @return The Action object
2157 public Action
getNextMarkerAction() {
2158 if (fNextMarkerAction
== null) {
2159 fNextMarkerAction
= new Action(Messages
.TmfTimeGraphViewer_NextMarkerActionText
, IAction
.AS_DROP_DOWN_MENU
) {
2161 public void runWithEvent(Event event
) {
2162 boolean extend
= (event
.stateMask
& SWT
.SHIFT
) != 0;
2164 extendToNextMarker();
2170 fNextMarkerAction
.setToolTipText(Messages
.TmfTimeGraphViewer_NextMarkerActionText
);
2171 fNextMarkerAction
.setImageDescriptor(NEXT_BOOKMARK
);
2172 fNextMarkerAction
.setMenuCreator(new IMenuCreator () {
2175 public void dispose() {
2183 public Menu
getMenu(Control parent
) {
2187 menu
= new Menu(parent
);
2188 for (String category
: fMarkerCategories
) {
2189 final Action action
= new Action(category
, IAction
.AS_CHECK_BOX
) {
2191 public void runWithEvent(Event event
) {
2193 fSkippedMarkerCategories
.remove(getText());
2195 fSkippedMarkerCategories
.add(getText());
2197 updateMarkerActions();
2200 action
.setEnabled(!fHiddenMarkerCategories
.contains(category
));
2201 action
.setChecked(action
.isEnabled() && !fSkippedMarkerCategories
.contains(category
));
2202 new ActionContributionItem(action
).fill(menu
, -1);
2208 public Menu
getMenu(Menu parent
) {
2213 return fNextMarkerAction
;
2217 * Get the previous marker action.
2219 * @return The Action object
2222 public Action
getPreviousMarkerAction() {
2223 if (fPreviousMarkerAction
== null) {
2224 fPreviousMarkerAction
= new Action() {
2226 public void runWithEvent(Event event
) {
2227 boolean extend
= (event
.stateMask
& SWT
.SHIFT
) != 0;
2229 extendToPrevMarker();
2235 fPreviousMarkerAction
.setText(Messages
.TmfTimeGraphViewer_PreviousMarkerActionText
);
2236 fPreviousMarkerAction
.setToolTipText(Messages
.TmfTimeGraphViewer_PreviousMarkerActionText
);
2237 fPreviousMarkerAction
.setImageDescriptor(PREVIOUS_BOOKMARK
);
2239 return fPreviousMarkerAction
;
2243 * Get the show markers menu.
2245 * @return The menu manager object
2248 public MenuManager
getMarkersMenu() {
2249 if (fMarkersMenu
== null) {
2250 fMarkersMenu
= new MenuManager(Messages
.TmfTimeGraphViewer_ShowMarkersMenuText
);
2251 fMarkersMenu
.setRemoveAllWhenShown(true);
2252 fMarkersMenu
.addMenuListener(new IMenuListener() {
2254 public void menuAboutToShow(IMenuManager manager
) {
2255 for (String category
: fMarkerCategories
) {
2256 final Action action
= new Action(category
, IAction
.AS_CHECK_BOX
) {
2258 public void runWithEvent(Event event
) {
2259 setMarkerCategoryVisible(getText(), isChecked());
2262 action
.setChecked(!fHiddenMarkerCategories
.contains(category
));
2263 manager
.add(action
);
2268 return fMarkersMenu
;
2272 * Select the next marker that begins at or after the current selection
2273 * begin time. Markers that begin at the same time are ordered by end time.
2275 private void selectNextMarker() {
2276 List
<IMarkerEvent
> markers
= getTimeGraphControl().getMarkers();
2277 if (markers
== null) {
2280 for (IMarkerEvent marker
: markers
) {
2281 final long time
= Math
.min(fSelectionBegin
, fSelectionEnd
);
2282 final long duration
= Math
.max(fSelectionBegin
, fSelectionEnd
) - time
;
2283 if ((marker
.getTime() > time
||
2284 (marker
.getTime() == time
&& marker
.getDuration() > duration
))
2285 && !fSkippedMarkerCategories
.contains(marker
.getCategory())) {
2286 setSelectionRangeNotify(marker
.getTime(), marker
.getTime() + marker
.getDuration(), true);
2287 fTimeGraphCtrl
.updateStatusLine();
2294 * Select the previous marker that begins at or before the current selection
2295 * begin time. Markers that begin at the same time are ordered by end time.
2297 private void selectPrevMarker() {
2298 List
<IMarkerEvent
> markers
= getTimeGraphControl().getMarkers();
2299 if (markers
== null) {
2302 final long time
= Math
.min(fSelectionBegin
, fSelectionEnd
);
2303 final long duration
= Math
.max(fSelectionBegin
, fSelectionEnd
) - time
;
2304 for (int i
= markers
.size() - 1; i
>= 0; i
--) {
2305 IMarkerEvent marker
= markers
.get(i
);
2306 if ((marker
.getTime() < time
||
2307 (marker
.getTime() == time
&& marker
.getDuration() < duration
))
2308 && !fSkippedMarkerCategories
.contains(marker
.getCategory())) {
2309 setSelectionRangeNotify(marker
.getTime(), marker
.getTime() + marker
.getDuration(), true);
2310 fTimeGraphCtrl
.updateStatusLine();
2317 * Extend the selection to the closest next marker end time.
2319 private void extendToNextMarker() {
2320 List
<IMarkerEvent
> markers
= getTimeGraphControl().getMarkers();
2321 if (markers
== null) {
2324 IMarkerEvent nextMarker
= null;
2325 for (IMarkerEvent marker
: markers
) {
2326 if (marker
.getTime() + marker
.getDuration() > fSelectionEnd
2327 && !fSkippedMarkerCategories
.contains(marker
.getCategory())
2328 && (nextMarker
== null || marker
.getTime() + marker
.getDuration() < nextMarker
.getTime() + nextMarker
.getDuration())) {
2329 nextMarker
= marker
;
2332 if (nextMarker
!= null) {
2333 setSelectionRangeNotify(fSelectionBegin
, nextMarker
.getTime() + nextMarker
.getDuration(), true);
2334 fTimeGraphCtrl
.updateStatusLine();
2339 * Extend the selection to the closest previous marker start time.
2341 private void extendToPrevMarker() {
2342 List
<IMarkerEvent
> markers
= getTimeGraphControl().getMarkers();
2343 if (markers
== null) {
2346 for (int i
= markers
.size() - 1; i
>= 0; i
--) {
2347 IMarkerEvent marker
= markers
.get(i
);
2348 if (marker
.getTime() < fSelectionEnd
2349 && !fSkippedMarkerCategories
.contains(marker
.getCategory())) {
2350 setSelectionRangeNotify(fSelectionBegin
, marker
.getTime(), true);
2351 fTimeGraphCtrl
.updateStatusLine();
2357 private IMarkerEvent
getBookmarkAtSelection() {
2358 final long time
= Math
.min(fSelectionBegin
, fSelectionEnd
);
2359 final long duration
= Math
.max(fSelectionBegin
, fSelectionEnd
) - time
;
2360 for (IMarkerEvent bookmark
: fBookmarks
) {
2361 if (bookmark
.getTime() == time
&& bookmark
.getDuration() == duration
) {
2368 private void updateMarkerActions() {
2369 boolean enabled
= fTime0Bound
!= SWT
.DEFAULT
|| fTime1Bound
!= SWT
.DEFAULT
;
2370 if (fToggleBookmarkAction
!= null) {
2371 if (getBookmarkAtSelection() != null) {
2372 fToggleBookmarkAction
.setText(Messages
.TmfTimeGraphViewer_BookmarkActionRemoveText
);
2373 fToggleBookmarkAction
.setToolTipText(Messages
.TmfTimeGraphViewer_BookmarkActionRemoveText
);
2374 fToggleBookmarkAction
.setImageDescriptor(REMOVE_BOOKMARK
);
2376 fToggleBookmarkAction
.setText(Messages
.TmfTimeGraphViewer_BookmarkActionAddText
);
2377 fToggleBookmarkAction
.setToolTipText(Messages
.TmfTimeGraphViewer_BookmarkActionAddText
);
2378 fToggleBookmarkAction
.setImageDescriptor(ADD_BOOKMARK
);
2380 fToggleBookmarkAction
.setEnabled(enabled
);
2382 List
<IMarkerEvent
> markers
= getTimeGraphControl().getMarkers();
2383 if (markers
== null) {
2384 markers
= Collections
.emptyList();
2386 if (fPreviousMarkerAction
!= null) {
2387 fPreviousMarkerAction
.setEnabled(enabled
&& !markers
.isEmpty());
2389 if (fNextMarkerAction
!= null) {
2390 fNextMarkerAction
.setEnabled(enabled
&& !markers
.isEmpty());
2394 private void updateMarkerList() {
2395 List
<IMarkerEvent
> markers
= new ArrayList
<>();
2396 for (IMarkerEvent marker
: fMarkers
) {
2397 if (!fHiddenMarkerCategories
.contains(marker
.getCategory())) {
2398 markers
.add(marker
);
2401 if (!fHiddenMarkerCategories
.contains(IMarkerEvent
.BOOKMARKS
)) {
2402 markers
.addAll(fBookmarks
);
2404 Collections
.sort(markers
, new MarkerComparator());
2405 fTimeGraphCtrl
.setMarkers(markers
);
2406 fMarkerAxisCtrl
.setMarkers(markers
);
2409 private void adjustHorizontalScrollBar() {
2410 long time0
= getTime0();
2411 long time1
= getTime1();
2412 long timeMin
= getMinTime();
2413 long timeMax
= getMaxTime();
2414 long delta
= timeMax
- timeMin
;
2416 int thumb
= H_SCROLLBAR_MAX
;
2418 // Thumb size (page size)
2419 thumb
= Math
.max(1, (int) (H_SCROLLBAR_MAX
* ((double) (time1
- time0
) / delta
)));
2420 // At the beginning of visible window
2421 timePos
= (int) (H_SCROLLBAR_MAX
* ((double) (time0
- timeMin
) / delta
));
2423 fHorizontalScrollBar
.setValues(timePos
, 0, H_SCROLLBAR_MAX
, thumb
, Math
.max(1, thumb
/ 2), Math
.max(2, thumb
));
2426 private void adjustVerticalScrollBar() {
2427 int topIndex
= fTimeGraphCtrl
.getTopIndex();
2428 int countPerPage
= fTimeGraphCtrl
.countPerPage();
2429 int expandedElementCount
= fTimeGraphCtrl
.getExpandedElementCount();
2430 if (topIndex
+ countPerPage
> expandedElementCount
) {
2431 fTimeGraphCtrl
.setTopIndex(Math
.max(0, expandedElementCount
- countPerPage
));
2434 int selection
= fTimeGraphCtrl
.getTopIndex();
2436 int max
= Math
.max(1, expandedElementCount
- 1);
2437 int thumb
= Math
.min(max
, Math
.max(1, countPerPage
- 1));
2439 int pageIncrement
= Math
.max(1, countPerPage
);
2440 fVerticalScrollBar
.setValues(selection
, min
, max
, thumb
, increment
, pageIncrement
);
2445 * a {@link MenuDetectListener}
2446 * @see org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.TimeGraphControl#addTimeGraphEntryMenuListener(org.eclipse.swt.events.MenuDetectListener)
2448 public void addTimeGraphEntryMenuListener(MenuDetectListener listener
) {
2449 fTimeGraphCtrl
.addTimeGraphEntryMenuListener(listener
);
2454 * a {@link MenuDetectListener}
2455 * @see org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.TimeGraphControl#removeTimeGraphEntryMenuListener(org.eclipse.swt.events.MenuDetectListener)
2457 public void removeTimeGraphEntryMenuListener(MenuDetectListener listener
) {
2458 fTimeGraphCtrl
.removeTimeGraphEntryMenuListener(listener
);
2463 * a {@link MenuDetectListener}
2464 * @see org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.TimeGraphControl#addTimeEventMenuListener(org.eclipse.swt.events.MenuDetectListener)
2466 public void addTimeEventMenuListener(MenuDetectListener listener
) {
2467 fTimeGraphCtrl
.addTimeEventMenuListener(listener
);
2472 * a {@link MenuDetectListener}
2473 * @see org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.TimeGraphControl#removeTimeEventMenuListener(org.eclipse.swt.events.MenuDetectListener)
2475 public void removeTimeEventMenuListener(MenuDetectListener listener
) {
2476 fTimeGraphCtrl
.removeTimeEventMenuListener(listener
);
2481 * The filter object to be attached to the view
2483 public void addFilter(@NonNull ViewerFilter filter
) {
2484 fTimeGraphCtrl
.addFilter(filter
);
2490 * The filter object to be attached to the view
2492 public void removeFilter(@NonNull ViewerFilter filter
) {
2493 fTimeGraphCtrl
.removeFilter(filter
);
2498 * Returns this viewer's filters.
2500 * @return an array of viewer filters
2503 public @NonNull ViewerFilter
[] getFilters() {
2504 return fTimeGraphCtrl
.getFilters();
2508 * Sets the filters, replacing any previous filters, and triggers
2509 * refiltering of the elements.
2512 * an array of viewer filters, or null
2515 public void setFilters(@NonNull ViewerFilter
[] filters
) {
2516 fTimeGraphCtrl
.setFilters(filters
);
2521 * Return the time alignment information
2523 * @return the time alignment information
2525 * @see ITmfTimeAligned
2529 public TmfTimeViewAlignmentInfo
getTimeViewAlignmentInfo() {
2530 return fTimeGraphCtrl
.getTimeViewAlignmentInfo();
2534 * Return the available width for the time-axis.
2536 * @see ITmfTimeAligned
2538 * @param requestedOffset
2539 * the requested offset
2540 * @return the available width for the time-axis
2544 public int getAvailableWidth(int requestedOffset
) {
2545 int totalWidth
= fTimeAlignedComposite
.getSize().x
;
2546 return Math
.min(totalWidth
, Math
.max(0, totalWidth
- requestedOffset
));
2550 * Perform the alignment operation.
2553 * the alignment offset
2555 * the alignment width
2557 * @see ITmfTimeAligned
2561 public void performAlign(int offset
, int width
) {
2562 fTimeGraphCtrl
.performAlign(offset
);
2563 int alignmentWidth
= width
;
2564 int size
= fTimeAlignedComposite
.getSize().x
;
2565 GridLayout layout
= (GridLayout
) fTimeAlignedComposite
.getLayout();
2566 int marginSize
= size
- alignmentWidth
- offset
;
2567 layout
.marginRight
= Math
.max(0, marginSize
);
2568 fTimeAlignedComposite
.layout();