1 /*******************************************************************************
2 * Copyright (c) 2012, 2015 Ericsson, École Polytechnique de Montréal
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * Patrick Tasse - Initial API and implementation
11 * Bernd Hufmann - Updated signal handling
12 * Geneviève Bastien - Move code to provide base classes for time graph view
13 * Marc-Andre Laperle - Add time zone preference
14 * Geneviève Bastien - Add event links between entries
15 *******************************************************************************/
17 package org
.eclipse
.tracecompass
.tmf
.ui
.views
.timegraph
;
19 import static org
.eclipse
.tracecompass
.common
.core
.NonNullUtils
.checkNotNull
;
21 import java
.util
.ArrayList
;
22 import java
.util
.Collections
;
23 import java
.util
.Comparator
;
24 import java
.util
.HashMap
;
25 import java
.util
.HashSet
;
26 import java
.util
.List
;
29 import java
.util
.concurrent
.CopyOnWriteArrayList
;
30 import java
.util
.regex
.Matcher
;
31 import java
.util
.regex
.Pattern
;
33 import org
.eclipse
.core
.resources
.IFile
;
34 import org
.eclipse
.core
.resources
.IMarker
;
35 import org
.eclipse
.core
.resources
.IMarkerDelta
;
36 import org
.eclipse
.core
.resources
.IResource
;
37 import org
.eclipse
.core
.resources
.IResourceChangeEvent
;
38 import org
.eclipse
.core
.resources
.IResourceChangeListener
;
39 import org
.eclipse
.core
.resources
.IWorkspaceRunnable
;
40 import org
.eclipse
.core
.resources
.ResourcesPlugin
;
41 import org
.eclipse
.core
.runtime
.CoreException
;
42 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
43 import org
.eclipse
.core
.runtime
.NullProgressMonitor
;
44 import org
.eclipse
.jdt
.annotation
.NonNull
;
45 import org
.eclipse
.jdt
.annotation
.Nullable
;
46 import org
.eclipse
.jface
.action
.Action
;
47 import org
.eclipse
.jface
.action
.IAction
;
48 import org
.eclipse
.jface
.action
.IMenuManager
;
49 import org
.eclipse
.jface
.action
.IStatusLineManager
;
50 import org
.eclipse
.jface
.action
.IToolBarManager
;
51 import org
.eclipse
.jface
.action
.Separator
;
52 import org
.eclipse
.jface
.viewers
.AbstractTreeViewer
;
53 import org
.eclipse
.jface
.viewers
.ILabelProvider
;
54 import org
.eclipse
.jface
.viewers
.ILabelProviderListener
;
55 import org
.eclipse
.jface
.viewers
.ISelectionProvider
;
56 import org
.eclipse
.jface
.viewers
.ITableLabelProvider
;
57 import org
.eclipse
.jface
.viewers
.ITreeContentProvider
;
58 import org
.eclipse
.jface
.viewers
.TreeViewer
;
59 import org
.eclipse
.jface
.viewers
.ViewerFilter
;
60 import org
.eclipse
.osgi
.util
.NLS
;
61 import org
.eclipse
.swt
.SWT
;
62 import org
.eclipse
.swt
.graphics
.Color
;
63 import org
.eclipse
.swt
.graphics
.Image
;
64 import org
.eclipse
.swt
.widgets
.Composite
;
65 import org
.eclipse
.swt
.widgets
.Display
;
66 import org
.eclipse
.swt
.widgets
.TreeColumn
;
67 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.Activator
;
68 import org
.eclipse
.tracecompass
.tmf
.core
.resources
.ITmfMarker
;
69 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfSelectionRangeUpdatedSignal
;
70 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfSignalHandler
;
71 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfTimestampFormatUpdateSignal
;
72 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfTraceClosedSignal
;
73 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfTraceOpenedSignal
;
74 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfTraceSelectedSignal
;
75 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfWindowRangeUpdatedSignal
;
76 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.ITmfTimestamp
;
77 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.TmfNanoTimestamp
;
78 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.TmfTimeRange
;
79 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfTrace
;
80 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.TmfTraceAdapterManager
;
81 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.TmfTraceContext
;
82 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.TmfTraceManager
;
83 import org
.eclipse
.tracecompass
.tmf
.ui
.TmfUiRefreshHandler
;
84 import org
.eclipse
.tracecompass
.tmf
.ui
.signal
.TmfTimeViewAlignmentInfo
;
85 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.ITmfTimeAligned
;
86 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.TmfView
;
87 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.ITimeGraphBookmarkListener
;
88 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.ITimeGraphContentProvider
;
89 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.ITimeGraphPresentationProvider2
;
90 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.ITimeGraphRangeListener
;
91 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.ITimeGraphSelectionListener
;
92 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.ITimeGraphTimeListener
;
93 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.TimeGraphBookmarkEvent
;
94 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.TimeGraphCombo
;
95 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.TimeGraphContentProvider
;
96 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.TimeGraphPresentationProvider
;
97 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.TimeGraphRangeUpdateEvent
;
98 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.TimeGraphTimeEvent
;
99 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.TimeGraphViewer
;
100 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.ILinkEvent
;
101 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.IMarkerEvent
;
102 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.IMarkerEventSource
;
103 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.ITimeEvent
;
104 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.ITimeGraphEntry
;
105 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.MarkerEvent
;
106 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.TimeGraphEntry
;
107 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.widgets
.Utils
.TimeFormat
;
108 import org
.eclipse
.ui
.IActionBars
;
111 * An abstract view all time graph views can inherit
113 * This view contains either a time graph viewer, or a time graph combo which is
114 * divided between a tree viewer on the left and a time graph viewer on the right.
116 public abstract class AbstractTimeGraphView
extends TmfView
implements ITmfTimeAligned
, IResourceChangeListener
{
118 /** Constant indicating that all levels of the time graph should be expanded */
119 protected static final int ALL_LEVELS
= AbstractTreeViewer
.ALL_LEVELS
;
121 private static final Pattern RGBA_PATTERN
= Pattern
.compile("RGBA \\{(\\d+), (\\d+), (\\d+), (\\d+)\\}"); //$NON-NLS-1$
130 // ------------------------------------------------------------------------
132 // ------------------------------------------------------------------------
134 /** The timegraph wrapper */
135 private ITimeGraphWrapper fTimeGraphWrapper
;
137 /** The selected trace */
138 private ITmfTrace fTrace
;
140 /** The selected trace editor file*/
141 private IFile fEditorFile
;
143 /** The timegraph entry list */
144 private List
<TimeGraphEntry
> fEntryList
;
146 /** The trace to entry list hash map */
147 private final Map
<ITmfTrace
, List
<TimeGraphEntry
>> fEntryListMap
= new HashMap
<>();
149 /** The trace to filters hash map */
150 private final Map
<ITmfTrace
, ViewerFilter
[]> fFiltersMap
= new HashMap
<>();
152 /** The trace to marker event sources hash map */
153 private final Map
<ITmfTrace
, List
<IMarkerEventSource
>> fMarkerEventSourcesMap
= new HashMap
<>();
155 /** The trace to build thread hash map */
156 private final Map
<ITmfTrace
, BuildThread
> fBuildThreadMap
= new HashMap
<>();
158 /** The start time */
159 private long fStartTime
= SWT
.DEFAULT
;
162 private long fEndTime
= SWT
.DEFAULT
;
164 /** The display width */
165 private final int fDisplayWidth
;
167 /** The zoom thread */
168 private ZoomThread fZoomThread
;
170 /** The next resource action */
171 private Action fNextResourceAction
;
173 /** The previous resource action */
174 private Action fPreviousResourceAction
;
176 /** A comparator class */
177 private Comparator
<ITimeGraphEntry
> fEntryComparator
= null;
179 /** The redraw state used to prevent unnecessary queuing of display runnables */
180 private State fRedrawState
= State
.IDLE
;
182 /** The redraw synchronization object */
183 private final Object fSyncObj
= new Object();
185 /** The presentation provider for this view */
186 private final TimeGraphPresentationProvider fPresentation
;
188 /** The tree column label array, or null if combo is not used */
189 private String
[] fColumns
;
191 /** The tree label provider, or null if combo is not used */
192 private TreeLabelProvider fLabelProvider
= null;
194 /** The time graph content provider */
195 private @NonNull ITimeGraphContentProvider fTimeGraphContentProvider
= new TimeGraphContentProvider();
197 /** The relative weight of the sash, ignored if combo is not used */
198 private int[] fWeight
= { 1, 3 };
200 /** The filter column label array, or null if filter is not used */
201 private String
[] fFilterColumns
;
203 /** The pack done flag */
204 private boolean fPackDone
= false;
206 /** The filter content provider, or null if filter is not used */
207 private ITreeContentProvider fFilterContentProvider
;
209 /** The filter label provider, or null if filter is not used */
210 private TreeLabelProvider fFilterLabelProvider
;
212 private int fAutoExpandLevel
= ALL_LEVELS
;
214 /** The list of color resources created by this view */
215 private final List
<Color
> fColors
= new ArrayList
<>();
217 // ------------------------------------------------------------------------
219 // ------------------------------------------------------------------------
221 private interface ITimeGraphWrapper
{
223 void setTimeGraphContentProvider(ITimeGraphContentProvider timeGraphContentProvider
);
225 void setTimeGraphPresentationProvider(TimeGraphPresentationProvider timeGraphPresentationProvider
);
227 TimeGraphViewer
getTimeGraphViewer();
229 void addSelectionListener(ITimeGraphSelectionListener listener
);
231 ISelectionProvider
getSelectionProvider();
235 boolean isDisposed();
239 void setInput(Object input
);
243 void setFilters(ViewerFilter
[] filters
);
245 ViewerFilter
[] getFilters();
251 void setAutoExpandLevel(int level
);
253 void setFilterColumns(String
[] columnNames
);
255 void setFilterContentProvider(ITreeContentProvider contentProvider
);
257 void setFilterLabelProvider(ITableLabelProvider labelProvider
);
259 IAction
getShowFilterDialogAction();
261 void performAlign(int offset
, int width
);
263 TmfTimeViewAlignmentInfo
getTimeViewAlignmentInfo();
265 int getAvailableWidth(int requestedOffset
);
268 private class TimeGraphViewerWrapper
implements ITimeGraphWrapper
{
269 private TimeGraphViewer viewer
;
271 private TimeGraphViewerWrapper(Composite parent
, int style
) {
272 viewer
= new TimeGraphViewer(parent
, style
);
276 public void setTimeGraphContentProvider(ITimeGraphContentProvider timeGraphContentProvider
) {
277 viewer
.setTimeGraphContentProvider(timeGraphContentProvider
);
281 public void setTimeGraphPresentationProvider(TimeGraphPresentationProvider timeGraphPresentationProvider
) {
282 viewer
.setTimeGraphProvider(timeGraphPresentationProvider
);
286 public TimeGraphViewer
getTimeGraphViewer() {
291 public void addSelectionListener(ITimeGraphSelectionListener listener
) {
292 viewer
.addSelectionListener(listener
);
296 public ISelectionProvider
getSelectionProvider() {
297 return viewer
.getSelectionProvider();
301 public void setFocus() {
306 public boolean isDisposed() {
307 return viewer
.getControl().isDisposed();
311 public void setInput(Object input
) {
312 viewer
.setInput(input
);
316 public Object
getInput() {
317 return viewer
.getInput();
321 public void setFilterColumns(String
[] columnNames
) {
322 viewer
.setFilterColumns(columnNames
);
326 public void setFilterContentProvider(ITreeContentProvider contentProvider
) {
327 viewer
.setFilterContentProvider(contentProvider
);
331 public void setFilterLabelProvider(ITableLabelProvider labelProvider
) {
332 viewer
.setFilterLabelProvider(labelProvider
);
336 public void setFilters(ViewerFilter
[] filters
) {
337 viewer
.setFilters(filters
);
341 public ViewerFilter
[] getFilters() {
342 return viewer
.getFilters();
346 public IAction
getShowFilterDialogAction() {
347 return viewer
.getShowFilterDialogAction();
351 public void refresh() {
356 public void redraw() {
357 viewer
.getControl().redraw();
361 public void update() {
362 viewer
.getControl().update();
366 public void setAutoExpandLevel(int level
) {
367 viewer
.setAutoExpandLevel(level
);
371 public void performAlign(int offset
, int width
) {
372 viewer
.performAlign(offset
, width
);
376 public TmfTimeViewAlignmentInfo
getTimeViewAlignmentInfo() {
377 return viewer
.getTimeViewAlignmentInfo();
381 public int getAvailableWidth(int requestedOffset
) {
382 return viewer
.getAvailableWidth(requestedOffset
);
386 private class TimeGraphComboWrapper
implements ITimeGraphWrapper
{
387 private TimeGraphCombo combo
;
389 private TimeGraphComboWrapper(Composite parent
, int style
) {
390 combo
= new TimeGraphCombo(parent
, style
, fWeight
);
394 public void setTimeGraphContentProvider(ITimeGraphContentProvider timeGraphContentProvider
) {
395 combo
.setTimeGraphContentProvider(timeGraphContentProvider
);
399 public void setTimeGraphPresentationProvider(TimeGraphPresentationProvider timeGraphPresentationProvider
) {
400 combo
.setTimeGraphProvider(timeGraphPresentationProvider
);
404 public TimeGraphViewer
getTimeGraphViewer() {
405 return combo
.getTimeGraphViewer();
409 public void addSelectionListener(ITimeGraphSelectionListener listener
) {
410 combo
.addSelectionListener(listener
);
414 public ISelectionProvider
getSelectionProvider() {
415 return combo
.getTreeViewer();
419 public void setFocus() {
424 public boolean isDisposed() {
425 return combo
.isDisposed();
429 public void setInput(Object input
) {
430 combo
.setInput(input
);
434 public Object
getInput() {
435 return combo
.getInput();
439 public void setFilterColumns(String
[] columnNames
) {
440 combo
.setFilterColumns(columnNames
);
444 public void setFilterContentProvider(ITreeContentProvider contentProvider
) {
445 combo
.setFilterContentProvider(contentProvider
);
449 public void setFilterLabelProvider(ITableLabelProvider labelProvider
) {
450 combo
.setFilterLabelProvider(labelProvider
);
454 public void setFilters(ViewerFilter
[] filters
) {
455 combo
.setFilters(filters
);
459 public ViewerFilter
[] getFilters() {
460 return combo
.getFilters();
464 public IAction
getShowFilterDialogAction() {
465 return combo
.getShowFilterDialogAction();
469 public void refresh() {
474 public void redraw() {
479 public void update() {
484 public void setAutoExpandLevel(int level
) {
485 combo
.setAutoExpandLevel(level
);
488 TimeGraphCombo
getTimeGraphCombo() {
492 TreeViewer
getTreeViewer() {
493 return combo
.getTreeViewer();
497 public void performAlign(int offset
, int width
) {
498 combo
.performAlign(offset
, width
);
502 public TmfTimeViewAlignmentInfo
getTimeViewAlignmentInfo() {
503 return combo
.getTimeViewAlignmentInfo();
507 public int getAvailableWidth(int requestedOffset
) {
508 return combo
.getAvailableWidth(requestedOffset
);
513 * Base class to provide the labels for the tree viewer. Views extending
514 * this class typically need to override the getColumnText method if they
515 * have more than one column to display
517 protected static class TreeLabelProvider
implements ITableLabelProvider
, ILabelProvider
{
520 public void addListener(ILabelProviderListener listener
) {
524 public void dispose() {
528 public boolean isLabelProperty(Object element
, String property
) {
533 public void removeListener(ILabelProviderListener listener
) {
537 public Image
getColumnImage(Object element
, int columnIndex
) {
542 public String
getColumnText(Object element
, int columnIndex
) {
543 TimeGraphEntry entry
= (TimeGraphEntry
) element
;
544 if (columnIndex
== 0) {
545 return entry
.getName();
551 public Image
getImage(Object element
) {
556 public String
getText(Object element
) {
557 TimeGraphEntry entry
= (TimeGraphEntry
) element
;
558 return entry
.getName();
563 private class BuildThread
extends Thread
{
564 private final @NonNull ITmfTrace fBuildTrace
;
565 private final @NonNull ITmfTrace fParentTrace
;
566 private final @NonNull IProgressMonitor fMonitor
;
568 public BuildThread(final @NonNull ITmfTrace trace
, final @NonNull ITmfTrace parentTrace
, final String name
) {
569 super(name
+ " build"); //$NON-NLS-1$
571 fParentTrace
= parentTrace
;
572 fMonitor
= new NullProgressMonitor();
577 buildEventList(fBuildTrace
, fParentTrace
, fMonitor
);
578 synchronized (fBuildThreadMap
) {
579 fBuildThreadMap
.remove(fBuildTrace
);
583 public void cancel() {
584 fMonitor
.setCanceled(true);
592 protected abstract class ZoomThread
extends Thread
{
593 private final long fZoomStartTime
;
594 private final long fZoomEndTime
;
595 private final long fResolution
;
596 private final @NonNull IProgressMonitor fMonitor
;
608 public ZoomThread(long startTime
, long endTime
, long resolution
) {
609 super(AbstractTimeGraphView
.this.getName() + " zoom"); //$NON-NLS-1$
610 fZoomStartTime
= startTime
;
611 fZoomEndTime
= endTime
;
612 fResolution
= resolution
;
613 fMonitor
= new NullProgressMonitor();
617 * @return the zoom start time
619 public long getZoomStartTime() {
620 return fZoomStartTime
;
624 * @return the zoom end time
626 public long getZoomEndTime() {
631 * @return the resolution
633 public long getResolution() {
638 * @return the monitor
640 public @NonNull IProgressMonitor
getMonitor() {
645 * Cancel the zoom thread
647 public void cancel() {
648 fMonitor
.setCanceled(true);
652 private class ZoomThreadByEntry
extends ZoomThread
{
653 private final @NonNull List
<TimeGraphEntry
> fZoomEntryList
;
655 public ZoomThreadByEntry(@NonNull List
<TimeGraphEntry
> entryList
, long startTime
, long endTime
, long resolution
) {
656 super(startTime
, endTime
, resolution
);
657 fZoomEntryList
= entryList
;
662 for (TimeGraphEntry entry
: fZoomEntryList
) {
663 if (getMonitor().isCanceled()) {
669 zoom(entry
, getMonitor());
671 /* Refresh the arrows when zooming */
672 List
<ILinkEvent
> events
= getLinkList(getZoomStartTime(), getZoomEndTime(), getResolution(), getMonitor());
673 if (events
!= null) {
674 fTimeGraphWrapper
.getTimeGraphViewer().setLinks(events
);
677 /* Refresh the view-specific markers when zooming */
678 List
<IMarkerEvent
> markers
= new ArrayList
<>(getViewMarkerList(getZoomStartTime(), getZoomEndTime(), getResolution(), getMonitor()));
679 /* Refresh the trace-specific markers when zooming */
680 markers
.addAll(getTraceMarkerList(getZoomStartTime(), getZoomEndTime(), getResolution(), getMonitor()));
681 fTimeGraphWrapper
.getTimeGraphViewer().setMarkers(markers
);
685 private void zoom(@NonNull TimeGraphEntry entry
, @NonNull IProgressMonitor monitor
) {
686 if (getZoomStartTime() <= fStartTime
&& getZoomEndTime() >= fEndTime
) {
687 entry
.setZoomedEventList(null);
689 List
<ITimeEvent
> zoomedEventList
= getEventList(entry
, getZoomStartTime(), getZoomEndTime(), getResolution(), monitor
);
690 if (zoomedEventList
!= null) {
691 entry
.setZoomedEventList(zoomedEventList
);
695 for (ITimeGraphEntry child
: entry
.getChildren()) {
696 if (monitor
.isCanceled()) {
699 if (child
instanceof TimeGraphEntry
) {
700 zoom((TimeGraphEntry
) child
, monitor
);
707 // ------------------------------------------------------------------------
709 // ------------------------------------------------------------------------
712 * Constructs a time graph view that contains either a time graph viewer or
713 * a time graph combo.
715 * By default, the view uses a time graph viewer. To use a time graph combo,
716 * the subclass constructor must call {@link #setTreeColumns(String[])} and
717 * {@link #setTreeLabelProvider(TreeLabelProvider)}.
722 * The presentation provider
724 public AbstractTimeGraphView(String id
, TimeGraphPresentationProvider pres
) {
726 fPresentation
= pres
;
727 fDisplayWidth
= Display
.getDefault().getBounds().width
;
730 // ------------------------------------------------------------------------
731 // Getters and setters
732 // ------------------------------------------------------------------------
735 * Getter for the time graph combo
737 * @return The time graph combo, or null if combo is not used
739 protected TimeGraphCombo
getTimeGraphCombo() {
740 if (fTimeGraphWrapper
instanceof TimeGraphComboWrapper
) {
741 return ((TimeGraphComboWrapper
) fTimeGraphWrapper
).getTimeGraphCombo();
747 * Getter for the time graph viewer
749 * @return The time graph viewer
751 protected TimeGraphViewer
getTimeGraphViewer() {
752 return fTimeGraphWrapper
.getTimeGraphViewer();
756 * Getter for the presentation provider
758 * @return The time graph presentation provider
760 protected ITimeGraphPresentationProvider2
getPresentationProvider() {
761 return fPresentation
;
765 * Sets the tree column labels.
766 * This should be called from the constructor.
769 * The array of tree column labels
771 protected void setTreeColumns(final String
[] columns
) {
776 * Sets the tree label provider.
777 * This should be called from the constructor.
780 * The tree label provider
782 protected void setTreeLabelProvider(final TreeLabelProvider tlp
) {
783 fLabelProvider
= tlp
;
787 * Sets the time graph content provider. This should be called from the
791 * The time graph content provider
794 protected void setTimeGraphContentProvider(final @NonNull ITimeGraphContentProvider tgcp
) {
795 fTimeGraphContentProvider
= tgcp
;
799 * Sets the relative weight of each part of the time graph combo.
800 * This should be called from the constructor.
803 * The array (length 2) of relative weights of each part of the combo
805 protected void setWeight(final int[] weights
) {
810 * Sets the filter column labels.
811 * This should be called from the constructor.
813 * @param filterColumns
814 * The array of filter column labels
816 protected void setFilterColumns(final String
[] filterColumns
) {
817 fFilterColumns
= filterColumns
;
821 * Sets the filter content provider.
822 * This should be called from the constructor.
824 * @param contentProvider
825 * The filter content provider
828 protected void setFilterContentProvider(final ITreeContentProvider contentProvider
) {
829 fFilterContentProvider
= contentProvider
;
833 * Sets the filter label provider.
834 * This should be called from the constructor.
836 * @param labelProvider
837 * The filter label provider
839 protected void setFilterLabelProvider(final TreeLabelProvider labelProvider
) {
840 fFilterLabelProvider
= labelProvider
;
844 * Gets the display width
846 * @return the display width
848 protected int getDisplayWidth() {
849 return fDisplayWidth
;
853 * Gets the comparator for the entries
855 * @return The entry comparator
857 protected Comparator
<ITimeGraphEntry
> getEntryComparator() {
858 return fEntryComparator
;
862 * Sets the comparator class for the entries.
864 * This comparator will apply recursively to entries that implement
865 * {@link TimeGraphEntry#sortChildren(Comparator)}.
868 * A comparator object
870 protected void setEntryComparator(final Comparator
<ITimeGraphEntry
> comparator
) {
871 fEntryComparator
= comparator
;
875 * Gets the trace displayed in the view
879 protected ITmfTrace
getTrace() {
884 * Gets the start time
886 * @return The start time
888 protected long getStartTime() {
893 * Sets the start time
898 protected void setStartTime(long time
) {
905 * @return The end time
907 protected long getEndTime() {
917 protected void setEndTime(long time
) {
922 * Sets the auto-expand level to be used for the input of the view. The
923 * value 0 means that there is no auto-expand; 1 means that top-level
924 * elements are expanded, but not their children; 2 means that top-level
925 * elements are expanded, and their children, but not grand-children; and so
928 * The value {@link #ALL_LEVELS} means that all subtrees should be expanded.
932 * non-negative level, or <code>ALL_LEVELS</code> to expand all
935 protected void setAutoExpandLevel(int level
) {
936 fAutoExpandLevel
= level
;
937 ITimeGraphWrapper tgWrapper
= fTimeGraphWrapper
;
938 if (tgWrapper
!= null) {
939 tgWrapper
.setAutoExpandLevel(level
);
944 * Gets the entry list for a trace
949 * @return the entry list map
951 protected List
<TimeGraphEntry
> getEntryList(ITmfTrace trace
) {
952 synchronized (fEntryListMap
) {
953 return fEntryListMap
.get(trace
);
958 * Adds a trace entry list to the entry list map
963 * the list of time graph entries
965 protected void putEntryList(ITmfTrace trace
, List
<TimeGraphEntry
> list
) {
966 synchronized (fEntryListMap
) {
967 fEntryListMap
.put(trace
, new CopyOnWriteArrayList
<>(list
));
972 * Adds a list of entries to a trace's entry list
977 * the list of time graph entries to add
979 protected void addToEntryList(ITmfTrace trace
, List
<TimeGraphEntry
> list
) {
980 synchronized (fEntryListMap
) {
981 List
<TimeGraphEntry
> entryList
= fEntryListMap
.get(trace
);
982 if (entryList
== null) {
983 fEntryListMap
.put(trace
, new CopyOnWriteArrayList
<>(list
));
985 entryList
.addAll(list
);
991 * Removes a list of entries from a trace's entry list
996 * the list of time graph entries to remove
998 protected void removeFromEntryList(ITmfTrace trace
, List
<TimeGraphEntry
> list
) {
999 synchronized (fEntryListMap
) {
1000 List
<TimeGraphEntry
> entryList
= fEntryListMap
.get(trace
);
1001 if (entryList
!= null) {
1002 entryList
.removeAll(list
);
1008 * Text for the "next" button
1010 * @return The "next" button text
1012 protected String
getNextText() {
1013 return Messages
.AbstractTimeGraphtView_NextText
;
1017 * Tooltip for the "next" button
1019 * @return Tooltip for the "next" button
1021 protected String
getNextTooltip() {
1022 return Messages
.AbstractTimeGraphView_NextTooltip
;
1026 * Text for the "Previous" button
1028 * @return The "Previous" button text
1030 protected String
getPrevText() {
1031 return Messages
.AbstractTimeGraphView_PreviousText
;
1035 * Tooltip for the "previous" button
1037 * @return Tooltip for the "previous" button
1039 protected String
getPrevTooltip() {
1040 return Messages
.AbstractTimeGraphView_PreviousTooltip
;
1043 // ------------------------------------------------------------------------
1045 // ------------------------------------------------------------------------
1048 public void createPartControl(Composite parent
) {
1049 super.createPartControl(parent
);
1050 if (fColumns
== null || fLabelProvider
== null) {
1051 fTimeGraphWrapper
= new TimeGraphViewerWrapper(parent
, SWT
.NONE
);
1053 TimeGraphComboWrapper wrapper
= new TimeGraphComboWrapper(parent
, SWT
.NONE
);
1054 fTimeGraphWrapper
= wrapper
;
1055 TimeGraphCombo combo
= wrapper
.getTimeGraphCombo();
1056 combo
.setTreeContentProvider(fTimeGraphContentProvider
);
1057 combo
.setTreeLabelProvider(fLabelProvider
);
1058 combo
.setTreeColumns(fColumns
);
1060 fTimeGraphWrapper
.setTimeGraphContentProvider(fTimeGraphContentProvider
);
1061 fTimeGraphWrapper
.setFilterContentProvider(fFilterContentProvider
!= null ? fFilterContentProvider
: fTimeGraphContentProvider
);
1062 fTimeGraphWrapper
.setFilterLabelProvider(fFilterLabelProvider
);
1063 fTimeGraphWrapper
.setFilterColumns(fFilterColumns
);
1065 fTimeGraphWrapper
.setTimeGraphPresentationProvider(fPresentation
);
1066 fTimeGraphWrapper
.setAutoExpandLevel(fAutoExpandLevel
);
1068 fTimeGraphWrapper
.getTimeGraphViewer().addRangeListener(new ITimeGraphRangeListener() {
1070 public void timeRangeUpdated(TimeGraphRangeUpdateEvent event
) {
1071 final long startTime
= event
.getStartTime();
1072 final long endTime
= event
.getEndTime();
1073 TmfTimeRange range
= new TmfTimeRange(new TmfNanoTimestamp(startTime
), new TmfNanoTimestamp(endTime
));
1074 broadcast(new TmfWindowRangeUpdatedSignal(AbstractTimeGraphView
.this, range
));
1075 startZoomThread(startTime
, endTime
);
1079 fTimeGraphWrapper
.getTimeGraphViewer().addTimeListener(new ITimeGraphTimeListener() {
1081 public void timeSelected(TimeGraphTimeEvent event
) {
1082 TmfNanoTimestamp startTime
= new TmfNanoTimestamp(event
.getBeginTime());
1083 TmfNanoTimestamp endTime
= new TmfNanoTimestamp(event
.getEndTime());
1084 broadcast(new TmfSelectionRangeUpdatedSignal(AbstractTimeGraphView
.this, startTime
, endTime
));
1088 fTimeGraphWrapper
.getTimeGraphViewer().addBookmarkListener(new ITimeGraphBookmarkListener() {
1090 public void bookmarkAdded(final TimeGraphBookmarkEvent event
) {
1092 ResourcesPlugin
.getWorkspace().run(new IWorkspaceRunnable() {
1094 public void run(IProgressMonitor monitor
) throws CoreException
{
1095 IMarkerEvent bookmark
= event
.getBookmark();
1096 IMarker marker
= fEditorFile
.createMarker(IMarker
.BOOKMARK
);
1097 marker
.setAttribute(IMarker
.MESSAGE
, bookmark
.getLabel());
1098 marker
.setAttribute(ITmfMarker
.MARKER_TIME
, Long
.toString(bookmark
.getTime()));
1099 if (bookmark
.getDuration() > 0) {
1100 marker
.setAttribute(ITmfMarker
.MARKER_DURATION
, Long
.toString(bookmark
.getDuration()));
1101 marker
.setAttribute(IMarker
.LOCATION
,
1102 NLS
.bind(org
.eclipse
.tracecompass
.internal
.tmf
.ui
.Messages
.TmfMarker_LocationTimeRange
,
1103 new TmfNanoTimestamp(bookmark
.getTime()),
1104 new TmfNanoTimestamp(bookmark
.getTime() + bookmark
.getDuration())));
1106 marker
.setAttribute(IMarker
.LOCATION
,
1107 NLS
.bind(org
.eclipse
.tracecompass
.internal
.tmf
.ui
.Messages
.TmfMarker_LocationTime
,
1108 new TmfNanoTimestamp(bookmark
.getTime())));
1110 marker
.setAttribute(ITmfMarker
.MARKER_COLOR
, bookmark
.getColor().getRGBA().toString());
1113 } catch (CoreException e
) {
1114 Activator
.getDefault().logError(e
.getMessage());
1119 public void bookmarkRemoved(TimeGraphBookmarkEvent event
) {
1121 IMarkerEvent bookmark
= event
.getBookmark();
1122 IMarker
[] markers
= fEditorFile
.findMarkers(IMarker
.BOOKMARK
, false, IResource
.DEPTH_ZERO
);
1123 for (IMarker marker
: markers
) {
1124 if (bookmark
.getLabel().equals(marker
.getAttribute(IMarker
.MESSAGE
)) &&
1125 Long
.toString(bookmark
.getTime()).equals(marker
.getAttribute(ITmfMarker
.MARKER_TIME
, (String
) null)) &&
1126 Long
.toString(bookmark
.getDuration()).equals(marker
.getAttribute(ITmfMarker
.MARKER_DURATION
, Long
.toString(0))) &&
1127 bookmark
.getColor().getRGBA().toString().equals(marker
.getAttribute(ITmfMarker
.MARKER_COLOR
))) {
1132 } catch (CoreException e
) {
1133 Activator
.getDefault().logError(e
.getMessage());
1138 fTimeGraphWrapper
.getTimeGraphViewer().setTimeFormat(TimeFormat
.CALENDAR
);
1140 IStatusLineManager statusLineManager
= getViewSite().getActionBars().getStatusLineManager();
1141 fTimeGraphWrapper
.getTimeGraphViewer().getTimeGraphControl().setStatusLineManager(statusLineManager
);
1143 // View Action Handling
1145 contributeToActionBars();
1147 ITmfTrace trace
= TmfTraceManager
.getInstance().getActiveTrace();
1148 if (trace
!= null) {
1149 traceSelected(new TmfTraceSelectedSignal(this, trace
));
1152 // make selection available to other views
1153 getSite().setSelectionProvider(fTimeGraphWrapper
.getSelectionProvider());
1155 ResourcesPlugin
.getWorkspace().addResourceChangeListener(this, IResourceChangeEvent
.POST_CHANGE
);
1159 public void setFocus() {
1160 fTimeGraphWrapper
.setFocus();
1164 public void dispose() {
1166 ResourcesPlugin
.getWorkspace().removeResourceChangeListener(this);
1173 public void resourceChanged(final IResourceChangeEvent event
) {
1174 for (final IMarkerDelta delta
: event
.findMarkerDeltas(IMarker
.BOOKMARK
, false)) {
1175 if (delta
.getResource().equals(fEditorFile
)) {
1176 fTimeGraphWrapper
.getTimeGraphViewer().setBookmarks(refreshBookmarks(fEditorFile
));
1183 private List
<IMarkerEvent
> refreshBookmarks(final IFile editorFile
) {
1184 List
<IMarkerEvent
> bookmarks
= new ArrayList
<>();
1185 for (Color color
: fColors
) {
1189 if (editorFile
== null || !editorFile
.exists()) {
1193 IMarker
[] markers
= editorFile
.findMarkers(IMarker
.BOOKMARK
, false, IResource
.DEPTH_ZERO
);
1194 for (IMarker marker
: markers
) {
1195 String label
= marker
.getAttribute(IMarker
.MESSAGE
, (String
) null);
1196 String time
= marker
.getAttribute(ITmfMarker
.MARKER_TIME
, (String
) null);
1197 String duration
= marker
.getAttribute(ITmfMarker
.MARKER_DURATION
, Long
.toString(0));
1198 String rgba
= marker
.getAttribute(ITmfMarker
.MARKER_COLOR
, (String
) null);
1199 if (label
!= null && time
!= null && rgba
!= null) {
1200 Matcher matcher
= RGBA_PATTERN
.matcher(rgba
);
1201 if (matcher
.matches()) {
1203 int red
= Integer
.valueOf(matcher
.group(1));
1204 int green
= Integer
.valueOf(matcher
.group(2));
1205 int blue
= Integer
.valueOf(matcher
.group(3));
1206 int alpha
= Integer
.valueOf(matcher
.group(4));
1207 Color color
= new Color(Display
.getDefault(), red
, green
, blue
, alpha
);
1209 bookmarks
.add(new MarkerEvent(null, Long
.valueOf(time
), Long
.valueOf(duration
), IMarkerEvent
.BOOKMARKS
, color
, label
, true));
1210 } catch (NumberFormatException e
) {
1211 Activator
.getDefault().logError(e
.getMessage());
1216 } catch (CoreException e
) {
1217 Activator
.getDefault().logError(e
.getMessage());
1222 // ------------------------------------------------------------------------
1224 // ------------------------------------------------------------------------
1227 * Handler for the trace opened signal.
1230 * The incoming signal
1233 public void traceOpened(TmfTraceOpenedSignal signal
) {
1234 loadTrace(signal
.getTrace());
1238 * Handler for the trace selected signal
1241 * The incoming signal
1244 public void traceSelected(final TmfTraceSelectedSignal signal
) {
1245 if (signal
.getTrace() == fTrace
) {
1248 loadTrace(signal
.getTrace());
1252 * Trace is closed: clear the data structures and the view
1255 * the signal received
1258 public void traceClosed(final TmfTraceClosedSignal signal
) {
1259 synchronized (fBuildThreadMap
) {
1260 for (ITmfTrace trace
: getTracesToBuild(signal
.getTrace())) {
1261 BuildThread buildThread
= fBuildThreadMap
.remove(trace
);
1262 if (buildThread
!= null) {
1263 buildThread
.cancel();
1267 fMarkerEventSourcesMap
.remove(signal
.getTrace());
1268 synchronized (fEntryListMap
) {
1269 fEntryListMap
.remove(signal
.getTrace());
1271 fFiltersMap
.remove(signal
.getTrace());
1272 if (signal
.getTrace() == fTrace
) {
1275 fStartTime
= SWT
.DEFAULT
;
1276 fEndTime
= SWT
.DEFAULT
;
1277 if (fZoomThread
!= null) {
1278 fZoomThread
.cancel();
1286 * Handler for the selection range signal.
1289 * The signal that's received
1293 public void selectionRangeUpdated(final TmfSelectionRangeUpdatedSignal signal
) {
1294 if (signal
.getSource() == this || fTrace
== null) {
1297 final long beginTime
= signal
.getBeginTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
1298 final long endTime
= signal
.getEndTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
1300 Display
.getDefault().asyncExec(new Runnable() {
1303 if (fTimeGraphWrapper
.isDisposed()) {
1306 if (beginTime
== endTime
) {
1307 fTimeGraphWrapper
.getTimeGraphViewer().setSelectedTime(beginTime
, true);
1309 fTimeGraphWrapper
.getTimeGraphViewer().setSelectionRange(beginTime
, endTime
, true);
1311 synchingToTime(fTimeGraphWrapper
.getTimeGraphViewer().getSelectionBegin());
1317 * Handler for the window range signal.
1320 * The signal that's received
1324 public void windowRangeUpdated(final TmfWindowRangeUpdatedSignal signal
) {
1325 if (signal
.getSource() == this || fTrace
== null) {
1328 if (signal
.getCurrentRange().getIntersection(fTrace
.getTimeRange()) == null) {
1331 final long startTime
= signal
.getCurrentRange().getStartTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
1332 final long endTime
= signal
.getCurrentRange().getEndTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
1333 Display
.getDefault().asyncExec(new Runnable() {
1336 if (fTimeGraphWrapper
.isDisposed()) {
1339 fTimeGraphWrapper
.getTimeGraphViewer().setStartFinishTime(startTime
, endTime
);
1340 startZoomThread(startTime
, endTime
);
1346 * @param signal the format of the timestamps was updated.
1349 public void updateTimeFormat( final TmfTimestampFormatUpdateSignal signal
){
1350 fTimeGraphWrapper
.refresh();
1353 // ------------------------------------------------------------------------
1355 // ------------------------------------------------------------------------
1357 private void loadTrace(final ITmfTrace trace
) {
1358 if (fZoomThread
!= null) {
1359 fZoomThread
.cancel();
1362 if (fTrace
!= null) {
1363 /* save the filters of the previous trace */
1364 fFiltersMap
.put(fTrace
, fTimeGraphWrapper
.getFilters());
1367 fEditorFile
= TmfTraceManager
.getInstance().getTraceEditorFile(trace
);
1368 synchronized (fEntryListMap
) {
1369 fEntryList
= fEntryListMap
.get(fTrace
);
1370 if (fEntryList
== null) {
1373 fStartTime
= fTrace
.getStartTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
1374 fEndTime
= fTrace
.getEndTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
1381 * Forces a rebuild of the entries list, even if entries already exist for this trace
1383 protected void rebuild() {
1384 setStartTime(Long
.MAX_VALUE
);
1385 setEndTime(Long
.MIN_VALUE
);
1387 ITmfTrace viewTrace
= fTrace
;
1388 if (viewTrace
== null) {
1391 List
<IMarkerEventSource
> markerEventSources
= new ArrayList
<>();
1392 synchronized (fBuildThreadMap
) {
1393 for (ITmfTrace trace
: getTracesToBuild(viewTrace
)) {
1394 if (trace
== null) {
1397 markerEventSources
.addAll(TmfTraceAdapterManager
.getAdapters(trace
, IMarkerEventSource
.class));
1398 BuildThread buildThread
= new BuildThread(trace
, viewTrace
, getName());
1399 fBuildThreadMap
.put(trace
, buildThread
);
1400 buildThread
.start();
1403 fMarkerEventSourcesMap
.put(viewTrace
, markerEventSources
);
1407 * Method called when synching to a given timestamp. Inheriting classes can
1408 * perform actions here to update the view at the given timestamp.
1411 * The currently selected time
1413 protected void synchingToTime(long time
) {
1418 * Return the list of traces whose data or analysis results will be used to
1419 * populate the view. By default, if the trace is an experiment, the traces
1420 * under it will be returned, otherwise, the trace itself is returned.
1422 * A build thread will be started for each trace returned by this method,
1423 * some of which may receive events in live streaming mode.
1426 * The trace associated with this view
1427 * @return List of traces with data to display
1429 protected @NonNull Iterable
<ITmfTrace
> getTracesToBuild(@NonNull ITmfTrace trace
) {
1430 return TmfTraceManager
.getTraceSet(trace
);
1434 * Build the entries list to show in this time graph
1436 * Called from the BuildThread
1439 * The trace being built
1440 * @param parentTrace
1441 * The parent of the trace set, or the trace itself
1443 * The progress monitor object
1445 protected abstract void buildEventList(@NonNull ITmfTrace trace
, @NonNull ITmfTrace parentTrace
, @NonNull IProgressMonitor monitor
);
1448 * Gets the list of event for an entry in a given timerange
1451 * The entry to get events for
1453 * Start of the time range
1455 * End of the time range
1459 * The progress monitor object
1460 * @return The list of events for the entry
1462 protected abstract @Nullable List
<@NonNull ITimeEvent
> getEventList(@NonNull TimeGraphEntry entry
,
1463 long startTime
, long endTime
, long resolution
,
1464 @NonNull IProgressMonitor monitor
);
1467 * Gets the list of links (displayed as arrows) for a trace in a given
1468 * timerange. Default implementation returns an empty list.
1471 * Start of the time range
1473 * End of the time range
1477 * The progress monitor object
1478 * @return The list of link events
1480 protected @Nullable List
<@NonNull ILinkEvent
> getLinkList(long startTime
, long endTime
,
1481 long resolution
, @NonNull IProgressMonitor monitor
) {
1482 return new ArrayList
<>();
1486 * Gets the list of view-specific marker categories. Default implementation
1487 * returns an empty list.
1489 * @return The list of marker categories
1492 protected @NonNull List
<String
> getViewMarkerCategories() {
1493 return new ArrayList
<>();
1497 * Gets the list of view-specific markers for a trace in a given time range.
1498 * Default implementation returns an empty list.
1501 * Start of the time range
1503 * End of the time range
1507 * The progress monitor object
1508 * @return The list of marker events
1511 protected @NonNull List
<IMarkerEvent
> getViewMarkerList(long startTime
, long endTime
,
1512 long resolution
, @NonNull IProgressMonitor monitor
) {
1513 return new ArrayList
<>();
1517 * Gets the list of trace-specific markers for a trace in a given time range.
1520 * Start of the time range
1522 * End of the time range
1526 * The progress monitor object
1527 * @return The list of marker events
1530 protected @NonNull List
<IMarkerEvent
> getTraceMarkerList(long startTime
, long endTime
,
1531 long resolution
, @NonNull IProgressMonitor monitor
) {
1532 List
<IMarkerEvent
> markers
= new ArrayList
<>();
1533 for (IMarkerEventSource markerEventSource
: getMarkerEventSources(fTrace
)) {
1534 for (String category
: markerEventSource
.getMarkerCategories()) {
1535 if (monitor
.isCanceled()) {
1538 markers
.addAll(markerEventSource
.getMarkerList(checkNotNull(category
), startTime
, endTime
, resolution
, monitor
));
1545 * Get the list of current marker categories.
1547 * @return The list of marker categories
1550 private @NonNull List
<String
> getMarkerCategories() {
1551 Set
<String
> categories
= new HashSet
<>(getViewMarkerCategories());
1552 for (IMarkerEventSource markerEventSource
: getMarkerEventSources(fTrace
)) {
1553 categories
.addAll(markerEventSource
.getMarkerCategories());
1555 return new ArrayList
<>(categories
);
1559 * Gets the list of marker event sources for a given trace.
1563 * @return The list of marker event sources
1566 private @NonNull List
<IMarkerEventSource
> getMarkerEventSources(ITmfTrace trace
) {
1567 List
<IMarkerEventSource
> markerEventSources
= fMarkerEventSourcesMap
.get(trace
);
1568 if (markerEventSources
== null) {
1569 markerEventSources
= checkNotNull(Collections
.<IMarkerEventSource
>emptyList());
1571 return markerEventSources
;
1575 * Refresh the display
1577 protected void refresh() {
1578 final boolean zoomThread
= Thread
.currentThread() instanceof ZoomThread
;
1579 TmfUiRefreshHandler
.getInstance().queueUpdate(this, new Runnable() {
1582 if (fTimeGraphWrapper
.isDisposed()) {
1585 boolean hasEntries
= false;
1586 synchronized (fEntryListMap
) {
1587 fEntryList
= fEntryListMap
.get(fTrace
);
1588 if (fEntryList
== null) {
1589 fEntryList
= new CopyOnWriteArrayList
<>();
1590 } else if (fEntryComparator
!= null) {
1591 List
<TimeGraphEntry
> list
= new ArrayList
<>(fEntryList
);
1592 Collections
.sort(list
, fEntryComparator
);
1593 for (ITimeGraphEntry entry
: list
) {
1594 sortChildren(entry
, fEntryComparator
);
1597 fEntryList
.addAll(list
);
1599 hasEntries
= fEntryList
.size() != 0;
1601 if (fEntryList
!= fTimeGraphWrapper
.getInput()) {
1602 fTimeGraphWrapper
.setInput(fEntryList
);
1603 /* restore the previously saved filters, if any */
1604 fTimeGraphWrapper
.setFilters(fFiltersMap
.get(fTrace
));
1605 fTimeGraphWrapper
.getTimeGraphViewer().setLinks(null);
1606 fTimeGraphWrapper
.getTimeGraphViewer().setBookmarks(refreshBookmarks(fEditorFile
));
1607 fTimeGraphWrapper
.getTimeGraphViewer().setMarkerCategories(getMarkerCategories());
1608 fTimeGraphWrapper
.getTimeGraphViewer().setMarkers(null);
1610 fTimeGraphWrapper
.refresh();
1612 long startBound
= (fStartTime
== Long
.MAX_VALUE ? SWT
.DEFAULT
: fStartTime
);
1613 long endBound
= (fEndTime
== Long
.MIN_VALUE ? SWT
.DEFAULT
: fEndTime
);
1614 fTimeGraphWrapper
.getTimeGraphViewer().setTimeBounds(startBound
, endBound
);
1616 TmfTraceContext ctx
= TmfTraceManager
.getInstance().getCurrentTraceContext();
1617 long selectionBeginTime
= fTrace
== null ? SWT
.DEFAULT
: ctx
.getSelectionRange().getStartTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
1618 long selectionEndTime
= fTrace
== null ? SWT
.DEFAULT
: ctx
.getSelectionRange().getEndTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
1619 long startTime
= fTrace
== null ? SWT
.DEFAULT
: ctx
.getWindowRange().getStartTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
1620 long endTime
= fTrace
== null ? SWT
.DEFAULT
: ctx
.getWindowRange().getEndTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
1621 startTime
= (fStartTime
== Long
.MAX_VALUE ? SWT
.DEFAULT
: Math
.max(startTime
, fStartTime
));
1622 endTime
= (fEndTime
== Long
.MIN_VALUE ? SWT
.DEFAULT
: Math
.min(endTime
, fEndTime
));
1623 fTimeGraphWrapper
.getTimeGraphViewer().setSelectionRange(selectionBeginTime
, selectionEndTime
, false);
1624 fTimeGraphWrapper
.getTimeGraphViewer().setStartFinishTime(startTime
, endTime
);
1626 if (fTimeGraphWrapper
instanceof TimeGraphComboWrapper
&& !fPackDone
) {
1627 for (TreeColumn column
: ((TimeGraphComboWrapper
) fTimeGraphWrapper
).getTreeViewer().getTree().getColumns()) {
1636 startZoomThread(startTime
, endTime
);
1645 protected void redraw() {
1646 synchronized (fSyncObj
) {
1647 if (fRedrawState
== State
.IDLE
) {
1648 fRedrawState
= State
.BUSY
;
1650 fRedrawState
= State
.PENDING
;
1654 Display
.getDefault().asyncExec(new Runnable() {
1657 if (fTimeGraphWrapper
.isDisposed()) {
1660 fTimeGraphWrapper
.redraw();
1661 fTimeGraphWrapper
.update();
1662 synchronized (fSyncObj
) {
1663 if (fRedrawState
== State
.PENDING
) {
1664 fRedrawState
= State
.IDLE
;
1667 fRedrawState
= State
.IDLE
;
1674 private static void sortChildren(ITimeGraphEntry entry
, Comparator
<ITimeGraphEntry
> comparator
) {
1675 if (entry
instanceof TimeGraphEntry
) {
1676 ((TimeGraphEntry
) entry
).sortChildren(comparator
);
1678 for (ITimeGraphEntry child
: entry
.getChildren()) {
1679 sortChildren(child
, comparator
);
1684 * Start or restart the zoom thread.
1687 * the zoom start time
1692 protected void startZoomThread(long startTime
, long endTime
) {
1693 boolean restart
= false;
1694 if (fZoomThread
!= null) {
1695 fZoomThread
.cancel();
1696 if (fZoomThread
.fZoomStartTime
== startTime
&& fZoomThread
.fZoomEndTime
== endTime
) {
1700 long resolution
= Math
.max(1, (endTime
- startTime
) / fDisplayWidth
);
1701 fZoomThread
= createZoomThread(startTime
, endTime
, resolution
, restart
);
1702 if (fZoomThread
!= null) {
1703 fZoomThread
.start();
1708 * Create a zoom thread.
1711 * the zoom start time
1717 * true if restarting zoom for the same time range
1718 * @return a zoom thread
1721 protected @Nullable ZoomThread
createZoomThread(long startTime
, long endTime
, long resolution
, boolean restart
) {
1722 final List
<TimeGraphEntry
> entryList
= fEntryList
;
1723 if (entryList
== null) {
1726 return new ZoomThreadByEntry(entryList
, startTime
, endTime
, resolution
);
1729 private void makeActions() {
1730 fPreviousResourceAction
= fTimeGraphWrapper
.getTimeGraphViewer().getPreviousItemAction();
1731 fPreviousResourceAction
.setText(getPrevText());
1732 fPreviousResourceAction
.setToolTipText(getPrevTooltip());
1733 fNextResourceAction
= fTimeGraphWrapper
.getTimeGraphViewer().getNextItemAction();
1734 fNextResourceAction
.setText(getNextText());
1735 fNextResourceAction
.setToolTipText(getNextTooltip());
1738 private void contributeToActionBars() {
1739 IActionBars bars
= getViewSite().getActionBars();
1740 fillLocalToolBar(bars
.getToolBarManager());
1741 fillLocalMenu(bars
.getMenuManager());
1745 * Add actions to local tool bar manager
1747 * @param manager the tool bar manager
1749 protected void fillLocalToolBar(IToolBarManager manager
) {
1750 if (fFilterColumns
!= null && fFilterLabelProvider
!= null && fFilterColumns
.length
> 0) {
1751 manager
.add(fTimeGraphWrapper
.getShowFilterDialogAction());
1753 manager
.add(fTimeGraphWrapper
.getTimeGraphViewer().getShowLegendAction());
1754 manager
.add(new Separator());
1755 manager
.add(fTimeGraphWrapper
.getTimeGraphViewer().getResetScaleAction());
1756 manager
.add(fTimeGraphWrapper
.getTimeGraphViewer().getPreviousEventAction());
1757 manager
.add(fTimeGraphWrapper
.getTimeGraphViewer().getNextEventAction());
1758 manager
.add(new Separator());
1759 manager
.add(fTimeGraphWrapper
.getTimeGraphViewer().getToggleBookmarkAction());
1760 manager
.add(fTimeGraphWrapper
.getTimeGraphViewer().getPreviousMarkerAction());
1761 manager
.add(fTimeGraphWrapper
.getTimeGraphViewer().getNextMarkerAction());
1762 manager
.add(new Separator());
1763 manager
.add(fPreviousResourceAction
);
1764 manager
.add(fNextResourceAction
);
1765 manager
.add(fTimeGraphWrapper
.getTimeGraphViewer().getZoomInAction());
1766 manager
.add(fTimeGraphWrapper
.getTimeGraphViewer().getZoomOutAction());
1767 manager
.add(new Separator());
1771 * Add actions to local menu manager
1773 * @param manager the tool bar manager
1776 protected void fillLocalMenu(IMenuManager manager
) {
1777 manager
.add(fTimeGraphWrapper
.getTimeGraphViewer().getMarkersMenu());
1784 public TmfTimeViewAlignmentInfo
getTimeViewAlignmentInfo() {
1785 if (fTimeGraphWrapper
== null) {
1788 return fTimeGraphWrapper
.getTimeViewAlignmentInfo();
1795 public int getAvailableWidth(int requestedOffset
) {
1796 if (fTimeGraphWrapper
== null) {
1799 return fTimeGraphWrapper
.getAvailableWidth(requestedOffset
);
1806 public void performAlign(int offset
, int width
) {
1807 if (fTimeGraphWrapper
!= null) {
1808 fTimeGraphWrapper
.performAlign(offset
, width
);