1 /*******************************************************************************
2 * Copyright (c) 2012, 2015 Ericsson, École Polytechnique de Montréal
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * Patrick Tasse - Initial API and implementation
11 * Bernd Hufmann - Updated signal handling
12 * Geneviève Bastien - Move code to provide base classes for time graph view
13 * Marc-Andre Laperle - Add time zone preference
14 * Geneviève Bastien - Add event links between entries
15 *******************************************************************************/
17 package org
.eclipse
.tracecompass
.tmf
.ui
.views
.timegraph
;
19 import static org
.eclipse
.tracecompass
.common
.core
.NonNullUtils
.checkNotNull
;
21 import java
.util
.ArrayList
;
22 import java
.util
.Collections
;
23 import java
.util
.Comparator
;
24 import java
.util
.HashMap
;
25 import java
.util
.HashSet
;
26 import java
.util
.List
;
29 import java
.util
.concurrent
.CopyOnWriteArrayList
;
30 import java
.util
.regex
.Matcher
;
31 import java
.util
.regex
.Pattern
;
33 import org
.eclipse
.core
.resources
.IFile
;
34 import org
.eclipse
.core
.resources
.IMarker
;
35 import org
.eclipse
.core
.resources
.IMarkerDelta
;
36 import org
.eclipse
.core
.resources
.IResource
;
37 import org
.eclipse
.core
.resources
.IResourceChangeEvent
;
38 import org
.eclipse
.core
.resources
.IResourceChangeListener
;
39 import org
.eclipse
.core
.resources
.IWorkspaceRunnable
;
40 import org
.eclipse
.core
.resources
.ResourcesPlugin
;
41 import org
.eclipse
.core
.runtime
.CoreException
;
42 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
43 import org
.eclipse
.core
.runtime
.NullProgressMonitor
;
44 import org
.eclipse
.jdt
.annotation
.NonNull
;
45 import org
.eclipse
.jdt
.annotation
.Nullable
;
46 import org
.eclipse
.jface
.action
.Action
;
47 import org
.eclipse
.jface
.action
.IAction
;
48 import org
.eclipse
.jface
.action
.IMenuManager
;
49 import org
.eclipse
.jface
.action
.IStatusLineManager
;
50 import org
.eclipse
.jface
.action
.IToolBarManager
;
51 import org
.eclipse
.jface
.action
.Separator
;
52 import org
.eclipse
.jface
.viewers
.AbstractTreeViewer
;
53 import org
.eclipse
.jface
.viewers
.ILabelProvider
;
54 import org
.eclipse
.jface
.viewers
.ILabelProviderListener
;
55 import org
.eclipse
.jface
.viewers
.ISelectionProvider
;
56 import org
.eclipse
.jface
.viewers
.ITableLabelProvider
;
57 import org
.eclipse
.jface
.viewers
.ITreeContentProvider
;
58 import org
.eclipse
.jface
.viewers
.TreeViewer
;
59 import org
.eclipse
.jface
.viewers
.ViewerFilter
;
60 import org
.eclipse
.osgi
.util
.NLS
;
61 import org
.eclipse
.swt
.SWT
;
62 import org
.eclipse
.swt
.graphics
.Color
;
63 import org
.eclipse
.swt
.graphics
.Image
;
64 import org
.eclipse
.swt
.widgets
.Composite
;
65 import org
.eclipse
.swt
.widgets
.Display
;
66 import org
.eclipse
.swt
.widgets
.TreeColumn
;
67 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.Activator
;
68 import org
.eclipse
.tracecompass
.tmf
.core
.resources
.ITmfMarker
;
69 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfSelectionRangeUpdatedSignal
;
70 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfSignalHandler
;
71 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfTimestampFormatUpdateSignal
;
72 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfTraceClosedSignal
;
73 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfTraceOpenedSignal
;
74 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfTraceSelectedSignal
;
75 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfWindowRangeUpdatedSignal
;
76 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.ITmfTimestamp
;
77 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.TmfNanoTimestamp
;
78 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.TmfTimeRange
;
79 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfTrace
;
80 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.TmfTraceAdapterManager
;
81 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.TmfTraceContext
;
82 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.TmfTraceManager
;
83 import org
.eclipse
.tracecompass
.tmf
.ui
.TmfUiRefreshHandler
;
84 import org
.eclipse
.tracecompass
.tmf
.ui
.signal
.TmfTimeViewAlignmentInfo
;
85 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.ITmfTimeAligned
;
86 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.TmfView
;
87 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.ITimeGraphBookmarkListener
;
88 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.ITimeGraphContentProvider
;
89 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.ITimeGraphPresentationProvider2
;
90 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.ITimeGraphRangeListener
;
91 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.ITimeGraphSelectionListener
;
92 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.ITimeGraphTimeListener
;
93 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.TimeGraphBookmarkEvent
;
94 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.TimeGraphCombo
;
95 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.TimeGraphContentProvider
;
96 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.TimeGraphPresentationProvider
;
97 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.TimeGraphRangeUpdateEvent
;
98 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.TimeGraphTimeEvent
;
99 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.TimeGraphViewer
;
100 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.ILinkEvent
;
101 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.IMarkerEvent
;
102 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.IMarkerEventSource
;
103 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.ITimeEvent
;
104 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.ITimeGraphEntry
;
105 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.MarkerEvent
;
106 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.TimeGraphEntry
;
107 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.widgets
.Utils
.TimeFormat
;
108 import org
.eclipse
.ui
.IActionBars
;
111 * An abstract view all time graph views can inherit
113 * This view contains either a time graph viewer, or a time graph combo which is
114 * divided between a tree viewer on the left and a time graph viewer on the right.
116 public abstract class AbstractTimeGraphView
extends TmfView
implements ITmfTimeAligned
, IResourceChangeListener
{
118 /** Constant indicating that all levels of the time graph should be expanded */
119 protected static final int ALL_LEVELS
= AbstractTreeViewer
.ALL_LEVELS
;
121 private static final Pattern RGBA_PATTERN
= Pattern
.compile("RGBA \\{(\\d+), (\\d+), (\\d+), (\\d+)\\}"); //$NON-NLS-1$
130 // ------------------------------------------------------------------------
132 // ------------------------------------------------------------------------
134 /** The timegraph wrapper */
135 private ITimeGraphWrapper fTimeGraphWrapper
;
137 /** The selected trace */
138 private ITmfTrace fTrace
;
140 /** The selected trace editor file*/
141 private IFile fEditorFile
;
143 /** The timegraph entry list */
144 private List
<TimeGraphEntry
> fEntryList
;
146 /** The trace to entry list hash map */
147 private final Map
<ITmfTrace
, List
<TimeGraphEntry
>> fEntryListMap
= new HashMap
<>();
149 /** The trace to filters hash map */
150 private final Map
<ITmfTrace
, ViewerFilter
[]> fFiltersMap
= new HashMap
<>();
152 /** The trace to marker event sources hash map */
153 private final Map
<ITmfTrace
, List
<IMarkerEventSource
>> fMarkerEventSourcesMap
= new HashMap
<>();
155 /** The trace to build thread hash map */
156 private final Map
<ITmfTrace
, BuildThread
> fBuildThreadMap
= new HashMap
<>();
158 /** The start time */
159 private long fStartTime
= SWT
.DEFAULT
;
162 private long fEndTime
= SWT
.DEFAULT
;
164 /** The display width */
165 private final int fDisplayWidth
;
167 /** The zoom thread */
168 private ZoomThread fZoomThread
;
170 /** The next resource action */
171 private Action fNextResourceAction
;
173 /** The previous resource action */
174 private Action fPreviousResourceAction
;
176 /** A comparator class */
177 private Comparator
<ITimeGraphEntry
> fEntryComparator
= null;
179 /** The redraw state used to prevent unnecessary queuing of display runnables */
180 private State fRedrawState
= State
.IDLE
;
182 /** The redraw synchronization object */
183 private final Object fSyncObj
= new Object();
185 /** The presentation provider for this view */
186 private final TimeGraphPresentationProvider fPresentation
;
188 /** The tree column label array, or null if combo is not used */
189 private String
[] fColumns
;
191 /** The tree label provider, or null if combo is not used */
192 private TreeLabelProvider fLabelProvider
= null;
194 /** The time graph content provider */
195 private @NonNull ITimeGraphContentProvider fTimeGraphContentProvider
= new TimeGraphContentProvider();
197 /** The relative weight of the sash, ignored if combo is not used */
198 private int[] fWeight
= { 1, 3 };
200 /** The filter column label array, or null if filter is not used */
201 private String
[] fFilterColumns
;
203 /** The pack done flag */
204 private boolean fPackDone
= false;
206 /** The filter label provider, or null if filter is not used */
207 private TreeLabelProvider fFilterLabelProvider
;
209 private int fAutoExpandLevel
= ALL_LEVELS
;
211 /** The list of color resources created by this view */
212 private final List
<Color
> fColors
= new ArrayList
<>();
214 // ------------------------------------------------------------------------
216 // ------------------------------------------------------------------------
218 private interface ITimeGraphWrapper
{
220 void setTimeGraphContentProvider(ITimeGraphContentProvider timeGraphContentProvider
);
222 void setTimeGraphPresentationProvider(TimeGraphPresentationProvider timeGraphPresentationProvider
);
224 TimeGraphViewer
getTimeGraphViewer();
226 void addSelectionListener(ITimeGraphSelectionListener listener
);
228 ISelectionProvider
getSelectionProvider();
232 boolean isDisposed();
236 void setInput(Object input
);
240 void setFilters(ViewerFilter
[] filters
);
242 ViewerFilter
[] getFilters();
248 void setAutoExpandLevel(int level
);
250 void setFilterColumns(String
[] columnNames
);
252 void setFilterContentProvider(ITreeContentProvider contentProvider
);
254 void setFilterLabelProvider(ITableLabelProvider labelProvider
);
256 IAction
getShowFilterDialogAction();
258 void performAlign(int offset
, int width
);
260 TmfTimeViewAlignmentInfo
getTimeViewAlignmentInfo();
262 int getAvailableWidth(int requestedOffset
);
265 private class TimeGraphViewerWrapper
implements ITimeGraphWrapper
{
266 private TimeGraphViewer viewer
;
268 private TimeGraphViewerWrapper(Composite parent
, int style
) {
269 viewer
= new TimeGraphViewer(parent
, style
);
273 public void setTimeGraphContentProvider(ITimeGraphContentProvider timeGraphContentProvider
) {
274 viewer
.setTimeGraphContentProvider(timeGraphContentProvider
);
278 public void setTimeGraphPresentationProvider(TimeGraphPresentationProvider timeGraphPresentationProvider
) {
279 viewer
.setTimeGraphProvider(timeGraphPresentationProvider
);
283 public TimeGraphViewer
getTimeGraphViewer() {
288 public void addSelectionListener(ITimeGraphSelectionListener listener
) {
289 viewer
.addSelectionListener(listener
);
293 public ISelectionProvider
getSelectionProvider() {
294 return viewer
.getSelectionProvider();
298 public void setFocus() {
303 public boolean isDisposed() {
304 return viewer
.getControl().isDisposed();
308 public void setInput(Object input
) {
309 viewer
.setInput(input
);
313 public Object
getInput() {
314 return viewer
.getInput();
318 public void setFilterColumns(String
[] columnNames
) {
319 viewer
.setFilterColumns(columnNames
);
323 public void setFilterContentProvider(ITreeContentProvider contentProvider
) {
324 viewer
.setFilterContentProvider(contentProvider
);
328 public void setFilterLabelProvider(ITableLabelProvider labelProvider
) {
329 viewer
.setFilterLabelProvider(labelProvider
);
333 public void setFilters(ViewerFilter
[] filters
) {
334 viewer
.setFilters(filters
);
338 public ViewerFilter
[] getFilters() {
339 return viewer
.getFilters();
343 public IAction
getShowFilterDialogAction() {
344 return viewer
.getShowFilterDialogAction();
348 public void refresh() {
353 public void redraw() {
354 viewer
.getControl().redraw();
358 public void update() {
359 viewer
.getControl().update();
363 public void setAutoExpandLevel(int level
) {
364 viewer
.setAutoExpandLevel(level
);
368 public void performAlign(int offset
, int width
) {
369 viewer
.performAlign(offset
, width
);
373 public TmfTimeViewAlignmentInfo
getTimeViewAlignmentInfo() {
374 return viewer
.getTimeViewAlignmentInfo();
378 public int getAvailableWidth(int requestedOffset
) {
379 return viewer
.getAvailableWidth(requestedOffset
);
383 private class TimeGraphComboWrapper
implements ITimeGraphWrapper
{
384 private TimeGraphCombo combo
;
386 private TimeGraphComboWrapper(Composite parent
, int style
) {
387 combo
= new TimeGraphCombo(parent
, style
, fWeight
);
391 public void setTimeGraphContentProvider(ITimeGraphContentProvider timeGraphContentProvider
) {
392 combo
.setTimeGraphContentProvider(timeGraphContentProvider
);
396 public void setTimeGraphPresentationProvider(TimeGraphPresentationProvider timeGraphPresentationProvider
) {
397 combo
.setTimeGraphProvider(timeGraphPresentationProvider
);
401 public TimeGraphViewer
getTimeGraphViewer() {
402 return combo
.getTimeGraphViewer();
406 public void addSelectionListener(ITimeGraphSelectionListener listener
) {
407 combo
.addSelectionListener(listener
);
411 public ISelectionProvider
getSelectionProvider() {
412 return combo
.getTreeViewer();
416 public void setFocus() {
421 public boolean isDisposed() {
422 return combo
.isDisposed();
426 public void setInput(Object input
) {
427 combo
.setInput(input
);
431 public Object
getInput() {
432 return combo
.getInput();
436 public void setFilterColumns(String
[] columnNames
) {
437 combo
.setFilterColumns(columnNames
);
441 public void setFilterContentProvider(ITreeContentProvider contentProvider
) {
442 combo
.setFilterContentProvider(contentProvider
);
446 public void setFilterLabelProvider(ITableLabelProvider labelProvider
) {
447 combo
.setFilterLabelProvider(labelProvider
);
451 public void setFilters(ViewerFilter
[] filters
) {
452 combo
.setFilters(filters
);
456 public ViewerFilter
[] getFilters() {
457 return combo
.getFilters();
461 public IAction
getShowFilterDialogAction() {
462 return combo
.getShowFilterDialogAction();
466 public void refresh() {
471 public void redraw() {
476 public void update() {
481 public void setAutoExpandLevel(int level
) {
482 combo
.setAutoExpandLevel(level
);
485 TimeGraphCombo
getTimeGraphCombo() {
489 TreeViewer
getTreeViewer() {
490 return combo
.getTreeViewer();
494 public void performAlign(int offset
, int width
) {
495 combo
.performAlign(offset
, width
);
499 public TmfTimeViewAlignmentInfo
getTimeViewAlignmentInfo() {
500 return combo
.getTimeViewAlignmentInfo();
504 public int getAvailableWidth(int requestedOffset
) {
505 return combo
.getAvailableWidth(requestedOffset
);
510 * Base class to provide the labels for the tree viewer. Views extending
511 * this class typically need to override the getColumnText method if they
512 * have more than one column to display
514 protected static class TreeLabelProvider
implements ITableLabelProvider
, ILabelProvider
{
517 public void addListener(ILabelProviderListener listener
) {
521 public void dispose() {
525 public boolean isLabelProperty(Object element
, String property
) {
530 public void removeListener(ILabelProviderListener listener
) {
534 public Image
getColumnImage(Object element
, int columnIndex
) {
539 public String
getColumnText(Object element
, int columnIndex
) {
540 TimeGraphEntry entry
= (TimeGraphEntry
) element
;
541 if (columnIndex
== 0) {
542 return entry
.getName();
548 public Image
getImage(Object element
) {
553 public String
getText(Object element
) {
554 TimeGraphEntry entry
= (TimeGraphEntry
) element
;
555 return entry
.getName();
560 private class BuildThread
extends Thread
{
561 private final @NonNull ITmfTrace fBuildTrace
;
562 private final @NonNull ITmfTrace fParentTrace
;
563 private final @NonNull IProgressMonitor fMonitor
;
565 public BuildThread(final @NonNull ITmfTrace trace
, final @NonNull ITmfTrace parentTrace
, final String name
) {
566 super(name
+ " build"); //$NON-NLS-1$
568 fParentTrace
= parentTrace
;
569 fMonitor
= new NullProgressMonitor();
574 buildEventList(fBuildTrace
, fParentTrace
, fMonitor
);
575 synchronized (fBuildThreadMap
) {
576 fBuildThreadMap
.remove(fBuildTrace
);
580 public void cancel() {
581 fMonitor
.setCanceled(true);
589 protected abstract class ZoomThread
extends Thread
{
590 private final long fZoomStartTime
;
591 private final long fZoomEndTime
;
592 private final long fResolution
;
593 private final @NonNull IProgressMonitor fMonitor
;
605 public ZoomThread(long startTime
, long endTime
, long resolution
) {
606 super(AbstractTimeGraphView
.this.getName() + " zoom"); //$NON-NLS-1$
607 fZoomStartTime
= startTime
;
608 fZoomEndTime
= endTime
;
609 fResolution
= resolution
;
610 fMonitor
= new NullProgressMonitor();
614 * @return the zoom start time
616 public long getZoomStartTime() {
617 return fZoomStartTime
;
621 * @return the zoom end time
623 public long getZoomEndTime() {
628 * @return the resolution
630 public long getResolution() {
635 * @return the monitor
637 public @NonNull IProgressMonitor
getMonitor() {
642 * Cancel the zoom thread
644 public void cancel() {
645 fMonitor
.setCanceled(true);
649 private class ZoomThreadByEntry
extends ZoomThread
{
650 private final @NonNull List
<TimeGraphEntry
> fZoomEntryList
;
652 public ZoomThreadByEntry(@NonNull List
<TimeGraphEntry
> entryList
, long startTime
, long endTime
, long resolution
) {
653 super(startTime
, endTime
, resolution
);
654 fZoomEntryList
= entryList
;
659 for (TimeGraphEntry entry
: fZoomEntryList
) {
660 if (getMonitor().isCanceled()) {
666 zoom(entry
, getMonitor());
668 /* Refresh the arrows when zooming */
669 List
<ILinkEvent
> events
= getLinkList(getZoomStartTime(), getZoomEndTime(), getResolution(), getMonitor());
670 if (events
!= null) {
671 fTimeGraphWrapper
.getTimeGraphViewer().setLinks(events
);
674 /* Refresh the view-specific markers when zooming */
675 List
<IMarkerEvent
> markers
= new ArrayList
<>(getViewMarkerList(getZoomStartTime(), getZoomEndTime(), getResolution(), getMonitor()));
676 /* Refresh the trace-specific markers when zooming */
677 markers
.addAll(getTraceMarkerList(getZoomStartTime(), getZoomEndTime(), getResolution(), getMonitor()));
678 fTimeGraphWrapper
.getTimeGraphViewer().setMarkers(markers
);
682 private void zoom(@NonNull TimeGraphEntry entry
, @NonNull IProgressMonitor monitor
) {
683 if (getZoomStartTime() <= fStartTime
&& getZoomEndTime() >= fEndTime
) {
684 entry
.setZoomedEventList(null);
686 List
<ITimeEvent
> zoomedEventList
= getEventList(entry
, getZoomStartTime(), getZoomEndTime(), getResolution(), monitor
);
687 if (zoomedEventList
!= null) {
688 entry
.setZoomedEventList(zoomedEventList
);
692 for (ITimeGraphEntry child
: entry
.getChildren()) {
693 if (monitor
.isCanceled()) {
696 if (child
instanceof TimeGraphEntry
) {
697 zoom((TimeGraphEntry
) child
, monitor
);
704 // ------------------------------------------------------------------------
706 // ------------------------------------------------------------------------
709 * Constructs a time graph view that contains either a time graph viewer or
710 * a time graph combo.
712 * By default, the view uses a time graph viewer. To use a time graph combo,
713 * the subclass constructor must call {@link #setTreeColumns(String[])} and
714 * {@link #setTreeLabelProvider(TreeLabelProvider)}.
719 * The presentation provider
721 public AbstractTimeGraphView(String id
, TimeGraphPresentationProvider pres
) {
723 fPresentation
= pres
;
724 fDisplayWidth
= Display
.getDefault().getBounds().width
;
727 // ------------------------------------------------------------------------
728 // Getters and setters
729 // ------------------------------------------------------------------------
732 * Getter for the time graph combo
734 * @return The time graph combo, or null if combo is not used
736 protected TimeGraphCombo
getTimeGraphCombo() {
737 if (fTimeGraphWrapper
instanceof TimeGraphComboWrapper
) {
738 return ((TimeGraphComboWrapper
) fTimeGraphWrapper
).getTimeGraphCombo();
744 * Getter for the time graph viewer
746 * @return The time graph viewer
748 protected TimeGraphViewer
getTimeGraphViewer() {
749 return fTimeGraphWrapper
.getTimeGraphViewer();
753 * Getter for the presentation provider
755 * @return The time graph presentation provider
757 protected ITimeGraphPresentationProvider2
getPresentationProvider() {
758 return fPresentation
;
762 * Sets the tree column labels.
763 * This should be called from the constructor.
766 * The array of tree column labels
768 protected void setTreeColumns(final String
[] columns
) {
773 * Sets the tree label provider.
774 * This should be called from the constructor.
777 * The tree label provider
779 protected void setTreeLabelProvider(final TreeLabelProvider tlp
) {
780 fLabelProvider
= tlp
;
784 * Sets the time graph content provider. This should be called from the
788 * The time graph content provider
791 protected void setTimeGraphContentProvider(final @NonNull ITimeGraphContentProvider tgcp
) {
792 fTimeGraphContentProvider
= tgcp
;
796 * Sets the relative weight of each part of the time graph combo.
797 * This should be called from the constructor.
800 * The array (length 2) of relative weights of each part of the combo
802 protected void setWeight(final int[] weights
) {
807 * Sets the filter column labels.
808 * This should be called from the constructor.
810 * @param filterColumns
811 * The array of filter column labels
813 protected void setFilterColumns(final String
[] filterColumns
) {
814 fFilterColumns
= filterColumns
;
818 * Sets the filter label provider.
819 * This should be called from the constructor.
821 * @param labelProvider
822 * The filter label provider
824 protected void setFilterLabelProvider(final TreeLabelProvider labelProvider
) {
825 fFilterLabelProvider
= labelProvider
;
829 * Gets the display width
831 * @return the display width
833 protected int getDisplayWidth() {
834 return fDisplayWidth
;
838 * Gets the comparator for the entries
840 * @return The entry comparator
842 protected Comparator
<ITimeGraphEntry
> getEntryComparator() {
843 return fEntryComparator
;
847 * Sets the comparator class for the entries
850 * A comparator object
852 protected void setEntryComparator(final Comparator
<ITimeGraphEntry
> comparator
) {
853 fEntryComparator
= comparator
;
857 * Gets the trace displayed in the view
861 protected ITmfTrace
getTrace() {
866 * Gets the start time
868 * @return The start time
870 protected long getStartTime() {
875 * Sets the start time
880 protected void setStartTime(long time
) {
887 * @return The end time
889 protected long getEndTime() {
899 protected void setEndTime(long time
) {
904 * Sets the auto-expand level to be used for the input of the view. The
905 * value 0 means that there is no auto-expand; 1 means that top-level
906 * elements are expanded, but not their children; 2 means that top-level
907 * elements are expanded, and their children, but not grand-children; and so
910 * The value {@link #ALL_LEVELS} means that all subtrees should be expanded.
914 * non-negative level, or <code>ALL_LEVELS</code> to expand all
917 protected void setAutoExpandLevel(int level
) {
918 fAutoExpandLevel
= level
;
919 ITimeGraphWrapper tgWrapper
= fTimeGraphWrapper
;
920 if (tgWrapper
!= null) {
921 tgWrapper
.setAutoExpandLevel(level
);
926 * Gets the entry list for a trace
931 * @return the entry list map
933 protected List
<TimeGraphEntry
> getEntryList(ITmfTrace trace
) {
934 synchronized (fEntryListMap
) {
935 return fEntryListMap
.get(trace
);
940 * Adds a trace entry list to the entry list map
945 * the list of time graph entries
947 protected void putEntryList(ITmfTrace trace
, List
<TimeGraphEntry
> list
) {
948 synchronized (fEntryListMap
) {
949 fEntryListMap
.put(trace
, new CopyOnWriteArrayList
<>(list
));
954 * Adds a list of entries to a trace's entry list
959 * the list of time graph entries to add
961 protected void addToEntryList(ITmfTrace trace
, List
<TimeGraphEntry
> list
) {
962 synchronized (fEntryListMap
) {
963 List
<TimeGraphEntry
> entryList
= fEntryListMap
.get(trace
);
964 if (entryList
== null) {
965 fEntryListMap
.put(trace
, new CopyOnWriteArrayList
<>(list
));
967 entryList
.addAll(list
);
973 * Removes a list of entries from a trace's entry list
978 * the list of time graph entries to remove
980 protected void removeFromEntryList(ITmfTrace trace
, List
<TimeGraphEntry
> list
) {
981 synchronized (fEntryListMap
) {
982 List
<TimeGraphEntry
> entryList
= fEntryListMap
.get(trace
);
983 if (entryList
!= null) {
984 entryList
.removeAll(list
);
990 * Text for the "next" button
992 * @return The "next" button text
994 protected String
getNextText() {
995 return Messages
.AbstractTimeGraphtView_NextText
;
999 * Tooltip for the "next" button
1001 * @return Tooltip for the "next" button
1003 protected String
getNextTooltip() {
1004 return Messages
.AbstractTimeGraphView_NextTooltip
;
1008 * Text for the "Previous" button
1010 * @return The "Previous" button text
1012 protected String
getPrevText() {
1013 return Messages
.AbstractTimeGraphView_PreviousText
;
1017 * Tooltip for the "previous" button
1019 * @return Tooltip for the "previous" button
1021 protected String
getPrevTooltip() {
1022 return Messages
.AbstractTimeGraphView_PreviousTooltip
;
1025 // ------------------------------------------------------------------------
1027 // ------------------------------------------------------------------------
1030 public void createPartControl(Composite parent
) {
1031 super.createPartControl(parent
);
1032 if (fColumns
== null || fLabelProvider
== null) {
1033 fTimeGraphWrapper
= new TimeGraphViewerWrapper(parent
, SWT
.NONE
);
1035 TimeGraphComboWrapper wrapper
= new TimeGraphComboWrapper(parent
, SWT
.NONE
);
1036 fTimeGraphWrapper
= wrapper
;
1037 TimeGraphCombo combo
= wrapper
.getTimeGraphCombo();
1038 combo
.setTreeContentProvider(fTimeGraphContentProvider
);
1039 combo
.setTreeLabelProvider(fLabelProvider
);
1040 combo
.setTreeColumns(fColumns
);
1042 fTimeGraphWrapper
.setTimeGraphContentProvider(fTimeGraphContentProvider
);
1043 fTimeGraphWrapper
.setFilterContentProvider(fTimeGraphContentProvider
);
1044 fTimeGraphWrapper
.setFilterLabelProvider(fFilterLabelProvider
);
1045 fTimeGraphWrapper
.setFilterColumns(fFilterColumns
);
1047 fTimeGraphWrapper
.setTimeGraphPresentationProvider(fPresentation
);
1048 fTimeGraphWrapper
.setAutoExpandLevel(fAutoExpandLevel
);
1050 fTimeGraphWrapper
.getTimeGraphViewer().addRangeListener(new ITimeGraphRangeListener() {
1052 public void timeRangeUpdated(TimeGraphRangeUpdateEvent event
) {
1053 final long startTime
= event
.getStartTime();
1054 final long endTime
= event
.getEndTime();
1055 TmfTimeRange range
= new TmfTimeRange(new TmfNanoTimestamp(startTime
), new TmfNanoTimestamp(endTime
));
1056 broadcast(new TmfWindowRangeUpdatedSignal(AbstractTimeGraphView
.this, range
));
1057 startZoomThread(startTime
, endTime
);
1061 fTimeGraphWrapper
.getTimeGraphViewer().addTimeListener(new ITimeGraphTimeListener() {
1063 public void timeSelected(TimeGraphTimeEvent event
) {
1064 TmfNanoTimestamp startTime
= new TmfNanoTimestamp(event
.getBeginTime());
1065 TmfNanoTimestamp endTime
= new TmfNanoTimestamp(event
.getEndTime());
1066 broadcast(new TmfSelectionRangeUpdatedSignal(AbstractTimeGraphView
.this, startTime
, endTime
));
1070 fTimeGraphWrapper
.getTimeGraphViewer().addBookmarkListener(new ITimeGraphBookmarkListener() {
1072 public void bookmarkAdded(final TimeGraphBookmarkEvent event
) {
1074 ResourcesPlugin
.getWorkspace().run(new IWorkspaceRunnable() {
1076 public void run(IProgressMonitor monitor
) throws CoreException
{
1077 IMarkerEvent bookmark
= event
.getBookmark();
1078 IMarker marker
= fEditorFile
.createMarker(IMarker
.BOOKMARK
);
1079 marker
.setAttribute(IMarker
.MESSAGE
, bookmark
.getLabel());
1080 marker
.setAttribute(ITmfMarker
.MARKER_TIME
, Long
.toString(bookmark
.getTime()));
1081 if (bookmark
.getDuration() > 0) {
1082 marker
.setAttribute(ITmfMarker
.MARKER_DURATION
, Long
.toString(bookmark
.getDuration()));
1083 marker
.setAttribute(IMarker
.LOCATION
,
1084 NLS
.bind(org
.eclipse
.tracecompass
.internal
.tmf
.ui
.Messages
.TmfMarker_LocationTimeRange
,
1085 new TmfNanoTimestamp(bookmark
.getTime()),
1086 new TmfNanoTimestamp(bookmark
.getTime() + bookmark
.getDuration())));
1088 marker
.setAttribute(IMarker
.LOCATION
,
1089 NLS
.bind(org
.eclipse
.tracecompass
.internal
.tmf
.ui
.Messages
.TmfMarker_LocationTime
,
1090 new TmfNanoTimestamp(bookmark
.getTime())));
1092 marker
.setAttribute(ITmfMarker
.MARKER_COLOR
, bookmark
.getColor().getRGBA().toString());
1095 } catch (CoreException e
) {
1096 Activator
.getDefault().logError(e
.getMessage());
1101 public void bookmarkRemoved(TimeGraphBookmarkEvent event
) {
1103 IMarkerEvent bookmark
= event
.getBookmark();
1104 IMarker
[] markers
= fEditorFile
.findMarkers(IMarker
.BOOKMARK
, false, IResource
.DEPTH_ZERO
);
1105 for (IMarker marker
: markers
) {
1106 if (bookmark
.getLabel().equals(marker
.getAttribute(IMarker
.MESSAGE
)) &&
1107 Long
.toString(bookmark
.getTime()).equals(marker
.getAttribute(ITmfMarker
.MARKER_TIME
, (String
) null)) &&
1108 Long
.toString(bookmark
.getDuration()).equals(marker
.getAttribute(ITmfMarker
.MARKER_DURATION
, Long
.toString(0))) &&
1109 bookmark
.getColor().getRGBA().toString().equals(marker
.getAttribute(ITmfMarker
.MARKER_COLOR
))) {
1114 } catch (CoreException e
) {
1115 Activator
.getDefault().logError(e
.getMessage());
1120 fTimeGraphWrapper
.getTimeGraphViewer().setTimeFormat(TimeFormat
.CALENDAR
);
1122 IStatusLineManager statusLineManager
= getViewSite().getActionBars().getStatusLineManager();
1123 fTimeGraphWrapper
.getTimeGraphViewer().getTimeGraphControl().setStatusLineManager(statusLineManager
);
1125 // View Action Handling
1127 contributeToActionBars();
1129 ITmfTrace trace
= TmfTraceManager
.getInstance().getActiveTrace();
1130 if (trace
!= null) {
1131 traceSelected(new TmfTraceSelectedSignal(this, trace
));
1134 // make selection available to other views
1135 getSite().setSelectionProvider(fTimeGraphWrapper
.getSelectionProvider());
1137 ResourcesPlugin
.getWorkspace().addResourceChangeListener(this, IResourceChangeEvent
.POST_CHANGE
);
1141 public void setFocus() {
1142 fTimeGraphWrapper
.setFocus();
1146 public void dispose() {
1148 ResourcesPlugin
.getWorkspace().removeResourceChangeListener(this);
1155 public void resourceChanged(final IResourceChangeEvent event
) {
1156 for (final IMarkerDelta delta
: event
.findMarkerDeltas(IMarker
.BOOKMARK
, false)) {
1157 if (delta
.getResource().equals(fEditorFile
)) {
1158 fTimeGraphWrapper
.getTimeGraphViewer().setBookmarks(refreshBookmarks(fEditorFile
));
1165 private List
<IMarkerEvent
> refreshBookmarks(final IFile editorFile
) {
1166 List
<IMarkerEvent
> bookmarks
= new ArrayList
<>();
1167 for (Color color
: fColors
) {
1171 if (editorFile
== null || !editorFile
.exists()) {
1175 IMarker
[] markers
= editorFile
.findMarkers(IMarker
.BOOKMARK
, false, IResource
.DEPTH_ZERO
);
1176 for (IMarker marker
: markers
) {
1177 String label
= marker
.getAttribute(IMarker
.MESSAGE
, (String
) null);
1178 String time
= marker
.getAttribute(ITmfMarker
.MARKER_TIME
, (String
) null);
1179 String duration
= marker
.getAttribute(ITmfMarker
.MARKER_DURATION
, Long
.toString(0));
1180 String rgba
= marker
.getAttribute(ITmfMarker
.MARKER_COLOR
, (String
) null);
1181 if (label
!= null && time
!= null && rgba
!= null) {
1182 Matcher matcher
= RGBA_PATTERN
.matcher(rgba
);
1183 if (matcher
.matches()) {
1185 int red
= Integer
.valueOf(matcher
.group(1));
1186 int green
= Integer
.valueOf(matcher
.group(2));
1187 int blue
= Integer
.valueOf(matcher
.group(3));
1188 int alpha
= Integer
.valueOf(matcher
.group(4));
1189 Color color
= new Color(Display
.getDefault(), red
, green
, blue
, alpha
);
1191 bookmarks
.add(new MarkerEvent(null, Long
.valueOf(time
), Long
.valueOf(duration
), IMarkerEvent
.BOOKMARKS
, color
, label
, true));
1192 } catch (NumberFormatException e
) {
1193 Activator
.getDefault().logError(e
.getMessage());
1198 } catch (CoreException e
) {
1199 Activator
.getDefault().logError(e
.getMessage());
1204 // ------------------------------------------------------------------------
1206 // ------------------------------------------------------------------------
1209 * Handler for the trace opened signal.
1212 * The incoming signal
1215 public void traceOpened(TmfTraceOpenedSignal signal
) {
1216 loadTrace(signal
.getTrace());
1220 * Handler for the trace selected signal
1223 * The incoming signal
1226 public void traceSelected(final TmfTraceSelectedSignal signal
) {
1227 if (signal
.getTrace() == fTrace
) {
1230 loadTrace(signal
.getTrace());
1234 * Trace is closed: clear the data structures and the view
1237 * the signal received
1240 public void traceClosed(final TmfTraceClosedSignal signal
) {
1241 synchronized (fBuildThreadMap
) {
1242 for (ITmfTrace trace
: getTracesToBuild(signal
.getTrace())) {
1243 BuildThread buildThread
= fBuildThreadMap
.remove(trace
);
1244 if (buildThread
!= null) {
1245 buildThread
.cancel();
1247 fMarkerEventSourcesMap
.remove(trace
);
1250 synchronized (fEntryListMap
) {
1251 fEntryListMap
.remove(signal
.getTrace());
1253 fFiltersMap
.remove(signal
.getTrace());
1254 if (signal
.getTrace() == fTrace
) {
1257 fStartTime
= SWT
.DEFAULT
;
1258 fEndTime
= SWT
.DEFAULT
;
1259 if (fZoomThread
!= null) {
1260 fZoomThread
.cancel();
1268 * Handler for the selection range signal.
1271 * The signal that's received
1275 public void selectionRangeUpdated(final TmfSelectionRangeUpdatedSignal signal
) {
1276 if (signal
.getSource() == this || fTrace
== null) {
1279 final long beginTime
= signal
.getBeginTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
1280 final long endTime
= signal
.getEndTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
1282 Display
.getDefault().asyncExec(new Runnable() {
1285 if (fTimeGraphWrapper
.isDisposed()) {
1288 if (beginTime
== endTime
) {
1289 fTimeGraphWrapper
.getTimeGraphViewer().setSelectedTime(beginTime
, true);
1291 fTimeGraphWrapper
.getTimeGraphViewer().setSelectionRange(beginTime
, endTime
);
1293 synchingToTime(fTimeGraphWrapper
.getTimeGraphViewer().getTime0());
1299 * Handler for the window range signal.
1302 * The signal that's received
1306 public void windowRangeUpdated(final TmfWindowRangeUpdatedSignal signal
) {
1307 if (signal
.getSource() == this || fTrace
== null) {
1310 if (signal
.getCurrentRange().getIntersection(fTrace
.getTimeRange()) == null) {
1313 final long startTime
= signal
.getCurrentRange().getStartTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
1314 final long endTime
= signal
.getCurrentRange().getEndTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
1315 Display
.getDefault().asyncExec(new Runnable() {
1318 if (fTimeGraphWrapper
.isDisposed()) {
1321 fTimeGraphWrapper
.getTimeGraphViewer().setStartFinishTime(startTime
, endTime
);
1322 startZoomThread(startTime
, endTime
);
1328 * @param signal the format of the timestamps was updated.
1331 public void updateTimeFormat( final TmfTimestampFormatUpdateSignal signal
){
1332 fTimeGraphWrapper
.refresh();
1335 // ------------------------------------------------------------------------
1337 // ------------------------------------------------------------------------
1339 private void loadTrace(final ITmfTrace trace
) {
1340 if (fZoomThread
!= null) {
1341 fZoomThread
.cancel();
1344 if (fTrace
!= null) {
1345 /* save the filters of the previous trace */
1346 fFiltersMap
.put(fTrace
, fTimeGraphWrapper
.getFilters());
1349 fEditorFile
= TmfTraceManager
.getInstance().getTraceEditorFile(trace
);
1350 synchronized (fEntryListMap
) {
1351 fEntryList
= fEntryListMap
.get(fTrace
);
1352 if (fEntryList
== null) {
1355 fStartTime
= fTrace
.getStartTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
1356 fEndTime
= fTrace
.getEndTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
1363 * Forces a rebuild of the entries list, even if entries already exist for this trace
1365 protected void rebuild() {
1366 setStartTime(Long
.MAX_VALUE
);
1367 setEndTime(Long
.MIN_VALUE
);
1369 ITmfTrace viewTrace
= fTrace
;
1370 if (viewTrace
== null) {
1373 synchronized (fBuildThreadMap
) {
1374 for (ITmfTrace trace
: getTracesToBuild(viewTrace
)) {
1375 if (trace
== null) {
1378 fMarkerEventSourcesMap
.put(trace
, TmfTraceAdapterManager
.getAdapters(trace
, IMarkerEventSource
.class));
1379 BuildThread buildThread
= new BuildThread(trace
, viewTrace
, getName());
1380 fBuildThreadMap
.put(trace
, buildThread
);
1381 buildThread
.start();
1387 * Method called when synching to a given timestamp. Inheriting classes can
1388 * perform actions here to update the view at the given timestamp.
1391 * The currently selected time
1393 protected void synchingToTime(long time
) {
1398 * Return the list of traces whose data or analysis results will be used to
1399 * populate the view. By default, if the trace is an experiment, the traces
1400 * under it will be returned, otherwise, the trace itself is returned.
1402 * A build thread will be started for each trace returned by this method,
1403 * some of which may receive events in live streaming mode.
1406 * The trace associated with this view
1407 * @return List of traces with data to display
1409 protected @NonNull Iterable
<ITmfTrace
> getTracesToBuild(@NonNull ITmfTrace trace
) {
1410 return TmfTraceManager
.getTraceSet(trace
);
1414 * Build the entries list to show in this time graph
1416 * Called from the BuildThread
1419 * The trace being built
1420 * @param parentTrace
1421 * The parent of the trace set, or the trace itself
1423 * The progress monitor object
1425 protected abstract void buildEventList(@NonNull ITmfTrace trace
, @NonNull ITmfTrace parentTrace
, @NonNull IProgressMonitor monitor
);
1428 * Gets the list of event for an entry in a given timerange
1431 * The entry to get events for
1433 * Start of the time range
1435 * End of the time range
1439 * The progress monitor object
1440 * @return The list of events for the entry
1442 protected abstract @Nullable List
<ITimeEvent
> getEventList(@NonNull TimeGraphEntry entry
,
1443 long startTime
, long endTime
, long resolution
,
1444 @NonNull IProgressMonitor monitor
);
1447 * Gets the list of links (displayed as arrows) for a trace in a given
1448 * timerange. Default implementation returns an empty list.
1451 * Start of the time range
1453 * End of the time range
1457 * The progress monitor object
1458 * @return The list of link events
1460 protected @Nullable List
<ILinkEvent
> getLinkList(long startTime
, long endTime
,
1461 long resolution
, @NonNull IProgressMonitor monitor
) {
1462 return new ArrayList
<>();
1466 * Gets the list of view-specific marker categories. Default implementation
1467 * returns an empty list.
1469 * @return The list of marker categories
1472 protected @NonNull List
<String
> getViewMarkerCategories() {
1473 return new ArrayList
<>();
1477 * Gets the list of view-specific markers for a trace in a given time range.
1478 * Default implementation returns an empty list.
1481 * Start of the time range
1483 * End of the time range
1487 * The progress monitor object
1488 * @return The list of marker events
1491 protected @NonNull List
<IMarkerEvent
> getViewMarkerList(long startTime
, long endTime
,
1492 long resolution
, @NonNull IProgressMonitor monitor
) {
1493 return new ArrayList
<>();
1497 * Gets the list of trace-specific markers for a trace in a given time range.
1500 * Start of the time range
1502 * End of the time range
1506 * The progress monitor object
1507 * @return The list of marker events
1510 protected @NonNull List
<IMarkerEvent
> getTraceMarkerList(long startTime
, long endTime
,
1511 long resolution
, @NonNull IProgressMonitor monitor
) {
1512 List
<IMarkerEvent
> markers
= new ArrayList
<>();
1513 for (IMarkerEventSource markerEventSource
: getMarkerEventSources(getTrace())) {
1514 for (String category
: markerEventSource
.getMarkerCategories()) {
1515 if (monitor
.isCanceled()) {
1518 markers
.addAll(markerEventSource
.getMarkerList(checkNotNull(category
), startTime
, endTime
, resolution
, monitor
));
1525 * Get the list of current marker categories.
1527 * @return The list of marker categories
1530 private @NonNull List
<String
> getMarkerCategories() {
1531 Set
<String
> categories
= new HashSet
<>(getViewMarkerCategories());
1532 for (IMarkerEventSource markerEventSource
: getMarkerEventSources(fTrace
)) {
1533 categories
.addAll(markerEventSource
.getMarkerCategories());
1535 return new ArrayList
<>(categories
);
1539 * Gets the list of marker event sources for a given trace.
1543 * @return The list of marker event sources
1546 private @NonNull List
<IMarkerEventSource
> getMarkerEventSources(ITmfTrace trace
) {
1547 List
<IMarkerEventSource
> markerEventSources
= fMarkerEventSourcesMap
.get(trace
);
1548 if (markerEventSources
== null) {
1549 markerEventSources
= checkNotNull(Collections
.<IMarkerEventSource
>emptyList());
1551 return markerEventSources
;
1555 * Refresh the display
1557 protected void refresh() {
1558 final boolean zoomThread
= Thread
.currentThread() instanceof ZoomThread
;
1559 TmfUiRefreshHandler
.getInstance().queueUpdate(this, new Runnable() {
1562 if (fTimeGraphWrapper
.isDisposed()) {
1565 boolean hasEntries
= false;
1566 synchronized (fEntryListMap
) {
1567 fEntryList
= fEntryListMap
.get(fTrace
);
1568 if (fEntryList
== null) {
1569 fEntryList
= new CopyOnWriteArrayList
<>();
1570 } else if (fEntryComparator
!= null) {
1571 List
<TimeGraphEntry
> list
= new ArrayList
<>(fEntryList
);
1572 Collections
.sort(list
, fEntryComparator
);
1574 fEntryList
.addAll(list
);
1576 hasEntries
= fEntryList
.size() != 0;
1578 if (fEntryList
!= fTimeGraphWrapper
.getInput()) {
1579 fTimeGraphWrapper
.setInput(fEntryList
);
1580 /* restore the previously saved filters, if any */
1581 fTimeGraphWrapper
.setFilters(fFiltersMap
.get(fTrace
));
1582 fTimeGraphWrapper
.getTimeGraphViewer().setLinks(null);
1583 fTimeGraphWrapper
.getTimeGraphViewer().setBookmarks(refreshBookmarks(fEditorFile
));
1584 fTimeGraphWrapper
.getTimeGraphViewer().setMarkerCategories(getMarkerCategories());
1586 fTimeGraphWrapper
.refresh();
1588 long startBound
= (fStartTime
== Long
.MAX_VALUE ? SWT
.DEFAULT
: fStartTime
);
1589 long endBound
= (fEndTime
== Long
.MIN_VALUE ? SWT
.DEFAULT
: fEndTime
);
1590 fTimeGraphWrapper
.getTimeGraphViewer().setTimeBounds(startBound
, endBound
);
1592 TmfTraceContext ctx
= TmfTraceManager
.getInstance().getCurrentTraceContext();
1593 long selectionBeginTime
= fTrace
== null ? SWT
.DEFAULT
: ctx
.getSelectionRange().getStartTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
1594 long selectionEndTime
= fTrace
== null ? SWT
.DEFAULT
: ctx
.getSelectionRange().getEndTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
1595 long startTime
= fTrace
== null ? SWT
.DEFAULT
: ctx
.getWindowRange().getStartTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
1596 long endTime
= fTrace
== null ? SWT
.DEFAULT
: ctx
.getWindowRange().getEndTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
1597 startTime
= (fStartTime
== Long
.MAX_VALUE ? SWT
.DEFAULT
: Math
.max(startTime
, fStartTime
));
1598 endTime
= (fEndTime
== Long
.MIN_VALUE ? SWT
.DEFAULT
: Math
.min(endTime
, fEndTime
));
1599 fTimeGraphWrapper
.getTimeGraphViewer().setSelectionRange(selectionBeginTime
, selectionEndTime
);
1600 fTimeGraphWrapper
.getTimeGraphViewer().setStartFinishTime(startTime
, endTime
);
1602 if (fTimeGraphWrapper
instanceof TimeGraphComboWrapper
&& !fPackDone
) {
1603 for (TreeColumn column
: ((TimeGraphComboWrapper
) fTimeGraphWrapper
).getTreeViewer().getTree().getColumns()) {
1612 startZoomThread(startTime
, endTime
);
1621 protected void redraw() {
1622 synchronized (fSyncObj
) {
1623 if (fRedrawState
== State
.IDLE
) {
1624 fRedrawState
= State
.BUSY
;
1626 fRedrawState
= State
.PENDING
;
1630 Display
.getDefault().asyncExec(new Runnable() {
1633 if (fTimeGraphWrapper
.isDisposed()) {
1636 fTimeGraphWrapper
.redraw();
1637 fTimeGraphWrapper
.update();
1638 synchronized (fSyncObj
) {
1639 if (fRedrawState
== State
.PENDING
) {
1640 fRedrawState
= State
.IDLE
;
1643 fRedrawState
= State
.IDLE
;
1650 private void startZoomThread(long startTime
, long endTime
) {
1651 boolean restart
= false;
1652 if (fZoomThread
!= null) {
1653 fZoomThread
.cancel();
1654 if (fZoomThread
.fZoomStartTime
== startTime
&& fZoomThread
.fZoomEndTime
== endTime
) {
1658 long resolution
= Math
.max(1, (endTime
- startTime
) / fDisplayWidth
);
1659 fZoomThread
= createZoomThread(startTime
, endTime
, resolution
, restart
);
1660 if (fZoomThread
!= null) {
1661 fZoomThread
.start();
1666 * Create a zoom thread.
1669 * the zoom start time
1675 * true if restarting zoom for the same time range
1676 * @return a zoom thread
1679 protected @Nullable ZoomThread
createZoomThread(long startTime
, long endTime
, long resolution
, boolean restart
) {
1680 final List
<TimeGraphEntry
> entryList
= fEntryList
;
1681 if (entryList
== null) {
1684 return new ZoomThreadByEntry(entryList
, startTime
, endTime
, resolution
);
1687 private void makeActions() {
1688 fPreviousResourceAction
= fTimeGraphWrapper
.getTimeGraphViewer().getPreviousItemAction();
1689 fPreviousResourceAction
.setText(getPrevText());
1690 fPreviousResourceAction
.setToolTipText(getPrevTooltip());
1691 fNextResourceAction
= fTimeGraphWrapper
.getTimeGraphViewer().getNextItemAction();
1692 fNextResourceAction
.setText(getNextText());
1693 fNextResourceAction
.setToolTipText(getNextTooltip());
1696 private void contributeToActionBars() {
1697 IActionBars bars
= getViewSite().getActionBars();
1698 fillLocalToolBar(bars
.getToolBarManager());
1699 fillLocalMenu(bars
.getMenuManager());
1703 * Add actions to local tool bar manager
1705 * @param manager the tool bar manager
1707 protected void fillLocalToolBar(IToolBarManager manager
) {
1708 if (fFilterColumns
!= null && fFilterLabelProvider
!= null && fFilterColumns
.length
> 0) {
1709 manager
.add(fTimeGraphWrapper
.getShowFilterDialogAction());
1711 manager
.add(fTimeGraphWrapper
.getTimeGraphViewer().getShowLegendAction());
1712 manager
.add(new Separator());
1713 manager
.add(fTimeGraphWrapper
.getTimeGraphViewer().getResetScaleAction());
1714 manager
.add(fTimeGraphWrapper
.getTimeGraphViewer().getPreviousEventAction());
1715 manager
.add(fTimeGraphWrapper
.getTimeGraphViewer().getNextEventAction());
1716 manager
.add(new Separator());
1717 manager
.add(fTimeGraphWrapper
.getTimeGraphViewer().getToggleBookmarkAction());
1718 manager
.add(fTimeGraphWrapper
.getTimeGraphViewer().getPreviousMarkerAction());
1719 manager
.add(fTimeGraphWrapper
.getTimeGraphViewer().getNextMarkerAction());
1720 manager
.add(new Separator());
1721 manager
.add(fPreviousResourceAction
);
1722 manager
.add(fNextResourceAction
);
1723 manager
.add(fTimeGraphWrapper
.getTimeGraphViewer().getZoomInAction());
1724 manager
.add(fTimeGraphWrapper
.getTimeGraphViewer().getZoomOutAction());
1725 manager
.add(new Separator());
1729 * Add actions to local menu manager
1731 * @param manager the tool bar manager
1734 protected void fillLocalMenu(IMenuManager manager
) {
1735 manager
.add(fTimeGraphWrapper
.getTimeGraphViewer().getMarkersMenu());
1742 public TmfTimeViewAlignmentInfo
getTimeViewAlignmentInfo() {
1743 if (fTimeGraphWrapper
== null) {
1746 return fTimeGraphWrapper
.getTimeViewAlignmentInfo();
1753 public int getAvailableWidth(int requestedOffset
) {
1754 if (fTimeGraphWrapper
== null) {
1757 return fTimeGraphWrapper
.getAvailableWidth(requestedOffset
);
1764 public void performAlign(int offset
, int width
) {
1765 if (fTimeGraphWrapper
!= null) {
1766 fTimeGraphWrapper
.performAlign(offset
, width
);