tmf: Mark TmfTraceManager @NonNullByDefault
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.ui / src / org / eclipse / tracecompass / tmf / ui / views / statesystem / TmfStateSystemViewer.java
index e822c93959b750c27b1e22c4126d21e212207fa5..7d803b447fc7596a22865a29408e902bdeec185e 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2014 École Polytechnique de Montréal
+ * Copyright (c) 2014, 2016 École Polytechnique de Montréal and others.
  *
  * All rights reserved. This program and the accompanying materials are
  * made available under the terms of the Eclipse Public License v1.0 which
@@ -29,11 +29,11 @@ import org.eclipse.swt.graphics.Color;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Display;
 import org.eclipse.tracecompass.statesystem.core.ITmfStateSystem;
-import org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException;
 import org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException;
 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.analysis.IAnalysisModule;
 import org.eclipse.tracecompass.tmf.core.signal.TmfSignalHandler;
 import org.eclipse.tracecompass.tmf.core.signal.TmfTimestampFormatUpdateSignal;
 import org.eclipse.tracecompass.tmf.core.statesystem.ITmfAnalysisModuleWithStateSystems;
@@ -42,7 +42,6 @@ import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestamp;
 import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
 import org.eclipse.tracecompass.tmf.core.trace.TmfTraceContext;
 import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager;
-import org.eclipse.tracecompass.tmf.core.trace.TmfTraceUtils;
 import org.eclipse.tracecompass.tmf.ui.viewers.tree.AbstractTmfTreeViewer;
 import org.eclipse.tracecompass.tmf.ui.viewers.tree.ITmfTreeColumnDataProvider;
 import org.eclipse.tracecompass.tmf.ui.viewers.tree.ITmfTreeViewerEntry;
