ss: Move plugins to Trace Compass namespace
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / views / timegraph / AbstractTimeGraphView.java
index 1c5dc2d5be8208d63aa153c9412352bcbb8020c2..18db3cc48e519306796b225e63aa8e565dc7612c 100644 (file)
@@ -17,6 +17,7 @@
 package org.eclipse.linuxtools.tmf.ui.views.timegraph;
 
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collections;
 import java.util.Comparator;
 import java.util.HashMap;
@@ -26,11 +27,13 @@ import java.util.concurrent.CopyOnWriteArrayList;
 
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.jdt.annotation.Nullable;
 import org.eclipse.jface.action.Action;
 import org.eclipse.jface.action.IAction;
 import org.eclipse.jface.action.IStatusLineManager;
 import org.eclipse.jface.action.IToolBarManager;
 import org.eclipse.jface.action.Separator;
+import org.eclipse.jface.viewers.ILabelProvider;
 import org.eclipse.jface.viewers.ILabelProviderListener;
 import org.eclipse.jface.viewers.ISelectionProvider;
 import org.eclipse.jface.viewers.ITableLabelProvider;
@@ -49,15 +52,16 @@ import org.eclipse.linuxtools.tmf.core.timestamp.TmfNanoTimestamp;
 import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimeRange;
 import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
 import org.eclipse.linuxtools.tmf.core.trace.TmfTraceManager;
+import org.eclipse.linuxtools.tmf.ui.TmfUiRefreshHandler;
 import org.eclipse.linuxtools.tmf.ui.views.TmfView;
 import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphContentProvider;
+import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphPresentationProvider2;
 import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphRangeListener;
 import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphSelectionListener;
 import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphTimeListener;
 import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TimeGraphCombo;
 import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TimeGraphPresentationProvider;
 import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TimeGraphRangeUpdateEvent;
-import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TimeGraphSelectionEvent;
 import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TimeGraphTimeEvent;
 import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TimeGraphViewer;
 import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ILinkEvent;
