1 /*******************************************************************************
2 * Copyright (c) 2012, 2016 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
.LinkedHashSet
;
26 import java
.util
.List
;
29 import java
.util
.concurrent
.CopyOnWriteArrayList
;
30 import java
.util
.concurrent
.atomic
.AtomicInteger
;
31 import java
.util
.logging
.Logger
;
32 import java
.util
.regex
.Matcher
;
33 import java
.util
.regex
.Pattern
;
35 import org
.eclipse
.core
.resources
.IFile
;
36 import org
.eclipse
.core
.resources
.IMarker
;
37 import org
.eclipse
.core
.resources
.IMarkerDelta
;
38 import org
.eclipse
.core
.resources
.IResource
;
39 import org
.eclipse
.core
.resources
.IResourceChangeEvent
;
40 import org
.eclipse
.core
.resources
.IResourceChangeListener
;
41 import org
.eclipse
.core
.resources
.IWorkspaceRunnable
;
42 import org
.eclipse
.core
.resources
.ResourcesPlugin
;
43 import org
.eclipse
.core
.runtime
.CoreException
;
44 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
45 import org
.eclipse
.core
.runtime
.NullProgressMonitor
;
46 import org
.eclipse
.jdt
.annotation
.NonNull
;
47 import org
.eclipse
.jdt
.annotation
.Nullable
;
48 import org
.eclipse
.jface
.action
.Action
;
49 import org
.eclipse
.jface
.action
.GroupMarker
;
50 import org
.eclipse
.jface
.action
.IAction
;
51 import org
.eclipse
.jface
.action
.IMenuListener
;
52 import org
.eclipse
.jface
.action
.IMenuManager
;
53 import org
.eclipse
.jface
.action
.IStatusLineManager
;
54 import org
.eclipse
.jface
.action
.IToolBarManager
;
55 import org
.eclipse
.jface
.action
.MenuManager
;
56 import org
.eclipse
.jface
.action
.Separator
;
57 import org
.eclipse
.jface
.commands
.ActionHandler
;
58 import org
.eclipse
.jface
.viewers
.AbstractTreeViewer
;
59 import org
.eclipse
.jface
.viewers
.ILabelProvider
;
60 import org
.eclipse
.jface
.viewers
.ILabelProviderListener
;
61 import org
.eclipse
.jface
.viewers
.ISelectionProvider
;
62 import org
.eclipse
.jface
.viewers
.ITableLabelProvider
;
63 import org
.eclipse
.jface
.viewers
.ITreeContentProvider
;
64 import org
.eclipse
.jface
.viewers
.TreeSelection
;
65 import org
.eclipse
.jface
.viewers
.TreeViewer
;
66 import org
.eclipse
.jface
.viewers
.ViewerFilter
;
67 import org
.eclipse
.osgi
.util
.NLS
;
68 import org
.eclipse
.swt
.SWT
;
69 import org
.eclipse
.swt
.events
.MenuDetectEvent
;
70 import org
.eclipse
.swt
.events
.MenuDetectListener
;
71 import org
.eclipse
.swt
.events
.SelectionAdapter
;
72 import org
.eclipse
.swt
.events
.SelectionEvent
;
73 import org
.eclipse
.swt
.graphics
.Image
;
74 import org
.eclipse
.swt
.graphics
.Point
;
75 import org
.eclipse
.swt
.graphics
.RGBA
;
76 import org
.eclipse
.swt
.widgets
.Composite
;
77 import org
.eclipse
.swt
.widgets
.Display
;
78 import org
.eclipse
.swt
.widgets
.Menu
;
79 import org
.eclipse
.swt
.widgets
.Shell
;
80 import org
.eclipse
.swt
.widgets
.Tree
;
81 import org
.eclipse
.swt
.widgets
.TreeColumn
;
82 import org
.eclipse
.tracecompass
.common
.core
.log
.TraceCompassLog
;
83 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.Activator
;
84 import org
.eclipse
.tracecompass
.tmf
.core
.resources
.ITmfMarker
;
85 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfMarkerEventSourceUpdatedSignal
;
86 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfSelectionRangeUpdatedSignal
;
87 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfSignalHandler
;
88 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfTimestampFormatUpdateSignal
;
89 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfTraceClosedSignal
;
90 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfTraceOpenedSignal
;
91 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfTraceSelectedSignal
;
92 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfWindowRangeUpdatedSignal
;
93 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.ITmfTimestamp
;
94 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.TmfTimeRange
;
95 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.TmfTimestamp
;
96 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfTrace
;
97 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.TmfTraceAdapterManager
;
98 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.TmfTraceContext
;
99 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.TmfTraceManager
;
100 import org
.eclipse
.tracecompass
.tmf
.ui
.TmfUiRefreshHandler
;
101 import org
.eclipse
.tracecompass
.tmf
.ui
.signal
.TmfTimeViewAlignmentInfo
;
102 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.ITmfTimeAligned
;
103 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.TmfView
;
104 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.ITimeGraphBookmarkListener
;
105 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.ITimeGraphContentProvider
;
106 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.ITimeGraphPresentationProvider2
;
107 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.ITimeGraphRangeListener
;
108 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.ITimeGraphSelectionListener
;
109 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.ITimeGraphTimeListener
;
110 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.TimeGraphBookmarkEvent
;
111 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.TimeGraphCombo
;
112 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.TimeGraphContentProvider
;
113 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.TimeGraphPresentationProvider
;
114 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.TimeGraphRangeUpdateEvent
;
115 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.TimeGraphTimeEvent
;
116 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.TimeGraphViewer
;
117 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.ILinkEvent
;
118 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.IMarkerEvent
;
119 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.IMarkerEventSource
;
120 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.ITimeEvent
;
121 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.ITimeGraphEntry
;
122 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.MarkerEvent
;
123 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.TimeGraphEntry
;
124 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.widgets
.TimeGraphControl
;
125 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.widgets
.Utils
.TimeFormat
;
126 import org
.eclipse
.ui
.IActionBars
;
127 import org
.eclipse
.ui
.IPartListener
;
128 import org
.eclipse
.ui
.IWorkbenchActionConstants
;
129 import org
.eclipse
.ui
.IWorkbenchPart
;
130 import org
.eclipse
.ui
.PlatformUI
;
131 import org
.eclipse
.ui
.actions
.ActionFactory
;
132 import org
.eclipse
.ui
.handlers
.IHandlerActivation
;
133 import org
.eclipse
.ui
.handlers
.IHandlerService
;
136 * An abstract view all time graph views can inherit
138 * This view contains either a time graph viewer, or a time graph combo which is
139 * divided between a tree viewer on the left and a time graph viewer on the right.
141 public abstract class AbstractTimeGraphView
extends TmfView
implements ITmfTimeAligned
, IResourceChangeListener
{
143 /** Constant indicating that all levels of the time graph should be expanded */
144 protected static final int ALL_LEVELS
= AbstractTreeViewer
.ALL_LEVELS
;
146 private static final Pattern RGBA_PATTERN
= Pattern
.compile("RGBA \\{(\\d+), (\\d+), (\\d+), (\\d+)\\}"); //$NON-NLS-1$
148 private static final Logger LOGGER
= TraceCompassLog
.getLogger(AbstractTimeGraphView
.class);
157 // ------------------------------------------------------------------------
159 // ------------------------------------------------------------------------
161 /** The timegraph wrapper */
162 private ITimeGraphWrapper fTimeGraphWrapper
;
164 private AtomicInteger fDirty
= new AtomicInteger();
166 private final Object fZoomThreadResultLock
= new Object();
168 /** The selected trace */
169 private ITmfTrace fTrace
;
171 /** The selected trace editor file*/
172 private IFile fEditorFile
;
174 /** The timegraph entry list */
175 private List
<TimeGraphEntry
> fEntryList
;
177 /** The trace to entry list hash map */
178 private final Map
<ITmfTrace
, List
<TimeGraphEntry
>> fEntryListMap
= new HashMap
<>();
180 /** The trace to filters hash map */
181 private final Map
<ITmfTrace
, @NonNull ViewerFilter
[]> fFiltersMap
= new HashMap
<>();
183 /** The trace to view context hash map */
184 private final Map
<ITmfTrace
, ViewContext
> fViewContext
= new HashMap
<>();
186 /** The trace to marker event sources hash map */
187 private final Map
<ITmfTrace
, List
<IMarkerEventSource
>> fMarkerEventSourcesMap
= new HashMap
<>();
189 /** The trace to build thread hash map */
190 private final Map
<ITmfTrace
, BuildThread
> fBuildThreadMap
= new HashMap
<>();
192 /** The start time */
193 private long fStartTime
= SWT
.DEFAULT
;
196 private long fEndTime
= SWT
.DEFAULT
;
198 /** The display width */
199 private final int fDisplayWidth
;
201 /** The zoom thread */
202 private ZoomThread fZoomThread
;
204 /** The next resource action */
205 private Action fNextResourceAction
;
207 /** The previous resource action */
208 private Action fPreviousResourceAction
;
210 /** A comparator class */
211 private Comparator
<ITimeGraphEntry
> fEntryComparator
= null;
213 /** The redraw state used to prevent unnecessary queuing of display runnables */
214 private State fRedrawState
= State
.IDLE
;
216 /** The redraw synchronization object */
217 private final Object fSyncObj
= new Object();
219 /** The presentation provider for this view */
220 private final TimeGraphPresentationProvider fPresentation
;
222 /** The tree column label array, or null if combo is not used */
223 private String
[] fColumns
;
225 private Comparator
<ITimeGraphEntry
>[] fColumnComparators
;
227 /** The tree label provider, or null if combo is not used */
228 private TreeLabelProvider fLabelProvider
= null;
230 /** The time graph content provider */
231 private @NonNull ITimeGraphContentProvider fTimeGraphContentProvider
= new TimeGraphContentProvider();
233 /** The relative weight of the sash, ignored if combo is not used */
234 private int[] fWeight
= { 1, 3 };
236 /** The filter column label array, or null if filter is not used */
237 private String
[] fFilterColumns
;
239 /** The pack done flag */
240 private boolean fPackDone
= false;
242 /** The filter content provider, or null if filter is not used */
243 private ITreeContentProvider fFilterContentProvider
;
245 /** The filter label provider, or null if filter is not used */
246 private TreeLabelProvider fFilterLabelProvider
;
248 private int fAutoExpandLevel
= ALL_LEVELS
;
250 /** The default column index for sorting */
251 private int fInitialSortColumn
= 0;
253 /** The default column index for sorting */
254 private int fCurrentSortColumn
= 0;
256 /** The current sort direction */
257 private int fSortDirection
= SWT
.DOWN
;
259 /** Flag to indicate to reveal selection */
260 private volatile boolean fIsRevealSelection
= false;
263 * Menu Manager for context-sensitive menu for time graph entries.
264 * This will be used on the tree viewer in case of the time graph combo
265 * or the on the namespace in case of a single time graph viewer.
267 private final @NonNull MenuManager fEntryMenuManager
= new MenuManager();
269 /** Time Graph View part listener */
270 private TimeGraphPartListener fPartListener
;
272 /** Action for the find command. There is only one for all Time Graph views */
273 private static final ShowFindDialogAction FIND_ACTION
= new ShowFindDialogAction();
275 /** The find action handler */
276 private ActionHandler fFindActionHandler
;
278 /** The find handler activation */
279 private IHandlerActivation fFindHandlerActivation
;
281 /** The find target to use */
282 private final FindTarget fFindTarget
;
284 // ------------------------------------------------------------------------
286 // ------------------------------------------------------------------------
288 private interface ITimeGraphWrapper
{
290 void setTimeGraphContentProvider(ITimeGraphContentProvider timeGraphContentProvider
);
292 void setTimeGraphPresentationProvider(TimeGraphPresentationProvider timeGraphPresentationProvider
);
294 TimeGraphViewer
getTimeGraphViewer();
296 void addSelectionListener(ITimeGraphSelectionListener listener
);
298 ISelectionProvider
getSelectionProvider();
302 boolean isDisposed();
306 void setInput(Object input
);
310 void setFilters(@NonNull ViewerFilter
[] filters
);
312 @NonNull ViewerFilter
[] getFilters();
318 void setAutoExpandLevel(int level
);
320 boolean getExpandedState(ITimeGraphEntry entry
);
322 void setExpandedState(ITimeGraphEntry entry
, boolean expanded
);
324 void setFilterColumns(String
[] columnNames
);
326 void setFilterContentProvider(ITreeContentProvider contentProvider
);
328 void setFilterLabelProvider(ITableLabelProvider labelProvider
);
330 IAction
getShowFilterDialogAction();
332 void performAlign(int offset
, int width
);
334 TmfTimeViewAlignmentInfo
getTimeViewAlignmentInfo();
336 int getAvailableWidth(int requestedOffset
);
338 ITimeGraphEntry
getSelection();
340 void setSelection(ITimeGraphEntry selection
);
342 void selectAndReveal(@NonNull ITimeGraphEntry selection
);
346 private class TimeGraphViewerWrapper
implements ITimeGraphWrapper
{
347 private TimeGraphViewer viewer
;
349 private TimeGraphViewerWrapper(Composite parent
, int style
) {
350 viewer
= new TimeGraphViewer(parent
, style
);
354 public void setTimeGraphContentProvider(ITimeGraphContentProvider timeGraphContentProvider
) {
355 viewer
.setTimeGraphContentProvider(timeGraphContentProvider
);
359 public void setTimeGraphPresentationProvider(TimeGraphPresentationProvider timeGraphPresentationProvider
) {
360 viewer
.setTimeGraphProvider(timeGraphPresentationProvider
);
364 public TimeGraphViewer
getTimeGraphViewer() {
369 public void addSelectionListener(ITimeGraphSelectionListener listener
) {
370 viewer
.addSelectionListener(listener
);
374 public ISelectionProvider
getSelectionProvider() {
375 return viewer
.getSelectionProvider();
379 public void setFocus() {
384 public boolean isDisposed() {
385 return viewer
.getControl().isDisposed();
389 public void setInput(Object input
) {
390 viewer
.setInput(input
);
394 public Object
getInput() {
395 return viewer
.getInput();
399 public void setFilterColumns(String
[] columnNames
) {
400 viewer
.setFilterColumns(columnNames
);
404 public void setFilterContentProvider(ITreeContentProvider contentProvider
) {
405 viewer
.setFilterContentProvider(contentProvider
);
409 public void setFilterLabelProvider(ITableLabelProvider labelProvider
) {
410 viewer
.setFilterLabelProvider(labelProvider
);
414 public void setFilters(@NonNull ViewerFilter
[] filters
) {
415 viewer
.setFilters(filters
);
419 public @NonNull ViewerFilter
[] getFilters() {
420 return viewer
.getFilters();
424 public IAction
getShowFilterDialogAction() {
425 return viewer
.getShowFilterDialogAction();
429 public void refresh() {
434 public void redraw() {
435 viewer
.getControl().redraw();
439 public void update() {
440 viewer
.getControl().update();
444 public void setAutoExpandLevel(int level
) {
445 viewer
.setAutoExpandLevel(level
);
449 public boolean getExpandedState(ITimeGraphEntry entry
) {
450 return viewer
.getExpandedState(entry
);
454 public void setExpandedState(ITimeGraphEntry entry
, boolean expanded
) {
455 viewer
.setExpandedState(entry
, expanded
);
459 public void performAlign(int offset
, int width
) {
460 viewer
.performAlign(offset
, width
);
464 public TmfTimeViewAlignmentInfo
getTimeViewAlignmentInfo() {
465 return viewer
.getTimeViewAlignmentInfo();
469 public int getAvailableWidth(int requestedOffset
) {
470 return viewer
.getAvailableWidth(requestedOffset
);
474 public ITimeGraphEntry
getSelection() {
475 return viewer
.getSelection();
479 public void setSelection(ITimeGraphEntry selection
) {
480 viewer
.setSelection(selection
);
484 public void selectAndReveal(@NonNull ITimeGraphEntry selection
) {
485 viewer
.selectAndReveal(selection
);
489 private class TimeGraphComboWrapper
implements ITimeGraphWrapper
{
490 private TimeGraphCombo combo
;
492 private TimeGraphComboWrapper(Composite parent
, int style
) {
493 combo
= new TimeGraphCombo(parent
, style
, fWeight
);
497 public void setTimeGraphContentProvider(ITimeGraphContentProvider timeGraphContentProvider
) {
498 combo
.setTimeGraphContentProvider(timeGraphContentProvider
);
502 public void setTimeGraphPresentationProvider(TimeGraphPresentationProvider timeGraphPresentationProvider
) {
503 combo
.setTimeGraphProvider(timeGraphPresentationProvider
);
507 public TimeGraphViewer
getTimeGraphViewer() {
508 return combo
.getTimeGraphViewer();
512 public void addSelectionListener(ITimeGraphSelectionListener listener
) {
513 combo
.addSelectionListener(listener
);
517 public ISelectionProvider
getSelectionProvider() {
518 return combo
.getTreeViewer();
522 public void setFocus() {
527 public boolean isDisposed() {
528 return combo
.isDisposed();
532 public void setInput(Object input
) {
533 combo
.setInput(input
);
537 public Object
getInput() {
538 return combo
.getInput();
542 public void setFilterColumns(String
[] columnNames
) {
543 combo
.setFilterColumns(columnNames
);
547 public void setFilterContentProvider(ITreeContentProvider contentProvider
) {
548 combo
.setFilterContentProvider(contentProvider
);
552 public void setFilterLabelProvider(ITableLabelProvider labelProvider
) {
553 combo
.setFilterLabelProvider(labelProvider
);
557 public void setFilters(@NonNull ViewerFilter
[] filters
) {
558 combo
.setFilters(filters
);
562 public @NonNull ViewerFilter
[] getFilters() {
563 return combo
.getFilters();
567 public IAction
getShowFilterDialogAction() {
568 return combo
.getShowFilterDialogAction();
572 public void refresh() {
577 public void redraw() {
582 public void update() {
587 public void setAutoExpandLevel(int level
) {
588 combo
.setAutoExpandLevel(level
);
592 public boolean getExpandedState(ITimeGraphEntry entry
) {
593 return combo
.getExpandedState(entry
);
597 public void setExpandedState(ITimeGraphEntry entry
, boolean expanded
) {
598 combo
.setExpandedState(entry
, expanded
);
601 TimeGraphCombo
getTimeGraphCombo() {
605 TreeViewer
getTreeViewer() {
606 return combo
.getTreeViewer();
610 public void performAlign(int offset
, int width
) {
611 combo
.performAlign(offset
, width
);
615 public TmfTimeViewAlignmentInfo
getTimeViewAlignmentInfo() {
616 return combo
.getTimeViewAlignmentInfo();
620 public int getAvailableWidth(int requestedOffset
) {
621 return combo
.getAvailableWidth(requestedOffset
);
625 public ITimeGraphEntry
getSelection() {
626 return combo
.getTimeGraphViewer().getSelection();
630 public void setSelection(ITimeGraphEntry selection
) {
631 combo
.setSelection(selection
);
635 public void selectAndReveal(@NonNull ITimeGraphEntry selection
) {
636 combo
.selectAndReveal(selection
);
641 * Base class to provide the labels for the tree viewer. Views extending
642 * this class typically need to override the getColumnText method if they
643 * have more than one column to display
645 protected static class TreeLabelProvider
implements ITableLabelProvider
, ILabelProvider
{
648 public void addListener(ILabelProviderListener listener
) {
652 public void dispose() {
656 public boolean isLabelProperty(Object element
, String property
) {
661 public void removeListener(ILabelProviderListener listener
) {
665 public Image
getColumnImage(Object element
, int columnIndex
) {
670 public String
getColumnText(Object element
, int columnIndex
) {
671 TimeGraphEntry entry
= (TimeGraphEntry
) element
;
672 if (columnIndex
== 0) {
673 return entry
.getName();
679 public Image
getImage(Object element
) {
684 public String
getText(Object element
) {
685 TimeGraphEntry entry
= (TimeGraphEntry
) element
;
686 return entry
.getName();
691 private class BuildThread
extends Thread
{
692 private final @NonNull ITmfTrace fBuildTrace
;
693 private final @NonNull ITmfTrace fParentTrace
;
694 private final @NonNull IProgressMonitor fMonitor
;
696 public BuildThread(final @NonNull ITmfTrace trace
, final @NonNull ITmfTrace parentTrace
, final String name
) {
697 super(name
+ " build"); //$NON-NLS-1$
699 fParentTrace
= parentTrace
;
700 fMonitor
= new NullProgressMonitor();
705 LOGGER
.info(() -> "[TimeGraphView:BuildThreadStart] trace=" + fBuildTrace
.getName()); //$NON-NLS-1$
707 buildEntryList(fBuildTrace
, fParentTrace
, fMonitor
);
708 synchronized (fBuildThreadMap
) {
709 fBuildThreadMap
.remove(fBuildTrace
);
712 LOGGER
.info(() -> "[TimeGraphView:BuildThreadEnd]"); //$NON-NLS-1$
715 public void cancel() {
716 fMonitor
.setCanceled(true);
724 protected abstract class ZoomThread
extends Thread
{
725 private final long fZoomStartTime
;
726 private final long fZoomEndTime
;
727 private final long fResolution
;
728 private final @NonNull IProgressMonitor fMonitor
;
740 public ZoomThread(long startTime
, long endTime
, long resolution
) {
741 super(AbstractTimeGraphView
.this.getName() + " zoom"); //$NON-NLS-1$
742 fZoomStartTime
= startTime
;
743 fZoomEndTime
= endTime
;
744 fResolution
= resolution
;
745 fMonitor
= new NullProgressMonitor();
749 * @return the zoom start time
751 public long getZoomStartTime() {
752 return fZoomStartTime
;
756 * @return the zoom end time
758 public long getZoomEndTime() {
763 * @return the resolution
765 public long getResolution() {
770 * @return the monitor
772 public @NonNull IProgressMonitor
getMonitor() {
777 * Cancel the zoom thread
779 public void cancel() {
780 fMonitor
.setCanceled(true);
784 public final void run() {
785 LOGGER
.info(() -> "[TimeGraphView:ZoomThreadStart] start=" + fZoomStartTime
+ ", end=" + fZoomEndTime
); //$NON-NLS-1$ //$NON-NLS-2$
788 fDirty
.decrementAndGet();
790 LOGGER
.info(() -> "[TimeGraphView:ZoomThreadEnd]"); //$NON-NLS-1$
794 * Applies the results of the ZoomThread calculations.
796 * Note: This method makes sure that only the results of the last
797 * created ZoomThread are applied.
800 * the code to run in order to apply the results
803 protected void applyResults(Runnable runnable
) {
804 synchronized (fZoomThreadResultLock
) {
805 if (this == fZoomThread
) {
812 * Run the zoom operation.
815 public abstract void doRun();
818 private class ZoomThreadByEntry
extends ZoomThread
{
819 private final @NonNull List
<TimeGraphEntry
> fZoomEntryList
;
821 public ZoomThreadByEntry(@NonNull List
<TimeGraphEntry
> entryList
, long startTime
, long endTime
, long resolution
) {
822 super(startTime
, endTime
, resolution
);
823 fZoomEntryList
= entryList
;
827 public void doRun() {
828 LOGGER
.config(() -> "[TimeGraphView:ZoomThreadGettingStates]"); //$NON-NLS-1$
830 for (TimeGraphEntry entry
: fZoomEntryList
) {
831 if (getMonitor().isCanceled()) {
832 LOGGER
.info(() -> "[TimeGraphView:ZoomThreadCanceled]"); //$NON-NLS-1$
838 zoom(entry
, getMonitor());
840 /* Refresh the arrows when zooming */
841 LOGGER
.config(() -> "[TimeGraphView:ZoomThreadGettingLinks]"); //$NON-NLS-1$
842 List
<ILinkEvent
> events
= getLinkList(getZoomStartTime(), getZoomEndTime(), getResolution(), getMonitor());
844 /* Refresh the view-specific markers when zooming */
845 LOGGER
.config(() -> "[TimeGraphView:ZoomThreadGettingMarkers]"); //$NON-NLS-1$
846 List
<IMarkerEvent
> markers
= new ArrayList
<>(getViewMarkerList(getZoomStartTime(), getZoomEndTime(), getResolution(), getMonitor()));
847 /* Refresh the trace-specific markers when zooming */
848 markers
.addAll(getTraceMarkerList(getZoomStartTime(), getZoomEndTime(), getResolution(), getMonitor()));
850 if (events
!= null) {
851 fTimeGraphWrapper
.getTimeGraphViewer().setLinks(events
);
853 fTimeGraphWrapper
.getTimeGraphViewer().setMarkerCategories(getMarkerCategories());
854 fTimeGraphWrapper
.getTimeGraphViewer().setMarkers(markers
);
859 private void zoom(@NonNull TimeGraphEntry entry
, @NonNull IProgressMonitor monitor
) {
860 if (getZoomStartTime() <= fStartTime
&& getZoomEndTime() >= fEndTime
) {
862 entry
.setZoomedEventList(null);
865 List
<ITimeEvent
> zoomedEventList
= getEventList(entry
, getZoomStartTime(), getZoomEndTime(), getResolution(), monitor
);
866 if (zoomedEventList
!= null) {
868 entry
.setZoomedEventList(zoomedEventList
);
873 for (TimeGraphEntry child
: entry
.getChildren()) {
874 if (monitor
.isCanceled()) {
877 zoom(child
, monitor
);
883 // ------------------------------------------------------------------------
885 // ------------------------------------------------------------------------
888 * Constructs a time graph view that contains either a time graph viewer or
889 * a time graph combo.
891 * By default, the view uses a time graph viewer. To use a time graph combo,
892 * the subclass constructor must call {@link #setTreeColumns(String[])} and
893 * {@link #setTreeLabelProvider(TreeLabelProvider)}.
898 * The presentation provider
900 public AbstractTimeGraphView(String id
, TimeGraphPresentationProvider pres
) {
902 fPresentation
= pres
;
903 fDisplayWidth
= Display
.getDefault().getBounds().width
;
904 fFindTarget
= new FindTarget();
907 // ------------------------------------------------------------------------
908 // Getters and setters
909 // ------------------------------------------------------------------------
912 * Getter for the time graph combo
914 * @return The time graph combo, or null if combo is not used
916 protected TimeGraphCombo
getTimeGraphCombo() {
917 if (fTimeGraphWrapper
instanceof TimeGraphComboWrapper
) {
918 return ((TimeGraphComboWrapper
) fTimeGraphWrapper
).getTimeGraphCombo();
924 * Getter for the time graph viewer
926 * @return The time graph viewer
928 protected TimeGraphViewer
getTimeGraphViewer() {
929 return fTimeGraphWrapper
.getTimeGraphViewer();
933 * Getter for the presentation provider
935 * @return The time graph presentation provider
937 protected ITimeGraphPresentationProvider2
getPresentationProvider() {
938 return fPresentation
;
942 * Sets the tree column labels.
944 * This should be called from the constructor.
947 * The array of tree column labels
949 protected void setTreeColumns(final String
[] columns
) {
950 setTreeColumns(columns
, null, 0);
954 * Sets the tree column labels.
956 * This should be called from the constructor.
959 * The array of tree column labels
961 * An array of column comparators for sorting of columns when
962 * clicking on column header
963 * @param initialSortColumn
964 * Index of column to sort initially
967 protected void setTreeColumns(final String
[] columns
, final Comparator
<ITimeGraphEntry
>[] comparators
, int initialSortColumn
) {
968 checkPartNotCreated();
970 fColumnComparators
= comparators
;
971 fInitialSortColumn
= initialSortColumn
;
975 * Sets the tree label provider.
977 * This should be called from the constructor.
980 * The tree label provider
982 protected void setTreeLabelProvider(final TreeLabelProvider tlp
) {
983 checkPartNotCreated();
984 fLabelProvider
= tlp
;
988 * Sets the time graph content provider.
990 * This should be called from the constructor.
993 * The time graph content provider
996 protected void setTimeGraphContentProvider(final @NonNull ITimeGraphContentProvider tgcp
) {
997 checkPartNotCreated();
998 fTimeGraphContentProvider
= tgcp
;
1002 * Sets the relative weight of each part of the time graph combo.
1004 * This should be called from the constructor.
1007 * The array (length 2) of relative weights of each part of the combo
1009 protected void setWeight(final int[] weights
) {
1010 checkPartNotCreated();
1015 * Sets the filter column labels.
1017 * This should be called from the constructor.
1019 * @param filterColumns
1020 * The array of filter column labels
1022 protected void setFilterColumns(final String
[] filterColumns
) {
1023 checkPartNotCreated();
1024 fFilterColumns
= filterColumns
;
1028 * Sets the filter content provider.
1030 * This should be called from the constructor.
1032 * @param contentProvider
1033 * The filter content provider
1036 protected void setFilterContentProvider(final ITreeContentProvider contentProvider
) {
1037 checkPartNotCreated();
1038 fFilterContentProvider
= contentProvider
;
1042 * Sets the filter label provider.
1044 * This should be called from the constructor.
1046 * @param labelProvider
1047 * The filter label provider
1049 protected void setFilterLabelProvider(final TreeLabelProvider labelProvider
) {
1050 checkPartNotCreated();
1051 fFilterLabelProvider
= labelProvider
;
1054 private void checkPartNotCreated() {
1055 if (getParentComposite() != null) {
1056 throw new IllegalStateException("This method must be called before createPartControl."); //$NON-NLS-1$
1061 * Gets the display width
1063 * @return the display width
1065 protected int getDisplayWidth() {
1066 return fDisplayWidth
;
1070 * Gets the comparator for the entries
1072 * @return The entry comparator
1074 protected Comparator
<ITimeGraphEntry
> getEntryComparator() {
1075 return fEntryComparator
;
1079 * Sets the comparator class for the entries.
1081 * This comparator will apply recursively to entries that implement
1082 * {@link TimeGraphEntry#sortChildren(Comparator)}.
1085 * A comparator object
1087 protected void setEntryComparator(final Comparator
<ITimeGraphEntry
> comparator
) {
1088 fEntryComparator
= comparator
;
1092 * Gets the trace displayed in the view
1096 protected ITmfTrace
getTrace() {
1101 * Gets the start time
1103 * @return The start time
1105 protected long getStartTime() {
1110 * Sets the start time
1115 protected void setStartTime(long time
) {
1122 * @return The end time
1124 protected long getEndTime() {
1134 protected void setEndTime(long time
) {
1139 * Sets the auto-expand level to be used for the input of the view. The
1140 * value 0 means that there is no auto-expand; 1 means that top-level
1141 * elements are expanded, but not their children; 2 means that top-level
1142 * elements are expanded, and their children, but not grand-children; and so
1145 * The value {@link #ALL_LEVELS} means that all subtrees should be expanded.
1149 * non-negative level, or <code>ALL_LEVELS</code> to expand all
1150 * levels of the tree
1152 protected void setAutoExpandLevel(int level
) {
1153 fAutoExpandLevel
= level
;
1154 ITimeGraphWrapper tgWrapper
= fTimeGraphWrapper
;
1155 if (tgWrapper
!= null) {
1156 tgWrapper
.setAutoExpandLevel(level
);
1161 * Gets the entry list for a trace
1166 * @return the entry list map
1168 protected List
<TimeGraphEntry
> getEntryList(ITmfTrace trace
) {
1169 synchronized (fEntryListMap
) {
1170 return fEntryListMap
.get(trace
);
1175 * Adds a trace entry list to the entry list map
1180 * the list of time graph entries
1182 protected void putEntryList(ITmfTrace trace
, List
<TimeGraphEntry
> list
) {
1183 synchronized (fEntryListMap
) {
1184 fEntryListMap
.put(trace
, new CopyOnWriteArrayList
<>(list
));
1189 * Adds a list of entries to a trace's entry list
1194 * the list of time graph entries to add
1196 protected void addToEntryList(ITmfTrace trace
, List
<TimeGraphEntry
> list
) {
1197 synchronized (fEntryListMap
) {
1198 List
<TimeGraphEntry
> entryList
= fEntryListMap
.get(trace
);
1199 if (entryList
== null) {
1200 fEntryListMap
.put(trace
, new CopyOnWriteArrayList
<>(list
));
1202 entryList
.addAll(list
);
1208 * Removes a list of entries from a trace's entry list
1213 * the list of time graph entries to remove
1215 protected void removeFromEntryList(ITmfTrace trace
, List
<TimeGraphEntry
> list
) {
1216 synchronized (fEntryListMap
) {
1217 List
<TimeGraphEntry
> entryList
= fEntryListMap
.get(trace
);
1218 if (entryList
!= null) {
1219 entryList
.removeAll(list
);
1225 * Text for the "next" button
1227 * @return The "next" button text
1229 protected String
getNextText() {
1230 return Messages
.AbstractTimeGraphtView_NextText
;
1234 * Tooltip for the "next" button
1236 * @return Tooltip for the "next" button
1238 protected String
getNextTooltip() {
1239 return Messages
.AbstractTimeGraphView_NextTooltip
;
1243 * Text for the "Previous" button
1245 * @return The "Previous" button text
1247 protected String
getPrevText() {
1248 return Messages
.AbstractTimeGraphView_PreviousText
;
1252 * Tooltip for the "previous" button
1254 * @return Tooltip for the "previous" button
1256 protected String
getPrevTooltip() {
1257 return Messages
.AbstractTimeGraphView_PreviousTooltip
;
1261 FindTarget
getFindTarget() {
1265 // ------------------------------------------------------------------------
1267 // ------------------------------------------------------------------------
1270 public void createPartControl(Composite parent
) {
1271 super.createPartControl(parent
);
1272 if (fColumns
== null || fLabelProvider
== null) {
1273 fTimeGraphWrapper
= new TimeGraphViewerWrapper(parent
, SWT
.NONE
);
1275 TimeGraphComboWrapper wrapper
= new TimeGraphComboWrapper(parent
, SWT
.NONE
);
1276 fTimeGraphWrapper
= wrapper
;
1277 TimeGraphCombo combo
= wrapper
.getTimeGraphCombo();
1278 combo
.setTreeContentProvider(fTimeGraphContentProvider
);
1279 combo
.setTreeLabelProvider(fLabelProvider
);
1280 combo
.setTreeColumns(fColumns
);
1281 if (fColumnComparators
!= null) {
1282 createColumnSelectionListener(combo
.getTreeViewer());
1284 // Add double click listener to tree viewer
1285 createDoubleClickListener(combo
.getTreeViewer());
1287 fTimeGraphWrapper
.setTimeGraphContentProvider(fTimeGraphContentProvider
);
1288 fTimeGraphWrapper
.setFilterContentProvider(fFilterContentProvider
!= null ? fFilterContentProvider
: fTimeGraphContentProvider
);
1289 fTimeGraphWrapper
.setFilterLabelProvider(fFilterLabelProvider
);
1290 fTimeGraphWrapper
.setFilterColumns(fFilterColumns
);
1292 fTimeGraphWrapper
.setTimeGraphPresentationProvider(fPresentation
);
1293 fTimeGraphWrapper
.setAutoExpandLevel(fAutoExpandLevel
);
1295 fTimeGraphWrapper
.getTimeGraphViewer().addRangeListener(new ITimeGraphRangeListener() {
1297 public void timeRangeUpdated(TimeGraphRangeUpdateEvent event
) {
1298 final long startTime
= event
.getStartTime();
1299 final long endTime
= event
.getEndTime();
1300 TmfTimeRange range
= new TmfTimeRange(TmfTimestamp
.fromNanos(startTime
), TmfTimestamp
.fromNanos(endTime
));
1301 broadcast(new TmfWindowRangeUpdatedSignal(AbstractTimeGraphView
.this, range
));
1302 startZoomThread(startTime
, endTime
);
1306 fTimeGraphWrapper
.getTimeGraphViewer().addTimeListener(new ITimeGraphTimeListener() {
1308 public void timeSelected(TimeGraphTimeEvent event
) {
1309 ITmfTimestamp startTime
= TmfTimestamp
.fromNanos(event
.getBeginTime());
1310 ITmfTimestamp endTime
= TmfTimestamp
.fromNanos(event
.getEndTime());
1311 broadcast(new TmfSelectionRangeUpdatedSignal(AbstractTimeGraphView
.this, startTime
, endTime
));
1315 fTimeGraphWrapper
.getTimeGraphViewer().addBookmarkListener(new ITimeGraphBookmarkListener() {
1317 public void bookmarkAdded(final TimeGraphBookmarkEvent event
) {
1319 ResourcesPlugin
.getWorkspace().run(new IWorkspaceRunnable() {
1321 public void run(IProgressMonitor monitor
) throws CoreException
{
1322 IMarkerEvent bookmark
= event
.getBookmark();
1323 IMarker marker
= fEditorFile
.createMarker(IMarker
.BOOKMARK
);
1324 marker
.setAttribute(IMarker
.MESSAGE
, bookmark
.getLabel());
1325 marker
.setAttribute(ITmfMarker
.MARKER_TIME
, Long
.toString(bookmark
.getTime()));
1326 if (bookmark
.getDuration() > 0) {
1327 marker
.setAttribute(ITmfMarker
.MARKER_DURATION
, Long
.toString(bookmark
.getDuration()));
1328 marker
.setAttribute(IMarker
.LOCATION
,
1329 NLS
.bind(org
.eclipse
.tracecompass
.internal
.tmf
.ui
.Messages
.TmfMarker_LocationTimeRange
,
1330 TmfTimestamp
.fromNanos(bookmark
.getTime()),
1331 TmfTimestamp
.fromNanos(bookmark
.getTime() + bookmark
.getDuration())));
1333 marker
.setAttribute(IMarker
.LOCATION
,
1334 NLS
.bind(org
.eclipse
.tracecompass
.internal
.tmf
.ui
.Messages
.TmfMarker_LocationTime
,
1335 TmfTimestamp
.fromNanos(bookmark
.getTime())));
1337 marker
.setAttribute(ITmfMarker
.MARKER_COLOR
, bookmark
.getColor().toString());
1340 } catch (CoreException e
) {
1341 Activator
.getDefault().logError(e
.getMessage());
1346 public void bookmarkRemoved(TimeGraphBookmarkEvent event
) {
1348 IMarkerEvent bookmark
= event
.getBookmark();
1349 IMarker
[] markers
= fEditorFile
.findMarkers(IMarker
.BOOKMARK
, false, IResource
.DEPTH_ZERO
);
1350 for (IMarker marker
: markers
) {
1351 if (bookmark
.getLabel().equals(marker
.getAttribute(IMarker
.MESSAGE
)) &&
1352 Long
.toString(bookmark
.getTime()).equals(marker
.getAttribute(ITmfMarker
.MARKER_TIME
, (String
) null)) &&
1353 Long
.toString(bookmark
.getDuration()).equals(marker
.getAttribute(ITmfMarker
.MARKER_DURATION
, Long
.toString(0))) &&
1354 bookmark
.getColor().toString().equals(marker
.getAttribute(ITmfMarker
.MARKER_COLOR
))) {
1359 } catch (CoreException e
) {
1360 Activator
.getDefault().logError(e
.getMessage());
1365 fTimeGraphWrapper
.getTimeGraphViewer().setTimeFormat(TimeFormat
.CALENDAR
);
1367 IStatusLineManager statusLineManager
= getViewSite().getActionBars().getStatusLineManager();
1368 fTimeGraphWrapper
.getTimeGraphViewer().getTimeGraphControl().setStatusLineManager(statusLineManager
);
1370 // View Action Handling
1372 contributeToActionBars();
1374 ITmfTrace trace
= TmfTraceManager
.getInstance().getActiveTrace();
1375 if (trace
!= null) {
1376 traceSelected(new TmfTraceSelectedSignal(this, trace
));
1379 // make selection available to other views
1380 getSite().setSelectionProvider(fTimeGraphWrapper
.getSelectionProvider());
1382 ResourcesPlugin
.getWorkspace().addResourceChangeListener(this, IResourceChangeEvent
.POST_CHANGE
);
1384 createContextMenu();
1385 fPartListener
= new TimeGraphPartListener();
1386 getSite().getPage().addPartListener(fPartListener
);
1390 public void setFocus() {
1391 fTimeGraphWrapper
.setFocus();
1395 public void dispose() {
1397 synchronized (fBuildThreadMap
) {
1398 fBuildThreadMap
.values().forEach(buildThread
-> {
1399 buildThread
.cancel();
1402 if (fZoomThread
!= null) {
1403 fZoomThread
.cancel();
1405 ResourcesPlugin
.getWorkspace().removeResourceChangeListener(this);
1406 getSite().getPage().removePartListener(fPartListener
);
1413 public void resourceChanged(final IResourceChangeEvent event
) {
1414 for (final IMarkerDelta delta
: event
.findMarkerDeltas(IMarker
.BOOKMARK
, false)) {
1415 if (delta
.getResource().equals(fEditorFile
)) {
1416 fTimeGraphWrapper
.getTimeGraphViewer().setBookmarks(refreshBookmarks(fEditorFile
));
1423 private static List
<IMarkerEvent
> refreshBookmarks(final IFile editorFile
) {
1424 List
<IMarkerEvent
> bookmarks
= new ArrayList
<>();
1425 if (editorFile
== null || !editorFile
.exists()) {
1429 IMarker
[] markers
= editorFile
.findMarkers(IMarker
.BOOKMARK
, false, IResource
.DEPTH_ZERO
);
1430 for (IMarker marker
: markers
) {
1431 String label
= marker
.getAttribute(IMarker
.MESSAGE
, (String
) null);
1432 String time
= marker
.getAttribute(ITmfMarker
.MARKER_TIME
, (String
) null);
1433 String duration
= marker
.getAttribute(ITmfMarker
.MARKER_DURATION
, Long
.toString(0));
1434 String rgba
= marker
.getAttribute(ITmfMarker
.MARKER_COLOR
, (String
) null);
1435 if (label
!= null && time
!= null && rgba
!= null) {
1436 Matcher matcher
= RGBA_PATTERN
.matcher(rgba
);
1437 if (matcher
.matches()) {
1439 int red
= Integer
.valueOf(matcher
.group(1));
1440 int green
= Integer
.valueOf(matcher
.group(2));
1441 int blue
= Integer
.valueOf(matcher
.group(3));
1442 int alpha
= Integer
.valueOf(matcher
.group(4));
1443 RGBA color
= new RGBA(red
, green
, blue
, alpha
);
1444 bookmarks
.add(new MarkerEvent(null, Long
.valueOf(time
), Long
.valueOf(duration
), IMarkerEvent
.BOOKMARKS
, color
, label
, true));
1445 } catch (NumberFormatException e
) {
1446 Activator
.getDefault().logError(e
.getMessage());
1451 } catch (CoreException e
) {
1452 Activator
.getDefault().logError(e
.getMessage());
1459 // ------------------------------------------------------------------------
1461 // ------------------------------------------------------------------------
1464 * Handler for the trace opened signal.
1467 * The incoming signal
1470 public void traceOpened(TmfTraceOpenedSignal signal
) {
1471 loadTrace(signal
.getTrace());
1475 * Handler for the trace selected signal
1478 * The incoming signal
1481 public void traceSelected(final TmfTraceSelectedSignal signal
) {
1482 if (signal
.getTrace() == fTrace
) {
1485 loadTrace(signal
.getTrace());
1489 * Trace is closed: clear the data structures and the view
1492 * the signal received
1495 public void traceClosed(final TmfTraceClosedSignal signal
) {
1496 resetView(signal
.getTrace());
1497 if (signal
.getTrace() == fTrace
) {
1500 setStartTime(SWT
.DEFAULT
);
1501 setEndTime(SWT
.DEFAULT
);
1507 * Handler for the selection range signal.
1510 * The signal that's received
1514 public void selectionRangeUpdated(final TmfSelectionRangeUpdatedSignal signal
) {
1515 if (signal
.getSource() == this || fTrace
== null) {
1518 final long beginTime
= signal
.getBeginTime().toNanos();
1519 final long endTime
= signal
.getEndTime().toNanos();
1521 Display
.getDefault().asyncExec(new Runnable() {
1524 if (fTimeGraphWrapper
.isDisposed()) {
1527 if (beginTime
== endTime
) {
1528 fTimeGraphWrapper
.getTimeGraphViewer().setSelectedTime(beginTime
, true);
1530 fTimeGraphWrapper
.getTimeGraphViewer().setSelectionRange(beginTime
, endTime
, true);
1532 synchingToTime(fTimeGraphWrapper
.getTimeGraphViewer().getSelectionBegin());
1538 * Handler for the window range signal.
1541 * The signal that's received
1545 public void windowRangeUpdated(final TmfWindowRangeUpdatedSignal signal
) {
1546 if (signal
.getSource() == this || fTrace
== null) {
1549 if (signal
.getCurrentRange().getIntersection(fTrace
.getTimeRange()) == null) {
1552 final long startTime
= signal
.getCurrentRange().getStartTime().toNanos();
1553 final long endTime
= signal
.getCurrentRange().getEndTime().toNanos();
1554 Display
.getDefault().asyncExec(new Runnable() {
1557 if (fTimeGraphWrapper
.isDisposed()) {
1560 fTimeGraphWrapper
.getTimeGraphViewer().setStartFinishTime(startTime
, endTime
);
1561 startZoomThread(startTime
, endTime
);
1567 * @param signal the format of the timestamps was updated.
1570 public void updateTimeFormat( final TmfTimestampFormatUpdateSignal signal
){
1571 fTimeGraphWrapper
.refresh();
1575 * A marker event source has been updated
1582 public void markerEventSourceUpdated(final TmfMarkerEventSourceUpdatedSignal signal
) {
1583 getTimeGraphViewer().setMarkerCategories(getMarkerCategories());
1584 getTimeGraphViewer().setMarkers(null);
1588 // ------------------------------------------------------------------------
1590 // ------------------------------------------------------------------------
1592 private void loadTrace(final ITmfTrace trace
) {
1593 if (fZoomThread
!= null) {
1594 fZoomThread
.cancel();
1597 if (fTrace
!= null) {
1598 /* save the filters of the previous trace */
1599 fFiltersMap
.put(fTrace
, fTimeGraphWrapper
.getFilters());
1600 fViewContext
.put(fTrace
, new ViewContext(fCurrentSortColumn
, fSortDirection
, fTimeGraphWrapper
.getSelection()));
1604 LOGGER
.info(() -> "[TimeGraphView:LoadingTrace] trace=" + trace
.getName()); //$NON-NLS-1$
1606 restoreViewContext();
1607 fEditorFile
= TmfTraceManager
.getInstance().getTraceEditorFile(trace
);
1608 synchronized (fEntryListMap
) {
1609 fEntryList
= fEntryListMap
.get(fTrace
);
1610 if (fEntryList
== null) {
1613 setStartTime(fTrace
.getStartTime().toNanos());
1614 setEndTime(fTrace
.getEndTime().toNanos());
1621 * Forces a rebuild of the entries list, even if entries already exist for this trace
1623 protected void rebuild() {
1624 setStartTime(Long
.MAX_VALUE
);
1625 setEndTime(Long
.MIN_VALUE
);
1627 ITmfTrace viewTrace
= fTrace
;
1628 if (viewTrace
== null) {
1631 resetView(viewTrace
);
1633 List
<IMarkerEventSource
> markerEventSources
= new ArrayList
<>();
1634 synchronized (fBuildThreadMap
) {
1635 for (ITmfTrace trace
: getTracesToBuild(viewTrace
)) {
1636 if (trace
== null) {
1639 markerEventSources
.addAll(TmfTraceAdapterManager
.getAdapters(trace
, IMarkerEventSource
.class));
1640 BuildThread buildThread
= new BuildThread(trace
, viewTrace
, getName());
1641 fBuildThreadMap
.put(trace
, buildThread
);
1642 buildThread
.start();
1645 fMarkerEventSourcesMap
.put(viewTrace
, markerEventSources
);
1649 * Method called when synching to a given timestamp. Inheriting classes can
1650 * perform actions here to update the view at the given timestamp.
1653 * The currently selected time
1655 protected void synchingToTime(long time
) {
1660 * Return the list of traces whose data or analysis results will be used to
1661 * populate the view. By default, if the trace is an experiment, the traces
1662 * under it will be returned, otherwise, the trace itself is returned.
1664 * A build thread will be started for each trace returned by this method,
1665 * some of which may receive events in live streaming mode.
1668 * The trace associated with this view, can be null
1669 * @return List of traces with data to display
1671 protected @NonNull Iterable
<ITmfTrace
> getTracesToBuild(@Nullable ITmfTrace trace
) {
1672 return TmfTraceManager
.getTraceSet(trace
);
1676 * Build the entry list to show in this time graph view.
1678 * Called from the BuildThread for each trace returned by
1679 * {@link #getTracesToBuild(ITmfTrace)}. The full event list is also
1680 * normally computed for every entry that is created.
1683 * The trace being built
1684 * @param parentTrace
1685 * The parent of the trace set, or the trace itself
1687 * The progress monitor object
1690 protected abstract void buildEntryList(@NonNull ITmfTrace trace
, @NonNull ITmfTrace parentTrace
, @NonNull IProgressMonitor monitor
);
1693 * Gets the list of event for an entry in a given time range.
1695 * Called from the ZoomThread for every entry to update the zoomed event
1696 * list. Can be an empty implementation if the view does not support zoomed
1697 * event lists. Can also be used to compute the full event list.
1700 * The entry to get events for
1702 * Start of the time range
1704 * End of the time range
1708 * The progress monitor object
1709 * @return The list of events for the entry
1711 protected abstract @Nullable List
<@NonNull ITimeEvent
> getEventList(@NonNull TimeGraphEntry entry
,
1712 long startTime
, long endTime
, long resolution
,
1713 @NonNull IProgressMonitor monitor
);
1716 * Gets the list of links (displayed as arrows) for a trace in a given
1717 * timerange. Default implementation returns an empty list.
1720 * Start of the time range
1722 * End of the time range
1726 * The progress monitor object
1727 * @return The list of link events
1729 protected @Nullable List
<@NonNull ILinkEvent
> getLinkList(long startTime
, long endTime
,
1730 long resolution
, @NonNull IProgressMonitor monitor
) {
1731 return new ArrayList
<>();
1735 * Gets the list of view-specific marker categories. Default implementation
1736 * returns an empty list.
1738 * @return The list of marker categories
1741 protected @NonNull List
<String
> getViewMarkerCategories() {
1742 return new ArrayList
<>();
1746 * Gets the list of view-specific markers for a trace in a given time range.
1747 * Default implementation returns an empty list.
1750 * Start of the time range
1752 * End of the time range
1756 * The progress monitor object
1757 * @return The list of marker events
1760 protected @NonNull List
<IMarkerEvent
> getViewMarkerList(long startTime
, long endTime
,
1761 long resolution
, @NonNull IProgressMonitor monitor
) {
1762 return new ArrayList
<>();
1766 * Gets the list of trace-specific markers for a trace in a given time range.
1769 * Start of the time range
1771 * End of the time range
1775 * The progress monitor object
1776 * @return The list of marker events
1779 protected @NonNull List
<IMarkerEvent
> getTraceMarkerList(long startTime
, long endTime
,
1780 long resolution
, @NonNull IProgressMonitor monitor
) {
1781 List
<IMarkerEvent
> markers
= new ArrayList
<>();
1782 for (IMarkerEventSource markerEventSource
: getMarkerEventSources(fTrace
)) {
1783 for (String category
: markerEventSource
.getMarkerCategories()) {
1784 if (monitor
.isCanceled()) {
1787 markers
.addAll(markerEventSource
.getMarkerList(category
, startTime
, endTime
, resolution
, monitor
));
1794 * Get the list of current marker categories.
1796 * @return The list of marker categories
1799 protected @NonNull List
<String
> getMarkerCategories() {
1800 Set
<String
> categories
= new LinkedHashSet
<>(getViewMarkerCategories());
1801 for (IMarkerEventSource markerEventSource
: getMarkerEventSources(fTrace
)) {
1802 categories
.addAll(markerEventSource
.getMarkerCategories());
1804 return new ArrayList
<>(categories
);
1808 * Gets the list of marker event sources for a given trace.
1812 * @return The list of marker event sources
1815 private @NonNull List
<IMarkerEventSource
> getMarkerEventSources(ITmfTrace trace
) {
1816 List
<IMarkerEventSource
> markerEventSources
= fMarkerEventSourcesMap
.get(trace
);
1817 if (markerEventSources
== null) {
1818 markerEventSources
= Collections
.emptyList();
1820 return markerEventSources
;
1824 * Refresh the display
1826 protected void refresh() {
1827 LOGGER
.info(() -> "[TimeGraphView:RefreshRequested]"); //$NON-NLS-1$
1828 final boolean zoomThread
= Thread
.currentThread() instanceof ZoomThread
;
1829 TmfUiRefreshHandler
.getInstance().queueUpdate(this, new Runnable() {
1832 LOGGER
.info(() -> "[TimeGraphView:RefreshStart]"); //$NON-NLS-1$
1833 if (fTimeGraphWrapper
.isDisposed()) {
1836 fDirty
.incrementAndGet();
1838 boolean hasEntries
= false;
1839 synchronized (fEntryListMap
) {
1840 fEntryList
= fEntryListMap
.get(fTrace
);
1841 if (fEntryList
== null) {
1842 fEntryList
= new CopyOnWriteArrayList
<>();
1843 } else if (fEntryComparator
!= null) {
1844 List
<TimeGraphEntry
> list
= new ArrayList
<>(fEntryList
);
1845 Collections
.sort(list
, fEntryComparator
);
1846 for (ITimeGraphEntry entry
: list
) {
1847 sortChildren(entry
, fEntryComparator
);
1850 fEntryList
.addAll(list
);
1852 hasEntries
= !fEntryList
.isEmpty();
1854 boolean inputChanged
= fEntryList
!= fTimeGraphWrapper
.getInput();
1855 TimeGraphCombo combo
= getTimeGraphCombo();
1857 // Set redraw to false to only draw once
1858 if (combo
!= null) {
1859 combo
.getTreeViewer().getTree().setRedraw(false);
1861 getTimeGraphViewer().getTimeGraphControl().setRedraw(false);
1863 fTimeGraphWrapper
.setInput(fEntryList
);
1864 /* restore the previously saved filters, if any */
1865 fTimeGraphWrapper
.setFilters(fFiltersMap
.get(fTrace
));
1866 fTimeGraphWrapper
.getTimeGraphViewer().setLinks(null);
1867 fTimeGraphWrapper
.getTimeGraphViewer().setBookmarks(refreshBookmarks(fEditorFile
));
1868 fTimeGraphWrapper
.getTimeGraphViewer().setMarkerCategories(getMarkerCategories());
1869 fTimeGraphWrapper
.getTimeGraphViewer().setMarkers(null);
1872 fTimeGraphWrapper
.refresh();
1875 if (fIsRevealSelection
) {
1876 fIsRevealSelection
= false;
1877 ITimeGraphEntry entry1
= fTimeGraphWrapper
.getSelection();
1878 fTimeGraphWrapper
.setSelection(entry1
);
1881 if (combo
!= null) {
1882 combo
.getTreeViewer().getTree().setRedraw(true);
1884 getTimeGraphViewer().getTimeGraphControl().setRedraw(true);
1886 long startBound
= (fStartTime
== Long
.MAX_VALUE ? SWT
.DEFAULT
: fStartTime
);
1887 long endBound
= (fEndTime
== Long
.MIN_VALUE ? SWT
.DEFAULT
: fEndTime
);
1888 fTimeGraphWrapper
.getTimeGraphViewer().setTimeBounds(startBound
, endBound
);
1890 TmfTraceContext ctx
= TmfTraceManager
.getInstance().getCurrentTraceContext();
1891 long selectionBeginTime
= fTrace
== null ? SWT
.DEFAULT
: ctx
.getSelectionRange().getStartTime().toNanos();
1892 long selectionEndTime
= fTrace
== null ? SWT
.DEFAULT
: ctx
.getSelectionRange().getEndTime().toNanos();
1893 long startTime
= fTrace
== null ? SWT
.DEFAULT
: ctx
.getWindowRange().getStartTime().toNanos();
1894 long endTime
= fTrace
== null ? SWT
.DEFAULT
: ctx
.getWindowRange().getEndTime().toNanos();
1895 startTime
= (fStartTime
== Long
.MAX_VALUE ? SWT
.DEFAULT
: Math
.max(startTime
, fStartTime
));
1896 endTime
= (fEndTime
== Long
.MIN_VALUE ? SWT
.DEFAULT
: Math
.min(endTime
, fEndTime
));
1897 fTimeGraphWrapper
.getTimeGraphViewer().setSelectionRange(selectionBeginTime
, selectionEndTime
, false);
1898 fTimeGraphWrapper
.getTimeGraphViewer().setStartFinishTime(startTime
, endTime
);
1900 if (inputChanged
&& selectionBeginTime
!= SWT
.DEFAULT
) {
1901 synchingToTime(selectionBeginTime
);
1904 if (fTimeGraphWrapper
instanceof TimeGraphComboWrapper
&& !fPackDone
) {
1905 for (TreeColumn column
: ((TimeGraphComboWrapper
) fTimeGraphWrapper
).getTreeViewer().getTree().getColumns()) {
1914 startZoomThread(startTime
, endTime
);
1916 fDirty
.decrementAndGet();
1917 LOGGER
.info(() -> "[TimeGraphView:RefreshEnd]"); //$NON-NLS-1$
1925 protected void redraw() {
1926 synchronized (fSyncObj
) {
1927 if (fRedrawState
== State
.IDLE
) {
1928 fRedrawState
= State
.BUSY
;
1930 fRedrawState
= State
.PENDING
;
1934 LOGGER
.info(() -> "[TimeGraphView:RedrawRequested]"); //$NON-NLS-1$
1935 Display
.getDefault().asyncExec(new Runnable() {
1938 LOGGER
.info(() -> "[TimeGraphView:RedrawStart]"); //$NON-NLS-1$
1939 if (fTimeGraphWrapper
.isDisposed()) {
1942 fTimeGraphWrapper
.redraw();
1943 fTimeGraphWrapper
.update();
1944 synchronized (fSyncObj
) {
1945 if (fRedrawState
== State
.PENDING
) {
1946 fRedrawState
= State
.IDLE
;
1949 fRedrawState
= State
.IDLE
;
1952 LOGGER
.info(() -> "[TimeGraphView:RedrawEnd]"); //$NON-NLS-1$
1957 private void sortChildren(ITimeGraphEntry entry
, Comparator
<ITimeGraphEntry
> comparator
) {
1958 if (entry
instanceof TimeGraphEntry
) {
1959 ((TimeGraphEntry
) entry
).sortChildren(comparator
);
1961 for (ITimeGraphEntry child
: entry
.getChildren()) {
1962 sortChildren(child
, comparator
);
1967 * Start or restart the zoom thread.
1970 * the zoom start time
1975 protected final void startZoomThread(long startTime
, long endTime
) {
1976 long clampedStartTime
= (fStartTime
== Long
.MAX_VALUE ? startTime
: Math
.min(Math
.max(startTime
, fStartTime
), fEndTime
));
1977 long clampedEndTime
= (fEndTime
== Long
.MIN_VALUE ? endTime
: Math
.max(Math
.min(endTime
, fEndTime
), fStartTime
));
1978 fDirty
.incrementAndGet();
1979 boolean restart
= false;
1980 if (fZoomThread
!= null) {
1981 fZoomThread
.cancel();
1982 if (fZoomThread
.fZoomStartTime
== clampedStartTime
&& fZoomThread
.fZoomEndTime
== clampedEndTime
) {
1986 long resolution
= Math
.max(1, (clampedEndTime
- clampedStartTime
) / fDisplayWidth
);
1987 fZoomThread
= createZoomThread(clampedStartTime
, clampedEndTime
, resolution
, restart
);
1988 if (fZoomThread
!= null) {
1989 // Don't start a new thread right away if results are being applied
1990 // from an old ZoomThread. Otherwise, the old results might
1991 // overwrite the new results if it finishes after.
1992 synchronized (fZoomThreadResultLock
) {
1993 fZoomThread
.start();
1996 fDirty
.decrementAndGet();
2001 * Create a zoom thread.
2004 * the zoom start time
2010 * true if restarting zoom for the same time range
2011 * @return a zoom thread
2014 protected @Nullable ZoomThread
createZoomThread(long startTime
, long endTime
, long resolution
, boolean restart
) {
2015 final List
<TimeGraphEntry
> entryList
= fEntryList
;
2016 if (entryList
== null) {
2019 return new ZoomThreadByEntry(entryList
, startTime
, endTime
, resolution
);
2022 private void makeActions() {
2023 fPreviousResourceAction
= fTimeGraphWrapper
.getTimeGraphViewer().getPreviousItemAction();
2024 fPreviousResourceAction
.setText(getPrevText());
2025 fPreviousResourceAction
.setToolTipText(getPrevTooltip());
2026 fNextResourceAction
= fTimeGraphWrapper
.getTimeGraphViewer().getNextItemAction();
2027 fNextResourceAction
.setText(getNextText());
2028 fNextResourceAction
.setToolTipText(getNextTooltip());
2031 private void contributeToActionBars() {
2032 IActionBars bars
= getViewSite().getActionBars();
2033 fillLocalToolBar(bars
.getToolBarManager());
2034 fillLocalMenu(bars
.getMenuManager());
2038 * Add actions to local tool bar manager
2040 * @param manager the tool bar manager
2042 protected void fillLocalToolBar(IToolBarManager manager
) {
2043 if (fFilterColumns
!= null && fFilterLabelProvider
!= null && fFilterColumns
.length
> 0) {
2044 manager
.add(fTimeGraphWrapper
.getShowFilterDialogAction());
2046 manager
.add(fTimeGraphWrapper
.getTimeGraphViewer().getShowLegendAction());
2047 manager
.add(new Separator());
2048 manager
.add(fTimeGraphWrapper
.getTimeGraphViewer().getResetScaleAction());
2049 manager
.add(fTimeGraphWrapper
.getTimeGraphViewer().getPreviousEventAction());
2050 manager
.add(fTimeGraphWrapper
.getTimeGraphViewer().getNextEventAction());
2051 manager
.add(new Separator());
2052 manager
.add(fTimeGraphWrapper
.getTimeGraphViewer().getToggleBookmarkAction());
2053 manager
.add(fTimeGraphWrapper
.getTimeGraphViewer().getPreviousMarkerAction());
2054 manager
.add(fTimeGraphWrapper
.getTimeGraphViewer().getNextMarkerAction());
2055 manager
.add(new Separator());
2056 manager
.add(fPreviousResourceAction
);
2057 manager
.add(fNextResourceAction
);
2058 manager
.add(fTimeGraphWrapper
.getTimeGraphViewer().getZoomInAction());
2059 manager
.add(fTimeGraphWrapper
.getTimeGraphViewer().getZoomOutAction());
2060 manager
.add(new Separator());
2064 * Add actions to local menu manager
2066 * @param manager the tool bar manager
2069 protected void fillLocalMenu(IMenuManager manager
) {
2070 manager
.add(fTimeGraphWrapper
.getTimeGraphViewer().getMarkersMenu());
2077 public TmfTimeViewAlignmentInfo
getTimeViewAlignmentInfo() {
2078 if (fTimeGraphWrapper
== null) {
2081 return fTimeGraphWrapper
.getTimeViewAlignmentInfo();
2088 public int getAvailableWidth(int requestedOffset
) {
2089 if (fTimeGraphWrapper
== null) {
2092 return fTimeGraphWrapper
.getAvailableWidth(requestedOffset
);
2099 public void performAlign(int offset
, int width
) {
2100 if (fTimeGraphWrapper
!= null) {
2101 fTimeGraphWrapper
.performAlign(offset
, width
);
2106 * Returns whether or not the time graph view is dirty. The time graph view
2107 * is considered dirty if it has yet to completely update its model.
2109 * This method is meant to be used by tests in order to know when it is safe
2112 * Note: If a trace is smaller than the initial window range (see
2113 * {@link ITmfTrace#getInitialRangeOffset}) this method will return true
2116 * @return true if the time graph view has yet to completely update its
2117 * model, false otherwise
2120 public boolean isDirty() {
2121 if (fTrace
== null) {
2125 TmfTraceContext ctx
= TmfTraceManager
.getInstance().getCurrentTraceContext();
2126 long startTime
= ctx
.getWindowRange().getStartTime().toNanos();
2127 long endTime
= ctx
.getWindowRange().getEndTime().toNanos();
2129 // If the time graph control hasn't updated all the way to the end of
2130 // the window range then it's dirty. A refresh should happen later.
2131 if (fTimeGraphWrapper
.getTimeGraphViewer().getTime0() != startTime
|| fTimeGraphWrapper
.getTimeGraphViewer().getTime1() != endTime
) {
2135 if (fZoomThread
== null) {
2136 // The zoom thread is null but we might be just about to create it (refresh called).
2137 return fDirty
.get() != 0;
2139 // Dirty if the zoom thread is not done or if it hasn't zoomed all the
2140 // way to the end of the window range. In the latter case, there should be
2141 // a subsequent zoom thread that will be triggered.
2142 return fDirty
.get() != 0 || fZoomThread
.getZoomStartTime() != startTime
|| fZoomThread
.getZoomEndTime() != endTime
;
2145 private void createColumnSelectionListener(TreeViewer treeViewer
) {
2146 for (int i
= 0; i
< fColumnComparators
.length
; i
++) {
2147 final int index
= i
;
2148 final Comparator
<ITimeGraphEntry
> comp
= fColumnComparators
[index
];
2149 final Tree tree
= treeViewer
.getTree();
2150 final TreeColumn column
= tree
.getColumn(i
);
2153 column
.addSelectionListener(new SelectionAdapter() {
2155 public void widgetSelected(SelectionEvent e
) {
2156 TreeColumn prevSortcolumn
= tree
.getSortColumn();
2157 int direction
= tree
.getSortDirection();
2158 if (prevSortcolumn
== column
) {
2159 direction
= (direction
== SWT
.DOWN
) ? SWT
.UP
: SWT
.DOWN
;
2161 direction
= SWT
.DOWN
;
2163 tree
.setSortColumn(column
);
2164 tree
.setSortDirection(direction
);
2165 fSortDirection
= direction
;
2166 fCurrentSortColumn
= index
;
2167 Comparator
<ITimeGraphEntry
> comparator
= comp
;
2169 if (comparator
instanceof ITimeGraphEntryComparator
) {
2170 ((ITimeGraphEntryComparator
) comparator
).setDirection(direction
);
2172 if (direction
!= SWT
.DOWN
) {
2173 comparator
= checkNotNull(Collections
.reverseOrder(comparator
));
2175 setEntryComparator(comparator
);
2176 fIsRevealSelection
= true;
2177 if (fTimeGraphWrapper
instanceof TimeGraphComboWrapper
) {
2178 ((TimeGraphComboWrapper
) fTimeGraphWrapper
).getTreeViewer().getControl().setFocus();
2187 private void createDoubleClickListener(TreeViewer treeViewer
) {
2188 treeViewer
.addDoubleClickListener(event
-> {
2189 if (event
.getSelection() instanceof TreeSelection
) {
2190 TreeSelection selection
= (TreeSelection
) event
.getSelection();
2191 if (selection
.getFirstElement() instanceof ITimeGraphEntry
) {
2192 ITimeGraphEntry entry
= (ITimeGraphEntry
) selection
.getFirstElement();
2193 if (entry
.hasChildren()) {
2194 fTimeGraphWrapper
.setExpandedState(entry
, !fTimeGraphWrapper
.getExpandedState(entry
));
2202 private void restoreViewContext() {
2203 TimeGraphCombo combo
= getTimeGraphCombo();
2204 ViewContext viewContext
= fViewContext
.get(fTrace
);
2205 if (combo
!= null) {
2206 if (fColumnComparators
!= null) {
2207 // restore sort settings
2208 fSortDirection
= SWT
.DOWN
;
2209 fCurrentSortColumn
= fInitialSortColumn
;
2210 if (viewContext
!= null) {
2211 fSortDirection
= viewContext
.getSortDirection();
2212 fCurrentSortColumn
= viewContext
.getSortColumn();
2214 if ((fCurrentSortColumn
< fColumnComparators
.length
) && (fColumnComparators
[fCurrentSortColumn
] != null)) {
2215 Comparator
<ITimeGraphEntry
> comparator
= fColumnComparators
[fCurrentSortColumn
];
2216 if (comparator
instanceof ITimeGraphEntryComparator
) {
2217 ((ITimeGraphEntryComparator
) comparator
).setDirection(fSortDirection
);
2219 if (fSortDirection
!= SWT
.DOWN
) {
2220 comparator
= checkNotNull(Collections
.reverseOrder(comparator
));
2222 setEntryComparator(comparator
);
2228 private void applyViewContext() {
2229 TimeGraphCombo combo
= getTimeGraphCombo();
2230 ViewContext viewContext
= fViewContext
.get(fTrace
);
2231 if (combo
!= null) {
2232 TreeViewer treeViewer
= combo
.getTreeViewer();
2233 final Tree tree
= treeViewer
.getTree();
2234 final TreeColumn column
= tree
.getColumn(fCurrentSortColumn
);
2235 tree
.setSortDirection(fSortDirection
);
2236 tree
.setSortColumn(column
);
2237 combo
.getTreeViewer().getControl().setFocus();
2239 // restore and reveal selection
2240 if ((viewContext
!= null) && (viewContext
.getSelection() != null)) {
2241 fTimeGraphWrapper
.setSelection(viewContext
.getSelection());
2243 fViewContext
.remove(fTrace
);
2246 private static class ViewContext
{
2247 private int fSortColumnIndex
;
2248 private int fSortDirection
;
2249 private @Nullable ITimeGraphEntry fSelection
;
2251 ViewContext(int sortColunm
, int sortDirection
, ITimeGraphEntry selection
) {
2252 fSortColumnIndex
= sortColunm
;
2253 fSortDirection
= sortDirection
;
2254 fSelection
= selection
;
2257 * @return the sortColumn
2259 public int getSortColumn() {
2260 return fSortColumnIndex
;
2263 * @return the sortDirection
2265 public int getSortDirection() {
2266 return fSortDirection
;
2269 * @return the selection
2271 public ITimeGraphEntry
getSelection() {
2277 * Method to reset the view internal data for a given trace.
2279 * When overriding this method make sure to call the super
2283 * trace to reset the view for.
2286 protected void resetView(ITmfTrace viewTrace
) {
2287 if (viewTrace
== null) {
2290 synchronized (fBuildThreadMap
) {
2291 for (ITmfTrace trace
: getTracesToBuild(viewTrace
)) {
2292 BuildThread buildThread
= fBuildThreadMap
.remove(trace
);
2293 if (buildThread
!= null) {
2294 buildThread
.cancel();
2298 synchronized (fEntryListMap
) {
2299 fEntryListMap
.remove(viewTrace
);
2301 fViewContext
.remove(viewTrace
);
2302 fFiltersMap
.remove(viewTrace
);
2303 fMarkerEventSourcesMap
.remove(viewTrace
);
2304 if (viewTrace
== fTrace
) {
2305 if (fZoomThread
!= null) {
2306 fZoomThread
.cancel();
2312 private void createContextMenu() {
2313 TimeGraphCombo combo
= getTimeGraphCombo();
2314 fEntryMenuManager
.setRemoveAllWhenShown(true);
2315 if (combo
!= null) {
2316 TreeViewer treeViewer
= combo
.getTreeViewer();
2317 Tree tree
= treeViewer
.getTree();
2318 Menu menu
= fEntryMenuManager
.createContextMenu(tree
);
2321 TimeGraphControl timeGraphControl
= getTimeGraphViewer().getTimeGraphControl();
2322 final Menu entryMenu
= fEntryMenuManager
.createContextMenu(timeGraphControl
);
2323 timeGraphControl
.addTimeGraphEntryMenuListener(new MenuDetectListener() {
2325 public void menuDetected(MenuDetectEvent event
) {
2326 Point p
= timeGraphControl
.toControl(event
.x
, event
.y
);
2328 * The TimeGraphControl will call the TimeGraphEntryMenuListener
2329 * before the TimeEventMenuListener. If the event is
2330 * triggered on the namespace then show the menu else
2333 if (p
.x
< getTimeGraphViewer().getNameSpace()) {
2334 timeGraphControl
.setMenu(entryMenu
);
2336 timeGraphControl
.setMenu(null);
2342 fEntryMenuManager
.addMenuListener(new IMenuListener() {
2344 public void menuAboutToShow(IMenuManager manager
) {
2345 fillTimeGraphEntryContextMenu(fEntryMenuManager
);
2346 fEntryMenuManager
.add(new GroupMarker(IWorkbenchActionConstants
.MB_ADDITIONS
));
2349 getSite().registerContextMenu(fEntryMenuManager
, fTimeGraphWrapper
.getSelectionProvider());
2355 * @param menuManager
2356 * a menuManager to fill
2359 protected void fillTimeGraphEntryContextMenu (@NonNull IMenuManager menuManager
) {
2363 * Inner classes used for searching
2366 public ITimeGraphEntry
getSelection() {
2367 return fTimeGraphWrapper
.getSelection();
2370 public void selectAndReveal(@NonNull ITimeGraphEntry entry
) {
2371 fTimeGraphWrapper
.selectAndReveal(entry
);
2374 public ITimeGraphEntry
[] getEntries() {
2375 TimeGraphViewer viewer
= getTimeGraphViewer();
2376 return viewer
.getTimeGraphContentProvider().getElements(viewer
.getInput());
2379 public Shell
getShell() {
2380 return getSite().getShell();
2384 class TimeGraphPartListener
implements IPartListener
{
2386 public void partActivated(IWorkbenchPart part
) {
2387 if (part
== AbstractTimeGraphView
.this) {
2388 synchronized (FIND_ACTION
) {
2389 if (fFindActionHandler
== null) {
2390 fFindActionHandler
= new ActionHandler(FIND_ACTION
);
2392 if (fFindHandlerActivation
== null) {
2393 final Object service
= PlatformUI
.getWorkbench().getService(IHandlerService
.class);
2394 fFindHandlerActivation
= ((IHandlerService
) service
).activateHandler(ActionFactory
.FIND
.getCommandId(), fFindActionHandler
);
2398 // Notify action for all parts
2399 FIND_ACTION
.partActivated(part
);
2402 public void partDeactivated(IWorkbenchPart part
) {
2403 if ((part
== AbstractTimeGraphView
.this) && (fFindHandlerActivation
!= null)) {
2404 final Object service
= PlatformUI
.getWorkbench().getService(IHandlerService
.class);
2405 ((IHandlerService
) service
).deactivateHandler(fFindHandlerActivation
);
2406 fFindHandlerActivation
= null;
2410 public void partBroughtToTop(IWorkbenchPart part
) {
2413 public void partClosed(IWorkbenchPart part
) {
2416 public void partOpened(IWorkbenchPart part
) {