@@ -198,22 +197,28 @@ public class TmfStateSystemViewer extends AbstractTmfTreeViewer {
         TmfTreeViewerEntry rootEntry = new TmfTreeViewerEntry("root"); //$NON-NLS-1$
 
         for (final ITmfTrace trace : TmfTraceManager.getTraceSetWithExperiment(getTrace())) {
-            if (trace != null) {
-                rootEntry.addChild(createTraceEntry(trace));
-            }
+            rootEntry.addChild(createTraceEntry(trace));
         }
         return rootEntry;
     }
 
     private static TmfTreeViewerEntry createTraceEntry(ITmfTrace trace) {
         TmfTreeViewerEntry traceEntry = new TmfTreeViewerEntry(trace.getName());
-        Iterable<ITmfAnalysisModuleWithStateSystems> modules = TmfTraceUtils.getAnalysisModulesOfClass(trace, ITmfAnalysisModuleWithStateSystems.class);
-        for (ITmfAnalysisModuleWithStateSystems module : modules) {
-            /* Just schedule the module, the data will be filled when available */
-            module.schedule();
-            module.waitForInitialization();
-            for (ITmfStateSystem ss : module.getStateSystems()) {
-                traceEntry.addChild(new StateSystemEntry(ss));
+        Iterable<IAnalysisModule> modules = trace.getAnalysisModules();
+        for (IAnalysisModule module : modules) {
+            if (module instanceof ITmfAnalysisModuleWithStateSystems) {
+                ITmfAnalysisModuleWithStateSystems moduleWithStateSystem = (ITmfAnalysisModuleWithStateSystems) module;
+                /*
+                 * Just schedule the module, the data will be filled when
+                 * available
+                 */
+                moduleWithStateSystem.schedule();
+                if (!moduleWithStateSystem.waitForInitialization()) {
+                    continue;
+                }
+                for (ITmfStateSystem ss : moduleWithStateSystem.getStateSystems()) {
+                    traceEntry.addChild(new StateSystemEntry(ss));
+                }
             }
         }
         return traceEntry;
@@ -249,48 +254,44 @@ public class TmfStateSystemViewer extends AbstractTmfTreeViewer {
 
     private boolean updateStateEntries(ITmfStateSystem ss, List<ITmfStateInterval> fullState, TmfTreeViewerEntry parent, int parentQuark, long timestamp) {
         boolean changed = false;
-        try {
-            for (int quark : ss.getSubAttributes(parentQuark, false)) {
-                if (quark >= fullState.size()) {
-                    // attribute was created after the full state query
-                    continue;
-                }
-                ITmfStateInterval interval = fullState.get(quark);
-                StateEntry stateEntry = findStateEntry(parent, quark);
-                if (stateEntry == null) {
-                    boolean modified = fFilterStatus ?
-                            interval.getStartTime() == timestamp :
-                                !interval.getStateValue().isNull();
-                    stateEntry = new StateEntry(ss.getAttributeName(quark), quark, ss.getFullAttributePath(quark),
-                            interval.getStateValue(),
-                            new TmfTimestamp(interval.getStartTime(), ITmfTimestamp.NANOSECOND_SCALE),
-                            new TmfTimestamp(interval.getEndTime(), ITmfTimestamp.NANOSECOND_SCALE),
-                            modified);
-
-                    // update children first to know if parent is really needed
-                    updateStateEntries(ss, fullState, stateEntry, quark, timestamp);
-
-                    /*
-                     * Add this entry to parent if filtering is off, or
-                     * if the entry has children to display, or
-                     * if there is a state change at the current timestamp
-                     */
-                    if (!fFilterStatus || stateEntry.hasChildren() || interval.getStartTime() == timestamp) {
-                        parent.addChild(stateEntry);
-                        changed = true;
-                    }
-                } else {
-                    stateEntry.update(interval.getStateValue(),
-                            new TmfTimestamp(interval.getStartTime(), ITmfTimestamp.NANOSECOND_SCALE),
-                            new TmfTimestamp(interval.getEndTime(), ITmfTimestamp.NANOSECOND_SCALE));
-
-                    // update children recursively
-                    updateStateEntries(ss, fullState, stateEntry, quark, timestamp);
+        for (int quark : ss.getSubAttributes(parentQuark, false)) {
+            if (quark >= fullState.size()) {
+                // attribute was created after the full state query
+                continue;
+            }
+            ITmfStateInterval interval = fullState.get(quark);
+            StateEntry stateEntry = findStateEntry(parent, quark);
+            if (stateEntry == null) {
+                boolean modified = fFilterStatus ?
+                        interval.getStartTime() == timestamp :
+                            !interval.getStateValue().isNull();
+                stateEntry = new StateEntry(ss.getAttributeName(quark), quark, ss.getFullAttributePath(quark),
+                        interval.getStateValue(),
+                        TmfTimestamp.fromNanos(interval.getStartTime()),
+                        TmfTimestamp.fromNanos(interval.getEndTime()),
+                        modified);
+
+                // update children first to know if parent is really needed
+                updateStateEntries(ss, fullState, stateEntry, quark, timestamp);
+
+                /*
+                 * Add this entry to parent if filtering is off, or
+                 * if the entry has children to display, or
+                 * if there is a state change at the current timestamp
+                 */
+                if (!fFilterStatus || stateEntry.hasChildren() || interval.getStartTime() == timestamp) {
+                    parent.addChild(stateEntry);
+                    changed = true;
                 }
+            } else {
+                stateEntry.update(interval.getStateValue(),
+                        TmfTimestamp.fromNanos(interval.getStartTime()),
+                        TmfTimestamp.fromNanos(interval.getEndTime()));
 
+                // update children recursively
+                updateStateEntries(ss, fullState, stateEntry, quark, timestamp);
             }
-        } catch (AttributeNotFoundException e) {
-            /* Should not happen, we're iterating on known attributes */
+
         }
         return changed;
     }
@@ -363,13 +364,13 @@ public class TmfStateSystemViewer extends AbstractTmfTreeViewer {
 
         private final int fQuark;
         private final String fFullPath;
-        private @NonNull TmfTimestamp fStart;
-        private @NonNull TmfTimestamp fEnd;
+        private @NonNull ITmfTimestamp fStart;
+        private @NonNull ITmfTimestamp fEnd;
         private ITmfStateValue fValue;
         private boolean fModified;
         private boolean fOutOfRange = false;
 
-        public StateEntry(String name, int quark, String fullPath, ITmfStateValue value, @NonNull TmfTimestamp start, @NonNull TmfTimestamp end, boolean modified) {
+        public StateEntry(String name, int quark, String fullPath, ITmfStateValue value, @NonNull ITmfTimestamp start, @NonNull ITmfTimestamp end, boolean modified) {
             super(name);
             fQuark = quark;
             fFullPath = fullPath;
@@ -410,6 +411,7 @@ public class TmfStateSystemViewer extends AbstractTmfTreeViewer {
             case LONG:
             case DOUBLE:
             case STRING:
+            case CUSTOM:
                 return fValue.toString();
             case NULL:
             default:
@@ -430,6 +432,8 @@ public class TmfStateSystemViewer extends AbstractTmfTreeViewer {
                 return Messages.TypeDouble;
             case STRING:
                 return Messages.TypeString;
+            case CUSTOM:
+                return Messages.TypeCustom;
             case NULL:
             default:
                 return EMPTY_STRING;
@@ -440,7 +444,7 @@ public class TmfStateSystemViewer extends AbstractTmfTreeViewer {
             return fModified;
         }
 
-        public void update(ITmfStateValue value, @NonNull TmfTimestamp start, @NonNull TmfTimestamp end) {
+        public void update(ITmfStateValue value, @NonNull ITmfTimestamp start, @NonNull ITmfTimestamp end) {
             fModified = false;
             fOutOfRange = false;
             if (!start.equals(fStart)) {
This page took 0.030595 seconds and 5 git commands to generate.