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
.List
;
24 import org
.eclipse
.jface
.action
.Action
;
25 import org
.eclipse
.jface
.action
.IAction
;
26 import org
.eclipse
.jface
.dialogs
.IDialogSettings
;
27 import org
.eclipse
.jface
.resource
.ImageDescriptor
;
28 import org
.eclipse
.jface
.viewers
.AbstractTreeViewer
;
29 import org
.eclipse
.jface
.viewers
.ISelectionProvider
;
30 import org
.eclipse
.jface
.viewers
.ITableLabelProvider
;
31 import org
.eclipse
.jface
.viewers
.ITreeContentProvider
;
32 import org
.eclipse
.jface
.viewers
.ViewerFilter
;
33 import org
.eclipse
.jface
.window
.Window
;
34 import org
.eclipse
.swt
.SWT
;
35 import org
.eclipse
.swt
.events
.ControlAdapter
;
36 import org
.eclipse
.swt
.events
.ControlEvent
;
37 import org
.eclipse
.swt
.events
.DisposeEvent
;
38 import org
.eclipse
.swt
.events
.DisposeListener
;
39 import org
.eclipse
.swt
.events
.KeyAdapter
;
40 import org
.eclipse
.swt
.events
.KeyEvent
;
41 import org
.eclipse
.swt
.events
.MenuDetectListener
;
42 import org
.eclipse
.swt
.events
.MouseEvent
;
43 import org
.eclipse
.swt
.events
.MouseWheelListener
;
44 import org
.eclipse
.swt
.events
.SelectionAdapter
;
45 import org
.eclipse
.swt
.events
.SelectionEvent
;
46 import org
.eclipse
.swt
.events
.SelectionListener
;
47 import org
.eclipse
.swt
.graphics
.Color
;
48 import org
.eclipse
.swt
.graphics
.RGBA
;
49 import org
.eclipse
.swt
.graphics
.Rectangle
;
50 import org
.eclipse
.swt
.layout
.FillLayout
;
51 import org
.eclipse
.swt
.layout
.GridData
;
52 import org
.eclipse
.swt
.layout
.GridLayout
;
53 import org
.eclipse
.swt
.widgets
.Composite
;
54 import org
.eclipse
.swt
.widgets
.Control
;
55 import org
.eclipse
.swt
.widgets
.Display
;
56 import org
.eclipse
.swt
.widgets
.Event
;
57 import org
.eclipse
.swt
.widgets
.Listener
;
58 import org
.eclipse
.swt
.widgets
.Slider
;
59 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.Activator
;
60 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.ITmfImageConstants
;
61 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.Messages
;
62 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.dialogs
.AddBookmarkDialog
;
63 import org
.eclipse
.tracecompass
.tmf
.ui
.signal
.TmfTimeViewAlignmentInfo
;
64 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.ITmfTimeAligned
;
65 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.dialogs
.ShowFilterDialogAction
;
66 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.dialogs
.TimeGraphLegend
;
67 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.ILinkEvent
;
68 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.IMarkerEvent
;
69 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.ITimeEvent
;
70 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.ITimeGraphEntry
;
71 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.MarkerEvent
;
72 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.widgets
.ITimeDataProvider
;
73 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.widgets
.TimeDataProviderCyclesConverter
;
74 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.widgets
.TimeGraphColorScheme
;
75 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.widgets
.TimeGraphControl
;
76 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.widgets
.TimeGraphScale
;
77 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.widgets
.TimeGraphTooltipHandler
;
78 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.widgets
.Utils
;
79 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.widgets
.Utils
.TimeFormat
;
80 import org
.eclipse
.ui
.PlatformUI
;
83 * Generic time graph viewer implementation
85 * @author Patrick Tasse, and others
87 public class TimeGraphViewer
implements ITimeDataProvider
, SelectionListener
{
89 /** Constant indicating that all levels of the time graph should be expanded */
90 public static final int ALL_LEVELS
= AbstractTreeViewer
.ALL_LEVELS
;
92 private static final int DEFAULT_NAME_WIDTH
= 200;
93 private static final int MIN_NAME_WIDTH
= 6;
94 private static final int MAX_NAME_WIDTH
= 1000;
95 private static final int DEFAULT_HEIGHT
= 22;
96 private static final String HIDE_ARROWS_KEY
= "hide.arrows"; //$NON-NLS-1$
97 private static final long DEFAULT_FREQUENCY
= 1000000000L;
98 private static final int H_SCROLLBAR_MAX
= Integer
.MAX_VALUE
- 1;
100 private static ImageDescriptor ADD_BOOKMARK
= Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_ADD_BOOKMARK
);
101 private static ImageDescriptor NEXT_BOOKMARK
= Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_NEXT_BOOKMARK
);
102 private static ImageDescriptor PREVIOUS_BOOKMARK
= Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_PREVIOUS_BOOKMARK
);
103 private static ImageDescriptor REMOVE_BOOKMARK
= Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_REMOVE_BOOKMARK
);
105 private long fMinTimeInterval
;
106 private ITimeGraphEntry fSelectedEntry
;
107 private long fBeginTime
= SWT
.DEFAULT
; // The user-specified bounds start time
108 private long fEndTime
= SWT
.DEFAULT
; // The user-specified bounds end time
109 private long fTime0
= SWT
.DEFAULT
; // The current window start time
110 private long fTime1
= SWT
.DEFAULT
; // The current window end time
111 private long fSelectionBegin
= SWT
.DEFAULT
;
112 private long fSelectionEnd
= SWT
.DEFAULT
;
113 private long fTime0Bound
= SWT
.DEFAULT
; // The bounds start time
114 private long fTime1Bound
= SWT
.DEFAULT
; // The bounds end time
115 private long fTime0ExtSynch
= SWT
.DEFAULT
;
116 private long fTime1ExtSynch
= SWT
.DEFAULT
;
117 private boolean fTimeRangeFixed
;
118 private int fNameWidthPref
= DEFAULT_NAME_WIDTH
;
119 private int fMinNameWidth
= MIN_NAME_WIDTH
;
120 private int fNameWidth
;
121 private Composite fDataViewer
;
123 private TimeGraphControl fTimeGraphCtrl
;
124 private TimeGraphScale fTimeScaleCtrl
;
125 private Slider fHorizontalScrollBar
;
126 private Slider fVerticalScrollBar
;
127 private TimeGraphColorScheme fColorScheme
;
128 private Object fInputElement
;
129 private ITimeGraphContentProvider fTimeGraphContentProvider
;
130 private ITimeGraphPresentationProvider fTimeGraphProvider
;
131 private ITimeDataProvider fTimeDataProvider
= this;
132 private TimeGraphTooltipHandler fToolTipHandler
;
134 private List
<ITimeGraphSelectionListener
> fSelectionListeners
= new ArrayList
<>();
135 private List
<ITimeGraphTimeListener
> fTimeListeners
= new ArrayList
<>();
136 private List
<ITimeGraphRangeListener
> fRangeListeners
= new ArrayList
<>();
137 private List
<ITimeGraphBookmarkListener
> fBookmarkListeners
= new ArrayList
<>();
139 // Time format, using Epoch reference, Relative time format(default),
141 private TimeFormat fTimeFormat
= TimeFormat
.RELATIVE
;
142 // Clock frequency to use for Cycles time format
143 private long fClockFrequency
= DEFAULT_FREQUENCY
;
144 private int fBorderWidth
= 0;
145 private int fTimeScaleHeight
= DEFAULT_HEIGHT
;
147 private Action fResetScaleAction
;
148 private Action fShowLegendAction
;
149 private Action fNextEventAction
;
150 private Action fPrevEventAction
;
151 private Action fNextItemAction
;
152 private Action fPreviousItemAction
;
153 private Action fZoomInAction
;
154 private Action fZoomOutAction
;
155 private Action fHideArrowsAction
;
156 private Action fFollowArrowFwdAction
;
157 private Action fFollowArrowBwdAction
;
158 private ShowFilterDialogAction fShowFilterDialogAction
;
159 private Action fToggleBookmarkAction
;
160 private Action fNextBookmarkAction
;
161 private Action fPreviousBookmarkAction
;
163 /** The list of bookmarks */
164 private final List
<IMarkerEvent
> fBookmarks
= new ArrayList
<>();
166 /** The list of color resources created by this viewer */
167 private final List
<Color
> fColors
= new ArrayList
<>();
169 private ListenerNotifier fListenerNotifier
;
171 private Composite fTimeAlignedComposite
;
173 private class ListenerNotifier
extends Thread
{
174 private static final long DELAY
= 400L;
175 private static final long POLLING_INTERVAL
= 10L;
176 private long fLastUpdateTime
= Long
.MAX_VALUE
;
177 private boolean fSelectionChanged
= false;
178 private boolean fTimeRangeUpdated
= false;
179 private boolean fTimeSelected
= false;
183 while ((System
.currentTimeMillis() - fLastUpdateTime
) < DELAY
) {
185 Thread
.sleep(POLLING_INTERVAL
);
186 } catch (Exception e
) {
190 Display
.getDefault().asyncExec(new Runnable() {
193 if (fListenerNotifier
!= ListenerNotifier
.this) {
196 fListenerNotifier
= null;
197 if (ListenerNotifier
.this.isInterrupted() || fDataViewer
.isDisposed()) {
200 if (fSelectionChanged
) {
201 fireSelectionChanged(fSelectedEntry
);
203 if (fTimeRangeUpdated
) {
204 fireTimeRangeUpdated(fTime0
, fTime1
);
207 fireTimeSelected(fSelectionBegin
, fSelectionEnd
);
213 public void selectionChanged() {
214 fSelectionChanged
= true;
215 fLastUpdateTime
= System
.currentTimeMillis();
218 public void timeRangeUpdated() {
219 fTimeRangeUpdated
= true;
220 fLastUpdateTime
= System
.currentTimeMillis();
223 public void timeSelected() {
224 fTimeSelected
= true;
225 fLastUpdateTime
= System
.currentTimeMillis();
228 public boolean hasSelectionChanged() {
229 return fSelectionChanged
;
232 public boolean hasTimeRangeUpdated() {
233 return fTimeRangeUpdated
;
236 public boolean hasTimeSelected() {
237 return fTimeSelected
;
241 private final static class BookmarkComparator
implements Comparator
<IMarkerEvent
> {
243 public int compare(IMarkerEvent o1
, IMarkerEvent o2
) {
244 int res
= Long
.compare(o1
.getTime(), o2
.getTime());
248 return Long
.compare(o1
.getDuration(), o2
.getDuration());
253 * Standard constructor.
255 * The default timegraph content provider accepts an ITimeGraphEntry[] as input element.
258 * The parent UI composite object
262 public TimeGraphViewer(Composite parent
, int style
) {
263 createDataViewer(parent
, style
);
264 fTimeGraphContentProvider
= new TimeGraphContentProvider();
268 * Sets the timegraph content provider used by this timegraph viewer.
270 * @param timeGraphContentProvider
271 * the timegraph content provider
273 public void setTimeGraphContentProvider(ITimeGraphContentProvider timeGraphContentProvider
) {
274 fTimeGraphContentProvider
= timeGraphContentProvider
;
278 * Gets the timegraph content provider used by this timegraph viewer.
280 * @return the timegraph content provider
282 public ITimeGraphContentProvider
getTimeGraphContentProvider() {
283 return fTimeGraphContentProvider
;
287 * Sets the timegraph presentation provider used by this timegraph viewer.
289 * @param timeGraphProvider
290 * the timegraph provider
292 public void setTimeGraphProvider(ITimeGraphPresentationProvider timeGraphProvider
) {
293 fTimeGraphProvider
= timeGraphProvider
;
294 fTimeGraphCtrl
.setTimeGraphProvider(timeGraphProvider
);
295 fToolTipHandler
= new TimeGraphTooltipHandler(fTimeGraphProvider
, fTimeDataProvider
);
296 fToolTipHandler
.activateHoverHelp(fTimeGraphCtrl
);
300 * Sets the tree columns for this time graph combo's filter dialog.
302 * @param columnNames the tree column names
305 public void setFilterColumns(String
[] columnNames
) {
306 getShowFilterDialogAction().getFilterDialog().setColumnNames(columnNames
);
310 * Sets the tree content provider used by the filter dialog
312 * @param contentProvider the tree content provider
315 public void setFilterContentProvider(ITreeContentProvider contentProvider
) {
316 getShowFilterDialogAction().getFilterDialog().setContentProvider(contentProvider
);
320 * Sets the tree label provider used by the filter dialog
322 * @param labelProvider the tree label provider
325 public void setFilterLabelProvider(ITableLabelProvider labelProvider
) {
326 getShowFilterDialogAction().getFilterDialog().setLabelProvider(labelProvider
);
330 * Sets or clears the input for this time graph viewer.
332 * @param inputElement
333 * The input of this time graph viewer, or <code>null</code> if
336 public void setInput(Object inputElement
) {
337 fInputElement
= inputElement
;
338 ITimeGraphEntry
[] input
= fTimeGraphContentProvider
.getElements(inputElement
);
339 fListenerNotifier
= null;
340 if (fTimeGraphCtrl
!= null) {
343 fSelectionBegin
= SWT
.DEFAULT
;
344 fSelectionEnd
= SWT
.DEFAULT
;
345 updateBookmarkActions();
346 fSelectedEntry
= null;
347 refreshAllData(input
);
352 * Gets the input for this time graph viewer.
354 * @return The input of this time graph viewer, or <code>null</code> if none
356 public Object
getInput() {
357 return fInputElement
;
361 * Sets (or clears if null) the list of links to display on this combo
364 * the links to display in this time graph combo
366 public void setLinks(List
<ILinkEvent
> links
) {
367 if (fTimeGraphCtrl
!= null) {
368 fTimeGraphCtrl
.refreshArrows(links
);
375 public void refresh() {
376 ITimeGraphEntry
[] input
= fTimeGraphContentProvider
.getElements(fInputElement
);
378 refreshAllData(input
);
382 * Callback for when the control is moved
387 public void controlMoved(ControlEvent e
) {
391 * Callback for when the control is resized
396 public void controlResized(ControlEvent e
) {
401 * @return The string representing the view type
403 protected String
getViewTypeStr() {
404 return "viewoption.threads"; //$NON-NLS-1$
407 int getMarginWidth() {
411 int getMarginHeight() {
416 fMinTimeInterval
= 1;
417 fSelectionBegin
= SWT
.DEFAULT
;
418 fSelectionEnd
= SWT
.DEFAULT
;
419 fNameWidth
= Utils
.loadIntOption(getPreferenceString("namewidth"), //$NON-NLS-1$
420 fNameWidthPref
, fMinNameWidth
, MAX_NAME_WIDTH
);
424 Utils
.saveIntOption(getPreferenceString("namewidth"), fNameWidth
); //$NON-NLS-1$
428 * Create a data viewer.
434 * @return The new data viewer
436 protected Control
createDataViewer(Composite parent
, int style
) {
438 fColorScheme
= new TimeGraphColorScheme();
439 fDataViewer
= new Composite(parent
, style
) {
441 public void redraw() {
442 fTimeScaleCtrl
.redraw();
443 fTimeGraphCtrl
.redraw();
447 fDataViewer
.addDisposeListener(new DisposeListener() {
449 public void widgetDisposed(DisposeEvent e
) {
450 for (Color color
: fColors
) {
455 GridLayout gl
= new GridLayout(2, false);
456 gl
.marginHeight
= fBorderWidth
;
458 gl
.verticalSpacing
= 0;
459 gl
.horizontalSpacing
= 0;
460 fDataViewer
.setLayout(gl
);
462 fTimeAlignedComposite
= new Composite(fDataViewer
, style
) {
464 public void redraw() {
465 fDataViewer
.redraw();
469 GridLayout gl2
= new GridLayout(1, false);
470 gl2
.marginHeight
= fBorderWidth
;
472 gl2
.verticalSpacing
= 0;
473 gl2
.horizontalSpacing
= 0;
474 fTimeAlignedComposite
.setLayout(gl2
);
475 fTimeAlignedComposite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
477 fTimeScaleCtrl
= new TimeGraphScale(fTimeAlignedComposite
, fColorScheme
);
478 fTimeScaleCtrl
.setTimeProvider(fTimeDataProvider
);
479 fTimeScaleCtrl
.setLayoutData(new GridData(SWT
.FILL
, SWT
.DEFAULT
, true, false));
480 fTimeScaleCtrl
.setHeight(fTimeScaleHeight
);
481 fTimeScaleCtrl
.addMouseWheelListener(new MouseWheelListener() {
483 public void mouseScrolled(MouseEvent e
) {
484 fTimeGraphCtrl
.zoom(e
.count
> 0);
488 fTimeGraphCtrl
= createTimeGraphControl(fTimeAlignedComposite
, fColorScheme
);
490 fTimeGraphCtrl
.setTimeProvider(this);
491 fTimeGraphCtrl
.setTimeGraphScale(fTimeScaleCtrl
);
492 fTimeGraphCtrl
.addSelectionListener(this);
493 fTimeGraphCtrl
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
494 fTimeGraphCtrl
.addMouseWheelListener(new MouseWheelListener() {
496 public void mouseScrolled(MouseEvent e
) {
497 adjustVerticalScrollBar();
500 fTimeGraphCtrl
.addKeyListener(new KeyAdapter() {
502 public void keyPressed(KeyEvent e
) {
503 if (e
.character
== '+') {
505 } else if (e
.character
== '-') {
508 adjustVerticalScrollBar();
512 fVerticalScrollBar
= new Slider(fDataViewer
, SWT
.VERTICAL
| SWT
.NO_FOCUS
);
513 fVerticalScrollBar
.setLayoutData(new GridData(SWT
.DEFAULT
, SWT
.FILL
, false, true, 1, 1));
514 fVerticalScrollBar
.addSelectionListener(new SelectionAdapter() {
516 public void widgetSelected(SelectionEvent e
) {
517 setTopIndex(fVerticalScrollBar
.getSelection());
521 fHorizontalScrollBar
= new Slider(fDataViewer
, SWT
.HORIZONTAL
| SWT
.NO_FOCUS
);
522 fHorizontalScrollBar
.setLayoutData(new GridData(SWT
.FILL
, SWT
.DEFAULT
, true, false));
523 fHorizontalScrollBar
.addListener(SWT
.MouseWheel
, new Listener() {
525 public void handleEvent(Event event
) {
526 if ((event
.stateMask
& SWT
.MODIFIER_MASK
) == SWT
.CTRL
) {
527 getTimeGraphControl().zoom(event
.count
> 0);
529 getTimeGraphControl().horizontalScroll(event
.count
> 0);
531 // don't handle the immediately following SWT.Selection event
535 fHorizontalScrollBar
.addListener(SWT
.Selection
, new Listener() {
537 public void handleEvent(Event event
) {
538 int start
= fHorizontalScrollBar
.getSelection();
539 long time0
= getTime0();
540 long time1
= getTime1();
541 long timeMin
= getMinTime();
542 long timeMax
= getMaxTime();
543 long delta
= timeMax
- timeMin
;
545 long range
= time1
- time0
;
546 time0
= timeMin
+ Math
.round(delta
* ((double) start
/ H_SCROLLBAR_MAX
));
547 time1
= time0
+ range
;
549 setStartFinishTimeNotify(time0
, time1
);
553 Composite filler
= new Composite(fDataViewer
, SWT
.NONE
);
554 GridData gd
= new GridData(SWT
.DEFAULT
, SWT
.DEFAULT
, false, false);
555 gd
.heightHint
= fHorizontalScrollBar
.getSize().y
;
556 filler
.setLayoutData(gd
);
557 filler
.setLayout(new FillLayout());
559 fTimeGraphCtrl
.addControlListener(new ControlAdapter() {
561 public void controlResized(ControlEvent event
) {
566 fDataViewer
.update();
567 adjustHorizontalScrollBar();
568 adjustVerticalScrollBar();
575 public void dispose() {
577 fTimeGraphCtrl
.dispose();
578 fDataViewer
.dispose();
579 fColorScheme
.dispose();
583 * Create a new time graph control.
586 * The parent composite
589 * @return The new TimeGraphControl
591 protected TimeGraphControl
createTimeGraphControl(Composite parent
,
592 TimeGraphColorScheme colors
) {
593 return new TimeGraphControl(parent
, colors
);
597 * Resize the controls
599 public void resizeControls() {
600 Rectangle r
= fDataViewer
.getClientArea();
606 if (fNameWidth
> width
- fMinNameWidth
) {
607 fNameWidth
= width
- fMinNameWidth
;
609 if (fNameWidth
< fMinNameWidth
) {
610 fNameWidth
= fMinNameWidth
;
612 adjustHorizontalScrollBar();
613 adjustVerticalScrollBar();
617 * Recalculate the time bounds based on the time graph entries,
618 * if the user-specified bound is set to SWT.DEFAULT.
621 * The root time graph entries in the model
623 public void setTimeRange(ITimeGraphEntry entries
[]) {
624 fTime0Bound
= (fBeginTime
!= SWT
.DEFAULT ? fBeginTime
: fEndTime
);
625 fTime1Bound
= (fEndTime
!= SWT
.DEFAULT ? fEndTime
: fBeginTime
);
626 if (fBeginTime
!= SWT
.DEFAULT
&& fEndTime
!= SWT
.DEFAULT
) {
629 if (entries
== null || entries
.length
== 0) {
632 if (fTime0Bound
== SWT
.DEFAULT
) {
633 fTime0Bound
= Long
.MAX_VALUE
;
635 if (fTime1Bound
== SWT
.DEFAULT
) {
636 fTime1Bound
= Long
.MIN_VALUE
;
638 for (ITimeGraphEntry entry
: entries
) {
643 private void setTimeRange(ITimeGraphEntry entry
) {
644 if (fBeginTime
== SWT
.DEFAULT
&& entry
.hasTimeEvents() && entry
.getStartTime() != SWT
.DEFAULT
) {
645 fTime0Bound
= Math
.min(entry
.getStartTime(), fTime0Bound
);
647 if (fEndTime
== SWT
.DEFAULT
&& entry
.hasTimeEvents() && entry
.getEndTime() != SWT
.DEFAULT
) {
648 fTime1Bound
= Math
.max(entry
.getEndTime(), fTime1Bound
);
650 if (entry
.hasChildren()) {
651 for (ITimeGraphEntry child
: entry
.getChildren()) {
658 * Set the time bounds to the provided values.
661 * The bounds begin time, or SWT.DEFAULT to use the input bounds
663 * The bounds end time, or SWT.DEFAULT to use the input bounds
665 public void setTimeBounds(long beginTime
, long endTime
) {
666 fBeginTime
= beginTime
;
668 fTime0Bound
= (fBeginTime
!= SWT
.DEFAULT ? fBeginTime
: fEndTime
);
669 fTime1Bound
= (fEndTime
!= SWT
.DEFAULT ? fEndTime
: fBeginTime
);
670 if (fTime0Bound
> fTime1Bound
) {
671 // only possible if both are not default
672 fBeginTime
= endTime
;
673 fEndTime
= beginTime
;
674 fTime0Bound
= fBeginTime
;
675 fTime1Bound
= fEndTime
;
677 adjustHorizontalScrollBar();
681 * Recalculate the current time window when bounds have changed.
683 public void setTimeBounds() {
684 if (!fTimeRangeFixed
) {
685 fTime0
= fTime0Bound
;
686 fTime1
= fTime1Bound
;
688 fTime0
= Math
.max(fTime0Bound
, Math
.min(fTime0
, fTime1Bound
));
689 fTime1
= Math
.max(fTime0Bound
, Math
.min(fTime1
, fTime1Bound
));
690 if (fTime1
- fTime0
< fMinTimeInterval
) {
691 fTime1
= Math
.min(fTime1Bound
, fTime0
+ fMinTimeInterval
);
698 private void refreshAllData(ITimeGraphEntry
[] traces
) {
700 if (fSelectionBegin
< fBeginTime
) {
701 fSelectionBegin
= fBeginTime
;
702 } else if (fSelectionBegin
> fEndTime
) {
703 fSelectionBegin
= fEndTime
;
705 if (fSelectionEnd
< fBeginTime
) {
706 fSelectionEnd
= fBeginTime
;
707 } else if (fSelectionEnd
> fEndTime
) {
708 fSelectionEnd
= fEndTime
;
710 fTimeGraphCtrl
.refreshData(traces
);
711 fTimeScaleCtrl
.redraw();
712 updateBookmarkActions();
713 adjustVerticalScrollBar();
717 * Callback for when this view is focused
719 public void setFocus() {
720 if (null != fTimeGraphCtrl
) {
721 fTimeGraphCtrl
.setFocus();
726 * Get the current focus status of this view.
728 * @return If the view is currently focused, or not
730 public boolean isInFocus() {
731 return fTimeGraphCtrl
.isInFocus();
735 * Get the view's current selection
737 * @return The entry that is selected
739 public ITimeGraphEntry
getSelection() {
740 return fTimeGraphCtrl
.getSelectedTrace();
744 * Get the index of the current selection
748 public int getSelectionIndex() {
749 return fTimeGraphCtrl
.getSelectedIndex();
753 public long getTime0() {
758 public long getTime1() {
763 public long getMinTimeInterval() {
764 return fMinTimeInterval
;
768 public int getNameSpace() {
773 public void setNameSpace(int width
) {
775 int w
= fTimeGraphCtrl
.getClientArea().width
;
776 if (fNameWidth
> w
- MIN_NAME_WIDTH
) {
777 fNameWidth
= w
- MIN_NAME_WIDTH
;
779 if (fNameWidth
< MIN_NAME_WIDTH
) {
780 fNameWidth
= MIN_NAME_WIDTH
;
782 fTimeGraphCtrl
.redraw();
783 fTimeScaleCtrl
.redraw();
787 public int getTimeSpace() {
788 int w
= fTimeGraphCtrl
.getClientArea().width
;
789 return w
- fNameWidth
;
793 public long getBeginTime() {
798 public long getEndTime() {
803 public long getMaxTime() {
808 public long getMinTime() {
813 public long getSelectionBegin() {
814 return fSelectionBegin
;
818 public long getSelectionEnd() {
819 return fSelectionEnd
;
823 public void setStartFinishTimeNotify(long time0
, long time1
) {
824 setStartFinishTimeInt(time0
, time1
);
825 notifyRangeListeners();
829 public void notifyStartFinishTime() {
830 notifyRangeListeners();
834 public void setStartFinishTime(long time0
, long time1
) {
835 /* if there is a pending time range, ignore this one */
836 if (fListenerNotifier
!= null && fListenerNotifier
.hasTimeRangeUpdated()) {
839 setStartFinishTimeInt(time0
, time1
);
840 updateExtSynchValues();
843 private void setStartFinishTimeInt(long time0
, long time1
) {
845 if (fTime0
< fTime0Bound
) {
846 fTime0
= fTime0Bound
;
848 if (fTime0
> fTime1Bound
) {
849 fTime0
= fTime1Bound
;
852 if (fTime1
< fTime0Bound
) {
853 fTime1
= fTime0Bound
;
855 if (fTime1
> fTime1Bound
) {
856 fTime1
= fTime1Bound
;
858 if (fTime1
- fTime0
< fMinTimeInterval
) {
859 fTime1
= Math
.min(fTime1Bound
, fTime0
+ fMinTimeInterval
);
861 fTimeRangeFixed
= true;
862 adjustHorizontalScrollBar();
863 fTimeGraphCtrl
.redraw();
864 fTimeScaleCtrl
.redraw();
868 public void resetStartFinishTime() {
869 setStartFinishTimeNotify(fTime0Bound
, fTime1Bound
);
870 fTimeRangeFixed
= false;
874 public void setSelectedTimeNotify(long time
, boolean ensureVisible
) {
875 setSelectedTimeInt(time
, ensureVisible
, true);
879 public void setSelectedTime(long time
, boolean ensureVisible
) {
880 /* if there is a pending time selection, ignore this one */
881 if (fListenerNotifier
!= null && fListenerNotifier
.hasTimeSelected()) {
884 setSelectedTimeInt(time
, ensureVisible
, false);
888 public void setSelectionRangeNotify(long beginTime
, long endTime
) {
891 long selectionBegin
= fSelectionBegin
;
892 long selectionEnd
= fSelectionEnd
;
893 fSelectionBegin
= Math
.max(fTime0Bound
, Math
.min(fTime1Bound
, beginTime
));
894 fSelectionEnd
= Math
.max(fTime0Bound
, Math
.min(fTime1Bound
, endTime
));
895 boolean changed
= (selectionBegin
!= fSelectionBegin
|| selectionEnd
!= fSelectionEnd
);
896 ensureVisible(fSelectionEnd
);
897 fTimeGraphCtrl
.redraw();
898 fTimeScaleCtrl
.redraw();
899 updateBookmarkActions();
900 if ((time0
!= fTime0
) || (time1
!= fTime1
)) {
901 notifyRangeListeners();
904 notifyTimeListeners();
909 public void setSelectionRange(long beginTime
, long endTime
) {
910 /* if there is a pending time selection, ignore this one */
911 if (fListenerNotifier
!= null && fListenerNotifier
.hasTimeSelected()) {
914 fSelectionBegin
= Math
.max(fTime0Bound
, Math
.min(fTime1Bound
, beginTime
));
915 fSelectionEnd
= Math
.max(fTime0Bound
, Math
.min(fTime1Bound
, endTime
));
916 fTimeGraphCtrl
.redraw();
917 fTimeScaleCtrl
.redraw();
918 updateBookmarkActions();
921 private void setSelectedTimeInt(long time
, boolean ensureVisible
, boolean doNotify
) {
922 long selection
= Math
.max(fTime0Bound
, Math
.min(fTime1Bound
, time
));
926 ensureVisible(selection
);
928 fTimeGraphCtrl
.redraw();
929 fTimeScaleCtrl
.redraw();
931 boolean notifySelectedTime
= (selection
!= fSelectionBegin
|| selection
!= fSelectionEnd
);
932 fSelectionBegin
= selection
;
933 fSelectionEnd
= selection
;
934 updateBookmarkActions();
936 if ((time0
!= fTime0
) || (time1
!= fTime1
)) {
937 notifyRangeListeners();
940 if (doNotify
&& notifySelectedTime
) {
941 notifyTimeListeners();
945 private void ensureVisible(long time
) {
946 long timeMid
= (fTime1
- fTime0
) / 2;
948 long dt
= fTime0
- time
+ timeMid
;
951 } else if (time
> fTime1
) {
952 long dt
= time
- fTime1
+ timeMid
;
956 if (fTime0
< fTime0Bound
) {
957 fTime1
= Math
.min(fTime1Bound
, fTime1
+ (fTime0Bound
- fTime0
));
958 fTime0
= fTime0Bound
;
959 } else if (fTime1
> fTime1Bound
) {
960 fTime0
= Math
.max(fTime0Bound
, fTime0
- (fTime1
- fTime1Bound
));
961 fTime1
= fTime1Bound
;
963 if (fTime1
- fTime0
< fMinTimeInterval
) {
964 fTime1
= Math
.min(fTime1Bound
, fTime0
+ fMinTimeInterval
);
966 adjustHorizontalScrollBar();
970 public void widgetDefaultSelected(SelectionEvent e
) {
971 if (fSelectedEntry
!= getSelection()) {
972 fSelectedEntry
= getSelection();
973 notifySelectionListeners();
978 public void widgetSelected(SelectionEvent e
) {
979 if (fSelectedEntry
!= getSelection()) {
980 fSelectedEntry
= getSelection();
981 notifySelectionListeners();
986 * Callback for when the next event is selected
989 * true to extend selection range, false for single selection
992 public void selectNextEvent(boolean extend
) {
993 fTimeGraphCtrl
.selectNextEvent(extend
);
994 adjustVerticalScrollBar();
998 * Callback for when the previous event is selected
1001 * true to extend selection range, false for single selection
1004 public void selectPrevEvent(boolean extend
) {
1005 fTimeGraphCtrl
.selectPrevEvent(extend
);
1006 adjustVerticalScrollBar();
1010 * Callback for when the next item is selected
1012 public void selectNextItem() {
1013 fTimeGraphCtrl
.selectNextTrace();
1014 adjustVerticalScrollBar();
1018 * Callback for when the previous item is selected
1020 public void selectPrevItem() {
1021 fTimeGraphCtrl
.selectPrevTrace();
1022 adjustVerticalScrollBar();
1026 * Callback for the show legend action
1028 public void showLegend() {
1029 if (fDataViewer
== null || fDataViewer
.isDisposed()) {
1033 TimeGraphLegend
.open(fDataViewer
.getShell(), fTimeGraphProvider
);
1037 * Callback for the Zoom In action
1039 public void zoomIn() {
1040 fTimeGraphCtrl
.zoomIn();
1044 * Callback for the Zoom Out action
1046 public void zoomOut() {
1047 fTimeGraphCtrl
.zoomOut();
1050 private String
getPreferenceString(String string
) {
1051 return getViewTypeStr() + "." + string
; //$NON-NLS-1$
1055 * Add a selection listener
1058 * The listener to add
1060 public void addSelectionListener(ITimeGraphSelectionListener listener
) {
1061 fSelectionListeners
.add(listener
);
1065 * Remove a selection listener
1068 * The listener to remove
1070 public void removeSelectionListener(ITimeGraphSelectionListener listener
) {
1071 fSelectionListeners
.remove(listener
);
1074 private void notifySelectionListeners() {
1075 if (fListenerNotifier
== null) {
1076 fListenerNotifier
= new ListenerNotifier();
1077 fListenerNotifier
.start();
1079 fListenerNotifier
.selectionChanged();
1082 private void fireSelectionChanged(ITimeGraphEntry selection
) {
1083 TimeGraphSelectionEvent event
= new TimeGraphSelectionEvent(this, selection
);
1085 for (ITimeGraphSelectionListener listener
: fSelectionListeners
) {
1086 listener
.selectionChanged(event
);
1091 * Add a time listener
1094 * The listener to add
1096 public void addTimeListener(ITimeGraphTimeListener listener
) {
1097 fTimeListeners
.add(listener
);
1101 * Remove a time listener
1104 * The listener to remove
1106 public void removeTimeListener(ITimeGraphTimeListener listener
) {
1107 fTimeListeners
.remove(listener
);
1110 private void notifyTimeListeners() {
1111 if (fListenerNotifier
== null) {
1112 fListenerNotifier
= new ListenerNotifier();
1113 fListenerNotifier
.start();
1115 fListenerNotifier
.timeSelected();
1118 private void fireTimeSelected(long startTime
, long endTime
) {
1119 TimeGraphTimeEvent event
= new TimeGraphTimeEvent(this, startTime
, endTime
);
1121 for (ITimeGraphTimeListener listener
: fTimeListeners
) {
1122 listener
.timeSelected(event
);
1127 * Add a range listener
1130 * The listener to add
1132 public void addRangeListener(ITimeGraphRangeListener listener
) {
1133 fRangeListeners
.add(listener
);
1137 * Remove a range listener
1140 * The listener to remove
1142 public void removeRangeListener(ITimeGraphRangeListener listener
) {
1143 fRangeListeners
.remove(listener
);
1146 private void notifyRangeListeners() {
1147 if (fListenerNotifier
== null) {
1148 fListenerNotifier
= new ListenerNotifier();
1149 fListenerNotifier
.start();
1151 fListenerNotifier
.timeRangeUpdated();
1154 private void fireTimeRangeUpdated(long startTime
, long endTime
) {
1155 // Check if the time has actually changed from last notification
1156 if (startTime
!= fTime0ExtSynch
|| endTime
!= fTime1ExtSynch
) {
1157 // Notify Time Scale Selection Listeners
1158 TimeGraphRangeUpdateEvent event
= new TimeGraphRangeUpdateEvent(this, startTime
, endTime
);
1160 for (ITimeGraphRangeListener listener
: fRangeListeners
) {
1161 listener
.timeRangeUpdated(event
);
1164 // update external synch values
1165 updateExtSynchValues();
1170 * Add a bookmark listener
1173 * The listener to add
1176 public void addBookmarkListener(ITimeGraphBookmarkListener listener
) {
1177 fBookmarkListeners
.add(listener
);
1181 * Remove a bookmark listener
1184 * The listener to remove
1187 public void removeBookmarkListener(ITimeGraphBookmarkListener listener
) {
1188 fBookmarkListeners
.remove(listener
);
1191 private void fireBookmarkAdded(IMarkerEvent bookmark
) {
1192 TimeGraphBookmarkEvent event
= new TimeGraphBookmarkEvent(this, bookmark
);
1194 for (ITimeGraphBookmarkListener listener
: fBookmarkListeners
) {
1195 listener
.bookmarkAdded(event
);
1199 private void fireBookmarkRemoved(IMarkerEvent bookmark
) {
1200 TimeGraphBookmarkEvent event
= new TimeGraphBookmarkEvent(this, bookmark
);
1202 for (ITimeGraphBookmarkListener listener
: fBookmarkListeners
) {
1203 listener
.bookmarkRemoved(event
);
1208 * Set the bookmarks list.
1211 * The bookmarks list, or null
1214 public void setBookmarks(List
<IMarkerEvent
> bookmarks
) {
1215 for (IMarkerEvent bookmark
: fBookmarks
) {
1216 checkDisposeColor(bookmark
.getColor());
1219 if (bookmarks
!= null) {
1220 fBookmarks
.addAll(bookmarks
);
1221 Collections
.sort(fBookmarks
, new BookmarkComparator());
1223 updateBookmarkActions();
1224 getTimeGraphControl().setBookmarks(bookmarks
);
1228 * Get the bookmarks list.
1230 * @return The bookmarks list
1233 public List
<IMarkerEvent
> getBookmarks() {
1234 return Collections
.unmodifiableList(fBookmarks
);
1238 * Dispose the color resource if and only if it was created by this viewer.
1243 private void checkDisposeColor(Color color
) {
1244 for (int i
= 0; i
< fColors
.size(); i
++) {
1245 /* check for identity, not equality */
1246 if (fColors
.get(i
) == color
) {
1255 * Callback to set a selected event in the view
1258 * The event that was selected
1260 * The source of this selection event
1262 public void setSelectedEvent(ITimeEvent event
, Object source
) {
1263 if (event
== null || source
== this) {
1266 fSelectedEntry
= event
.getEntry();
1267 fTimeGraphCtrl
.selectItem(fSelectedEntry
, false);
1269 setSelectedTimeInt(event
.getTime(), true, true);
1270 adjustVerticalScrollBar();
1274 * Set the seeked time of a trace
1277 * The trace that was seeked
1281 * The source of this seek event
1283 public void setSelectedTraceTime(ITimeGraphEntry trace
, long time
, Object source
) {
1284 if (trace
== null || source
== this) {
1287 fSelectedEntry
= trace
;
1288 fTimeGraphCtrl
.selectItem(trace
, false);
1290 setSelectedTimeInt(time
, true, true);
1294 * Callback for a trace selection
1297 * The trace that was selected
1299 public void setSelection(ITimeGraphEntry trace
) {
1300 /* if there is a pending selection, ignore this one */
1301 if (fListenerNotifier
!= null && fListenerNotifier
.hasSelectionChanged()) {
1304 fSelectedEntry
= trace
;
1305 fTimeGraphCtrl
.selectItem(trace
, false);
1306 adjustVerticalScrollBar();
1310 * Callback for a time window selection
1313 * Start time of the range
1315 * End time of the range
1317 * Source of the event
1319 public void setSelectVisTimeWindow(long time0
, long time1
, Object source
) {
1320 if (source
== this) {
1324 setStartFinishTimeInt(time0
, time1
);
1326 // update notification time values since we are now in synch with the
1327 // external application
1328 updateExtSynchValues();
1332 * update the cache values used to identify the need to send a time window
1333 * update to external registered listeners
1335 private void updateExtSynchValues() {
1336 // last time notification cache
1337 fTime0ExtSynch
= fTime0
;
1338 fTime1ExtSynch
= fTime1
;
1342 public TimeFormat
getTimeFormat() {
1348 * the {@link TimeFormat} used to display timestamps
1350 public void setTimeFormat(TimeFormat tf
) {
1351 this.fTimeFormat
= tf
;
1352 if (tf
== TimeFormat
.CYCLES
) {
1353 fTimeDataProvider
= new TimeDataProviderCyclesConverter(this, fClockFrequency
);
1355 fTimeDataProvider
= this;
1357 fTimeScaleCtrl
.setTimeProvider(fTimeDataProvider
);
1358 if (fToolTipHandler
!= null) {
1359 fToolTipHandler
.setTimeProvider(fTimeDataProvider
);
1364 * Sets the clock frequency. Used when the time format is set to CYCLES.
1366 * @param clockFrequency
1367 * the clock frequency in Hz
1369 public void setClockFrequency(long clockFrequency
) {
1370 fClockFrequency
= clockFrequency
;
1371 if (fTimeFormat
== TimeFormat
.CYCLES
) {
1372 fTimeDataProvider
= new TimeDataProviderCyclesConverter(this, fClockFrequency
);
1373 fTimeScaleCtrl
.setTimeProvider(fTimeDataProvider
);
1374 if (fToolTipHandler
!= null) {
1375 fToolTipHandler
.setTimeProvider(fTimeDataProvider
);
1381 * Retrieve the border width
1385 public int getBorderWidth() {
1386 return fBorderWidth
;
1390 * Set the border width
1392 * @param borderWidth
1395 public void setBorderWidth(int borderWidth
) {
1396 if (borderWidth
> -1) {
1397 this.fBorderWidth
= borderWidth
;
1398 GridLayout gl
= (GridLayout
) fDataViewer
.getLayout();
1399 gl
.marginHeight
= borderWidth
;
1404 * Retrieve the height of the header
1406 * @return The height
1408 public int getHeaderHeight() {
1409 return fTimeScaleHeight
;
1413 * Set the height of the header
1415 * @param headerHeight
1418 public void setHeaderHeight(int headerHeight
) {
1419 if (headerHeight
> -1) {
1420 this.fTimeScaleHeight
= headerHeight
;
1421 fTimeScaleCtrl
.setHeight(headerHeight
);
1426 * Retrieve the height of an item row
1428 * @return The height
1430 public int getItemHeight() {
1431 if (fTimeGraphCtrl
!= null) {
1432 return fTimeGraphCtrl
.getItemHeight();
1438 * Set the height of an item row
1443 public void setItemHeight(int rowHeight
) {
1444 if (fTimeGraphCtrl
!= null) {
1445 fTimeGraphCtrl
.setItemHeight(rowHeight
);
1450 * Set the minimum item width
1455 public void setMinimumItemWidth(int width
) {
1456 if (fTimeGraphCtrl
!= null) {
1457 fTimeGraphCtrl
.setMinimumItemWidth(width
);
1462 * Set the width for the name column
1467 public void setNameWidthPref(int width
) {
1468 fNameWidthPref
= width
;
1476 * Retrieve the configure width for the name column
1482 public int getNameWidthPref(int width
) {
1483 return fNameWidthPref
;
1487 * Returns the primary control associated with this viewer.
1489 * @return the SWT control which displays this viewer's content
1491 public Control
getControl() {
1496 * Returns the time graph control associated with this viewer.
1498 * @return the time graph control
1500 public TimeGraphControl
getTimeGraphControl() {
1501 return fTimeGraphCtrl
;
1505 * Returns the time graph scale associated with this viewer.
1507 * @return the time graph scale
1509 public TimeGraphScale
getTimeGraphScale() {
1510 return fTimeScaleCtrl
;
1514 * Returns the composite containing all the controls that are time aligned,
1515 * i.e. TimeGraphScale, TimeGraphControl.
1517 * @return the time based composite
1520 public Composite
getTimeAlignedComposite() {
1521 return fTimeAlignedComposite
;
1525 * Return the x coordinate corresponding to a time
1529 * @return the x coordinate corresponding to the time
1531 public int getXForTime(long time
) {
1532 return fTimeGraphCtrl
.getXForTime(time
);
1536 * Return the time corresponding to an x coordinate
1540 * @return the time corresponding to the x coordinate
1542 public long getTimeAtX(int x
) {
1543 return fTimeGraphCtrl
.getTimeAtX(x
);
1547 * Get the selection provider
1549 * @return the selection provider
1551 public ISelectionProvider
getSelectionProvider() {
1552 return fTimeGraphCtrl
;
1556 * Wait for the cursor
1559 * Wait indefinitely?
1561 public void waitCursor(boolean waitInd
) {
1562 fTimeGraphCtrl
.waitCursor(waitInd
);
1566 * Get the horizontal scroll bar object
1568 * @return The scroll bar
1570 public Slider
getHorizontalBar() {
1571 return fHorizontalScrollBar
;
1575 * Get the vertical scroll bar object
1577 * @return The scroll bar
1579 public Slider
getVerticalBar() {
1580 return fVerticalScrollBar
;
1584 * Set the given index as the top one
1587 * The index that will go to the top
1589 public void setTopIndex(int index
) {
1590 fTimeGraphCtrl
.setTopIndex(index
);
1591 adjustVerticalScrollBar();
1595 * Retrieve the current top index
1597 * @return The top index
1599 public int getTopIndex() {
1600 return fTimeGraphCtrl
.getTopIndex();
1604 * Sets the auto-expand level to be used for new entries discovered when
1605 * calling {@link #setInput(Object)} or {@link #refresh()}. The value 0
1606 * means that there is no auto-expand; 1 means that top-level entries are
1607 * expanded, but not their children; 2 means that top-level entries are
1608 * expanded, and their children, but not grand-children; and so on.
1610 * The value {@link #ALL_LEVELS} means that all subtrees should be expanded.
1614 * non-negative level, or <code>ALL_LEVELS</code> to expand all
1615 * levels of the tree
1617 public void setAutoExpandLevel(int level
) {
1618 fTimeGraphCtrl
.setAutoExpandLevel(level
);
1622 * Returns the auto-expand level.
1624 * @return non-negative level, or <code>ALL_LEVELS</code> if all levels of
1625 * the tree are expanded automatically
1626 * @see #setAutoExpandLevel
1628 public int getAutoExpandLevel() {
1629 return fTimeGraphCtrl
.getAutoExpandLevel();
1633 * Get the expanded state of an entry.
1637 * @return true if the entry is expanded, false if collapsed
1640 public boolean getExpandedState(ITimeGraphEntry entry
) {
1641 return fTimeGraphCtrl
.getExpandedState(entry
);
1645 * Set the expanded state of an entry
1648 * The entry to expand/collapse
1650 * True for expanded, false for collapsed
1652 public void setExpandedState(ITimeGraphEntry entry
, boolean expanded
) {
1653 fTimeGraphCtrl
.setExpandedState(entry
, expanded
);
1654 adjustVerticalScrollBar();
1658 * Collapses all nodes of the viewer's tree, starting with the root.
1660 public void collapseAll() {
1661 fTimeGraphCtrl
.collapseAll();
1662 adjustVerticalScrollBar();
1666 * Expands all entries of the viewer's tree, starting with the root.
1668 public void expandAll() {
1669 fTimeGraphCtrl
.expandAll();
1670 adjustVerticalScrollBar();
1674 * Get the number of expanded (visible) time graph entries. This includes
1675 * leafs and does not include filtered-out entries.
1677 * @return The number of expanded (visible) time graph entries
1679 public int getExpandedElementCount() {
1680 return fTimeGraphCtrl
.getExpandedElementCount();
1684 * Get the expanded (visible) time graph entries. This includes leafs and
1685 * does not include filtered-out entries.
1687 * @return The array of expanded (visible) time graph entries
1689 public ITimeGraphEntry
[] getExpandedElements() {
1690 return fTimeGraphCtrl
.getExpandedElements();
1694 * Add a tree listener
1697 * The listener to add
1699 public void addTreeListener(ITimeGraphTreeListener listener
) {
1700 fTimeGraphCtrl
.addTreeListener(listener
);
1704 * Remove a tree listener
1707 * The listener to remove
1709 public void removeTreeListener(ITimeGraphTreeListener listener
) {
1710 fTimeGraphCtrl
.removeTreeListener(listener
);
1714 * Get the reset scale action.
1716 * @return The Action object
1718 public Action
getResetScaleAction() {
1719 if (fResetScaleAction
== null) {
1721 fResetScaleAction
= new Action() {
1724 resetStartFinishTime();
1727 fResetScaleAction
.setText(Messages
.TmfTimeGraphViewer_ResetScaleActionNameText
);
1728 fResetScaleAction
.setToolTipText(Messages
.TmfTimeGraphViewer_ResetScaleActionToolTipText
);
1729 fResetScaleAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_HOME_MENU
));
1731 return fResetScaleAction
;
1735 * Get the show legend action.
1737 * @return The Action object
1739 public Action
getShowLegendAction() {
1740 if (fShowLegendAction
== null) {
1742 fShowLegendAction
= new Action() {
1748 fShowLegendAction
.setText(Messages
.TmfTimeGraphViewer_LegendActionNameText
);
1749 fShowLegendAction
.setToolTipText(Messages
.TmfTimeGraphViewer_LegendActionToolTipText
);
1750 fShowLegendAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_SHOW_LEGEND
));
1753 return fShowLegendAction
;
1757 * Get the the next event action.
1759 * @return The action object
1761 public Action
getNextEventAction() {
1762 if (fNextEventAction
== null) {
1763 fNextEventAction
= new Action() {
1765 public void runWithEvent(Event event
) {
1766 boolean extend
= (event
.stateMask
& SWT
.SHIFT
) != 0;
1767 selectNextEvent(extend
);
1771 fNextEventAction
.setText(Messages
.TmfTimeGraphViewer_NextEventActionNameText
);
1772 fNextEventAction
.setToolTipText(Messages
.TmfTimeGraphViewer_NextEventActionToolTipText
);
1773 fNextEventAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_NEXT_EVENT
));
1776 return fNextEventAction
;
1780 * Get the previous event action.
1782 * @return The Action object
1784 public Action
getPreviousEventAction() {
1785 if (fPrevEventAction
== null) {
1786 fPrevEventAction
= new Action() {
1788 public void runWithEvent(Event event
) {
1789 boolean extend
= (event
.stateMask
& SWT
.SHIFT
) != 0;
1790 selectPrevEvent(extend
);
1794 fPrevEventAction
.setText(Messages
.TmfTimeGraphViewer_PreviousEventActionNameText
);
1795 fPrevEventAction
.setToolTipText(Messages
.TmfTimeGraphViewer_PreviousEventActionToolTipText
);
1796 fPrevEventAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_PREV_EVENT
));
1799 return fPrevEventAction
;
1803 * Get the next item action.
1805 * @return The Action object
1807 public Action
getNextItemAction() {
1808 if (fNextItemAction
== null) {
1810 fNextItemAction
= new Action() {
1816 fNextItemAction
.setText(Messages
.TmfTimeGraphViewer_NextItemActionNameText
);
1817 fNextItemAction
.setToolTipText(Messages
.TmfTimeGraphViewer_NextItemActionToolTipText
);
1818 fNextItemAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_NEXT_ITEM
));
1820 return fNextItemAction
;
1824 * Get the previous item action.
1826 * @return The Action object
1828 public Action
getPreviousItemAction() {
1829 if (fPreviousItemAction
== null) {
1831 fPreviousItemAction
= new Action() {
1837 fPreviousItemAction
.setText(Messages
.TmfTimeGraphViewer_PreviousItemActionNameText
);
1838 fPreviousItemAction
.setToolTipText(Messages
.TmfTimeGraphViewer_PreviousItemActionToolTipText
);
1839 fPreviousItemAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_PREV_ITEM
));
1841 return fPreviousItemAction
;
1845 * Get the zoom in action
1847 * @return The Action object
1849 public Action
getZoomInAction() {
1850 if (fZoomInAction
== null) {
1851 fZoomInAction
= new Action() {
1857 fZoomInAction
.setText(Messages
.TmfTimeGraphViewer_ZoomInActionNameText
);
1858 fZoomInAction
.setToolTipText(Messages
.TmfTimeGraphViewer_ZoomInActionToolTipText
);
1859 fZoomInAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_ZOOM_IN_MENU
));
1861 return fZoomInAction
;
1865 * Get the zoom out action
1867 * @return The Action object
1869 public Action
getZoomOutAction() {
1870 if (fZoomOutAction
== null) {
1871 fZoomOutAction
= new Action() {
1877 fZoomOutAction
.setText(Messages
.TmfTimeGraphViewer_ZoomOutActionNameText
);
1878 fZoomOutAction
.setToolTipText(Messages
.TmfTimeGraphViewer_ZoomOutActionToolTipText
);
1879 fZoomOutAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_ZOOM_OUT_MENU
));
1881 return fZoomOutAction
;
1885 * Get the hide arrows action
1887 * @param dialogSettings
1888 * The dialog settings section where the state should be stored,
1891 * @return The Action object
1893 public Action
getHideArrowsAction(final IDialogSettings dialogSettings
) {
1894 if (fHideArrowsAction
== null) {
1895 fHideArrowsAction
= new Action(Messages
.TmfTimeGraphViewer_HideArrowsActionNameText
, IAction
.AS_CHECK_BOX
) {
1898 boolean hideArrows
= fHideArrowsAction
.isChecked();
1899 fTimeGraphCtrl
.hideArrows(hideArrows
);
1901 if (dialogSettings
!= null) {
1902 dialogSettings
.put(HIDE_ARROWS_KEY
, hideArrows
);
1904 if (fFollowArrowFwdAction
!= null) {
1905 fFollowArrowFwdAction
.setEnabled(!hideArrows
);
1907 if (fFollowArrowBwdAction
!= null) {
1908 fFollowArrowBwdAction
.setEnabled(!hideArrows
);
1912 fHideArrowsAction
.setToolTipText(Messages
.TmfTimeGraphViewer_HideArrowsActionToolTipText
);
1913 fHideArrowsAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_HIDE_ARROWS
));
1914 if (dialogSettings
!= null) {
1915 boolean hideArrows
= dialogSettings
.getBoolean(HIDE_ARROWS_KEY
);
1916 fTimeGraphCtrl
.hideArrows(hideArrows
);
1917 fHideArrowsAction
.setChecked(hideArrows
);
1918 if (fFollowArrowFwdAction
!= null) {
1919 fFollowArrowFwdAction
.setEnabled(!hideArrows
);
1921 if (fFollowArrowBwdAction
!= null) {
1922 fFollowArrowBwdAction
.setEnabled(!hideArrows
);
1926 return fHideArrowsAction
;
1930 * Get the follow arrow forward action.
1932 * @return The Action object
1934 public Action
getFollowArrowFwdAction() {
1935 if (fFollowArrowFwdAction
== null) {
1936 fFollowArrowFwdAction
= new Action() {
1938 public void runWithEvent(Event event
) {
1939 boolean extend
= (event
.stateMask
& SWT
.SHIFT
) != 0;
1940 fTimeGraphCtrl
.followArrowFwd(extend
);
1941 adjustVerticalScrollBar();
1944 fFollowArrowFwdAction
.setText(Messages
.TmfTimeGraphViewer_FollowArrowForwardActionNameText
);
1945 fFollowArrowFwdAction
.setToolTipText(Messages
.TmfTimeGraphViewer_FollowArrowForwardActionToolTipText
);
1946 fFollowArrowFwdAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_FOLLOW_ARROW_FORWARD
));
1947 if (fHideArrowsAction
!= null) {
1948 fFollowArrowFwdAction
.setEnabled(!fHideArrowsAction
.isChecked());
1951 return fFollowArrowFwdAction
;
1955 * Get the follow arrow backward action.
1957 * @return The Action object
1959 public Action
getFollowArrowBwdAction() {
1960 if (fFollowArrowBwdAction
== null) {
1961 fFollowArrowBwdAction
= new Action() {
1963 public void runWithEvent(Event event
) {
1964 boolean extend
= (event
.stateMask
& SWT
.SHIFT
) != 0;
1965 fTimeGraphCtrl
.followArrowBwd(extend
);
1966 adjustVerticalScrollBar();
1969 fFollowArrowBwdAction
.setText(Messages
.TmfTimeGraphViewer_FollowArrowBackwardActionNameText
);
1970 fFollowArrowBwdAction
.setToolTipText(Messages
.TmfTimeGraphViewer_FollowArrowBackwardActionToolTipText
);
1971 fFollowArrowBwdAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_FOLLOW_ARROW_BACKWARD
));
1972 if (fHideArrowsAction
!= null) {
1973 fFollowArrowBwdAction
.setEnabled(!fHideArrowsAction
.isChecked());
1976 return fFollowArrowBwdAction
;
1980 * Get the show filter dialog action.
1982 * @return The Action object
1985 public ShowFilterDialogAction
getShowFilterDialogAction() {
1986 if (fShowFilterDialogAction
== null) {
1987 fShowFilterDialogAction
= new ShowFilterDialogAction(this);
1989 return fShowFilterDialogAction
;
1993 * Get the toggle bookmark action.
1995 * @return The Action object
1998 public Action
getToggleBookmarkAction() {
1999 if (fToggleBookmarkAction
== null) {
2000 fToggleBookmarkAction
= new Action() {
2002 public void runWithEvent(Event event
) {
2003 IMarkerEvent selectedBookmark
= getBookmarkAtSelection();
2004 if (selectedBookmark
== null) {
2005 final long time
= Math
.min(fSelectionBegin
, fSelectionEnd
);
2006 final long duration
= Math
.max(fSelectionBegin
, fSelectionEnd
) - time
;
2007 final AddBookmarkDialog dialog
= new AddBookmarkDialog(PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getShell());
2008 if (dialog
.open() == Window
.OK
) {
2009 final String label
= dialog
.getValue();
2010 final RGBA rgba
= dialog
.getColorValue();
2011 Color color
= new Color(Display
.getDefault(), rgba
.rgb
.red
, rgba
.rgb
.green
, rgba
.rgb
.blue
, rgba
.alpha
);
2013 IMarkerEvent bookmark
= new MarkerEvent(null, time
, duration
, color
, label
, true);
2014 fBookmarks
.add(bookmark
);
2015 Collections
.sort(fBookmarks
, new BookmarkComparator());
2016 getTimeGraphControl().setBookmarks(fBookmarks
);
2017 getControl().redraw();
2018 fireBookmarkAdded(bookmark
);
2021 checkDisposeColor(selectedBookmark
.getColor());
2022 fBookmarks
.remove(selectedBookmark
);
2023 getTimeGraphControl().setBookmarks(fBookmarks
);
2024 getControl().redraw();
2025 fireBookmarkRemoved(selectedBookmark
);
2027 updateBookmarkActions();
2030 fToggleBookmarkAction
.setText(Messages
.TmfTimeGraphViewer_BookmarkActionAddText
);
2031 fToggleBookmarkAction
.setToolTipText(Messages
.TmfTimeGraphViewer_BookmarkActionAddText
);
2032 fToggleBookmarkAction
.setImageDescriptor(ADD_BOOKMARK
);
2034 return fToggleBookmarkAction
;
2038 * Get the next bookmark action.
2040 * @return The Action object
2043 public Action
getNextBookmarkAction() {
2044 if (fNextBookmarkAction
== null) {
2045 fNextBookmarkAction
= new Action() {
2047 public void runWithEvent(Event event
) {
2048 final long time
= Math
.min(fSelectionBegin
, fSelectionEnd
);
2049 final long duration
= Math
.max(fSelectionBegin
, fSelectionEnd
) - time
;
2050 for (IMarkerEvent bookmark
: fBookmarks
) {
2051 if (bookmark
.getTime() > time
||
2052 (bookmark
.getTime() == time
&& bookmark
.getDuration() > duration
)) {
2053 setSelectionRangeNotify(bookmark
.getTime(), bookmark
.getTime() + bookmark
.getDuration());
2059 fNextBookmarkAction
.setText(Messages
.TmfTimeGraphViewer_NextBookmarkActionText
);
2060 fNextBookmarkAction
.setToolTipText(Messages
.TmfTimeGraphViewer_NextBookmarkActionText
);
2061 fNextBookmarkAction
.setImageDescriptor(NEXT_BOOKMARK
);
2063 return fNextBookmarkAction
;
2067 * Get the previous bookmark action.
2069 * @return The Action object
2072 public Action
getPreviousBookmarkAction() {
2073 if (fPreviousBookmarkAction
== null) {
2074 fPreviousBookmarkAction
= new Action() {
2076 public void runWithEvent(Event event
) {
2077 final long time
= Math
.min(fSelectionBegin
, fSelectionEnd
);
2078 final long duration
= Math
.max(fSelectionBegin
, fSelectionEnd
) - time
;
2079 for (int i
= fBookmarks
.size() - 1; i
>= 0; i
--) {
2080 IMarkerEvent bookmark
= fBookmarks
.get(i
);
2081 if (bookmark
.getTime() < time
||
2082 (bookmark
.getTime() == time
&& bookmark
.getDuration() < duration
)) {
2083 setSelectionRangeNotify(bookmark
.getTime(), bookmark
.getTime() + bookmark
.getDuration());
2089 fPreviousBookmarkAction
.setText(Messages
.TmfTimeGraphViewer_PreviousBookmarkActionText
);
2090 fPreviousBookmarkAction
.setToolTipText(Messages
.TmfTimeGraphViewer_PreviousBookmarkActionText
);
2091 fPreviousBookmarkAction
.setImageDescriptor(PREVIOUS_BOOKMARK
);
2093 return fPreviousBookmarkAction
;
2096 private IMarkerEvent
getBookmarkAtSelection() {
2097 final long time
= Math
.min(fSelectionBegin
, fSelectionEnd
);
2098 final long duration
= Math
.max(fSelectionBegin
, fSelectionEnd
) - time
;
2099 for (IMarkerEvent bookmark
: fBookmarks
) {
2100 if (bookmark
.getTime() == time
&& bookmark
.getDuration() == duration
) {
2107 private void updateBookmarkActions() {
2108 if (fToggleBookmarkAction
!= null) {
2109 if (getBookmarkAtSelection() != null) {
2110 fToggleBookmarkAction
.setText(Messages
.TmfTimeGraphViewer_BookmarkActionRemoveText
);
2111 fToggleBookmarkAction
.setToolTipText(Messages
.TmfTimeGraphViewer_BookmarkActionRemoveText
);
2112 fToggleBookmarkAction
.setImageDescriptor(REMOVE_BOOKMARK
);
2114 fToggleBookmarkAction
.setText(Messages
.TmfTimeGraphViewer_BookmarkActionAddText
);
2115 fToggleBookmarkAction
.setToolTipText(Messages
.TmfTimeGraphViewer_BookmarkActionAddText
);
2116 fToggleBookmarkAction
.setImageDescriptor(ADD_BOOKMARK
);
2119 final long time
= Math
.min(fSelectionBegin
, fSelectionEnd
);
2120 final long duration
= Math
.max(fSelectionBegin
, fSelectionEnd
) - time
;
2121 if (fPreviousBookmarkAction
!= null) {
2122 fPreviousBookmarkAction
.setEnabled(!fBookmarks
.isEmpty() &&
2123 (time
> fBookmarks
.get(0).getTime() || (time
== fBookmarks
.get(0).getTime() && duration
> fBookmarks
.get(0).getDuration())));
2125 if (fNextBookmarkAction
!= null) {
2126 int last
= fBookmarks
.size() - 1;
2127 fNextBookmarkAction
.setEnabled(!fBookmarks
.isEmpty() &&
2128 (time
< fBookmarks
.get(last
).getTime() || (time
== fBookmarks
.get(last
).getTime() && duration
< fBookmarks
.get(last
).getDuration())));
2132 private void adjustHorizontalScrollBar() {
2133 long time0
= getTime0();
2134 long time1
= getTime1();
2135 long timeMin
= getMinTime();
2136 long timeMax
= getMaxTime();
2137 long delta
= timeMax
- timeMin
;
2139 int thumb
= H_SCROLLBAR_MAX
;
2141 // Thumb size (page size)
2142 thumb
= Math
.max(1, (int) (H_SCROLLBAR_MAX
* ((double) (time1
- time0
) / delta
)));
2143 // At the beginning of visible window
2144 timePos
= (int) (H_SCROLLBAR_MAX
* ((double) (time0
- timeMin
) / delta
));
2146 fHorizontalScrollBar
.setValues(timePos
, 0, H_SCROLLBAR_MAX
, thumb
, Math
.max(1, thumb
/ 2), Math
.max(2, thumb
));
2149 private void adjustVerticalScrollBar() {
2150 int topIndex
= fTimeGraphCtrl
.getTopIndex();
2151 int countPerPage
= fTimeGraphCtrl
.countPerPage();
2152 int expandedElementCount
= fTimeGraphCtrl
.getExpandedElementCount();
2153 if (topIndex
+ countPerPage
> expandedElementCount
) {
2154 fTimeGraphCtrl
.setTopIndex(Math
.max(0, expandedElementCount
- countPerPage
));
2157 int selection
= fTimeGraphCtrl
.getTopIndex();
2159 int max
= Math
.max(1, expandedElementCount
- 1);
2160 int thumb
= Math
.min(max
, Math
.max(1, countPerPage
- 1));
2162 int pageIncrement
= Math
.max(1, countPerPage
);
2163 fVerticalScrollBar
.setValues(selection
, min
, max
, thumb
, increment
, pageIncrement
);
2168 * a {@link MenuDetectListener}
2169 * @see org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.TimeGraphControl#addTimeGraphEntryMenuListener(org.eclipse.swt.events.MenuDetectListener)
2171 public void addTimeGraphEntryMenuListener(MenuDetectListener listener
) {
2172 fTimeGraphCtrl
.addTimeGraphEntryMenuListener(listener
);
2177 * a {@link MenuDetectListener}
2178 * @see org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.TimeGraphControl#removeTimeGraphEntryMenuListener(org.eclipse.swt.events.MenuDetectListener)
2180 public void removeTimeGraphEntryMenuListener(MenuDetectListener listener
) {
2181 fTimeGraphCtrl
.removeTimeGraphEntryMenuListener(listener
);
2186 * a {@link MenuDetectListener}
2187 * @see org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.TimeGraphControl#addTimeEventMenuListener(org.eclipse.swt.events.MenuDetectListener)
2189 public void addTimeEventMenuListener(MenuDetectListener listener
) {
2190 fTimeGraphCtrl
.addTimeEventMenuListener(listener
);
2195 * a {@link MenuDetectListener}
2196 * @see org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.TimeGraphControl#removeTimeEventMenuListener(org.eclipse.swt.events.MenuDetectListener)
2198 public void removeTimeEventMenuListener(MenuDetectListener listener
) {
2199 fTimeGraphCtrl
.removeTimeEventMenuListener(listener
);
2204 * The filter object to be attached to the view
2206 public void addFilter(ViewerFilter filter
) {
2207 fTimeGraphCtrl
.addFilter(filter
);
2213 * The filter object to be attached to the view
2215 public void removeFilter(ViewerFilter filter
) {
2216 fTimeGraphCtrl
.removeFilter(filter
);
2221 * Returns this viewer's filters.
2223 * @return an array of viewer filters
2226 public ViewerFilter
[] getFilters() {
2227 return fTimeGraphCtrl
.getFilters();
2231 * Sets the filters, replacing any previous filters, and triggers
2232 * refiltering of the elements.
2235 * an array of viewer filters, or null
2238 public void setFilters(ViewerFilter
[] filters
) {
2239 fTimeGraphCtrl
.setFilters(filters
);
2244 * Return the time alignment information
2246 * @return the time alignment information
2248 * @see ITmfTimeAligned
2252 public TmfTimeViewAlignmentInfo
getTimeViewAlignmentInfo() {
2253 return fTimeGraphCtrl
.getTimeViewAlignmentInfo();
2257 * Return the available width for the time-axis.
2259 * @see ITmfTimeAligned
2261 * @param requestedOffset
2262 * the requested offset
2263 * @return the available width for the time-axis
2267 public int getAvailableWidth(int requestedOffset
) {
2268 int totalWidth
= fTimeAlignedComposite
.getSize().x
;
2269 return Math
.min(totalWidth
, Math
.max(0, totalWidth
- requestedOffset
));
2273 * Perform the alignment operation.
2276 * the alignment offset
2278 * the alignment width
2280 * @see ITmfTimeAligned
2284 public void performAlign(int offset
, int width
) {
2285 fTimeGraphCtrl
.performAlign(offset
);
2286 int alignmentWidth
= width
;
2287 int size
= fTimeAlignedComposite
.getSize().x
;
2288 GridLayout layout
= (GridLayout
) fTimeAlignedComposite
.getLayout();
2289 int marginSize
= size
- alignmentWidth
- offset
;
2290 layout
.marginRight
= Math
.max(0, marginSize
);
2291 fTimeAlignedComposite
.layout();