tmf: bug 486053 Add the possibility for analyses to provide properties
authorGeneviève Bastien <gbastien+lttng@versatic.net>
Wed, 27 Jan 2016 03:17:14 +0000 (22:17 -0500)
committerMarc-Andre Laperle <marc-andre.laperle@ericsson.com>
Tue, 16 Feb 2016 21:04:42 +0000 (16:04 -0500)
Change-Id: I29058e50f71509c214f7d2a11cede4ca89b5a93c
Signed-off-by: Geneviève Bastien <gbastien+lttng@versatic.net>
Reviewed-on: https://git.eclipse.org/r/65226
Reviewed-by: Hudson CI
Reviewed-by: Marc-Andre Laperle <marc-andre.laperle@ericsson.com>
Tested-by: Marc-Andre Laperle <marc-andre.laperle@ericsson.com>
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/messages.properties

index 7ffb65fd740db9bf30828a02019a42098a0bb3b9..fb7c323a4b55f9ff88c9480841d7b3a2426a0796 100644 (file)
@@ -24,6 +24,20 @@ public class Messages extends NLS {
 
     private static final String BUNDLE_NAME = "org.eclipse.tracecompass.tmf.ui.project.model.messages"; //$NON-NLS-1$
 
+    /**
+     * The category of the analysis helper properties
+     *
+     * @since 2.0
+     */
+    public static String TmfAnalysisElement_HelperProperties;
+
+    /**
+     * The category of the analysis properties
+     *
+     * @since 2.0
+     */
+    public static String TmfAnalysisElement_AnalysisProperties;
+
     /** Instantiate analysis message box title */
     public static String TmfAnalysisElement_InstantiateAnalysis;
 
index 485196d80a5f59a5130d0167479147d416497c1f..02820b687382ae1a1190676efe430490d5e21533 100644 (file)
@@ -14,6 +14,7 @@
 package org.eclipse.tracecompass.tmf.ui.project.model;
 
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -28,15 +29,20 @@ import org.eclipse.swt.graphics.TextStyle;
 import org.eclipse.tracecompass.tmf.core.analysis.IAnalysisModule;
 import org.eclipse.tracecompass.tmf.core.analysis.IAnalysisModuleHelper;
 import org.eclipse.tracecompass.tmf.core.analysis.IAnalysisOutput;
+import org.eclipse.tracecompass.tmf.core.project.model.ITmfPropertiesProvider;
 import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
+import org.eclipse.tracecompass.tmf.ui.properties.ReadOnlyTextPropertyDescriptor;
+import org.eclipse.ui.views.properties.IPropertyDescriptor;
+import org.eclipse.ui.views.properties.IPropertySource2;
 import org.osgi.framework.Bundle;
 
 /**
  * Class for project elements of type analysis modules
  *
  * @author Geneviève Bastien
+ * @since 2.0
  */
-public class TmfAnalysisElement extends TmfProjectModelElement implements ITmfStyledProjectModelElement {
+public class TmfAnalysisElement extends TmfProjectModelElement implements ITmfStyledProjectModelElement, IPropertySource2 {
 
     private static final Styler ANALYSIS_CANT_EXECUTE_STYLER = new Styler() {
         @Override
@@ -48,6 +54,9 @@ public class TmfAnalysisElement extends TmfProjectModelElement implements ITmfSt
     private final @NonNull IAnalysisModuleHelper fAnalysisHelper;
     private boolean fCanExecute = true;
 
+    private static final String ANALYSIS_PROPERTIES_CATEGORY = Messages.TmfAnalysisElement_AnalysisProperties;
+    private static final String HELPER_PROPERTIES_CATEGORY = Messages.TmfAnalysisElement_HelperProperties;
+
     /**
      * Constructor
      *
@@ -232,4 +241,128 @@ public class TmfAnalysisElement extends TmfProjectModelElement implements ITmfSt
         }
     }
 
+    // ------------------------------------------------------------------------
+    // IPropertySource2
+    // ------------------------------------------------------------------------
+
+    /**
+     * @since 2.0
+     */
+    @Override
+    public Object getEditableValue() {
+        return null;
+    }
+
+    /**
+     * Get the analysis properties of this analysisElement if the corresponding
+     * analysis exists for the current trace
+     *
+     * @return a map with the names and values of the trace properties
+     *         respectively as keys and values
+     */
+    private Map<String, String> getAnalysisProperties() {
+        ITmfProjectModelElement parent = getParent();
+
+        if (parent instanceof TmfCommonProjectElement) {
+            ITmfTrace trace = ((TmfCommonProjectElement) parent).getTrace();
+            if (trace == null) {
+                return Collections.EMPTY_MAP;
+            }
+            IAnalysisModule module = trace.getAnalysisModule(fAnalysisHelper.getId());
+            if (module instanceof ITmfPropertiesProvider) {
+                return ((ITmfPropertiesProvider) module).getProperties();
+            }
+        }
+
+        return Collections.EMPTY_MAP;
+    }
+
+    private Map<String, String> getAnalysisHelperProperties() {
+        if (fAnalysisHelper instanceof ITmfPropertiesProvider) {
+            ITmfPropertiesProvider analysisProperties = (ITmfPropertiesProvider) fAnalysisHelper;
+            return analysisProperties.getProperties();
+        }
+        return Collections.EMPTY_MAP;
+    }
+
+    /**
+     * @since 2.0
+     */
+    @Override
+    public IPropertyDescriptor[] getPropertyDescriptors() {
+        Map<String, String> helperProperties = getAnalysisHelperProperties();
+        Map<String, String> analysisProperties = getAnalysisProperties();
+        if (!analysisProperties.isEmpty() || !helperProperties.isEmpty()) {
+            List<IPropertyDescriptor> propertyDescriptorArray = new ArrayList<>(analysisProperties.size() + helperProperties.size());
+            for (Map.Entry<String, String> varName : helperProperties.entrySet()) {
+                ReadOnlyTextPropertyDescriptor descriptor = new ReadOnlyTextPropertyDescriptor(this.getName() + '_' + varName.getKey(), varName.getKey());
+                descriptor.setCategory(HELPER_PROPERTIES_CATEGORY);
+                propertyDescriptorArray.add(descriptor);
+            }
+            for (Map.Entry<String, String> varName : analysisProperties.entrySet()) {
+                ReadOnlyTextPropertyDescriptor descriptor = new ReadOnlyTextPropertyDescriptor(this.getName() + '_' + varName.getKey(), varName.getKey());
+                descriptor.setCategory(ANALYSIS_PROPERTIES_CATEGORY);
+                propertyDescriptorArray.add(descriptor);
+            }
+            return propertyDescriptorArray.toArray(new IPropertyDescriptor[analysisProperties.size() + helperProperties.size()]);
+        }
+        return new IPropertyDescriptor[0];
+    }
+
+    /**
+     * @since 2.0
+     */
+    @Override
+    public Object getPropertyValue(Object id) {
+        if (id == null) {
+            return null;
+        }
+        Map<String, String> properties = getAnalysisHelperProperties();
+        String key = (String) id;
+        /* Remove name from key */
+        key = key.substring(this.getName().length() + 1);
+        if (properties.containsKey(key)) {
+            String value = properties.get(key);
+            return value;
+        }
+
+        properties = getAnalysisProperties();
+        if (properties.containsKey(key)) {
+            String value = properties.get(key);
+            return value;
+        }
+
+        return null;
+    }
+
+    /**
+     * @since 2.0
+     */
+    @Override
+    public final void resetPropertyValue(Object id) {
+    }
+
+    /**
+     * @since 2.0
+     */
+    @Override
+    public final void setPropertyValue(Object id, Object value) {
+    }
+
+    /**
+     * @since 2.0
+     */
+    @Override
+    public final boolean isPropertyResettable(Object id) {
+        return false;
+    }
+
+    /**
+     * @since 2.0
+     */
+    @Override
+    public final boolean isPropertySet(Object id) {
+        return false;
+    }
+
 }
index f931a19a6f3bc6a5f2c2d0853f2b1d77a39546ce..6d34d2757ad8bff50b15a890666bdb4751b0b42c 100644 (file)
@@ -12,6 +12,8 @@
 
 # Environment properties dialog
 
+TmfAnalysisElement_AnalysisProperties=Analysis module properties
+TmfAnalysisElement_HelperProperties=Analysis helper properties
 TmfAnalysisElement_InstantiateAnalysis=Instantiate analysis
 TmfAnalysisViewOutput_ViewUnavailable=\ (view unavailable)
 TmfAnalysisViewOutput_Title=Open analysis output
This page took 0.028204 seconds and 5 git commands to generate.