tmf: Put analyses under their own node in the Project View
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.ui / src / org / eclipse / tracecompass / tmf / ui / project / model / TmfExperimentElement.java
index df44b6e21b92c5b626e7745ced6353925b74899e..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;
@@ -38,7 +40,10 @@ import org.eclipse.core.runtime.IStatus;
 import org.eclipse.core.runtime.InvalidRegistryObjectException;
 import org.eclipse.core.runtime.NullProgressMonitor;
 import org.eclipse.core.runtime.Platform;
+import org.eclipse.jdt.annotation.NonNull;
 import org.eclipse.osgi.util.NLS;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.Display;
 import org.eclipse.tracecompass.internal.tmf.ui.Activator;
 import org.eclipse.tracecompass.internal.tmf.ui.editors.ITmfEventsEditorConstants;
 import org.eclipse.tracecompass.tmf.core.TmfCommonConstants;
@@ -56,6 +61,7 @@ import org.eclipse.ui.views.properties.IPropertySource2;
 /**
  * Implementation of TMF Experiment Model Element.
  * <p>
+ *
  * @version 1.0
  * @author Francois Chouinard
  *
@@ -67,34 +73,34 @@ public class TmfExperimentElement extends TmfCommonProjectElement implements IPr
     // ------------------------------------------------------------------------
 
     // Property View stuff
-    private static final String sfInfoCategory = "Info"; //$NON-NLS-1$
-    private static final String sfName = "name"; //$NON-NLS-1$
-    private static final String sfPath = "path"; //$NON-NLS-1$
-    private static final String sfLocation = "location"; //$NON-NLS-1$
-    private static final String sfFolderSuffix = "_exp"; //$NON-NLS-1$
-    private static final String sfExperimentType = "type"; //$NON-NLS-1$
-
-    private static final ReadOnlyTextPropertyDescriptor sfNameDescriptor = new ReadOnlyTextPropertyDescriptor(sfName, sfName);
-    private static final ReadOnlyTextPropertyDescriptor sfPathDescriptor = new ReadOnlyTextPropertyDescriptor(sfPath, sfPath);
-    private static final ReadOnlyTextPropertyDescriptor sfLocationDescriptor = new ReadOnlyTextPropertyDescriptor(sfLocation,
-            sfLocation);
-    private static final ReadOnlyTextPropertyDescriptor sfTypeDescriptor = new ReadOnlyTextPropertyDescriptor(sfExperimentType, sfExperimentType);
-
-    private static final IPropertyDescriptor[] sfDescriptors = { sfNameDescriptor, sfPathDescriptor,
-            sfLocationDescriptor, sfTypeDescriptor };
+    private static final String INFO_CATEGORY = "Info"; //$NON-NLS-1$
+    private static final String NAME = "name"; //$NON-NLS-1$
+    private static final String PATH = "path"; //$NON-NLS-1$
+    private static final String LOCATION = "location"; //$NON-NLS-1$
+    private static final String FOLDER_SUFFIX = "_exp"; //$NON-NLS-1$
+    private static final String EXPERIMENT_TYPE = "type"; //$NON-NLS-1$
+
+    private static final ReadOnlyTextPropertyDescriptor NAME_DESCRIPTOR = new ReadOnlyTextPropertyDescriptor(NAME, NAME);
+    private static final ReadOnlyTextPropertyDescriptor PATH_DESCRIPTOR = new ReadOnlyTextPropertyDescriptor(PATH, PATH);
+    private static final ReadOnlyTextPropertyDescriptor LOCATION_DESCRIPTOR = new ReadOnlyTextPropertyDescriptor(LOCATION,
+            LOCATION);
+    private static final ReadOnlyTextPropertyDescriptor TYPE_DESCRIPTOR = new ReadOnlyTextPropertyDescriptor(EXPERIMENT_TYPE, EXPERIMENT_TYPE);
+
+    private static final IPropertyDescriptor[] DESCRIPTORS = { NAME_DESCRIPTOR, PATH_DESCRIPTOR,
+            LOCATION_DESCRIPTOR, TYPE_DESCRIPTOR };
 
     static {
-        sfNameDescriptor.setCategory(sfInfoCategory);
-        sfPathDescriptor.setCategory(sfInfoCategory);
-        sfLocationDescriptor.setCategory(sfInfoCategory);
-        sfTypeDescriptor.setCategory(sfInfoCategory);
+        NAME_DESCRIPTOR.setCategory(INFO_CATEGORY);
+        PATH_DESCRIPTOR.setCategory(INFO_CATEGORY);
+        LOCATION_DESCRIPTOR.setCategory(INFO_CATEGORY);
+        TYPE_DESCRIPTOR.setCategory(INFO_CATEGORY);
     }
 
     // The mapping of available trace type IDs to their corresponding
     // configuration element
-    private static final Map<String, IConfigurationElement> sfTraceTypeAttributes = new HashMap<>();
-    private static final Map<String, IConfigurationElement> sfTraceTypeUIAttributes = new HashMap<>();
-    private static final Map<String, IConfigurationElement> sfTraceCategories = new HashMap<>();
+    private static final Map<String, IConfigurationElement> TRACE_TYPE_ATTRIBUTES = new HashMap<>();
+    private static final Map<String, IConfigurationElement> TRACE_TYPE_UI_ATTRIBUTES = new HashMap<>();
+    private static final Map<String, IConfigurationElement> TRACE_CATEGORIES = new HashMap<>();
 
     // ------------------------------------------------------------------------
     // Static initialization
@@ -110,10 +116,10 @@ public class TmfExperimentElement extends TmfCommonProjectElement implements IPr
             String elementName = ce.getName();
             if (elementName.equals(TmfTraceType.EXPERIMENT_ELEM)) {
                 String traceTypeId = ce.getAttribute(TmfTraceType.ID_ATTR);
-                sfTraceTypeAttributes.put(traceTypeId, ce);
+                TRACE_TYPE_ATTRIBUTES.put(traceTypeId, ce);
             } else if (elementName.equals(TmfTraceType.CATEGORY_ELEM)) {
                 String categoryId = ce.getAttribute(TmfTraceType.ID_ATTR);
-                sfTraceCategories.put(categoryId, ce);
+                TRACE_CATEGORIES.put(categoryId, ce);
             }
         }
 
@@ -126,7 +132,7 @@ public class TmfExperimentElement extends TmfCommonProjectElement implements IPr
             String elemName = ce.getName();
             if (TmfTraceTypeUIUtils.EXPERIMENT_ELEM.equals(elemName)) {
                 String traceType = ce.getAttribute(TmfTraceTypeUIUtils.TRACETYPE_ATTR);
-                sfTraceTypeUIAttributes.put(traceType, ce);
+                TRACE_TYPE_UI_ATTRIBUTES.put(traceType, ce);
             }
         }
     }
@@ -136,9 +142,13 @@ public class TmfExperimentElement extends TmfCommonProjectElement implements IPr
     // ------------------------------------------------------------------------
     /**
      * Constructor
-     * @param name The name of the experiment
-     * @param folder The folder reference
-     * @param parent The experiment folder reference.
+     *
+     * @param name
+     *            The name of the experiment
+     * @param folder
+     *            The folder reference
+     * @param parent
+     *            The experiment folder reference.
      */
     public TmfExperimentElement(String name, IFolder folder, TmfExperimentFolder parent) {
         super(name, folder, parent);
@@ -150,11 +160,14 @@ public class TmfExperimentElement extends TmfCommonProjectElement implements IPr
 
     @Override
     public IFolder getResource() {
-        return (IFolder) fResource;
+        return (IFolder) super.getResource();
     }
 
+    /**
+     * @since 2.0
+     */
     @Override
-    void refreshChildren() {
+    protected void refreshChildren() {
         IFolder folder = getResource();
 
         /* Update the trace children of this experiment */
@@ -173,6 +186,7 @@ public class TmfExperimentElement extends TmfCommonProjectElement implements IPr
                 childrenMap.remove(elementPath);
             } else {
                 element = new TmfTraceElement(name, resource, this);
+                addChild(element);
             }
         }
 
@@ -192,14 +206,19 @@ 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);
         }
         for (IAnalysisModuleHelper module : TmfAnalysisManager.getAnalysisModules().values()) {
             if (!analysisMap.containsKey(module.getId()) && module.appliesToExperiment() && (experiment.getAnalysisModule(module.getId()) != null)) {
-                IFolder newresource = ResourcesPlugin.getWorkspace().getRoot().getFolder(fResource.getFullPath().append(module.getId()));
-                TmfAnalysisElement analysis = new TmfAnalysisElement(module.getName(), newresource, this, module);
+                IFolder newresource = ResourcesPlugin.getWorkspace().getRoot().getFolder(getResource().getFullPath().append(module.getId()));
+                TmfAnalysisElement analysis = new TmfAnalysisElement(module.getName(), newresource, viewsElement, module);
+                viewsElement.addChild(analysis);
                 analysis.refreshChildren();
                 analysisMap.put(module.getId(), analysis);
             }
@@ -231,6 +250,23 @@ public class TmfExperimentElement extends TmfCommonProjectElement implements IPr
         return list;
     }
 