@@ -386,7 +390,7 @@ public abstract class AbstractTimeGraphView extends TmfView {
      * this class typically need to override the getColumnText method if they
      * have more than one column to display
      */
-    protected static class TreeLabelProvider implements ITableLabelProvider {
+    protected static class TreeLabelProvider implements ITableLabelProvider, ILabelProvider {
 
         @Override
         public void addListener(ILabelProviderListener listener) {
@@ -419,6 +423,23 @@ public abstract class AbstractTimeGraphView extends TmfView {
             return new String();
         }
 
+        /**
+         * @since 3.2
+         */
+        @Override
+        public Image getImage(Object element) {
+            return null;
+        }
+
+        /**
+         * @since 3.2
+         */
+        @Override
+        public String getText(Object element) {
+            TimeGraphEntry entry = (TimeGraphEntry) element;
+            return entry.getName();
+        }
+
     }
 
     private class BuildThread extends Thread {
@@ -491,11 +512,13 @@ public abstract class AbstractTimeGraphView extends TmfView {
                 }
             }
             redraw();
-            for (TimeGraphEntry child : entry.getChildren()) {
+            for (ITimeGraphEntry child : entry.getChildren()) {
                 if (fMonitor.isCanceled()) {
                     return;
                 }
-                zoom(child, monitor);
+                if (child instanceof TimeGraphEntry) {
+                    zoom((TimeGraphEntry) child, monitor);
+                }
             }
         }
 
@@ -552,6 +575,16 @@ public abstract class AbstractTimeGraphView extends TmfView {
         return fTimeGraphWrapper.getTimeGraphViewer();
     }
 
+    /**
+     * Getter for the presentation provider
+     *
+     * @return The time graph presentation provider
+     * @since 3.0
+     */
+    protected ITimeGraphPresentationProvider2 getPresentationProvider() {
+        return fPresentation;
+    }
+
     /**
      * Sets the tree column labels.
      * This should be called from the constructor.
@@ -835,13 +868,6 @@ public abstract class AbstractTimeGraphView extends TmfView {
             }
         });
 
-        fTimeGraphWrapper.addSelectionListener(new ITimeGraphSelectionListener() {
-            @Override
-            public void selectionChanged(TimeGraphSelectionEvent event) {
-                // ITimeGraphEntry selection = event.getSelection();
-            }
-        });
-
         fTimeGraphWrapper.getTimeGraphViewer().setTimeFormat(TimeFormat.CALENDAR);
 
         IStatusLineManager statusLineManager = getViewSite().getActionBars().getStatusLineManager();
@@ -907,7 +933,7 @@ public abstract class AbstractTimeGraphView extends TmfView {
     @TmfSignalHandler
     public void traceClosed(final TmfTraceClosedSignal signal) {
         synchronized (fBuildThreadMap) {
-            for (ITmfTrace trace : TmfTraceManager.getTraceSet(signal.getTrace())) {
+            for (ITmfTrace trace : getTracesToBuild(signal.getTrace())) {
                 BuildThread buildThread = fBuildThreadMap.remove(trace);
                 if (buildThread != null) {
                     buildThread.cancel();
@@ -1005,15 +1031,7 @@ public abstract class AbstractTimeGraphView extends TmfView {
         synchronized (fEntryListMap) {
             fEntryList = fEntryListMap.get(fTrace);
             if (fEntryList == null) {
-                setStartTime(Long.MAX_VALUE);
-                setEndTime(Long.MIN_VALUE);
-                synchronized (fBuildThreadMap) {
-                    for (ITmfTrace trace : TmfTraceManager.getTraceSet(fTrace)) {
-                        BuildThread buildThread = new BuildThread(trace, fTrace, getName());
-                        fBuildThreadMap.put(trace, buildThread);
-                        buildThread.start();
-                    }
-                }
+                rebuild();
             } else {
                 fStartTime = fTrace.getStartTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue();
                 fEndTime = fTrace.getEndTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue();
@@ -1022,6 +1040,22 @@ public abstract class AbstractTimeGraphView extends TmfView {
         }
     }
 
+    /**
+     * Forces a rebuild of the entries list, even if entries already exist for this trace
+     * @since 3.0
+     */
+    protected void rebuild() {
+        setStartTime(Long.MAX_VALUE);
+        setEndTime(Long.MIN_VALUE);
+        synchronized (fBuildThreadMap) {
+            for (ITmfTrace trace : getTracesToBuild(fTrace)) {
+                BuildThread buildThread = new BuildThread(trace, fTrace, getName());
+                fBuildThreadMap.put(trace, buildThread);
+                buildThread.start();
+            }
+        }
+    }
+
     /**
      * Method called when synching to a given timestamp. Inheriting classes can
      * perform actions here to update the view at the given timestamp.
@@ -1033,6 +1067,23 @@ public abstract class AbstractTimeGraphView extends TmfView {
 
     }
 
+    /**
+     * Return the list of traces whose data or analysis results will be used to
+     * populate the view. By default, if the trace is an experiment, the traces
+     * under it will be returned, otherwise, the trace itself is returned.
+     *
+     * A build thread will be started for each trace returned by this method,
+     * some of which may receive events in live streaming mode.
+     *
+     * @param trace
+     *            The trace associated with this view
+     * @return List of traces with data to display
+     * @since 3.0
+     */
+    protected Iterable<ITmfTrace> getTracesToBuild(ITmfTrace trace) {
+        return Arrays.asList(TmfTraceManager.getTraceSet(trace));
+    }
+
     /**
      * Build the entries list to show in this time graph
      *
@@ -1063,7 +1114,7 @@ public abstract class AbstractTimeGraphView extends TmfView {
      *            The progress monitor object
      * @return The list of events for the entry
      */
-    protected abstract List<ITimeEvent> getEventList(TimeGraphEntry entry,
+    protected abstract @Nullable List<ITimeEvent> getEventList(TimeGraphEntry entry,
             long startTime, long endTime, long resolution,
             IProgressMonitor monitor);
 
@@ -1092,7 +1143,7 @@ public abstract class AbstractTimeGraphView extends TmfView {
      * Refresh the display
      */
     protected void refresh() {
-        Display.getDefault().asyncExec(new Runnable() {
+        TmfUiRefreshHandler.getInstance().queueUpdate(this, new Runnable() {
             @Override
             public void run() {
                 if (fTimeGraphWrapper.isDisposed()) {
This page took 0.027093 seconds and 5 git commands to generate.