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=8ef4854ce3f4914cb907394362878ac57a3da03e;hb=13f2a21a0d71ebf754749fee4382264e453d850d;hp=30021e15908c6693e3cb3775e3ec9877cbe956e9;hpb=5a5c2fc71993d8dd81a2f4623bc9d02a0fe5ac81;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 30021e1590..8ef4854ce3 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,111 +1,149 @@ /******************************************************************************* - * Copyright (c) 2010, 2011 Ericsson - * + * Copyright (c) 2010, 2014 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 + * Geneviève Bastien - Moved trace type related methods to parent class *******************************************************************************/ package org.eclipse.linuxtools.tmf.ui.project.model; 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.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.tmf.core.event.TmfEvent; +import org.eclipse.core.runtime.URIUtil; +import org.eclipse.linuxtools.internal.tmf.ui.Activator; +import org.eclipse.linuxtools.tmf.core.event.ITmfEvent; +import org.eclipse.linuxtools.tmf.core.parsers.custom.CustomTxtEvent; +import org.eclipse.linuxtools.tmf.core.parsers.custom.CustomTxtTrace; +import org.eclipse.linuxtools.tmf.core.parsers.custom.CustomTxtTraceDefinition; +import org.eclipse.linuxtools.tmf.core.parsers.custom.CustomXmlEvent; +import org.eclipse.linuxtools.tmf.core.parsers.custom.CustomXmlTrace; +import org.eclipse.linuxtools.tmf.core.parsers.custom.CustomXmlTraceDefinition; +import org.eclipse.linuxtools.tmf.core.project.model.TmfTraceType; 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.parsers.custom.CustomTxtEvent; -import org.eclipse.linuxtools.tmf.ui.parsers.custom.CustomTxtTrace; -import org.eclipse.linuxtools.tmf.ui.parsers.custom.CustomTxtTraceDefinition; -import org.eclipse.linuxtools.tmf.ui.parsers.custom.CustomXmlEvent; -import org.eclipse.linuxtools.tmf.ui.parsers.custom.CustomXmlTrace; -import org.eclipse.linuxtools.tmf.ui.parsers.custom.CustomXmlTraceDefinition; +import org.eclipse.linuxtools.tmf.ui.properties.ReadOnlyTextPropertyDescriptor; import org.eclipse.ui.IActionFilter; import org.eclipse.ui.views.properties.IPropertyDescriptor; import org.eclipse.ui.views.properties.IPropertySource2; -import org.eclipse.ui.views.properties.TextPropertyDescriptor; /** - * TmfTraceElement - *
+ * 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 TmfCommonProjectElement 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);
}
- // ------------------------------------------------------------------------
- // Attributes
- // ------------------------------------------------------------------------
-
- // This trace type ID as defined in plugin.xml
- private String fTraceTypeId = null;
-
// ------------------------------------------------------------------------
// Static initialization
// ------------------------------------------------------------------------
- // The mapping of available trace type IDs to their corresponding configuration element
- private static final MapITmfTrace
object based on the trace type and
+ * the corresponding extension.
+ *
+ * @return the ITmfTrace
or null
for an error
+ */
+ @Override
+ public ITmfTrace instantiateTrace() {
try {
- fTraceTypeId = getResource().getPersistentProperty(TRACETYPE);
- } catch (CoreException e) {
- e.printStackTrace();
- }
- }
- public ITmfTrace> instantiateTrace() {
- try {
- if (fTraceTypeId != null) {
- if (fTraceTypeId.startsWith(CustomTxtTrace.class.getCanonicalName())) {
+ // make sure that supplementary folder exists
+ refreshSupplementaryFolder();
+
+ if (getTraceType() != null) {
+ if (getTraceType().startsWith(CustomTxtTrace.class.getCanonicalName())) {
for (CustomTxtTraceDefinition def : CustomTxtTraceDefinition.loadAll()) {
- if (fTraceTypeId.equals(CustomTxtTrace.class.getCanonicalName() + ":" + def.definitionName)) { //$NON-NLS-1$
+ if (getTraceType().equals(CustomTxtTrace.class.getCanonicalName() + ":" + def.definitionName)) { //$NON-NLS-1$
return new CustomTxtTrace(def);
}
}
}
- if (fTraceTypeId.startsWith(CustomXmlTrace.class.getCanonicalName())) {
+ if (getTraceType().startsWith(CustomXmlTrace.class.getCanonicalName())) {
for (CustomXmlTraceDefinition def : CustomXmlTraceDefinition.loadAll()) {
- if (fTraceTypeId.equals(CustomXmlTrace.class.getCanonicalName() + ":" + def.definitionName)) { //$NON-NLS-1$
+ if (getTraceType().equals(CustomXmlTrace.class.getCanonicalName() + ":" + def.definitionName)) { //$NON-NLS-1$
return new CustomXmlTrace(def);
}
}
}
- IConfigurationElement ce = sfTraceTypeAttributes.get(fTraceTypeId);
- ITmfTrace> trace = (ITmfTrace>) ce.createExecutableExtension(TmfTraceType.TRACE_TYPE_ATTR);
+ IConfigurationElement ce = sfTraceTypeAttributes.get(getTraceType());
+ 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 ITmfEvent
object based on the trace type and
+ * the corresponding extension.
+ *
+ * @return the ITmfEvent
or null
for an error
+ */
+ public ITmfEvent instantiateEvent() {
try {
- if (fTraceTypeId != null) {
- if (fTraceTypeId.startsWith(CustomTxtTrace.class.getCanonicalName())) {
+ if (getTraceType() != null) {
+ if (getTraceType().startsWith(CustomTxtTrace.class.getCanonicalName())) {
for (CustomTxtTraceDefinition def : CustomTxtTraceDefinition.loadAll()) {
- if (fTraceTypeId.equals(CustomTxtTrace.class.getCanonicalName() + ":" + def.definitionName)) { //$NON-NLS-1$
+ if (getTraceType().equals(CustomTxtTrace.class.getCanonicalName() + ":" + def.definitionName)) { //$NON-NLS-1$
return new CustomTxtEvent(def);
}
}
}
- if (fTraceTypeId.startsWith(CustomXmlTrace.class.getCanonicalName())) {
+ if (getTraceType().startsWith(CustomXmlTrace.class.getCanonicalName())) {
for (CustomXmlTraceDefinition def : CustomXmlTraceDefinition.loadAll()) {
- if (fTraceTypeId.equals(CustomXmlTrace.class.getCanonicalName() + ":" + def.definitionName)) { //$NON-NLS-1$
+ if (getTraceType().equals(CustomXmlTrace.class.getCanonicalName() + ":" + def.definitionName)) { //$NON-NLS-1$
return new CustomXmlEvent(def);
}
}
}
- IConfigurationElement ce = sfTraceTypeAttributes.get(fTraceTypeId);
- TmfEvent event = (TmfEvent) ce.createExecutableExtension(TmfTraceType.EVENT_TYPE_ATTR);
+ IConfigurationElement ce = sfTraceTypeAttributes.get(getTraceType());
+ 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;
}
+ @Override
public String getEditorId() {
- if (fTraceTypeId != null) {
- if (fTraceTypeId.startsWith(CustomTxtTrace.class.getCanonicalName())) {
+ if (getTraceType() != null) {
+ if (getTraceType().startsWith(CustomTxtTrace.class.getCanonicalName())) {
return TmfEventsEditor.ID;
}
- if (fTraceTypeId.startsWith(CustomXmlTrace.class.getCanonicalName())) {
+ if (getTraceType().startsWith(CustomXmlTrace.class.getCanonicalName())) {
return TmfEventsEditor.ID;
}
- IConfigurationElement ce = sfTraceTypeAttributes.get(fTraceTypeId);
- IConfigurationElement[] defaultEditorCE = ce.getChildren(TmfTraceType.DEFAULT_EDITOR_ELEM);
+ IConfigurationElement ce = sfTraceTypeUIAttributes.get(getTraceType());
+ if (ce == null) {
+ /* This trace type does not define UI attributes */
+ return null;
+ }
+ IConfigurationElement[] defaultEditorCE = ce.getChildren(TmfTraceTypeUIUtils.DEFAULT_EDITOR_ELEM);
if (defaultEditorCE.length == 1) {
return defaultEditorCE[0].getAttribute(TmfTraceType.ID_ATTR);
}
@@ -215,6 +286,73 @@ 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
+ */
+ @Override
+ public IFile createBookmarksFile() throws CoreException {
+ IFile file = getBookmarksFile();
+ if (fResource instanceof IFolder) {
+ return createBookmarksFile(getProject().getTracesFolder().getResource(), 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
+ */
+ @Override
+ 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 TmfTraceElement
located under the
+ * TmfTracesFolder
.
+ *
+ * @return this
if this element is under the
+ * TmfTracesFolder
else the corresponding
+ * TmfTraceElement
if this element is under
+ * TmfExperimentElement
.
+ */
+ 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;
+ }
+
+ @Override
+ public String getTypeName() {
+ return Messages.TmfTraceElement_TypeName;
+ }
+
// ------------------------------------------------------------------------
// IActionFilter
// ------------------------------------------------------------------------
@@ -257,37 +395,86 @@ 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