+    /**
+     * @since 2.0
+     */
+    @Override
+    public @NonNull Image getIcon() {
+        Image icon = super.getIcon();
+        return (icon == null ? TmfProjectModelIcons.DEFAULT_EXPERIMENT_ICON : icon);
+    }
+
+    /**
+     * @since 2.0
+     */
+    @Override
+    public String getLabelText() {
+        return getName() + " [" + getTraces().size() + "]"; //$NON-NLS-1$ //$NON-NLS-2$
+    }
+
     // ------------------------------------------------------------------------
     // Operations
     // ------------------------------------------------------------------------
@@ -260,6 +296,7 @@ public class TmfExperimentElement extends TmfCommonProjectElement implements IPr
 
     /**
      * Returns a list of TmfTraceElements contained in this experiment.
+     *
      * @return a list of TmfTraceElements
      */
     @Override
@@ -277,7 +314,8 @@ public class TmfExperimentElement extends TmfCommonProjectElement implements IPr
     /**
      * Adds a trace to the experiment
      *
-     * @param trace The trace element to add
+     * @param trace
+     *            The trace element to add
      */
     public void addTrace(TmfTraceElement trace) {
         addTrace(trace, true);
@@ -286,8 +324,10 @@ public class TmfExperimentElement extends TmfCommonProjectElement implements IPr
     /**
      * Adds a trace to the experiment
      *
-     * @param trace The trace element to add
-     * @param refresh Flag for refreshing the project
+     * @param trace
+     *            The trace element to add
+     * @param refresh
+     *            Flag for refreshing the project
      */
     public void addTrace(TmfTraceElement trace, boolean refresh) {
         /**
@@ -336,15 +376,22 @@ public class TmfExperimentElement extends TmfCommonProjectElement implements IPr
     /**
      * Removes a trace from an experiment
      *
-     * @param trace The trace to remove
-     * @throws CoreException exception
+     * @param trace
+     *            The trace to remove
+     * @throws CoreException
+     *             exception
      */
     public void removeTrace(TmfTraceElement trace) throws CoreException {
 
-        // Close the experiment if open
-        closeEditors();
+        // Close editors in UI Thread
+        Display.getDefault().syncExec(new Runnable() {
+            @Override
+            public void run() {
+                closeEditors();
+            }
+        });
 
-        /* Finally, remove the trace from experiment*/
+        /* Finally, remove the trace from experiment */
         removeChild(trace);
         deleteTraceResource(trace.getResource());
         deleteSupplementaryResources();
@@ -368,7 +415,7 @@ public class TmfExperimentElement extends TmfCommonProjectElement implements IPr
     public String getEditorId() {
         /* See if a default editor was set for this experiment type */
         if (getTraceType() != null) {
-            IConfigurationElement ce = sfTraceTypeUIAttributes.get(getTraceType());
+            IConfigurationElement ce = TRACE_TYPE_UI_ATTRIBUTES.get(getTraceType());
             if (ce != null) {
                 IConfigurationElement[] defaultEditorCE = ce.getChildren(TmfTraceTypeUIUtils.DEFAULT_EDITOR_ELEM);
                 if (defaultEditorCE.length == 1) {
@@ -409,7 +456,7 @@ public class TmfExperimentElement extends TmfCommonProjectElement implements IPr
 
             if (getTraceType() != null) {
 
-                IConfigurationElement ce = sfTraceTypeAttributes.get(getTraceType());
+                IConfigurationElement ce = TRACE_TYPE_ATTRIBUTES.get(getTraceType());
                 if (ce == null) {
                     return null;
                 }
@@ -438,33 +485,33 @@ public class TmfExperimentElement extends TmfCommonProjectElement implements IPr
 
     @Override
     public IPropertyDescriptor[] getPropertyDescriptors() {
-        return Arrays.copyOf(sfDescriptors, sfDescriptors.length);
+        return Arrays.copyOf(DESCRIPTORS, DESCRIPTORS.length);
     }
 
     @Override
     public Object getPropertyValue(Object id) {
 
-        if (sfName.equals(id)) {
+        if (NAME.equals(id)) {
             return getName();
         }
 
-        if (sfPath.equals(id)) {
+        if (PATH.equals(id)) {
             return getPath().toString();
         }
 
-        if (sfLocation.equals(id)) {
+        if (LOCATION.equals(id)) {
             return getLocation().toString();
         }
 
-        if (sfExperimentType.equals(id)) {
+        if (EXPERIMENT_TYPE.equals(id)) {
             if (getTraceType() != null) {
-                IConfigurationElement ce = sfTraceTypeAttributes.get(getTraceType());
+                IConfigurationElement ce = TRACE_TYPE_ATTRIBUTES.get(getTraceType());
                 if (ce == null) {
                     return ""; //$NON-NLS-1$
                 }
                 String categoryId = ce.getAttribute(TmfTraceType.CATEGORY_ATTR);
                 if (categoryId != null) {
-                    IConfigurationElement category = sfTraceCategories.get(categoryId);
+                    IConfigurationElement category = TRACE_CATEGORIES.get(categoryId);
                     if (category != null) {
                         return category.getAttribute(TmfTraceType.NAME_ATTR) + ':' + ce.getAttribute(TmfTraceType.NAME_ATTR);
                     }
@@ -496,11 +543,12 @@ public class TmfExperimentElement extends TmfCommonProjectElement implements IPr
 
     /**
      * Return the suffix for resource names
+     *
      * @return The folder suffix
      */
     @Override
     public String getSuffix() {
-        return sfFolderSuffix;
+        return FOLDER_SUFFIX;
     }
 
 }
This page took 0.029889 seconds and 5 git commands to generate.