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
) {
505 fTimeGraphCtrl
.zoom(e
.count
> 0);
509 fTimeGraphCtrl
= createTimeGraphControl(fTimeAlignedComposite
, fColorScheme
);
511 fTimeGraphCtrl
.setTimeProvider(this);
512 fTimeGraphCtrl
.setTimeGraphScale(fTimeScaleCtrl
);
513 fTimeGraphCtrl
.addSelectionListener(this);
514 fTimeGraphCtrl
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
515 fTimeGraphCtrl
.addMouseWheelListener(new MouseWheelListener() {
517 public void mouseScrolled(MouseEvent e
) {
518 adjustVerticalScrollBar();
521 fTimeGraphCtrl
.addKeyListener(new KeyAdapter() {
523 public void keyPressed(KeyEvent e
) {
524 if ((e
.character
== '+' || e
.character
== '=') && ((e
.stateMask
& SWT
.CTRL
) == 0)) {
526 } else if (e
.character
== '-' && ((e
.stateMask
& SWT
.CTRL
) == 0)) {
528 } else if (e
.keyCode
== '.') {
529 boolean extend
= (e
.stateMask
& SWT
.SHIFT
) != 0;
531 extendToNextMarker();
535 } else if (e
.keyCode
== ',') {
536 boolean extend
= (e
.stateMask
& SWT
.SHIFT
) != 0;
538 extendToPrevMarker();
543 adjustVerticalScrollBar();
547 fMarkerAxisCtrl
= createTimeGraphMarkerAxis(fTimeAlignedComposite
, fColorScheme
, this);
548 fMarkerAxisCtrl
.setLayoutData(new GridData(SWT
.FILL
, SWT
.DEFAULT
, true, false));
549 fMarkerAxisCtrl
.addMarkerAxisListener(this);
550 fMarkerAxisCtrl
.addMouseWheelListener(new MouseWheelListener() {
552 public void mouseScrolled(MouseEvent e
) {
553 fTimeGraphCtrl
.zoom(e
.count
> 0);
557 fVerticalScrollBar
= new Slider(fDataViewer
, SWT
.VERTICAL
| SWT
.NO_FOCUS
);
558 fVerticalScrollBar
.setLayoutData(new GridData(SWT
.DEFAULT
, SWT
.FILL
, false, true, 1, 1));
559 fVerticalScrollBar
.addSelectionListener(new SelectionAdapter() {
561 public void widgetSelected(SelectionEvent e
) {
562 setTopIndex(fVerticalScrollBar
.getSelection());
566 fHorizontalScrollBar
= new Slider(fDataViewer
, SWT
.HORIZONTAL
| SWT
.NO_FOCUS
);
567 fHorizontalScrollBar
.setLayoutData(new GridData(SWT
.FILL
, SWT
.DEFAULT
, true, false));
568 fHorizontalScrollBar
.addListener(SWT
.MouseWheel
, new Listener() {
570 public void handleEvent(Event event
) {
571 if ((event
.stateMask
& SWT
.MODIFIER_MASK
) == SWT
.CTRL
) {
572 getTimeGraphControl().zoom(event
.count
> 0);
574 getTimeGraphControl().horizontalScroll(event
.count
> 0);
576 // don't handle the immediately following SWT.Selection event
580 fHorizontalScrollBar
.addListener(SWT
.Selection
, new Listener() {
582 public void handleEvent(Event event
) {
583 int start
= fHorizontalScrollBar
.getSelection();
584 long time0
= getTime0();
585 long time1
= getTime1();
586 long timeMin
= getMinTime();
587 long timeMax
= getMaxTime();
588 long delta
= timeMax
- timeMin
;
590 long range
= time1
- time0
;
591 time0
= timeMin
+ Math
.round(delta
* ((double) start
/ H_SCROLLBAR_MAX
));
592 time1
= time0
+ range
;
594 setStartFinishTimeNotify(time0
, time1
);
598 Composite filler
= new Composite(fDataViewer
, SWT
.NONE
);
599 GridData gd
= new GridData(SWT
.DEFAULT
, SWT
.DEFAULT
, false, false);
600 gd
.heightHint
= fHorizontalScrollBar
.getSize().y
;
601 filler
.setLayoutData(gd
);
602 filler
.setLayout(new FillLayout());
604 fTimeGraphCtrl
.addControlListener(new ControlAdapter() {
606 public void controlResized(ControlEvent event
) {
611 fDataViewer
.update();
612 adjustHorizontalScrollBar();
613 adjustVerticalScrollBar();
620 public void dispose() {
622 fTimeGraphCtrl
.dispose();
623 fDataViewer
.dispose();
624 fColorScheme
.dispose();
628 * Create a new time graph control.
631 * The parent composite
634 * @return The new TimeGraphControl
636 protected TimeGraphControl
createTimeGraphControl(Composite parent
,
637 TimeGraphColorScheme colors
) {
638 return new TimeGraphControl(parent
, colors
);
642 * Create a new time graph marker axis.
645 * The parent composite object
647 * The color scheme to use
648 * @param timeProvider
649 * The time data provider
650 * @return The new TimeGraphMarkerAxis
653 protected TimeGraphMarkerAxis
createTimeGraphMarkerAxis(Composite parent
,
654 @NonNull TimeGraphColorScheme colorScheme
, @NonNull ITimeDataProvider timeProvider
) {
655 return new TimeGraphMarkerAxis(parent
, colorScheme
, timeProvider
);
659 * Resize the controls
661 public void resizeControls() {
662 Rectangle r
= fDataViewer
.getClientArea();
668 if (fNameWidth
> width
- fMinNameWidth
) {
669 fNameWidth
= width
- fMinNameWidth
;
671 if (fNameWidth
< fMinNameWidth
) {
672 fNameWidth
= fMinNameWidth
;
674 adjustHorizontalScrollBar();
675 adjustVerticalScrollBar();
679 * Recalculate the time bounds based on the time graph entries,
680 * if the user-specified bound is set to SWT.DEFAULT.
683 * The root time graph entries in the model
685 public void setTimeRange(ITimeGraphEntry entries
[]) {
686 fTime0Bound
= (fBeginTime
!= SWT
.DEFAULT ? fBeginTime
: fEndTime
);
687 fTime1Bound
= (fEndTime
!= SWT
.DEFAULT ? fEndTime
: fBeginTime
);
688 if (fBeginTime
!= SWT
.DEFAULT
&& fEndTime
!= SWT
.DEFAULT
) {
691 if (entries
== null || entries
.length
== 0) {
694 if (fTime0Bound
== SWT
.DEFAULT
) {
695 fTime0Bound
= Long
.MAX_VALUE
;
697 if (fTime1Bound
== SWT
.DEFAULT
) {
698 fTime1Bound
= Long
.MIN_VALUE
;
700 for (ITimeGraphEntry entry
: entries
) {
705 private void setTimeRange(ITimeGraphEntry entry
) {
706 if (fBeginTime
== SWT
.DEFAULT
&& entry
.hasTimeEvents() && entry
.getStartTime() != SWT
.DEFAULT
) {
707 fTime0Bound
= Math
.min(entry
.getStartTime(), fTime0Bound
);
709 if (fEndTime
== SWT
.DEFAULT
&& entry
.hasTimeEvents() && entry
.getEndTime() != SWT
.DEFAULT
) {
710 fTime1Bound
= Math
.max(entry
.getEndTime(), fTime1Bound
);
712 if (entry
.hasChildren()) {
713 for (ITimeGraphEntry child
: entry
.getChildren()) {
720 * Set the time bounds to the provided values.
723 * The bounds begin time, or SWT.DEFAULT to use the input bounds
725 * The bounds end time, or SWT.DEFAULT to use the input bounds
727 public void setTimeBounds(long beginTime
, long endTime
) {
728 fBeginTime
= beginTime
;
730 fTime0Bound
= (fBeginTime
!= SWT
.DEFAULT ? fBeginTime
: fEndTime
);
731 fTime1Bound
= (fEndTime
!= SWT
.DEFAULT ? fEndTime
: fBeginTime
);
732 if (fTime0Bound
> fTime1Bound
) {
733 // only possible if both are not default
734 fBeginTime
= endTime
;
735 fEndTime
= beginTime
;
736 fTime0Bound
= fBeginTime
;
737 fTime1Bound
= fEndTime
;
739 adjustHorizontalScrollBar();
743 * Recalculate the current time window when bounds have changed.
745 public void setTimeBounds() {
746 if (!fTimeRangeFixed
) {
747 fTime0
= fTime0Bound
;
748 fTime1
= fTime1Bound
;
750 fTime0
= Math
.max(fTime0Bound
, Math
.min(fTime0
, fTime1Bound
));
751 fTime1
= Math
.max(fTime0Bound
, Math
.min(fTime1
, fTime1Bound
));
752 if (fTime1
- fTime0
< fMinTimeInterval
) {
753 fTime1
= Math
.min(fTime1Bound
, fTime0
+ fMinTimeInterval
);
760 private void refreshAllData(ITimeGraphEntry
[] traces
) {
762 if (fSelectionBegin
< fBeginTime
) {
763 fSelectionBegin
= fBeginTime
;
764 } else if (fSelectionBegin
> fEndTime
) {
765 fSelectionBegin
= fEndTime
;
767 if (fSelectionEnd
< fBeginTime
) {
768 fSelectionEnd
= fBeginTime
;
769 } else if (fSelectionEnd
> fEndTime
) {
770 fSelectionEnd
= fEndTime
;
772 fTimeGraphCtrl
.refreshData(traces
);
773 fTimeScaleCtrl
.redraw();
774 fMarkerAxisCtrl
.redraw();
775 updateMarkerActions();
776 adjustVerticalScrollBar();
780 * Callback for when this view is focused
782 public void setFocus() {
783 if (null != fTimeGraphCtrl
) {
784 fTimeGraphCtrl
.setFocus();
789 * Get the current focus status of this view.
791 * @return If the view is currently focused, or not
793 public boolean isInFocus() {
794 return fTimeGraphCtrl
.isInFocus();
798 * Get the view's current selection
800 * @return The entry that is selected
802 public ITimeGraphEntry
getSelection() {
803 return fTimeGraphCtrl
.getSelectedTrace();
807 * Get the index of the current selection
811 public int getSelectionIndex() {
812 return fTimeGraphCtrl
.getSelectedIndex();
816 public long getTime0() {
821 public long getTime1() {
826 public long getMinTimeInterval() {
827 return fMinTimeInterval
;
831 public int getNameSpace() {
836 public void setNameSpace(int width
) {
838 int w
= fTimeGraphCtrl
.getClientArea().width
;
839 if (fNameWidth
> w
- MIN_NAME_WIDTH
) {
840 fNameWidth
= w
- MIN_NAME_WIDTH
;
842 if (fNameWidth
< MIN_NAME_WIDTH
) {
843 fNameWidth
= MIN_NAME_WIDTH
;
845 fTimeGraphCtrl
.redraw();
846 fTimeScaleCtrl
.redraw();
847 fMarkerAxisCtrl
.redraw();
848 /* force update the controls to keep them aligned */
849 fTimeScaleCtrl
.update();
850 fMarkerAxisCtrl
.update();
851 fTimeGraphCtrl
.update();
855 public int getTimeSpace() {
856 int w
= fTimeGraphCtrl
.getClientArea().width
;
857 return w
- fNameWidth
;
861 public long getBeginTime() {
866 public long getEndTime() {
871 public long getMaxTime() {
876 public long getMinTime() {
881 public long getSelectionBegin() {
882 return fSelectionBegin
;
886 public long getSelectionEnd() {
887 return fSelectionEnd
;
891 public void setStartFinishTimeNotify(long time0
, long time1
) {
892 setStartFinishTimeInt(time0
, time1
);
893 notifyRangeListeners();
897 public void notifyStartFinishTime() {
898 notifyRangeListeners();
902 public void setStartFinishTime(long time0
, long time1
) {
903 /* if there is a pending time range, ignore this one */
904 if (fListenerNotifier
!= null && fListenerNotifier
.hasTimeRangeUpdated()) {
907 setStartFinishTimeInt(time0
, time1
);
908 updateExtSynchValues();
911 private void setStartFinishTimeInt(long time0
, long time1
) {
913 if (fTime0
< fTime0Bound
) {
914 fTime0
= fTime0Bound
;
916 if (fTime0
> fTime1Bound
) {
917 fTime0
= fTime1Bound
;
920 if (fTime1
< fTime0Bound
) {
921 fTime1
= fTime0Bound
;
923 if (fTime1
> fTime1Bound
) {
924 fTime1
= fTime1Bound
;
926 if (fTime1
- fTime0
< fMinTimeInterval
) {
927 fTime1
= Math
.min(fTime1Bound
, fTime0
+ fMinTimeInterval
);
929 fTimeRangeFixed
= true;
930 adjustHorizontalScrollBar();
931 fTimeGraphCtrl
.redraw();
932 fTimeScaleCtrl
.redraw();
933 fMarkerAxisCtrl
.redraw();
934 /* force update the controls to keep them aligned */
935 fTimeScaleCtrl
.update();
936 fMarkerAxisCtrl
.update();
937 fTimeGraphCtrl
.update();
941 public void resetStartFinishTime() {
942 setStartFinishTimeNotify(fTime0Bound
, fTime1Bound
);
943 fTimeRangeFixed
= false;
947 public void setSelectedTimeNotify(long time
, boolean ensureVisible
) {
948 setSelectedTimeInt(time
, ensureVisible
, true);
952 public void setSelectedTime(long time
, boolean ensureVisible
) {
953 /* if there is a pending time selection, ignore this one */
954 if (fListenerNotifier
!= null && fListenerNotifier
.hasTimeSelected()) {
957 setSelectedTimeInt(time
, ensureVisible
, false);
960 private void setSelectedTimeInt(long time
, boolean ensureVisible
, boolean doNotify
) {
961 setSelectionRangeInt(time
, time
, ensureVisible
, doNotify
);
968 public void setSelectionRangeNotify(long beginTime
, long endTime
, boolean ensureVisible
) {
969 setSelectionRangeInt(beginTime
, endTime
, ensureVisible
, true);
976 public void setSelectionRange(long beginTime
, long endTime
, boolean ensureVisible
) {
977 /* if there is a pending time selection, ignore this one */
978 if (fListenerNotifier
!= null && fListenerNotifier
.hasTimeSelected()) {
981 setSelectionRangeInt(beginTime
, endTime
, ensureVisible
, false);
984 private void setSelectionRangeInt(long beginTime
, long endTime
, boolean ensureVisible
, boolean doNotify
) {
987 long selectionBegin
= fSelectionBegin
;
988 long selectionEnd
= fSelectionEnd
;
989 fSelectionBegin
= Math
.max(fTime0Bound
, Math
.min(fTime1Bound
, beginTime
));
990 fSelectionEnd
= Math
.max(fTime0Bound
, Math
.min(fTime1Bound
, endTime
));
991 boolean changed
= (selectionBegin
!= fSelectionBegin
|| selectionEnd
!= fSelectionEnd
);
994 ensureVisible(selectionBegin
!= fSelectionBegin ? fSelectionBegin
: fSelectionEnd
);
997 fTimeGraphCtrl
.redraw();
998 fTimeScaleCtrl
.redraw();
999 fMarkerAxisCtrl
.redraw();
1000 updateMarkerActions();
1002 if ((time0
!= fTime0
) || (time1
!= fTime1
)) {
1003 notifyRangeListeners();
1006 if (doNotify
&& changed
) {
1007 notifyTimeListeners();
1011 private void ensureVisible(long time
) {
1012 long timeMid
= (fTime1
- fTime0
) / 2;
1013 if (time
< fTime0
) {
1014 long dt
= fTime0
- time
+ timeMid
;
1017 } else if (time
> fTime1
) {
1018 long dt
= time
- fTime1
+ timeMid
;
1022 if (fTime0
< fTime0Bound
) {
1023 fTime1
= Math
.min(fTime1Bound
, fTime1
+ (fTime0Bound
- fTime0
));
1024 fTime0
= fTime0Bound
;
1025 } else if (fTime1
> fTime1Bound
) {
1026 fTime0
= Math
.max(fTime0Bound
, fTime0
- (fTime1
- fTime1Bound
));
1027 fTime1
= fTime1Bound
;
1029 if (fTime1
- fTime0
< fMinTimeInterval
) {
1030 fTime1
= Math
.min(fTime1Bound
, fTime0
+ fMinTimeInterval
);
1032 adjustHorizontalScrollBar();
1036 public void widgetDefaultSelected(SelectionEvent e
) {
1037 if (fSelectedEntry
!= getSelection()) {
1038 fSelectedEntry
= getSelection();
1039 notifySelectionListeners();
1044 public void widgetSelected(SelectionEvent e
) {
1045 if (fSelectedEntry
!= getSelection()) {
1046 fSelectedEntry
= getSelection();
1047 notifySelectionListeners();
1052 * Callback for when the next event is selected
1055 * true to extend selection range, false for single selection
1058 public void selectNextEvent(boolean extend
) {
1059 fTimeGraphCtrl
.selectNextEvent(extend
);
1060 adjustVerticalScrollBar();
1064 * Callback for when the previous event is selected
1067 * true to extend selection range, false for single selection
1070 public void selectPrevEvent(boolean extend
) {
1071 fTimeGraphCtrl
.selectPrevEvent(extend
);
1072 adjustVerticalScrollBar();
1076 * Callback for when the next item is selected
1078 public void selectNextItem() {
1079 fTimeGraphCtrl
.selectNextTrace();
1080 adjustVerticalScrollBar();
1084 * Callback for when the previous item is selected
1086 public void selectPrevItem() {
1087 fTimeGraphCtrl
.selectPrevTrace();
1088 adjustVerticalScrollBar();
1092 * Callback for the show legend action
1094 public void showLegend() {
1095 if (fDataViewer
== null || fDataViewer
.isDisposed()) {
1099 TimeGraphLegend
.open(fDataViewer
.getShell(), fTimeGraphProvider
);
1103 * Callback for the Zoom In action
1105 public void zoomIn() {
1106 fTimeGraphCtrl
.zoomIn();
1110 * Callback for the Zoom Out action
1112 public void zoomOut() {
1113 fTimeGraphCtrl
.zoomOut();
1116 private String
getPreferenceString(String string
) {
1117 return getViewTypeStr() + "." + string
; //$NON-NLS-1$
1121 * Add a selection listener
1124 * The listener to add
1126 public void addSelectionListener(ITimeGraphSelectionListener listener
) {
1127 fSelectionListeners
.add(listener
);
1131 * Remove a selection listener
1134 * The listener to remove
1136 public void removeSelectionListener(ITimeGraphSelectionListener listener
) {
1137 fSelectionListeners
.remove(listener
);
1140 private void notifySelectionListeners() {
1141 if (fListenerNotifier
== null) {
1142 fListenerNotifier
= new ListenerNotifier();
1143 fListenerNotifier
.start();
1145 fListenerNotifier
.selectionChanged();
1148 private void fireSelectionChanged(ITimeGraphEntry selection
) {
1149 TimeGraphSelectionEvent event
= new TimeGraphSelectionEvent(this, selection
);
1151 for (ITimeGraphSelectionListener listener
: fSelectionListeners
) {
1152 listener
.selectionChanged(event
);
1157 * Add a time listener
1160 * The listener to add
1162 public void addTimeListener(ITimeGraphTimeListener listener
) {
1163 fTimeListeners
.add(listener
);
1167 * Remove a time listener
1170 * The listener to remove
1172 public void removeTimeListener(ITimeGraphTimeListener listener
) {
1173 fTimeListeners
.remove(listener
);
1176 private void notifyTimeListeners() {
1177 if (fListenerNotifier
== null) {
1178 fListenerNotifier
= new ListenerNotifier();
1179 fListenerNotifier
.start();
1181 fListenerNotifier
.timeSelected();
1184 private void fireTimeSelected(long startTime
, long endTime
) {
1185 TimeGraphTimeEvent event
= new TimeGraphTimeEvent(this, startTime
, endTime
);
1187 for (ITimeGraphTimeListener listener
: fTimeListeners
) {
1188 listener
.timeSelected(event
);
1193 * Add a range listener
1196 * The listener to add
1198 public void addRangeListener(ITimeGraphRangeListener listener
) {
1199 fRangeListeners
.add(listener
);
1203 * Remove a range listener
1206 * The listener to remove
1208 public void removeRangeListener(ITimeGraphRangeListener listener
) {
1209 fRangeListeners
.remove(listener
);
1212 private void notifyRangeListeners() {
1213 if (fListenerNotifier
== null) {
1214 fListenerNotifier
= new ListenerNotifier();
1215 fListenerNotifier
.start();
1217 fListenerNotifier
.timeRangeUpdated();
1220 private void fireTimeRangeUpdated(long startTime
, long endTime
) {
1221 // Check if the time has actually changed from last notification
1222 if (startTime
!= fTime0ExtSynch
|| endTime
!= fTime1ExtSynch
) {
1223 // Notify Time Scale Selection Listeners
1224 TimeGraphRangeUpdateEvent event
= new TimeGraphRangeUpdateEvent(this, startTime
, endTime
);
1226 for (ITimeGraphRangeListener listener
: fRangeListeners
) {
1227 listener
.timeRangeUpdated(event
);
1230 // update external synch values
1231 updateExtSynchValues();
1236 * Add a bookmark listener
1239 * The listener to add
1242 public void addBookmarkListener(ITimeGraphBookmarkListener listener
) {
1243 fBookmarkListeners
.add(listener
);
1247 * Remove a bookmark listener
1250 * The listener to remove
1253 public void removeBookmarkListener(ITimeGraphBookmarkListener listener
) {
1254 fBookmarkListeners
.remove(listener
);
1257 private void fireBookmarkAdded(IMarkerEvent bookmark
) {
1258 TimeGraphBookmarkEvent event
= new TimeGraphBookmarkEvent(this, bookmark
);
1260 for (ITimeGraphBookmarkListener listener
: fBookmarkListeners
) {
1261 listener
.bookmarkAdded(event
);
1265 private void fireBookmarkRemoved(IMarkerEvent bookmark
) {
1266 TimeGraphBookmarkEvent event
= new TimeGraphBookmarkEvent(this, bookmark
);
1268 for (ITimeGraphBookmarkListener listener
: fBookmarkListeners
) {
1269 listener
.bookmarkRemoved(event
);
1274 * Set the bookmarks list.
1277 * The bookmarks list, or null
1280 public void setBookmarks(List
<IMarkerEvent
> bookmarks
) {
1282 if (bookmarks
!= null) {
1283 fBookmarks
.addAll(bookmarks
);
1286 updateMarkerActions();
1290 * Get the bookmarks list.
1292 * @return The bookmarks list
1295 public List
<IMarkerEvent
> getBookmarks() {
1296 return Collections
.unmodifiableList(fBookmarks
);
1300 * Set the list of marker categories.
1303 * The list of marker categories, or null
1306 public void setMarkerCategories(List
<String
> categories
) {
1307 fMarkerCategories
.clear();
1308 if (categories
!= null) {
1309 fMarkerCategories
.addAll(categories
);
1311 fMarkerCategories
.add(IMarkerEvent
.BOOKMARKS
);
1312 fMarkerAxisCtrl
.setMarkerCategories(fMarkerCategories
);
1319 public void setMarkerCategoryVisible(String category
, boolean visible
) {
1320 boolean changed
= false;
1322 changed
= fHiddenMarkerCategories
.remove(category
);
1324 changed
= fHiddenMarkerCategories
.add(category
);
1328 updateMarkerActions();
1329 getControl().redraw();
1334 * Set the markers list.
1337 * The markers list, or null
1340 public void setMarkers(List
<IMarkerEvent
> markers
) {
1342 if (markers
!= null) {
1343 fMarkers
.addAll(markers
);
1346 updateMarkerActions();
1350 * Get the markers list.
1352 * @return The markers list, or null
1355 public List
<IMarkerEvent
> getMarkers() {
1356 return Collections
.unmodifiableList(fMarkers
);
1360 * Callback to set a selected event in the view
1363 * The event that was selected
1365 * The source of this selection event
1367 public void setSelectedEvent(ITimeEvent event
, Object source
) {
1368 if (event
== null || source
== this) {
1371 fSelectedEntry
= event
.getEntry();
1372 fTimeGraphCtrl
.selectItem(fSelectedEntry
, false);
1374 setSelectedTimeInt(event
.getTime(), true, true);
1375 adjustVerticalScrollBar();
1379 * Set the seeked time of a trace
1382 * The trace that was seeked
1386 * The source of this seek event
1388 public void setSelectedTraceTime(ITimeGraphEntry trace
, long time
, Object source
) {
1389 if (trace
== null || source
== this) {
1392 fSelectedEntry
= trace
;
1393 fTimeGraphCtrl
.selectItem(trace
, false);
1395 setSelectedTimeInt(time
, true, true);
1399 * Callback for a trace selection
1402 * The trace that was selected
1404 public void setSelection(ITimeGraphEntry trace
) {
1405 /* if there is a pending selection, ignore this one */
1406 if (fListenerNotifier
!= null && fListenerNotifier
.hasSelectionChanged()) {
1409 fSelectedEntry
= trace
;
1410 fTimeGraphCtrl
.selectItem(trace
, false);
1411 adjustVerticalScrollBar();
1415 * Callback for a time window selection
1418 * Start time of the range
1420 * End time of the range
1422 * Source of the event
1424 public void setSelectVisTimeWindow(long time0
, long time1
, Object source
) {
1425 if (source
== this) {
1429 setStartFinishTimeInt(time0
, time1
);
1431 // update notification time values since we are now in synch with the
1432 // external application
1433 updateExtSynchValues();
1437 * update the cache values used to identify the need to send a time window
1438 * update to external registered listeners
1440 private void updateExtSynchValues() {
1441 // last time notification cache
1442 fTime0ExtSynch
= fTime0
;
1443 fTime1ExtSynch
= fTime1
;
1447 public TimeFormat
getTimeFormat() {
1453 * the {@link TimeFormat} used to display timestamps
1455 public void setTimeFormat(TimeFormat tf
) {
1456 this.fTimeFormat
= tf
;
1457 if (tf
== TimeFormat
.CYCLES
) {
1458 fTimeDataProvider
= new TimeDataProviderCyclesConverter(this, fClockFrequency
);
1460 fTimeDataProvider
= this;
1462 fTimeScaleCtrl
.setTimeProvider(fTimeDataProvider
);
1463 if (fToolTipHandler
!= null) {
1464 fToolTipHandler
.setTimeProvider(fTimeDataProvider
);
1469 * Sets the clock frequency. Used when the time format is set to CYCLES.
1471 * @param clockFrequency
1472 * the clock frequency in Hz
1474 public void setClockFrequency(long clockFrequency
) {
1475 fClockFrequency
= clockFrequency
;
1476 if (fTimeFormat
== TimeFormat
.CYCLES
) {
1477 fTimeDataProvider
= new TimeDataProviderCyclesConverter(this, fClockFrequency
);
1478 fTimeScaleCtrl
.setTimeProvider(fTimeDataProvider
);
1479 if (fToolTipHandler
!= null) {
1480 fToolTipHandler
.setTimeProvider(fTimeDataProvider
);
1486 * Retrieve the border width
1490 public int getBorderWidth() {
1491 return fBorderWidth
;
1495 * Set the border width
1497 * @param borderWidth
1500 public void setBorderWidth(int borderWidth
) {
1501 if (borderWidth
> -1) {
1502 this.fBorderWidth
= borderWidth
;
1503 GridLayout gl
= (GridLayout
) fDataViewer
.getLayout();
1504 gl
.marginHeight
= borderWidth
;
1509 * Retrieve the height of the header
1511 * @return The height
1513 public int getHeaderHeight() {
1514 return fTimeScaleHeight
;
1518 * Set the height of the header
1520 * @param headerHeight
1523 public void setHeaderHeight(int headerHeight
) {
1524 if (headerHeight
> -1) {
1525 this.fTimeScaleHeight
= headerHeight
;
1526 fTimeScaleCtrl
.setHeight(headerHeight
);
1531 * Retrieve the height of an item row
1533 * @return The height
1535 public int getItemHeight() {
1536 if (fTimeGraphCtrl
!= null) {
1537 return fTimeGraphCtrl
.getItemHeight();
1543 * Set the height of an item row
1548 public void setItemHeight(int rowHeight
) {
1549 if (fTimeGraphCtrl
!= null) {
1550 fTimeGraphCtrl
.setItemHeight(rowHeight
);
1555 * Set the minimum item width
1560 public void setMinimumItemWidth(int width
) {
1561 if (fTimeGraphCtrl
!= null) {
1562 fTimeGraphCtrl
.setMinimumItemWidth(width
);
1567 * Set the width for the name column
1572 public void setNameWidthPref(int width
) {
1573 fNameWidthPref
= width
;
1581 * Retrieve the configure width for the name column
1587 public int getNameWidthPref(int width
) {
1588 return fNameWidthPref
;
1592 * Returns the primary control associated with this viewer.
1594 * @return the SWT control which displays this viewer's content
1596 public Control
getControl() {
1601 * Returns the time graph control associated with this viewer.
1603 * @return the time graph control
1605 public TimeGraphControl
getTimeGraphControl() {
1606 return fTimeGraphCtrl
;
1610 * Returns the time graph scale associated with this viewer.
1612 * @return the time graph scale
1614 public TimeGraphScale
getTimeGraphScale() {
1615 return fTimeScaleCtrl
;
1619 * Returns the composite containing all the controls that are time aligned,
1620 * i.e. TimeGraphScale, TimeGraphControl.
1622 * @return the time based composite
1625 public Composite
getTimeAlignedComposite() {
1626 return fTimeAlignedComposite
;
1630 * Return the x coordinate corresponding to a time
1634 * @return the x coordinate corresponding to the time
1636 public int getXForTime(long time
) {
1637 return fTimeGraphCtrl
.getXForTime(time
);
1641 * Return the time corresponding to an x coordinate
1645 * @return the time corresponding to the x coordinate
1647 public long getTimeAtX(int x
) {
1648 return fTimeGraphCtrl
.getTimeAtX(x
);
1652 * Get the selection provider
1654 * @return the selection provider
1656 public ISelectionProvider
getSelectionProvider() {
1657 return fTimeGraphCtrl
;
1661 * Wait for the cursor
1664 * Wait indefinitely?
1666 public void waitCursor(boolean waitInd
) {
1667 fTimeGraphCtrl
.waitCursor(waitInd
);
1671 * Get the horizontal scroll bar object
1673 * @return The scroll bar
1675 public Slider
getHorizontalBar() {
1676 return fHorizontalScrollBar
;
1680 * Get the vertical scroll bar object
1682 * @return The scroll bar
1684 public Slider
getVerticalBar() {
1685 return fVerticalScrollBar
;
1689 * Set the given index as the top one
1692 * The index that will go to the top
1694 public void setTopIndex(int index
) {
1695 fTimeGraphCtrl
.setTopIndex(index
);
1696 adjustVerticalScrollBar();
1700 * Retrieve the current top index
1702 * @return The top index
1704 public int getTopIndex() {
1705 return fTimeGraphCtrl
.getTopIndex();
1709 * Sets the auto-expand level to be used for new entries discovered when
1710 * calling {@link #setInput(Object)} or {@link #refresh()}. The value 0
1711 * means that there is no auto-expand; 1 means that top-level entries are
1712 * expanded, but not their children; 2 means that top-level entries are
1713 * expanded, and their children, but not grand-children; and so on.
1715 * The value {@link #ALL_LEVELS} means that all subtrees should be expanded.
1719 * non-negative level, or <code>ALL_LEVELS</code> to expand all
1720 * levels of the tree
1722 public void setAutoExpandLevel(int level
) {
1723 fTimeGraphCtrl
.setAutoExpandLevel(level
);
1727 * Returns the auto-expand level.
1729 * @return non-negative level, or <code>ALL_LEVELS</code> if all levels of
1730 * the tree are expanded automatically
1731 * @see #setAutoExpandLevel
1733 public int getAutoExpandLevel() {
1734 return fTimeGraphCtrl
.getAutoExpandLevel();
1738 * Get the expanded state of an entry.
1742 * @return true if the entry is expanded, false if collapsed
1745 public boolean getExpandedState(ITimeGraphEntry entry
) {
1746 return fTimeGraphCtrl
.getExpandedState(entry
);
1750 * Set the expanded state of an entry
1753 * The entry to expand/collapse
1755 * True for expanded, false for collapsed
1757 public void setExpandedState(ITimeGraphEntry entry
, boolean expanded
) {
1758 fTimeGraphCtrl
.setExpandedState(entry
, expanded
);
1759 adjustVerticalScrollBar();
1763 * Collapses all nodes of the viewer's tree, starting with the root.
1765 public void collapseAll() {
1766 fTimeGraphCtrl
.collapseAll();
1767 adjustVerticalScrollBar();
1771 * Expands all entries of the viewer's tree, starting with the root.
1773 public void expandAll() {
1774 fTimeGraphCtrl
.expandAll();
1775 adjustVerticalScrollBar();
1779 * Get the number of expanded (visible) time graph entries. This includes
1780 * leafs and does not include filtered-out entries.
1782 * @return The number of expanded (visible) time graph entries
1784 public int getExpandedElementCount() {
1785 return fTimeGraphCtrl
.getExpandedElementCount();
1789 * Get the expanded (visible) time graph entries. This includes leafs and
1790 * does not include filtered-out entries.
1792 * @return The array of expanded (visible) time graph entries
1794 public ITimeGraphEntry
[] getExpandedElements() {
1795 return fTimeGraphCtrl
.getExpandedElements();
1799 * Add a tree listener
1802 * The listener to add
1804 public void addTreeListener(ITimeGraphTreeListener listener
) {
1805 fTimeGraphCtrl
.addTreeListener(listener
);
1809 * Remove a tree listener
1812 * The listener to remove
1814 public void removeTreeListener(ITimeGraphTreeListener listener
) {
1815 fTimeGraphCtrl
.removeTreeListener(listener
);
1819 * Get the reset scale action.
1821 * @return The Action object
1823 public Action
getResetScaleAction() {
1824 if (fResetScaleAction
== null) {
1826 fResetScaleAction
= new Action() {
1829 resetStartFinishTime();
1832 fResetScaleAction
.setText(Messages
.TmfTimeGraphViewer_ResetScaleActionNameText
);
1833 fResetScaleAction
.setToolTipText(Messages
.TmfTimeGraphViewer_ResetScaleActionToolTipText
);
1834 fResetScaleAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_HOME_MENU
));
1836 return fResetScaleAction
;
1840 * Get the show legend action.
1842 * @return The Action object
1844 public Action
getShowLegendAction() {
1845 if (fShowLegendAction
== null) {
1847 fShowLegendAction
= new Action() {
1853 fShowLegendAction
.setText(Messages
.TmfTimeGraphViewer_LegendActionNameText
);
1854 fShowLegendAction
.setToolTipText(Messages
.TmfTimeGraphViewer_LegendActionToolTipText
);
1855 fShowLegendAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_SHOW_LEGEND
));
1858 return fShowLegendAction
;
1862 * Get the the next event action.
1864 * @return The action object
1866 public Action
getNextEventAction() {
1867 if (fNextEventAction
== null) {
1868 fNextEventAction
= new Action() {
1870 public void runWithEvent(Event event
) {
1871 boolean extend
= (event
.stateMask
& SWT
.SHIFT
) != 0;
1872 selectNextEvent(extend
);
1876 fNextEventAction
.setText(Messages
.TmfTimeGraphViewer_NextEventActionNameText
);
1877 fNextEventAction
.setToolTipText(Messages
.TmfTimeGraphViewer_NextEventActionToolTipText
);
1878 fNextEventAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_NEXT_EVENT
));
1881 return fNextEventAction
;
1885 * Get the previous event action.
1887 * @return The Action object
1889 public Action
getPreviousEventAction() {
1890 if (fPrevEventAction
== null) {
1891 fPrevEventAction
= new Action() {
1893 public void runWithEvent(Event event
) {
1894 boolean extend
= (event
.stateMask
& SWT
.SHIFT
) != 0;
1895 selectPrevEvent(extend
);
1899 fPrevEventAction
.setText(Messages
.TmfTimeGraphViewer_PreviousEventActionNameText
);
1900 fPrevEventAction
.setToolTipText(Messages
.TmfTimeGraphViewer_PreviousEventActionToolTipText
);
1901 fPrevEventAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_PREV_EVENT
));
1904 return fPrevEventAction
;
1908 * Get the next item action.
1910 * @return The Action object
1912 public Action
getNextItemAction() {
1913 if (fNextItemAction
== null) {
1915 fNextItemAction
= new Action() {
1921 fNextItemAction
.setText(Messages
.TmfTimeGraphViewer_NextItemActionNameText
);
1922 fNextItemAction
.setToolTipText(Messages
.TmfTimeGraphViewer_NextItemActionToolTipText
);
1923 fNextItemAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_NEXT_ITEM
));
1925 return fNextItemAction
;
1929 * Get the previous item action.
1931 * @return The Action object
1933 public Action
getPreviousItemAction() {
1934 if (fPreviousItemAction
== null) {
1936 fPreviousItemAction
= new Action() {
1942 fPreviousItemAction
.setText(Messages
.TmfTimeGraphViewer_PreviousItemActionNameText
);
1943 fPreviousItemAction
.setToolTipText(Messages
.TmfTimeGraphViewer_PreviousItemActionToolTipText
);
1944 fPreviousItemAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_PREV_ITEM
));
1946 return fPreviousItemAction
;
1950 * Get the zoom in action
1952 * @return The Action object
1954 public Action
getZoomInAction() {
1955 if (fZoomInAction
== null) {
1956 fZoomInAction
= new Action() {
1962 fZoomInAction
.setText(Messages
.TmfTimeGraphViewer_ZoomInActionNameText
);
1963 fZoomInAction
.setToolTipText(Messages
.TmfTimeGraphViewer_ZoomInActionToolTipText
);
1964 fZoomInAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_ZOOM_IN_MENU
));
1966 return fZoomInAction
;
1970 * Get the zoom out action
1972 * @return The Action object
1974 public Action
getZoomOutAction() {
1975 if (fZoomOutAction
== null) {
1976 fZoomOutAction
= new Action() {
1982 fZoomOutAction
.setText(Messages
.TmfTimeGraphViewer_ZoomOutActionNameText
);
1983 fZoomOutAction
.setToolTipText(Messages
.TmfTimeGraphViewer_ZoomOutActionToolTipText
);
1984 fZoomOutAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_ZOOM_OUT_MENU
));
1986 return fZoomOutAction
;
1990 * Get the hide arrows action
1992 * @param dialogSettings
1993 * The dialog settings section where the state should be stored,
1996 * @return The Action object
1998 public Action
getHideArrowsAction(final IDialogSettings dialogSettings
) {
1999 if (fHideArrowsAction
== null) {
2000 fHideArrowsAction
= new Action(Messages
.TmfTimeGraphViewer_HideArrowsActionNameText
, IAction
.AS_CHECK_BOX
) {
2003 boolean hideArrows
= fHideArrowsAction
.isChecked();
2004 fTimeGraphCtrl
.hideArrows(hideArrows
);
2006 if (dialogSettings
!= null) {
2007 dialogSettings
.put(HIDE_ARROWS_KEY
, hideArrows
);
2009 if (fFollowArrowFwdAction
!= null) {
2010 fFollowArrowFwdAction
.setEnabled(!hideArrows
);
2012 if (fFollowArrowBwdAction
!= null) {
2013 fFollowArrowBwdAction
.setEnabled(!hideArrows
);
2017 fHideArrowsAction
.setToolTipText(Messages
.TmfTimeGraphViewer_HideArrowsActionToolTipText
);
2018 fHideArrowsAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_HIDE_ARROWS
));
2019 if (dialogSettings
!= null) {
2020 boolean hideArrows
= dialogSettings
.getBoolean(HIDE_ARROWS_KEY
);
2021 fTimeGraphCtrl
.hideArrows(hideArrows
);
2022 fHideArrowsAction
.setChecked(hideArrows
);
2023 if (fFollowArrowFwdAction
!= null) {
2024 fFollowArrowFwdAction
.setEnabled(!hideArrows
);
2026 if (fFollowArrowBwdAction
!= null) {
2027 fFollowArrowBwdAction
.setEnabled(!hideArrows
);
2031 return fHideArrowsAction
;
2035 * Get the follow arrow forward action.
2037 * @return The Action object
2039 public Action
getFollowArrowFwdAction() {
2040 if (fFollowArrowFwdAction
== null) {
2041 fFollowArrowFwdAction
= new Action() {
2043 public void runWithEvent(Event event
) {
2044 boolean extend
= (event
.stateMask
& SWT
.SHIFT
) != 0;
2045 fTimeGraphCtrl
.followArrowFwd(extend
);
2046 adjustVerticalScrollBar();
2049 fFollowArrowFwdAction
.setText(Messages
.TmfTimeGraphViewer_FollowArrowForwardActionNameText
);
2050 fFollowArrowFwdAction
.setToolTipText(Messages
.TmfTimeGraphViewer_FollowArrowForwardActionToolTipText
);
2051 fFollowArrowFwdAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_FOLLOW_ARROW_FORWARD
));
2052 if (fHideArrowsAction
!= null) {
2053 fFollowArrowFwdAction
.setEnabled(!fHideArrowsAction
.isChecked());
2056 return fFollowArrowFwdAction
;
2060 * Get the follow arrow backward action.
2062 * @return The Action object
2064 public Action
getFollowArrowBwdAction() {
2065 if (fFollowArrowBwdAction
== null) {
2066 fFollowArrowBwdAction
= new Action() {
2068 public void runWithEvent(Event event
) {
2069 boolean extend
= (event
.stateMask
& SWT
.SHIFT
) != 0;
2070 fTimeGraphCtrl
.followArrowBwd(extend
);
2071 adjustVerticalScrollBar();
2074 fFollowArrowBwdAction
.setText(Messages
.TmfTimeGraphViewer_FollowArrowBackwardActionNameText
);
2075 fFollowArrowBwdAction
.setToolTipText(Messages
.TmfTimeGraphViewer_FollowArrowBackwardActionToolTipText
);
2076 fFollowArrowBwdAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_FOLLOW_ARROW_BACKWARD
));
2077 if (fHideArrowsAction
!= null) {
2078 fFollowArrowBwdAction
.setEnabled(!fHideArrowsAction
.isChecked());
2081 return fFollowArrowBwdAction
;
2085 * Get the show filter dialog action.
2087 * @return The Action object
2090 public ShowFilterDialogAction
getShowFilterDialogAction() {
2091 if (fShowFilterDialogAction
== null) {
2092 fShowFilterDialogAction
= new ShowFilterDialogAction(this);
2094 return fShowFilterDialogAction
;
2098 * Get the toggle bookmark action.
2100 * @return The Action object
2103 public Action
getToggleBookmarkAction() {
2104 if (fToggleBookmarkAction
== null) {
2105 fToggleBookmarkAction
= new Action() {
2107 public void runWithEvent(Event event
) {
2108 IMarkerEvent selectedBookmark
= getBookmarkAtSelection();
2109 if (selectedBookmark
== null) {
2110 final long time
= Math
.min(fSelectionBegin
, fSelectionEnd
);
2111 final long duration
= Math
.max(fSelectionBegin
, fSelectionEnd
) - time
;
2112 final AddBookmarkDialog dialog
= new AddBookmarkDialog(PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getShell(), null);
2113 if (dialog
.open() == Window
.OK
) {
2114 final String label
= dialog
.getValue();
2115 final RGBA rgba
= dialog
.getColorValue();
2116 IMarkerEvent bookmark
= new MarkerEvent(null, time
, duration
, IMarkerEvent
.BOOKMARKS
, rgba
, label
, true);
2117 fBookmarks
.add(bookmark
);
2119 updateMarkerActions();
2120 getControl().redraw();
2121 fireBookmarkAdded(bookmark
);
2124 fBookmarks
.remove(selectedBookmark
);
2126 updateMarkerActions();
2127 getControl().redraw();
2128 fireBookmarkRemoved(selectedBookmark
);
2132 fToggleBookmarkAction
.setText(Messages
.TmfTimeGraphViewer_BookmarkActionAddText
);
2133 fToggleBookmarkAction
.setToolTipText(Messages
.TmfTimeGraphViewer_BookmarkActionAddText
);
2134 fToggleBookmarkAction
.setImageDescriptor(ADD_BOOKMARK
);
2136 return fToggleBookmarkAction
;
2140 * Get the next marker action.
2142 * @return The Action object
2145 public Action
getNextMarkerAction() {
2146 if (fNextMarkerAction
== null) {
2147 fNextMarkerAction
= new Action(Messages
.TmfTimeGraphViewer_NextMarkerActionText
, IAction
.AS_DROP_DOWN_MENU
) {
2149 public void runWithEvent(Event event
) {
2150 boolean extend
= (event
.stateMask
& SWT
.SHIFT
) != 0;
2152 extendToNextMarker();
2158 fNextMarkerAction
.setToolTipText(Messages
.TmfTimeGraphViewer_NextMarkerActionText
);
2159 fNextMarkerAction
.setImageDescriptor(NEXT_BOOKMARK
);
2160 fNextMarkerAction
.setMenuCreator(new IMenuCreator () {
2163 public void dispose() {
2171 public Menu
getMenu(Control parent
) {
2175 menu
= new Menu(parent
);
2176 for (String category
: fMarkerCategories
) {
2177 final Action action
= new Action(category
, IAction
.AS_CHECK_BOX
) {
2179 public void runWithEvent(Event event
) {
2181 fSkippedMarkerCategories
.remove(getText());
2183 fSkippedMarkerCategories
.add(getText());
2185 updateMarkerActions();
2188 action
.setEnabled(!fHiddenMarkerCategories
.contains(category
));
2189 action
.setChecked(action
.isEnabled() && !fSkippedMarkerCategories
.contains(category
));
2190 new ActionContributionItem(action
).fill(menu
, -1);
2196 public Menu
getMenu(Menu parent
) {
2201 return fNextMarkerAction
;
2205 * Get the previous marker action.
2207 * @return The Action object
2210 public Action
getPreviousMarkerAction() {
2211 if (fPreviousMarkerAction
== null) {
2212 fPreviousMarkerAction
= new Action() {
2214 public void runWithEvent(Event event
) {
2215 boolean extend
= (event
.stateMask
& SWT
.SHIFT
) != 0;
2217 extendToPrevMarker();
2223 fPreviousMarkerAction
.setText(Messages
.TmfTimeGraphViewer_PreviousMarkerActionText
);
2224 fPreviousMarkerAction
.setToolTipText(Messages
.TmfTimeGraphViewer_PreviousMarkerActionText
);
2225 fPreviousMarkerAction
.setImageDescriptor(PREVIOUS_BOOKMARK
);
2227 return fPreviousMarkerAction
;
2231 * Get the show markers menu.
2233 * @return The menu manager object
2236 public MenuManager
getMarkersMenu() {
2237 if (fMarkersMenu
== null) {
2238 fMarkersMenu
= new MenuManager(Messages
.TmfTimeGraphViewer_ShowMarkersMenuText
);
2239 fMarkersMenu
.setRemoveAllWhenShown(true);
2240 fMarkersMenu
.addMenuListener(new IMenuListener() {
2242 public void menuAboutToShow(IMenuManager manager
) {
2243 for (String category
: fMarkerCategories
) {
2244 final Action action
= new Action(category
, IAction
.AS_CHECK_BOX
) {
2246 public void runWithEvent(Event event
) {
2247 setMarkerCategoryVisible(getText(), isChecked());
2250 action
.setChecked(!fHiddenMarkerCategories
.contains(category
));
2251 manager
.add(action
);
2256 return fMarkersMenu
;
2260 * Select the next marker that begins at or after the current selection
2261 * begin time. Markers that begin at the same time are ordered by end time.
2263 private void selectNextMarker() {
2264 List
<IMarkerEvent
> markers
= getTimeGraphControl().getMarkers();
2265 if (markers
== null) {
2268 for (IMarkerEvent marker
: markers
) {
2269 final long time
= Math
.min(fSelectionBegin
, fSelectionEnd
);
2270 final long duration
= Math
.max(fSelectionBegin
, fSelectionEnd
) - time
;
2271 if ((marker
.getTime() > time
||
2272 (marker
.getTime() == time
&& marker
.getDuration() > duration
))
2273 && !fSkippedMarkerCategories
.contains(marker
.getCategory())) {
2274 setSelectionRangeNotify(marker
.getTime(), marker
.getTime() + marker
.getDuration(), true);
2275 fTimeGraphCtrl
.updateStatusLine();
2282 * Select the previous marker that begins at or before the current selection
2283 * begin time. Markers that begin at the same time are ordered by end time.
2285 private void selectPrevMarker() {
2286 List
<IMarkerEvent
> markers
= getTimeGraphControl().getMarkers();
2287 if (markers
== null) {
2290 final long time
= Math
.min(fSelectionBegin
, fSelectionEnd
);
2291 final long duration
= Math
.max(fSelectionBegin
, fSelectionEnd
) - time
;
2292 for (int i
= markers
.size() - 1; i
>= 0; i
--) {
2293 IMarkerEvent marker
= markers
.get(i
);
2294 if ((marker
.getTime() < time
||
2295 (marker
.getTime() == time
&& marker
.getDuration() < duration
))
2296 && !fSkippedMarkerCategories
.contains(marker
.getCategory())) {
2297 setSelectionRangeNotify(marker
.getTime(), marker
.getTime() + marker
.getDuration(), true);
2298 fTimeGraphCtrl
.updateStatusLine();
2305 * Extend the selection to the closest next marker end time.
2307 private void extendToNextMarker() {
2308 List
<IMarkerEvent
> markers
= getTimeGraphControl().getMarkers();
2309 if (markers
== null) {
2312 IMarkerEvent nextMarker
= null;
2313 for (IMarkerEvent marker
: markers
) {
2314 if (marker
.getTime() + marker
.getDuration() > fSelectionEnd
2315 && !fSkippedMarkerCategories
.contains(marker
.getCategory())
2316 && (nextMarker
== null || marker
.getTime() + marker
.getDuration() < nextMarker
.getTime() + nextMarker
.getDuration())) {
2317 nextMarker
= marker
;
2320 if (nextMarker
!= null) {
2321 setSelectionRangeNotify(fSelectionBegin
, nextMarker
.getTime() + nextMarker
.getDuration(), true);
2322 fTimeGraphCtrl
.updateStatusLine();
2327 * Extend the selection to the closest previous marker start time.
2329 private void extendToPrevMarker() {
2330 List
<IMarkerEvent
> markers
= getTimeGraphControl().getMarkers();
2331 if (markers
== null) {
2334 for (int i
= markers
.size() - 1; i
>= 0; i
--) {
2335 IMarkerEvent marker
= markers
.get(i
);
2336 if (marker
.getTime() < fSelectionEnd
2337 && !fSkippedMarkerCategories
.contains(marker
.getCategory())) {
2338 setSelectionRangeNotify(fSelectionBegin
, marker
.getTime(), true);
2339 fTimeGraphCtrl
.updateStatusLine();
2345 private IMarkerEvent
getBookmarkAtSelection() {
2346 final long time
= Math
.min(fSelectionBegin
, fSelectionEnd
);
2347 final long duration
= Math
.max(fSelectionBegin
, fSelectionEnd
) - time
;
2348 for (IMarkerEvent bookmark
: fBookmarks
) {
2349 if (bookmark
.getTime() == time
&& bookmark
.getDuration() == duration
) {
2356 private void updateMarkerActions() {
2357 boolean enabled
= fTime0Bound
!= SWT
.DEFAULT
|| fTime1Bound
!= SWT
.DEFAULT
;
2358 if (fToggleBookmarkAction
!= null) {
2359 if (getBookmarkAtSelection() != null) {
2360 fToggleBookmarkAction
.setText(Messages
.TmfTimeGraphViewer_BookmarkActionRemoveText
);
2361 fToggleBookmarkAction
.setToolTipText(Messages
.TmfTimeGraphViewer_BookmarkActionRemoveText
);
2362 fToggleBookmarkAction
.setImageDescriptor(REMOVE_BOOKMARK
);
2364 fToggleBookmarkAction
.setText(Messages
.TmfTimeGraphViewer_BookmarkActionAddText
);
2365 fToggleBookmarkAction
.setToolTipText(Messages
.TmfTimeGraphViewer_BookmarkActionAddText
);
2366 fToggleBookmarkAction
.setImageDescriptor(ADD_BOOKMARK
);
2368 fToggleBookmarkAction
.setEnabled(enabled
);
2370 List
<IMarkerEvent
> markers
= getTimeGraphControl().getMarkers();
2371 if (markers
== null) {
2372 markers
= Collections
.emptyList();
2374 if (fPreviousMarkerAction
!= null) {
2375 fPreviousMarkerAction
.setEnabled(enabled
&& !markers
.isEmpty());
2377 if (fNextMarkerAction
!= null) {
2378 fNextMarkerAction
.setEnabled(enabled
&& !markers
.isEmpty());
2382 private void updateMarkerList() {
2383 List
<IMarkerEvent
> markers
= new ArrayList
<>();
2384 for (IMarkerEvent marker
: fMarkers
) {
2385 if (!fHiddenMarkerCategories
.contains(marker
.getCategory())) {
2386 markers
.add(marker
);
2389 if (!fHiddenMarkerCategories
.contains(IMarkerEvent
.BOOKMARKS
)) {
2390 markers
.addAll(fBookmarks
);
2392 Collections
.sort(markers
, new MarkerComparator());
2393 fTimeGraphCtrl
.setMarkers(markers
);
2394 fMarkerAxisCtrl
.setMarkers(markers
);
2397 private void adjustHorizontalScrollBar() {
2398 long time0
= getTime0();
2399 long time1
= getTime1();
2400 long timeMin
= getMinTime();
2401 long timeMax
= getMaxTime();
2402 long delta
= timeMax
- timeMin
;
2404 int thumb
= H_SCROLLBAR_MAX
;
2406 // Thumb size (page size)
2407 thumb
= Math
.max(1, (int) (H_SCROLLBAR_MAX
* ((double) (time1
- time0
) / delta
)));
2408 // At the beginning of visible window
2409 timePos
= (int) (H_SCROLLBAR_MAX
* ((double) (time0
- timeMin
) / delta
));
2411 fHorizontalScrollBar
.setValues(timePos
, 0, H_SCROLLBAR_MAX
, thumb
, Math
.max(1, thumb
/ 2), Math
.max(2, thumb
));
2414 private void adjustVerticalScrollBar() {
2415 int topIndex
= fTimeGraphCtrl
.getTopIndex();
2416 int countPerPage
= fTimeGraphCtrl
.countPerPage();
2417 int expandedElementCount
= fTimeGraphCtrl
.getExpandedElementCount();
2418 if (topIndex
+ countPerPage
> expandedElementCount
) {
2419 fTimeGraphCtrl
.setTopIndex(Math
.max(0, expandedElementCount
- countPerPage
));
2422 int selection
= fTimeGraphCtrl
.getTopIndex();
2424 int max
= Math
.max(1, expandedElementCount
- 1);
2425 int thumb
= Math
.min(max
, Math
.max(1, countPerPage
- 1));
2427 int pageIncrement
= Math
.max(1, countPerPage
);
2428 fVerticalScrollBar
.setValues(selection
, min
, max
, thumb
, increment
, pageIncrement
);
2433 * a {@link MenuDetectListener}
2434 * @see org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.TimeGraphControl#addTimeGraphEntryMenuListener(org.eclipse.swt.events.MenuDetectListener)
2436 public void addTimeGraphEntryMenuListener(MenuDetectListener listener
) {
2437 fTimeGraphCtrl
.addTimeGraphEntryMenuListener(listener
);
2442 * a {@link MenuDetectListener}
2443 * @see org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.TimeGraphControl#removeTimeGraphEntryMenuListener(org.eclipse.swt.events.MenuDetectListener)
2445 public void removeTimeGraphEntryMenuListener(MenuDetectListener listener
) {
2446 fTimeGraphCtrl
.removeTimeGraphEntryMenuListener(listener
);
2451 * a {@link MenuDetectListener}
2452 * @see org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.TimeGraphControl#addTimeEventMenuListener(org.eclipse.swt.events.MenuDetectListener)
2454 public void addTimeEventMenuListener(MenuDetectListener listener
) {
2455 fTimeGraphCtrl
.addTimeEventMenuListener(listener
);
2460 * a {@link MenuDetectListener}
2461 * @see org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.TimeGraphControl#removeTimeEventMenuListener(org.eclipse.swt.events.MenuDetectListener)
2463 public void removeTimeEventMenuListener(MenuDetectListener listener
) {
2464 fTimeGraphCtrl
.removeTimeEventMenuListener(listener
);
2469 * The filter object to be attached to the view
2471 public void addFilter(@NonNull ViewerFilter filter
) {
2472 fTimeGraphCtrl
.addFilter(filter
);
2478 * The filter object to be attached to the view
2480 public void removeFilter(@NonNull ViewerFilter filter
) {
2481 fTimeGraphCtrl
.removeFilter(filter
);
2486 * Returns this viewer's filters.
2488 * @return an array of viewer filters
2491 public @NonNull ViewerFilter
[] getFilters() {
2492 return fTimeGraphCtrl
.getFilters();
2496 * Sets the filters, replacing any previous filters, and triggers
2497 * refiltering of the elements.
2500 * an array of viewer filters, or null
2503 public void setFilters(@NonNull ViewerFilter
[] filters
) {
2504 fTimeGraphCtrl
.setFilters(filters
);
2509 * Return the time alignment information
2511 * @return the time alignment information
2513 * @see ITmfTimeAligned
2517 public TmfTimeViewAlignmentInfo
getTimeViewAlignmentInfo() {
2518 return fTimeGraphCtrl
.getTimeViewAlignmentInfo();
2522 * Return the available width for the time-axis.
2524 * @see ITmfTimeAligned
2526 * @param requestedOffset
2527 * the requested offset
2528 * @return the available width for the time-axis
2532 public int getAvailableWidth(int requestedOffset
) {
2533 int totalWidth
= fTimeAlignedComposite
.getSize().x
;
2534 return Math
.min(totalWidth
, Math
.max(0, totalWidth
- requestedOffset
));
2538 * Perform the alignment operation.
2541 * the alignment offset
2543 * the alignment width
2545 * @see ITmfTimeAligned
2549 public void performAlign(int offset
, int width
) {
2550 fTimeGraphCtrl
.performAlign(offset
);
2551 int alignmentWidth
= width
;
2552 int size
= fTimeAlignedComposite
.getSize().x
;
2553 GridLayout layout
= (GridLayout
) fTimeAlignedComposite
.getLayout();
2554 int marginSize
= size
- alignmentWidth
- offset
;
2555 layout
.marginRight
= Math
.max(0, marginSize
);
2556 fTimeAlignedComposite
.layout();