tmf: Support dynamic marker event sources
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.ui / src / org / eclipse / tracecompass / tmf / ui / views / timegraph / AbstractStateSystemTimeGraphView.java
index 5cd5fcc0ad749aa1f7927dec44c628954ce4bbcc..5b24998db1e9445e2f10a33dc38b04f4ce65d60c 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2015 Ericsson
+ * Copyright (c) 2015, 2016 Ericsson
  *
  * All rights reserved. This program and the accompanying materials are
  * made available under the terms of the Eclipse Public License v1.0 which
@@ -19,20 +19,20 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.logging.Logger;
 
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.jdt.annotation.NonNull;
 import org.eclipse.jdt.annotation.Nullable;
+import org.eclipse.tracecompass.common.core.log.TraceCompassLog;
 import org.eclipse.tracecompass.statesystem.core.ITmfStateSystem;
 import org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException;
 import org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval;
-import org.eclipse.tracecompass.tmf.core.signal.TmfSignalHandler;
-import org.eclipse.tracecompass.tmf.core.signal.TmfTraceClosedSignal;
 import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
 import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.TimeGraphPresentationProvider;
 import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ILinkEvent;
+import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.IMarkerEvent;
 import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeEvent;
-import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeGraphEntry;
 import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.TimeGraphEntry;
 
 import com.google.common.collect.HashMultimap;
@@ -44,7 +44,7 @@ import com.google.common.collect.Multimap;
  * order before creating the time event lists as this is optimal for state
  * system queries.
  *
- * @since 2.0
+ * @since 1.1
  */
 public abstract class AbstractStateSystemTimeGraphView extends AbstractTimeGraphView {
 
@@ -59,11 +59,13 @@ public abstract class AbstractStateSystemTimeGraphView extends AbstractTimeGraph
     // ------------------------------------------------------------------------
 
     /** The state system to entry list hash map */
-    private final Map<ITmfStateSystem, List<TimeGraphEntry>> fSSEntryListMap = new HashMap<>();
+    private final Map<ITmfStateSystem, List<@NonNull TimeGraphEntry>> fSSEntryListMap = new HashMap<>();
 
     /** The trace to state system multi map */
     private final Multimap<ITmfTrace, ITmfStateSystem> fTraceSSMap = HashMultimap.create();
 
+    private static final Logger LOGGER = TraceCompassLog.getLogger(AbstractStateSystemTimeGraphView.class);
+
     // ------------------------------------------------------------------------
     // Classes
     // ------------------------------------------------------------------------
@@ -97,8 +99,9 @@ public abstract class AbstractStateSystemTimeGraphView extends AbstractTimeGraph
         }
 
         @Override
-        public void run() {
+        public void doRun() {
             final List<ILinkEvent> links = new ArrayList<>();
+            final List<IMarkerEvent> markers = new ArrayList<>();
             if (fClearZoomedLists) {
                 clearZoomedLists();
             }
@@ -108,11 +111,19 @@ public abstract class AbstractStateSystemTimeGraphView extends AbstractTimeGraph
                     entryList = fSSEntryListMap.get(ss);
                 }
                 if (entryList != null) {
-                    zoomByTime(ss, entryList, links, getZoomStartTime(), getZoomEndTime(), getResolution(), getMonitor());
+                    zoomByTime(ss, entryList, links, markers, getZoomStartTime(), getZoomEndTime(), getResolution(), getMonitor());
                 }
             }
             if (!getMonitor().isCanceled()) {
-                getTimeGraphViewer().setLinks(links);
+                /* Refresh the trace-specific markers when zooming */
+                markers.addAll(getTraceMarkerList(getZoomStartTime(), getZoomEndTime(), getResolution(), getMonitor()));
+                applyResults(() -> {
+                    getTimeGraphViewer().setLinks(links);
+                    getTimeGraphViewer().setMarkerCategories(getMarkerCategories());
+                    getTimeGraphViewer().setMarkers(markers);
+                });
+            } else {
+                LOGGER.info(() -> "[TimeGraphView:ZoomThreadCanceled]"); //$NON-NLS-1$
             }
         }
 
@@ -124,7 +135,7 @@ public abstract class AbstractStateSystemTimeGraphView extends AbstractTimeGraph
             }
         }
 
