lttng: Update @since annotations for 3.0
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / project / model / TmfTraceElement.java
index 474186a486dab05c7165e91e0e9c93187669b8b0..b05f4f02b8ff721900676bd6b13878a04f7095c2 100644 (file)
 /*******************************************************************************
- * Copyright (c) 2010, 2011 Ericsson
- * 
+ * Copyright (c) 2010, 2013 Ericsson, École Polytechnique de Montréal
+ *
  * 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
- * 
+ *
  * Contributors:
  *   Francois Chouinard - Initial API and implementation
+ *   Bernd Hufmann - Added supplementary files handling
+ *   Geneviève Bastien - Moved supplementary files handling to parent class,
+ *                       added code to copy trace
+ *   Patrick Tasse - Close editors to release resources
+ *   Jean-Christian Kouame - added trace properties to be shown into
+ *                           the properties view
  *******************************************************************************/
 
 package org.eclipse.linuxtools.tmf.ui.project.model;
 
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
 import java.util.Map;
 
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IFolder;
 import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.ResourcesPlugin;
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.core.runtime.Platform;
-import org.eclipse.core.runtime.QualifiedName;
+import org.eclipse.linuxtools.internal.tmf.ui.Activator;
 import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomTxtEvent;
 import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomTxtTrace;
 import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomTxtTraceDefinition;
 import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomXmlEvent;
 import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomXmlTrace;
 import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomXmlTraceDefinition;
-import org.eclipse.linuxtools.tmf.core.event.TmfEvent;
+import org.eclipse.linuxtools.tmf.core.TmfCommonConstants;
+import org.eclipse.linuxtools.tmf.core.analysis.IAnalysisModuleHelper;
+import org.eclipse.linuxtools.tmf.core.analysis.TmfAnalysisManager;
+import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
+import org.eclipse.linuxtools.tmf.core.signal.TmfSignalHandler;
+import org.eclipse.linuxtools.tmf.core.signal.TmfSignalManager;
+import org.eclipse.linuxtools.tmf.core.signal.TmfTraceOpenedSignal;
 import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
-import org.eclipse.linuxtools.tmf.core.util.TmfTraceType;
+import org.eclipse.linuxtools.tmf.core.trace.ITmfTraceProperties;
+import org.eclipse.linuxtools.tmf.core.trace.TmfTrace;
+import org.eclipse.linuxtools.tmf.core.trace.TmfTraceManager;
 import org.eclipse.linuxtools.tmf.ui.editors.TmfEventsEditor;
+import org.eclipse.linuxtools.tmf.ui.properties.ReadOnlyTextPropertyDescriptor;
 import org.eclipse.ui.IActionFilter;
+import org.eclipse.ui.IEditorReference;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.part.FileEditorInput;
 import org.eclipse.ui.views.properties.IPropertyDescriptor;
 import org.eclipse.ui.views.properties.IPropertySource2;
-import org.eclipse.ui.views.properties.TextPropertyDescriptor;
 
 /**
- * <b><u>TmfTraceElement</u></b>
- * <p>
+ * Implementation of trace model element representing a trace. It provides
+ * methods to instantiate <code>ITmfTrace</code> and <code>ITmfEvent</code> as
+ * well as editor ID from the trace type extension definition.
+ *
+ * @version 1.0
+ * @author Francois Chouinard
  */
