tmf: Tweak ITmfStateSystemAnalysisModule
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / views / statesystem / TmfStateSystemExplorer.java
index ec4f1b445b21bc12505d1599500c14dbc4b32b36..3dda6779599c2790110f8d5e85ac0e46672c70c7 100644 (file)
 package org.eclipse.linuxtools.tmf.ui.views.statesystem;
 
 import java.io.File;
+import java.util.HashMap;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Map.Entry;
 
+import org.eclipse.core.runtime.NullProgressMonitor;
 import org.eclipse.jface.action.Action;
 import org.eclipse.jface.action.IToolBarManager;
 import org.eclipse.jface.resource.ImageDescriptor;
 import org.eclipse.linuxtools.internal.tmf.ui.Activator;
+import org.eclipse.linuxtools.tmf.core.analysis.IAnalysisModule;
 import org.eclipse.linuxtools.tmf.core.exceptions.AttributeNotFoundException;
 import org.eclipse.linuxtools.tmf.core.exceptions.StateSystemDisposedException;
 import org.eclipse.linuxtools.tmf.core.exceptions.StateValueTypeException;
@@ -36,6 +40,7 @@ import org.eclipse.linuxtools.tmf.core.signal.TmfTraceClosedSignal;
 import org.eclipse.linuxtools.tmf.core.signal.TmfTraceOpenedSignal;
 import org.eclipse.linuxtools.tmf.core.signal.TmfTraceSelectedSignal;
 import org.eclipse.linuxtools.tmf.core.statesystem.ITmfStateSystem;
+import org.eclipse.linuxtools.tmf.core.statesystem.ITmfAnalysisModuleWithStateSystems;
 import org.eclipse.linuxtools.tmf.core.statevalue.ITmfStateValue;
 import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp;
 import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimestamp;
