/*******************************************************************************
- * Copyright (c) 2010, 2013 Ericsson, École Polytechnique de Montréal
+ * 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
* 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.io.ByteArrayInputStream;
-import java.io.InputStream;
-import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedList;
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.URIUtil;
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.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.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.trace.ITmfTraceProperties;
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;
* @version 1.0
* @author Francois Chouinard
*/
-public class TmfTraceElement extends TmfWithFolderElement implements IActionFilter, IPropertySource2 {
+public class TmfTraceElement extends TmfCommonProjectElement implements IActionFilter, IPropertySource2 {
// ------------------------------------------------------------------------
// Constants
sfIsLinkedDescriptor.setCategory(sfResourcePropertiesCategory);
}
- private static final String BOOKMARKS_HIDDEN_FILE = ".bookmarks"; //$NON-NLS-1$
-
- // ------------------------------------------------------------------------
- // 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 Map<String, IConfigurationElement> sfTraceTypeAttributes = new HashMap<String, IConfigurationElement>();
- private static final Map<String, IConfigurationElement> sfTraceCategories = new HashMap<String, IConfigurationElement>();
+ private static final Map<String, IConfigurationElement> sfTraceTypeAttributes = new HashMap<>();
+ private static final Map<String, IConfigurationElement> sfTraceTypeUIAttributes = new HashMap<>();
+ private static final Map<String, IConfigurationElement> sfTraceCategories = new HashMap<>();
/**
* Initialize statically at startup by getting extensions from the platform
* extension registry.
*/
public static void init() {
+ /* Read the tmf.core "tracetype" extension point */
IConfigurationElement[] config = Platform.getExtensionRegistry().getConfigurationElementsFor(TmfTraceType.TMF_TRACE_TYPE_ID);
for (IConfigurationElement ce : config) {
- String elementName = ce.getName();
- if (elementName.equals(TmfTraceType.TYPE_ELEM)) {
+ switch (ce.getName()) {
+ case TmfTraceType.TYPE_ELEM:
String traceTypeId = ce.getAttribute(TmfTraceType.ID_ATTR);
sfTraceTypeAttributes.put(traceTypeId, ce);
- } else if (elementName.equals(TmfTraceType.CATEGORY_ELEM)) {
+ break;
+ case TmfTraceType.CATEGORY_ELEM:
String categoryId = ce.getAttribute(TmfTraceType.ID_ATTR);
sfTraceCategories.put(categoryId, ce);
+ break;
+ default:
+ }
+ }
+
+ /*
+ * Read the corresponding tmf.ui "tracetypeui" extension point for this
+ * trace type, if it exists.
+ */
+ config = Platform.getExtensionRegistry().getConfigurationElementsFor(TmfTraceTypeUIUtils.TMF_TRACE_TYPE_UI_ID);
+ for (IConfigurationElement ce : config) {
+ String elemName = ce.getName();
+ if (TmfTraceTypeUIUtils.TYPE_ELEM.equals(elemName)) {
+ String traceType = ce.getAttribute(TmfTraceTypeUIUtils.TRACETYPE_ATTR);
+ sfTraceTypeUIAttributes.put(traceType, ce);
}
}
}
private TmfTraceElement(String name, IResource trace, TmfProjectModelElement parent) {
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(TmfCommonConstants.TRACETYPE);
- refreshAnalysis();
- } catch (CoreException e) {
- Activator.getDefault().logError("Error refreshing trace type pesistent property for trace " + getName(), e); //$NON-NLS-1$
- }
- }
/**
* Instantiate a <code>ITmfTrace</code> object based on the trace type and
*
* @return the <code>ITmfTrace</code> or <code>null</code> for an error
*/
+ @Override
public ITmfTrace instantiateTrace() {
try {
// make sure that supplementary folder exists
refreshSupplementaryFolder();
- 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 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);
+ IConfigurationElement ce = sfTraceTypeAttributes.get(getTraceType());
if (ce == null) {
return null;
}
*/
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);
+ IConfigurationElement ce = sfTraceTypeAttributes.get(getTraceType());
if (ce == null) {
return null;
}
return null;
}
- /**
- * Returns the optional editor ID from the trace type extension.
- *
- * @return the editor ID or <code>null</code> if not defined.
- */
+ @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);
}
* if the bookmarks file cannot be created
* @since 2.0
*/
+ @Override
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 createBookmarksFile(getProject().getTracesFolder().getResource(), TmfTrace.class.getCanonicalName());
}
return file;
}
* @return the bookmarks file
* @since 2.0
*/
+ @Override
public IFile getBookmarksFile() {
IFile file = null;
if (fResource instanceof IFile) {
return this;
}
+ @Override
+ public String getTypeName() {
+ return Messages.TmfTraceElement_TypeName;
+ }
+
// ------------------------------------------------------------------------
// IActionFilter
// ------------------------------------------------------------------------
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 (this.getLocation().getPath().endsWith(singleTrace.getPath())) {
if (singleTrace instanceof ITmfTraceProperties) {
ITmfTraceProperties traceProperties = (ITmfTraceProperties) singleTrace;
return traceProperties.getTraceProperties();
}
}
}
- return new HashMap<String, String>();
+ return new HashMap<>();
}
@Override
}
if (sfLocation.equals(id)) {
- return getLocation().toString();
+ return URIUtil.toUnencodedString(getLocation());
}
if (sfIsLinked.equals(id)) {
}
if (sfEventType.equals(id)) {
- if (fTraceTypeId != null) {
- IConfigurationElement ce = sfTraceTypeAttributes.get(fTraceTypeId);
+ if (getTraceType() != null) {
+ IConfigurationElement ce = sfTraceTypeAttributes.get(getTraceType());
return (ce != null) ? (getCategory(ce) + " : " + ce.getAttribute(TmfTraceType.NAME_ATTR)) : ""; //$NON-NLS-1$ //$NON-NLS-2$
}
}
*
* @since 2.0
*/
+ @Override
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$
- }
- }
- }
- }
+ super.closeEditors();
// Close experiments that contain the trace if open
if (getParent() instanceof TmfTraceFolder) {
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 (path != null) {
+ if (getParent() instanceof TmfTraceFolder) {
+ TmfExperimentFolder experimentFolder = getProject().getExperimentsFolder();
+
+ // Propagate the removal to traces
+ for (ITmfProjectModelElement experiment : experimentFolder.getChildren()) {
+ List<ITmfProjectModelElement> toRemove = new LinkedList<>();
+ for (ITmfProjectModelElement child : experiment.getChildren()) {
+ if (child.getName().equals(getName())) {
+ toRemove.add(child);
+ }
}
- }
- }
- 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;
+ for (ITmfProjectModelElement child : toRemove) {
+ ((TmfExperimentElement) experiment).removeTrace((TmfTraceElement) child);
}
}
- }
- } 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();
+ // Delete supplementary files
+ deleteSupplementaryFolder();
- 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);
+ } else if (getParent() instanceof TmfExperimentElement) {
+ TmfExperimentElement experimentElement = (TmfExperimentElement) getParent();
+ experimentElement.removeTrace(this);
+ }
}
- return list;
+ // Finally, delete the trace
+ fResource.delete(true, progressMonitor);
}
- /**
- * Handler for the Trace Opened signal
- *
- * @param signal
- * The incoming signal
- */
- @TmfSignalHandler
- public void traceOpened(TmfTraceOpenedSignal signal) {
- IResource resource = signal.getTrace().getResource();
- if ((resource == null) || !resource.equals(getResource())) {
- return;
- }
-
- refreshAnalysis();
- getParent().refresh();
- }
}