xml: bug 493954: Allow string states to be displayed in time graph views
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.analysis.xml.ui / src / org / eclipse / tracecompass / internal / tmf / analysis / xml / ui / views / timegraph / XmlTimeGraphView.java
index aa9f8fe7da0e604855866f7d131415bd564f0ea2..41b3c9a50d20b7432f38fa92ddd35fd8a0e9f61a 100644 (file)
@@ -32,7 +32,6 @@ import org.eclipse.jdt.annotation.NonNull;
 import org.eclipse.jface.util.IPropertyChangeListener;
 import org.eclipse.jface.util.PropertyChangeEvent;
 import org.eclipse.swt.widgets.Display;
-import org.eclipse.tracecompass.common.core.NonNullUtils;
 import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model.ITmfXmlModelFactory;
 import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model.ITmfXmlStateAttribute;
 import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model.readonly.TmfXmlReadOnlyModelFactory;
@@ -50,9 +49,9 @@ import org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedE
 import org.eclipse.tracecompass.statesystem.core.exceptions.StateValueTypeException;
 import org.eclipse.tracecompass.statesystem.core.exceptions.TimeRangeException;
 import org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval;
+import org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue;
 import org.eclipse.tracecompass.tmf.core.statesystem.ITmfAnalysisModuleWithStateSystems;
 import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
-import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager;
 import org.eclipse.tracecompass.tmf.core.trace.TmfTraceUtils;
 import org.eclipse.tracecompass.tmf.ui.views.timegraph.AbstractTimeGraphView;
 import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.ITimeGraphPresentationProvider2;
@@ -99,6 +98,7 @@ public class XmlTimeGraphView extends AbstractTimeGraphView {
 
     private final @NonNull XmlViewInfo fViewInfo = new XmlViewInfo(ID);
     private final ITmfXmlModelFactory fFactory;
+    private final Map<String, Integer> fStringValueMap = new HashMap<>();
 
     // ------------------------------------------------------------------------
     // Constructors
@@ -245,6 +245,10 @@ public class XmlTimeGraphView extends AbstractTimeGraphView {
             title = Messages.XmlTimeGraphView_DefaultTitle;
         }
         setViewTitle(title);
+
+        // Empty the additional state values
+        fStringValueMap.clear();
+
         Set<String> analysisIds = fViewInfo.getViewAnalysisIds(viewElement);
 
         List<Element> entries = XmlUtils.getChildElements(viewElement, TmfXmlUiStrings.ENTRY_ELEMENT);
@@ -493,7 +497,7 @@ public class XmlTimeGraphView extends AbstractTimeGraphView {
                     if (monitor.isCanceled()) {
                         return null;
                     }
-                    int status = statusInterval.getStateValue().unboxInt();
+                    int status = getStatusFromInterval(statusInterval);
                     long time = statusInterval.getStartTime();
                     long duration = statusInterval.getEndTime() - time + 1;
                     if (!statusInterval.getStateValue().isNull()) {
@@ -514,52 +518,46 @@ public class XmlTimeGraphView extends AbstractTimeGraphView {
         return eventList;
     }
 
+    private int getStatusFromInterval(ITmfStateInterval statusInterval) {
+        ITmfStateValue stateValue = statusInterval.getStateValue();
+        int status = -1;
+        switch (stateValue.getType()) {
+        case INTEGER:
+        case NULL:
+            status = stateValue.unboxInt();
+            break;
+        case LONG:
+            status = (int) stateValue.unboxLong();
+            break;
+        case STRING:
+            String statusStr = stateValue.unboxStr();
+            Integer statusInt = fStringValueMap.get(statusStr);
+            if (statusInt != null) {
+                status = statusInt;
+                break;
+            }
+            ITimeGraphPresentationProvider2 pres = this.getPresentationProvider();
+            if (pres instanceof XmlPresentationProvider) {
+                // Add this new state to the presentation provider
+                status = ((XmlPresentationProvider) pres).addState(statusStr);
+                fStringValueMap.put(statusStr, status);
+            }
+            break;
+        case DOUBLE:
+            status = (int) stateValue.unboxDouble();
+            break;
+        case CUSTOM:
+        default:
+            break;
+        }
+
+        return status;
+    }
+
     @Override
     protected List<ILinkEvent> getLinkList(long startTime, long endTime, long resolution, IProgressMonitor monitor) {
         /* TODO: not implemented yet, need XML to go along */
         return Collections.EMPTY_LIST;
     }
 
-    /**
-     * This method will pre-filter the traces that contain analysis modules
-     * supported by this view, whether they are from a trace or an experiment.
-     */
-    @Override
-    protected Iterable<ITmfTrace> getTracesToBuild(ITmfTrace trace) {
-        /*
-         * Get the view element from the XML file. If the element can't be
-         * found, return.
-         */
-        Element viewElement = fViewInfo.getViewElement(TmfXmlUiStrings.TIME_GRAPH_VIEW);
-        if (viewElement == null) {
-            return super.getTracesToBuild(trace);
-        }
-
-        Set<String> analysisIds = fViewInfo.getViewAnalysisIds(viewElement);
-        Set<ITmfTrace> traces = new HashSet<>();
-
-        for (ITmfTrace aTrace : TmfTraceManager.getTraceSetWithExperiment(trace)) {
-            if (aTrace == null) {
-                continue;
-            }
-            if ((analysisIds.isEmpty() && TmfTraceUtils.getAnalysisModulesOfClass(aTrace, ITmfAnalysisModuleWithStateSystems.class).iterator().hasNext())) {
-                /*
-                 * No analysis ID specified, so this trace will be built only if
-                 * it has state system modules
-                 */
-                traces.add(aTrace);
-            } else {
-                /* Build this trace only if it has one the requested modules */
-                for (String moduleId : analysisIds) {
-                    if (TmfTraceUtils.getAnalysisModuleOfClass(aTrace, ITmfAnalysisModuleWithStateSystems.class, NonNullUtils.checkNotNull(moduleId)) != null) {
-                        traces.add(aTrace);
-                    }
-                }
-            }
-        }
-        if (traces.isEmpty()) {
-            return super.getTracesToBuild(trace);
-        }
-        return traces;
-    }
 }
This page took 0.027586 seconds and 5 git commands to generate.