-public class TmfTraceElement extends TmfProjectModelElement implements IActionFilter, IPropertySource2 {
+public class TmfTraceElement extends TmfWithFolderElement implements IActionFilter, IPropertySource2 {
 
     // ------------------------------------------------------------------------
     // Constants
     // ------------------------------------------------------------------------
 
-    // Property keys
-    public static final QualifiedName TRACEBUNDLE = new QualifiedName("org.eclipse.linuxtools.tmf", "tracetype.bundle"); //$NON-NLS-1$//$NON-NLS-2$
-    public static final QualifiedName TRACETYPE = new QualifiedName("org.eclipse.linuxtools.tmf", "tracetype.id"); //$NON-NLS-1$//$NON-NLS-2$
-    public static final QualifiedName TRACEICON = new QualifiedName("org.eclipse.linuxtools.tmf", "tracetype.icon"); //$NON-NLS-1$//$NON-NLS-2$
-
     // Other attributes
+    /**
+     * Bundle attribute name
+     */
     public static final String BUNDLE = "bundle"; //$NON-NLS-1$
+    /**
+     * IsLinked attribute name.
+     */
     public static final String IS_LINKED = "isLinked"; //$NON-NLS-1$
 
     // 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 sfEventType = "type"; //$NON-NLS-1$
-    private static final String sfIsLinked = "linked"; //$NON-NLS-1$
-
-    private static final TextPropertyDescriptor sfNameDescriptor = new TextPropertyDescriptor(sfName, sfName);
-    private static final TextPropertyDescriptor sfPathDescriptor = new TextPropertyDescriptor(sfPath, sfPath);
-    private static final TextPropertyDescriptor sfLocationDescriptor = new TextPropertyDescriptor(sfLocation, sfLocation);
-    private static final TextPropertyDescriptor sfTypeDescriptor = new TextPropertyDescriptor(sfEventType, sfEventType);
-    private static final TextPropertyDescriptor sfIsLinkedDescriptor = new TextPropertyDescriptor(sfIsLinked, sfIsLinked);
+    private static final String sfResourcePropertiesCategory = Messages.TmfTraceElement_ResourceProperties;
+    private static final String sfName = Messages.TmfTraceElement_Name;
+    private static final String sfPath = Messages.TmfTraceElement_Path;
+    private static final String sfLocation = Messages.TmfTraceElement_Location;
+    private static final String sfEventType = Messages.TmfTraceElement_EventType;
+    private static final String sfIsLinked = Messages.TmfTraceElement_IsLinked;
+    private static final String sfTracePropertiesCategory = Messages.TmfTraceElement_TraceProperties;
+
+    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(sfEventType, sfEventType);
+    private static final ReadOnlyTextPropertyDescriptor sfIsLinkedDescriptor = new ReadOnlyTextPropertyDescriptor(sfIsLinked, sfIsLinked);
 
     private static final IPropertyDescriptor[] sfDescriptors = { sfNameDescriptor, sfPathDescriptor, sfLocationDescriptor,
             sfTypeDescriptor, sfIsLinkedDescriptor };
 
     static {
-        sfNameDescriptor.setCategory(sfInfoCategory);
-        sfPathDescriptor.setCategory(sfInfoCategory);
-        sfLocationDescriptor.setCategory(sfInfoCategory);
-        sfTypeDescriptor.setCategory(sfInfoCategory);
-        sfIsLinkedDescriptor.setCategory(sfInfoCategory);
+        sfNameDescriptor.setCategory(sfResourcePropertiesCategory);
+        sfPathDescriptor.setCategory(sfResourcePropertiesCategory);
+        sfLocationDescriptor.setCategory(sfResourcePropertiesCategory);
+        sfTypeDescriptor.setCategory(sfResourcePropertiesCategory);
+        sfIsLinkedDescriptor.setCategory(sfResourcePropertiesCategory);
     }
 
+    private static final String BOOKMARKS_HIDDEN_FILE = ".bookmarks"; //$NON-NLS-1$
+
     // ------------------------------------------------------------------------
     // Attributes
     // ------------------------------------------------------------------------
@@ -91,11 +130,15 @@ public class TmfTraceElement extends TmfProjectModelElement implements IActionFi
     // Static initialization
     // ------------------------------------------------------------------------
 
-    // The mapping of available trace type IDs to their corresponding configuration element
+    // The mapping of available trace type IDs to their corresponding
+    // configuration element
     private static final Map<String, IConfigurationElement> sfTraceTypeAttributes = new HashMap<String, IConfigurationElement>();
     private static final Map<String, IConfigurationElement> sfTraceCategories = new HashMap<String, IConfigurationElement>();
 
-    // Initialize statically at startup
+    /**
+     * Initialize statically at startup by getting extensions from the platform
+     * extension registry.
+     */
     public static void init() {
         IConfigurationElement[] config = Platform.getExtensionRegistry().getConfigurationElementsFor(TmfTraceType.TMF_TRACE_TYPE_ID);
         for (IConfigurationElement ce : config) {
@@ -113,11 +156,30 @@ public class TmfTraceElement extends TmfProjectModelElement implements IActionFi
     // ------------------------------------------------------------------------
     // Constructors
     // ------------------------------------------------------------------------
-
+    /**
+     * Constructor. Creates trace model element under the trace folder.
+     *
+     * @param name
+     *            The name of trace
+     * @param trace
+     *            The trace resource.
+     * @param parent
+     *            The parent element (trace folder)
+     */
     public TmfTraceElement(String name, IResource trace, TmfTraceFolder parent) {
         this(name, trace, (TmfProjectModelElement) parent);
     }
 
+    /**
+     * Constructor. Creates trace model element under the experiment folder.
+     *
+     * @param name
+     *            The name of trace
+     * @param trace
+     *            The trace resource.
+     * @param parent
+     *            The parent element (experiment folder)
+     */
     public TmfTraceElement(String name, IResource trace, TmfExperimentElement parent) {
         this(name, trace, (TmfProjectModelElement) parent);
     }
@@ -126,26 +188,46 @@ public class TmfTraceElement extends TmfProjectModelElement implements IActionFi
         super(name, trace, parent);
         parent.addChild(this);
         refreshTraceType();
+        TmfSignalManager.register(this);
     }
 
     // ------------------------------------------------------------------------
     // Operations
     // ------------------------------------------------------------------------
-
+    /**
+     * Returns the trace type ID.
+     *
+     * @return trace type ID.
+     */
     public String getTraceType() {
         return fTraceTypeId;
     }
 
+    /**
+     * Refreshes the trace type filed by reading the trace type persistent
+     * property of the resource referenece.
+     */
     public void refreshTraceType() {
         try {
-            fTraceTypeId = getResource().getPersistentProperty(TRACETYPE);
+            fTraceTypeId = getResource().getPersistentProperty(TmfCommonConstants.TRACETYPE);
+            refreshAnalysis();
         } catch (CoreException e) {
-            e.printStackTrace();
+            Activator.getDefault().logError("Error refreshing trace type pesistent property for trace " + getName(), e); //$NON-NLS-1$
         }
     }
 
-    public ITmfTrace<?> instantiateTrace() {
+    /**
+     * Instantiate a <code>ITmfTrace</code> object based on the trace type and
+     * the corresponding extension.
+     *
+     * @return the <code>ITmfTrace</code> or <code>null</code> for an error
+     */
+    public ITmfTrace instantiateTrace() {
         try {
+
+            // make sure that supplementary folder exists
+            refreshSupplementaryFolder();
+
             if (fTraceTypeId != null) {
                 if (fTraceTypeId.startsWith(CustomTxtTrace.class.getCanonicalName())) {
                     for (CustomTxtTraceDefinition def : CustomTxtTraceDefinition.loadAll()) {
@@ -162,16 +244,25 @@ public class TmfTraceElement extends TmfProjectModelElement implements IActionFi
                     }
                 }
                 IConfigurationElement ce = sfTraceTypeAttributes.get(fTraceTypeId);
-                ITmfTrace<?> trace = (ITmfTrace<?>) ce.createExecutableExtension(TmfTraceType.TRACE_TYPE_ATTR);
+                if (ce == null) {
+                    return null;
+                }
+                ITmfTrace trace = (ITmfTrace) ce.createExecutableExtension(TmfTraceType.TRACE_TYPE_ATTR);
                 return trace;
             }
         } catch (CoreException e) {
-            e.printStackTrace();
+            Activator.getDefault().logError("Error instantiating ITmfTrace object for trace " + getName(), e); //$NON-NLS-1$
         }
         return null;
     }
 
-    public TmfEvent instantiateEvent() {
+    /**
+     * Instantiate a <code>ITmfEvent</code> object based on the trace type and
+     * the corresponding extension.
+     *
+     * @return the <code>ITmfEvent</code> or <code>null</code> for an error
+     */
+    public ITmfEvent instantiateEvent() {
         try {
             if (fTraceTypeId != null) {
                 if (fTraceTypeId.startsWith(CustomTxtTrace.class.getCanonicalName())) {
@@ -189,15 +280,23 @@ public class TmfTraceElement extends TmfProjectModelElement implements IActionFi
                     }
                 }
                 IConfigurationElement ce = sfTraceTypeAttributes.get(fTraceTypeId);
-                TmfEvent event = (TmfEvent) ce.createExecutableExtension(TmfTraceType.EVENT_TYPE_ATTR);
+                if (ce == null) {
+                    return null;
+                }
+                ITmfEvent event = (ITmfEvent) ce.createExecutableExtension(TmfTraceType.EVENT_TYPE_ATTR);
                 return event;
             }
         } catch (CoreException e) {
-            e.printStackTrace();
+            Activator.getDefault().logError("Error instantiating ITmfEvent object for trace " + getName(), e); //$NON-NLS-1$
         }
         return null;
     }
 
+    /**
+     * Returns the optional editor ID from the trace type extension.
+     *
+     * @return the editor ID or <code>null</code> if not defined.
+     */
     public String getEditorId() {
         if (fTraceTypeId != null) {
             if (fTraceTypeId.startsWith(CustomTxtTrace.class.getCanonicalName())) {
@@ -215,6 +314,76 @@ public class TmfTraceElement extends TmfProjectModelElement implements IActionFi
         return null;
     }
 
+    /**
+     * Returns the file resource used to store bookmarks after creating it if
+     * necessary. If the trace resource is a file, it is returned directly. If
+     * the trace resource is a folder, a linked file is returned. The file will
+     * be created if it does not exist.
+     *
+     * @return the bookmarks file
+     * @throws CoreException
+     *             if the bookmarks file cannot be created
+     * @since 2.0
+     */
+    public IFile createBookmarksFile() throws CoreException {
+        IFile file = getBookmarksFile();
+        if (fResource instanceof IFolder) {
+            if (!file.exists()) {
+                final IFile bookmarksFile = getProject().getTracesFolder().getResource().getFile(BOOKMARKS_HIDDEN_FILE);
+                if (!bookmarksFile.exists()) {
+                    final InputStream source = new ByteArrayInputStream(new byte[0]);
+                    bookmarksFile.create(source, true, null);
+                }
+                bookmarksFile.setHidden(true);
+                file.createLink(bookmarksFile.getLocation(), IResource.REPLACE, null);
+                file.setHidden(true);
+                file.setPersistentProperty(TmfCommonConstants.TRACETYPE, TmfTrace.class.getCanonicalName());
+            }
+        }
+        return file;
+    }
+
+    /**
+     * Returns the file resource used to store bookmarks. The file may not
+     * exist.
+     *
+     * @return the bookmarks file
+     * @since 2.0
+     */
+    public IFile getBookmarksFile() {
+        IFile file = null;
+        if (fResource instanceof IFile) {
+            file = (IFile) fResource;
+        } else if (fResource instanceof IFolder) {
+            final IFolder folder = (IFolder) fResource;
+            file = folder.getFile(getName() + '_');
+        }
+        return file;
+    }
+
+    /**
+     * Returns the <code>TmfTraceElement</code> located under the
+     * <code>TmfTracesFolder</code>.
+     *
+     * @return <code>this</code> if this element is under the
+     *         <code>TmfTracesFolder</code> else the corresponding
+     *         <code>TmfTraceElement</code> if this element is under
+     *         <code>TmfExperimentElement</code>.
+     */
+    public TmfTraceElement getElementUnderTraceFolder() {
+
+        // If trace is under an experiment, return original trace from the
+        // traces folder
+        if (getParent() instanceof TmfExperimentElement) {
+            for (TmfTraceElement aTrace : getProject().getTracesFolder().getTraces()) {
+                if (aTrace.getName().equals(getName())) {
+                    return aTrace;
+                }
+            }
+        }
+        return this;
+    }
+
     // ------------------------------------------------------------------------
     // IActionFilter
     // ------------------------------------------------------------------------
@@ -257,25 +426,66 @@ public class TmfTraceElement extends TmfProjectModelElement implements IActionFi
         return null;
     }
 
+    /**
+     * Get the trace properties of this traceElement if the corresponding trace
+     * is opened in an editor
+     *
+     * @return a map with the names and values of the trace properties
+     *         respectively as keys and values
+     */
+    private Map<String, String> getTraceProperties() {
+        for (ITmfTrace openedTrace : TmfTraceManager.getInstance().getOpenedTraces()) {
+            for (ITmfTrace singleTrace : TmfTraceManager.getTraceSet(openedTrace)) {
+                if (this.getLocation().toString().endsWith(singleTrace.getPath())) {
+                    if (singleTrace instanceof ITmfTraceProperties) {
+                        ITmfTraceProperties traceProperties = (ITmfTraceProperties) singleTrace;
+                        return traceProperties.getTraceProperties();
+                    }
+                }
+            }
+        }
+        return new HashMap<String, String>();
+    }
+
     @Override
     public IPropertyDescriptor[] getPropertyDescriptors() {
-        return (sfDescriptors != null) ? Arrays.copyOf(sfDescriptors, sfDescriptors.length) : null;
+        Map<String, String> traceProperties = getTraceProperties();
+        if (!traceProperties.isEmpty()) {
+            IPropertyDescriptor[] propertyDescriptorArray = new IPropertyDescriptor[traceProperties.size() + sfDescriptors.length];
+            int index = 0;
+            for (Map.Entry<String, String> varName : traceProperties.entrySet()) {
+                ReadOnlyTextPropertyDescriptor descriptor = new ReadOnlyTextPropertyDescriptor(this.getName() + "_" + varName.getKey(), varName.getKey()); //$NON-NLS-1$
+                descriptor.setCategory(sfTracePropertiesCategory);
+                propertyDescriptorArray[index] = descriptor;
+                index++;
+            }
+            for (int i = 0; i < sfDescriptors.length; i++) {
+                propertyDescriptorArray[index] = sfDescriptors[i];
+                index++;
+            }
+            return propertyDescriptorArray;
+        }
+        return Arrays.copyOf(sfDescriptors, sfDescriptors.length);
     }
 
     @Override
     public Object getPropertyValue(Object id) {
 
-        if (sfName.equals(id))
+        if (sfName.equals(id)) {
             return getName();
+        }
 
-        if (sfPath.equals(id))
+        if (sfPath.equals(id)) {
             return getPath().toString();
+        }
 
-        if (sfLocation.equals(id))
+        if (sfLocation.equals(id)) {
             return getLocation().toString();
+        }
 
-        if (sfIsLinked.equals(id))
+        if (sfIsLinked.equals(id)) {
             return Boolean.valueOf(getResource().isLinked()).toString();
+        }
 
         if (sfEventType.equals(id)) {
             if (fTraceTypeId != null) {
@@ -284,10 +494,18 @@ public class TmfTraceElement extends TmfProjectModelElement implements IActionFi
             }
         }
 
+        Map<String, String> traceProperties = getTraceProperties();
+        if (id != null && !traceProperties.isEmpty()) {
+            String key = (String) id;
+            key = key.replaceFirst(this.getName() + "_", ""); //$NON-NLS-1$ //$NON-NLS-2$
+            String value = traceProperties.get(key);
+            return value;
+        }
+
         return null;
     }
 
-    private String getCategory(IConfigurationElement ce) {
+    private static String getCategory(IConfigurationElement ce) {
         String categoryId = ce.getAttribute(TmfTraceType.CATEGORY_ATTR);
         if (categoryId != null) {
             IConfigurationElement category = sfTraceCategories.get(categoryId);
@@ -316,4 +534,196 @@ public class TmfTraceElement extends TmfProjectModelElement implements IActionFi
         return false;
     }
 
+    /**
+     * Copy this trace in the trace folder. No other parameters are mentioned so
+     * the trace is copied in this element's project trace folder
+     *
+     * @param string
+     *            The new trace name
+     * @return the new Resource object
+     * @since 2.0
+     */
+    public TmfTraceElement copy(String string) {
+        TmfTraceFolder folder = this.getProject().getTracesFolder();
+        IResource res = super.copy(string, false);
+        return new TmfTraceElement(string, res, folder);
+    }
+
+    /**
+     * Close opened editors associated with this trace.
+     *
+     * @since 2.0
+     */
+    public void closeEditors() {
+        // Close the trace if open
+        IFile file = getBookmarksFile();
+        FileEditorInput input = new FileEditorInput(file);
+        IWorkbench wb = PlatformUI.getWorkbench();
+        for (IWorkbenchWindow wbWindow : wb.getWorkbenchWindows()) {
+            for (IWorkbenchPage wbPage : wbWindow.getPages()) {
+                for (IEditorReference editorReference : wbPage.getEditorReferences()) {
+                    try {
+                        if (editorReference.getEditorInput().equals(input)) {
+                            wbPage.closeEditor(editorReference.getEditor(false), false);
+                        }
+                    } catch (PartInitException e) {
+                        Activator.getDefault().logError("Error closing editor for trace " + getName(), e); //$NON-NLS-1$
+                    }
+                }
+            }
+        }
+
+        // Close experiments that contain the trace if open
+        if (getParent() instanceof TmfTraceFolder) {
+            TmfExperimentFolder experimentFolder = getProject().getExperimentsFolder();
+            for (ITmfProjectModelElement experiment : experimentFolder.getChildren()) {
+                for (ITmfProjectModelElement child : experiment.getChildren()) {
+                    if (child.getName().equals(getName())) {
+                        ((TmfExperimentElement) experiment).closeEditors();
+                        break;
+                    }
+                }
+            }
+        } else if (getParent() instanceof TmfExperimentElement) {
+            TmfExperimentElement experiment = (TmfExperimentElement) getParent();
+            experiment.closeEditors();
+        }
+    }
+
+    /**
+     * Delete the trace resource, remove it from experiments and delete its
+     * supplementary files
+     *
+     * @param progressMonitor
+     *            a progress monitor, or null if progress reporting is not
+     *            desired
+     *
+     * @throws CoreException
+     *             thrown when IResource.delete fails
+     * @since 2.2
+     */
+    public void delete(IProgressMonitor progressMonitor) throws CoreException {
+        closeEditors();
+
+        IPath path = fResource.getLocation();
+        if (path != null && (getParent() instanceof TmfTraceFolder)) {
+            TmfExperimentFolder experimentFolder = getProject().getExperimentsFolder();
+
+            // Propagate the removal to traces
+            for (ITmfProjectModelElement experiment : experimentFolder.getChildren()) {
+                List<ITmfProjectModelElement> toRemove = new LinkedList<ITmfProjectModelElement>();
+                for (ITmfProjectModelElement child : experiment.getChildren()) {
+                    if (child.getName().equals(getName())) {
+                        toRemove.add(child);
+                    }
+                }
+                for (ITmfProjectModelElement child : toRemove) {
+                    ((TmfExperimentElement) experiment).removeTrace((TmfTraceElement) child);
+                }
+            }
+
+            // Delete supplementary files
+            deleteSupplementaryFolder();
+        }
+
+        // Finally, delete the trace
+        fResource.delete(true, progressMonitor);
+    }
+
+    /**
+     * Get the instantiated trace associated with this element.
+     *
+     * @return The instantiated trace or null if trace is not (yet) available
+     * @since 2.1
+     */
+    public ITmfTrace getTrace() {
+        for (ITmfTrace trace : TmfTraceManager.getInstance().getOpenedTraces()) {
+            if (trace.getResource().equals(getResource())) {
+                return trace;
+            }
+        }
+        return null;
+    }
+
+    private void refreshAnalysis() {
+        List<TmfAnalysisElement> list = getAvailableAnalysis();
+
+        /* Remove children */
+        getChildren().clear();
+
+        /* Add the children again */
+        for (TmfAnalysisElement module : list) {
+            addChild(module);
+        }
+
+    }
+
+    /**
+     * Get the list of analysis elements
+     *
+     * @return Array of analysis elements
+     * @since 3.0
+     */
+    public List<TmfAnalysisElement> getAvailableAnalysis() {
+        List<TmfAnalysisElement> list = new ArrayList<TmfAnalysisElement>();
+
+        TraceTypeHelper helper = TmfTraceType.getInstance().getTraceType(getTraceType());
+
+        Class<? extends ITmfTrace> traceClass = null;
+
+        if (helper == null && fTraceTypeId != null) {
+            if (fTraceTypeId.startsWith(CustomTxtTrace.class.getCanonicalName())) {
+                for (CustomTxtTraceDefinition def : CustomTxtTraceDefinition.loadAll()) {
+                    if (fTraceTypeId.equals(CustomTxtTrace.class.getCanonicalName() + ":" + def.definitionName)) { //$NON-NLS-1$
+                        traceClass = CustomTxtTrace.class;
+                    }
+                }
+            }
+            if (fTraceTypeId.startsWith(CustomXmlTrace.class.getCanonicalName())) {
+                for (CustomXmlTraceDefinition def : CustomXmlTraceDefinition.loadAll()) {
+                    if (fTraceTypeId.equals(CustomXmlTrace.class.getCanonicalName() + ":" + def.definitionName)) { //$NON-NLS-1$
+                        traceClass = CustomTxtTrace.class;
+                    }
+                }
+            }
+        } else if (helper != null) {
+            traceClass = helper.getTraceClass();
+        }
+
+        if (traceClass == null) {
+            return list;
+        }
+
+        /** Get the base path to put the resource to */
+        IPath path = fResource.getFullPath();
+
+        for (IAnalysisModuleHelper module : TmfAnalysisManager.getAnalysisModules(traceClass).values()) {
+
+            /** No need for the resource to exist, nothing will be done with it */
+            IFolder newresource = ResourcesPlugin.getWorkspace().getRoot().getFolder(path.append(module.getId()));
+
+            TmfAnalysisElement analysis = new TmfAnalysisElement(module.getName(), newresource, this, module.getId());
+            list.add(analysis);
+        }
+
+        return list;
+    }
+
+    /**
+     * Handler for the Trace Opened signal
+     *
+     * @param signal
+     *            The incoming signal
+     * @since 3.0
+     */
+    @TmfSignalHandler
+    public void traceOpened(TmfTraceOpenedSignal signal) {
+        IResource resource = signal.getTrace().getResource();
+        if ((resource == null) || !resource.equals(getResource())) {
+            return;
+        }
+
+        refreshAnalysis();
+        getParent().refresh();
+    }
 }
This page took 0.03229 seconds and 5 git commands to generate.