X-Git-Url: http://drtracing.org/?a=blobdiff_plain;f=org.eclipse.linuxtools.tmf.ui%2Fsrc%2Forg%2Feclipse%2Flinuxtools%2Ftmf%2Fui%2Fproject%2Fmodel%2FTmfTraceElement.java;h=2a81f93472c5ccb4e72a8766ebf4044bb86a6344;hb=080600d9018f188e488a634be6e25bf91d3f692b;hp=c30e692759f7ce10f7083c022ff49eb56b1b6f0e;hpb=82cbc173f13cd74135f669f0f9b9f20519981215;p=deliverable%2Ftracecompass.git
diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfTraceElement.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfTraceElement.java
index c30e692759..2a81f93472 100644
--- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfTraceElement.java
+++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfTraceElement.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010, 2011, 2012 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
@@ -9,19 +9,24 @@
* 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
*******************************************************************************/
package org.eclipse.linuxtools.tmf.ui.project.model;
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
import java.util.Arrays;
import java.util.HashMap;
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.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
-import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Platform;
import org.eclipse.linuxtools.internal.tmf.ui.Activator;
import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomTxtEvent;
@@ -33,21 +38,29 @@ import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomXmlTraceDefin
import org.eclipse.linuxtools.tmf.core.TmfCommonConstants;
import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
+import org.eclipse.linuxtools.tmf.core.trace.TmfTrace;
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;
/**
- * Implementation of trace model element representing a trace. It provides methods to instantiate
- * ITmfTrace
and ITmfEvent
as well as editor ID from the trace type
- * extension definition.
+ * Implementation of trace model element representing a trace. It provides
+ * methods to instantiate ITmfTrace
and ITmfEvent
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
@@ -71,11 +84,11 @@ public class TmfTraceElement extends TmfProjectModelElement implements IActionFi
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 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 };
@@ -88,6 +101,8 @@ public class TmfTraceElement extends TmfProjectModelElement implements IActionFi
sfIsLinkedDescriptor.setCategory(sfInfoCategory);
}
+ private static final String BOOKMARKS_HIDDEN_FILE = ".bookmarks"; //$NON-NLS-1$
+
// ------------------------------------------------------------------------
// Attributes
// ------------------------------------------------------------------------
@@ -99,12 +114,14 @@ 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 sfTraceTypeAttributes = new HashMap();
private static final Map sfTraceCategories = new HashMap();
/**
- * Initialize statically at startup by getting extensions from the platform extension registry.
+ * 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);
@@ -124,21 +141,28 @@ 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)
+ * 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)
+ * 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);
@@ -155,6 +179,7 @@ public class TmfTraceElement extends TmfProjectModelElement implements IActionFi
// ------------------------------------------------------------------------
/**
* Returns the trace type ID.
+ *
* @return trace type ID.
*/
public String getTraceType() {
@@ -162,8 +187,8 @@ public class TmfTraceElement extends TmfProjectModelElement implements IActionFi
}
/**
- * Refreshes the trace type filed by reading the trace type persistent property of the resource
- * referenece.
+ * Refreshes the trace type filed by reading the trace type persistent
+ * property of the resource referenece.
*/
public void refreshTraceType() {
try {
@@ -174,7 +199,8 @@ public class TmfTraceElement extends TmfProjectModelElement implements IActionFi
}
/**
- * Instantiate a ITmfTrace
object based on the trace type and the corresponding extension.
+ * Instantiate a ITmfTrace
object based on the trace type and
+ * the corresponding extension.
*
* @return the ITmfTrace
or null
for an error
*/
@@ -200,6 +226,9 @@ public class TmfTraceElement extends TmfProjectModelElement implements IActionFi
}
}
IConfigurationElement ce = sfTraceTypeAttributes.get(fTraceTypeId);
+ if (ce == null) {
+ return null;
+ }
ITmfTrace trace = (ITmfTrace) ce.createExecutableExtension(TmfTraceType.TRACE_TYPE_ATTR);
return trace;
}
@@ -210,7 +239,8 @@ public class TmfTraceElement extends TmfProjectModelElement implements IActionFi
}
/**
- * Instantiate a ITmfEvent
object based on the trace type and the corresponding extension.
+ * Instantiate a ITmfEvent
object based on the trace type and
+ * the corresponding extension.
*
* @return the ITmfEvent
or null
for an error
*/
@@ -232,6 +262,9 @@ public class TmfTraceElement extends TmfProjectModelElement implements IActionFi
}
}
IConfigurationElement ce = sfTraceTypeAttributes.get(fTraceTypeId);
+ if (ce == null) {
+ return null;
+ }
ITmfEvent event = (ITmfEvent) ce.createExecutableExtension(TmfTraceType.EVENT_TYPE_ATTR);
return event;
}
@@ -243,6 +276,7 @@ public class TmfTraceElement extends TmfProjectModelElement implements IActionFi
/**
* Returns the optional editor ID from the trace type extension.
+ *
* @return the editor ID or null
if not defined.
*/
public String getEditorId() {
@@ -263,163 +297,73 @@ public class TmfTraceElement extends TmfProjectModelElement implements IActionFi
}
/**
- * Returns the TmfTraceElement
located under the TmfTracesFolder
.
+ * 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 this
if this element is under the TmfTracesFolder
- * else the corresponding TmfTraceElement
if this element is under
- * TmfExperimentElement
.
+ * @return the bookmarks file
+ * @throws CoreException
+ * if the bookmarks file cannot be created
+ * @since 2.0
*/
- 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;
+ 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 this;
- }
-
- /**
- * Deletes the trace specific supplementary folder.
- */
- public void deleteSupplementaryFolder() {
- IFolder supplFolder = getTraceSupplementaryFolder(fResource.getName());
- if (supplFolder.exists()) {
- try {
- supplFolder.delete(true, new NullProgressMonitor());
- } catch (CoreException e) {
- Activator.getDefault().logError("Error deleting supplementary folder " + supplFolder, e); //$NON-NLS-1$
- }
- }
- }
-
- /**
- * Renames the trace specific supplementary folder according to the new trace name.
- *
- * @param newTraceName The new trace name
- */
- public void renameSupplementaryFolder(String newTraceName) {
- IFolder oldSupplFolder = getTraceSupplementaryFolder(fResource.getName());
- IFolder newSupplFolder = getTraceSupplementaryFolder(newTraceName);
-
- // Rename supplementary folder
- if (oldSupplFolder.exists()) {
- try {
- oldSupplFolder.move(newSupplFolder.getFullPath(), true, new NullProgressMonitor());
- } catch (CoreException e) {
- Activator.getDefault().logError("Error renaming supplementary folder " + oldSupplFolder, e); //$NON-NLS-1$
- }
- }
- }
-
- /**
- * Copies the trace specific supplementary folder to the new trace name.
- *
- * @param newTraceName The new trace name
- */
- public void copySupplementaryFolder(String newTraceName) {
- IFolder oldSupplFolder = getTraceSupplementaryFolder(fResource.getName());
- IFolder newSupplFolder = getTraceSupplementaryFolder(newTraceName);
-
- // copy supplementary folder
- if (oldSupplFolder.exists()) {
- try {
- oldSupplFolder.copy(newSupplFolder.getFullPath(), true, new NullProgressMonitor());
- } catch (CoreException e) {
- Activator.getDefault().logError("Error renaming supplementary folder " + oldSupplFolder, e); //$NON-NLS-1$
- }
- }
- }
-
- /**
- * Copies the trace specific supplementary folder a new folder.
- *
- * @param destination The destination folder to copy to.
- */
- public void copySupplementaryFolder(IFolder destination) {
- IFolder oldSupplFolder = getTraceSupplementaryFolder(fResource.getName());
-
- // copy supplementary folder
- if (oldSupplFolder.exists()) {
- try {
- oldSupplFolder.copy(destination.getFullPath(), true, new NullProgressMonitor());
- } catch (CoreException e) {
- Activator.getDefault().logError("Error copying supplementary folder " + oldSupplFolder, e); //$NON-NLS-1$
- }
- }
- }
-
-
- /**
- * Refreshes the trace specific supplementary folder information. It creates the folder if not exists.
- * It sets the persistence property of the trace resource
- */
- public void refreshSupplementaryFolder() {
- createSupplementaryDirectory();
- }
-
- /**
- * Checks if supplementary resource exist or not.
- *
- * @return true
if one or more files are under the trace supplementary folder
- */
- public boolean hasSupplementaryResources() {
- IResource[] resources = getSupplementaryResources();
- return (resources.length > 0);
+ return file;
}
/**
- * Returns the supplementary resources under the trace supplementary folder.
+ * Returns the file resource used to store bookmarks. The file may not
+ * exist.
*
- * @return array of resources under the trace supplementary folder.
+ * @return the bookmarks file
+ * @since 2.0
*/
- public IResource[] getSupplementaryResources() {
- IFolder supplFolder = getTraceSupplementaryFolder(fResource.getName());
- if (supplFolder.exists()) {
- try {
- return supplFolder.members();
- } catch (CoreException e) {
- Activator.getDefault().logError("Error deleting supplementary folder " + supplFolder, e); //$NON-NLS-1$
- }
+ 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 new IResource[0];
+ return file;
}
/**
- * Deletes the given resources.
+ * Returns the TmfTraceElement
located under the
+ * TmfTracesFolder
.
*
- * @param resources array of resources to delete.
+ * @return this
if this element is under the
+ * TmfTracesFolder
else the corresponding
+ * TmfTraceElement
if this element is under
+ * TmfExperimentElement
.
*/
- public void deleteSupplementaryResources(IResource[] resources) {
-
- for (int i = 0; i < resources.length; i++) {
- try {
- resources[i].delete(true, new NullProgressMonitor());
- } catch (CoreException e) {
- Activator.getDefault().logError("Error deleting supplementary resource " + resources[i], e); //$NON-NLS-1$
- }
- }
- }
+ public TmfTraceElement getElementUnderTraceFolder() {
- private void createSupplementaryDirectory() {
- IFolder supplFolder = getTraceSupplementaryFolder(fResource.getName());
- if (!supplFolder.exists()) {
- try {
- supplFolder.create(true, true, new NullProgressMonitor());
- } catch (CoreException e) {
- Activator.getDefault().logError("Error creating resource supplementary file " + supplFolder, e); //$NON-NLS-1$
+ // 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;
+ }
}
}
-
- try {
- fResource.setPersistentProperty(TmfCommonConstants.TRACE_SUPPLEMENTARY_FOLDER, supplFolder.getLocationURI().getPath());
- } catch (CoreException e) {
- Activator.getDefault().logError("Error setting persistant property " + TmfCommonConstants.TRACE_SUPPLEMENTARY_FOLDER, e); //$NON-NLS-1$
- }
-
+ return this;
}
// ------------------------------------------------------------------------
@@ -438,10 +382,7 @@ public class TmfTraceElement extends TmfProjectModelElement implements IActionFi
// ------------------------------------------------------------------------
// TmfTraceElement
// ------------------------------------------------------------------------
- /*
- * (non-Javadoc)
- * @see org.eclipse.linuxtools.tmf.ui.project.model.ITmfProjectModelElement#getProject()
- */
+
@Override
public TmfProjectElement getProject() {
if (getParent() instanceof TmfTraceFolder) {
@@ -462,28 +403,16 @@ public class TmfTraceElement extends TmfProjectModelElement implements IActionFi
// IPropertySource2
// ------------------------------------------------------------------------
- /*
- * (non-Javadoc)
- * @see org.eclipse.ui.views.properties.IPropertySource#getEditableValue()
- */
@Override
public Object getEditableValue() {
return null;
}
- /*
- * (non-Javadoc)
- * @see org.eclipse.ui.views.properties.IPropertySource#getPropertyDescriptors()
- */
@Override
public IPropertyDescriptor[] getPropertyDescriptors() {
- return (sfDescriptors != null) ? Arrays.copyOf(sfDescriptors, sfDescriptors.length) : null;
+ return Arrays.copyOf(sfDescriptors, sfDescriptors.length);
}
- /*
- * (non-Javadoc)
- * @see org.eclipse.ui.views.properties.IPropertySource#getPropertyValue(java.lang.Object)
- */
@Override
public Object getPropertyValue(Object id) {
@@ -524,38 +453,76 @@ public class TmfTraceElement extends TmfProjectModelElement implements IActionFi
return "[no category]"; //$NON-NLS-1$
}
- /*
- * (non-Javadoc)
- * @see org.eclipse.ui.views.properties.IPropertySource#resetPropertyValue(java.lang.Object)
- */
@Override
public void resetPropertyValue(Object id) {
}
- /*
- * (non-Javadoc)
- * @see org.eclipse.ui.views.properties.IPropertySource#setPropertyValue(java.lang.Object, java.lang.Object)
- */
@Override
public void setPropertyValue(Object id, Object value) {
}
- /*
- * (non-Javadoc)
- * @see org.eclipse.ui.views.properties.IPropertySource2#isPropertyResettable(java.lang.Object)
- */
@Override
public boolean isPropertyResettable(Object id) {
return false;
}
- /*
- * (non-Javadoc)
- * @see org.eclipse.ui.views.properties.IPropertySource2#isPropertySet(java.lang.Object)
- */
@Override
public boolean isPropertySet(Object id) {
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();
+ }
+ }
}