tmf: Introduce IOnDemandAnalysisReport and corresponding element
authorAlexandre Montplaisir <alexmonthy@efficios.com>
Tue, 26 Apr 2016 21:47:58 +0000 (17:47 -0400)
committerAlexandre Montplaisir <alexmonthy@efficios.com>
Wed, 4 May 2016 21:27:26 +0000 (17:27 -0400)
For now the ReportsElement will be responsible for tracking which
reports are currently available. This means they are not persisted
and will be lost on restart. A future improvement could be to move
this logic to the trace so they can be saved as supplementary files.

Change-Id: I6c896665c7e4f43155aa499e59dc93d296e3119e
Signed-off-by: Alexandre Montplaisir <alexmonthy@efficios.com>
Reviewed-on: https://git.eclipse.org/r/71562
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.core/src/org/eclipse/tracecompass/tmf/core/analysis/ondemand/IOnDemandAnalysisReport.java [new file with mode: 0644]
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/TmfProjectModelIcons.java
tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/project/model/TmfReportElement.java [new file with mode: 0644]
tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/project/model/TmfReportsElement.java

diff --git a/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/analysis/ondemand/IOnDemandAnalysisReport.java b/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/analysis/ondemand/IOnDemandAnalysisReport.java
new file mode 100644 (file)
index 0000000..1fe64f0
--- /dev/null
@@ -0,0 +1,33 @@
+/*******************************************************************************
+ * 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.core.analysis.ondemand;
+
+/**
+ * Reports are the output of on-demand analysis ran on a particular trace.
+ * Several runs of the same ODA should produce different report objects
+ * (although their contents could be the same).
+ *
+ * They are meant to be standalone objects, but should normally keep track of
+ * which analysis and trace created them.
+ *
+ * Unlike on-demand analyses, a report is specific to its trace.
+ *
+ * @author Alexandre Montplaisir
+ * @since 2.0
+ */
+public interface IOnDemandAnalysisReport {
+
+    /**
+     * Get the name of this report.
+     *
+     * @return The name of this report
+     */
+    String getName();
+}
index b73c9e33f7e44a3291a93b5ab2c4e28e988bfaed..a1d3342d990941332f821485318cff46964a7762 100644 (file)
@@ -185,6 +185,16 @@ public abstract class TmfCommonProjectElement extends TmfProjectModelElement {
         return fViewsElement;
     }
 
+    /**
+     * Get the child element "Reports".
+     *
+     * @return The Reports child element
+     * @since 2.0
+     */
+    public TmfReportsElement getChildElementReports() {
+        return fReportsElement;
+    }
+
     /**
      * Returns the trace type ID.
      *
index 14b18cd6379946b3a885e4e9fa56bf5faff6caab..4c1332f5e6f2f6119df8a833539b4fa88c44f7d4 100644 (file)
@@ -37,6 +37,7 @@ 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 DEFAULT_REPORT_ICON;
 
     public static final @NonNull Image FOLDER_ICON;
     public static final @NonNull Image VIEWS_ICON;
@@ -51,6 +52,7 @@ final class TmfProjectModelIcons {
     private static final String VIEW_ICON_FILE = "icons/obj16/node_obj.gif"; //$NON-NLS-1$
     private static final String ONDEMAND_ANALYSES_ICON_FILE = "icons/obj16/debugt_obj.gif"; //$NON-NLS-1$
     private static final String REPORTS_ICON_FILE = "icons/obj16/arraypartition_obj.gif"; //$NON-NLS-1$
+    private static final String DEFAULT_REPORT_ICON_FILE = "icons/etool16/copy_edit.gif"; //$NON-NLS-1$
 
     // ------------------------------------------------------------------------
     // Initialization
@@ -69,6 +71,7 @@ final class TmfProjectModelIcons {
         DEFAULT_EXPERIMENT_ICON = checkNotNull(loadIcon(bundle, EXPERIMENT_ICON_FILE));
         DEFAULT_ANALYSIS_ICON = checkNotNull(loadIcon(bundle, ANALYSIS_ICON_FILE));
         DEFAULT_VIEW_ICON = checkNotNull(loadIcon(bundle, VIEW_ICON_FILE));
+        DEFAULT_REPORT_ICON = checkNotNull(loadIcon(bundle, DEFAULT_REPORT_ICON_FILE));
     }
 
     public static @Nullable Image loadIcon(Bundle bundle, String url) {
diff --git a/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/project/model/TmfReportElement.java b/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/project/model/TmfReportElement.java
new file mode 100644 (file)
index 0000000..115c0ad
--- /dev/null
@@ -0,0 +1,69 @@
+/*******************************************************************************
+ * 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 org.eclipse.core.resources.IResource;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.tracecompass.tmf.core.analysis.ondemand.IOnDemandAnalysisReport;
+
+/**
+ * Project model element containing a report, which is the result of the
+ * execution of an on-demand analysis.
+ *
+ * @author Alexandre Montplaisir
+ * @since 2.0
+ */
+public class TmfReportElement extends TmfProjectModelElement {
+
+    private final IOnDemandAnalysisReport fReport;
+
+    /**
+     * Constructor
+     *
+     * @param reportName
+     *            Name of this report element
+     * @param resource
+     *            The resource to be associated with this element
+     * @param parent
+     *            The parent element
+     * @param report
+     *            The report object represented by this element
+     */
+    protected TmfReportElement(String reportName, IResource resource,
+            TmfReportsElement parent,  IOnDemandAnalysisReport report) {
+        super(reportName, resource, parent);
+        fReport = report;
+    }
+
+    @Override
+    public TmfReportsElement getParent() {
+        /* Type enforced at constructor */
+        return (TmfReportsElement) super.getParent();
+    }
+
+    @Override
+    public Image getIcon() {
+        return TmfProjectModelIcons.DEFAULT_REPORT_ICON;
+    }
+
+    @Override
+    protected void refreshChildren() {
+        /* No children */
+    }
+
+    /**
+     * Get the report object of this element.
+     *
+     * @return The report
+     */
+    public IOnDemandAnalysisReport getReport() {
+        return fReport;
+    }
+}
index a5b187989a0f442c78b0ef725c84f7f628b022e5..cbab457a2202c7a271881de96953419d98bc67bb 100644 (file)
@@ -9,8 +9,18 @@
 
 package org.eclipse.tracecompass.tmf.ui.project.model;
 
