1 /*******************************************************************************
2 * Copyright (c) 2012, 2014 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
.linuxtools
.tmf
.ui
.views
.timegraph
;
19 import java
.util
.ArrayList
;
20 import java
.util
.Collections
;
21 import java
.util
.Comparator
;
22 import java
.util
.HashMap
;
23 import java
.util
.List
;
25 import java
.util
.concurrent
.CopyOnWriteArrayList
;
27 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
28 import org
.eclipse
.core
.runtime
.NullProgressMonitor
;
29 import org
.eclipse
.jface
.action
.Action
;
30 import org
.eclipse
.jface
.action
.IAction
;
31 import org
.eclipse
.jface
.action
.IStatusLineManager
;
32 import org
.eclipse
.jface
.action
.IToolBarManager
;
33 import org
.eclipse
.jface
.action
.Separator
;
34 import org
.eclipse
.jface
.viewers
.ILabelProviderListener
;
35 import org
.eclipse
.jface
.viewers
.ISelectionProvider
;
36 import org
.eclipse
.jface
.viewers
.ITableLabelProvider
;
37 import org
.eclipse
.jface
.viewers
.ITreeContentProvider
;
38 import org
.eclipse
.jface
.viewers
.TreeViewer
;
39 import org
.eclipse
.jface
.viewers
.Viewer
;
40 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfRangeSynchSignal
;
41 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfSignalHandler
;
42 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfTimeSynchSignal
;
43 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfTimestampFormatUpdateSignal
;
44 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfTraceClosedSignal
;
45 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfTraceOpenedSignal
;
46 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfTraceSelectedSignal
;
47 import org
.eclipse
.linuxtools
.tmf
.core
.timestamp
.ITmfTimestamp
;
48 import org
.eclipse
.linuxtools
.tmf
.core
.timestamp
.TmfNanoTimestamp
;
49 import org
.eclipse
.linuxtools
.tmf
.core
.timestamp
.TmfTimeRange
;
50 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfTrace
;
51 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.TmfTraceManager
;
52 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.TmfView
;
53 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.ITimeGraphContentProvider
;
54 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.ITimeGraphRangeListener
;
55 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.ITimeGraphSelectionListener
;
56 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.ITimeGraphTimeListener
;
57 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.TimeGraphCombo
;
58 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.TimeGraphPresentationProvider
;
59 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.TimeGraphRangeUpdateEvent
;
60 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.TimeGraphSelectionEvent
;
61 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.TimeGraphTimeEvent
;
62 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.TimeGraphViewer
;
63 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.model
.ILinkEvent
;
64 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.model
.ITimeEvent
;
65 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.model
.ITimeGraphEntry
;
66 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.model
.TimeGraphEntry
;
67 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.widgets
.Utils
.TimeFormat
;
68 import org
.eclipse
.swt
.SWT
;
69 import org
.eclipse
.swt
.graphics
.Image
;
70 import org
.eclipse
.swt
.widgets
.Composite
;
71 import org
.eclipse
.swt
.widgets
.Display
;
72 import org
.eclipse
.swt
.widgets
.TreeColumn
;
73 import org
.eclipse
.ui
.IActionBars
;
76 * An abstract view all time graph views can inherit
78 * This view contains either a time graph viewer, or a time graph combo which is
79 * divided between a tree viewer on the left and a time graph viewer on the right.
83 public abstract class AbstractTimeGraphView
extends TmfView
{
92 // ------------------------------------------------------------------------
94 // ------------------------------------------------------------------------
96 /** The timegraph wrapper */
97 private ITimeGraphWrapper fTimeGraphWrapper
;
99 /** The selected trace */
100 private ITmfTrace fTrace
;
102 /** The timegraph entry list */
103 private List
<TimeGraphEntry
> fEntryList
;
105 /** The trace to entry list hash map */
106 private final Map
<ITmfTrace
, List
<TimeGraphEntry
>> fEntryListMap
= new HashMap
<>();
108 /** The trace to build thread hash map */
109 private final Map
<ITmfTrace
, BuildThread
> fBuildThreadMap
= new HashMap
<>();
111 /** The start time */
112 private long fStartTime
;
115 private long fEndTime
;
117 /** The display width */
118 private final int fDisplayWidth
;
120 /** The zoom thread */
121 private ZoomThread fZoomThread
;
123 /** The next resource action */
124 private Action fNextResourceAction
;
126 /** The previous resource action */
127 private Action fPreviousResourceAction
;
129 /** A comparator class */
130 private Comparator
<ITimeGraphEntry
> fEntryComparator
= null;
132 /** The redraw state used to prevent unnecessary queuing of display runnables */
133 private State fRedrawState
= State
.IDLE
;
135 /** The redraw synchronization object */
136 private final Object fSyncObj
= new Object();
138 /** The presentation provider for this view */
139 private final TimeGraphPresentationProvider fPresentation
;
141 /** The tree column label array, or null if combo is not used */
142 private String
[] fColumns
;
144 /** The tree label provider, or null if combo is not used */
145 private TreeLabelProvider fLabelProvider
= null;
147 /** The relative weight of the sash, ignored if combo is not used */
148 private int[] fWeight
= { 1, 1 };
150 /** The filter column label array, or null if filter is not used */
151 private String
[] fFilterColumns
;
153 /** The pack done flag */
154 private boolean fPackDone
= false;
156 /** The filter label provider, or null if filter is not used */
157 private TreeLabelProvider fFilterLabelProvider
;
159 // ------------------------------------------------------------------------
161 // ------------------------------------------------------------------------
163 private interface ITimeGraphWrapper
{
165 void setTimeGraphProvider(TimeGraphPresentationProvider fPresentation
);
167 TimeGraphViewer
getTimeGraphViewer();
169 void addSelectionListener(ITimeGraphSelectionListener iTimeGraphSelectionListener
);
171 ISelectionProvider
getSelectionProvider();
175 boolean isDisposed();
179 void setInput(Object input
);
189 private class TimeGraphViewerWrapper
implements ITimeGraphWrapper
{
190 private TimeGraphViewer viewer
;
192 private TimeGraphViewerWrapper(Composite parent
, int style
) {
193 viewer
= new TimeGraphViewer(parent
, style
);
197 public void setTimeGraphProvider(TimeGraphPresentationProvider timeGraphProvider
) {
198 viewer
.setTimeGraphProvider(timeGraphProvider
);
202 public TimeGraphViewer
getTimeGraphViewer() {
207 public void addSelectionListener(ITimeGraphSelectionListener listener
) {
208 viewer
.addSelectionListener(listener
);
212 public ISelectionProvider
getSelectionProvider() {
213 return viewer
.getSelectionProvider();
217 public void setFocus() {
222 public boolean isDisposed() {
223 return viewer
.getControl().isDisposed();
227 public void setInput(Object input
) {
228 viewer
.setInput(input
);
232 public Object
getInput() {
233 return viewer
.getInput();
237 public void refresh() {
242 public void redraw() {
243 viewer
.getControl().redraw();
247 public void update() {
248 viewer
.getControl().update();
252 private class TimeGraphComboWrapper
implements ITimeGraphWrapper
{
253 private TimeGraphCombo combo
;
255 private TimeGraphComboWrapper(Composite parent
, int style
) {
256 combo
= new TimeGraphCombo(parent
, style
, fWeight
);
260 public void setTimeGraphProvider(TimeGraphPresentationProvider timeGraphProvider
) {
261 combo
.setTimeGraphProvider(timeGraphProvider
);
265 public TimeGraphViewer
getTimeGraphViewer() {
266 return combo
.getTimeGraphViewer();
270 public void addSelectionListener(ITimeGraphSelectionListener listener
) {
271 combo
.addSelectionListener(listener
);
275 public ISelectionProvider
getSelectionProvider() {
276 return combo
.getTreeViewer();
280 public void setFocus() {
285 public boolean isDisposed() {
286 return combo
.isDisposed();
290 public void setInput(Object input
) {
291 combo
.setInput(input
);
295 public Object
getInput() {
296 return combo
.getInput();
300 public void refresh() {
305 public void redraw() {
310 public void update() {
314 TimeGraphCombo
getTimeGraphCombo() {
318 TreeViewer
getTreeViewer() {
319 return combo
.getTreeViewer();
322 IAction
getShowFilterAction() {
323 return combo
.getShowFilterAction();
327 private class TreeContentProvider
implements ITreeContentProvider
{
330 public void dispose() {
334 public void inputChanged(Viewer viewer
, Object oldInput
, Object newInput
) {
338 public ITimeGraphEntry
[] getElements(Object inputElement
) {
339 if (inputElement
!= null) {
341 return ((List
<?
>) inputElement
).toArray(new ITimeGraphEntry
[0]);
342 } catch (ClassCastException e
) {
345 return new ITimeGraphEntry
[0];
349 public Object
[] getChildren(Object parentElement
) {
350 ITimeGraphEntry entry
= (ITimeGraphEntry
) parentElement
;
351 List
<?
extends ITimeGraphEntry
> children
= entry
.getChildren();
352 return children
.toArray(new ITimeGraphEntry
[children
.size()]);
356 public Object
getParent(Object element
) {
357 ITimeGraphEntry entry
= (ITimeGraphEntry
) element
;
358 return entry
.getParent();
362 public boolean hasChildren(Object element
) {
363 ITimeGraphEntry entry
= (ITimeGraphEntry
) element
;
364 return entry
.hasChildren();
369 private class TimeGraphContentProvider
implements ITimeGraphContentProvider
{
372 public ITimeGraphEntry
[] getElements(Object inputElement
) {
373 if (inputElement
!= null) {
375 return ((List
<?
>) inputElement
).toArray(new ITimeGraphEntry
[0]);
376 } catch (ClassCastException e
) {
379 return new ITimeGraphEntry
[0];
385 * Base class to provide the labels for the tree viewer. Views extending
386 * this class typically need to override the getColumnText method if they
387 * have more than one column to display
389 protected static class TreeLabelProvider
implements ITableLabelProvider
{
392 public void addListener(ILabelProviderListener listener
) {
396 public void dispose() {
400 public boolean isLabelProperty(Object element
, String property
) {
405 public void removeListener(ILabelProviderListener listener
) {
409 public Image
getColumnImage(Object element
, int columnIndex
) {
414 public String
getColumnText(Object element
, int columnIndex
) {
415 TimeGraphEntry entry
= (TimeGraphEntry
) element
;
416 if (columnIndex
== 0) {
417 return entry
.getName();
424 private class BuildThread
extends Thread
{
425 private final ITmfTrace fBuildTrace
;
426 private final ITmfTrace fParentTrace
;
427 private final IProgressMonitor fMonitor
;
429 public BuildThread(final ITmfTrace trace
, final ITmfTrace parentTrace
, final String name
) {
430 super(name
+ " build"); //$NON-NLS-1$
432 fParentTrace
= parentTrace
;
433 fMonitor
= new NullProgressMonitor();
438 buildEventList(fBuildTrace
, fParentTrace
, fMonitor
);
439 synchronized (fBuildThreadMap
) {
440 fBuildThreadMap
.remove(fBuildTrace
);
444 public void cancel() {
445 fMonitor
.setCanceled(true);
449 private class ZoomThread
extends Thread
{
450 private final List
<TimeGraphEntry
> fZoomEntryList
;
451 private final long fZoomStartTime
;
452 private final long fZoomEndTime
;
453 private final long fResolution
;
454 private final IProgressMonitor fMonitor
;
456 public ZoomThread(List
<TimeGraphEntry
> entryList
, long startTime
, long endTime
, String name
) {
457 super(name
+ " zoom"); //$NON-NLS-1$
458 fZoomEntryList
= entryList
;
459 fZoomStartTime
= startTime
;
460 fZoomEndTime
= endTime
;
461 fResolution
= Math
.max(1, (fZoomEndTime
- fZoomStartTime
) / fDisplayWidth
);
462 fMonitor
= new NullProgressMonitor();
467 if (fZoomEntryList
== null) {
470 for (TimeGraphEntry entry
: fZoomEntryList
) {
471 if (fMonitor
.isCanceled()) {
474 zoom(entry
, fMonitor
);
476 /* Refresh the arrows when zooming */
477 List
<ILinkEvent
> events
= getLinkList(fZoomStartTime
, fZoomEndTime
, fResolution
, fMonitor
);
478 if (events
!= null) {
479 fTimeGraphWrapper
.getTimeGraphViewer().setLinks(events
);
484 private void zoom(TimeGraphEntry entry
, IProgressMonitor monitor
) {
485 if (fZoomStartTime
<= fStartTime
&& fZoomEndTime
>= fEndTime
) {
486 entry
.setZoomedEventList(null);
488 List
<ITimeEvent
> zoomedEventList
= getEventList(entry
, fZoomStartTime
, fZoomEndTime
, fResolution
, monitor
);
489 if (zoomedEventList
!= null) {
490 entry
.setZoomedEventList(zoomedEventList
);
494 for (TimeGraphEntry child
: entry
.getChildren()) {
495 if (fMonitor
.isCanceled()) {
498 zoom(child
, monitor
);
502 public void cancel() {
503 fMonitor
.setCanceled(true);
507 // ------------------------------------------------------------------------
509 // ------------------------------------------------------------------------
512 * Constructs a time graph view that contains either a time graph viewer or
513 * a time graph combo.
515 * By default, the view uses a time graph viewer. To use a time graph combo,
516 * the subclass constructor must call {@link #setTreeColumns(String[])} and
517 * {@link #setTreeLabelProvider(TreeLabelProvider)}.
522 * The presentation provider
524 public AbstractTimeGraphView(String id
, TimeGraphPresentationProvider pres
) {
526 fPresentation
= pres
;
527 fDisplayWidth
= Display
.getDefault().getBounds().width
;
530 // ------------------------------------------------------------------------
531 // Getters and setters
532 // ------------------------------------------------------------------------
535 * Getter for the time graph combo
537 * @return The time graph combo, or null if combo is not used
539 protected TimeGraphCombo
getTimeGraphCombo() {
540 if (fTimeGraphWrapper
instanceof TimeGraphComboWrapper
) {
541 return ((TimeGraphComboWrapper
) fTimeGraphWrapper
).getTimeGraphCombo();
547 * Getter for the time graph viewer
549 * @return The time graph viewer
551 protected TimeGraphViewer
getTimeGraphViewer() {
552 return fTimeGraphWrapper
.getTimeGraphViewer();
556 * Sets the tree column labels.
557 * This should be called from the constructor.
560 * The array of tree column labels
562 protected void setTreeColumns(final String
[] columns
) {
567 * Sets the tree label provider.
568 * This should be called from the constructor.
571 * The tree label provider
573 protected void setTreeLabelProvider(final TreeLabelProvider tlp
) {
574 fLabelProvider
= tlp
;
578 * Sets the relative weight of each part of the time graph combo.
579 * This should be called from the constructor.
582 * The array (length 2) of relative weights of each part of the combo
584 protected void setWeight(final int[] weights
) {
589 * Sets the filter column labels.
590 * This should be called from the constructor.
592 * @param filterColumns
593 * The array of filter column labels
595 protected void setFilterColumns(final String
[] filterColumns
) {
596 fFilterColumns
= filterColumns
;
600 * Sets the filter label provider.
601 * This should be called from the constructor.
603 * @param labelProvider
604 * The filter label provider
608 protected void setFilterLabelProvider(final TreeLabelProvider labelProvider
) {
609 fFilterLabelProvider
= labelProvider
;
613 * Gets the display width
615 * @return the display width
617 protected int getDisplayWidth() {
618 return fDisplayWidth
;
622 * Gets the comparator for the entries
624 * @return The entry comparator
626 protected Comparator
<ITimeGraphEntry
> getEntryComparator() {
627 return fEntryComparator
;
631 * Sets the comparator class for the entries
634 * A comparator object
636 protected void setEntryComparator(final Comparator
<ITimeGraphEntry
> comparator
) {
637 fEntryComparator
= comparator
;
641 * Gets the trace displayed in the view
645 protected ITmfTrace
getTrace() {
650 * Gets the start time
652 * @return The start time
654 protected long getStartTime() {
659 * Sets the start time
664 protected void setStartTime(long time
) {
671 * @return The end time
673 protected long getEndTime() {
683 protected void setEndTime(long time
) {
688 * Gets the entry list for a trace
693 * @return the entry list map
696 protected List
<TimeGraphEntry
> getEntryList(ITmfTrace trace
) {
697 synchronized (fEntryListMap
) {
698 return fEntryListMap
.get(trace
);
703 * Adds a trace entry list to the entry list map
708 * the list of time graph entries
710 protected void putEntryList(ITmfTrace trace
, List
<TimeGraphEntry
> list
) {
711 synchronized (fEntryListMap
) {
712 fEntryListMap
.put(trace
, new CopyOnWriteArrayList
<>(list
));
717 * Adds a list of entries to a trace's entry list
722 * the list of time graph entries to add
725 protected void addToEntryList(ITmfTrace trace
, List
<TimeGraphEntry
> list
) {
726 synchronized (fEntryListMap
) {
727 List
<TimeGraphEntry
> entryList
= fEntryListMap
.get(trace
);
728 if (entryList
== null) {
729 fEntryListMap
.put(trace
, new CopyOnWriteArrayList
<>(list
));
731 entryList
.addAll(list
);
737 * Removes a list of entries from a trace's entry list
742 * the list of time graph entries to remove
745 protected void removeFromEntryList(ITmfTrace trace
, List
<TimeGraphEntry
> list
) {
746 synchronized (fEntryListMap
) {
747 List
<TimeGraphEntry
> entryList
= fEntryListMap
.get(trace
);
748 if (entryList
!= null) {
749 entryList
.removeAll(list
);
755 * Text for the "next" button
757 * @return The "next" button text
759 protected String
getNextText() {
760 return Messages
.AbstractTimeGraphtView_NextText
;
764 * Tooltip for the "next" button
766 * @return Tooltip for the "next" button
768 protected String
getNextTooltip() {
769 return Messages
.AbstractTimeGraphView_NextTooltip
;
773 * Text for the "Previous" button
775 * @return The "Previous" button text
777 protected String
getPrevText() {
778 return Messages
.AbstractTimeGraphView_PreviousText
;
782 * Tooltip for the "previous" button
784 * @return Tooltip for the "previous" button
786 protected String
getPrevTooltip() {
787 return Messages
.AbstractTimeGraphView_PreviousTooltip
;
790 // ------------------------------------------------------------------------
792 // ------------------------------------------------------------------------
795 public void createPartControl(Composite parent
) {
796 if (fColumns
== null || fLabelProvider
== null) {
797 fTimeGraphWrapper
= new TimeGraphViewerWrapper(parent
, SWT
.NONE
);
798 TimeGraphViewer viewer
= fTimeGraphWrapper
.getTimeGraphViewer();
799 viewer
.setTimeGraphContentProvider(new TimeGraphContentProvider());
801 TimeGraphComboWrapper wrapper
= new TimeGraphComboWrapper(parent
, SWT
.NONE
);
802 fTimeGraphWrapper
= wrapper
;
803 TimeGraphCombo combo
= wrapper
.getTimeGraphCombo();
804 combo
.setTreeContentProvider(new TreeContentProvider());
805 combo
.setTreeLabelProvider(fLabelProvider
);
806 combo
.setTreeColumns(fColumns
);
807 combo
.setFilterContentProvider(new TreeContentProvider());
808 combo
.setFilterLabelProvider(fFilterLabelProvider
);
809 combo
.setFilterColumns(fFilterColumns
);
810 combo
.setTimeGraphContentProvider(new TimeGraphContentProvider());
813 fTimeGraphWrapper
.setTimeGraphProvider(fPresentation
);
815 fTimeGraphWrapper
.getTimeGraphViewer().addRangeListener(new ITimeGraphRangeListener() {
817 public void timeRangeUpdated(TimeGraphRangeUpdateEvent event
) {
818 final long startTime
= event
.getStartTime();
819 final long endTime
= event
.getEndTime();
820 TmfTimeRange range
= new TmfTimeRange(new TmfNanoTimestamp(startTime
), new TmfNanoTimestamp(endTime
));
821 broadcast(new TmfRangeSynchSignal(AbstractTimeGraphView
.this, range
));
822 if (fZoomThread
!= null) {
823 fZoomThread
.cancel();
825 startZoomThread(startTime
, endTime
);
829 fTimeGraphWrapper
.getTimeGraphViewer().addTimeListener(new ITimeGraphTimeListener() {
831 public void timeSelected(TimeGraphTimeEvent event
) {
832 TmfNanoTimestamp startTime
= new TmfNanoTimestamp(event
.getBeginTime());
833 TmfNanoTimestamp endTime
= new TmfNanoTimestamp(event
.getEndTime());
834 broadcast(new TmfTimeSynchSignal(AbstractTimeGraphView
.this, startTime
, endTime
));
838 fTimeGraphWrapper
.addSelectionListener(new ITimeGraphSelectionListener() {
840 public void selectionChanged(TimeGraphSelectionEvent event
) {
841 // ITimeGraphEntry selection = event.getSelection();
845 fTimeGraphWrapper
.getTimeGraphViewer().setTimeFormat(TimeFormat
.CALENDAR
);
847 IStatusLineManager statusLineManager
= getViewSite().getActionBars().getStatusLineManager();
848 fTimeGraphWrapper
.getTimeGraphViewer().getTimeGraphControl().setStatusLineManager(statusLineManager
);
850 // View Action Handling
852 contributeToActionBars();
854 ITmfTrace trace
= getActiveTrace();
856 traceSelected(new TmfTraceSelectedSignal(this, trace
));
859 // make selection available to other views
860 getSite().setSelectionProvider(fTimeGraphWrapper
.getSelectionProvider());
864 public void setFocus() {
865 fTimeGraphWrapper
.setFocus();
868 // ------------------------------------------------------------------------
870 // ------------------------------------------------------------------------
873 * Handler for the trace opened signal.
876 * The incoming signal
880 public void traceOpened(TmfTraceOpenedSignal signal
) {
881 fTrace
= signal
.getTrace();
886 * Handler for the trace selected signal
889 * The incoming signal
892 public void traceSelected(final TmfTraceSelectedSignal signal
) {
893 if (signal
.getTrace() == fTrace
) {
896 fTrace
= signal
.getTrace();
902 * Trace is closed: clear the data structures and the view
905 * the signal received
908 public void traceClosed(final TmfTraceClosedSignal signal
) {
909 synchronized (fBuildThreadMap
) {
910 for (ITmfTrace trace
: TmfTraceManager
.getTraceSet(signal
.getTrace())) {
911 BuildThread buildThread
= fBuildThreadMap
.remove(trace
);
912 if (buildThread
!= null) {
913 buildThread
.cancel();
917 synchronized (fEntryListMap
) {
918 fEntryListMap
.remove(signal
.getTrace());
920 if (signal
.getTrace() == fTrace
) {
924 if (fZoomThread
!= null) {
925 fZoomThread
.cancel();
932 * Handler for the time synch signal
935 * The signal that's received
938 public void synchToTime(final TmfTimeSynchSignal signal
) {
939 if (signal
.getSource() == this || fTrace
== null) {
942 final long beginTime
= signal
.getBeginTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
943 final long endTime
= signal
.getEndTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
945 Display
.getDefault().asyncExec(new Runnable() {
948 if (fTimeGraphWrapper
.isDisposed()) {
951 if (beginTime
== endTime
) {
952 fTimeGraphWrapper
.getTimeGraphViewer().setSelectedTime(beginTime
, true);
954 fTimeGraphWrapper
.getTimeGraphViewer().setSelectionRange(beginTime
, endTime
);
956 startZoomThread(fTimeGraphWrapper
.getTimeGraphViewer().getTime0(), fTimeGraphWrapper
.getTimeGraphViewer().getTime1());
958 synchingToTime(beginTime
);
964 * Handler for the range synch signal
967 * The signal that's received
970 public void synchToRange(final TmfRangeSynchSignal signal
) {
971 if (signal
.getSource() == this || fTrace
== null) {
974 if (signal
.getCurrentRange().getIntersection(fTrace
.getTimeRange()) == null) {
977 final long startTime
= signal
.getCurrentRange().getStartTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
978 final long endTime
= signal
.getCurrentRange().getEndTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
979 Display
.getDefault().asyncExec(new Runnable() {
982 if (fTimeGraphWrapper
.isDisposed()) {
985 fTimeGraphWrapper
.getTimeGraphViewer().setStartFinishTime(startTime
, endTime
);
986 startZoomThread(startTime
, endTime
);
992 * @param signal the format of the timestamps was updated.
996 public void updateTimeFormat( final TmfTimestampFormatUpdateSignal signal
){
997 fTimeGraphWrapper
.refresh();
1000 // ------------------------------------------------------------------------
1002 // ------------------------------------------------------------------------
1004 private void loadTrace() {
1005 synchronized (fEntryListMap
) {
1006 fEntryList
= fEntryListMap
.get(fTrace
);
1007 if (fEntryList
== null) {
1008 setStartTime(Long
.MAX_VALUE
);
1009 setEndTime(Long
.MIN_VALUE
);
1010 synchronized (fBuildThreadMap
) {
1011 for (ITmfTrace trace
: TmfTraceManager
.getTraceSet(fTrace
)) {
1012 BuildThread buildThread
= new BuildThread(trace
, fTrace
, getName());
1013 fBuildThreadMap
.put(trace
, buildThread
);
1014 buildThread
.start();
1018 fStartTime
= fTrace
.getStartTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
1019 fEndTime
= fTrace
.getEndTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
1026 * Method called when synching to a given timestamp. Inheriting classes can
1027 * perform actions here to update the view at the given timestamp.
1030 * The currently selected time
1032 protected void synchingToTime(long time
) {
1037 * Build the entries list to show in this time graph
1039 * Called from the BuildThread
1042 * The trace being built
1043 * @param parentTrace
1044 * The parent of the trace set, or the trace itself
1046 * The progress monitor object
1049 protected abstract void buildEventList(ITmfTrace trace
, ITmfTrace parentTrace
, IProgressMonitor monitor
);
1052 * Gets the list of event for an entry in a given timerange
1055 * The entry to get events for
1057 * Start of the time range
1059 * End of the time range
1063 * The progress monitor object
1064 * @return The list of events for the entry
1066 protected abstract List
<ITimeEvent
> getEventList(TimeGraphEntry entry
,
1067 long startTime
, long endTime
, long resolution
,
1068 IProgressMonitor monitor
);
1071 * Gets the list of links (displayed as arrows) for a trace in a given
1072 * timerange. Default implementation returns an empty list.
1075 * Start of the time range
1077 * End of the time range
1081 * The progress monitor object
1082 * @return The list of link events
1085 protected List
<ILinkEvent
> getLinkList(long startTime
, long endTime
,
1086 long resolution
, IProgressMonitor monitor
) {
1087 return new ArrayList
<>();
1092 * Refresh the display
1094 protected void refresh() {
1095 Display
.getDefault().asyncExec(new Runnable() {
1098 if (fTimeGraphWrapper
.isDisposed()) {
1101 boolean hasEntries
= false;
1102 synchronized (fEntryListMap
) {
1103 fEntryList
= fEntryListMap
.get(fTrace
);
1104 if (fEntryList
== null) {
1105 fEntryList
= new CopyOnWriteArrayList
<>();
1106 } else if (fEntryComparator
!= null) {
1107 List
<TimeGraphEntry
> list
= new ArrayList
<>(fEntryList
);
1108 Collections
.sort(list
, fEntryComparator
);
1110 fEntryList
.addAll(list
);
1112 hasEntries
= fEntryList
.size() != 0;
1114 if (fEntryList
!= fTimeGraphWrapper
.getInput()) {
1115 fTimeGraphWrapper
.setInput(fEntryList
);
1117 fTimeGraphWrapper
.refresh();
1119 fTimeGraphWrapper
.getTimeGraphViewer().setTimeBounds(fStartTime
, fEndTime
);
1121 long selectionBeginTime
= fTrace
== null ?
0 : fTraceManager
.getSelectionBeginTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
1122 long selectionEndTime
= fTrace
== null ?
0 : fTraceManager
.getSelectionEndTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
1123 long startTime
= fTrace
== null ?
0 : fTraceManager
.getCurrentRange().getStartTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
1124 long endTime
= fTrace
== null ?
0 : fTraceManager
.getCurrentRange().getEndTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
1125 startTime
= Math
.max(startTime
, fStartTime
);
1126 endTime
= Math
.min(endTime
, fEndTime
);
1127 fTimeGraphWrapper
.getTimeGraphViewer().setSelectionRange(selectionBeginTime
, selectionEndTime
);
1128 fTimeGraphWrapper
.getTimeGraphViewer().setStartFinishTime(startTime
, endTime
);
1130 if (fTimeGraphWrapper
instanceof TimeGraphComboWrapper
&& !fPackDone
) {
1131 for (TreeColumn column
: ((TimeGraphComboWrapper
) fTimeGraphWrapper
).getTreeViewer().getTree().getColumns()) {
1139 startZoomThread(startTime
, endTime
);
1147 protected void redraw() {
1148 synchronized (fSyncObj
) {
1149 if (fRedrawState
== State
.IDLE
) {
1150 fRedrawState
= State
.BUSY
;
1152 fRedrawState
= State
.PENDING
;
1156 Display
.getDefault().asyncExec(new Runnable() {
1159 if (fTimeGraphWrapper
.isDisposed()) {
1162 fTimeGraphWrapper
.redraw();
1163 fTimeGraphWrapper
.update();
1164 synchronized (fSyncObj
) {
1165 if (fRedrawState
== State
.PENDING
) {
1166 fRedrawState
= State
.IDLE
;
1169 fRedrawState
= State
.IDLE
;
1176 private void startZoomThread(long startTime
, long endTime
) {
1177 if (fZoomThread
!= null) {
1178 fZoomThread
.cancel();
1180 fZoomThread
= new ZoomThread(fEntryList
, startTime
, endTime
, getName());
1181 fZoomThread
.start();
1184 private void makeActions() {
1185 fPreviousResourceAction
= fTimeGraphWrapper
.getTimeGraphViewer().getPreviousItemAction();
1186 fPreviousResourceAction
.setText(getPrevText());
1187 fPreviousResourceAction
.setToolTipText(getPrevTooltip());
1188 fNextResourceAction
= fTimeGraphWrapper
.getTimeGraphViewer().getNextItemAction();
1189 fNextResourceAction
.setText(getNextText());
1190 fNextResourceAction
.setToolTipText(getNextTooltip());
1193 private void contributeToActionBars() {
1194 IActionBars bars
= getViewSite().getActionBars();
1195 fillLocalToolBar(bars
.getToolBarManager());
1199 * Add actions to local tool bar manager
1201 * @param manager the tool bar manager
1203 protected void fillLocalToolBar(IToolBarManager manager
) {
1204 if (fTimeGraphWrapper
instanceof TimeGraphComboWrapper
) {
1205 if (fFilterColumns
!= null && fFilterLabelProvider
!= null && fFilterColumns
.length
> 0) {
1206 manager
.add(((TimeGraphComboWrapper
) fTimeGraphWrapper
).getShowFilterAction());
1209 manager
.add(fTimeGraphWrapper
.getTimeGraphViewer().getShowLegendAction());
1210 manager
.add(new Separator());
1211 manager
.add(fTimeGraphWrapper
.getTimeGraphViewer().getResetScaleAction());
1212 manager
.add(fTimeGraphWrapper
.getTimeGraphViewer().getPreviousEventAction());
1213 manager
.add(fTimeGraphWrapper
.getTimeGraphViewer().getNextEventAction());
1214 manager
.add(fPreviousResourceAction
);
1215 manager
.add(fNextResourceAction
);
1216 manager
.add(fTimeGraphWrapper
.getTimeGraphViewer().getZoomInAction());
1217 manager
.add(fTimeGraphWrapper
.getTimeGraphViewer().getZoomOutAction());
1218 manager
.add(new Separator());