-        private void zoomByTime(final ITmfStateSystem ss, final List<TimeGraphEntry> entryList, final List<ILinkEvent> links,
+        private void zoomByTime(final ITmfStateSystem ss, final List<TimeGraphEntry> entryList, final List<ILinkEvent> links, final List<IMarkerEvent> markers,
                 long startTime, long endTime, long resolution, final @NonNull IProgressMonitor monitor) {
             final long start = Math.max(startTime, ss.getStartTime());
             final long end = Math.min(endTime, ss.getCurrentEndTime());
@@ -138,13 +149,19 @@ public abstract class AbstractStateSystemTimeGraphView extends AbstractTimeGraph
             queryFullStates(ss, start, end, resolution, monitor, new IQueryHandler() {
                 @Override
                 public void handle(@NonNull List<List<ITmfStateInterval>> fullStates, @Nullable List<ITmfStateInterval> prevFullState) {
+                    LOGGER.config(() -> "[TimeGraphView:ZoomThreadGettingStates]"); //$NON-NLS-1$
                     if (!fullRange) {
                         for (TimeGraphEntry entry : entryList) {
                             zoom(checkNotNull(entry), ss, fullStates, prevFullState, monitor);
                         }
                     }
                     /* Refresh the arrows when zooming */
-                    links.addAll(getLinkList(ss, fullStates, monitor));
+                    LOGGER.config(() -> "[TimeGraphView:ZoomThreadGettingLinks]"); //$NON-NLS-1$
+                    links.addAll(getLinkList(ss, fullStates, prevFullState, monitor));
+                    /* Refresh the view-specific markers when zooming */
+                    LOGGER.config(() -> "[TimeGraphView:ZoomThreadGettingMarkers]"); //$NON-NLS-1$
+                    markers.addAll(getViewMarkerList(ss, fullStates, prevFullState, monitor));
+                    LOGGER.config(() -> "[TimeGraphView:ZoomThreadDone]"); //$NON-NLS-1$
                 }
             });
             refresh();
@@ -153,17 +170,21 @@ public abstract class AbstractStateSystemTimeGraphView extends AbstractTimeGraph
         private void zoom(@NonNull TimeGraphEntry entry, ITmfStateSystem ss, @NonNull List<List<ITmfStateInterval>> fullStates, @Nullable List<ITmfStateInterval> prevFullState, @NonNull IProgressMonitor monitor) {
             List<ITimeEvent> eventList = getEventList(entry, ss, fullStates, prevFullState, monitor);
             if (eventList != null) {
-                for (ITimeEvent event : eventList) {
-                    entry.addZoomedEvent(event);
-                }
+                applyResults(() -> {
+                    for (ITimeEvent event : eventList) {
+                        if (monitor.isCanceled()) {
+                            return;
+                        }
+                        entry.addZoomedEvent(event);
+                    }
+                });
             }
-            for (ITimeGraphEntry child : entry.getChildren()) {
+            for (TimeGraphEntry child : entry.getChildren()) {
                 if (monitor.isCanceled()) {
+                    LOGGER.info(() -> "[TimeGraphView:ZoomThreadCanceled]"); //$NON-NLS-1$
                     return;
                 }
-                if (child instanceof TimeGraphEntry) {
-                    zoom((TimeGraphEntry) child, ss, fullStates, prevFullState, monitor);
-                }
+                zoom(child, ss, fullStates, prevFullState, monitor);
             }
         }
 
@@ -184,10 +205,8 @@ public abstract class AbstractStateSystemTimeGraphView extends AbstractTimeGraph
 
         private void clearZoomedList(TimeGraphEntry entry) {
             entry.setZoomedEventList(null);
-            for (ITimeGraphEntry child : entry.getChildren()) {
-                if (child instanceof TimeGraphEntry) {
-                    clearZoomedList((TimeGraphEntry) child);
-                }
+            for (TimeGraphEntry child : entry.getChildren()) {
+                clearZoomedList(child);
             }
         }
     }
@@ -225,7 +244,7 @@ public abstract class AbstractStateSystemTimeGraphView extends AbstractTimeGraph
      *
      * @return the entry list map
      */
-    protected List<TimeGraphEntry> getEntryList(ITmfStateSystem ss) {
+    protected List<@NonNull TimeGraphEntry> getEntryList(ITmfStateSystem ss) {
         synchronized (fSSEntryListMap) {
             return fSSEntryListMap.get(ss);
         }
@@ -241,7 +260,7 @@ public abstract class AbstractStateSystemTimeGraphView extends AbstractTimeGraph
      * @param list
      *            the list of time graph entries
      */
-    protected void putEntryList(ITmfTrace trace, ITmfStateSystem ss, List<TimeGraphEntry> list) {
+    protected void putEntryList(ITmfTrace trace, ITmfStateSystem ss, List<@NonNull TimeGraphEntry> list) {
         super.putEntryList(trace, list);
         synchronized (fSSEntryListMap) {
             fSSEntryListMap.put(ss, new CopyOnWriteArrayList<>(list));
@@ -259,10 +278,10 @@ public abstract class AbstractStateSystemTimeGraphView extends AbstractTimeGraph
      * @param list
      *            the list of time graph entries to add
      */
-    protected void addToEntryList(ITmfTrace trace, ITmfStateSystem ss, List<TimeGraphEntry> list) {
+    protected void addToEntryList(ITmfTrace trace, ITmfStateSystem ss, List<@NonNull TimeGraphEntry> list) {
         super.addToEntryList(trace, list);
         synchronized (fSSEntryListMap) {
-            List<TimeGraphEntry> entryList = fSSEntryListMap.get(ss);
+            List<@NonNull TimeGraphEntry> entryList = fSSEntryListMap.get(ss);
             if (entryList == null) {
                 fSSEntryListMap.put(ss, new CopyOnWriteArrayList<>(list));
             } else {
@@ -355,6 +374,10 @@ public abstract class AbstractStateSystemTimeGraphView extends AbstractTimeGraph
 
     /**
      * Gets the list of events for an entry for a given list of full states.
+     * <p>
+     * Called from the ZoomThread for every entry to update the zoomed event
+     * list. Can be an empty implementation if the view does not support zoomed
+     * event lists. Can also be used to compute the full event list.
      *
      * @param tgentry
      *            The time graph entry
@@ -379,12 +402,35 @@ public abstract class AbstractStateSystemTimeGraphView extends AbstractTimeGraph
      *            The state system
      * @param fullStates
      *            A list of full states
+     * @param prevFullState
+     *            The previous full state, or null
      * @param monitor
      *            A progress monitor
      * @return The list of link events
+     * @since 2.0
      */
     protected @NonNull List<ILinkEvent> getLinkList(ITmfStateSystem ss,
-            @NonNull List<List<ITmfStateInterval>> fullStates, @NonNull IProgressMonitor monitor) {
+            @NonNull List<List<ITmfStateInterval>> fullStates, @Nullable List<ITmfStateInterval> prevFullState, @NonNull IProgressMonitor monitor) {
+        return new ArrayList<>();
+    }
+
+    /**
+     * Gets the list of markers for a given list of full
+     * states. The default implementation returns an empty list.
+     *
+     * @param ss
+     *            The state system
+     * @param fullStates
+     *            A list of full states
+     * @param prevFullState
+     *            The previous full state, or null
+     * @param monitor
+     *            A progress monitor
+     * @return The list of marker events
+     * @since 2.0
+     */
+    protected @NonNull List<IMarkerEvent> getViewMarkerList(ITmfStateSystem ss,
+            @NonNull List<List<ITmfStateInterval>> fullStates, @Nullable List<ITmfStateInterval> prevFullState, @NonNull IProgressMonitor monitor) {
         return new ArrayList<>();
     }
 
@@ -434,7 +480,7 @@ public abstract class AbstractStateSystemTimeGraphView extends AbstractTimeGraph
     }
 
     /**
-     * @deprecated The subclass should implement {@link #getLinkList(ITmfStateSystem, List, IProgressMonitor)} instead.
+     * @deprecated The subclass should implement {@link #getLinkList(ITmfStateSystem, List, List, IProgressMonitor)} instead.
      */
     @Deprecated
     @Override
@@ -442,16 +488,21 @@ public abstract class AbstractStateSystemTimeGraphView extends AbstractTimeGraph
         throw new UnsupportedOperationException();
     }
 
-    // ------------------------------------------------------------------------
-    // Signal handlers
-    // ------------------------------------------------------------------------
+    /**
+     * @deprecated The subclass should implement {@link #getViewMarkerList(ITmfStateSystem, List, List, IProgressMonitor)} instead.
+     */
+    @Deprecated
+    @Override
+    protected final List<IMarkerEvent> getViewMarkerList(long startTime, long endTime, long resolution, IProgressMonitor monitor) {
+        throw new UnsupportedOperationException();
+    }
 
-    @TmfSignalHandler
     @Override
-    public void traceClosed(final TmfTraceClosedSignal signal) {
-        super.traceClosed(signal);
+    protected void resetView(ITmfTrace viewTrace) {
+        // Don't remove super call
+        super.resetView(viewTrace);
         synchronized (fSSEntryListMap) {
-            for (ITmfStateSystem ss : fTraceSSMap.removeAll(signal.getTrace())) {
+            for (ITmfStateSystem ss : fTraceSSMap.removeAll(viewTrace)) {
                 fSSEntryListMap.remove(ss);
             }
         }
This page took 0.02773 seconds and 5 git commands to generate.