1 /*******************************************************************************
2 * Copyright (c) 2012, 2015 Ericsson, École Polytechnique de Montréal
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * Patrick Tasse - Initial API and implementation
11 * Bernd Hufmann - Updated signal handling
12 * Geneviève Bastien - Move code to provide base classes for time graph view
13 * Marc-Andre Laperle - Add time zone preference
14 * Geneviève Bastien - Add event links between entries
15 *******************************************************************************/
17 package org
.eclipse
.tracecompass
.tmf
.ui
.views
.timegraph
;
19 import static org
.eclipse
.tracecompass
.common
.core
.NonNullUtils
.checkNotNull
;
21 import java
.util
.ArrayList
;
22 import java
.util
.Collections
;
23 import java
.util
.Comparator
;
24 import java
.util
.HashMap
;
25 import java
.util
.HashSet
;
26 import java
.util
.List
;
29 import java
.util
.concurrent
.CopyOnWriteArrayList
;
30 import java
.util
.regex
.Matcher
;
31 import java
.util
.regex
.Pattern
;
33 import org
.eclipse
.core
.resources
.IFile
;
34 import org
.eclipse
.core
.resources
.IMarker
;
35 import org
.eclipse
.core
.resources
.IMarkerDelta
;
36 import org
.eclipse
.core
.resources
.IResource
;
37 import org
.eclipse
.core
.resources
.IResourceChangeEvent
;
38 import org
.eclipse
.core
.resources
.IResourceChangeListener
;
39 import org
.eclipse
.core
.resources
.IWorkspaceRunnable
;
40 import org
.eclipse
.core
.resources
.ResourcesPlugin
;
41 import org
.eclipse
.core
.runtime
.CoreException
;
42 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
43 import org
.eclipse
.core
.runtime
.NullProgressMonitor
;
44 import org
.eclipse
.jdt
.annotation
.NonNull
;
45 import org
.eclipse
.jdt
.annotation
.Nullable
;
46 import org
.eclipse
.jface
.action
.Action
;
47 import org
.eclipse
.jface
.action
.IAction
;
48 import org
.eclipse
.jface
.action
.IMenuManager
;
49 import org
.eclipse
.jface
.action
.IStatusLineManager
;
50 import org
.eclipse
.jface
.action
.IToolBarManager
;
51 import org
.eclipse
.jface
.action
.Separator
;
52 import org
.eclipse
.jface
.viewers
.AbstractTreeViewer
;
53 import org
.eclipse
.jface
.viewers
.ILabelProvider
;
54 import org
.eclipse
.jface
.viewers
.ILabelProviderListener
;
55 import org
.eclipse
.jface
.viewers
.ISelectionProvider
;
56 import org
.eclipse
.jface
.viewers
.ITableLabelProvider
;
57 import org
.eclipse
.jface
.viewers
.ITreeContentProvider
;
58 import org
.eclipse
.jface
.viewers
.TreeViewer
;
59 import org
.eclipse
.jface
.viewers
.ViewerFilter
;
60 import org
.eclipse
.osgi
.util
.NLS
;
61 import org
.eclipse
.swt
.SWT
;
62 import org
.eclipse
.swt
.graphics
.Color
;
63 import org
.eclipse
.swt
.graphics
.Image
;
64 import org
.eclipse
.swt
.widgets
.Composite
;
65 import org
.eclipse
.swt
.widgets
.Display
;
66 import org
.eclipse
.swt
.widgets
.TreeColumn
;
67 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.Activator
;
68 import org
.eclipse
.tracecompass
.tmf
.core
.resources
.ITmfMarker
;
69 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfSelectionRangeUpdatedSignal
;
70 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfSignalHandler
;
71 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfTimestampFormatUpdateSignal
;
72 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfTraceClosedSignal
;
73 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfTraceOpenedSignal
;
74 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfTraceSelectedSignal
;
75 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfWindowRangeUpdatedSignal
;
76 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.ITmfTimestamp
;
77 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.TmfNanoTimestamp
;
78 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.TmfTimeRange
;
79 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfTrace
;
80 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.TmfTraceAdapterManager
;
81 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.TmfTraceContext
;
82 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.TmfTraceManager
;
83 import org
.eclipse
.tracecompass
.tmf
.ui
.TmfUiRefreshHandler
;
84 import org
.eclipse
.tracecompass
.tmf
.ui
.signal
.TmfTimeViewAlignmentInfo
;
85 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.ITmfTimeAligned
;
86 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.TmfView
;
87 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.ITimeGraphBookmarkListener
;
88 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.ITimeGraphContentProvider
;
89 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.ITimeGraphPresentationProvider2
;
90 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.ITimeGraphRangeListener
;
91 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.ITimeGraphSelectionListener
;
92 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.ITimeGraphTimeListener
;
93 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.TimeGraphBookmarkEvent
;
94 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.TimeGraphCombo
;
95 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.TimeGraphContentProvider
;
96 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.TimeGraphPresentationProvider
;
97 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.TimeGraphRangeUpdateEvent
;
98 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.TimeGraphTimeEvent
;
99 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.TimeGraphViewer
;
100 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.ILinkEvent
;
101 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.IMarkerEvent
;
102 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.IMarkerEventSource
;
103 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.ITimeEvent
;
104 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.ITimeGraphEntry
;
105 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.MarkerEvent
;
106 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.TimeGraphEntry
;
107 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.widgets
.Utils
.TimeFormat
;
108 import org
.eclipse
.ui
.IActionBars
;
111 * An abstract view all time graph views can inherit
113 * This view contains either a time graph viewer, or a time graph combo which is
114 * divided between a tree viewer on the left and a time graph viewer on the right.
116 public abstract class AbstractTimeGraphView
extends TmfView
implements ITmfTimeAligned
, IResourceChangeListener
{
118 /** Constant indicating that all levels of the time graph should be expanded */
119 protected static final int ALL_LEVELS
= AbstractTreeViewer
.ALL_LEVELS
;
121 private static final Pattern RGBA_PATTERN
= Pattern
.compile("RGBA \\{(\\d+), (\\d+), (\\d+), (\\d+)\\}"); //$NON-NLS-1$
130 // ------------------------------------------------------------------------
132 // ------------------------------------------------------------------------
134 /** The timegraph wrapper */
135 private ITimeGraphWrapper fTimeGraphWrapper
;
137 /** The selected trace */
138 private ITmfTrace fTrace
;
140 /** The selected trace editor file*/
141 private IFile fEditorFile
;
143 /** The timegraph entry list */
144 private List
<TimeGraphEntry
> fEntryList
;
146 /** The trace to entry list hash map */
147 private final Map
<ITmfTrace
, List
<TimeGraphEntry
>> fEntryListMap
= new HashMap
<>();
149 /** The trace to filters hash map */
150 private final Map
<ITmfTrace
, ViewerFilter
[]> fFiltersMap
= new HashMap
<>();
152 /** The trace to marker event sources hash map */
153 private final Map
<ITmfTrace
, List
<IMarkerEventSource
>> fMarkerEventSourcesMap
= new HashMap
<>();
155 /** The trace to build thread hash map */
156 private final Map
<ITmfTrace
, BuildThread
> fBuildThreadMap
= new HashMap
<>();
158 /** The start time */
159 private long fStartTime
= SWT
.DEFAULT
;
162 private long fEndTime
= SWT
.DEFAULT
;
164 /** The display width */
165 private final int fDisplayWidth
;
167 /** The zoom thread */
168 private ZoomThread fZoomThread
;
170 /** The next resource action */
171 private Action fNextResourceAction
;
173 /** The previous resource action */
174 private Action fPreviousResourceAction
;
176 /** A comparator class */
177 private Comparator
<ITimeGraphEntry
> fEntryComparator
= null;
179 /** The redraw state used to prevent unnecessary queuing of display runnables */
180 private State fRedrawState
= State
.IDLE
;
182 /** The redraw synchronization object */
183 private final Object fSyncObj
= new Object();
185 /** The presentation provider for this view */
186 private final TimeGraphPresentationProvider fPresentation
;
188 /** The tree column label array, or null if combo is not used */
189 private String
[] fColumns
;
191 /** The tree label provider, or null if combo is not used */
192 private TreeLabelProvider fLabelProvider
= null;
194 /** The time graph content provider */
195 private @NonNull ITimeGraphContentProvider fTimeGraphContentProvider
= new TimeGraphContentProvider();
197 /** The relative weight of the sash, ignored if combo is not used */
198 private int[] fWeight
= { 1, 3 };
200 /** The filter column label array, or null if filter is not used */
201 private String
[] fFilterColumns
;
203 /** The pack done flag */
204 private boolean fPackDone
= false;
206 /** The filter label provider, or null if filter is not used */
207 private TreeLabelProvider fFilterLabelProvider
;
209 private int fAutoExpandLevel
= ALL_LEVELS
;
211 /** The list of color resources created by this view */
212 private final List
<Color
> fColors
= new ArrayList
<>();
214 // ------------------------------------------------------------------------
216 // ------------------------------------------------------------------------
218 private interface ITimeGraphWrapper
{
220 void setTimeGraphContentProvider(ITimeGraphContentProvider timeGraphContentProvider
);
222 void setTimeGraphPresentationProvider(TimeGraphPresentationProvider timeGraphPresentationProvider
);
224 TimeGraphViewer
getTimeGraphViewer();
226 void addSelectionListener(ITimeGraphSelectionListener listener
);
228 ISelectionProvider
getSelectionProvider();
232 boolean isDisposed();
236 void setInput(Object input
);
240 void setFilters(ViewerFilter
[] filters
);
242 ViewerFilter
[] getFilters();
248 void setAutoExpandLevel(int level
);
250 void setFilterColumns(String
[] columnNames
);
252 void setFilterContentProvider(ITreeContentProvider contentProvider
);
254 void setFilterLabelProvider(ITableLabelProvider labelProvider
);
256 IAction
getShowFilterDialogAction();
258 void performAlign(int offset
, int width
);
260 TmfTimeViewAlignmentInfo
getTimeViewAlignmentInfo();
262 int getAvailableWidth(int requestedOffset
);
265 private class TimeGraphViewerWrapper
implements ITimeGraphWrapper
{
266 private TimeGraphViewer viewer
;
268 private TimeGraphViewerWrapper(Composite parent
, int style
) {
269 viewer
= new TimeGraphViewer(parent
, style
);
273 public void setTimeGraphContentProvider(ITimeGraphContentProvider timeGraphContentProvider
) {
274 viewer
.setTimeGraphContentProvider(timeGraphContentProvider
);
278 public void setTimeGraphPresentationProvider(TimeGraphPresentationProvider timeGraphPresentationProvider
) {
279 viewer
.setTimeGraphProvider(timeGraphPresentationProvider
);
283 public TimeGraphViewer
getTimeGraphViewer() {
288 public void addSelectionListener(ITimeGraphSelectionListener listener
) {
289 viewer
.addSelectionListener(listener
);
293 public ISelectionProvider
getSelectionProvider() {
294 return viewer
.getSelectionProvider();
298 public void setFocus() {
303 public boolean isDisposed() {
304 return viewer
.getControl().isDisposed();
308 public void setInput(Object input
) {
309 viewer
.setInput(input
);
313 public Object
getInput() {
314 return viewer
.getInput();
318 public void setFilterColumns(String
[] columnNames
) {
319 viewer
.setFilterColumns(columnNames
);
323 public void setFilterContentProvider(ITreeContentProvider contentProvider
) {
324 viewer
.setFilterContentProvider(contentProvider
);
328 public void setFilterLabelProvider(ITableLabelProvider labelProvider
) {
329 viewer
.setFilterLabelProvider(labelProvider
);
333 public void setFilters(ViewerFilter
[] filters
) {
334 viewer
.setFilters(filters
);
338 public ViewerFilter
[] getFilters() {
339 return viewer
.getFilters();
343 public IAction
getShowFilterDialogAction() {
344 return viewer
.getShowFilterDialogAction();
348 public void refresh() {
353 public void redraw() {
354 viewer
.getControl().redraw();
358 public void update() {
359 viewer
.getControl().update();
363 public void setAutoExpandLevel(int level
) {
364 viewer
.setAutoExpandLevel(level
);
368 public void performAlign(int offset
, int width
) {
369 viewer
.performAlign(offset
, width
);
373 public TmfTimeViewAlignmentInfo
getTimeViewAlignmentInfo() {
374 return viewer
.getTimeViewAlignmentInfo();
378 public int getAvailableWidth(int requestedOffset
) {
379 return viewer
.getAvailableWidth(requestedOffset
);
383 private class TimeGraphComboWrapper
implements ITimeGraphWrapper
{
384 private TimeGraphCombo combo
;
386 private TimeGraphComboWrapper(Composite parent
, int style
) {
387 combo
= new TimeGraphCombo(parent
, style
, fWeight
);
391 public void setTimeGraphContentProvider(ITimeGraphContentProvider timeGraphContentProvider
) {
392 combo
.setTimeGraphContentProvider(timeGraphContentProvider
);
396 public void setTimeGraphPresentationProvider(TimeGraphPresentationProvider timeGraphPresentationProvider
) {
397 combo
.setTimeGraphProvider(timeGraphPresentationProvider
);
401 public TimeGraphViewer
getTimeGraphViewer() {
402 return combo
.getTimeGraphViewer();
406 public void addSelectionListener(ITimeGraphSelectionListener listener
) {
407 combo
.addSelectionListener(listener
);
411 public ISelectionProvider
getSelectionProvider() {
412 return combo
.getTreeViewer();
416 public void setFocus() {
421 public boolean isDisposed() {
422 return combo
.isDisposed();
426 public void setInput(Object input
) {
427 combo
.setInput(input
);
431 public Object
getInput() {
432 return combo
.getInput();
436 public void setFilterColumns(String
[] columnNames
) {
437 combo
.setFilterColumns(columnNames
);
441 public void setFilterContentProvider(ITreeContentProvider contentProvider
) {
442 combo
.setFilterContentProvider(contentProvider
);
446 public void setFilterLabelProvider(ITableLabelProvider labelProvider
) {
447 combo
.setFilterLabelProvider(labelProvider
);
451 public void setFilters(ViewerFilter
[] filters
) {
452 combo
.setFilters(filters
);
456 public ViewerFilter
[] getFilters() {
457 return combo
.getFilters();
461 public IAction
getShowFilterDialogAction() {
462 return combo
.getShowFilterDialogAction();
466 public void refresh() {
471 public void redraw() {
476 public void update() {
481 public void setAutoExpandLevel(int level
) {
482 combo
.setAutoExpandLevel(level
);
485 TimeGraphCombo
getTimeGraphCombo() {
489 TreeViewer
getTreeViewer() {
490 return combo
.getTreeViewer();
494 public void performAlign(int offset
, int width
) {
495 combo
.performAlign(offset
, width
);
499 public TmfTimeViewAlignmentInfo
getTimeViewAlignmentInfo() {
500 return combo
.getTimeViewAlignmentInfo();
504 public int getAvailableWidth(int requestedOffset
) {
505 return combo
.getAvailableWidth(requestedOffset
);
510 * Base class to provide the labels for the tree viewer. Views extending
511 * this class typically need to override the getColumnText method if they
512 * have more than one column to display
514 protected static class TreeLabelProvider
implements ITableLabelProvider
, ILabelProvider
{
517 public void addListener(ILabelProviderListener listener
) {
521 public void dispose() {
525 public boolean isLabelProperty(Object element
, String property
) {
530 public void removeListener(ILabelProviderListener listener
) {
534 public Image
getColumnImage(Object element
, int columnIndex
) {
539 public String
getColumnText(Object element
, int columnIndex
) {
540 TimeGraphEntry entry
= (TimeGraphEntry
) element
;
541 if (columnIndex
== 0) {
542 return entry
.getName();
548 public Image
getImage(Object element
) {
553 public String
getText(Object element
) {
554 TimeGraphEntry entry
= (TimeGraphEntry
) element
;
555 return entry
.getName();
560 private class BuildThread
extends Thread
{
561 private final @NonNull ITmfTrace fBuildTrace
;
562 private final @NonNull ITmfTrace fParentTrace
;
563 private final @NonNull IProgressMonitor fMonitor
;
565 public BuildThread(final @NonNull ITmfTrace trace
, final @NonNull ITmfTrace parentTrace
, final String name
) {
566 super(name
+ " build"); //$NON-NLS-1$
568 fParentTrace
= parentTrace
;
569 fMonitor
= new NullProgressMonitor();
574 buildEventList(fBuildTrace
, fParentTrace
, fMonitor
);
575 synchronized (fBuildThreadMap
) {
576 fBuildThreadMap
.remove(fBuildTrace
);
580 public void cancel() {
581 fMonitor
.setCanceled(true);
589 protected abstract class ZoomThread
extends Thread
{
590 private final long fZoomStartTime
;
591 private final long fZoomEndTime
;
592 private final long fResolution
;
593 private final @NonNull IProgressMonitor fMonitor
;
605 public ZoomThread(long startTime
, long endTime
, long resolution
) {
606 super(AbstractTimeGraphView
.this.getName() + " zoom"); //$NON-NLS-1$
607 fZoomStartTime
= startTime
;
608 fZoomEndTime
= endTime
;
609 fResolution
= resolution
;
610 fMonitor
= new NullProgressMonitor();
614 * @return the zoom start time
616 public long getZoomStartTime() {
617 return fZoomStartTime
;
621 * @return the zoom end time
623 public long getZoomEndTime() {
628 * @return the resolution
630 public long getResolution() {
635 * @return the monitor
637 public @NonNull IProgressMonitor
getMonitor() {
642 * Cancel the zoom thread
644 public void cancel() {
645 fMonitor
.setCanceled(true);
649 private class ZoomThreadByEntry
extends ZoomThread
{
650 private final @NonNull List
<TimeGraphEntry
> fZoomEntryList
;
652 public ZoomThreadByEntry(@NonNull List
<TimeGraphEntry
> entryList
, long startTime
, long endTime
, long resolution
) {
653 super(startTime
, endTime
, resolution
);
654 fZoomEntryList
= entryList
;
659 for (TimeGraphEntry entry
: fZoomEntryList
) {
660 if (getMonitor().isCanceled()) {
666 zoom(entry
, getMonitor());
668 /* Refresh the arrows when zooming */
669 List
<ILinkEvent
> events
= getLinkList(getZoomStartTime(), getZoomEndTime(), getResolution(), getMonitor());
670 if (events
!= null) {
671 fTimeGraphWrapper
.getTimeGraphViewer().setLinks(events
);
674 /* Refresh the view-specific markers when zooming */
675 List
<IMarkerEvent
> markers
= new ArrayList
<>(getViewMarkerList(getZoomStartTime(), getZoomEndTime(), getResolution(), getMonitor()));
676 /* Refresh the trace-specific markers when zooming */
677 markers
.addAll(getTraceMarkerList(getZoomStartTime(), getZoomEndTime(), getResolution(), getMonitor()));
678 fTimeGraphWrapper
.getTimeGraphViewer().setMarkers(markers
);
682 private void zoom(@NonNull TimeGraphEntry entry
, @NonNull IProgressMonitor monitor
) {
683 if (getZoomStartTime() <= fStartTime
&& getZoomEndTime() >= fEndTime
) {
684 entry
.setZoomedEventList(null);
686 List
<ITimeEvent
> zoomedEventList
= getEventList(entry
, getZoomStartTime(), getZoomEndTime(), getResolution(), monitor
);
687 if (zoomedEventList
!= null) {
688 entry
.setZoomedEventList(zoomedEventList
);
692 for (ITimeGraphEntry child
: entry
.getChildren()) {
693 if (monitor
.isCanceled()) {
696 if (child
instanceof TimeGraphEntry
) {
697 zoom((TimeGraphEntry
) child
, monitor
);
704 // ------------------------------------------------------------------------
706 // ------------------------------------------------------------------------
709 * Constructs a time graph view that contains either a time graph viewer or
710 * a time graph combo.
712 * By default, the view uses a time graph viewer. To use a time graph combo,
713 * the subclass constructor must call {@link #setTreeColumns(String[])} and
714 * {@link #setTreeLabelProvider(TreeLabelProvider)}.
719 * The presentation provider
721 public AbstractTimeGraphView(String id
, TimeGraphPresentationProvider pres
) {
723 fPresentation
= pres
;
724 fDisplayWidth
= Display
.getDefault().getBounds().width
;
727 // ------------------------------------------------------------------------
728 // Getters and setters
729 // ------------------------------------------------------------------------
732 * Getter for the time graph combo
734 * @return The time graph combo, or null if combo is not used
736 protected TimeGraphCombo
getTimeGraphCombo() {
737 if (fTimeGraphWrapper
instanceof TimeGraphComboWrapper
) {
738 return ((TimeGraphComboWrapper
) fTimeGraphWrapper
).getTimeGraphCombo();
744 * Getter for the time graph viewer
746 * @return The time graph viewer
748 protected TimeGraphViewer
getTimeGraphViewer() {
749 return fTimeGraphWrapper
.getTimeGraphViewer();
753 * Getter for the presentation provider
755 * @return The time graph presentation provider
757 protected ITimeGraphPresentationProvider2
getPresentationProvider() {
758 return fPresentation
;
762 * Sets the tree column labels.
763 * This should be called from the constructor.
766 * The array of tree column labels
768 protected void setTreeColumns(final String
[] columns
) {
773 * Sets the tree label provider.
774 * This should be called from the constructor.
777 * The tree label provider
779 protected void setTreeLabelProvider(final TreeLabelProvider tlp
) {
780 fLabelProvider
= tlp
;
784 * Sets the time graph content provider. This should be called from the
788 * The time graph content provider
791 protected void setTimeGraphContentProvider(final @NonNull ITimeGraphContentProvider tgcp
) {
792 fTimeGraphContentProvider
= tgcp
;
796 * Sets the relative weight of each part of the time graph combo.
797 * This should be called from the constructor.
800 * The array (length 2) of relative weights of each part of the combo
802 protected void setWeight(final int[] weights
) {
807 * Sets the filter column labels.
808 * This should be called from the constructor.
810 * @param filterColumns
811 * The array of filter column labels
813 protected void setFilterColumns(final String
[] filterColumns
) {
814 fFilterColumns
= filterColumns
;
818 * Sets the filter label provider.
819 * This should be called from the constructor.
821 * @param labelProvider
822 * The filter label provider
824 protected void setFilterLabelProvider(final TreeLabelProvider labelProvider
) {
825 fFilterLabelProvider
= labelProvider
;
829 * Gets the display width
831 * @return the display width
833 protected int getDisplayWidth() {
834 return fDisplayWidth
;
838 * Gets the comparator for the entries
840 * @return The entry comparator
842 protected Comparator
<ITimeGraphEntry
> getEntryComparator() {
843 return fEntryComparator
;
847 * Sets the comparator class for the entries.
849 * This comparator will apply recursively to entries that implement
850 * {@link TimeGraphEntry#sortChildren(Comparator)}.
853 * A comparator object
855 protected void setEntryComparator(final Comparator
<ITimeGraphEntry
> comparator
) {
856 fEntryComparator
= comparator
;
860 * Gets the trace displayed in the view
864 protected ITmfTrace
getTrace() {
869 * Gets the start time
871 * @return The start time
873 protected long getStartTime() {
878 * Sets the start time
883 protected void setStartTime(long time
) {
890 * @return The end time
892 protected long getEndTime() {
902 protected void setEndTime(long time
) {
907 * Sets the auto-expand level to be used for the input of the view. The
908 * value 0 means that there is no auto-expand; 1 means that top-level
909 * elements are expanded, but not their children; 2 means that top-level
910 * elements are expanded, and their children, but not grand-children; and so
913 * The value {@link #ALL_LEVELS} means that all subtrees should be expanded.
917 * non-negative level, or <code>ALL_LEVELS</code> to expand all
920 protected void setAutoExpandLevel(int level
) {
921 fAutoExpandLevel
= level
;
922 ITimeGraphWrapper tgWrapper
= fTimeGraphWrapper
;
923 if (tgWrapper
!= null) {
924 tgWrapper
.setAutoExpandLevel(level
);
929 * Gets the entry list for a trace
934 * @return the entry list map
936 protected List
<TimeGraphEntry
> getEntryList(ITmfTrace trace
) {
937 synchronized (fEntryListMap
) {
938 return fEntryListMap
.get(trace
);
943 * Adds a trace entry list to the entry list map
948 * the list of time graph entries
950 protected void putEntryList(ITmfTrace trace
, List
<TimeGraphEntry
> list
) {
951 synchronized (fEntryListMap
) {
952 fEntryListMap
.put(trace
, new CopyOnWriteArrayList
<>(list
));
957 * Adds a list of entries to a trace's entry list
962 * the list of time graph entries to add
964 protected void addToEntryList(ITmfTrace trace
, List
<TimeGraphEntry
> list
) {
965 synchronized (fEntryListMap
) {
966 List
<TimeGraphEntry
> entryList
= fEntryListMap
.get(trace
);
967 if (entryList
== null) {
968 fEntryListMap
.put(trace
, new CopyOnWriteArrayList
<>(list
));
970 entryList
.addAll(list
);
976 * Removes a list of entries from a trace's entry list
981 * the list of time graph entries to remove
983 protected void removeFromEntryList(ITmfTrace trace
, List
<TimeGraphEntry
> list
) {
984 synchronized (fEntryListMap
) {
985 List
<TimeGraphEntry
> entryList
= fEntryListMap
.get(trace
);
986 if (entryList
!= null) {
987 entryList
.removeAll(list
);
993 * Text for the "next" button
995 * @return The "next" button text
997 protected String
getNextText() {
998 return Messages
.AbstractTimeGraphtView_NextText
;
1002 * Tooltip for the "next" button
1004 * @return Tooltip for the "next" button
1006 protected String
getNextTooltip() {
1007 return Messages
.AbstractTimeGraphView_NextTooltip
;
1011 * Text for the "Previous" button
1013 * @return The "Previous" button text
1015 protected String
getPrevText() {
1016 return Messages
.AbstractTimeGraphView_PreviousText
;
1020 * Tooltip for the "previous" button
1022 * @return Tooltip for the "previous" button
1024 protected String
getPrevTooltip() {
1025 return Messages
.AbstractTimeGraphView_PreviousTooltip
;
1028 // ------------------------------------------------------------------------
1030 // ------------------------------------------------------------------------
1033 public void createPartControl(Composite parent
) {
1034 super.createPartControl(parent
);
1035 if (fColumns
== null || fLabelProvider
== null) {
1036 fTimeGraphWrapper
= new TimeGraphViewerWrapper(parent
, SWT
.NONE
);
1038 TimeGraphComboWrapper wrapper
= new TimeGraphComboWrapper(parent
, SWT
.NONE
);
1039 fTimeGraphWrapper
= wrapper
;
1040 TimeGraphCombo combo
= wrapper
.getTimeGraphCombo();
1041 combo
.setTreeContentProvider(fTimeGraphContentProvider
);
1042 combo
.setTreeLabelProvider(fLabelProvider
);
1043 combo
.setTreeColumns(fColumns
);
1045 fTimeGraphWrapper
.setTimeGraphContentProvider(fTimeGraphContentProvider
);
1046 fTimeGraphWrapper
.setFilterContentProvider(fTimeGraphContentProvider
);
1047 fTimeGraphWrapper
.setFilterLabelProvider(fFilterLabelProvider
);
1048 fTimeGraphWrapper
.setFilterColumns(fFilterColumns
);
1050 fTimeGraphWrapper
.setTimeGraphPresentationProvider(fPresentation
);
1051 fTimeGraphWrapper
.setAutoExpandLevel(fAutoExpandLevel
);
1053 fTimeGraphWrapper
.getTimeGraphViewer().addRangeListener(new ITimeGraphRangeListener() {
1055 public void timeRangeUpdated(TimeGraphRangeUpdateEvent event
) {
1056 final long startTime
= event
.getStartTime();
1057 final long endTime
= event
.getEndTime();
1058 TmfTimeRange range
= new TmfTimeRange(new TmfNanoTimestamp(startTime
), new TmfNanoTimestamp(endTime
));
1059 broadcast(new TmfWindowRangeUpdatedSignal(AbstractTimeGraphView
.this, range
));
1060 startZoomThread(startTime
, endTime
);
1064 fTimeGraphWrapper
.getTimeGraphViewer().addTimeListener(new ITimeGraphTimeListener() {
1066 public void timeSelected(TimeGraphTimeEvent event
) {
1067 TmfNanoTimestamp startTime
= new TmfNanoTimestamp(event
.getBeginTime());
1068 TmfNanoTimestamp endTime
= new TmfNanoTimestamp(event
.getEndTime());
1069 broadcast(new TmfSelectionRangeUpdatedSignal(AbstractTimeGraphView
.this, startTime
, endTime
));
1073 fTimeGraphWrapper
.getTimeGraphViewer().addBookmarkListener(new ITimeGraphBookmarkListener() {
1075 public void bookmarkAdded(final TimeGraphBookmarkEvent event
) {
1077 ResourcesPlugin
.getWorkspace().run(new IWorkspaceRunnable() {
1079 public void run(IProgressMonitor monitor
) throws CoreException
{
1080 IMarkerEvent bookmark
= event
.getBookmark();
1081 IMarker marker
= fEditorFile
.createMarker(IMarker
.BOOKMARK
);
1082 marker
.setAttribute(IMarker
.MESSAGE
, bookmark
.getLabel());
1083 marker
.setAttribute(ITmfMarker
.MARKER_TIME
, Long
.toString(bookmark
.getTime()));
1084 if (bookmark
.getDuration() > 0) {
1085 marker
.setAttribute(ITmfMarker
.MARKER_DURATION
, Long
.toString(bookmark
.getDuration()));
1086 marker
.setAttribute(IMarker
.LOCATION
,
1087 NLS
.bind(org
.eclipse
.tracecompass
.internal
.tmf
.ui
.Messages
.TmfMarker_LocationTimeRange
,
1088 new TmfNanoTimestamp(bookmark
.getTime()),
1089 new TmfNanoTimestamp(bookmark
.getTime() + bookmark
.getDuration())));
1091 marker
.setAttribute(IMarker
.LOCATION
,
1092 NLS
.bind(org
.eclipse
.tracecompass
.internal
.tmf
.ui
.Messages
.TmfMarker_LocationTime
,
1093 new TmfNanoTimestamp(bookmark
.getTime())));
1095 marker
.setAttribute(ITmfMarker
.MARKER_COLOR
, bookmark
.getColor().getRGBA().toString());
1098 } catch (CoreException e
) {
1099 Activator
.getDefault().logError(e
.getMessage());
1104 public void bookmarkRemoved(TimeGraphBookmarkEvent event
) {
1106 IMarkerEvent bookmark
= event
.getBookmark();
1107 IMarker
[] markers
= fEditorFile
.findMarkers(IMarker
.BOOKMARK
, false, IResource
.DEPTH_ZERO
);
1108 for (IMarker marker
: markers
) {
1109 if (bookmark
.getLabel().equals(marker
.getAttribute(IMarker
.MESSAGE
)) &&
1110 Long
.toString(bookmark
.getTime()).equals(marker
.getAttribute(ITmfMarker
.MARKER_TIME
, (String
) null)) &&
1111 Long
.toString(bookmark
.getDuration()).equals(marker
.getAttribute(ITmfMarker
.MARKER_DURATION
, Long
.toString(0))) &&
1112 bookmark
.getColor().getRGBA().toString().equals(marker
.getAttribute(ITmfMarker
.MARKER_COLOR
))) {
1117 } catch (CoreException e
) {
1118 Activator
.getDefault().logError(e
.getMessage());
1123 fTimeGraphWrapper
.getTimeGraphViewer().setTimeFormat(TimeFormat
.CALENDAR
);
1125 IStatusLineManager statusLineManager
= getViewSite().getActionBars().getStatusLineManager();
1126 fTimeGraphWrapper
.getTimeGraphViewer().getTimeGraphControl().setStatusLineManager(statusLineManager
);
1128 // View Action Handling
1130 contributeToActionBars();
1132 ITmfTrace trace
= TmfTraceManager
.getInstance().getActiveTrace();
1133 if (trace
!= null) {
1134 traceSelected(new TmfTraceSelectedSignal(this, trace
));
1137 // make selection available to other views
1138 getSite().setSelectionProvider(fTimeGraphWrapper
.getSelectionProvider());
1140 ResourcesPlugin
.getWorkspace().addResourceChangeListener(this, IResourceChangeEvent
.POST_CHANGE
);
1144 public void setFocus() {
1145 fTimeGraphWrapper
.setFocus();
1149 public void dispose() {
1151 ResourcesPlugin
.getWorkspace().removeResourceChangeListener(this);
1158 public void resourceChanged(final IResourceChangeEvent event
) {
1159 for (final IMarkerDelta delta
: event
.findMarkerDeltas(IMarker
.BOOKMARK
, false)) {
1160 if (delta
.getResource().equals(fEditorFile
)) {
1161 fTimeGraphWrapper
.getTimeGraphViewer().setBookmarks(refreshBookmarks(fEditorFile
));
1168 private List
<IMarkerEvent
> refreshBookmarks(final IFile editorFile
) {
1169 List
<IMarkerEvent
> bookmarks
= new ArrayList
<>();
1170 for (Color color
: fColors
) {
1174 if (editorFile
== null || !editorFile
.exists()) {
1178 IMarker
[] markers
= editorFile
.findMarkers(IMarker
.BOOKMARK
, false, IResource
.DEPTH_ZERO
);
1179 for (IMarker marker
: markers
) {
1180 String label
= marker
.getAttribute(IMarker
.MESSAGE
, (String
) null);
1181 String time
= marker
.getAttribute(ITmfMarker
.MARKER_TIME
, (String
) null);
1182 String duration
= marker
.getAttribute(ITmfMarker
.MARKER_DURATION
, Long
.toString(0));
1183 String rgba
= marker
.getAttribute(ITmfMarker
.MARKER_COLOR
, (String
) null);
1184 if (label
!= null && time
!= null && rgba
!= null) {
1185 Matcher matcher
= RGBA_PATTERN
.matcher(rgba
);
1186 if (matcher
.matches()) {
1188 int red
= Integer
.valueOf(matcher
.group(1));
1189 int green
= Integer
.valueOf(matcher
.group(2));
1190 int blue
= Integer
.valueOf(matcher
.group(3));
1191 int alpha
= Integer
.valueOf(matcher
.group(4));
1192 Color color
= new Color(Display
.getDefault(), red
, green
, blue
, alpha
);
1194 bookmarks
.add(new MarkerEvent(null, Long
.valueOf(time
), Long
.valueOf(duration
), IMarkerEvent
.BOOKMARKS
, color
, label
, true));
1195 } catch (NumberFormatException e
) {
1196 Activator
.getDefault().logError(e
.getMessage());
1201 } catch (CoreException e
) {
1202 Activator
.getDefault().logError(e
.getMessage());
1207 // ------------------------------------------------------------------------
1209 // ------------------------------------------------------------------------
1212 * Handler for the trace opened signal.
1215 * The incoming signal
1218 public void traceOpened(TmfTraceOpenedSignal signal
) {
1219 loadTrace(signal
.getTrace());
1223 * Handler for the trace selected signal
1226 * The incoming signal
1229 public void traceSelected(final TmfTraceSelectedSignal signal
) {
1230 if (signal
.getTrace() == fTrace
) {
1233 loadTrace(signal
.getTrace());
1237 * Trace is closed: clear the data structures and the view
1240 * the signal received
1243 public void traceClosed(final TmfTraceClosedSignal signal
) {
1244 synchronized (fBuildThreadMap
) {
1245 for (ITmfTrace trace
: getTracesToBuild(signal
.getTrace())) {
1246 BuildThread buildThread
= fBuildThreadMap
.remove(trace
);
1247 if (buildThread
!= null) {
1248 buildThread
.cancel();
1252 fMarkerEventSourcesMap
.remove(signal
.getTrace());
1253 synchronized (fEntryListMap
) {
1254 fEntryListMap
.remove(signal
.getTrace());
1256 fFiltersMap
.remove(signal
.getTrace());
1257 if (signal
.getTrace() == fTrace
) {
1260 fStartTime
= SWT
.DEFAULT
;
1261 fEndTime
= SWT
.DEFAULT
;
1262 if (fZoomThread
!= null) {
1263 fZoomThread
.cancel();
1271 * Handler for the selection range signal.
1274 * The signal that's received
1278 public void selectionRangeUpdated(final TmfSelectionRangeUpdatedSignal signal
) {
1279 if (signal
.getSource() == this || fTrace
== null) {
1282 final long beginTime
= signal
.getBeginTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
1283 final long endTime
= signal
.getEndTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
1285 Display
.getDefault().asyncExec(new Runnable() {
1288 if (fTimeGraphWrapper
.isDisposed()) {
1291 if (beginTime
== endTime
) {
1292 fTimeGraphWrapper
.getTimeGraphViewer().setSelectedTime(beginTime
, true);
1294 fTimeGraphWrapper
.getTimeGraphViewer().setSelectionRange(beginTime
, endTime
, true);
1296 synchingToTime(fTimeGraphWrapper
.getTimeGraphViewer().getSelectionBegin());
1302 * Handler for the window range signal.
1305 * The signal that's received
1309 public void windowRangeUpdated(final TmfWindowRangeUpdatedSignal signal
) {
1310 if (signal
.getSource() == this || fTrace
== null) {
1313 if (signal
.getCurrentRange().getIntersection(fTrace
.getTimeRange()) == null) {
1316 final long startTime
= signal
.getCurrentRange().getStartTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
1317 final long endTime
= signal
.getCurrentRange().getEndTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
1318 Display
.getDefault().asyncExec(new Runnable() {
1321 if (fTimeGraphWrapper
.isDisposed()) {
1324 fTimeGraphWrapper
.getTimeGraphViewer().setStartFinishTime(startTime
, endTime
);
1325 startZoomThread(startTime
, endTime
);
1331 * @param signal the format of the timestamps was updated.
1334 public void updateTimeFormat( final TmfTimestampFormatUpdateSignal signal
){
1335 fTimeGraphWrapper
.refresh();
1338 // ------------------------------------------------------------------------
1340 // ------------------------------------------------------------------------
1342 private void loadTrace(final ITmfTrace trace
) {
1343 if (fZoomThread
!= null) {
1344 fZoomThread
.cancel();
1347 if (fTrace
!= null) {
1348 /* save the filters of the previous trace */
1349 fFiltersMap
.put(fTrace
, fTimeGraphWrapper
.getFilters());
1352 fEditorFile
= TmfTraceManager
.getInstance().getTraceEditorFile(trace
);
1353 synchronized (fEntryListMap
) {
1354 fEntryList
= fEntryListMap
.get(fTrace
);
1355 if (fEntryList
== null) {
1358 fStartTime
= fTrace
.getStartTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
1359 fEndTime
= fTrace
.getEndTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
1366 * Forces a rebuild of the entries list, even if entries already exist for this trace
1368 protected void rebuild() {
1369 setStartTime(Long
.MAX_VALUE
);
1370 setEndTime(Long
.MIN_VALUE
);
1372 ITmfTrace viewTrace
= fTrace
;
1373 if (viewTrace
== null) {
1376 List
<IMarkerEventSource
> markerEventSources
= new ArrayList
<>();
1377 synchronized (fBuildThreadMap
) {
1378 for (ITmfTrace trace
: getTracesToBuild(viewTrace
)) {
1379 if (trace
== null) {
1382 markerEventSources
.addAll(TmfTraceAdapterManager
.getAdapters(trace
, IMarkerEventSource
.class));
1383 BuildThread buildThread
= new BuildThread(trace
, viewTrace
, getName());
1384 fBuildThreadMap
.put(trace
, buildThread
);
1385 buildThread
.start();
1388 fMarkerEventSourcesMap
.put(viewTrace
, markerEventSources
);
1392 * Method called when synching to a given timestamp. Inheriting classes can
1393 * perform actions here to update the view at the given timestamp.
1396 * The currently selected time
1398 protected void synchingToTime(long time
) {
1403 * Return the list of traces whose data or analysis results will be used to
1404 * populate the view. By default, if the trace is an experiment, the traces
1405 * under it will be returned, otherwise, the trace itself is returned.
1407 * A build thread will be started for each trace returned by this method,
1408 * some of which may receive events in live streaming mode.
1411 * The trace associated with this view
1412 * @return List of traces with data to display
1414 protected @NonNull Iterable
<ITmfTrace
> getTracesToBuild(@NonNull ITmfTrace trace
) {
1415 return TmfTraceManager
.getTraceSet(trace
);
1419 * Build the entries list to show in this time graph
1421 * Called from the BuildThread
1424 * The trace being built
1425 * @param parentTrace
1426 * The parent of the trace set, or the trace itself
1428 * The progress monitor object
1430 protected abstract void buildEventList(@NonNull ITmfTrace trace
, @NonNull ITmfTrace parentTrace
, @NonNull IProgressMonitor monitor
);
1433 * Gets the list of event for an entry in a given timerange
1436 * The entry to get events for
1438 * Start of the time range
1440 * End of the time range
1444 * The progress monitor object
1445 * @return The list of events for the entry
1447 protected abstract @Nullable List
<@NonNull ITimeEvent
> getEventList(@NonNull TimeGraphEntry entry
,
1448 long startTime
, long endTime
, long resolution
,
1449 @NonNull IProgressMonitor monitor
);
1452 * Gets the list of links (displayed as arrows) for a trace in a given
1453 * timerange. Default implementation returns an empty list.
1456 * Start of the time range
1458 * End of the time range
1462 * The progress monitor object
1463 * @return The list of link events
1465 protected @Nullable List
<@NonNull ILinkEvent
> getLinkList(long startTime
, long endTime
,
1466 long resolution
, @NonNull IProgressMonitor monitor
) {
1467 return new ArrayList
<>();
1471 * Gets the list of view-specific marker categories. Default implementation
1472 * returns an empty list.
1474 * @return The list of marker categories
1477 protected @NonNull List
<String
> getViewMarkerCategories() {
1478 return new ArrayList
<>();
1482 * Gets the list of view-specific markers for a trace in a given time range.
1483 * Default implementation returns an empty list.
1486 * Start of the time range
1488 * End of the time range
1492 * The progress monitor object
1493 * @return The list of marker events
1496 protected @NonNull List
<IMarkerEvent
> getViewMarkerList(long startTime
, long endTime
,
1497 long resolution
, @NonNull IProgressMonitor monitor
) {
1498 return new ArrayList
<>();
1502 * Gets the list of trace-specific markers for a trace in a given time range.
1505 * Start of the time range
1507 * End of the time range
1511 * The progress monitor object
1512 * @return The list of marker events
1515 protected @NonNull List
<IMarkerEvent
> getTraceMarkerList(long startTime
, long endTime
,
1516 long resolution
, @NonNull IProgressMonitor monitor
) {
1517 List
<IMarkerEvent
> markers
= new ArrayList
<>();
1518 for (IMarkerEventSource markerEventSource
: getMarkerEventSources(fTrace
)) {
1519 for (String category
: markerEventSource
.getMarkerCategories()) {
1520 if (monitor
.isCanceled()) {
1523 markers
.addAll(markerEventSource
.getMarkerList(checkNotNull(category
), startTime
, endTime
, resolution
, monitor
));
1530 * Get the list of current marker categories.
1532 * @return The list of marker categories
1535 private @NonNull List
<String
> getMarkerCategories() {
1536 Set
<String
> categories
= new HashSet
<>(getViewMarkerCategories());
1537 for (IMarkerEventSource markerEventSource
: getMarkerEventSources(fTrace
)) {
1538 categories
.addAll(markerEventSource
.getMarkerCategories());
1540 return new ArrayList
<>(categories
);
1544 * Gets the list of marker event sources for a given trace.
1548 * @return The list of marker event sources
1551 private @NonNull List
<IMarkerEventSource
> getMarkerEventSources(ITmfTrace trace
) {
1552 List
<IMarkerEventSource
> markerEventSources
= fMarkerEventSourcesMap
.get(trace
);
1553 if (markerEventSources
== null) {
1554 markerEventSources
= checkNotNull(Collections
.<IMarkerEventSource
>emptyList());
1556 return markerEventSources
;
1560 * Refresh the display
1562 protected void refresh() {
1563 final boolean zoomThread
= Thread
.currentThread() instanceof ZoomThread
;
1564 TmfUiRefreshHandler
.getInstance().queueUpdate(this, new Runnable() {
1567 if (fTimeGraphWrapper
.isDisposed()) {
1570 boolean hasEntries
= false;
1571 synchronized (fEntryListMap
) {
1572 fEntryList
= fEntryListMap
.get(fTrace
);
1573 if (fEntryList
== null) {
1574 fEntryList
= new CopyOnWriteArrayList
<>();
1575 } else if (fEntryComparator
!= null) {
1576 List
<TimeGraphEntry
> list
= new ArrayList
<>(fEntryList
);
1577 Collections
.sort(list
, fEntryComparator
);
1578 for (ITimeGraphEntry entry
: list
) {
1579 sortChildren(entry
, fEntryComparator
);
1582 fEntryList
.addAll(list
);
1584 hasEntries
= fEntryList
.size() != 0;
1586 if (fEntryList
!= fTimeGraphWrapper
.getInput()) {
1587 fTimeGraphWrapper
.setInput(fEntryList
);
1588 /* restore the previously saved filters, if any */
1589 fTimeGraphWrapper
.setFilters(fFiltersMap
.get(fTrace
));
1590 fTimeGraphWrapper
.getTimeGraphViewer().setLinks(null);
1591 fTimeGraphWrapper
.getTimeGraphViewer().setBookmarks(refreshBookmarks(fEditorFile
));
1592 fTimeGraphWrapper
.getTimeGraphViewer().setMarkerCategories(getMarkerCategories());
1593 fTimeGraphWrapper
.getTimeGraphViewer().setMarkers(null);
1595 fTimeGraphWrapper
.refresh();
1597 long startBound
= (fStartTime
== Long
.MAX_VALUE ? SWT
.DEFAULT
: fStartTime
);
1598 long endBound
= (fEndTime
== Long
.MIN_VALUE ? SWT
.DEFAULT
: fEndTime
);
1599 fTimeGraphWrapper
.getTimeGraphViewer().setTimeBounds(startBound
, endBound
);
1601 TmfTraceContext ctx
= TmfTraceManager
.getInstance().getCurrentTraceContext();
1602 long selectionBeginTime
= fTrace
== null ? SWT
.DEFAULT
: ctx
.getSelectionRange().getStartTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
1603 long selectionEndTime
= fTrace
== null ? SWT
.DEFAULT
: ctx
.getSelectionRange().getEndTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
1604 long startTime
= fTrace
== null ? SWT
.DEFAULT
: ctx
.getWindowRange().getStartTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
1605 long endTime
= fTrace
== null ? SWT
.DEFAULT
: ctx
.getWindowRange().getEndTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
1606 startTime
= (fStartTime
== Long
.MAX_VALUE ? SWT
.DEFAULT
: Math
.max(startTime
, fStartTime
));
1607 endTime
= (fEndTime
== Long
.MIN_VALUE ? SWT
.DEFAULT
: Math
.min(endTime
, fEndTime
));
1608 fTimeGraphWrapper
.getTimeGraphViewer().setSelectionRange(selectionBeginTime
, selectionEndTime
, false);
1609 fTimeGraphWrapper
.getTimeGraphViewer().setStartFinishTime(startTime
, endTime
);
1611 if (fTimeGraphWrapper
instanceof TimeGraphComboWrapper
&& !fPackDone
) {
1612 for (TreeColumn column
: ((TimeGraphComboWrapper
) fTimeGraphWrapper
).getTreeViewer().getTree().getColumns()) {
1621 startZoomThread(startTime
, endTime
);
1630 protected void redraw() {
1631 synchronized (fSyncObj
) {
1632 if (fRedrawState
== State
.IDLE
) {
1633 fRedrawState
= State
.BUSY
;
1635 fRedrawState
= State
.PENDING
;
1639 Display
.getDefault().asyncExec(new Runnable() {
1642 if (fTimeGraphWrapper
.isDisposed()) {
1645 fTimeGraphWrapper
.redraw();
1646 fTimeGraphWrapper
.update();
1647 synchronized (fSyncObj
) {
1648 if (fRedrawState
== State
.PENDING
) {
1649 fRedrawState
= State
.IDLE
;
1652 fRedrawState
= State
.IDLE
;
1659 private static void sortChildren(ITimeGraphEntry entry
, Comparator
<ITimeGraphEntry
> comparator
) {
1660 if (entry
instanceof TimeGraphEntry
) {
1661 ((TimeGraphEntry
) entry
).sortChildren(comparator
);
1663 for (ITimeGraphEntry child
: entry
.getChildren()) {
1664 sortChildren(child
, comparator
);
1669 * Start or restart the zoom thread.
1672 * the zoom start time
1677 protected void startZoomThread(long startTime
, long endTime
) {
1678 boolean restart
= false;
1679 if (fZoomThread
!= null) {
1680 fZoomThread
.cancel();
1681 if (fZoomThread
.fZoomStartTime
== startTime
&& fZoomThread
.fZoomEndTime
== endTime
) {
1685 long resolution
= Math
.max(1, (endTime
- startTime
) / fDisplayWidth
);
1686 fZoomThread
= createZoomThread(startTime
, endTime
, resolution
, restart
);
1687 if (fZoomThread
!= null) {
1688 fZoomThread
.start();
1693 * Create a zoom thread.
1696 * the zoom start time
1702 * true if restarting zoom for the same time range
1703 * @return a zoom thread
1706 protected @Nullable ZoomThread
createZoomThread(long startTime
, long endTime
, long resolution
, boolean restart
) {
1707 final List
<TimeGraphEntry
> entryList
= fEntryList
;
1708 if (entryList
== null) {
1711 return new ZoomThreadByEntry(entryList
, startTime
, endTime
, resolution
);
1714 private void makeActions() {
1715 fPreviousResourceAction
= fTimeGraphWrapper
.getTimeGraphViewer().getPreviousItemAction();
1716 fPreviousResourceAction
.setText(getPrevText());
1717 fPreviousResourceAction
.setToolTipText(getPrevTooltip());
1718 fNextResourceAction
= fTimeGraphWrapper
.getTimeGraphViewer().getNextItemAction();
1719 fNextResourceAction
.setText(getNextText());
1720 fNextResourceAction
.setToolTipText(getNextTooltip());
1723 private void contributeToActionBars() {
1724 IActionBars bars
= getViewSite().getActionBars();
1725 fillLocalToolBar(bars
.getToolBarManager());
1726 fillLocalMenu(bars
.getMenuManager());
1730 * Add actions to local tool bar manager
1732 * @param manager the tool bar manager
1734 protected void fillLocalToolBar(IToolBarManager manager
) {
1735 if (fFilterColumns
!= null && fFilterLabelProvider
!= null && fFilterColumns
.length
> 0) {
1736 manager
.add(fTimeGraphWrapper
.getShowFilterDialogAction());
1738 manager
.add(fTimeGraphWrapper
.getTimeGraphViewer().getShowLegendAction());
1739 manager
.add(new Separator());
1740 manager
.add(fTimeGraphWrapper
.getTimeGraphViewer().getResetScaleAction());
1741 manager
.add(fTimeGraphWrapper
.getTimeGraphViewer().getPreviousEventAction());
1742 manager
.add(fTimeGraphWrapper
.getTimeGraphViewer().getNextEventAction());
1743 manager
.add(new Separator());
1744 manager
.add(fTimeGraphWrapper
.getTimeGraphViewer().getToggleBookmarkAction());
1745 manager
.add(fTimeGraphWrapper
.getTimeGraphViewer().getPreviousMarkerAction());
1746 manager
.add(fTimeGraphWrapper
.getTimeGraphViewer().getNextMarkerAction());
1747 manager
.add(new Separator());
1748 manager
.add(fPreviousResourceAction
);
1749 manager
.add(fNextResourceAction
);
1750 manager
.add(fTimeGraphWrapper
.getTimeGraphViewer().getZoomInAction());
1751 manager
.add(fTimeGraphWrapper
.getTimeGraphViewer().getZoomOutAction());
1752 manager
.add(new Separator());
1756 * Add actions to local menu manager
1758 * @param manager the tool bar manager
1761 protected void fillLocalMenu(IMenuManager manager
) {
1762 manager
.add(fTimeGraphWrapper
.getTimeGraphViewer().getMarkersMenu());
1769 public TmfTimeViewAlignmentInfo
getTimeViewAlignmentInfo() {
1770 if (fTimeGraphWrapper
== null) {
1773 return fTimeGraphWrapper
.getTimeViewAlignmentInfo();
1780 public int getAvailableWidth(int requestedOffset
) {
1781 if (fTimeGraphWrapper
== null) {
1784 return fTimeGraphWrapper
.getAvailableWidth(requestedOffset
);
1791 public void performAlign(int offset
, int width
) {
1792 if (fTimeGraphWrapper
!= null) {
1793 fTimeGraphWrapper
.performAlign(offset
, width
);