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
.graphics
.Color
;
64 import org
.eclipse
.swt
.graphics
.Image
;
65 import org
.eclipse
.swt
.widgets
.Composite
;
66 import org
.eclipse
.swt
.widgets
.Display
;
67 import org
.eclipse
.swt
.widgets
.TreeColumn
;
68 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.Activator
;
69 import org
.eclipse
.tracecompass
.tmf
.core
.resources
.ITmfMarker
;
70 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfSelectionRangeUpdatedSignal
;
71 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfSignalHandler
;
72 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfTimestampFormatUpdateSignal
;
73 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfTraceClosedSignal
;
74 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfTraceOpenedSignal
;
75 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfTraceSelectedSignal
;
76 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfWindowRangeUpdatedSignal
;
77 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.ITmfTimestamp
;
78 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.TmfNanoTimestamp
;
79 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.TmfTimeRange
;
80 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfTrace
;
81 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.TmfTraceAdapterManager
;
82 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.TmfTraceContext
;
83 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.TmfTraceManager
;
84 import org
.eclipse
.tracecompass
.tmf
.ui
.TmfUiRefreshHandler
;
85 import org
.eclipse
.tracecompass
.tmf
.ui
.signal
.TmfTimeViewAlignmentInfo
;
86 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.ITmfTimeAligned
;
87 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.TmfView
;
88 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.ITimeGraphBookmarkListener
;
89 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.ITimeGraphContentProvider
;
90 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.ITimeGraphPresentationProvider2
;
91 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.ITimeGraphRangeListener
;
92 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.ITimeGraphSelectionListener
;
93 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.ITimeGraphTimeListener
;
94 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.TimeGraphBookmarkEvent
;
95 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.TimeGraphCombo
;
96 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.TimeGraphContentProvider
;
97 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.TimeGraphPresentationProvider
;
98 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.TimeGraphRangeUpdateEvent
;
99 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.TimeGraphTimeEvent
;
100 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.TimeGraphViewer
;
101 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.ILinkEvent
;
102 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.IMarkerEvent
;
103 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.IMarkerEventSource
;
104 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.ITimeEvent
;
105 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.ITimeGraphEntry
;
106 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.MarkerEvent
;
107 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.TimeGraphEntry
;
108 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.widgets
.Utils
.TimeFormat
;
109 import org
.eclipse
.ui
.IActionBars
;
112 * An abstract view all time graph views can inherit
114 * This view contains either a time graph viewer, or a time graph combo which is
115 * divided between a tree viewer on the left and a time graph viewer on the right.
117 public abstract class AbstractTimeGraphView
extends TmfView
implements ITmfTimeAligned
, IResourceChangeListener
{
119 /** Constant indicating that all levels of the time graph should be expanded */
120 protected static final int ALL_LEVELS
= AbstractTreeViewer
.ALL_LEVELS
;
122 private static final Pattern RGBA_PATTERN
= Pattern
.compile("RGBA \\{(\\d+), (\\d+), (\\d+), (\\d+)\\}"); //$NON-NLS-1$
131 // ------------------------------------------------------------------------
133 // ------------------------------------------------------------------------
135 /** The timegraph wrapper */
136 private ITimeGraphWrapper fTimeGraphWrapper
;
138 private AtomicInteger fDirty
= new AtomicInteger();
140 /** The selected trace */
141 private ITmfTrace fTrace
;
143 /** The selected trace editor file*/
144 private IFile fEditorFile
;
146 /** The timegraph entry list */
147 private List
<TimeGraphEntry
> fEntryList
;
149 /** The trace to entry list hash map */
150 private final Map
<ITmfTrace
, List
<TimeGraphEntry
>> fEntryListMap
= new HashMap
<>();
152 /** The trace to filters hash map */
153 private final Map
<ITmfTrace
, ViewerFilter
[]> fFiltersMap
= new HashMap
<>();
155 /** The trace to marker event sources hash map */
156 private final Map
<ITmfTrace
, List
<IMarkerEventSource
>> fMarkerEventSourcesMap
= new HashMap
<>();
158 /** The trace to build thread hash map */
159 private final Map
<ITmfTrace
, BuildThread
> fBuildThreadMap
= new HashMap
<>();
161 /** The start time */
162 private long fStartTime
= SWT
.DEFAULT
;
165 private long fEndTime
= SWT
.DEFAULT
;
167 /** The display width */
168 private final int fDisplayWidth
;
170 /** The zoom thread */
171 private ZoomThread fZoomThread
;
173 /** The next resource action */
174 private Action fNextResourceAction
;
176 /** The previous resource action */
177 private Action fPreviousResourceAction
;
179 /** A comparator class */
180 private Comparator
<ITimeGraphEntry
> fEntryComparator
= null;
182 /** The redraw state used to prevent unnecessary queuing of display runnables */
183 private State fRedrawState
= State
.IDLE
;
185 /** The redraw synchronization object */
186 private final Object fSyncObj
= new Object();
188 /** The presentation provider for this view */
189 private final TimeGraphPresentationProvider fPresentation
;
191 /** The tree column label array, or null if combo is not used */
192 private String
[] fColumns
;
194 /** The tree label provider, or null if combo is not used */
195 private TreeLabelProvider fLabelProvider
= null;
197 /** The time graph content provider */
198 private @NonNull ITimeGraphContentProvider fTimeGraphContentProvider
= new TimeGraphContentProvider();
200 /** The relative weight of the sash, ignored if combo is not used */
201 private int[] fWeight
= { 1, 3 };
203 /** The filter column label array, or null if filter is not used */
204 private String
[] fFilterColumns
;
206 /** The pack done flag */
207 private boolean fPackDone
= false;
209 /** The filter content provider, or null if filter is not used */
210 private ITreeContentProvider fFilterContentProvider
;
212 /** The filter label provider, or null if filter is not used */
213 private TreeLabelProvider fFilterLabelProvider
;
215 private int fAutoExpandLevel
= ALL_LEVELS
;
217 /** The list of color resources created by this view */
218 private final List
<Color
> fColors
= new ArrayList
<>();
220 // ------------------------------------------------------------------------
222 // ------------------------------------------------------------------------
224 private interface ITimeGraphWrapper
{
226 void setTimeGraphContentProvider(ITimeGraphContentProvider timeGraphContentProvider
);
228 void setTimeGraphPresentationProvider(TimeGraphPresentationProvider timeGraphPresentationProvider
);
230 TimeGraphViewer
getTimeGraphViewer();
232 void addSelectionListener(ITimeGraphSelectionListener listener
);
234 ISelectionProvider
getSelectionProvider();
238 boolean isDisposed();
242 void setInput(Object input
);
246 void setFilters(@NonNull ViewerFilter
[] filters
);
248 @NonNull ViewerFilter
[] getFilters();
254 void setAutoExpandLevel(int level
);
256 void setFilterColumns(String
[] columnNames
);
258 void setFilterContentProvider(ITreeContentProvider contentProvider
);
260 void setFilterLabelProvider(ITableLabelProvider labelProvider
);
262 IAction
getShowFilterDialogAction();
264 void performAlign(int offset
, int width
);
266 TmfTimeViewAlignmentInfo
getTimeViewAlignmentInfo();
268 int getAvailableWidth(int requestedOffset
);
271 private class TimeGraphViewerWrapper
implements ITimeGraphWrapper
{
272 private TimeGraphViewer viewer
;
274 private TimeGraphViewerWrapper(Composite parent
, int style
) {
275 viewer
= new TimeGraphViewer(parent
, style
);
279 public void setTimeGraphContentProvider(ITimeGraphContentProvider timeGraphContentProvider
) {
280 viewer
.setTimeGraphContentProvider(timeGraphContentProvider
);
284 public void setTimeGraphPresentationProvider(TimeGraphPresentationProvider timeGraphPresentationProvider
) {
285 viewer
.setTimeGraphProvider(timeGraphPresentationProvider
);
289 public TimeGraphViewer
getTimeGraphViewer() {
294 public void addSelectionListener(ITimeGraphSelectionListener listener
) {
295 viewer
.addSelectionListener(listener
);
299 public ISelectionProvider
getSelectionProvider() {
300 return viewer
.getSelectionProvider();
304 public void setFocus() {
309 public boolean isDisposed() {
310 return viewer
.getControl().isDisposed();
314 public void setInput(Object input
) {
315 viewer
.setInput(input
);
319 public Object
getInput() {
320 return viewer
.getInput();
324 public void setFilterColumns(String
[] columnNames
) {
325 viewer
.setFilterColumns(columnNames
);
329 public void setFilterContentProvider(ITreeContentProvider contentProvider
) {
330 viewer
.setFilterContentProvider(contentProvider
);
334 public void setFilterLabelProvider(ITableLabelProvider labelProvider
) {
335 viewer
.setFilterLabelProvider(labelProvider
);
339 public void setFilters(@NonNull ViewerFilter
[] filters
) {
340 viewer
.setFilters(filters
);
344 public @NonNull ViewerFilter
[] getFilters() {
345 return viewer
.getFilters();
349 public IAction
getShowFilterDialogAction() {
350 return viewer
.getShowFilterDialogAction();
354 public void refresh() {
359 public void redraw() {
360 viewer
.getControl().redraw();
364 public void update() {
365 viewer
.getControl().update();
369 public void setAutoExpandLevel(int level
) {
370 viewer
.setAutoExpandLevel(level
);
374 public void performAlign(int offset
, int width
) {
375 viewer
.performAlign(offset
, width
);
379 public TmfTimeViewAlignmentInfo
getTimeViewAlignmentInfo() {
380 return viewer
.getTimeViewAlignmentInfo();
384 public int getAvailableWidth(int requestedOffset
) {
385 return viewer
.getAvailableWidth(requestedOffset
);
389 private class TimeGraphComboWrapper
implements ITimeGraphWrapper
{
390 private TimeGraphCombo combo
;
392 private TimeGraphComboWrapper(Composite parent
, int style
) {
393 combo
= new TimeGraphCombo(parent
, style
, fWeight
);
397 public void setTimeGraphContentProvider(ITimeGraphContentProvider timeGraphContentProvider
) {
398 combo
.setTimeGraphContentProvider(timeGraphContentProvider
);
402 public void setTimeGraphPresentationProvider(TimeGraphPresentationProvider timeGraphPresentationProvider
) {
403 combo
.setTimeGraphProvider(timeGraphPresentationProvider
);
407 public TimeGraphViewer
getTimeGraphViewer() {
408 return combo
.getTimeGraphViewer();
412 public void addSelectionListener(ITimeGraphSelectionListener listener
) {
413 combo
.addSelectionListener(listener
);
417 public ISelectionProvider
getSelectionProvider() {
418 return combo
.getTreeViewer();
422 public void setFocus() {
427 public boolean isDisposed() {
428 return combo
.isDisposed();
432 public void setInput(Object input
) {
433 combo
.setInput(input
);
437 public Object
getInput() {
438 return combo
.getInput();
442 public void setFilterColumns(String
[] columnNames
) {
443 combo
.setFilterColumns(columnNames
);
447 public void setFilterContentProvider(ITreeContentProvider contentProvider
) {
448 combo
.setFilterContentProvider(contentProvider
);
452 public void setFilterLabelProvider(ITableLabelProvider labelProvider
) {
453 combo
.setFilterLabelProvider(labelProvider
);
457 public void setFilters(@NonNull ViewerFilter
[] filters
) {
458 combo
.setFilters(filters
);
462 public @NonNull ViewerFilter
[] getFilters() {
463 return combo
.getFilters();
467 public IAction
getShowFilterDialogAction() {
468 return combo
.getShowFilterDialogAction();
472 public void refresh() {
477 public void redraw() {
482 public void update() {
487 public void setAutoExpandLevel(int level
) {
488 combo
.setAutoExpandLevel(level
);
491 TimeGraphCombo
getTimeGraphCombo() {
495 TreeViewer
getTreeViewer() {
496 return combo
.getTreeViewer();
500 public void performAlign(int offset
, int width
) {
501 combo
.performAlign(offset
, width
);
505 public TmfTimeViewAlignmentInfo
getTimeViewAlignmentInfo() {
506 return combo
.getTimeViewAlignmentInfo();
510 public int getAvailableWidth(int requestedOffset
) {
511 return combo
.getAvailableWidth(requestedOffset
);
516 * Base class to provide the labels for the tree viewer. Views extending
517 * this class typically need to override the getColumnText method if they
518 * have more than one column to display
520 protected static class TreeLabelProvider
implements ITableLabelProvider
, ILabelProvider
{
523 public void addListener(ILabelProviderListener listener
) {
527 public void dispose() {
531 public boolean isLabelProperty(Object element
, String property
) {
536 public void removeListener(ILabelProviderListener listener
) {
540 public Image
getColumnImage(Object element
, int columnIndex
) {
545 public String
getColumnText(Object element
, int columnIndex
) {
546 TimeGraphEntry entry
= (TimeGraphEntry
) element
;
547 if (columnIndex
== 0) {
548 return entry
.getName();
554 public Image
getImage(Object element
) {
559 public String
getText(Object element
) {
560 TimeGraphEntry entry
= (TimeGraphEntry
) element
;
561 return entry
.getName();
566 private class BuildThread
extends Thread
{
567 private final @NonNull ITmfTrace fBuildTrace
;
568 private final @NonNull ITmfTrace fParentTrace
;
569 private final @NonNull IProgressMonitor fMonitor
;
571 public BuildThread(final @NonNull ITmfTrace trace
, final @NonNull ITmfTrace parentTrace
, final String name
) {
572 super(name
+ " build"); //$NON-NLS-1$
574 fParentTrace
= parentTrace
;
575 fMonitor
= new NullProgressMonitor();
580 buildEventList(fBuildTrace
, fParentTrace
, fMonitor
);
581 synchronized (fBuildThreadMap
) {
582 fBuildThreadMap
.remove(fBuildTrace
);
586 public void cancel() {
587 fMonitor
.setCanceled(true);
595 protected abstract class ZoomThread
extends Thread
{
596 private final long fZoomStartTime
;
597 private final long fZoomEndTime
;
598 private final long fResolution
;
599 private final @NonNull IProgressMonitor fMonitor
;
611 public ZoomThread(long startTime
, long endTime
, long resolution
) {
612 super(AbstractTimeGraphView
.this.getName() + " zoom"); //$NON-NLS-1$
613 fZoomStartTime
= startTime
;
614 fZoomEndTime
= endTime
;
615 fResolution
= resolution
;
616 fMonitor
= new NullProgressMonitor();
620 * @return the zoom start time
622 public long getZoomStartTime() {
623 return fZoomStartTime
;
627 * @return the zoom end time
629 public long getZoomEndTime() {
634 * @return the resolution
636 public long getResolution() {
641 * @return the monitor
643 public @NonNull IProgressMonitor
getMonitor() {
648 * Cancel the zoom thread
650 public void cancel() {
651 fMonitor
.setCanceled(true);
655 public final void run() {
657 fDirty
.decrementAndGet();
661 * Run the zoom operation.
664 public abstract void doRun();
667 private class ZoomThreadByEntry
extends ZoomThread
{
668 private final @NonNull List
<TimeGraphEntry
> fZoomEntryList
;
670 public ZoomThreadByEntry(@NonNull List
<TimeGraphEntry
> entryList
, long startTime
, long endTime
, long resolution
) {
671 super(startTime
, endTime
, resolution
);
672 fZoomEntryList
= entryList
;
676 public void doRun() {
677 for (TimeGraphEntry entry
: fZoomEntryList
) {
678 if (getMonitor().isCanceled()) {
684 zoom(entry
, getMonitor());
686 /* Refresh the arrows when zooming */
687 List
<ILinkEvent
> events
= getLinkList(getZoomStartTime(), getZoomEndTime(), getResolution(), getMonitor());
688 if (events
!= null) {
689 fTimeGraphWrapper
.getTimeGraphViewer().setLinks(events
);
692 /* Refresh the view-specific markers when zooming */
693 List
<IMarkerEvent
> markers
= new ArrayList
<>(getViewMarkerList(getZoomStartTime(), getZoomEndTime(), getResolution(), getMonitor()));
694 /* Refresh the trace-specific markers when zooming */
695 markers
.addAll(getTraceMarkerList(getZoomStartTime(), getZoomEndTime(), getResolution(), getMonitor()));
696 fTimeGraphWrapper
.getTimeGraphViewer().setMarkers(markers
);
700 private void zoom(@NonNull TimeGraphEntry entry
, @NonNull IProgressMonitor monitor
) {
701 if (getZoomStartTime() <= fStartTime
&& getZoomEndTime() >= fEndTime
) {
702 entry
.setZoomedEventList(null);
704 List
<ITimeEvent
> zoomedEventList
= getEventList(entry
, getZoomStartTime(), getZoomEndTime(), getResolution(), monitor
);
705 if (zoomedEventList
!= null) {
706 entry
.setZoomedEventList(zoomedEventList
);
710 for (ITimeGraphEntry child
: entry
.getChildren()) {
711 if (monitor
.isCanceled()) {
714 if (child
instanceof TimeGraphEntry
) {
715 zoom((TimeGraphEntry
) child
, monitor
);
722 // ------------------------------------------------------------------------
724 // ------------------------------------------------------------------------
727 * Constructs a time graph view that contains either a time graph viewer or
728 * a time graph combo.
730 * By default, the view uses a time graph viewer. To use a time graph combo,
731 * the subclass constructor must call {@link #setTreeColumns(String[])} and
732 * {@link #setTreeLabelProvider(TreeLabelProvider)}.
737 * The presentation provider
739 public AbstractTimeGraphView(String id
, TimeGraphPresentationProvider pres
) {
741 fPresentation
= pres
;
742 fDisplayWidth
= Display
.getDefault().getBounds().width
;
745 // ------------------------------------------------------------------------
746 // Getters and setters
747 // ------------------------------------------------------------------------
750 * Getter for the time graph combo
752 * @return The time graph combo, or null if combo is not used
754 protected TimeGraphCombo
getTimeGraphCombo() {
755 if (fTimeGraphWrapper
instanceof TimeGraphComboWrapper
) {
756 return ((TimeGraphComboWrapper
) fTimeGraphWrapper
).getTimeGraphCombo();
762 * Getter for the time graph viewer
764 * @return The time graph viewer
766 protected TimeGraphViewer
getTimeGraphViewer() {
767 return fTimeGraphWrapper
.getTimeGraphViewer();
771 * Getter for the presentation provider
773 * @return The time graph presentation provider
775 protected ITimeGraphPresentationProvider2
getPresentationProvider() {
776 return fPresentation
;
780 * Sets the tree column labels.
782 * This should be called from the constructor.
785 * The array of tree column labels
787 protected void setTreeColumns(final String
[] columns
) {
788 checkPartNotCreated();
793 * Sets the tree label provider.
795 * This should be called from the constructor.
798 * The tree label provider
800 protected void setTreeLabelProvider(final TreeLabelProvider tlp
) {
801 checkPartNotCreated();
802 fLabelProvider
= tlp
;
806 * Sets the time graph content provider.
808 * This should be called from the constructor.
811 * The time graph content provider
814 protected void setTimeGraphContentProvider(final @NonNull ITimeGraphContentProvider tgcp
) {
815 checkPartNotCreated();
816 fTimeGraphContentProvider
= tgcp
;
820 * Sets the relative weight of each part of the time graph combo.
822 * This should be called from the constructor.
825 * The array (length 2) of relative weights of each part of the combo
827 protected void setWeight(final int[] weights
) {
828 checkPartNotCreated();
833 * Sets the filter column labels.
835 * This should be called from the constructor.
837 * @param filterColumns
838 * The array of filter column labels
840 protected void setFilterColumns(final String
[] filterColumns
) {
841 checkPartNotCreated();
842 fFilterColumns
= filterColumns
;
846 * Sets the filter content provider.
848 * This should be called from the constructor.
850 * @param contentProvider
851 * The filter content provider
854 protected void setFilterContentProvider(final ITreeContentProvider contentProvider
) {
855 checkPartNotCreated();
856 fFilterContentProvider
= contentProvider
;
860 * Sets the filter label provider.
862 * This should be called from the constructor.
864 * @param labelProvider
865 * The filter label provider
867 protected void setFilterLabelProvider(final TreeLabelProvider labelProvider
) {
868 checkPartNotCreated();
869 fFilterLabelProvider
= labelProvider
;
872 private void checkPartNotCreated() {
873 if (getParentComposite() != null) {
874 throw new IllegalStateException("This method must be called before createPartControl."); //$NON-NLS-1$
879 * Gets the display width
881 * @return the display width
883 protected int getDisplayWidth() {
884 return fDisplayWidth
;
888 * Gets the comparator for the entries
890 * @return The entry comparator
892 protected Comparator
<ITimeGraphEntry
> getEntryComparator() {
893 return fEntryComparator
;
897 * Sets the comparator class for the entries.
899 * This comparator will apply recursively to entries that implement
900 * {@link TimeGraphEntry#sortChildren(Comparator)}.
903 * A comparator object
905 protected void setEntryComparator(final Comparator
<ITimeGraphEntry
> comparator
) {
906 fEntryComparator
= comparator
;
910 * Gets the trace displayed in the view
914 protected ITmfTrace
getTrace() {
919 * Gets the start time
921 * @return The start time
923 protected long getStartTime() {
928 * Sets the start time
933 protected void setStartTime(long time
) {
940 * @return The end time
942 protected long getEndTime() {
952 protected void setEndTime(long time
) {
957 * Sets the auto-expand level to be used for the input of the view. The
958 * value 0 means that there is no auto-expand; 1 means that top-level
959 * elements are expanded, but not their children; 2 means that top-level
960 * elements are expanded, and their children, but not grand-children; and so
963 * The value {@link #ALL_LEVELS} means that all subtrees should be expanded.
967 * non-negative level, or <code>ALL_LEVELS</code> to expand all
970 protected void setAutoExpandLevel(int level
) {
971 fAutoExpandLevel
= level
;
972 ITimeGraphWrapper tgWrapper
= fTimeGraphWrapper
;
973 if (tgWrapper
!= null) {
974 tgWrapper
.setAutoExpandLevel(level
);
979 * Gets the entry list for a trace
984 * @return the entry list map
986 protected List
<TimeGraphEntry
> getEntryList(ITmfTrace trace
) {
987 synchronized (fEntryListMap
) {
988 return fEntryListMap
.get(trace
);
993 * Adds a trace entry list to the entry list map
998 * the list of time graph entries
1000 protected void putEntryList(ITmfTrace trace
, List
<TimeGraphEntry
> list
) {
1001 synchronized (fEntryListMap
) {
1002 fEntryListMap
.put(trace
, new CopyOnWriteArrayList
<>(list
));
1007 * Adds a list of entries to a trace's entry list
1012 * the list of time graph entries to add
1014 protected void addToEntryList(ITmfTrace trace
, List
<TimeGraphEntry
> list
) {
1015 synchronized (fEntryListMap
) {
1016 List
<TimeGraphEntry
> entryList
= fEntryListMap
.get(trace
);
1017 if (entryList
== null) {
1018 fEntryListMap
.put(trace
, new CopyOnWriteArrayList
<>(list
));
1020 entryList
.addAll(list
);
1026 * Removes a list of entries from a trace's entry list
1031 * the list of time graph entries to remove
1033 protected void removeFromEntryList(ITmfTrace trace
, List
<TimeGraphEntry
> list
) {
1034 synchronized (fEntryListMap
) {
1035 List
<TimeGraphEntry
> entryList
= fEntryListMap
.get(trace
);
1036 if (entryList
!= null) {
1037 entryList
.removeAll(list
);
1043 * Text for the "next" button
1045 * @return The "next" button text
1047 protected String
getNextText() {
1048 return Messages
.AbstractTimeGraphtView_NextText
;
1052 * Tooltip for the "next" button
1054 * @return Tooltip for the "next" button
1056 protected String
getNextTooltip() {
1057 return Messages
.AbstractTimeGraphView_NextTooltip
;
1061 * Text for the "Previous" button
1063 * @return The "Previous" button text
1065 protected String
getPrevText() {
1066 return Messages
.AbstractTimeGraphView_PreviousText
;
1070 * Tooltip for the "previous" button
1072 * @return Tooltip for the "previous" button
1074 protected String
getPrevTooltip() {
1075 return Messages
.AbstractTimeGraphView_PreviousTooltip
;
1078 // ------------------------------------------------------------------------
1080 // ------------------------------------------------------------------------
1083 public void createPartControl(Composite parent
) {
1084 super.createPartControl(parent
);
1085 if (fColumns
== null || fLabelProvider
== null) {
1086 fTimeGraphWrapper
= new TimeGraphViewerWrapper(parent
, SWT
.NONE
);
1088 TimeGraphComboWrapper wrapper
= new TimeGraphComboWrapper(parent
, SWT
.NONE
);
1089 fTimeGraphWrapper
= wrapper
;
1090 TimeGraphCombo combo
= wrapper
.getTimeGraphCombo();
1091 combo
.setTreeContentProvider(fTimeGraphContentProvider
);
1092 combo
.setTreeLabelProvider(fLabelProvider
);
1093 combo
.setTreeColumns(fColumns
);
1095 fTimeGraphWrapper
.setTimeGraphContentProvider(fTimeGraphContentProvider
);
1096 fTimeGraphWrapper
.setFilterContentProvider(fFilterContentProvider
!= null ? fFilterContentProvider
: fTimeGraphContentProvider
);
1097 fTimeGraphWrapper
.setFilterLabelProvider(fFilterLabelProvider
);
1098 fTimeGraphWrapper
.setFilterColumns(fFilterColumns
);
1100 fTimeGraphWrapper
.setTimeGraphPresentationProvider(fPresentation
);
1101 fTimeGraphWrapper
.setAutoExpandLevel(fAutoExpandLevel
);
1103 fTimeGraphWrapper
.getTimeGraphViewer().addRangeListener(new ITimeGraphRangeListener() {
1105 public void timeRangeUpdated(TimeGraphRangeUpdateEvent event
) {
1106 final long startTime
= event
.getStartTime();
1107 final long endTime
= event
.getEndTime();
1108 TmfTimeRange range
= new TmfTimeRange(new TmfNanoTimestamp(startTime
), new TmfNanoTimestamp(endTime
));
1109 broadcast(new TmfWindowRangeUpdatedSignal(AbstractTimeGraphView
.this, range
));
1110 startZoomThread(startTime
, endTime
);
1114 fTimeGraphWrapper
.getTimeGraphViewer().addTimeListener(new ITimeGraphTimeListener() {
1116 public void timeSelected(TimeGraphTimeEvent event
) {
1117 TmfNanoTimestamp startTime
= new TmfNanoTimestamp(event
.getBeginTime());
1118 TmfNanoTimestamp endTime
= new TmfNanoTimestamp(event
.getEndTime());
1119 broadcast(new TmfSelectionRangeUpdatedSignal(AbstractTimeGraphView
.this, startTime
, endTime
));
1123 fTimeGraphWrapper
.getTimeGraphViewer().addBookmarkListener(new ITimeGraphBookmarkListener() {
1125 public void bookmarkAdded(final TimeGraphBookmarkEvent event
) {
1127 ResourcesPlugin
.getWorkspace().run(new IWorkspaceRunnable() {
1129 public void run(IProgressMonitor monitor
) throws CoreException
{
1130 IMarkerEvent bookmark
= event
.getBookmark();
1131 IMarker marker
= fEditorFile
.createMarker(IMarker
.BOOKMARK
);
1132 marker
.setAttribute(IMarker
.MESSAGE
, bookmark
.getLabel());
1133 marker
.setAttribute(ITmfMarker
.MARKER_TIME
, Long
.toString(bookmark
.getTime()));
1134 if (bookmark
.getDuration() > 0) {
1135 marker
.setAttribute(ITmfMarker
.MARKER_DURATION
, Long
.toString(bookmark
.getDuration()));
1136 marker
.setAttribute(IMarker
.LOCATION
,
1137 NLS
.bind(org
.eclipse
.tracecompass
.internal
.tmf
.ui
.Messages
.TmfMarker_LocationTimeRange
,
1138 new TmfNanoTimestamp(bookmark
.getTime()),
1139 new TmfNanoTimestamp(bookmark
.getTime() + bookmark
.getDuration())));
1141 marker
.setAttribute(IMarker
.LOCATION
,
1142 NLS
.bind(org
.eclipse
.tracecompass
.internal
.tmf
.ui
.Messages
.TmfMarker_LocationTime
,
1143 new TmfNanoTimestamp(bookmark
.getTime())));
1145 marker
.setAttribute(ITmfMarker
.MARKER_COLOR
, bookmark
.getColor().getRGBA().toString());
1148 } catch (CoreException e
) {
1149 Activator
.getDefault().logError(e
.getMessage());
1154 public void bookmarkRemoved(TimeGraphBookmarkEvent event
) {
1156 IMarkerEvent bookmark
= event
.getBookmark();
1157 IMarker
[] markers
= fEditorFile
.findMarkers(IMarker
.BOOKMARK
, false, IResource
.DEPTH_ZERO
);
1158 for (IMarker marker
: markers
) {
1159 if (bookmark
.getLabel().equals(marker
.getAttribute(IMarker
.MESSAGE
)) &&
1160 Long
.toString(bookmark
.getTime()).equals(marker
.getAttribute(ITmfMarker
.MARKER_TIME
, (String
) null)) &&
1161 Long
.toString(bookmark
.getDuration()).equals(marker
.getAttribute(ITmfMarker
.MARKER_DURATION
, Long
.toString(0))) &&
1162 bookmark
.getColor().getRGBA().toString().equals(marker
.getAttribute(ITmfMarker
.MARKER_COLOR
))) {
1167 } catch (CoreException e
) {
1168 Activator
.getDefault().logError(e
.getMessage());
1173 fTimeGraphWrapper
.getTimeGraphViewer().setTimeFormat(TimeFormat
.CALENDAR
);
1175 IStatusLineManager statusLineManager
= getViewSite().getActionBars().getStatusLineManager();
1176 fTimeGraphWrapper
.getTimeGraphViewer().getTimeGraphControl().setStatusLineManager(statusLineManager
);
1178 // View Action Handling
1180 contributeToActionBars();
1182 ITmfTrace trace
= TmfTraceManager
.getInstance().getActiveTrace();
1183 if (trace
!= null) {
1184 traceSelected(new TmfTraceSelectedSignal(this, trace
));
1187 // make selection available to other views
1188 getSite().setSelectionProvider(fTimeGraphWrapper
.getSelectionProvider());
1190 ResourcesPlugin
.getWorkspace().addResourceChangeListener(this, IResourceChangeEvent
.POST_CHANGE
);
1194 public void setFocus() {
1195 fTimeGraphWrapper
.setFocus();
1199 public void dispose() {
1201 ResourcesPlugin
.getWorkspace().removeResourceChangeListener(this);
1208 public void resourceChanged(final IResourceChangeEvent event
) {
1209 for (final IMarkerDelta delta
: event
.findMarkerDeltas(IMarker
.BOOKMARK
, false)) {
1210 if (delta
.getResource().equals(fEditorFile
)) {
1211 fTimeGraphWrapper
.getTimeGraphViewer().setBookmarks(refreshBookmarks(fEditorFile
));
1218 private List
<IMarkerEvent
> refreshBookmarks(final IFile editorFile
) {
1219 List
<IMarkerEvent
> bookmarks
= new ArrayList
<>();
1220 for (Color color
: fColors
) {
1224 if (editorFile
== null || !editorFile
.exists()) {
1228 IMarker
[] markers
= editorFile
.findMarkers(IMarker
.BOOKMARK
, false, IResource
.DEPTH_ZERO
);
1229 for (IMarker marker
: markers
) {
1230 String label
= marker
.getAttribute(IMarker
.MESSAGE
, (String
) null);
1231 String time
= marker
.getAttribute(ITmfMarker
.MARKER_TIME
, (String
) null);
1232 String duration
= marker
.getAttribute(ITmfMarker
.MARKER_DURATION
, Long
.toString(0));
1233 String rgba
= marker
.getAttribute(ITmfMarker
.MARKER_COLOR
, (String
) null);
1234 if (label
!= null && time
!= null && rgba
!= null) {
1235 Matcher matcher
= RGBA_PATTERN
.matcher(rgba
);
1236 if (matcher
.matches()) {
1238 int red
= Integer
.valueOf(matcher
.group(1));
1239 int green
= Integer
.valueOf(matcher
.group(2));
1240 int blue
= Integer
.valueOf(matcher
.group(3));
1241 int alpha
= Integer
.valueOf(matcher
.group(4));
1242 Color color
= new Color(Display
.getDefault(), red
, green
, blue
, alpha
);
1244 bookmarks
.add(new MarkerEvent(null, Long
.valueOf(time
), Long
.valueOf(duration
), IMarkerEvent
.BOOKMARKS
, color
, label
, true));
1245 } catch (NumberFormatException e
) {
1246 Activator
.getDefault().logError(e
.getMessage());
1251 } catch (CoreException e
) {
1252 Activator
.getDefault().logError(e
.getMessage());
1257 // ------------------------------------------------------------------------
1259 // ------------------------------------------------------------------------
1262 * Handler for the trace opened signal.
1265 * The incoming signal
1268 public void traceOpened(TmfTraceOpenedSignal signal
) {
1269 loadTrace(signal
.getTrace());
1273 * Handler for the trace selected signal
1276 * The incoming signal
1279 public void traceSelected(final TmfTraceSelectedSignal signal
) {
1280 if (signal
.getTrace() == fTrace
) {
1283 loadTrace(signal
.getTrace());
1287 * Trace is closed: clear the data structures and the view
1290 * the signal received
1293 public void traceClosed(final TmfTraceClosedSignal signal
) {
1294 synchronized (fBuildThreadMap
) {
1295 for (ITmfTrace trace
: getTracesToBuild(signal
.getTrace())) {
1296 BuildThread buildThread
= fBuildThreadMap
.remove(trace
);
1297 if (buildThread
!= null) {
1298 buildThread
.cancel();
1302 fMarkerEventSourcesMap
.remove(signal
.getTrace());
1303 synchronized (fEntryListMap
) {
1304 fEntryListMap
.remove(signal
.getTrace());
1306 fFiltersMap
.remove(signal
.getTrace());
1307 if (signal
.getTrace() == fTrace
) {
1310 fStartTime
= SWT
.DEFAULT
;
1311 fEndTime
= SWT
.DEFAULT
;
1312 if (fZoomThread
!= null) {
1313 fZoomThread
.cancel();
1321 * Handler for the selection range signal.
1324 * The signal that's received
1328 public void selectionRangeUpdated(final TmfSelectionRangeUpdatedSignal signal
) {
1329 if (signal
.getSource() == this || fTrace
== null) {
1332 final long beginTime
= signal
.getBeginTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
1333 final long endTime
= signal
.getEndTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
1335 Display
.getDefault().asyncExec(new Runnable() {
1338 if (fTimeGraphWrapper
.isDisposed()) {
1341 if (beginTime
== endTime
) {
1342 fTimeGraphWrapper
.getTimeGraphViewer().setSelectedTime(beginTime
, true);
1344 fTimeGraphWrapper
.getTimeGraphViewer().setSelectionRange(beginTime
, endTime
, true);
1346 synchingToTime(fTimeGraphWrapper
.getTimeGraphViewer().getSelectionBegin());
1352 * Handler for the window range signal.
1355 * The signal that's received
1359 public void windowRangeUpdated(final TmfWindowRangeUpdatedSignal signal
) {
1360 if (signal
.getSource() == this || fTrace
== null) {
1363 if (signal
.getCurrentRange().getIntersection(fTrace
.getTimeRange()) == null) {
1366 final long startTime
= signal
.getCurrentRange().getStartTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
1367 final long endTime
= signal
.getCurrentRange().getEndTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
1368 Display
.getDefault().asyncExec(new Runnable() {
1371 if (fTimeGraphWrapper
.isDisposed()) {
1374 fTimeGraphWrapper
.getTimeGraphViewer().setStartFinishTime(startTime
, endTime
);
1375 startZoomThread(startTime
, endTime
);
1381 * @param signal the format of the timestamps was updated.
1384 public void updateTimeFormat( final TmfTimestampFormatUpdateSignal signal
){
1385 fTimeGraphWrapper
.refresh();
1388 // ------------------------------------------------------------------------
1390 // ------------------------------------------------------------------------
1392 private void loadTrace(final ITmfTrace trace
) {
1393 if (fZoomThread
!= null) {
1394 fZoomThread
.cancel();
1397 if (fTrace
!= null) {
1398 /* save the filters of the previous trace */
1399 fFiltersMap
.put(fTrace
, fTimeGraphWrapper
.getFilters());
1402 fEditorFile
= TmfTraceManager
.getInstance().getTraceEditorFile(trace
);
1403 synchronized (fEntryListMap
) {
1404 fEntryList
= fEntryListMap
.get(fTrace
);
1405 if (fEntryList
== null) {
1408 fStartTime
= fTrace
.getStartTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
1409 fEndTime
= fTrace
.getEndTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
1416 * Forces a rebuild of the entries list, even if entries already exist for this trace
1418 protected void rebuild() {
1419 setStartTime(Long
.MAX_VALUE
);
1420 setEndTime(Long
.MIN_VALUE
);
1422 ITmfTrace viewTrace
= fTrace
;
1423 if (viewTrace
== null) {
1426 List
<IMarkerEventSource
> markerEventSources
= new ArrayList
<>();
1427 synchronized (fBuildThreadMap
) {
1428 for (ITmfTrace trace
: getTracesToBuild(viewTrace
)) {
1429 if (trace
== null) {
1432 markerEventSources
.addAll(TmfTraceAdapterManager
.getAdapters(trace
, IMarkerEventSource
.class));
1433 BuildThread buildThread
= new BuildThread(trace
, viewTrace
, getName());
1434 fBuildThreadMap
.put(trace
, buildThread
);
1435 buildThread
.start();
1438 fMarkerEventSourcesMap
.put(viewTrace
, markerEventSources
);
1442 * Method called when synching to a given timestamp. Inheriting classes can
1443 * perform actions here to update the view at the given timestamp.
1446 * The currently selected time
1448 protected void synchingToTime(long time
) {
1453 * Return the list of traces whose data or analysis results will be used to
1454 * populate the view. By default, if the trace is an experiment, the traces
1455 * under it will be returned, otherwise, the trace itself is returned.
1457 * A build thread will be started for each trace returned by this method,
1458 * some of which may receive events in live streaming mode.
1461 * The trace associated with this view
1462 * @return List of traces with data to display
1464 protected @NonNull Iterable
<ITmfTrace
> getTracesToBuild(@NonNull ITmfTrace trace
) {
1465 return TmfTraceManager
.getTraceSet(trace
);
1469 * Build the entries list to show in this time graph
1471 * Called from the BuildThread
1474 * The trace being built
1475 * @param parentTrace
1476 * The parent of the trace set, or the trace itself
1478 * The progress monitor object
1480 protected abstract void buildEventList(@NonNull ITmfTrace trace
, @NonNull ITmfTrace parentTrace
, @NonNull IProgressMonitor monitor
);
1483 * Gets the list of event for an entry in a given timerange
1486 * The entry to get events for
1488 * Start of the time range
1490 * End of the time range
1494 * The progress monitor object
1495 * @return The list of events for the entry
1497 protected abstract @Nullable List
<@NonNull ITimeEvent
> getEventList(@NonNull TimeGraphEntry entry
,
1498 long startTime
, long endTime
, long resolution
,
1499 @NonNull IProgressMonitor monitor
);
1502 * Gets the list of links (displayed as arrows) for a trace in a given
1503 * timerange. Default implementation returns an empty list.
1506 * Start of the time range
1508 * End of the time range
1512 * The progress monitor object
1513 * @return The list of link events
1515 protected @Nullable List
<@NonNull ILinkEvent
> getLinkList(long startTime
, long endTime
,
1516 long resolution
, @NonNull IProgressMonitor monitor
) {
1517 return new ArrayList
<>();
1521 * Gets the list of view-specific marker categories. Default implementation
1522 * returns an empty list.
1524 * @return The list of marker categories
1527 protected @NonNull List
<String
> getViewMarkerCategories() {
1528 return new ArrayList
<>();
1532 * Gets the list of view-specific markers for a trace in a given time range.
1533 * Default implementation returns an empty list.
1536 * Start of the time range
1538 * End of the time range
1542 * The progress monitor object
1543 * @return The list of marker events
1546 protected @NonNull List
<IMarkerEvent
> getViewMarkerList(long startTime
, long endTime
,
1547 long resolution
, @NonNull IProgressMonitor monitor
) {
1548 return new ArrayList
<>();
1552 * Gets the list of trace-specific markers for a trace in a given time range.
1555 * Start of the time range
1557 * End of the time range
1561 * The progress monitor object
1562 * @return The list of marker events
1565 protected @NonNull List
<IMarkerEvent
> getTraceMarkerList(long startTime
, long endTime
,
1566 long resolution
, @NonNull IProgressMonitor monitor
) {
1567 List
<IMarkerEvent
> markers
= new ArrayList
<>();
1568 for (IMarkerEventSource markerEventSource
: getMarkerEventSources(fTrace
)) {
1569 for (String category
: markerEventSource
.getMarkerCategories()) {
1570 if (monitor
.isCanceled()) {
1573 markers
.addAll(markerEventSource
.getMarkerList(checkNotNull(category
), startTime
, endTime
, resolution
, monitor
));
1580 * Get the list of current marker categories.
1582 * @return The list of marker categories
1585 private @NonNull List
<String
> getMarkerCategories() {
1586 Set
<String
> categories
= new HashSet
<>(getViewMarkerCategories());
1587 for (IMarkerEventSource markerEventSource
: getMarkerEventSources(fTrace
)) {
1588 categories
.addAll(markerEventSource
.getMarkerCategories());
1590 return new ArrayList
<>(categories
);
1594 * Gets the list of marker event sources for a given trace.
1598 * @return The list of marker event sources
1601 private @NonNull List
<IMarkerEventSource
> getMarkerEventSources(ITmfTrace trace
) {
1602 List
<IMarkerEventSource
> markerEventSources
= fMarkerEventSourcesMap
.get(trace
);
1603 if (markerEventSources
== null) {
1604 markerEventSources
= checkNotNull(Collections
.<IMarkerEventSource
>emptyList());
1606 return markerEventSources
;
1610 * Refresh the display
1612 protected void refresh() {
1613 final boolean zoomThread
= Thread
.currentThread() instanceof ZoomThread
;
1614 TmfUiRefreshHandler
.getInstance().queueUpdate(this, new Runnable() {
1617 if (fTimeGraphWrapper
.isDisposed()) {
1620 boolean hasEntries
= false;
1621 synchronized (fEntryListMap
) {
1622 fEntryList
= fEntryListMap
.get(fTrace
);
1623 if (fEntryList
== null) {
1624 fEntryList
= new CopyOnWriteArrayList
<>();
1625 } else if (fEntryComparator
!= null) {
1626 List
<TimeGraphEntry
> list
= new ArrayList
<>(fEntryList
);
1627 Collections
.sort(list
, fEntryComparator
);
1628 for (ITimeGraphEntry entry
: list
) {
1629 sortChildren(entry
, fEntryComparator
);
1632 fEntryList
.addAll(list
);
1634 hasEntries
= !fEntryList
.isEmpty();
1636 boolean inputChanged
= fEntryList
!= fTimeGraphWrapper
.getInput();
1638 fTimeGraphWrapper
.setInput(fEntryList
);
1639 /* restore the previously saved filters, if any */
1640 fTimeGraphWrapper
.setFilters(fFiltersMap
.get(fTrace
));
1641 fTimeGraphWrapper
.getTimeGraphViewer().setLinks(null);
1642 fTimeGraphWrapper
.getTimeGraphViewer().setBookmarks(refreshBookmarks(fEditorFile
));
1643 fTimeGraphWrapper
.getTimeGraphViewer().setMarkerCategories(getMarkerCategories());
1644 fTimeGraphWrapper
.getTimeGraphViewer().setMarkers(null);
1646 fTimeGraphWrapper
.refresh();
1648 long startBound
= (fStartTime
== Long
.MAX_VALUE ? SWT
.DEFAULT
: fStartTime
);
1649 long endBound
= (fEndTime
== Long
.MIN_VALUE ? SWT
.DEFAULT
: fEndTime
);
1650 fTimeGraphWrapper
.getTimeGraphViewer().setTimeBounds(startBound
, endBound
);
1652 TmfTraceContext ctx
= TmfTraceManager
.getInstance().getCurrentTraceContext();
1653 long selectionBeginTime
= fTrace
== null ? SWT
.DEFAULT
: ctx
.getSelectionRange().getStartTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
1654 long selectionEndTime
= fTrace
== null ? SWT
.DEFAULT
: ctx
.getSelectionRange().getEndTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
1655 long startTime
= fTrace
== null ? SWT
.DEFAULT
: ctx
.getWindowRange().getStartTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
1656 long endTime
= fTrace
== null ? SWT
.DEFAULT
: ctx
.getWindowRange().getEndTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
1657 startTime
= (fStartTime
== Long
.MAX_VALUE ? SWT
.DEFAULT
: Math
.max(startTime
, fStartTime
));
1658 endTime
= (fEndTime
== Long
.MIN_VALUE ? SWT
.DEFAULT
: Math
.min(endTime
, fEndTime
));
1659 fTimeGraphWrapper
.getTimeGraphViewer().setSelectionRange(selectionBeginTime
, selectionEndTime
, false);
1660 fTimeGraphWrapper
.getTimeGraphViewer().setStartFinishTime(startTime
, endTime
);
1662 if (inputChanged
&& selectionBeginTime
!= SWT
.DEFAULT
) {
1663 synchingToTime(selectionBeginTime
);
1666 if (fTimeGraphWrapper
instanceof TimeGraphComboWrapper
&& !fPackDone
) {
1667 for (TreeColumn column
: ((TimeGraphComboWrapper
) fTimeGraphWrapper
).getTreeViewer().getTree().getColumns()) {
1676 startZoomThread(startTime
, endTime
);
1685 protected void redraw() {
1686 synchronized (fSyncObj
) {
1687 if (fRedrawState
== State
.IDLE
) {
1688 fRedrawState
= State
.BUSY
;
1690 fRedrawState
= State
.PENDING
;
1694 Display
.getDefault().asyncExec(new Runnable() {
1697 if (fTimeGraphWrapper
.isDisposed()) {
1700 fTimeGraphWrapper
.redraw();
1701 fTimeGraphWrapper
.update();
1702 synchronized (fSyncObj
) {
1703 if (fRedrawState
== State
.PENDING
) {
1704 fRedrawState
= State
.IDLE
;
1707 fRedrawState
= State
.IDLE
;
1714 private static void sortChildren(ITimeGraphEntry entry
, Comparator
<ITimeGraphEntry
> comparator
) {
1715 if (entry
instanceof TimeGraphEntry
) {
1716 ((TimeGraphEntry
) entry
).sortChildren(comparator
);
1718 for (ITimeGraphEntry child
: entry
.getChildren()) {
1719 sortChildren(child
, comparator
);
1724 * Start or restart the zoom thread.
1727 * the zoom start time
1732 protected final void startZoomThread(long startTime
, long endTime
) {
1733 fDirty
.incrementAndGet();
1734 boolean restart
= false;
1735 if (fZoomThread
!= null) {
1736 fZoomThread
.cancel();
1737 if (fZoomThread
.fZoomStartTime
== startTime
&& fZoomThread
.fZoomEndTime
== endTime
) {
1741 long resolution
= Math
.max(1, (endTime
- startTime
) / fDisplayWidth
);
1742 fZoomThread
= createZoomThread(startTime
, endTime
, resolution
, restart
);
1743 if (fZoomThread
!= null) {
1744 fZoomThread
.start();
1746 fDirty
.decrementAndGet();
1751 * Create a zoom thread.
1754 * the zoom start time
1760 * true if restarting zoom for the same time range
1761 * @return a zoom thread
1764 protected @Nullable ZoomThread
createZoomThread(long startTime
, long endTime
, long resolution
, boolean restart
) {
1765 final List
<TimeGraphEntry
> entryList
= fEntryList
;
1766 if (entryList
== null) {
1769 return new ZoomThreadByEntry(entryList
, startTime
, endTime
, resolution
);
1772 private void makeActions() {
1773 fPreviousResourceAction
= fTimeGraphWrapper
.getTimeGraphViewer().getPreviousItemAction();
1774 fPreviousResourceAction
.setText(getPrevText());
1775 fPreviousResourceAction
.setToolTipText(getPrevTooltip());
1776 fNextResourceAction
= fTimeGraphWrapper
.getTimeGraphViewer().getNextItemAction();
1777 fNextResourceAction
.setText(getNextText());
1778 fNextResourceAction
.setToolTipText(getNextTooltip());
1781 private void contributeToActionBars() {
1782 IActionBars bars
= getViewSite().getActionBars();
1783 fillLocalToolBar(bars
.getToolBarManager());
1784 fillLocalMenu(bars
.getMenuManager());
1788 * Add actions to local tool bar manager
1790 * @param manager the tool bar manager
1792 protected void fillLocalToolBar(IToolBarManager manager
) {
1793 if (fFilterColumns
!= null && fFilterLabelProvider
!= null && fFilterColumns
.length
> 0) {
1794 manager
.add(fTimeGraphWrapper
.getShowFilterDialogAction());
1796 manager
.add(fTimeGraphWrapper
.getTimeGraphViewer().getShowLegendAction());
1797 manager
.add(new Separator());
1798 manager
.add(fTimeGraphWrapper
.getTimeGraphViewer().getResetScaleAction());
1799 manager
.add(fTimeGraphWrapper
.getTimeGraphViewer().getPreviousEventAction());
1800 manager
.add(fTimeGraphWrapper
.getTimeGraphViewer().getNextEventAction());
1801 manager
.add(new Separator());
1802 manager
.add(fTimeGraphWrapper
.getTimeGraphViewer().getToggleBookmarkAction());
1803 manager
.add(fTimeGraphWrapper
.getTimeGraphViewer().getPreviousMarkerAction());
1804 manager
.add(fTimeGraphWrapper
.getTimeGraphViewer().getNextMarkerAction());
1805 manager
.add(new Separator());
1806 manager
.add(fPreviousResourceAction
);
1807 manager
.add(fNextResourceAction
);
1808 manager
.add(fTimeGraphWrapper
.getTimeGraphViewer().getZoomInAction());
1809 manager
.add(fTimeGraphWrapper
.getTimeGraphViewer().getZoomOutAction());
1810 manager
.add(new Separator());
1814 * Add actions to local menu manager
1816 * @param manager the tool bar manager
1819 protected void fillLocalMenu(IMenuManager manager
) {
1820 manager
.add(fTimeGraphWrapper
.getTimeGraphViewer().getMarkersMenu());
1827 public TmfTimeViewAlignmentInfo
getTimeViewAlignmentInfo() {
1828 if (fTimeGraphWrapper
== null) {
1831 return fTimeGraphWrapper
.getTimeViewAlignmentInfo();
1838 public int getAvailableWidth(int requestedOffset
) {
1839 if (fTimeGraphWrapper
== null) {
1842 return fTimeGraphWrapper
.getAvailableWidth(requestedOffset
);
1849 public void performAlign(int offset
, int width
) {
1850 if (fTimeGraphWrapper
!= null) {
1851 fTimeGraphWrapper
.performAlign(offset
, width
);
1856 * Returns whether or not the time graph view is dirty. The time graph view
1857 * is considered dirty if it has yet to completely update its model.
1859 * @return true if the time graph view has yet to completely update its
1860 * model, false otherwise
1863 public boolean isDirty() {
1864 if (fZoomThread
== null) {
1867 return fDirty
.get() != 0 || fZoomThread
.getZoomStartTime() != fTimeGraphWrapper
.getTimeGraphViewer().getTime0() || fZoomThread
.getZoomEndTime() != fTimeGraphWrapper
.getTimeGraphViewer().getTime1();