+import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull;
+
+import org.eclipse.core.resources.IFolder;
 import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IWorkspaceRoot;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.IPath;
 import org.eclipse.swt.graphics.Image;
+import org.eclipse.tracecompass.tmf.core.analysis.ondemand.IOnDemandAnalysisReport;
+
+import com.google.common.collect.BiMap;
+import com.google.common.collect.HashBiMap;
 
 /**
  * Project model element for the "Reports" element, which lists the analysis
@@ -31,6 +41,8 @@ public class TmfReportsElement extends TmfProjectModelElement {
 
     private static final String ELEMENT_NAME = Messages.TmfReportsElement_Name;
 
+    private final BiMap<String, IOnDemandAnalysisReport> fCurrentReports = HashBiMap.create();
+
     /**
      * Constructor
      *
@@ -59,4 +71,46 @@ public class TmfReportsElement extends TmfProjectModelElement {
         /* No children at the moment */
     }
 
+    /**
+     * Add a new report under this element.
+     *
+     * @param report
+     *            The report to add
+     */
+    public void addReport(IOnDemandAnalysisReport report) {
+        IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
+        IPath nodePath = getResource().getFullPath();
+
+        /* Append #2,#3,... to the name if needed */
+        String reportDisplayName = report.getName();
+        int i = 1;
+        while (fCurrentReports.containsKey(reportDisplayName)) {
+            i++;
+            reportDisplayName = report.getName() + " #" + i; //$NON-NLS-1$
+        }
+
+        fCurrentReports.put(reportDisplayName, report);
+
+        IFolder analysisRes = checkNotNull(root.getFolder(nodePath.append(reportDisplayName)));
+        TmfReportElement elem = new TmfReportElement(reportDisplayName, analysisRes, this, report);
+        addChild(elem);
+        refresh();
+    }
+
+    /**
+     * Remove a report from under this element.
+     *
+     * @param report
+     *            The report to remove
+     */
+    public void removeReport(IOnDemandAnalysisReport report) {
+        String displayName = fCurrentReports.inverse().get(report);
+        fCurrentReports.values().remove(report);
+
+        ITmfProjectModelElement elementToRemove = getChildren().stream()
+                .filter(elem -> elem.getName().equals(displayName))
+                .findFirst().orElse(null);
+        removeChild(elementToRemove);
+        refresh();
+    }
 }
This page took 0.028877 seconds and 5 git commands to generate.