tmf: Put analyses under their own node in the Project View
authorAlexandre Montplaisir <alexmonthy@efficios.com>
Tue, 23 Feb 2016 02:00:19 +0000 (21:00 -0500)
committerAlexandre Montplaisir <alexmonthy@efficios.com>
Mon, 2 May 2016 20:41:41 +0000 (16:41 -0400)
Moves all the analysis/views element under a trace to a new
sub-tree called "Views".

First part of implementing Proposal #2 at
https://wiki.eclipse.org/Trace_Compass/Design_Documents/Project_View#Proposal_2

Change-Id: Icfe0f779b61db1c0a84845b87273d33b8d9cf9dc
Signed-off-by: Alexandre Montplaisir <alexmonthy@efficios.com>
Reviewed-on: https://git.eclipse.org/r/69071
Reviewed-by: Hudson CI
Reviewed-by: Patrick Tasse <patrick.tasse@gmail.com>
Tested-by: Patrick Tasse <patrick.tasse@gmail.com>
tmf/org.eclipse.tracecompass.tmf.ui.tests/src/org/eclipse/tracecompass/tmf/ui/tests/project/model/ProjectModelAnalysisTest.java
tmf/org.eclipse.tracecompass.tmf.ui.tests/src/org/eclipse/tracecompass/tmf/ui/tests/project/model/ProjectModelOutputTest.java
tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/project/model/Messages.java
tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/project/model/TmfAnalysisElement.java
tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/project/model/TmfAnalysisOutputElement.java
tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/project/model/TmfCommonProjectElement.java
tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/project/model/TmfExperimentElement.java
tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/project/model/TmfProjectModelIcons.java
tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/project/model/TmfViewsElement.java [new file with mode: 0644]
tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/project/model/messages.properties

index 0a271f8784bd774e574e2c0888b4d6b1e75efdc4..bb907db14cc1e4221b9f05c70802452842f5ae29 100644 (file)
@@ -15,9 +15,11 @@ package org.eclipse.tracecompass.tmf.ui.tests.project.model;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
 import java.util.List;
+import java.util.Optional;
 import java.util.concurrent.TimeoutException;
 
 import org.eclipse.core.runtime.CoreException;
@@ -26,6 +28,7 @@ import org.eclipse.tracecompass.tmf.ui.project.model.ITmfProjectModelElement;
 import org.eclipse.tracecompass.tmf.ui.project.model.TmfAnalysisElement;
 import org.eclipse.tracecompass.tmf.ui.project.model.TmfProjectElement;
 import org.eclipse.tracecompass.tmf.ui.project.model.TmfTraceElement;
+import org.eclipse.tracecompass.tmf.ui.project.model.TmfViewsElement;
 import org.eclipse.tracecompass.tmf.ui.tests.shared.ProjectModelTestData;
 import org.eclipse.tracecompass.tmf.ui.tests.stubs.analysis.TestAnalysisUi;
 import org.junit.After;
