1 /*****************************************************************************
2 * Copyright (c) 2007, 2015 Intel Corporation, Ericsson, others
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
9 * Intel Corporation - Initial API and implementation
10 * Ruslan A. Scherbakov, Intel - Initial API and implementation
11 * Alexander N. Alexeev, Intel - Add monitors statistics support
12 * Alvaro Sanchez-Leon - Adapted for TMF
13 * Patrick Tasse - Refactoring
14 * Geneviève Bastien - Add event links between entries
15 *****************************************************************************/
17 package org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
;
19 import java
.util
.ArrayList
;
20 import java
.util
.Collections
;
21 import java
.util
.Comparator
;
22 import java
.util
.HashSet
;
23 import java
.util
.List
;
26 import org
.eclipse
.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
.Color
;
56 import org
.eclipse
.swt
.graphics
.RGBA
;
57 import org
.eclipse
.swt
.graphics
.Rectangle
;
58 import org
.eclipse
.swt
.layout
.FillLayout
;
59 import org
.eclipse
.swt
.layout
.GridData
;
60 import org
.eclipse
.swt
.layout
.GridLayout
;
61 import org
.eclipse
.swt
.widgets
.Composite
;
62 import org
.eclipse
.swt
.widgets
.Control
;
63 import org
.eclipse
.swt
.widgets
.Display
;
64 import org
.eclipse
.swt
.widgets
.Event
;
65 import org
.eclipse
.swt
.widgets
.Listener
;
66 import org
.eclipse
.swt
.widgets
.Menu
;
67 import org
.eclipse
.swt
.widgets
.Slider
;
68 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.Activator
;
69 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.ITmfImageConstants
;
70 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.Messages
;
71 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.dialogs
.AddBookmarkDialog
;
72 import org
.eclipse
.tracecompass
.tmf
.ui
.signal
.TmfTimeViewAlignmentInfo
;
73 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.ITmfTimeAligned
;
74 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.dialogs
.ShowFilterDialogAction
;
75 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.dialogs
.TimeGraphLegend
;
76 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.ILinkEvent
;
77 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.IMarkerEvent
;
78 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.ITimeEvent
;
79 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.ITimeGraphEntry
;
80 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.MarkerEvent
;
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
.TimeGraphScale
;
86 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.widgets
.TimeGraphTooltipHandler
;
87 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.widgets
.Utils
;
88 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.widgets
.Utils
.TimeFormat
;
89 import org
.eclipse
.ui
.PlatformUI
;
92 * Generic time graph viewer implementation
94 * @author Patrick Tasse, and others
96 public class TimeGraphViewer
implements ITimeDataProvider
, SelectionListener
{
98 /** Constant indicating that all levels of the time graph should be expanded */
99 public static final int ALL_LEVELS
= AbstractTreeViewer
.ALL_LEVELS
;
101 private static final int DEFAULT_NAME_WIDTH
= 200;
102 private static final int MIN_NAME_WIDTH
= 6;
103 private static final int MAX_NAME_WIDTH
= 1000;
104 private static final int DEFAULT_HEIGHT
= 22;
105 private static final String HIDE_ARROWS_KEY
= "hide.arrows"; //$NON-NLS-1$
106 private static final long DEFAULT_FREQUENCY
= 1000000000L;
107 private static final int H_SCROLLBAR_MAX
= Integer
.MAX_VALUE
- 1;
109 private static final ImageDescriptor ADD_BOOKMARK
= Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_ADD_BOOKMARK
);
110 private static final ImageDescriptor NEXT_BOOKMARK
= Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_NEXT_BOOKMARK
);
111 private static final ImageDescriptor PREVIOUS_BOOKMARK
= Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_PREVIOUS_BOOKMARK
);
112 private static final ImageDescriptor REMOVE_BOOKMARK
= Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_REMOVE_BOOKMARK
);
114 private long fMinTimeInterval
;
115 private ITimeGraphEntry fSelectedEntry
;
116 private long fBeginTime
= SWT
.DEFAULT
; // The user-specified bounds start time
117 private long fEndTime
= SWT
.DEFAULT
; // The user-specified bounds end time
118 private long fTime0
= SWT
.DEFAULT
; // The current window start time
119 private long fTime1
= SWT
.DEFAULT
; // The current window end time
120 private long fSelectionBegin
= SWT
.DEFAULT
;
121 private long fSelectionEnd
= SWT
.DEFAULT
;
122 private long fTime0Bound
= SWT
.DEFAULT
; // The bounds start time
123 private long fTime1Bound
= SWT
.DEFAULT
; // The bounds end time
124 private long fTime0ExtSynch
= SWT
.DEFAULT
;
125 private long fTime1ExtSynch
= SWT
.DEFAULT
;
126 private boolean fTimeRangeFixed
;
127 private int fNameWidthPref
= DEFAULT_NAME_WIDTH
;
128 private int fMinNameWidth
= MIN_NAME_WIDTH
;
129 private int fNameWidth
;
130 private Composite fDataViewer
;
132 private TimeGraphControl fTimeGraphCtrl
;
133 private TimeGraphScale fTimeScaleCtrl
;
134 private Slider fHorizontalScrollBar
;
135 private Slider fVerticalScrollBar
;
136 private TimeGraphColorScheme fColorScheme
;
137 private Object fInputElement
;
138 private ITimeGraphContentProvider fTimeGraphContentProvider
;
139 private ITimeGraphPresentationProvider fTimeGraphProvider
;
140 private ITimeDataProvider fTimeDataProvider
= this;
141 private TimeGraphTooltipHandler fToolTipHandler
;
143 private List
<ITimeGraphSelectionListener
> fSelectionListeners
= new ArrayList
<>();
144 private List
<ITimeGraphTimeListener
> fTimeListeners
= new ArrayList
<>();
145 private List
<ITimeGraphRangeListener
> fRangeListeners
= new ArrayList
<>();
146 private List
<ITimeGraphBookmarkListener
> fBookmarkListeners
= new ArrayList
<>();
148 // Time format, using Epoch reference, Relative time format(default),
150 private TimeFormat fTimeFormat
= TimeFormat
.RELATIVE
;
151 // Clock frequency to use for Cycles time format
152 private long fClockFrequency
= DEFAULT_FREQUENCY
;
153 private int fBorderWidth
= 0;
154 private int fTimeScaleHeight
= DEFAULT_HEIGHT
;
156 private Action fResetScaleAction
;
157 private Action fShowLegendAction
;
158 private Action fNextEventAction
;
159 private Action fPrevEventAction
;
160 private Action fNextItemAction
;
161 private Action fPreviousItemAction
;
162 private Action fZoomInAction
;
163 private Action fZoomOutAction
;
164 private Action fHideArrowsAction
;
165 private Action fFollowArrowFwdAction
;
166 private Action fFollowArrowBwdAction
;
167 private ShowFilterDialogAction fShowFilterDialogAction
;
168 private Action fToggleBookmarkAction
;
169 private Action fNextMarkerAction
;
170 private Action fPreviousMarkerAction
;
171 private MenuManager fMarkersMenu
;
173 /** The list of bookmarks */
174 private final List
<IMarkerEvent
> fBookmarks
= new ArrayList
<>();
176 /** The list of marker categories */
177 private final List
<String
> fMarkerCategories
= new ArrayList
<>();
179 /** The set of hidden marker categories */
180 private final Set
<String
> fHiddenMarkerCategories
= new HashSet
<>();
182 /** The set of skipped marker categories */
183 private final Set
<String
> fSkippedMarkerCategories
= new HashSet
<>();
185 /** The list of markers */
186 private final List
<IMarkerEvent
> fMarkers
= new ArrayList
<>();
188 /** The list of color resources created by this viewer */
189 private final List
<Color
> fColors
= new ArrayList
<>();
191 private ListenerNotifier fListenerNotifier
;
193 private Composite fTimeAlignedComposite
;
195 private class ListenerNotifier
extends Thread
{
196 private static final long DELAY
= 400L;
197 private static final long POLLING_INTERVAL
= 10L;
198 private long fLastUpdateTime
= Long
.MAX_VALUE
;
199 private boolean fSelectionChanged
= false;
200 private boolean fTimeRangeUpdated
= false;
201 private boolean fTimeSelected
= false;
205 while ((System
.currentTimeMillis() - fLastUpdateTime
) < DELAY
) {
207 Thread
.sleep(POLLING_INTERVAL
);
208 } catch (Exception e
) {
212 Display
.getDefault().asyncExec(new Runnable() {
215 if (fListenerNotifier
!= ListenerNotifier
.this) {
218 fListenerNotifier
= null;
219 if (ListenerNotifier
.this.isInterrupted() || fDataViewer
.isDisposed()) {
222 if (fSelectionChanged
) {
223 fireSelectionChanged(fSelectedEntry
);
225 if (fTimeRangeUpdated
) {
226 fireTimeRangeUpdated(fTime0
, fTime1
);
229 fireTimeSelected(fSelectionBegin
, fSelectionEnd
);
235 public void selectionChanged() {
236 fSelectionChanged
= true;
237 fLastUpdateTime
= System
.currentTimeMillis();
240 public void timeRangeUpdated() {
241 fTimeRangeUpdated
= true;
242 fLastUpdateTime
= System
.currentTimeMillis();
245 public void timeSelected() {
246 fTimeSelected
= true;
247 fLastUpdateTime
= System
.currentTimeMillis();
250 public boolean hasSelectionChanged() {
251 return fSelectionChanged
;
254 public boolean hasTimeRangeUpdated() {
255 return fTimeRangeUpdated
;
258 public boolean hasTimeSelected() {
259 return fTimeSelected
;
263 private final static class MarkerComparator
implements Comparator
<IMarkerEvent
> {
265 public int compare(IMarkerEvent o1
, IMarkerEvent o2
) {
266 int res
= Long
.compare(o1
.getTime(), o2
.getTime());
270 return Long
.compare(o1
.getDuration(), o2
.getDuration());
275 * Standard constructor.
277 * The default timegraph content provider accepts an ITimeGraphEntry[] as input element.
280 * The parent UI composite object
284 public TimeGraphViewer(Composite parent
, int style
) {
285 createDataViewer(parent
, style
);
286 fTimeGraphContentProvider
= new TimeGraphContentProvider();
290 * Sets the timegraph content provider used by this timegraph viewer.
292 * @param timeGraphContentProvider
293 * the timegraph content provider
295 public void setTimeGraphContentProvider(ITimeGraphContentProvider timeGraphContentProvider
) {
296 fTimeGraphContentProvider
= timeGraphContentProvider
;
300 * Gets the timegraph content provider used by this timegraph viewer.
302 * @return the timegraph content provider
304 public ITimeGraphContentProvider
getTimeGraphContentProvider() {
305 return fTimeGraphContentProvider
;
309 * Sets the timegraph presentation provider used by this timegraph viewer.
311 * @param timeGraphProvider
312 * the timegraph provider
314 public void setTimeGraphProvider(ITimeGraphPresentationProvider timeGraphProvider
) {
315 fTimeGraphProvider
= timeGraphProvider
;
316 fTimeGraphCtrl
.setTimeGraphProvider(timeGraphProvider
);
317 fToolTipHandler
= new TimeGraphTooltipHandler(fTimeGraphProvider
, fTimeDataProvider
);
318 fToolTipHandler
.activateHoverHelp(fTimeGraphCtrl
);
322 * Sets the tree columns for this time graph combo's filter dialog.
324 * @param columnNames the tree column names
327 public void setFilterColumns(String
[] columnNames
) {
328 getShowFilterDialogAction().getFilterDialog().setColumnNames(columnNames
);
332 * Sets the tree content provider used by the filter dialog
334 * @param contentProvider the tree content provider
337 public void setFilterContentProvider(ITreeContentProvider contentProvider
) {
338 getShowFilterDialogAction().getFilterDialog().setContentProvider(contentProvider
);
342 * Sets the tree label provider used by the filter dialog
344 * @param labelProvider the tree label provider
347 public void setFilterLabelProvider(ITableLabelProvider labelProvider
) {
348 getShowFilterDialogAction().getFilterDialog().setLabelProvider(labelProvider
);
352 * Sets or clears the input for this time graph viewer.
354 * @param inputElement
355 * The input of this time graph viewer, or <code>null</code> if
358 public void setInput(Object inputElement
) {
359 fInputElement
= inputElement
;
360 ITimeGraphEntry
[] input
= fTimeGraphContentProvider
.getElements(inputElement
);
361 fListenerNotifier
= null;
362 if (fTimeGraphCtrl
!= null) {
365 fSelectionBegin
= SWT
.DEFAULT
;
366 fSelectionEnd
= SWT
.DEFAULT
;
367 updateMarkerActions();
368 fSelectedEntry
= null;
369 refreshAllData(input
);
374 * Gets the input for this time graph viewer.
376 * @return The input of this time graph viewer, or <code>null</code> if none
378 public Object
getInput() {
379 return fInputElement
;
383 * Sets (or clears if null) the list of links to display on this combo
386 * the links to display in this time graph combo
388 public void setLinks(List
<ILinkEvent
> links
) {
389 if (fTimeGraphCtrl
!= null) {
390 fTimeGraphCtrl
.refreshArrows(links
);
397 public void refresh() {
398 ITimeGraphEntry
[] input
= fTimeGraphContentProvider
.getElements(fInputElement
);
400 refreshAllData(input
);
404 * Callback for when the control is moved
409 public void controlMoved(ControlEvent e
) {
413 * Callback for when the control is resized
418 public void controlResized(ControlEvent e
) {
423 * @return The string representing the view type
425 protected String
getViewTypeStr() {
426 return "viewoption.threads"; //$NON-NLS-1$
429 int getMarginWidth() {
433 int getMarginHeight() {
438 fMinTimeInterval
= 1;
439 fSelectionBegin
= SWT
.DEFAULT
;
440 fSelectionEnd
= SWT
.DEFAULT
;
441 fNameWidth
= Utils
.loadIntOption(getPreferenceString("namewidth"), //$NON-NLS-1$
442 fNameWidthPref
, fMinNameWidth
, MAX_NAME_WIDTH
);
446 Utils
.saveIntOption(getPreferenceString("namewidth"), fNameWidth
); //$NON-NLS-1$
450 * Create a data viewer.
456 * @return The new data viewer
458 protected Control
createDataViewer(Composite parent
, int style
) {
460 fColorScheme
= new TimeGraphColorScheme();
461 fDataViewer
= new Composite(parent
, style
) {
463 public void redraw() {
464 fTimeScaleCtrl
.redraw();
465 fTimeGraphCtrl
.redraw();
469 fDataViewer
.addDisposeListener(new DisposeListener() {
471 public void widgetDisposed(DisposeEvent e
) {
472 for (Color color
: fColors
) {
475 if (fMarkersMenu
!= null) {
476 fMarkersMenu
.dispose();
480 GridLayout gl
= new GridLayout(2, false);
481 gl
.marginHeight
= fBorderWidth
;
483 gl
.verticalSpacing
= 0;
484 gl
.horizontalSpacing
= 0;
485 fDataViewer
.setLayout(gl
);
487 fTimeAlignedComposite
= new Composite(fDataViewer
, style
) {
489 public void redraw() {
490 fDataViewer
.redraw();
494 GridLayout gl2
= new GridLayout(1, false);
495 gl2
.marginHeight
= fBorderWidth
;
497 gl2
.verticalSpacing
= 0;
498 gl2
.horizontalSpacing
= 0;
499 fTimeAlignedComposite
.setLayout(gl2
);
500 fTimeAlignedComposite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
502 fTimeScaleCtrl
= new TimeGraphScale(fTimeAlignedComposite
, fColorScheme
);
503 fTimeScaleCtrl
.setTimeProvider(fTimeDataProvider
);
504 fTimeScaleCtrl
.setLayoutData(new GridData(SWT
.FILL
, SWT
.DEFAULT
, true, false));
505 fTimeScaleCtrl
.setHeight(fTimeScaleHeight
);
506 fTimeScaleCtrl
.addMouseWheelListener(new MouseWheelListener() {
508 public void mouseScrolled(MouseEvent e
) {
509 fTimeGraphCtrl
.zoom(e
.count
> 0);
513 fTimeGraphCtrl
= createTimeGraphControl(fTimeAlignedComposite
, fColorScheme
);
515 fTimeGraphCtrl
.setTimeProvider(this);
516 fTimeGraphCtrl
.setTimeGraphScale(fTimeScaleCtrl
);
517 fTimeGraphCtrl
.addSelectionListener(this);
518 fTimeGraphCtrl
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
519 fTimeGraphCtrl
.addMouseWheelListener(new MouseWheelListener() {
521 public void mouseScrolled(MouseEvent e
) {
522 adjustVerticalScrollBar();
525 fTimeGraphCtrl
.addKeyListener(new KeyAdapter() {
527 public void keyPressed(KeyEvent e
) {
528 if (e
.character
== '+') {
530 } else if (e
.character
== '-') {
532 } else if (e
.keyCode
== '.') {
533 boolean extend
= (e
.stateMask
& SWT
.SHIFT
) != 0;
535 extendToNextMarker();
539 } else if (e
.keyCode
== ',') {
540 boolean extend
= (e
.stateMask
& SWT
.SHIFT
) != 0;
542 extendToPrevMarker();
547 adjustVerticalScrollBar();
551 fVerticalScrollBar
= new Slider(fDataViewer
, SWT
.VERTICAL
| SWT
.NO_FOCUS
);
552 fVerticalScrollBar
.setLayoutData(new GridData(SWT
.DEFAULT
, SWT
.FILL
, false, true, 1, 1));
553 fVerticalScrollBar
.addSelectionListener(new SelectionAdapter() {
555 public void widgetSelected(SelectionEvent e
) {
556 setTopIndex(fVerticalScrollBar
.getSelection());
560 fHorizontalScrollBar
= new Slider(fDataViewer
, SWT
.HORIZONTAL
| SWT
.NO_FOCUS
);
561 fHorizontalScrollBar
.setLayoutData(new GridData(SWT
.FILL
, SWT
.DEFAULT
, true, false));
562 fHorizontalScrollBar
.addListener(SWT
.MouseWheel
, new Listener() {
564 public void handleEvent(Event event
) {
565 if ((event
.stateMask
& SWT
.MODIFIER_MASK
) == SWT
.CTRL
) {
566 getTimeGraphControl().zoom(event
.count
> 0);
568 getTimeGraphControl().horizontalScroll(event
.count
> 0);
570 // don't handle the immediately following SWT.Selection event
574 fHorizontalScrollBar
.addListener(SWT
.Selection
, new Listener() {
576 public void handleEvent(Event event
) {
577 int start
= fHorizontalScrollBar
.getSelection();
578 long time0
= getTime0();
579 long time1
= getTime1();
580 long timeMin
= getMinTime();
581 long timeMax
= getMaxTime();
582 long delta
= timeMax
- timeMin
;
584 long range
= time1
- time0
;
585 time0
= timeMin
+ Math
.round(delta
* ((double) start
/ H_SCROLLBAR_MAX
));
586 time1
= time0
+ range
;
588 setStartFinishTimeNotify(time0
, time1
);
592 Composite filler
= new Composite(fDataViewer
, SWT
.NONE
);
593 GridData gd
= new GridData(SWT
.DEFAULT
, SWT
.DEFAULT
, false, false);
594 gd
.heightHint
= fHorizontalScrollBar
.getSize().y
;
595 filler
.setLayoutData(gd
);
596 filler
.setLayout(new FillLayout());
598 fTimeGraphCtrl
.addControlListener(new ControlAdapter() {
600 public void controlResized(ControlEvent event
) {
605 fDataViewer
.update();
606 adjustHorizontalScrollBar();
607 adjustVerticalScrollBar();
614 public void dispose() {
616 fTimeGraphCtrl
.dispose();
617 fDataViewer
.dispose();
618 fColorScheme
.dispose();
622 * Create a new time graph control.
625 * The parent composite
628 * @return The new TimeGraphControl
630 protected TimeGraphControl
createTimeGraphControl(Composite parent
,
631 TimeGraphColorScheme colors
) {
632 return new TimeGraphControl(parent
, colors
);
636 * Resize the controls
638 public void resizeControls() {
639 Rectangle r
= fDataViewer
.getClientArea();
645 if (fNameWidth
> width
- fMinNameWidth
) {
646 fNameWidth
= width
- fMinNameWidth
;
648 if (fNameWidth
< fMinNameWidth
) {
649 fNameWidth
= fMinNameWidth
;
651 adjustHorizontalScrollBar();
652 adjustVerticalScrollBar();
656 * Recalculate the time bounds based on the time graph entries,
657 * if the user-specified bound is set to SWT.DEFAULT.
660 * The root time graph entries in the model
662 public void setTimeRange(ITimeGraphEntry entries
[]) {
663 fTime0Bound
= (fBeginTime
!= SWT
.DEFAULT ? fBeginTime
: fEndTime
);
664 fTime1Bound
= (fEndTime
!= SWT
.DEFAULT ? fEndTime
: fBeginTime
);
665 if (fBeginTime
!= SWT
.DEFAULT
&& fEndTime
!= SWT
.DEFAULT
) {
668 if (entries
== null || entries
.length
== 0) {
671 if (fTime0Bound
== SWT
.DEFAULT
) {
672 fTime0Bound
= Long
.MAX_VALUE
;
674 if (fTime1Bound
== SWT
.DEFAULT
) {
675 fTime1Bound
= Long
.MIN_VALUE
;
677 for (ITimeGraphEntry entry
: entries
) {
682 private void setTimeRange(ITimeGraphEntry entry
) {
683 if (fBeginTime
== SWT
.DEFAULT
&& entry
.hasTimeEvents() && entry
.getStartTime() != SWT
.DEFAULT
) {
684 fTime0Bound
= Math
.min(entry
.getStartTime(), fTime0Bound
);
686 if (fEndTime
== SWT
.DEFAULT
&& entry
.hasTimeEvents() && entry
.getEndTime() != SWT
.DEFAULT
) {
687 fTime1Bound
= Math
.max(entry
.getEndTime(), fTime1Bound
);
689 if (entry
.hasChildren()) {
690 for (ITimeGraphEntry child
: entry
.getChildren()) {
697 * Set the time bounds to the provided values.
700 * The bounds begin time, or SWT.DEFAULT to use the input bounds
702 * The bounds end time, or SWT.DEFAULT to use the input bounds
704 public void setTimeBounds(long beginTime
, long endTime
) {
705 fBeginTime
= beginTime
;
707 fTime0Bound
= (fBeginTime
!= SWT
.DEFAULT ? fBeginTime
: fEndTime
);
708 fTime1Bound
= (fEndTime
!= SWT
.DEFAULT ? fEndTime
: fBeginTime
);
709 if (fTime0Bound
> fTime1Bound
) {
710 // only possible if both are not default
711 fBeginTime
= endTime
;
712 fEndTime
= beginTime
;
713 fTime0Bound
= fBeginTime
;
714 fTime1Bound
= fEndTime
;
716 adjustHorizontalScrollBar();
720 * Recalculate the current time window when bounds have changed.
722 public void setTimeBounds() {
723 if (!fTimeRangeFixed
) {
724 fTime0
= fTime0Bound
;
725 fTime1
= fTime1Bound
;
727 fTime0
= Math
.max(fTime0Bound
, Math
.min(fTime0
, fTime1Bound
));
728 fTime1
= Math
.max(fTime0Bound
, Math
.min(fTime1
, fTime1Bound
));
729 if (fTime1
- fTime0
< fMinTimeInterval
) {
730 fTime1
= Math
.min(fTime1Bound
, fTime0
+ fMinTimeInterval
);
737 private void refreshAllData(ITimeGraphEntry
[] traces
) {
739 if (fSelectionBegin
< fBeginTime
) {
740 fSelectionBegin
= fBeginTime
;
741 } else if (fSelectionBegin
> fEndTime
) {
742 fSelectionBegin
= fEndTime
;
744 if (fSelectionEnd
< fBeginTime
) {
745 fSelectionEnd
= fBeginTime
;
746 } else if (fSelectionEnd
> fEndTime
) {
747 fSelectionEnd
= fEndTime
;
749 fTimeGraphCtrl
.refreshData(traces
);
750 fTimeScaleCtrl
.redraw();
751 updateMarkerActions();
752 adjustVerticalScrollBar();
756 * Callback for when this view is focused
758 public void setFocus() {
759 if (null != fTimeGraphCtrl
) {
760 fTimeGraphCtrl
.setFocus();
765 * Get the current focus status of this view.
767 * @return If the view is currently focused, or not
769 public boolean isInFocus() {
770 return fTimeGraphCtrl
.isInFocus();
774 * Get the view's current selection
776 * @return The entry that is selected
778 public ITimeGraphEntry
getSelection() {
779 return fTimeGraphCtrl
.getSelectedTrace();
783 * Get the index of the current selection
787 public int getSelectionIndex() {
788 return fTimeGraphCtrl
.getSelectedIndex();
792 public long getTime0() {
797 public long getTime1() {
802 public long getMinTimeInterval() {
803 return fMinTimeInterval
;
807 public int getNameSpace() {
812 public void setNameSpace(int width
) {
814 int w
= fTimeGraphCtrl
.getClientArea().width
;
815 if (fNameWidth
> w
- MIN_NAME_WIDTH
) {
816 fNameWidth
= w
- MIN_NAME_WIDTH
;
818 if (fNameWidth
< MIN_NAME_WIDTH
) {
819 fNameWidth
= MIN_NAME_WIDTH
;
821 fTimeGraphCtrl
.redraw();
822 fTimeScaleCtrl
.redraw();
826 public int getTimeSpace() {
827 int w
= fTimeGraphCtrl
.getClientArea().width
;
828 return w
- fNameWidth
;
832 public long getBeginTime() {
837 public long getEndTime() {
842 public long getMaxTime() {
847 public long getMinTime() {
852 public long getSelectionBegin() {
853 return fSelectionBegin
;
857 public long getSelectionEnd() {
858 return fSelectionEnd
;
862 public void setStartFinishTimeNotify(long time0
, long time1
) {
863 setStartFinishTimeInt(time0
, time1
);
864 notifyRangeListeners();
868 public void notifyStartFinishTime() {
869 notifyRangeListeners();
873 public void setStartFinishTime(long time0
, long time1
) {
874 /* if there is a pending time range, ignore this one */
875 if (fListenerNotifier
!= null && fListenerNotifier
.hasTimeRangeUpdated()) {
878 setStartFinishTimeInt(time0
, time1
);
879 updateExtSynchValues();
882 private void setStartFinishTimeInt(long time0
, long time1
) {
884 if (fTime0
< fTime0Bound
) {
885 fTime0
= fTime0Bound
;
887 if (fTime0
> fTime1Bound
) {
888 fTime0
= fTime1Bound
;
891 if (fTime1
< fTime0Bound
) {
892 fTime1
= fTime0Bound
;
894 if (fTime1
> fTime1Bound
) {
895 fTime1
= fTime1Bound
;
897 if (fTime1
- fTime0
< fMinTimeInterval
) {
898 fTime1
= Math
.min(fTime1Bound
, fTime0
+ fMinTimeInterval
);
900 fTimeRangeFixed
= true;
901 adjustHorizontalScrollBar();
902 fTimeGraphCtrl
.redraw();
903 fTimeScaleCtrl
.redraw();
907 public void resetStartFinishTime() {
908 setStartFinishTimeNotify(fTime0Bound
, fTime1Bound
);
909 fTimeRangeFixed
= false;
913 public void setSelectedTimeNotify(long time
, boolean ensureVisible
) {
914 setSelectedTimeInt(time
, ensureVisible
, true);
918 public void setSelectedTime(long time
, boolean ensureVisible
) {
919 /* if there is a pending time selection, ignore this one */
920 if (fListenerNotifier
!= null && fListenerNotifier
.hasTimeSelected()) {
923 setSelectedTimeInt(time
, ensureVisible
, false);
926 private void setSelectedTimeInt(long time
, boolean ensureVisible
, boolean doNotify
) {
927 setSelectionRangeInt(time
, time
, ensureVisible
, doNotify
);
934 public void setSelectionRangeNotify(long beginTime
, long endTime
, boolean ensureVisible
) {
935 setSelectionRangeInt(beginTime
, endTime
, ensureVisible
, true);
942 public void setSelectionRange(long beginTime
, long endTime
, boolean ensureVisible
) {
943 /* if there is a pending time selection, ignore this one */
944 if (fListenerNotifier
!= null && fListenerNotifier
.hasTimeSelected()) {
947 setSelectionRangeInt(beginTime
, endTime
, ensureVisible
, false);
950 private void setSelectionRangeInt(long beginTime
, long endTime
, boolean ensureVisible
, boolean doNotify
) {
953 long selectionBegin
= fSelectionBegin
;
954 long selectionEnd
= fSelectionEnd
;
955 fSelectionBegin
= Math
.max(fTime0Bound
, Math
.min(fTime1Bound
, beginTime
));
956 fSelectionEnd
= Math
.max(fTime0Bound
, Math
.min(fTime1Bound
, endTime
));
957 boolean changed
= (selectionBegin
!= fSelectionBegin
|| selectionEnd
!= fSelectionEnd
);
960 ensureVisible(selectionBegin
!= fSelectionBegin ? fSelectionBegin
: fSelectionEnd
);
963 fTimeGraphCtrl
.redraw();
964 fTimeScaleCtrl
.redraw();
965 updateMarkerActions();
967 if ((time0
!= fTime0
) || (time1
!= fTime1
)) {
968 notifyRangeListeners();
971 if (doNotify
&& changed
) {
972 notifyTimeListeners();
976 private void ensureVisible(long time
) {
977 long timeMid
= (fTime1
- fTime0
) / 2;
979 long dt
= fTime0
- time
+ timeMid
;
982 } else if (time
> fTime1
) {
983 long dt
= time
- fTime1
+ timeMid
;
987 if (fTime0
< fTime0Bound
) {
988 fTime1
= Math
.min(fTime1Bound
, fTime1
+ (fTime0Bound
- fTime0
));
989 fTime0
= fTime0Bound
;
990 } else if (fTime1
> fTime1Bound
) {
991 fTime0
= Math
.max(fTime0Bound
, fTime0
- (fTime1
- fTime1Bound
));
992 fTime1
= fTime1Bound
;
994 if (fTime1
- fTime0
< fMinTimeInterval
) {
995 fTime1
= Math
.min(fTime1Bound
, fTime0
+ fMinTimeInterval
);
997 adjustHorizontalScrollBar();
1001 public void widgetDefaultSelected(SelectionEvent e
) {
1002 if (fSelectedEntry
!= getSelection()) {
1003 fSelectedEntry
= getSelection();
1004 notifySelectionListeners();
1009 public void widgetSelected(SelectionEvent e
) {
1010 if (fSelectedEntry
!= getSelection()) {
1011 fSelectedEntry
= getSelection();
1012 notifySelectionListeners();
1017 * Callback for when the next event is selected
1020 * true to extend selection range, false for single selection
1023 public void selectNextEvent(boolean extend
) {
1024 fTimeGraphCtrl
.selectNextEvent(extend
);
1025 adjustVerticalScrollBar();
1029 * Callback for when the previous event is selected
1032 * true to extend selection range, false for single selection
1035 public void selectPrevEvent(boolean extend
) {
1036 fTimeGraphCtrl
.selectPrevEvent(extend
);
1037 adjustVerticalScrollBar();
1041 * Callback for when the next item is selected
1043 public void selectNextItem() {
1044 fTimeGraphCtrl
.selectNextTrace();
1045 adjustVerticalScrollBar();
1049 * Callback for when the previous item is selected
1051 public void selectPrevItem() {
1052 fTimeGraphCtrl
.selectPrevTrace();
1053 adjustVerticalScrollBar();
1057 * Callback for the show legend action
1059 public void showLegend() {
1060 if (fDataViewer
== null || fDataViewer
.isDisposed()) {
1064 TimeGraphLegend
.open(fDataViewer
.getShell(), fTimeGraphProvider
);
1068 * Callback for the Zoom In action
1070 public void zoomIn() {
1071 fTimeGraphCtrl
.zoomIn();
1075 * Callback for the Zoom Out action
1077 public void zoomOut() {
1078 fTimeGraphCtrl
.zoomOut();
1081 private String
getPreferenceString(String string
) {
1082 return getViewTypeStr() + "." + string
; //$NON-NLS-1$
1086 * Add a selection listener
1089 * The listener to add
1091 public void addSelectionListener(ITimeGraphSelectionListener listener
) {
1092 fSelectionListeners
.add(listener
);
1096 * Remove a selection listener
1099 * The listener to remove
1101 public void removeSelectionListener(ITimeGraphSelectionListener listener
) {
1102 fSelectionListeners
.remove(listener
);
1105 private void notifySelectionListeners() {
1106 if (fListenerNotifier
== null) {
1107 fListenerNotifier
= new ListenerNotifier();
1108 fListenerNotifier
.start();
1110 fListenerNotifier
.selectionChanged();
1113 private void fireSelectionChanged(ITimeGraphEntry selection
) {
1114 TimeGraphSelectionEvent event
= new TimeGraphSelectionEvent(this, selection
);
1116 for (ITimeGraphSelectionListener listener
: fSelectionListeners
) {
1117 listener
.selectionChanged(event
);
1122 * Add a time listener
1125 * The listener to add
1127 public void addTimeListener(ITimeGraphTimeListener listener
) {
1128 fTimeListeners
.add(listener
);
1132 * Remove a time listener
1135 * The listener to remove
1137 public void removeTimeListener(ITimeGraphTimeListener listener
) {
1138 fTimeListeners
.remove(listener
);
1141 private void notifyTimeListeners() {
1142 if (fListenerNotifier
== null) {
1143 fListenerNotifier
= new ListenerNotifier();
1144 fListenerNotifier
.start();
1146 fListenerNotifier
.timeSelected();
1149 private void fireTimeSelected(long startTime
, long endTime
) {
1150 TimeGraphTimeEvent event
= new TimeGraphTimeEvent(this, startTime
, endTime
);
1152 for (ITimeGraphTimeListener listener
: fTimeListeners
) {
1153 listener
.timeSelected(event
);
1158 * Add a range listener
1161 * The listener to add
1163 public void addRangeListener(ITimeGraphRangeListener listener
) {
1164 fRangeListeners
.add(listener
);
1168 * Remove a range listener
1171 * The listener to remove
1173 public void removeRangeListener(ITimeGraphRangeListener listener
) {
1174 fRangeListeners
.remove(listener
);
1177 private void notifyRangeListeners() {
1178 if (fListenerNotifier
== null) {
1179 fListenerNotifier
= new ListenerNotifier();
1180 fListenerNotifier
.start();
1182 fListenerNotifier
.timeRangeUpdated();
1185 private void fireTimeRangeUpdated(long startTime
, long endTime
) {
1186 // Check if the time has actually changed from last notification
1187 if (startTime
!= fTime0ExtSynch
|| endTime
!= fTime1ExtSynch
) {
1188 // Notify Time Scale Selection Listeners
1189 TimeGraphRangeUpdateEvent event
= new TimeGraphRangeUpdateEvent(this, startTime
, endTime
);
1191 for (ITimeGraphRangeListener listener
: fRangeListeners
) {
1192 listener
.timeRangeUpdated(event
);
1195 // update external synch values
1196 updateExtSynchValues();
1201 * Add a bookmark listener
1204 * The listener to add
1207 public void addBookmarkListener(ITimeGraphBookmarkListener listener
) {
1208 fBookmarkListeners
.add(listener
);
1212 * Remove a bookmark listener
1215 * The listener to remove
1218 public void removeBookmarkListener(ITimeGraphBookmarkListener listener
) {
1219 fBookmarkListeners
.remove(listener
);
1222 private void fireBookmarkAdded(IMarkerEvent bookmark
) {
1223 TimeGraphBookmarkEvent event
= new TimeGraphBookmarkEvent(this, bookmark
);
1225 for (ITimeGraphBookmarkListener listener
: fBookmarkListeners
) {
1226 listener
.bookmarkAdded(event
);
1230 private void fireBookmarkRemoved(IMarkerEvent bookmark
) {
1231 TimeGraphBookmarkEvent event
= new TimeGraphBookmarkEvent(this, bookmark
);
1233 for (ITimeGraphBookmarkListener listener
: fBookmarkListeners
) {
1234 listener
.bookmarkRemoved(event
);
1239 * Set the bookmarks list.
1242 * The bookmarks list, or null
1245 public void setBookmarks(List
<IMarkerEvent
> bookmarks
) {
1246 for (IMarkerEvent bookmark
: fBookmarks
) {
1247 checkDisposeColor(bookmark
.getColor());
1250 if (bookmarks
!= null) {
1251 fBookmarks
.addAll(bookmarks
);
1254 updateMarkerActions();
1258 * Get the bookmarks list.
1260 * @return The bookmarks list
1263 public List
<IMarkerEvent
> getBookmarks() {
1264 return Collections
.unmodifiableList(fBookmarks
);
1268 * Set the list of marker categories.
1271 * The list of marker categories, or null
1274 public void setMarkerCategories(List
<String
> categories
) {
1275 fMarkerCategories
.clear();
1276 fMarkerCategories
.add(IMarkerEvent
.BOOKMARKS
);
1277 if (categories
!= null) {
1278 fMarkerCategories
.addAll(categories
);
1280 Collections
.sort(fMarkerCategories
);
1284 * Set the markers list.
1287 * The markers list, or null
1290 public void setMarkers(List
<IMarkerEvent
> markers
) {
1292 if (markers
!= null) {
1293 fMarkers
.addAll(markers
);
1296 updateMarkerActions();
1300 * Get the markers list.
1302 * @return The markers list, or null
1305 public List
<IMarkerEvent
> getMarkers() {
1306 return Collections
.unmodifiableList(fMarkers
);
1310 * Dispose the color resource if and only if it was created by this viewer.
1315 private void checkDisposeColor(Color color
) {
1316 for (int i
= 0; i
< fColors
.size(); i
++) {
1317 /* check for identity, not equality */
1318 if (fColors
.get(i
) == color
) {
1327 * Callback to set a selected event in the view
1330 * The event that was selected
1332 * The source of this selection event
1334 public void setSelectedEvent(ITimeEvent event
, Object source
) {
1335 if (event
== null || source
== this) {
1338 fSelectedEntry
= event
.getEntry();
1339 fTimeGraphCtrl
.selectItem(fSelectedEntry
, false);
1341 setSelectedTimeInt(event
.getTime(), true, true);
1342 adjustVerticalScrollBar();
1346 * Set the seeked time of a trace
1349 * The trace that was seeked
1353 * The source of this seek event
1355 public void setSelectedTraceTime(ITimeGraphEntry trace
, long time
, Object source
) {
1356 if (trace
== null || source
== this) {
1359 fSelectedEntry
= trace
;
1360 fTimeGraphCtrl
.selectItem(trace
, false);
1362 setSelectedTimeInt(time
, true, true);
1366 * Callback for a trace selection
1369 * The trace that was selected
1371 public void setSelection(ITimeGraphEntry trace
) {
1372 /* if there is a pending selection, ignore this one */
1373 if (fListenerNotifier
!= null && fListenerNotifier
.hasSelectionChanged()) {
1376 fSelectedEntry
= trace
;
1377 fTimeGraphCtrl
.selectItem(trace
, false);
1378 adjustVerticalScrollBar();
1382 * Callback for a time window selection
1385 * Start time of the range
1387 * End time of the range
1389 * Source of the event
1391 public void setSelectVisTimeWindow(long time0
, long time1
, Object source
) {
1392 if (source
== this) {
1396 setStartFinishTimeInt(time0
, time1
);
1398 // update notification time values since we are now in synch with the
1399 // external application
1400 updateExtSynchValues();
1404 * update the cache values used to identify the need to send a time window
1405 * update to external registered listeners
1407 private void updateExtSynchValues() {
1408 // last time notification cache
1409 fTime0ExtSynch
= fTime0
;
1410 fTime1ExtSynch
= fTime1
;
1414 public TimeFormat
getTimeFormat() {
1420 * the {@link TimeFormat} used to display timestamps
1422 public void setTimeFormat(TimeFormat tf
) {
1423 this.fTimeFormat
= tf
;
1424 if (tf
== TimeFormat
.CYCLES
) {
1425 fTimeDataProvider
= new TimeDataProviderCyclesConverter(this, fClockFrequency
);
1427 fTimeDataProvider
= this;
1429 fTimeScaleCtrl
.setTimeProvider(fTimeDataProvider
);
1430 if (fToolTipHandler
!= null) {
1431 fToolTipHandler
.setTimeProvider(fTimeDataProvider
);
1436 * Sets the clock frequency. Used when the time format is set to CYCLES.
1438 * @param clockFrequency
1439 * the clock frequency in Hz
1441 public void setClockFrequency(long clockFrequency
) {
1442 fClockFrequency
= clockFrequency
;
1443 if (fTimeFormat
== TimeFormat
.CYCLES
) {
1444 fTimeDataProvider
= new TimeDataProviderCyclesConverter(this, fClockFrequency
);
1445 fTimeScaleCtrl
.setTimeProvider(fTimeDataProvider
);
1446 if (fToolTipHandler
!= null) {
1447 fToolTipHandler
.setTimeProvider(fTimeDataProvider
);
1453 * Retrieve the border width
1457 public int getBorderWidth() {
1458 return fBorderWidth
;
1462 * Set the border width
1464 * @param borderWidth
1467 public void setBorderWidth(int borderWidth
) {
1468 if (borderWidth
> -1) {
1469 this.fBorderWidth
= borderWidth
;
1470 GridLayout gl
= (GridLayout
) fDataViewer
.getLayout();
1471 gl
.marginHeight
= borderWidth
;
1476 * Retrieve the height of the header
1478 * @return The height
1480 public int getHeaderHeight() {
1481 return fTimeScaleHeight
;
1485 * Set the height of the header
1487 * @param headerHeight
1490 public void setHeaderHeight(int headerHeight
) {
1491 if (headerHeight
> -1) {
1492 this.fTimeScaleHeight
= headerHeight
;
1493 fTimeScaleCtrl
.setHeight(headerHeight
);
1498 * Retrieve the height of an item row
1500 * @return The height
1502 public int getItemHeight() {
1503 if (fTimeGraphCtrl
!= null) {
1504 return fTimeGraphCtrl
.getItemHeight();
1510 * Set the height of an item row
1515 public void setItemHeight(int rowHeight
) {
1516 if (fTimeGraphCtrl
!= null) {
1517 fTimeGraphCtrl
.setItemHeight(rowHeight
);
1522 * Set the minimum item width
1527 public void setMinimumItemWidth(int width
) {
1528 if (fTimeGraphCtrl
!= null) {
1529 fTimeGraphCtrl
.setMinimumItemWidth(width
);
1534 * Set the width for the name column
1539 public void setNameWidthPref(int width
) {
1540 fNameWidthPref
= width
;
1548 * Retrieve the configure width for the name column
1554 public int getNameWidthPref(int width
) {
1555 return fNameWidthPref
;
1559 * Returns the primary control associated with this viewer.
1561 * @return the SWT control which displays this viewer's content
1563 public Control
getControl() {
1568 * Returns the time graph control associated with this viewer.
1570 * @return the time graph control
1572 public TimeGraphControl
getTimeGraphControl() {
1573 return fTimeGraphCtrl
;
1577 * Returns the time graph scale associated with this viewer.
1579 * @return the time graph scale
1581 public TimeGraphScale
getTimeGraphScale() {
1582 return fTimeScaleCtrl
;
1586 * Returns the composite containing all the controls that are time aligned,
1587 * i.e. TimeGraphScale, TimeGraphControl.
1589 * @return the time based composite
1592 public Composite
getTimeAlignedComposite() {
1593 return fTimeAlignedComposite
;
1597 * Return the x coordinate corresponding to a time
1601 * @return the x coordinate corresponding to the time
1603 public int getXForTime(long time
) {
1604 return fTimeGraphCtrl
.getXForTime(time
);
1608 * Return the time corresponding to an x coordinate
1612 * @return the time corresponding to the x coordinate
1614 public long getTimeAtX(int x
) {
1615 return fTimeGraphCtrl
.getTimeAtX(x
);
1619 * Get the selection provider
1621 * @return the selection provider
1623 public ISelectionProvider
getSelectionProvider() {
1624 return fTimeGraphCtrl
;
1628 * Wait for the cursor
1631 * Wait indefinitely?
1633 public void waitCursor(boolean waitInd
) {
1634 fTimeGraphCtrl
.waitCursor(waitInd
);
1638 * Get the horizontal scroll bar object
1640 * @return The scroll bar
1642 public Slider
getHorizontalBar() {
1643 return fHorizontalScrollBar
;
1647 * Get the vertical scroll bar object
1649 * @return The scroll bar
1651 public Slider
getVerticalBar() {
1652 return fVerticalScrollBar
;
1656 * Set the given index as the top one
1659 * The index that will go to the top
1661 public void setTopIndex(int index
) {
1662 fTimeGraphCtrl
.setTopIndex(index
);
1663 adjustVerticalScrollBar();
1667 * Retrieve the current top index
1669 * @return The top index
1671 public int getTopIndex() {
1672 return fTimeGraphCtrl
.getTopIndex();
1676 * Sets the auto-expand level to be used for new entries discovered when
1677 * calling {@link #setInput(Object)} or {@link #refresh()}. The value 0
1678 * means that there is no auto-expand; 1 means that top-level entries are
1679 * expanded, but not their children; 2 means that top-level entries are
1680 * expanded, and their children, but not grand-children; and so on.
1682 * The value {@link #ALL_LEVELS} means that all subtrees should be expanded.
1686 * non-negative level, or <code>ALL_LEVELS</code> to expand all
1687 * levels of the tree
1689 public void setAutoExpandLevel(int level
) {
1690 fTimeGraphCtrl
.setAutoExpandLevel(level
);
1694 * Returns the auto-expand level.
1696 * @return non-negative level, or <code>ALL_LEVELS</code> if all levels of
1697 * the tree are expanded automatically
1698 * @see #setAutoExpandLevel
1700 public int getAutoExpandLevel() {
1701 return fTimeGraphCtrl
.getAutoExpandLevel();
1705 * Get the expanded state of an entry.
1709 * @return true if the entry is expanded, false if collapsed
1712 public boolean getExpandedState(ITimeGraphEntry entry
) {
1713 return fTimeGraphCtrl
.getExpandedState(entry
);
1717 * Set the expanded state of an entry
1720 * The entry to expand/collapse
1722 * True for expanded, false for collapsed
1724 public void setExpandedState(ITimeGraphEntry entry
, boolean expanded
) {
1725 fTimeGraphCtrl
.setExpandedState(entry
, expanded
);
1726 adjustVerticalScrollBar();
1730 * Collapses all nodes of the viewer's tree, starting with the root.
1732 public void collapseAll() {
1733 fTimeGraphCtrl
.collapseAll();
1734 adjustVerticalScrollBar();
1738 * Expands all entries of the viewer's tree, starting with the root.
1740 public void expandAll() {
1741 fTimeGraphCtrl
.expandAll();
1742 adjustVerticalScrollBar();
1746 * Get the number of expanded (visible) time graph entries. This includes
1747 * leafs and does not include filtered-out entries.
1749 * @return The number of expanded (visible) time graph entries
1751 public int getExpandedElementCount() {
1752 return fTimeGraphCtrl
.getExpandedElementCount();
1756 * Get the expanded (visible) time graph entries. This includes leafs and
1757 * does not include filtered-out entries.
1759 * @return The array of expanded (visible) time graph entries
1761 public ITimeGraphEntry
[] getExpandedElements() {
1762 return fTimeGraphCtrl
.getExpandedElements();
1766 * Add a tree listener
1769 * The listener to add
1771 public void addTreeListener(ITimeGraphTreeListener listener
) {
1772 fTimeGraphCtrl
.addTreeListener(listener
);
1776 * Remove a tree listener
1779 * The listener to remove
1781 public void removeTreeListener(ITimeGraphTreeListener listener
) {
1782 fTimeGraphCtrl
.removeTreeListener(listener
);
1786 * Get the reset scale action.
1788 * @return The Action object
1790 public Action
getResetScaleAction() {
1791 if (fResetScaleAction
== null) {
1793 fResetScaleAction
= new Action() {
1796 resetStartFinishTime();
1799 fResetScaleAction
.setText(Messages
.TmfTimeGraphViewer_ResetScaleActionNameText
);
1800 fResetScaleAction
.setToolTipText(Messages
.TmfTimeGraphViewer_ResetScaleActionToolTipText
);
1801 fResetScaleAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_HOME_MENU
));
1803 return fResetScaleAction
;
1807 * Get the show legend action.
1809 * @return The Action object
1811 public Action
getShowLegendAction() {
1812 if (fShowLegendAction
== null) {
1814 fShowLegendAction
= new Action() {
1820 fShowLegendAction
.setText(Messages
.TmfTimeGraphViewer_LegendActionNameText
);
1821 fShowLegendAction
.setToolTipText(Messages
.TmfTimeGraphViewer_LegendActionToolTipText
);
1822 fShowLegendAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_SHOW_LEGEND
));
1825 return fShowLegendAction
;
1829 * Get the the next event action.
1831 * @return The action object
1833 public Action
getNextEventAction() {
1834 if (fNextEventAction
== null) {
1835 fNextEventAction
= new Action() {
1837 public void runWithEvent(Event event
) {
1838 boolean extend
= (event
.stateMask
& SWT
.SHIFT
) != 0;
1839 selectNextEvent(extend
);
1843 fNextEventAction
.setText(Messages
.TmfTimeGraphViewer_NextEventActionNameText
);
1844 fNextEventAction
.setToolTipText(Messages
.TmfTimeGraphViewer_NextEventActionToolTipText
);
1845 fNextEventAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_NEXT_EVENT
));
1848 return fNextEventAction
;
1852 * Get the previous event action.
1854 * @return The Action object
1856 public Action
getPreviousEventAction() {
1857 if (fPrevEventAction
== null) {
1858 fPrevEventAction
= new Action() {
1860 public void runWithEvent(Event event
) {
1861 boolean extend
= (event
.stateMask
& SWT
.SHIFT
) != 0;
1862 selectPrevEvent(extend
);
1866 fPrevEventAction
.setText(Messages
.TmfTimeGraphViewer_PreviousEventActionNameText
);
1867 fPrevEventAction
.setToolTipText(Messages
.TmfTimeGraphViewer_PreviousEventActionToolTipText
);
1868 fPrevEventAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_PREV_EVENT
));
1871 return fPrevEventAction
;
1875 * Get the next item action.
1877 * @return The Action object
1879 public Action
getNextItemAction() {
1880 if (fNextItemAction
== null) {
1882 fNextItemAction
= new Action() {
1888 fNextItemAction
.setText(Messages
.TmfTimeGraphViewer_NextItemActionNameText
);
1889 fNextItemAction
.setToolTipText(Messages
.TmfTimeGraphViewer_NextItemActionToolTipText
);
1890 fNextItemAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_NEXT_ITEM
));
1892 return fNextItemAction
;
1896 * Get the previous item action.
1898 * @return The Action object
1900 public Action
getPreviousItemAction() {
1901 if (fPreviousItemAction
== null) {
1903 fPreviousItemAction
= new Action() {
1909 fPreviousItemAction
.setText(Messages
.TmfTimeGraphViewer_PreviousItemActionNameText
);
1910 fPreviousItemAction
.setToolTipText(Messages
.TmfTimeGraphViewer_PreviousItemActionToolTipText
);
1911 fPreviousItemAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_PREV_ITEM
));
1913 return fPreviousItemAction
;
1917 * Get the zoom in action
1919 * @return The Action object
1921 public Action
getZoomInAction() {
1922 if (fZoomInAction
== null) {
1923 fZoomInAction
= new Action() {
1929 fZoomInAction
.setText(Messages
.TmfTimeGraphViewer_ZoomInActionNameText
);
1930 fZoomInAction
.setToolTipText(Messages
.TmfTimeGraphViewer_ZoomInActionToolTipText
);
1931 fZoomInAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_ZOOM_IN_MENU
));
1933 return fZoomInAction
;
1937 * Get the zoom out action
1939 * @return The Action object
1941 public Action
getZoomOutAction() {
1942 if (fZoomOutAction
== null) {
1943 fZoomOutAction
= new Action() {
1949 fZoomOutAction
.setText(Messages
.TmfTimeGraphViewer_ZoomOutActionNameText
);
1950 fZoomOutAction
.setToolTipText(Messages
.TmfTimeGraphViewer_ZoomOutActionToolTipText
);
1951 fZoomOutAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_ZOOM_OUT_MENU
));
1953 return fZoomOutAction
;
1957 * Get the hide arrows action
1959 * @param dialogSettings
1960 * The dialog settings section where the state should be stored,
1963 * @return The Action object
1965 public Action
getHideArrowsAction(final IDialogSettings dialogSettings
) {
1966 if (fHideArrowsAction
== null) {
1967 fHideArrowsAction
= new Action(Messages
.TmfTimeGraphViewer_HideArrowsActionNameText
, IAction
.AS_CHECK_BOX
) {
1970 boolean hideArrows
= fHideArrowsAction
.isChecked();
1971 fTimeGraphCtrl
.hideArrows(hideArrows
);
1973 if (dialogSettings
!= null) {
1974 dialogSettings
.put(HIDE_ARROWS_KEY
, hideArrows
);
1976 if (fFollowArrowFwdAction
!= null) {
1977 fFollowArrowFwdAction
.setEnabled(!hideArrows
);
1979 if (fFollowArrowBwdAction
!= null) {
1980 fFollowArrowBwdAction
.setEnabled(!hideArrows
);
1984 fHideArrowsAction
.setToolTipText(Messages
.TmfTimeGraphViewer_HideArrowsActionToolTipText
);
1985 fHideArrowsAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_HIDE_ARROWS
));
1986 if (dialogSettings
!= null) {
1987 boolean hideArrows
= dialogSettings
.getBoolean(HIDE_ARROWS_KEY
);
1988 fTimeGraphCtrl
.hideArrows(hideArrows
);
1989 fHideArrowsAction
.setChecked(hideArrows
);
1990 if (fFollowArrowFwdAction
!= null) {
1991 fFollowArrowFwdAction
.setEnabled(!hideArrows
);
1993 if (fFollowArrowBwdAction
!= null) {
1994 fFollowArrowBwdAction
.setEnabled(!hideArrows
);
1998 return fHideArrowsAction
;
2002 * Get the follow arrow forward action.
2004 * @return The Action object
2006 public Action
getFollowArrowFwdAction() {
2007 if (fFollowArrowFwdAction
== null) {
2008 fFollowArrowFwdAction
= new Action() {
2010 public void runWithEvent(Event event
) {
2011 boolean extend
= (event
.stateMask
& SWT
.SHIFT
) != 0;
2012 fTimeGraphCtrl
.followArrowFwd(extend
);
2013 adjustVerticalScrollBar();
2016 fFollowArrowFwdAction
.setText(Messages
.TmfTimeGraphViewer_FollowArrowForwardActionNameText
);
2017 fFollowArrowFwdAction
.setToolTipText(Messages
.TmfTimeGraphViewer_FollowArrowForwardActionToolTipText
);
2018 fFollowArrowFwdAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_FOLLOW_ARROW_FORWARD
));
2019 if (fHideArrowsAction
!= null) {
2020 fFollowArrowFwdAction
.setEnabled(!fHideArrowsAction
.isChecked());
2023 return fFollowArrowFwdAction
;
2027 * Get the follow arrow backward action.
2029 * @return The Action object
2031 public Action
getFollowArrowBwdAction() {
2032 if (fFollowArrowBwdAction
== null) {
2033 fFollowArrowBwdAction
= new Action() {
2035 public void runWithEvent(Event event
) {
2036 boolean extend
= (event
.stateMask
& SWT
.SHIFT
) != 0;
2037 fTimeGraphCtrl
.followArrowBwd(extend
);
2038 adjustVerticalScrollBar();
2041 fFollowArrowBwdAction
.setText(Messages
.TmfTimeGraphViewer_FollowArrowBackwardActionNameText
);
2042 fFollowArrowBwdAction
.setToolTipText(Messages
.TmfTimeGraphViewer_FollowArrowBackwardActionToolTipText
);
2043 fFollowArrowBwdAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_FOLLOW_ARROW_BACKWARD
));
2044 if (fHideArrowsAction
!= null) {
2045 fFollowArrowBwdAction
.setEnabled(!fHideArrowsAction
.isChecked());
2048 return fFollowArrowBwdAction
;
2052 * Get the show filter dialog action.
2054 * @return The Action object
2057 public ShowFilterDialogAction
getShowFilterDialogAction() {
2058 if (fShowFilterDialogAction
== null) {
2059 fShowFilterDialogAction
= new ShowFilterDialogAction(this);
2061 return fShowFilterDialogAction
;
2065 * Get the toggle bookmark action.
2067 * @return The Action object
2070 public Action
getToggleBookmarkAction() {
2071 if (fToggleBookmarkAction
== null) {
2072 fToggleBookmarkAction
= new Action() {
2074 public void runWithEvent(Event event
) {
2075 IMarkerEvent selectedBookmark
= getBookmarkAtSelection();
2076 if (selectedBookmark
== null) {
2077 final long time
= Math
.min(fSelectionBegin
, fSelectionEnd
);
2078 final long duration
= Math
.max(fSelectionBegin
, fSelectionEnd
) - time
;
2079 final AddBookmarkDialog dialog
= new AddBookmarkDialog(PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getShell(), null);
2080 if (dialog
.open() == Window
.OK
) {
2081 final String label
= dialog
.getValue();
2082 final RGBA rgba
= dialog
.getColorValue();
2083 Color color
= new Color(Display
.getDefault(), rgba
.rgb
.red
, rgba
.rgb
.green
, rgba
.rgb
.blue
, rgba
.alpha
);
2085 IMarkerEvent bookmark
= new MarkerEvent(null, time
, duration
, IMarkerEvent
.BOOKMARKS
, color
, label
, true);
2086 fBookmarks
.add(bookmark
);
2088 updateMarkerActions();
2089 getControl().redraw();
2090 fireBookmarkAdded(bookmark
);
2093 checkDisposeColor(selectedBookmark
.getColor());
2094 fBookmarks
.remove(selectedBookmark
);
2096 updateMarkerActions();
2097 getControl().redraw();
2098 fireBookmarkRemoved(selectedBookmark
);
2102 fToggleBookmarkAction
.setText(Messages
.TmfTimeGraphViewer_BookmarkActionAddText
);
2103 fToggleBookmarkAction
.setToolTipText(Messages
.TmfTimeGraphViewer_BookmarkActionAddText
);
2104 fToggleBookmarkAction
.setImageDescriptor(ADD_BOOKMARK
);
2106 return fToggleBookmarkAction
;
2110 * Get the next marker action.
2112 * @return The Action object
2115 public Action
getNextMarkerAction() {
2116 if (fNextMarkerAction
== null) {
2117 fNextMarkerAction
= new Action(Messages
.TmfTimeGraphViewer_NextMarkerActionText
, IAction
.AS_DROP_DOWN_MENU
) {
2119 public void runWithEvent(Event event
) {
2120 boolean extend
= (event
.stateMask
& SWT
.SHIFT
) != 0;
2122 extendToNextMarker();
2128 fNextMarkerAction
.setToolTipText(Messages
.TmfTimeGraphViewer_NextMarkerActionText
);
2129 fNextMarkerAction
.setImageDescriptor(NEXT_BOOKMARK
);
2130 fNextMarkerAction
.setMenuCreator(new IMenuCreator () {
2133 public void dispose() {
2141 public Menu
getMenu(Control parent
) {
2145 menu
= new Menu(parent
);
2146 for (String category
: fMarkerCategories
) {
2147 final Action action
= new Action(category
, IAction
.AS_CHECK_BOX
) {
2149 public void runWithEvent(Event event
) {
2151 fSkippedMarkerCategories
.remove(getText());
2153 fSkippedMarkerCategories
.add(getText());
2155 updateMarkerActions();
2158 action
.setEnabled(!fHiddenMarkerCategories
.contains(category
));
2159 action
.setChecked(action
.isEnabled() && !fSkippedMarkerCategories
.contains(category
));
2160 new ActionContributionItem(action
).fill(menu
, -1);
2166 public Menu
getMenu(Menu parent
) {
2171 return fNextMarkerAction
;
2175 * Get the previous marker action.
2177 * @return The Action object
2180 public Action
getPreviousMarkerAction() {
2181 if (fPreviousMarkerAction
== null) {
2182 fPreviousMarkerAction
= new Action() {
2184 public void runWithEvent(Event event
) {
2185 boolean extend
= (event
.stateMask
& SWT
.SHIFT
) != 0;
2187 extendToPrevMarker();
2193 fPreviousMarkerAction
.setText(Messages
.TmfTimeGraphViewer_PreviousMarkerActionText
);
2194 fPreviousMarkerAction
.setToolTipText(Messages
.TmfTimeGraphViewer_PreviousMarkerActionText
);
2195 fPreviousMarkerAction
.setImageDescriptor(PREVIOUS_BOOKMARK
);
2197 return fPreviousMarkerAction
;
2201 * Get the show markers menu.
2203 * @return The menu manager object
2206 public MenuManager
getMarkersMenu() {
2207 if (fMarkersMenu
== null) {
2208 fMarkersMenu
= new MenuManager(Messages
.TmfTimeGraphViewer_ShowMarkersMenuText
);
2209 fMarkersMenu
.setRemoveAllWhenShown(true);
2210 fMarkersMenu
.addMenuListener(new IMenuListener() {
2212 public void menuAboutToShow(IMenuManager manager
) {
2213 for (String category
: fMarkerCategories
) {
2214 final Action action
= new Action(category
, IAction
.AS_CHECK_BOX
) {
2216 public void runWithEvent(Event event
) {
2218 fHiddenMarkerCategories
.remove(getText());
2220 fHiddenMarkerCategories
.add(getText());
2223 updateMarkerActions();
2224 getControl().redraw();
2227 action
.setChecked(!fHiddenMarkerCategories
.contains(category
));
2228 manager
.add(action
);
2233 return fMarkersMenu
;
2237 * Select the next marker that begins at or after the current selection
2238 * begin time. Markers that begin at the same time are ordered by end time.
2240 private void selectNextMarker() {
2241 List
<IMarkerEvent
> markers
= getTimeGraphControl().getMarkers();
2242 if (markers
== null) {
2245 for (IMarkerEvent marker
: markers
) {
2246 final long time
= Math
.min(fSelectionBegin
, fSelectionEnd
);
2247 final long duration
= Math
.max(fSelectionBegin
, fSelectionEnd
) - time
;
2248 if ((marker
.getTime() > time
||
2249 (marker
.getTime() == time
&& marker
.getDuration() > duration
))
2250 && !fSkippedMarkerCategories
.contains(marker
.getCategory())) {
2251 setSelectionRangeNotify(marker
.getTime(), marker
.getTime() + marker
.getDuration(), true);
2252 fTimeGraphCtrl
.updateStatusLine();
2259 * Select the previous marker that begins at or before the current selection
2260 * begin time. Markers that begin at the same time are ordered by end time.
2262 private void selectPrevMarker() {
2263 List
<IMarkerEvent
> markers
= getTimeGraphControl().getMarkers();
2264 if (markers
== null) {
2267 final long time
= Math
.min(fSelectionBegin
, fSelectionEnd
);
2268 final long duration
= Math
.max(fSelectionBegin
, fSelectionEnd
) - time
;
2269 for (int i
= markers
.size() - 1; i
>= 0; i
--) {
2270 IMarkerEvent marker
= markers
.get(i
);
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 * Extend the selection to the closest next marker end time.
2284 private void extendToNextMarker() {
2285 List
<IMarkerEvent
> markers
= getTimeGraphControl().getMarkers();
2286 if (markers
== null) {
2289 IMarkerEvent nextMarker
= null;
2290 for (IMarkerEvent marker
: markers
) {
2291 if (marker
.getTime() + marker
.getDuration() > fSelectionEnd
2292 && !fSkippedMarkerCategories
.contains(marker
.getCategory())
2293 && (nextMarker
== null || marker
.getTime() + marker
.getDuration() < nextMarker
.getTime() + nextMarker
.getDuration())) {
2294 nextMarker
= marker
;
2297 if (nextMarker
!= null) {
2298 setSelectionRangeNotify(fSelectionBegin
, nextMarker
.getTime() + nextMarker
.getDuration(), true);
2299 fTimeGraphCtrl
.updateStatusLine();
2304 * Extend the selection to the closest previous marker start time.
2306 private void extendToPrevMarker() {
2307 List
<IMarkerEvent
> markers
= getTimeGraphControl().getMarkers();
2308 if (markers
== null) {
2311 for (int i
= markers
.size() - 1; i
>= 0; i
--) {
2312 IMarkerEvent marker
= markers
.get(i
);
2313 if (marker
.getTime() < fSelectionEnd
2314 && !fSkippedMarkerCategories
.contains(marker
.getCategory())) {
2315 setSelectionRangeNotify(fSelectionBegin
, marker
.getTime(), true);
2316 fTimeGraphCtrl
.updateStatusLine();
2322 private IMarkerEvent
getBookmarkAtSelection() {
2323 final long time
= Math
.min(fSelectionBegin
, fSelectionEnd
);
2324 final long duration
= Math
.max(fSelectionBegin
, fSelectionEnd
) - time
;
2325 for (IMarkerEvent bookmark
: fBookmarks
) {
2326 if (bookmark
.getTime() == time
&& bookmark
.getDuration() == duration
) {
2333 private void updateMarkerActions() {
2334 boolean enabled
= fTime0Bound
!= SWT
.DEFAULT
|| fTime1Bound
!= SWT
.DEFAULT
;
2335 if (fToggleBookmarkAction
!= null) {
2336 if (getBookmarkAtSelection() != null) {
2337 fToggleBookmarkAction
.setText(Messages
.TmfTimeGraphViewer_BookmarkActionRemoveText
);
2338 fToggleBookmarkAction
.setToolTipText(Messages
.TmfTimeGraphViewer_BookmarkActionRemoveText
);
2339 fToggleBookmarkAction
.setImageDescriptor(REMOVE_BOOKMARK
);
2341 fToggleBookmarkAction
.setText(Messages
.TmfTimeGraphViewer_BookmarkActionAddText
);
2342 fToggleBookmarkAction
.setToolTipText(Messages
.TmfTimeGraphViewer_BookmarkActionAddText
);
2343 fToggleBookmarkAction
.setImageDescriptor(ADD_BOOKMARK
);
2345 fToggleBookmarkAction
.setEnabled(enabled
);
2347 List
<IMarkerEvent
> markers
= getTimeGraphControl().getMarkers();
2348 if (markers
== null) {
2349 markers
= Collections
.emptyList();
2351 if (fPreviousMarkerAction
!= null) {
2352 fPreviousMarkerAction
.setEnabled(enabled
&& !markers
.isEmpty());
2354 if (fNextMarkerAction
!= null) {
2355 fNextMarkerAction
.setEnabled(enabled
&& !markers
.isEmpty());
2359 private void updateMarkerList() {
2360 List
<IMarkerEvent
> markers
= new ArrayList
<>();
2361 for (IMarkerEvent marker
: fMarkers
) {
2362 if (!fHiddenMarkerCategories
.contains(marker
.getCategory())) {
2363 markers
.add(marker
);
2366 if (!fHiddenMarkerCategories
.contains(IMarkerEvent
.BOOKMARKS
)) {
2367 markers
.addAll(fBookmarks
);
2369 Collections
.sort(markers
, new MarkerComparator());
2370 getTimeGraphControl().setMarkers(markers
);
2373 private void adjustHorizontalScrollBar() {
2374 long time0
= getTime0();
2375 long time1
= getTime1();
2376 long timeMin
= getMinTime();
2377 long timeMax
= getMaxTime();
2378 long delta
= timeMax
- timeMin
;
2380 int thumb
= H_SCROLLBAR_MAX
;
2382 // Thumb size (page size)
2383 thumb
= Math
.max(1, (int) (H_SCROLLBAR_MAX
* ((double) (time1
- time0
) / delta
)));
2384 // At the beginning of visible window
2385 timePos
= (int) (H_SCROLLBAR_MAX
* ((double) (time0
- timeMin
) / delta
));
2387 fHorizontalScrollBar
.setValues(timePos
, 0, H_SCROLLBAR_MAX
, thumb
, Math
.max(1, thumb
/ 2), Math
.max(2, thumb
));
2390 private void adjustVerticalScrollBar() {
2391 int topIndex
= fTimeGraphCtrl
.getTopIndex();
2392 int countPerPage
= fTimeGraphCtrl
.countPerPage();
2393 int expandedElementCount
= fTimeGraphCtrl
.getExpandedElementCount();
2394 if (topIndex
+ countPerPage
> expandedElementCount
) {
2395 fTimeGraphCtrl
.setTopIndex(Math
.max(0, expandedElementCount
- countPerPage
));
2398 int selection
= fTimeGraphCtrl
.getTopIndex();
2400 int max
= Math
.max(1, expandedElementCount
- 1);
2401 int thumb
= Math
.min(max
, Math
.max(1, countPerPage
- 1));
2403 int pageIncrement
= Math
.max(1, countPerPage
);
2404 fVerticalScrollBar
.setValues(selection
, min
, max
, thumb
, increment
, pageIncrement
);
2409 * a {@link MenuDetectListener}
2410 * @see org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.TimeGraphControl#addTimeGraphEntryMenuListener(org.eclipse.swt.events.MenuDetectListener)
2412 public void addTimeGraphEntryMenuListener(MenuDetectListener listener
) {
2413 fTimeGraphCtrl
.addTimeGraphEntryMenuListener(listener
);
2418 * a {@link MenuDetectListener}
2419 * @see org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.TimeGraphControl#removeTimeGraphEntryMenuListener(org.eclipse.swt.events.MenuDetectListener)
2421 public void removeTimeGraphEntryMenuListener(MenuDetectListener listener
) {
2422 fTimeGraphCtrl
.removeTimeGraphEntryMenuListener(listener
);
2427 * a {@link MenuDetectListener}
2428 * @see org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.TimeGraphControl#addTimeEventMenuListener(org.eclipse.swt.events.MenuDetectListener)
2430 public void addTimeEventMenuListener(MenuDetectListener listener
) {
2431 fTimeGraphCtrl
.addTimeEventMenuListener(listener
);
2436 * a {@link MenuDetectListener}
2437 * @see org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.TimeGraphControl#removeTimeEventMenuListener(org.eclipse.swt.events.MenuDetectListener)
2439 public void removeTimeEventMenuListener(MenuDetectListener listener
) {
2440 fTimeGraphCtrl
.removeTimeEventMenuListener(listener
);
2445 * The filter object to be attached to the view
2447 public void addFilter(@NonNull ViewerFilter filter
) {
2448 fTimeGraphCtrl
.addFilter(filter
);
2454 * The filter object to be attached to the view
2456 public void removeFilter(@NonNull ViewerFilter filter
) {
2457 fTimeGraphCtrl
.removeFilter(filter
);
2462 * Returns this viewer's filters.
2464 * @return an array of viewer filters
2467 public @NonNull ViewerFilter
[] getFilters() {
2468 return fTimeGraphCtrl
.getFilters();
2472 * Sets the filters, replacing any previous filters, and triggers
2473 * refiltering of the elements.
2476 * an array of viewer filters, or null
2479 public void setFilters(@NonNull ViewerFilter
[] filters
) {
2480 fTimeGraphCtrl
.setFilters(filters
);
2485 * Return the time alignment information
2487 * @return the time alignment information
2489 * @see ITmfTimeAligned
2493 public TmfTimeViewAlignmentInfo
getTimeViewAlignmentInfo() {
2494 return fTimeGraphCtrl
.getTimeViewAlignmentInfo();
2498 * Return the available width for the time-axis.
2500 * @see ITmfTimeAligned
2502 * @param requestedOffset
2503 * the requested offset
2504 * @return the available width for the time-axis
2508 public int getAvailableWidth(int requestedOffset
) {
2509 int totalWidth
= fTimeAlignedComposite
.getSize().x
;
2510 return Math
.min(totalWidth
, Math
.max(0, totalWidth
- requestedOffset
));
2514 * Perform the alignment operation.
2517 * the alignment offset
2519 * the alignment width
2521 * @see ITmfTimeAligned
2525 public void performAlign(int offset
, int width
) {
2526 fTimeGraphCtrl
.performAlign(offset
);
2527 int alignmentWidth
= width
;
2528 int size
= fTimeAlignedComposite
.getSize().x
;
2529 GridLayout layout
= (GridLayout
) fTimeAlignedComposite
.getLayout();
2530 int marginSize
= size
- alignmentWidth
- offset
;
2531 layout
.marginRight
= Math
.max(0, marginSize
);
2532 fTimeAlignedComposite
.layout();