@@ -167,24 +172,42 @@ public class TmfStateSystemExplorer extends TmfView {
              * We will first do all the queries for this trace, then update that
              * sub-tree in the UI thread.
              */
-            final Map<String, ITmfStateSystem> sss = currentTrace.getStateSystems();
+            Map<String, ITmfAnalysisModuleWithStateSystems> modules = currentTrace.getAnalysisModules(ITmfAnalysisModuleWithStateSystems.class);
+            final Map<String, ITmfStateSystem> sss = new HashMap<>();
             final Map<String, List<ITmfStateInterval>> fullStates =
-                    new LinkedHashMap<String, List<ITmfStateInterval>>();
-            for (Map.Entry<String, ITmfStateSystem> entry : sss.entrySet()) {
-                String ssName = entry.getKey();
-                ITmfStateSystem ss = entry.getValue();
-                ss.waitUntilBuilt();
-                if (ts == -1 || ts < ss.getStartTime() || ts > ss.getCurrentEndTime()) {
-                    ts = ss.getStartTime();
+                    new LinkedHashMap<>();
+            for (Entry<String, ITmfAnalysisModuleWithStateSystems> entry : modules.entrySet()) {
+                /*
+                 * FIXME: For now, this view is a way to execute and display
+                 * state system. But with phase 2 of analysis API, we won't want
+                 * to run state system that have not been requested. We will
+                 * leave the title, but there won't be anything underneath.
+                 */
+                ITmfAnalysisModuleWithStateSystems module = entry.getValue();
+                if (module instanceof IAnalysisModule) {
+                    IAnalysisModule mod = (IAnalysisModule) module;
+                    mod.schedule();
+                    mod.waitForCompletion(new NullProgressMonitor());
                 }
-                try {
-                    fullStates.put(ssName, ss.queryFullState(ts));
-                } catch (TimeRangeException e) {
-                    /* We already checked the limits ourselves */
-                    throw new RuntimeException();
-                } catch (StateSystemDisposedException e) {
-                    /* Probably shutting down, cancel and return */
-                    return;
+                for (ITmfStateSystem ss : module.getStateSystems()) {
+                    if (ss == null) {
+                        continue;
+                    }
+                    String ssName = module.getStateSystemId(ss);
+                    sss.put(ssName, ss);
+
+                    if (ts == -1 || ts < ss.getStartTime() || ts > ss.getCurrentEndTime()) {
+                        ts = ss.getStartTime();
+                    }
+                    try {
+                        fullStates.put(ssName, ss.queryFullState(ts));
+                    } catch (TimeRangeException e) {
+                        /* We already checked the limits ourselves */
+                        throw new IllegalStateException();
+                    } catch (StateSystemDisposedException e) {
+                        /* Probably shutting down, cancel and return */
+                        return;
+                    }
                 }
             }
 
@@ -210,7 +233,9 @@ public class TmfStateSystemExplorer extends TmfView {
                          * Calling with quark '-1' here to start with the root
                          * attribute, then it will be called recursively.
                          */
-                        addChildren(ss, fullState, -1, item);
+                        if (ss != null) {
+                            addChildren(ss, fullState, -1, item);
+                        }
                     }
 
                     /* Expand the first-level tree items */
@@ -266,52 +291,60 @@ public class TmfStateSystemExplorer extends TmfView {
 
         /* For each trace... */
         for (int traceNb = 0; traceNb < traces.length; traceNb++) {
-            Map<String, ITmfStateSystem> sss = traces[traceNb].getStateSystems();
+            Map<String, ITmfAnalysisModuleWithStateSystems> modules = traces[traceNb].getAnalysisModules(ITmfAnalysisModuleWithStateSystems.class);
 
             /* For each state system associated with this trace... */
             int ssNb = 0;
-            for (Map.Entry<String, ITmfStateSystem> entry : sss.entrySet()) {
+            for (Entry<String, ITmfAnalysisModuleWithStateSystems> module : modules.entrySet()) {
+
                 /*
                  * Even though we only use the value, it just feels safer to
                  * iterate the same way as before to keep the order the same.
                  */
-                final ITmfStateSystem ss = entry.getValue();
-                final int traceNb1 = traceNb;
-                final int ssNb1 = ssNb;
-                ts = (ts == -1 ? ss.getStartTime() : ts);
-                try {
-                    final List<ITmfStateInterval> fullState = ss.queryFullState(ts);
-                    fTree.getDisplay().asyncExec(new Runnable() {
-                        @Override
-                        public void run() {
-                            /* Get the tree item of the relevant state system */
-                            TreeItem traceItem = fTree.getItem(traceNb1);
-                            TreeItem item = traceItem.getItem(ssNb1);
-                            /* Update it, then its children, recursively */
-                            item.setText(VALUE_COL, emptyString);
-                            updateChildren(ss, fullState, -1, item);
-                        }
-                    });
-
-                } catch (TimeRangeException e) {
-                    /*
-                     * This can happen in an experiment, if the user selects a
-                     * range valid in the experiment, but this specific does not
-                     * exist. Print "out-of-range" into all the values.
-                     */
-                    fTree.getDisplay().asyncExec(new Runnable() {
-                        @Override
-                        public void run() {
-                            TreeItem traceItem = fTree.getItem(traceNb1);
-                            TreeItem item = traceItem.getItem(ssNb1);
-                            markOutOfRange(item);
+                for (final ITmfStateSystem ss : module.getValue().getStateSystems()) {
+                    final int traceNb1 = traceNb;
+                    final int ssNb1 = ssNb;
+                    if (ss != null) {
+                        ts = (ts == -1 ? ss.getStartTime() : ts);
+                        try {
+                            final List<ITmfStateInterval> fullState = ss.queryFullState(ts);
+                            fTree.getDisplay().asyncExec(new Runnable() {
+                                @Override
+                                public void run() {
+                                    /*
+                                     * Get the tree item of the relevant state
+                                     * system
+                                     */
+                                    TreeItem traceItem = fTree.getItem(traceNb1);
+                                    TreeItem item = traceItem.getItem(ssNb1);
+                                    /* Update it, then its children, recursively */
+                                    item.setText(VALUE_COL, emptyString);
+                                    updateChildren(ss, fullState, -1, item);
+                                }
+                            });
+
+                        } catch (TimeRangeException e) {
+                            /*
+                             * This can happen in an experiment, if the user
+                             * selects a range valid in the experiment, but this
+                             * specific does not exist. Print "out-of-range"
+                             * into all the values.
+                             */
+                            fTree.getDisplay().asyncExec(new Runnable() {
+                                @Override
+                                public void run() {
+                                    TreeItem traceItem = fTree.getItem(traceNb1);
+                                    TreeItem item = traceItem.getItem(ssNb1);
+                                    markOutOfRange(item);
+                                }
+                            });
+                        } catch (StateSystemDisposedException e) {
+                            return;
                         }
-                    });
-                } catch (StateSystemDisposedException e) {
-                    return;
-                }
+                    }
 
-                ssNb++;
+                    ssNb++;
+                }
             }
         }
     }
@@ -357,6 +390,10 @@ public class TmfStateSystemExplorer extends TmfView {
                 value = String.valueOf(state.unboxLong());
                 item.setText(TYPE_COL, Messages.TypeLong);
                 break;
+            case DOUBLE:
+                value = String.valueOf(state.unboxDouble());
+                item.setText(TYPE_COL, Messages.TypeDouble);
+                break;
             case STRING:
                 value = state.unboxStr();
                 item.setText(TYPE_COL, Messages.TypeString);
@@ -481,7 +518,7 @@ public class TmfStateSystemExplorer extends TmfView {
         Thread thread = new Thread("State system visualizer update") { //$NON-NLS-1$
             @Override
             public void run() {
-                ITmfTimestamp currentTime = signal.getCurrentTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE);
+                ITmfTimestamp currentTime = signal.getBeginTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE);
                 fCurrentTimestamp = currentTime.getValue();
 
                 if (filterStatus) {
@@ -503,7 +540,7 @@ public class TmfStateSystemExplorer extends TmfView {
         };
         thread.start();
     }
-    
+
     /**
      * Update the display to use the updated timestamp format
      *
This page took 0.028547 seconds and 5 git commands to generate.