@@ -108,23 +111,23 @@ public class ProjectModelAnalysisTest {
     public void testPopulate() {
         TmfTraceElement trace = getTraceElement();
 
-        /* Make sure the analysis list is not empty */
-        List<ITmfProjectModelElement> analysisList = trace.getChildren();
-        assertFalse(analysisList.isEmpty());
+        /* Make sure the list of views is there and not empty */
+        Optional<TmfViewsElement> possibleViewsElem = trace.getChildren()
+                .stream()
+                .filter(child -> child instanceof TmfViewsElement)
+                .map(elem -> (TmfViewsElement) elem)
+                .findFirst();
+        assertTrue(possibleViewsElem.isPresent());
+        TmfViewsElement viewsElem = possibleViewsElem.get();
 
         /* Make sure TestAnalysisUi is there */
-        TmfAnalysisElement analysis = null;
-        for (ITmfProjectModelElement element : analysisList) {
-            if (element instanceof TmfAnalysisElement) {
-                TmfAnalysisElement analysisElement = (TmfAnalysisElement) element;
-                if (analysisElement.getAnalysisId().equals(MODULE_UI)) {
-                    analysis = analysisElement;
-                }
-            }
-        }
-        assertNotNull(analysis);
-
-        assertEquals("Test analysis in UI", analysis.getName());
+        Optional<TmfAnalysisElement> possibleAnalysisElem = viewsElem.getChildren().stream()
+                .filter(child -> child instanceof TmfAnalysisElement)
+                .map(elem -> (TmfAnalysisElement) elem)
+                .filter(analysisElem -> analysisElem.getAnalysisId().equals(MODULE_UI))
+                .findFirst();
+        assertTrue(possibleAnalysisElem.isPresent());
+        assertEquals("Test analysis in UI", possibleAnalysisElem.get().getName());
     }
 
     /**
@@ -134,17 +137,13 @@ public class ProjectModelAnalysisTest {
     public void testInstantiate() {
         TmfTraceElement traceElement = getTraceElement();
 
-        TmfAnalysisElement analysis = null;
-        for (TmfAnalysisElement analysisElement : traceElement.getAvailableAnalysis()) {
-            if (analysisElement.getAnalysisId().equals(MODULE_UI)) {
-                analysis = analysisElement;
-            }
-        }
-        assertNotNull(analysis);
+        TmfAnalysisElement analysis = traceElement.getAvailableAnalysis().stream()
+                .filter(availableAnalysis -> availableAnalysis.getAnalysisId().equals(MODULE_UI))
+                .findFirst().get();
 
         /* Instantiate an analysis on a trace that is closed */
         traceElement.closeEditors();
-        analysis.activateParent();
+        analysis.activateParentTrace();
 
         try {
             ProjectModelTestData.delayUntilTraceOpened(traceElement);
index 7195161b2be79bc3f44ac7707f0fe1a7d6cc4dc1..157b07f3375ba14cd6d3c30ef8330f67cad3ae77 100644 (file)
@@ -105,7 +105,7 @@ public class ProjectModelOutputTest {
         TmfAnalysisElement analysis = getTestAnalysisUi();
 
         /* To get the list of outputs the trace needs to be opened */
-        analysis.activateParent();
+        analysis.activateParentTrace();
         try {
             ProjectModelTestData.delayUntilTraceOpened(analysis.getParent());
         } catch (TimeoutException e) {
@@ -134,7 +134,7 @@ public class ProjectModelOutputTest {
     public void testOpenView() {
         TmfAnalysisElement analysis = getTestAnalysisUi();
 
-        analysis.activateParent();
+        analysis.activateParentTrace();
         try {
             ProjectModelTestData.delayUntilTraceOpened(analysis.getParent());
         } catch (TimeoutException e) {
index ccc068db483e123f3a8d7f937e09383432870b2f..77b8e534236d3855d4eecc53d1de3103c9aacb70 100644 (file)
@@ -101,6 +101,11 @@ public class Messages extends NLS {
 
     /** Trace text */
     public static String TmfTraceElement_TypeName;
+
+    /** Name of the "Views" element
+     * @since 2.0*/
+    public static String TmfViewsElement_Name;
+
     /**
      * The title for the select trace type dialog */
     public static String TmfTraceType_SelectTraceType;
index 7d20800a2f1e2299f367b39496f0f94ba71de681..859a8c42b897c5126596c59cc6ba62966787fd48 100644 (file)
@@ -69,9 +69,10 @@ public class TmfAnalysisElement extends TmfProjectModelElement implements ITmfSt
      *            Parent of the analysis
      * @param module
      *            The analysis module helper
-     * @since 1.0
+     * @since 2.0
      */
-    protected TmfAnalysisElement(String name, IResource resource, ITmfProjectModelElement parent, @NonNull IAnalysisModuleHelper module) {
+    protected TmfAnalysisElement(String name, IResource resource,
+            TmfViewsElement parent, @NonNull IAnalysisModuleHelper module) {
         super(name, resource, parent);
         fAnalysisHelper = module;
     }
@@ -80,6 +81,15 @@ public class TmfAnalysisElement extends TmfProjectModelElement implements ITmfSt
     // TmfProjectModelElement
     // ------------------------------------------------------------------------
 
+    /**
+     * @since 2.0
+     */
+    @Override
+    public TmfViewsElement getParent() {
+        /* Type enforced at constructor */
+        return (TmfViewsElement) super.getParent();
+    }
+
     /**
      * @since 2.0
      */
@@ -104,36 +114,35 @@ public class TmfAnalysisElement extends TmfProjectModelElement implements ITmfSt
          * We can get a list of available outputs once the analysis is
          * instantiated when the trace is opened
          */
-        ITmfProjectModelElement parent = getParent();
-        if (parent instanceof TmfCommonProjectElement) {
-            ITmfTrace trace = ((TmfCommonProjectElement) parent).getTrace();
-            if (trace == null) {
-                deleteOutputs();
-                return;
-            }
+        TmfCommonProjectElement parentTraceElement = getParent().getParent();
 
-            IAnalysisModule module = trace.getAnalysisModule(fAnalysisHelper.getId());
-            if (module == null) {
-                deleteOutputs();
-                /*
-                 * Trace is opened, but the analysis is null, so it does not
-                 * apply
-                 */
-                fCanExecute = false;
-                return;
-            }
+        ITmfTrace trace = parentTraceElement.getTrace();
+        if (trace == null) {
+            deleteOutputs();
+            return;
+        }
 
-            for (IAnalysisOutput output : module.getOutputs()) {
-                TmfAnalysisOutputElement outputElement = childrenMap.remove(output.getName());
-                if (outputElement == null) {
-                    IFolder newresource = ResourcesPlugin.getWorkspace().getRoot().getFolder(path.append(output.getName()));
-                    outputElement = new TmfAnalysisOutputElement(output.getName(), newresource, this, output);
-                    addChild(outputElement);
-                }
-                outputElement.refreshChildren();
-            }
+        IAnalysisModule module = trace.getAnalysisModule(fAnalysisHelper.getId());
+        if (module == null) {
+            deleteOutputs();
+            /*
+             * Trace is opened, but the analysis is null, so it does not
+             * apply
+             */
+            fCanExecute = false;
+            return;
+        }
 
+        for (IAnalysisOutput output : module.getOutputs()) {
+            TmfAnalysisOutputElement outputElement = childrenMap.remove(output.getName());
+            if (outputElement == null) {
+                IFolder newresource = ResourcesPlugin.getWorkspace().getRoot().getFolder(path.append(output.getName()));
+                outputElement = new TmfAnalysisOutputElement(output.getName(), newresource, this, output);
+                addChild(outputElement);
+            }
+            outputElement.refreshChildren();
         }
+
         /* Remove outputs that are not children of this analysis anymore */
         for (TmfAnalysisOutputElement output : childrenMap.values()) {
             removeChild(output);
@@ -205,11 +214,11 @@ public class TmfAnalysisElement extends TmfProjectModelElement implements ITmfSt
      * @return The help message
      */
     public String getHelpMessage() {
-        ITmfProjectModelElement parent = getParent();
+        TmfCommonProjectElement parentTrace = getParent().getParent();
 
         ITmfTrace trace = null;
-        if (parent instanceof TmfTraceElement) {
-            TmfTraceElement traceElement = (TmfTraceElement) parent;
+        if (parentTrace instanceof TmfTraceElement) {
+            TmfTraceElement traceElement = (TmfTraceElement) parentTrace;
             trace = traceElement.getTrace();
             if (trace != null) {
                 IAnalysisModule module = trace.getAnalysisModule(fAnalysisHelper.getId());
@@ -254,12 +263,13 @@ public class TmfAnalysisElement extends TmfProjectModelElement implements ITmfSt
     /**
      * Make sure the trace this analysis is associated to is the currently
      * selected one
+     * @since 2.0
      */
-    public void activateParent() {
-        ITmfProjectModelElement parent = getParent();
+    public void activateParentTrace() {
+        TmfCommonProjectElement parentTrace = getParent().getParent();
 
-        if (parent instanceof TmfTraceElement) {
-            TmfTraceElement traceElement = (TmfTraceElement) parent;
+        if (parentTrace instanceof TmfTraceElement) {
+            TmfTraceElement traceElement = (TmfTraceElement) parentTrace;
             TmfOpenTraceHelper.openTraceFromElement(traceElement);
         }
     }
index 37c7944149afa3a8018ad496674320a253a0874d..6ee604f35c0f7aa4d3bf6b14f480c97d03c0a883 100644 (file)
@@ -41,8 +41,9 @@ public class TmfAnalysisOutputElement extends TmfProjectModelElement {
      *            Parent analysis of the view
      * @param output
      *            The output object
+     * @since 2.0
      */
-    protected TmfAnalysisOutputElement(String name, IResource resource, ITmfProjectModelElement parent, IAnalysisOutput output) {
+    protected TmfAnalysisOutputElement(String name, IResource resource, TmfAnalysisElement parent, IAnalysisOutput output) {
         super(name, resource, parent);
         fOutput = output;
     }
@@ -74,7 +75,7 @@ public class TmfAnalysisOutputElement extends TmfProjectModelElement {
     public void outputAnalysis() {
         ITmfProjectModelElement parent = getParent();
         if (parent instanceof TmfAnalysisElement) {
-            ((TmfAnalysisElement) parent).activateParent();
+            ((TmfAnalysisElement) parent).activateParentTrace();
             fOutput.requestOutput();
         }
     }
index da97411174c30da16cc4a3f1752e858ed757c16e..fa86e7a705b3bb38d2ca422a6e29de4f6f3b47ac 100644 (file)
@@ -21,9 +21,8 @@ import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull;
 import java.io.ByteArrayInputStream;
 import java.io.InputStream;
 import java.util.ArrayList;
-import java.util.HashMap;
 import java.util.List;
-import java.util.Map;
+import java.util.stream.Collectors;
 
 import org.eclipse.core.resources.IContainer;
 import org.eclipse.core.resources.IFile;
@@ -42,10 +41,7 @@ import org.eclipse.swt.graphics.Image;
 import org.eclipse.tracecompass.internal.tmf.ui.Activator;
 import org.eclipse.tracecompass.internal.tmf.ui.editors.ITmfEventsEditorConstants;
 import org.eclipse.tracecompass.tmf.core.TmfCommonConstants;
-import org.eclipse.tracecompass.tmf.core.analysis.IAnalysisModuleHelper;
-import org.eclipse.tracecompass.tmf.core.analysis.TmfAnalysisManager;
 import org.eclipse.tracecompass.tmf.core.project.model.TmfTraceType;
-import org.eclipse.tracecompass.tmf.core.project.model.TraceTypeHelper;
 import org.eclipse.tracecompass.tmf.core.project.model.TmfTraceType.TraceElementType;
 import org.eclipse.tracecompass.tmf.core.signal.TmfSignalHandler;
 import org.eclipse.tracecompass.tmf.core.signal.TmfSignalManager;
@@ -73,11 +69,13 @@ public abstract class TmfCommonProjectElement extends TmfProjectModelElement {
     // Attributes
     // ------------------------------------------------------------------------
 
-    // This trace type ID as defined in plugin.xml
-    private String fTraceTypeId = null;
-
     private static final String BOOKMARKS_HIDDEN_FILE = ".bookmarks"; //$NON-NLS-1$
 
+    private TmfViewsElement fViewsElement = null;
+
+    /** This trace type ID as defined in plugin.xml */
+    private String fTraceTypeId = null;
+
     // ------------------------------------------------------------------------
     // Constructors
     // ------------------------------------------------------------------------
@@ -107,53 +105,16 @@ public abstract class TmfCommonProjectElement extends TmfProjectModelElement {
      */
     @Override
     protected void refreshChildren() {
-
-        /* Refreshes the analysis under this trace */
-        Map<String, TmfAnalysisElement> childrenMap = new HashMap<>();
-        for (TmfAnalysisElement analysis : getAvailableAnalysis()) {
-            childrenMap.put(analysis.getAnalysisId(), analysis);
-        }
-
-        TraceTypeHelper helper = TmfTraceType.getTraceType(getTraceType());
-
-        Class<@NonNull ? extends ITmfTrace> traceClass = null;
-
-        if (helper != null) {
-            traceClass = helper.getTraceClass();
-        }
-
-        /* Remove all analysis and return */
-        if (traceClass == null) {
-            for (TmfAnalysisElement analysis : childrenMap.values()) {
-                removeChild(analysis);
-            }
-            return;
-        }
-
-        /** Get the base path to put the resource to */
-        IPath path = getResource().getFullPath();
-
-        /* Add all new analysis modules or refresh outputs of existing ones */
-        for (IAnalysisModuleHelper module : TmfAnalysisManager.getAnalysisModules(traceClass).values()) {
-
-            /* If the analysis is not a child of the trace, create it */
-            TmfAnalysisElement analysis = childrenMap.remove(module.getId());
-            if (analysis == null) {
-                /**
-                 * No need for the resource to exist, nothing will be done with
-                 * it
-                 */
-                IFolder newresource = ResourcesPlugin.getWorkspace().getRoot().getFolder(path.append(module.getId()));
-                analysis = new TmfAnalysisElement(module.getName(), newresource, this, module);
-                addChild(analysis);
-            }
-            analysis.refreshChildren();
-        }
-
-        /* Remove analysis that are not children of this trace anymore */
-        for (TmfAnalysisElement analysis : childrenMap.values()) {
-            removeChild(analysis);
+        /* Get the base path to put the resource to */
+        IPath tracePath = getResource().getFullPath();
+
+        if (fViewsElement == null) {
+            /* Add the "Views" node */
+            IFolder viewsNodeRes = ResourcesPlugin.getWorkspace().getRoot().getFolder(tracePath.append(TmfViewsElement.PATH_ELEMENT));
+            fViewsElement = new TmfViewsElement(viewsNodeRes, this);
+            addChild(fViewsElement);
         }
+        fViewsElement.refreshChildren();
     }
 
     /**
@@ -193,6 +154,16 @@ public abstract class TmfCommonProjectElement extends TmfProjectModelElement {
     // Operations
     // ------------------------------------------------------------------------
 
+    /**
+     * Get the child element "Views". There should always be one.
+     *
+     * @return The child element
+     * @since 2.0
+     */
+    protected TmfViewsElement getChildElementViews() {
+        return fViewsElement;
+    }
+
     /**
      * Returns the trace type ID.
      *
@@ -413,14 +384,9 @@ public abstract class TmfCommonProjectElement extends TmfProjectModelElement {
      * @return Array of analysis elements
      */
     public List<TmfAnalysisElement> getAvailableAnalysis() {
-        List<ITmfProjectModelElement> children = getChildren();
-        List<TmfAnalysisElement> analysis = new ArrayList<>();
-        for (ITmfProjectModelElement child : children) {
-            if (child instanceof TmfAnalysisElement) {
-                analysis.add((TmfAnalysisElement) child);
-            }
-        }
-        return analysis;
+        return getChildElementViews().getChildren().stream()
+            .map(elem -> (TmfAnalysisElement) elem)
+            .collect(Collectors.toList());
     }
 
     // ------------------------------------------------------------------------
index 09509f4cef6b721d2ec033162ecae828a4c2367d..25f01daafb38fbba0c7e4605be4f3a5afe3d7dba 100644 (file)
@@ -15,6 +15,8 @@
 
 package org.eclipse.tracecompass.tmf.ui.project.model;
 
+import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull;
+
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
@@ -204,6 +206,10 @@ public class TmfExperimentElement extends TmfCommonProjectElement implements IPr
         if (experiment == null) {
             return;
         }
+
+        /* super.refreshChildren() above should have set this */
+        TmfViewsElement viewsElement = checkNotNull(getChildElementViews());
+
         Map<String, TmfAnalysisElement> analysisMap = new HashMap<>();
         for (TmfAnalysisElement analysis : getAvailableAnalysis()) {
             analysisMap.put(analysis.getAnalysisId(), analysis);
@@ -211,8 +217,8 @@ public class TmfExperimentElement extends TmfCommonProjectElement implements IPr
         for (IAnalysisModuleHelper module : TmfAnalysisManager.getAnalysisModules().values()) {
             if (!analysisMap.containsKey(module.getId()) && module.appliesToExperiment() && (experiment.getAnalysisModule(module.getId()) != null)) {
                 IFolder newresource = ResourcesPlugin.getWorkspace().getRoot().getFolder(getResource().getFullPath().append(module.getId()));
-                TmfAnalysisElement analysis = new TmfAnalysisElement(module.getName(), newresource, this, module);
-                addChild(analysis);
+                TmfAnalysisElement analysis = new TmfAnalysisElement(module.getName(), newresource, viewsElement, module);
+                viewsElement.addChild(analysis);
                 analysis.refreshChildren();
                 analysisMap.put(module.getId(), analysis);
             }
index 72826655c2dd83d691a4f2b817de582b55f0d553..09acdda3bfc0babf16d1ed51d92a762f4adcb3fe 100644 (file)
@@ -37,7 +37,9 @@ final class TmfProjectModelIcons {
     public static final @NonNull Image DEFAULT_EXPERIMENT_ICON;
     public static final @NonNull Image DEFAULT_ANALYSIS_ICON;
     public static final @NonNull Image DEFAULT_VIEW_ICON;
+
     public static final @NonNull Image FOLDER_ICON;
+    public static final @NonNull Image VIEWS_ICON;
 
     public static final WorkbenchLabelProvider WORKSPACE_LABEL_PROVIDER = new WorkbenchLabelProvider();
 
@@ -51,7 +53,9 @@ final class TmfProjectModelIcons {
     // ------------------------------------------------------------------------
 
     static {
-        FOLDER_ICON = checkNotNull(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_FOLDER));
+        ISharedImages sharedImages = PlatformUI.getWorkbench().getSharedImages();
+        FOLDER_ICON = checkNotNull(sharedImages.getImage(ISharedImages.IMG_OBJ_FOLDER));
+        VIEWS_ICON = checkNotNull(sharedImages.getImage(ISharedImages.IMG_OBJ_ELEMENT));
 
         Bundle bundle = Activator.getDefault().getBundle();
         DEFAULT_TRACE_ICON = checkNotNull(loadIcon(bundle, TRACE_ICON_FILE));
diff --git a/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/project/model/TmfViewsElement.java b/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/project/model/TmfViewsElement.java
new file mode 100644 (file)
index 0000000..a49e8ff
--- /dev/null
@@ -0,0 +1,117 @@
+/*******************************************************************************
+ * Copyright (c) 2016 EfficiOS Inc., Alexandre Montplaisir
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.tmf.ui.project.model;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.tracecompass.tmf.core.analysis.IAnalysisModuleHelper;
+import org.eclipse.tracecompass.tmf.core.analysis.TmfAnalysisManager;
+import org.eclipse.tracecompass.tmf.core.project.model.TmfTraceType;
+import org.eclipse.tracecompass.tmf.core.project.model.TraceTypeHelper;
+import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
+
+/**
+ * Project model element for the "Views" node.
+ *
+ * For now it contains the list of the standard analyses, with their outputs
+ * (views) under each. The plan is to eventually only show the views under this
+ * node, since the user cannot really interact with the analyses themselves.
+ *
+ * @author Alexandre Montplaisir
+ * @since 2.0
+ */
+public class TmfViewsElement extends TmfProjectModelElement {
+
+    /**
+     * Element of the resource path
+     */
+    public static final String PATH_ELEMENT = ".views"; //$NON-NLS-1$
+
+    private static final String ELEMENT_NAME = Messages.TmfViewsElement_Name;
+
+    /**
+     * Constructor
+     *
+     * @param resource
+     *            The resource to be associated with this element
+     * @param parent
+     *            The parent element
+     */
+    protected TmfViewsElement(IResource resource, TmfCommonProjectElement parent) {
+        super(ELEMENT_NAME, resource, parent);
+    }
+
+    // ------------------------------------------------------------------------
+    // TmfProjectModelElement
+    // ------------------------------------------------------------------------
+
+    @Override
+    public TmfCommonProjectElement getParent() {
+        /* Type enforced at constructor */
+        return (TmfCommonProjectElement) super.getParent();
+    }
+
+    @Override
+    protected void refreshChildren() {
+        /* Refreshes the analysis under this trace */
+        Map<String, TmfAnalysisElement> childrenMap = new HashMap<>();
+        for (TmfAnalysisElement analysis : getParent().getAvailableAnalysis()) {
+            childrenMap.put(analysis.getAnalysisId(), analysis);
+        }
+
+        TraceTypeHelper helper = TmfTraceType.getTraceType(getParent().getTraceType());
+
+        Class<@NonNull ? extends ITmfTrace> traceClass = null;
+
+        if (helper != null) {
+            traceClass = helper.getTraceClass();
+        }
+
+        /* Remove all analysis and return */
+        if (traceClass == null) {
+            for (TmfAnalysisElement analysis : childrenMap.values()) {
+                removeChild(analysis);
+            }
+            return;
+        }
+
+        IPath nodePath = getResource().getFullPath();
+
+        /* Add all new analysis modules or refresh outputs of existing ones */
+        for (IAnalysisModuleHelper module : TmfAnalysisManager.getAnalysisModules(traceClass).values()) {
+
+            /* If the analysis is not a child of the trace, create it */
+            TmfAnalysisElement analysis = childrenMap.remove(module.getId());
+            if (analysis == null) {
+                IFolder analysisRes = ResourcesPlugin.getWorkspace().getRoot().getFolder(nodePath.append(module.getId()));
+                analysis = new TmfAnalysisElement(module.getName(), analysisRes, this, module);
+                addChild(analysis);
+            }
+            analysis.refreshChildren();
+        }
+
+        /* Remove analysis that are not children of this trace anymore */
+        for (TmfAnalysisElement analysis : childrenMap.values()) {
+            removeChild(analysis);
+        }
+    }
+
+    @Override
+    public Image getIcon() {
+        return TmfProjectModelIcons.VIEWS_ICON;
+    }
+}
index 8252f3de43e20b0ada66706c2bf71e627d410b1d..c332c0d7ca2d8720f2fb5f678e796e401f97cd6a 100644 (file)
@@ -37,6 +37,7 @@ TmfTraceElement_FolderSizeString={0} bytes in {1} files
 TmfTraceElement_FolderSizeOverflowString=At least {0} bytes in more than {1} files
 TmfTraceElement_TypeName=Trace
 TmfTraceType_SelectTraceType=Select Trace Type
+TmfViewsElement_Name=Views
 
 # Open trace error messages
 TmfOpenTraceHelper_ErrorOpeningElement=Error opening {0}
This page took 0.035272 seconds and 5 git commands to generate.