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
.concurrent
.atomic
.AtomicInteger
;
31 import java
.util
.regex
.Matcher
;
32 import java
.util
.regex
.Pattern
;
34 import org
.eclipse
.core
.resources
.IFile
;
35 import org
.eclipse
.core
.resources
.IMarker
;
36 import org
.eclipse
.core
.resources
.IMarkerDelta
;
37 import org
.eclipse
.core
.resources
.IResource
;
38 import org
.eclipse
.core
.resources
.IResourceChangeEvent
;
39 import org
.eclipse
.core
.resources
.IResourceChangeListener
;
40 import org
.eclipse
.core
.resources
.IWorkspaceRunnable
;
41 import org
.eclipse
.core
.resources
.ResourcesPlugin
;
42 import org
.eclipse
.core
.runtime
.CoreException
;
43 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
44 import org
.eclipse
.core
.runtime
.NullProgressMonitor
;
45 import org
.eclipse
.jdt
.annotation
.NonNull
;
46 import org
.eclipse
.jdt
.annotation
.Nullable
;
47 import org
.eclipse
.jface
.action
.Action
;
48 import org
.eclipse
.jface
.action
.IAction
;
49 import org
.eclipse
.jface
.action
.IMenuManager
;
50 import org
.eclipse
.jface
.action
.IStatusLineManager
;
51 import org
.eclipse
.jface
.action
.IToolBarManager
;
52 import org
.eclipse
.jface
.action
.Separator
;
53 import org
.eclipse
.jface
.viewers
.AbstractTreeViewer
;
54 import org
.eclipse
.jface
.viewers
.ILabelProvider
;
55 import org
.eclipse
.jface
.viewers
.ILabelProviderListener
;
56 import org
.eclipse
.jface
.viewers
.ISelectionProvider
;
57 import org
.eclipse
.jface
.viewers
.ITableLabelProvider
;
58 import org
.eclipse
.jface
.viewers
.ITreeContentProvider
;
59 import org
.eclipse
.jface
.viewers
.TreeViewer
;
60 import org
.eclipse
.jface
.viewers
.ViewerFilter
;
61 import org
.eclipse
.osgi
.util
.NLS
;
62 import org
.eclipse
.swt
.SWT
;
63 import org
.eclipse
.swt
.events
.SelectionAdapter
;
64 import org
.eclipse
.swt
.events
.SelectionEvent
;
65 import org
.eclipse
.swt
.graphics
.Color
;
66 import org
.eclipse
.swt
.graphics
.Image
;
67 import org
.eclipse
.swt
.widgets
.Composite
;
68 import org
.eclipse
.swt
.widgets
.Display
;
69 import org
.eclipse
.swt
.widgets
.Tree
;
70 import org
.eclipse
.swt
.widgets
.TreeColumn
;
71 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.Activator
;
72 import org
.eclipse
.tracecompass
.tmf
.core
.resources
.ITmfMarker
;
73 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfSelectionRangeUpdatedSignal
;
74 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfSignalHandler
;
75 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfTimestampFormatUpdateSignal
;
76 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfTraceClosedSignal
;
77 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfTraceOpenedSignal
;
78 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfTraceSelectedSignal
;
79 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfWindowRangeUpdatedSignal
;
80 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.ITmfTimestamp
;
81 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.TmfNanoTimestamp
;
82 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.TmfTimeRange
;
83 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfTrace
;
84 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.TmfTraceAdapterManager
;
85 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.TmfTraceContext
;
86 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.TmfTraceManager
;
87 import org
.eclipse
.tracecompass
.tmf
.ui
.TmfUiRefreshHandler
;
88 import org
.eclipse
.tracecompass
.tmf
.ui
.signal
.TmfTimeViewAlignmentInfo
;
89 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.ITmfTimeAligned
;
90 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.TmfView
;
91 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.ITimeGraphBookmarkListener
;
92 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.ITimeGraphContentProvider
;
93 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.ITimeGraphPresentationProvider2
;
94 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.ITimeGraphRangeListener
;
95 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.ITimeGraphSelectionListener
;
96 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.ITimeGraphTimeListener
;
97 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.TimeGraphBookmarkEvent
;
98 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.TimeGraphCombo
;
99 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.TimeGraphContentProvider
;
100 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.TimeGraphPresentationProvider
;
101 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.TimeGraphRangeUpdateEvent
;
102 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.TimeGraphTimeEvent
;
103 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.TimeGraphViewer
;
104 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.ILinkEvent
;
105 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.IMarkerEvent
;
106 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.IMarkerEventSource
;
107 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.ITimeEvent
;
108 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.ITimeGraphEntry
;
109 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.MarkerEvent
;
110 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.TimeGraphEntry
;
111 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.widgets
.Utils
.TimeFormat
;
112 import org
.eclipse
.ui
.IActionBars
;
115 * An abstract view all time graph views can inherit
117 * This view contains either a time graph viewer, or a time graph combo which is
118 * divided between a tree viewer on the left and a time graph viewer on the right.
120 public abstract class AbstractTimeGraphView
extends TmfView
implements ITmfTimeAligned
, IResourceChangeListener
{
122 /** Constant indicating that all levels of the time graph should be expanded */
123 protected static final int ALL_LEVELS
= AbstractTreeViewer
.ALL_LEVELS
;
125 private static final Pattern RGBA_PATTERN
= Pattern
.compile("RGBA \\{(\\d+), (\\d+), (\\d+), (\\d+)\\}"); //$NON-NLS-1$
134 // ------------------------------------------------------------------------
136 // ------------------------------------------------------------------------
138 /** The timegraph wrapper */
139 private ITimeGraphWrapper fTimeGraphWrapper
;
141 private AtomicInteger fDirty
= new AtomicInteger();
143 /** The selected trace */
144 private ITmfTrace fTrace
;
146 /** The selected trace editor file*/
147 private IFile fEditorFile
;
149 /** The timegraph entry list */
150 private List
<TimeGraphEntry
> fEntryList
;
152 /** The trace to entry list hash map */
153 private final Map
<ITmfTrace
, List
<TimeGraphEntry
>> fEntryListMap
= new HashMap
<>();
155 /** The trace to filters hash map */
156 private final Map
<ITmfTrace
, @NonNull ViewerFilter
[]> fFiltersMap
= new HashMap
<>();
158 /** The trace to marker event sources hash map */
159 private final Map
<ITmfTrace
, List
<IMarkerEventSource
>> fMarkerEventSourcesMap
= new HashMap
<>();
161 /** The trace to build thread hash map */
162 private final Map
<ITmfTrace
, BuildThread
> fBuildThreadMap
= new HashMap
<>();
164 /** The start time */
165 private long fStartTime
= SWT
.DEFAULT
;
168 private long fEndTime
= SWT
.DEFAULT
;
170 /** The display width */
171 private final int fDisplayWidth
;
173 /** The zoom thread */
174 private ZoomThread fZoomThread
;
176 /** The next resource action */
177 private Action fNextResourceAction
;
179 /** The previous resource action */
180 private Action fPreviousResourceAction
;
182 /** A comparator class */
183 private Comparator
<ITimeGraphEntry
> fEntryComparator
= null;
185 /** The redraw state used to prevent unnecessary queuing of display runnables */
186 private State fRedrawState
= State
.IDLE
;
188 /** The redraw synchronization object */
189 private final Object fSyncObj
= new Object();
191 /** The presentation provider for this view */
192 private final TimeGraphPresentationProvider fPresentation
;
194 /** The tree column label array, or null if combo is not used */
195 private String
[] fColumns
;
197 private Comparator
<ITimeGraphEntry
>[] fColumnComparators
;
199 /** The sort direction */
200 private int fDirection
= SWT
.DOWN
;
202 /** The tree label provider, or null if combo is not used */
203 private TreeLabelProvider fLabelProvider
= null;
205 /** The time graph content provider */
206 private @NonNull ITimeGraphContentProvider fTimeGraphContentProvider
= new TimeGraphContentProvider();
208 /** The relative weight of the sash, ignored if combo is not used */
209 private int[] fWeight
= { 1, 3 };
211 /** The filter column label array, or null if filter is not used */
212 private String
[] fFilterColumns
;
214 /** The pack done flag */
215 private boolean fPackDone
= false;
217 /** The filter content provider, or null if filter is not used */
218 private ITreeContentProvider fFilterContentProvider
;
220 /** The filter label provider, or null if filter is not used */
221 private TreeLabelProvider fFilterLabelProvider
;
223 private int fAutoExpandLevel
= ALL_LEVELS
;
225 /** The list of color resources created by this view */
226 private final List
<Color
> fColors
= new ArrayList
<>();
228 /** The default column index for sorting */
229 private int fInitialSortColumn
= 0;
231 /** Flag to indicate to reveal selection */
232 private volatile boolean fIsRevealSelection
= false;
234 // ------------------------------------------------------------------------
236 // ------------------------------------------------------------------------
238 private interface ITimeGraphWrapper
{
240 void setTimeGraphContentProvider(ITimeGraphContentProvider timeGraphContentProvider
);
242 void setTimeGraphPresentationProvider(TimeGraphPresentationProvider timeGraphPresentationProvider
);
244 TimeGraphViewer
getTimeGraphViewer();
246 void addSelectionListener(ITimeGraphSelectionListener listener
);
248 ISelectionProvider
getSelectionProvider();
252 boolean isDisposed();
256 void setInput(Object input
);
260 void setFilters(@NonNull ViewerFilter
[] filters
);
262 @NonNull ViewerFilter
[] getFilters();
268 void setAutoExpandLevel(int level
);
270 void setFilterColumns(String
[] columnNames
);
272 void setFilterContentProvider(ITreeContentProvider contentProvider
);
274 void setFilterLabelProvider(ITableLabelProvider labelProvider
);
276 IAction
getShowFilterDialogAction();
278 void performAlign(int offset
, int width
);
280 TmfTimeViewAlignmentInfo
getTimeViewAlignmentInfo();
282 int getAvailableWidth(int requestedOffset
);
285 private class TimeGraphViewerWrapper
implements ITimeGraphWrapper
{
286 private TimeGraphViewer viewer
;
288 private TimeGraphViewerWrapper(Composite parent
, int style
) {
289 viewer
= new TimeGraphViewer(parent
, style
);
293 public void setTimeGraphContentProvider(ITimeGraphContentProvider timeGraphContentProvider
) {
294 viewer
.setTimeGraphContentProvider(timeGraphContentProvider
);
298 public void setTimeGraphPresentationProvider(TimeGraphPresentationProvider timeGraphPresentationProvider
) {
299 viewer
.setTimeGraphProvider(timeGraphPresentationProvider
);
303 public TimeGraphViewer
getTimeGraphViewer() {
308 public void addSelectionListener(ITimeGraphSelectionListener listener
) {
309 viewer
.addSelectionListener(listener
);
313 public ISelectionProvider
getSelectionProvider() {
314 return viewer
.getSelectionProvider();
318 public void setFocus() {
323 public boolean isDisposed() {
324 return viewer
.getControl().isDisposed();
328 public void setInput(Object input
) {
329 viewer
.setInput(input
);
333 public Object
getInput() {
334 return viewer
.getInput();
338 public void setFilterColumns(String
[] columnNames
) {
339 viewer
.setFilterColumns(columnNames
);
343 public void setFilterContentProvider(ITreeContentProvider contentProvider
) {
344 viewer
.setFilterContentProvider(contentProvider
);
348 public void setFilterLabelProvider(ITableLabelProvider labelProvider
) {
349 viewer
.setFilterLabelProvider(labelProvider
);
353 public void setFilters(@NonNull ViewerFilter
[] filters
) {
354 viewer
.setFilters(filters
);
358 public @NonNull ViewerFilter
[] getFilters() {
359 return viewer
.getFilters();
363 public IAction
getShowFilterDialogAction() {
364 return viewer
.getShowFilterDialogAction();
368 public void refresh() {
373 public void redraw() {
374 viewer
.getControl().redraw();
378 public void update() {
379 viewer
.getControl().update();
383 public void setAutoExpandLevel(int level
) {
384 viewer
.setAutoExpandLevel(level
);
388 public void performAlign(int offset
, int width
) {
389 viewer
.performAlign(offset
, width
);
393 public TmfTimeViewAlignmentInfo
getTimeViewAlignmentInfo() {
394 return viewer
.getTimeViewAlignmentInfo();
398 public int getAvailableWidth(int requestedOffset
) {
399 return viewer
.getAvailableWidth(requestedOffset
);
403 private class TimeGraphComboWrapper
implements ITimeGraphWrapper
{
404 private TimeGraphCombo combo
;
406 private TimeGraphComboWrapper(Composite parent
, int style
) {
407 combo
= new TimeGraphCombo(parent
, style
, fWeight
);
411 public void setTimeGraphContentProvider(ITimeGraphContentProvider timeGraphContentProvider
) {
412 combo
.setTimeGraphContentProvider(timeGraphContentProvider
);
416 public void setTimeGraphPresentationProvider(TimeGraphPresentationProvider timeGraphPresentationProvider
) {
417 combo
.setTimeGraphProvider(timeGraphPresentationProvider
);
421 public TimeGraphViewer
getTimeGraphViewer() {
422 return combo
.getTimeGraphViewer();
426 public void addSelectionListener(ITimeGraphSelectionListener listener
) {
427 combo
.addSelectionListener(listener
);
431 public ISelectionProvider
getSelectionProvider() {
432 return combo
.getTreeViewer();
436 public void setFocus() {
441 public boolean isDisposed() {
442 return combo
.isDisposed();
446 public void setInput(Object input
) {
447 combo
.setInput(input
);
451 public Object
getInput() {
452 return combo
.getInput();
456 public void setFilterColumns(String
[] columnNames
) {
457 combo
.setFilterColumns(columnNames
);
461 public void setFilterContentProvider(ITreeContentProvider contentProvider
) {
462 combo
.setFilterContentProvider(contentProvider
);
466 public void setFilterLabelProvider(ITableLabelProvider labelProvider
) {
467 combo
.setFilterLabelProvider(labelProvider
);
471 public void setFilters(@NonNull ViewerFilter
[] filters
) {
472 combo
.setFilters(filters
);
476 public @NonNull ViewerFilter
[] getFilters() {
477 return combo
.getFilters();
481 public IAction
getShowFilterDialogAction() {
482 return combo
.getShowFilterDialogAction();
486 public void refresh() {
491 public void redraw() {
496 public void update() {
501 public void setAutoExpandLevel(int level
) {
502 combo
.setAutoExpandLevel(level
);
505 TimeGraphCombo
getTimeGraphCombo() {
509 TreeViewer
getTreeViewer() {
510 return combo
.getTreeViewer();
514 public void performAlign(int offset
, int width
) {
515 combo
.performAlign(offset
, width
);
519 public TmfTimeViewAlignmentInfo
getTimeViewAlignmentInfo() {
520 return combo
.getTimeViewAlignmentInfo();
524 public int getAvailableWidth(int requestedOffset
) {
525 return combo
.getAvailableWidth(requestedOffset
);
530 * Base class to provide the labels for the tree viewer. Views extending
531 * this class typically need to override the getColumnText method if they
532 * have more than one column to display
534 protected static class TreeLabelProvider
implements ITableLabelProvider
, ILabelProvider
{
537 public void addListener(ILabelProviderListener listener
) {
541 public void dispose() {
545 public boolean isLabelProperty(Object element
, String property
) {
550 public void removeListener(ILabelProviderListener listener
) {
554 public Image
getColumnImage(Object element
, int columnIndex
) {
559 public String
getColumnText(Object element
, int columnIndex
) {
560 TimeGraphEntry entry
= (TimeGraphEntry
) element
;
561 if (columnIndex
== 0) {
562 return entry
.getName();
568 public Image
getImage(Object element
) {
573 public String
getText(Object element
) {
574 TimeGraphEntry entry
= (TimeGraphEntry
) element
;
575 return entry
.getName();
580 private class BuildThread
extends Thread
{
581 private final @NonNull ITmfTrace fBuildTrace
;
582 private final @NonNull ITmfTrace fParentTrace
;
583 private final @NonNull IProgressMonitor fMonitor
;
585 public BuildThread(final @NonNull ITmfTrace trace
, final @NonNull ITmfTrace parentTrace
, final String name
) {
586 super(name
+ " build"); //$NON-NLS-1$
588 fParentTrace
= parentTrace
;
589 fMonitor
= new NullProgressMonitor();
594 buildEventList(fBuildTrace
, fParentTrace
, fMonitor
);
595 synchronized (fBuildThreadMap
) {
596 fBuildThreadMap
.remove(fBuildTrace
);
600 public void cancel() {
601 fMonitor
.setCanceled(true);
609 protected abstract class ZoomThread
extends Thread
{
610 private final long fZoomStartTime
;
611 private final long fZoomEndTime
;
612 private final long fResolution
;
613 private final @NonNull IProgressMonitor fMonitor
;
625 public ZoomThread(long startTime
, long endTime
, long resolution
) {
626 super(AbstractTimeGraphView
.this.getName() + " zoom"); //$NON-NLS-1$
627 fZoomStartTime
= startTime
;
628 fZoomEndTime
= endTime
;
629 fResolution
= resolution
;
630 fMonitor
= new NullProgressMonitor();
634 * @return the zoom start time
636 public long getZoomStartTime() {
637 return fZoomStartTime
;
641 * @return the zoom end time
643 public long getZoomEndTime() {
648 * @return the resolution
650 public long getResolution() {
655 * @return the monitor
657 public @NonNull IProgressMonitor
getMonitor() {
662 * Cancel the zoom thread
664 public void cancel() {
665 fMonitor
.setCanceled(true);
669 public final void run() {
671 fDirty
.decrementAndGet();
675 * Run the zoom operation.
678 public abstract void doRun();
681 private class ZoomThreadByEntry
extends ZoomThread
{
682 private final @NonNull List
<TimeGraphEntry
> fZoomEntryList
;
684 public ZoomThreadByEntry(@NonNull List
<TimeGraphEntry
> entryList
, long startTime
, long endTime
, long resolution
) {
685 super(startTime
, endTime
, resolution
);
686 fZoomEntryList
= entryList
;
690 public void doRun() {
691 for (TimeGraphEntry entry
: fZoomEntryList
) {
692 if (getMonitor().isCanceled()) {
698 zoom(entry
, getMonitor());
700 /* Refresh the arrows when zooming */
701 List
<ILinkEvent
> events
= getLinkList(getZoomStartTime(), getZoomEndTime(), getResolution(), getMonitor());
702 if (events
!= null) {
703 fTimeGraphWrapper
.getTimeGraphViewer().setLinks(events
);
706 /* Refresh the view-specific markers when zooming */
707 List
<IMarkerEvent
> markers
= new ArrayList
<>(getViewMarkerList(getZoomStartTime(), getZoomEndTime(), getResolution(), getMonitor()));
708 /* Refresh the trace-specific markers when zooming */
709 markers
.addAll(getTraceMarkerList(getZoomStartTime(), getZoomEndTime(), getResolution(), getMonitor()));
710 fTimeGraphWrapper
.getTimeGraphViewer().setMarkers(markers
);
714 private void zoom(@NonNull TimeGraphEntry entry
, @NonNull IProgressMonitor monitor
) {
715 if (getZoomStartTime() <= fStartTime
&& getZoomEndTime() >= fEndTime
) {
716 entry
.setZoomedEventList(null);
718 List
<ITimeEvent
> zoomedEventList
= getEventList(entry
, getZoomStartTime(), getZoomEndTime(), getResolution(), monitor
);
719 if (zoomedEventList
!= null) {
720 entry
.setZoomedEventList(zoomedEventList
);
724 for (ITimeGraphEntry child
: entry
.getChildren()) {
725 if (monitor
.isCanceled()) {
728 if (child
instanceof TimeGraphEntry
) {
729 zoom((TimeGraphEntry
) child
, monitor
);
736 // ------------------------------------------------------------------------
738 // ------------------------------------------------------------------------
741 * Constructs a time graph view that contains either a time graph viewer or
742 * a time graph combo.
744 * By default, the view uses a time graph viewer. To use a time graph combo,
745 * the subclass constructor must call {@link #setTreeColumns(String[])} and
746 * {@link #setTreeLabelProvider(TreeLabelProvider)}.
751 * The presentation provider
753 public AbstractTimeGraphView(String id
, TimeGraphPresentationProvider pres
) {
755 fPresentation
= pres
;
756 fDisplayWidth
= Display
.getDefault().getBounds().width
;
759 // ------------------------------------------------------------------------
760 // Getters and setters
761 // ------------------------------------------------------------------------
764 * Getter for the time graph combo
766 * @return The time graph combo, or null if combo is not used
768 protected TimeGraphCombo
getTimeGraphCombo() {
769 if (fTimeGraphWrapper
instanceof TimeGraphComboWrapper
) {
770 return ((TimeGraphComboWrapper
) fTimeGraphWrapper
).getTimeGraphCombo();
776 * Getter for the time graph viewer
778 * @return The time graph viewer
780 protected TimeGraphViewer
getTimeGraphViewer() {
781 return fTimeGraphWrapper
.getTimeGraphViewer();
785 * Getter for the presentation provider
787 * @return The time graph presentation provider
789 protected ITimeGraphPresentationProvider2
getPresentationProvider() {
790 return fPresentation
;
794 * Sets the tree column labels.
796 * This should be called from the constructor.
799 * The array of tree column labels
801 protected void setTreeColumns(final String
[] columns
) {
802 setTreeColumns(columns
, null, 0);
806 * Sets the tree column labels.
808 * This should be called from the constructor.
811 * The array of tree column labels
813 * An array of column comparators for sorting of columns when
814 * clicking on column header
815 * @param initialSortColumn
816 * Index of column to sort initially
819 protected void setTreeColumns(final String
[] columns
, final Comparator
<ITimeGraphEntry
>[] comparators
, int initialSortColumn
) {
820 checkPartNotCreated();
822 fColumnComparators
= comparators
;
823 fInitialSortColumn
= initialSortColumn
;
827 * Sets the tree label provider.
829 * This should be called from the constructor.
832 * The tree label provider
834 protected void setTreeLabelProvider(final TreeLabelProvider tlp
) {
835 checkPartNotCreated();
836 fLabelProvider
= tlp
;
840 * Sets the time graph content provider.
842 * This should be called from the constructor.
845 * The time graph content provider
848 protected void setTimeGraphContentProvider(final @NonNull ITimeGraphContentProvider tgcp
) {
849 checkPartNotCreated();
850 fTimeGraphContentProvider
= tgcp
;
854 * Sets the relative weight of each part of the time graph combo.
856 * This should be called from the constructor.
859 * The array (length 2) of relative weights of each part of the combo
861 protected void setWeight(final int[] weights
) {
862 checkPartNotCreated();
867 * Sets the filter column labels.
869 * This should be called from the constructor.
871 * @param filterColumns
872 * The array of filter column labels
874 protected void setFilterColumns(final String
[] filterColumns
) {
875 checkPartNotCreated();
876 fFilterColumns
= filterColumns
;
880 * Sets the filter content provider.
882 * This should be called from the constructor.
884 * @param contentProvider
885 * The filter content provider
888 protected void setFilterContentProvider(final ITreeContentProvider contentProvider
) {
889 checkPartNotCreated();
890 fFilterContentProvider
= contentProvider
;
894 * Sets the filter label provider.
896 * This should be called from the constructor.
898 * @param labelProvider
899 * The filter label provider
901 protected void setFilterLabelProvider(final TreeLabelProvider labelProvider
) {
902 checkPartNotCreated();
903 fFilterLabelProvider
= labelProvider
;
906 private void checkPartNotCreated() {
907 if (getParentComposite() != null) {
908 throw new IllegalStateException("This method must be called before createPartControl."); //$NON-NLS-1$
913 * Gets the display width
915 * @return the display width
917 protected int getDisplayWidth() {
918 return fDisplayWidth
;
922 * Gets the comparator for the entries
924 * @return The entry comparator
926 protected Comparator
<ITimeGraphEntry
> getEntryComparator() {
927 return fEntryComparator
;
931 * Sets the comparator class for the entries.
933 * This comparator will apply recursively to entries that implement
934 * {@link TimeGraphEntry#sortChildren(Comparator)}.
937 * A comparator object
939 protected void setEntryComparator(final Comparator
<ITimeGraphEntry
> comparator
) {
940 fEntryComparator
= comparator
;
944 * Gets the trace displayed in the view
948 protected ITmfTrace
getTrace() {
953 * Gets the start time
955 * @return The start time
957 protected long getStartTime() {
962 * Sets the start time
967 protected void setStartTime(long time
) {
974 * @return The end time
976 protected long getEndTime() {
986 protected void setEndTime(long time
) {
991 * Sets the auto-expand level to be used for the input of the view. The
992 * value 0 means that there is no auto-expand; 1 means that top-level
993 * elements are expanded, but not their children; 2 means that top-level
994 * elements are expanded, and their children, but not grand-children; and so
997 * The value {@link #ALL_LEVELS} means that all subtrees should be expanded.
1001 * non-negative level, or <code>ALL_LEVELS</code> to expand all
1002 * levels of the tree
1004 protected void setAutoExpandLevel(int level
) {
1005 fAutoExpandLevel
= level
;
1006 ITimeGraphWrapper tgWrapper
= fTimeGraphWrapper
;
1007 if (tgWrapper
!= null) {
1008 tgWrapper
.setAutoExpandLevel(level
);
1013 * Gets the entry list for a trace
1018 * @return the entry list map
1020 protected List
<TimeGraphEntry
> getEntryList(ITmfTrace trace
) {
1021 synchronized (fEntryListMap
) {
1022 return fEntryListMap
.get(trace
);
1027 * Adds a trace entry list to the entry list map
1032 * the list of time graph entries
1034 protected void putEntryList(ITmfTrace trace
, List
<TimeGraphEntry
> list
) {
1035 synchronized (fEntryListMap
) {
1036 fEntryListMap
.put(trace
, new CopyOnWriteArrayList
<>(list
));
1041 * Adds a list of entries to a trace's entry list
1046 * the list of time graph entries to add
1048 protected void addToEntryList(ITmfTrace trace
, List
<TimeGraphEntry
> list
) {
1049 synchronized (fEntryListMap
) {
1050 List
<TimeGraphEntry
> entryList
= fEntryListMap
.get(trace
);
1051 if (entryList
== null) {
1052 fEntryListMap
.put(trace
, new CopyOnWriteArrayList
<>(list
));
1054 entryList
.addAll(list
);
1060 * Removes a list of entries from a trace's entry list
1065 * the list of time graph entries to remove
1067 protected void removeFromEntryList(ITmfTrace trace
, List
<TimeGraphEntry
> list
) {
1068 synchronized (fEntryListMap
) {
1069 List
<TimeGraphEntry
> entryList
= fEntryListMap
.get(trace
);
1070 if (entryList
!= null) {
1071 entryList
.removeAll(list
);
1077 * Text for the "next" button
1079 * @return The "next" button text
1081 protected String
getNextText() {
1082 return Messages
.AbstractTimeGraphtView_NextText
;
1086 * Tooltip for the "next" button
1088 * @return Tooltip for the "next" button
1090 protected String
getNextTooltip() {
1091 return Messages
.AbstractTimeGraphView_NextTooltip
;
1095 * Text for the "Previous" button
1097 * @return The "Previous" button text
1099 protected String
getPrevText() {
1100 return Messages
.AbstractTimeGraphView_PreviousText
;
1104 * Tooltip for the "previous" button
1106 * @return Tooltip for the "previous" button
1108 protected String
getPrevTooltip() {
1109 return Messages
.AbstractTimeGraphView_PreviousTooltip
;
1112 // ------------------------------------------------------------------------
1114 // ------------------------------------------------------------------------
1117 public void createPartControl(Composite parent
) {
1118 super.createPartControl(parent
);
1119 if (fColumns
== null || fLabelProvider
== null) {
1120 fTimeGraphWrapper
= new TimeGraphViewerWrapper(parent
, SWT
.NONE
);
1122 TimeGraphComboWrapper wrapper
= new TimeGraphComboWrapper(parent
, SWT
.NONE
);
1123 fTimeGraphWrapper
= wrapper
;
1124 TimeGraphCombo combo
= wrapper
.getTimeGraphCombo();
1125 combo
.setTreeContentProvider(fTimeGraphContentProvider
);
1126 combo
.setTreeLabelProvider(fLabelProvider
);
1127 combo
.setTreeColumns(fColumns
);
1128 if (fColumnComparators
!= null) {
1129 createColumnSelectionListener(combo
.getTreeViewer());
1132 fTimeGraphWrapper
.setTimeGraphContentProvider(fTimeGraphContentProvider
);
1133 fTimeGraphWrapper
.setFilterContentProvider(fFilterContentProvider
!= null ? fFilterContentProvider
: fTimeGraphContentProvider
);
1134 fTimeGraphWrapper
.setFilterLabelProvider(fFilterLabelProvider
);
1135 fTimeGraphWrapper
.setFilterColumns(fFilterColumns
);
1137 fTimeGraphWrapper
.setTimeGraphPresentationProvider(fPresentation
);
1138 fTimeGraphWrapper
.setAutoExpandLevel(fAutoExpandLevel
);
1140 fTimeGraphWrapper
.getTimeGraphViewer().addRangeListener(new ITimeGraphRangeListener() {
1142 public void timeRangeUpdated(TimeGraphRangeUpdateEvent event
) {
1143 final long startTime
= event
.getStartTime();
1144 final long endTime
= event
.getEndTime();
1145 TmfTimeRange range
= new TmfTimeRange(new TmfNanoTimestamp(startTime
), new TmfNanoTimestamp(endTime
));
1146 broadcast(new TmfWindowRangeUpdatedSignal(AbstractTimeGraphView
.this, range
));
1147 startZoomThread(startTime
, endTime
);
1151 fTimeGraphWrapper
.getTimeGraphViewer().addTimeListener(new ITimeGraphTimeListener() {
1153 public void timeSelected(TimeGraphTimeEvent event
) {
1154 TmfNanoTimestamp startTime
= new TmfNanoTimestamp(event
.getBeginTime());
1155 TmfNanoTimestamp endTime
= new TmfNanoTimestamp(event
.getEndTime());
1156 broadcast(new TmfSelectionRangeUpdatedSignal(AbstractTimeGraphView
.this, startTime
, endTime
));
1160 fTimeGraphWrapper
.getTimeGraphViewer().addBookmarkListener(new ITimeGraphBookmarkListener() {
1162 public void bookmarkAdded(final TimeGraphBookmarkEvent event
) {
1164 ResourcesPlugin
.getWorkspace().run(new IWorkspaceRunnable() {
1166 public void run(IProgressMonitor monitor
) throws CoreException
{
1167 IMarkerEvent bookmark
= event
.getBookmark();
1168 IMarker marker
= fEditorFile
.createMarker(IMarker
.BOOKMARK
);
1169 marker
.setAttribute(IMarker
.MESSAGE
, bookmark
.getLabel());
1170 marker
.setAttribute(ITmfMarker
.MARKER_TIME
, Long
.toString(bookmark
.getTime()));
1171 if (bookmark
.getDuration() > 0) {
1172 marker
.setAttribute(ITmfMarker
.MARKER_DURATION
, Long
.toString(bookmark
.getDuration()));
1173 marker
.setAttribute(IMarker
.LOCATION
,
1174 NLS
.bind(org
.eclipse
.tracecompass
.internal
.tmf
.ui
.Messages
.TmfMarker_LocationTimeRange
,
1175 new TmfNanoTimestamp(bookmark
.getTime()),
1176 new TmfNanoTimestamp(bookmark
.getTime() + bookmark
.getDuration())));
1178 marker
.setAttribute(IMarker
.LOCATION
,
1179 NLS
.bind(org
.eclipse
.tracecompass
.internal
.tmf
.ui
.Messages
.TmfMarker_LocationTime
,
1180 new TmfNanoTimestamp(bookmark
.getTime())));
1182 marker
.setAttribute(ITmfMarker
.MARKER_COLOR
, bookmark
.getColor().getRGBA().toString());
1185 } catch (CoreException e
) {
1186 Activator
.getDefault().logError(e
.getMessage());
1191 public void bookmarkRemoved(TimeGraphBookmarkEvent event
) {
1193 IMarkerEvent bookmark
= event
.getBookmark();
1194 IMarker
[] markers
= fEditorFile
.findMarkers(IMarker
.BOOKMARK
, false, IResource
.DEPTH_ZERO
);
1195 for (IMarker marker
: markers
) {
1196 if (bookmark
.getLabel().equals(marker
.getAttribute(IMarker
.MESSAGE
)) &&
1197 Long
.toString(bookmark
.getTime()).equals(marker
.getAttribute(ITmfMarker
.MARKER_TIME
, (String
) null)) &&
1198 Long
.toString(bookmark
.getDuration()).equals(marker
.getAttribute(ITmfMarker
.MARKER_DURATION
, Long
.toString(0))) &&
1199 bookmark
.getColor().getRGBA().toString().equals(marker
.getAttribute(ITmfMarker
.MARKER_COLOR
))) {
1204 } catch (CoreException e
) {
1205 Activator
.getDefault().logError(e
.getMessage());
1210 fTimeGraphWrapper
.getTimeGraphViewer().setTimeFormat(TimeFormat
.CALENDAR
);
1212 IStatusLineManager statusLineManager
= getViewSite().getActionBars().getStatusLineManager();
1213 fTimeGraphWrapper
.getTimeGraphViewer().getTimeGraphControl().setStatusLineManager(statusLineManager
);
1215 // View Action Handling
1217 contributeToActionBars();
1219 ITmfTrace trace
= TmfTraceManager
.getInstance().getActiveTrace();
1220 if (trace
!= null) {
1221 traceSelected(new TmfTraceSelectedSignal(this, trace
));
1224 // make selection available to other views
1225 getSite().setSelectionProvider(fTimeGraphWrapper
.getSelectionProvider());
1227 ResourcesPlugin
.getWorkspace().addResourceChangeListener(this, IResourceChangeEvent
.POST_CHANGE
);
1231 public void setFocus() {
1232 fTimeGraphWrapper
.setFocus();
1236 public void dispose() {
1238 ResourcesPlugin
.getWorkspace().removeResourceChangeListener(this);
1245 public void resourceChanged(final IResourceChangeEvent event
) {
1246 for (final IMarkerDelta delta
: event
.findMarkerDeltas(IMarker
.BOOKMARK
, false)) {
1247 if (delta
.getResource().equals(fEditorFile
)) {
1248 fTimeGraphWrapper
.getTimeGraphViewer().setBookmarks(refreshBookmarks(fEditorFile
));
1255 private List
<IMarkerEvent
> refreshBookmarks(final IFile editorFile
) {
1256 List
<IMarkerEvent
> bookmarks
= new ArrayList
<>();
1257 for (Color color
: fColors
) {
1261 if (editorFile
== null || !editorFile
.exists()) {
1265 IMarker
[] markers
= editorFile
.findMarkers(IMarker
.BOOKMARK
, false, IResource
.DEPTH_ZERO
);
1266 for (IMarker marker
: markers
) {
1267 String label
= marker
.getAttribute(IMarker
.MESSAGE
, (String
) null);
1268 String time
= marker
.getAttribute(ITmfMarker
.MARKER_TIME
, (String
) null);
1269 String duration
= marker
.getAttribute(ITmfMarker
.MARKER_DURATION
, Long
.toString(0));
1270 String rgba
= marker
.getAttribute(ITmfMarker
.MARKER_COLOR
, (String
) null);
1271 if (label
!= null && time
!= null && rgba
!= null) {
1272 Matcher matcher
= RGBA_PATTERN
.matcher(rgba
);
1273 if (matcher
.matches()) {
1275 int red
= Integer
.valueOf(matcher
.group(1));
1276 int green
= Integer
.valueOf(matcher
.group(2));
1277 int blue
= Integer
.valueOf(matcher
.group(3));
1278 int alpha
= Integer
.valueOf(matcher
.group(4));
1279 Color color
= new Color(Display
.getDefault(), red
, green
, blue
, alpha
);
1281 bookmarks
.add(new MarkerEvent(null, Long
.valueOf(time
), Long
.valueOf(duration
), IMarkerEvent
.BOOKMARKS
, color
, label
, true));
1282 } catch (NumberFormatException e
) {
1283 Activator
.getDefault().logError(e
.getMessage());
1288 } catch (CoreException e
) {
1289 Activator
.getDefault().logError(e
.getMessage());
1296 // ------------------------------------------------------------------------
1298 // ------------------------------------------------------------------------
1301 * Handler for the trace opened signal.
1304 * The incoming signal
1307 public void traceOpened(TmfTraceOpenedSignal signal
) {
1308 loadTrace(signal
.getTrace());
1312 * Handler for the trace selected signal
1315 * The incoming signal
1318 public void traceSelected(final TmfTraceSelectedSignal signal
) {
1319 if (signal
.getTrace() == fTrace
) {
1322 loadTrace(signal
.getTrace());
1326 * Trace is closed: clear the data structures and the view
1329 * the signal received
1332 public void traceClosed(final TmfTraceClosedSignal signal
) {
1333 synchronized (fBuildThreadMap
) {
1334 for (ITmfTrace trace
: getTracesToBuild(signal
.getTrace())) {
1335 BuildThread buildThread
= fBuildThreadMap
.remove(trace
);
1336 if (buildThread
!= null) {
1337 buildThread
.cancel();
1341 fMarkerEventSourcesMap
.remove(signal
.getTrace());
1342 synchronized (fEntryListMap
) {
1343 fEntryListMap
.remove(signal
.getTrace());
1345 fFiltersMap
.remove(signal
.getTrace());
1346 if (signal
.getTrace() == fTrace
) {
1349 fStartTime
= SWT
.DEFAULT
;
1350 fEndTime
= SWT
.DEFAULT
;
1351 if (fZoomThread
!= null) {
1352 fZoomThread
.cancel();
1360 * Handler for the selection range signal.
1363 * The signal that's received
1367 public void selectionRangeUpdated(final TmfSelectionRangeUpdatedSignal signal
) {
1368 if (signal
.getSource() == this || fTrace
== null) {
1371 final long beginTime
= signal
.getBeginTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
1372 final long endTime
= signal
.getEndTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
1374 Display
.getDefault().asyncExec(new Runnable() {
1377 if (fTimeGraphWrapper
.isDisposed()) {
1380 if (beginTime
== endTime
) {
1381 fTimeGraphWrapper
.getTimeGraphViewer().setSelectedTime(beginTime
, true);
1383 fTimeGraphWrapper
.getTimeGraphViewer().setSelectionRange(beginTime
, endTime
, true);
1385 synchingToTime(fTimeGraphWrapper
.getTimeGraphViewer().getSelectionBegin());
1391 * Handler for the window range signal.
1394 * The signal that's received
1398 public void windowRangeUpdated(final TmfWindowRangeUpdatedSignal signal
) {
1399 if (signal
.getSource() == this || fTrace
== null) {
1402 if (signal
.getCurrentRange().getIntersection(fTrace
.getTimeRange()) == null) {
1405 final long startTime
= signal
.getCurrentRange().getStartTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
1406 final long endTime
= signal
.getCurrentRange().getEndTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
1407 Display
.getDefault().asyncExec(new Runnable() {
1410 if (fTimeGraphWrapper
.isDisposed()) {
1413 fTimeGraphWrapper
.getTimeGraphViewer().setStartFinishTime(startTime
, endTime
);
1414 startZoomThread(startTime
, endTime
);
1420 * @param signal the format of the timestamps was updated.
1423 public void updateTimeFormat( final TmfTimestampFormatUpdateSignal signal
){
1424 fTimeGraphWrapper
.refresh();
1427 // ------------------------------------------------------------------------
1429 // ------------------------------------------------------------------------
1431 private void loadTrace(final ITmfTrace trace
) {
1432 if (fZoomThread
!= null) {
1433 fZoomThread
.cancel();
1436 if (fTrace
!= null) {
1437 /* save the filters of the previous trace */
1438 fFiltersMap
.put(fTrace
, fTimeGraphWrapper
.getFilters());
1441 fEditorFile
= TmfTraceManager
.getInstance().getTraceEditorFile(trace
);
1442 synchronized (fEntryListMap
) {
1443 fEntryList
= fEntryListMap
.get(fTrace
);
1444 if (fEntryList
== null) {
1447 fStartTime
= fTrace
.getStartTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
1448 fEndTime
= fTrace
.getEndTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
1455 * Forces a rebuild of the entries list, even if entries already exist for this trace
1457 protected void rebuild() {
1458 setStartTime(Long
.MAX_VALUE
);
1459 setEndTime(Long
.MIN_VALUE
);
1461 ITmfTrace viewTrace
= fTrace
;
1462 if (viewTrace
== null) {
1465 List
<IMarkerEventSource
> markerEventSources
= new ArrayList
<>();
1466 synchronized (fBuildThreadMap
) {
1467 for (ITmfTrace trace
: getTracesToBuild(viewTrace
)) {
1468 if (trace
== null) {
1471 markerEventSources
.addAll(TmfTraceAdapterManager
.getAdapters(trace
, IMarkerEventSource
.class));
1472 BuildThread buildThread
= new BuildThread(trace
, viewTrace
, getName());
1473 fBuildThreadMap
.put(trace
, buildThread
);
1474 buildThread
.start();
1477 fMarkerEventSourcesMap
.put(viewTrace
, markerEventSources
);
1481 * Method called when synching to a given timestamp. Inheriting classes can
1482 * perform actions here to update the view at the given timestamp.
1485 * The currently selected time
1487 protected void synchingToTime(long time
) {
1492 * Return the list of traces whose data or analysis results will be used to
1493 * populate the view. By default, if the trace is an experiment, the traces
1494 * under it will be returned, otherwise, the trace itself is returned.
1496 * A build thread will be started for each trace returned by this method,
1497 * some of which may receive events in live streaming mode.
1500 * The trace associated with this view
1501 * @return List of traces with data to display
1503 protected @NonNull Iterable
<ITmfTrace
> getTracesToBuild(@NonNull ITmfTrace trace
) {
1504 return TmfTraceManager
.getTraceSet(trace
);
1508 * Build the entries list to show in this time graph
1510 * Called from the BuildThread
1513 * The trace being built
1514 * @param parentTrace
1515 * The parent of the trace set, or the trace itself
1517 * The progress monitor object
1519 protected abstract void buildEventList(@NonNull ITmfTrace trace
, @NonNull ITmfTrace parentTrace
, @NonNull IProgressMonitor monitor
);
1522 * Gets the list of event for an entry in a given timerange
1525 * The entry to get events for
1527 * Start of the time range
1529 * End of the time range
1533 * The progress monitor object
1534 * @return The list of events for the entry
1536 protected abstract @Nullable List
<@NonNull ITimeEvent
> getEventList(@NonNull TimeGraphEntry entry
,
1537 long startTime
, long endTime
, long resolution
,
1538 @NonNull IProgressMonitor monitor
);
1541 * Gets the list of links (displayed as arrows) for a trace in a given
1542 * timerange. Default implementation returns an empty list.
1545 * Start of the time range
1547 * End of the time range
1551 * The progress monitor object
1552 * @return The list of link events
1554 protected @Nullable List
<@NonNull ILinkEvent
> getLinkList(long startTime
, long endTime
,
1555 long resolution
, @NonNull IProgressMonitor monitor
) {
1556 return new ArrayList
<>();
1560 * Gets the list of view-specific marker categories. Default implementation
1561 * returns an empty list.
1563 * @return The list of marker categories
1566 protected @NonNull List
<String
> getViewMarkerCategories() {
1567 return new ArrayList
<>();
1571 * Gets the list of view-specific markers for a trace in a given time range.
1572 * Default implementation returns an empty list.
1575 * Start of the time range
1577 * End of the time range
1581 * The progress monitor object
1582 * @return The list of marker events
1585 protected @NonNull List
<IMarkerEvent
> getViewMarkerList(long startTime
, long endTime
,
1586 long resolution
, @NonNull IProgressMonitor monitor
) {
1587 return new ArrayList
<>();
1591 * Gets the list of trace-specific markers for a trace in a given time range.
1594 * Start of the time range
1596 * End of the time range
1600 * The progress monitor object
1601 * @return The list of marker events
1604 protected @NonNull List
<IMarkerEvent
> getTraceMarkerList(long startTime
, long endTime
,
1605 long resolution
, @NonNull IProgressMonitor monitor
) {
1606 List
<IMarkerEvent
> markers
= new ArrayList
<>();
1607 for (IMarkerEventSource markerEventSource
: getMarkerEventSources(fTrace
)) {
1608 for (String category
: markerEventSource
.getMarkerCategories()) {
1609 if (monitor
.isCanceled()) {
1612 markers
.addAll(markerEventSource
.getMarkerList(checkNotNull(category
), startTime
, endTime
, resolution
, monitor
));
1619 * Get the list of current marker categories.
1621 * @return The list of marker categories
1624 private @NonNull List
<String
> getMarkerCategories() {
1625 Set
<String
> categories
= new HashSet
<>(getViewMarkerCategories());
1626 for (IMarkerEventSource markerEventSource
: getMarkerEventSources(fTrace
)) {
1627 categories
.addAll(markerEventSource
.getMarkerCategories());
1629 return new ArrayList
<>(categories
);
1633 * Gets the list of marker event sources for a given trace.
1637 * @return The list of marker event sources
1640 private @NonNull List
<IMarkerEventSource
> getMarkerEventSources(ITmfTrace trace
) {
1641 List
<IMarkerEventSource
> markerEventSources
= fMarkerEventSourcesMap
.get(trace
);
1642 if (markerEventSources
== null) {
1643 markerEventSources
= checkNotNull(Collections
.<IMarkerEventSource
>emptyList());
1645 return markerEventSources
;
1649 * Refresh the display
1651 protected void refresh() {
1652 final boolean zoomThread
= Thread
.currentThread() instanceof ZoomThread
;
1653 TmfUiRefreshHandler
.getInstance().queueUpdate(this, new Runnable() {
1656 if (fTimeGraphWrapper
.isDisposed()) {
1659 boolean hasEntries
= false;
1660 synchronized (fEntryListMap
) {
1661 fEntryList
= fEntryListMap
.get(fTrace
);
1662 if (fEntryList
== null) {
1663 fEntryList
= new CopyOnWriteArrayList
<>();
1664 } else if (fEntryComparator
!= null) {
1665 List
<TimeGraphEntry
> list
= new ArrayList
<>(fEntryList
);
1666 Collections
.sort(list
, fEntryComparator
);
1667 for (ITimeGraphEntry entry
: list
) {
1668 sortChildren(entry
, fEntryComparator
);
1671 fEntryList
.addAll(list
);
1673 hasEntries
= !fEntryList
.isEmpty();
1675 boolean inputChanged
= fEntryList
!= fTimeGraphWrapper
.getInput();
1677 fTimeGraphWrapper
.setInput(fEntryList
);
1678 /* restore the previously saved filters, if any */
1679 fTimeGraphWrapper
.setFilters(fFiltersMap
.get(fTrace
));
1680 fTimeGraphWrapper
.getTimeGraphViewer().setLinks(null);
1681 fTimeGraphWrapper
.getTimeGraphViewer().setBookmarks(refreshBookmarks(fEditorFile
));
1682 fTimeGraphWrapper
.getTimeGraphViewer().setMarkerCategories(getMarkerCategories());
1683 fTimeGraphWrapper
.getTimeGraphViewer().setMarkers(null);
1684 resetColumnSorting();
1686 fTimeGraphWrapper
.refresh();
1688 long startBound
= (fStartTime
== Long
.MAX_VALUE ? SWT
.DEFAULT
: fStartTime
);
1689 long endBound
= (fEndTime
== Long
.MIN_VALUE ? SWT
.DEFAULT
: fEndTime
);
1690 fTimeGraphWrapper
.getTimeGraphViewer().setTimeBounds(startBound
, endBound
);
1692 TmfTraceContext ctx
= TmfTraceManager
.getInstance().getCurrentTraceContext();
1693 long selectionBeginTime
= fTrace
== null ? SWT
.DEFAULT
: ctx
.getSelectionRange().getStartTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
1694 long selectionEndTime
= fTrace
== null ? SWT
.DEFAULT
: ctx
.getSelectionRange().getEndTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
1695 long startTime
= fTrace
== null ? SWT
.DEFAULT
: ctx
.getWindowRange().getStartTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
1696 long endTime
= fTrace
== null ? SWT
.DEFAULT
: ctx
.getWindowRange().getEndTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
1697 startTime
= (fStartTime
== Long
.MAX_VALUE ? SWT
.DEFAULT
: Math
.max(startTime
, fStartTime
));
1698 endTime
= (fEndTime
== Long
.MIN_VALUE ? SWT
.DEFAULT
: Math
.min(endTime
, fEndTime
));
1699 fTimeGraphWrapper
.getTimeGraphViewer().setSelectionRange(selectionBeginTime
, selectionEndTime
, false);
1700 fTimeGraphWrapper
.getTimeGraphViewer().setStartFinishTime(startTime
, endTime
);
1702 if (inputChanged
&& selectionBeginTime
!= SWT
.DEFAULT
) {
1703 synchingToTime(selectionBeginTime
);
1706 if (fTimeGraphWrapper
instanceof TimeGraphComboWrapper
&& !fPackDone
) {
1707 for (TreeColumn column
: ((TimeGraphComboWrapper
) fTimeGraphWrapper
).getTreeViewer().getTree().getColumns()) {
1716 if (fIsRevealSelection
&& fTimeGraphWrapper
instanceof TimeGraphComboWrapper
) {
1717 fIsRevealSelection
= false;
1718 ITimeGraphEntry entry1
= fTimeGraphWrapper
.getTimeGraphViewer().getSelection();
1719 fTimeGraphWrapper
.getTimeGraphViewer().setSelection(entry1
);
1723 startZoomThread(startTime
, endTime
);
1733 protected void redraw() {
1734 synchronized (fSyncObj
) {
1735 if (fRedrawState
== State
.IDLE
) {
1736 fRedrawState
= State
.BUSY
;
1738 fRedrawState
= State
.PENDING
;
1742 Display
.getDefault().asyncExec(new Runnable() {
1745 if (fTimeGraphWrapper
.isDisposed()) {
1748 fTimeGraphWrapper
.redraw();
1749 fTimeGraphWrapper
.update();
1750 synchronized (fSyncObj
) {
1751 if (fRedrawState
== State
.PENDING
) {
1752 fRedrawState
= State
.IDLE
;
1755 fRedrawState
= State
.IDLE
;
1762 private void sortChildren(ITimeGraphEntry entry
, Comparator
<ITimeGraphEntry
> comparator
) {
1763 if (entry
instanceof TimeGraphEntry
) {
1764 ((TimeGraphEntry
) entry
).sortChildren(comparator
);
1766 for (ITimeGraphEntry child
: entry
.getChildren()) {
1767 sortChildren(child
, comparator
);
1772 * Start or restart the zoom thread.
1775 * the zoom start time
1780 protected final void startZoomThread(long startTime
, long endTime
) {
1781 fDirty
.incrementAndGet();
1782 boolean restart
= false;
1783 if (fZoomThread
!= null) {
1784 fZoomThread
.cancel();
1785 if (fZoomThread
.fZoomStartTime
== startTime
&& fZoomThread
.fZoomEndTime
== endTime
) {
1789 long resolution
= Math
.max(1, (endTime
- startTime
) / fDisplayWidth
);
1790 fZoomThread
= createZoomThread(startTime
, endTime
, resolution
, restart
);
1791 if (fZoomThread
!= null) {
1792 fZoomThread
.start();
1794 fDirty
.decrementAndGet();
1799 * Create a zoom thread.
1802 * the zoom start time
1808 * true if restarting zoom for the same time range
1809 * @return a zoom thread
1812 protected @Nullable ZoomThread
createZoomThread(long startTime
, long endTime
, long resolution
, boolean restart
) {
1813 final List
<TimeGraphEntry
> entryList
= fEntryList
;
1814 if (entryList
== null) {
1817 return new ZoomThreadByEntry(entryList
, startTime
, endTime
, resolution
);
1820 private void makeActions() {
1821 fPreviousResourceAction
= fTimeGraphWrapper
.getTimeGraphViewer().getPreviousItemAction();
1822 fPreviousResourceAction
.setText(getPrevText());
1823 fPreviousResourceAction
.setToolTipText(getPrevTooltip());
1824 fNextResourceAction
= fTimeGraphWrapper
.getTimeGraphViewer().getNextItemAction();
1825 fNextResourceAction
.setText(getNextText());
1826 fNextResourceAction
.setToolTipText(getNextTooltip());
1829 private void contributeToActionBars() {
1830 IActionBars bars
= getViewSite().getActionBars();
1831 fillLocalToolBar(bars
.getToolBarManager());
1832 fillLocalMenu(bars
.getMenuManager());
1836 * Add actions to local tool bar manager
1838 * @param manager the tool bar manager
1840 protected void fillLocalToolBar(IToolBarManager manager
) {
1841 if (fFilterColumns
!= null && fFilterLabelProvider
!= null && fFilterColumns
.length
> 0) {
1842 manager
.add(fTimeGraphWrapper
.getShowFilterDialogAction());
1844 manager
.add(fTimeGraphWrapper
.getTimeGraphViewer().getShowLegendAction());
1845 manager
.add(new Separator());
1846 manager
.add(fTimeGraphWrapper
.getTimeGraphViewer().getResetScaleAction());
1847 manager
.add(fTimeGraphWrapper
.getTimeGraphViewer().getPreviousEventAction());
1848 manager
.add(fTimeGraphWrapper
.getTimeGraphViewer().getNextEventAction());
1849 manager
.add(new Separator());
1850 manager
.add(fTimeGraphWrapper
.getTimeGraphViewer().getToggleBookmarkAction());
1851 manager
.add(fTimeGraphWrapper
.getTimeGraphViewer().getPreviousMarkerAction());
1852 manager
.add(fTimeGraphWrapper
.getTimeGraphViewer().getNextMarkerAction());
1853 manager
.add(new Separator());
1854 manager
.add(fPreviousResourceAction
);
1855 manager
.add(fNextResourceAction
);
1856 manager
.add(fTimeGraphWrapper
.getTimeGraphViewer().getZoomInAction());
1857 manager
.add(fTimeGraphWrapper
.getTimeGraphViewer().getZoomOutAction());
1858 manager
.add(new Separator());
1862 * Add actions to local menu manager
1864 * @param manager the tool bar manager
1867 protected void fillLocalMenu(IMenuManager manager
) {
1868 manager
.add(fTimeGraphWrapper
.getTimeGraphViewer().getMarkersMenu());
1875 public TmfTimeViewAlignmentInfo
getTimeViewAlignmentInfo() {
1876 if (fTimeGraphWrapper
== null) {
1879 return fTimeGraphWrapper
.getTimeViewAlignmentInfo();
1886 public int getAvailableWidth(int requestedOffset
) {
1887 if (fTimeGraphWrapper
== null) {
1890 return fTimeGraphWrapper
.getAvailableWidth(requestedOffset
);
1897 public void performAlign(int offset
, int width
) {
1898 if (fTimeGraphWrapper
!= null) {
1899 fTimeGraphWrapper
.performAlign(offset
, width
);
1904 * Returns whether or not the time graph view is dirty. The time graph view
1905 * is considered dirty if it has yet to completely update its model.
1907 * @return true if the time graph view has yet to completely update its
1908 * model, false otherwise
1911 public boolean isDirty() {
1912 if (fZoomThread
== null) {
1915 return fDirty
.get() != 0 || fZoomThread
.getZoomStartTime() != fTimeGraphWrapper
.getTimeGraphViewer().getTime0() || fZoomThread
.getZoomEndTime() != fTimeGraphWrapper
.getTimeGraphViewer().getTime1();
1918 private void createColumnSelectionListener(TreeViewer treeViewer
) {
1919 for (int i
= 0; i
< fColumnComparators
.length
; i
++) {
1920 final Comparator
<ITimeGraphEntry
> comp
= fColumnComparators
[i
];
1921 final Tree tree
= treeViewer
.getTree();
1922 final TreeColumn column
= tree
.getColumn(i
);
1925 column
.addSelectionListener(new SelectionAdapter() {
1927 public void widgetSelected(SelectionEvent e
) {
1928 TreeColumn prevSortcolumn
= tree
.getSortColumn();
1929 if (prevSortcolumn
== column
) {
1930 fDirection
= (fDirection
== SWT
.DOWN
) ? SWT
.UP
: SWT
.DOWN
;
1932 fDirection
= SWT
.DOWN
;
1934 tree
.setSortColumn(column
);
1935 tree
.setSortDirection(fDirection
);
1936 Comparator
<ITimeGraphEntry
> comparator
= comp
;
1937 if (comparator
instanceof ITimeGraphEntryComparator
) {
1938 ((ITimeGraphEntryComparator
) comparator
).setDirection(fDirection
);
1940 if (fDirection
!= SWT
.DOWN
) {
1941 comparator
= checkNotNull(Collections
.reverseOrder(comparator
));
1943 setEntryComparator(comparator
);
1944 fIsRevealSelection
= true;
1945 if (fTimeGraphWrapper
instanceof TimeGraphComboWrapper
) {
1946 ((TimeGraphComboWrapper
) fTimeGraphWrapper
).getTreeViewer().getControl().setFocus();
1955 private void resetColumnSorting() {
1956 if ((fTimeGraphWrapper
instanceof TimeGraphComboWrapper
) && (fColumnComparators
!= null)) {
1957 TreeViewer treeViewer
= ((TimeGraphComboWrapper
) fTimeGraphWrapper
).getTreeViewer();
1958 fDirection
= SWT
.DOWN
;
1959 if ((fInitialSortColumn
< fColumnComparators
.length
) && (fColumnComparators
[fInitialSortColumn
] != null)) {
1960 setEntryComparator(fColumnComparators
[fInitialSortColumn
]);
1962 final Tree tree
= treeViewer
.getTree();
1963 final TreeColumn column
= tree
.getColumn(fInitialSortColumn
);
1964 tree
.setSortDirection(fDirection
);
1965 tree
.setSortColumn(column
);