1 /*******************************************************************************
2 * Copyright (c) 2010, 2013 Ericsson, École Polytechnique de Montréal
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * Francois Chouinard - Initial API and implementation
11 * Bernd Hufmann - Added supplementary files handling
12 * Geneviève Bastien - Moved supplementary files handling to parent class,
13 * added code to copy trace
14 * Patrick Tasse - Close editors to release resources
15 * Jean-Christian Kouame - added trace properties to be shown into
17 *******************************************************************************/
19 package org
.eclipse
.linuxtools
.tmf
.ui
.project
.model
;
21 import java
.io
.ByteArrayInputStream
;
22 import java
.io
.InputStream
;
23 import java
.util
.ArrayList
;
24 import java
.util
.Arrays
;
25 import java
.util
.HashMap
;
26 import java
.util
.LinkedList
;
27 import java
.util
.List
;
30 import org
.eclipse
.core
.resources
.IFile
;
31 import org
.eclipse
.core
.resources
.IFolder
;
32 import org
.eclipse
.core
.resources
.IResource
;
33 import org
.eclipse
.core
.resources
.ResourcesPlugin
;
34 import org
.eclipse
.core
.runtime
.CoreException
;
35 import org
.eclipse
.core
.runtime
.IConfigurationElement
;
36 import org
.eclipse
.core
.runtime
.IPath
;
37 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
38 import org
.eclipse
.core
.runtime
.Platform
;
39 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.Activator
;
40 import org
.eclipse
.linuxtools
.tmf
.core
.TmfCommonConstants
;
41 import org
.eclipse
.linuxtools
.tmf
.core
.analysis
.IAnalysisModuleHelper
;
42 import org
.eclipse
.linuxtools
.tmf
.core
.analysis
.TmfAnalysisManager
;
43 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfEvent
;
44 import org
.eclipse
.linuxtools
.tmf
.core
.parsers
.custom
.CustomTxtEvent
;
45 import org
.eclipse
.linuxtools
.tmf
.core
.parsers
.custom
.CustomTxtTrace
;
46 import org
.eclipse
.linuxtools
.tmf
.core
.parsers
.custom
.CustomTxtTraceDefinition
;
47 import org
.eclipse
.linuxtools
.tmf
.core
.parsers
.custom
.CustomXmlEvent
;
48 import org
.eclipse
.linuxtools
.tmf
.core
.parsers
.custom
.CustomXmlTrace
;
49 import org
.eclipse
.linuxtools
.tmf
.core
.parsers
.custom
.CustomXmlTraceDefinition
;
50 import org
.eclipse
.linuxtools
.tmf
.core
.project
.model
.TmfTraceType
;
51 import org
.eclipse
.linuxtools
.tmf
.core
.project
.model
.TraceTypeHelper
;
52 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfSignalHandler
;
53 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfSignalManager
;
54 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfTraceOpenedSignal
;
55 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfTrace
;
56 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfTraceProperties
;
57 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.TmfTrace
;
58 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.TmfTraceManager
;
59 import org
.eclipse
.linuxtools
.tmf
.ui
.editors
.TmfEventsEditor
;
60 import org
.eclipse
.linuxtools
.tmf
.ui
.properties
.ReadOnlyTextPropertyDescriptor
;
61 import org
.eclipse
.ui
.IActionFilter
;
62 import org
.eclipse
.ui
.IEditorReference
;
63 import org
.eclipse
.ui
.IWorkbench
;
64 import org
.eclipse
.ui
.IWorkbenchPage
;
65 import org
.eclipse
.ui
.IWorkbenchWindow
;
66 import org
.eclipse
.ui
.PartInitException
;
67 import org
.eclipse
.ui
.PlatformUI
;
68 import org
.eclipse
.ui
.part
.FileEditorInput
;
69 import org
.eclipse
.ui
.views
.properties
.IPropertyDescriptor
;
70 import org
.eclipse
.ui
.views
.properties
.IPropertySource2
;
73 * Implementation of trace model element representing a trace. It provides
74 * methods to instantiate <code>ITmfTrace</code> and <code>ITmfEvent</code> as
75 * well as editor ID from the trace type extension definition.
78 * @author Francois Chouinard
80 public class TmfTraceElement
extends TmfWithFolderElement
implements IActionFilter
, IPropertySource2
{
82 // ------------------------------------------------------------------------
84 // ------------------------------------------------------------------------
88 * Bundle attribute name
90 public static final String BUNDLE
= "bundle"; //$NON-NLS-1$
92 * IsLinked attribute name.
94 public static final String IS_LINKED
= "isLinked"; //$NON-NLS-1$
96 // Property View stuff
97 private static final String sfResourcePropertiesCategory
= Messages
.TmfTraceElement_ResourceProperties
;
98 private static final String sfName
= Messages
.TmfTraceElement_Name
;
99 private static final String sfPath
= Messages
.TmfTraceElement_Path
;
100 private static final String sfLocation
= Messages
.TmfTraceElement_Location
;
101 private static final String sfEventType
= Messages
.TmfTraceElement_EventType
;
102 private static final String sfIsLinked
= Messages
.TmfTraceElement_IsLinked
;
103 private static final String sfTracePropertiesCategory
= Messages
.TmfTraceElement_TraceProperties
;
105 private static final ReadOnlyTextPropertyDescriptor sfNameDescriptor
= new ReadOnlyTextPropertyDescriptor(sfName
, sfName
);
106 private static final ReadOnlyTextPropertyDescriptor sfPathDescriptor
= new ReadOnlyTextPropertyDescriptor(sfPath
, sfPath
);
107 private static final ReadOnlyTextPropertyDescriptor sfLocationDescriptor
= new ReadOnlyTextPropertyDescriptor(sfLocation
, sfLocation
);
108 private static final ReadOnlyTextPropertyDescriptor sfTypeDescriptor
= new ReadOnlyTextPropertyDescriptor(sfEventType
, sfEventType
);
109 private static final ReadOnlyTextPropertyDescriptor sfIsLinkedDescriptor
= new ReadOnlyTextPropertyDescriptor(sfIsLinked
, sfIsLinked
);
111 private static final IPropertyDescriptor
[] sfDescriptors
= { sfNameDescriptor
, sfPathDescriptor
, sfLocationDescriptor
,
112 sfTypeDescriptor
, sfIsLinkedDescriptor
};
115 sfNameDescriptor
.setCategory(sfResourcePropertiesCategory
);
116 sfPathDescriptor
.setCategory(sfResourcePropertiesCategory
);
117 sfLocationDescriptor
.setCategory(sfResourcePropertiesCategory
);
118 sfTypeDescriptor
.setCategory(sfResourcePropertiesCategory
);
119 sfIsLinkedDescriptor
.setCategory(sfResourcePropertiesCategory
);
122 private static final String BOOKMARKS_HIDDEN_FILE
= ".bookmarks"; //$NON-NLS-1$
124 // ------------------------------------------------------------------------
126 // ------------------------------------------------------------------------
128 // This trace type ID as defined in plugin.xml
129 private String fTraceTypeId
= null;
131 // ------------------------------------------------------------------------
132 // Static initialization
133 // ------------------------------------------------------------------------
135 // The mapping of available trace type IDs to their corresponding
136 // configuration element
137 private static final Map
<String
, IConfigurationElement
> sfTraceTypeAttributes
= new HashMap
<>();
138 private static final Map
<String
, IConfigurationElement
> sfTraceCategories
= new HashMap
<>();
141 * Initialize statically at startup by getting extensions from the platform
142 * extension registry.
144 public static void init() {
145 IConfigurationElement
[] config
= Platform
.getExtensionRegistry().getConfigurationElementsFor(TmfTraceType
.TMF_TRACE_TYPE_ID
);
146 for (IConfigurationElement ce
: config
) {
147 String elementName
= ce
.getName();
148 if (elementName
.equals(TmfTraceType
.TYPE_ELEM
)) {
149 String traceTypeId
= ce
.getAttribute(TmfTraceType
.ID_ATTR
);
150 sfTraceTypeAttributes
.put(traceTypeId
, ce
);
151 } else if (elementName
.equals(TmfTraceType
.CATEGORY_ELEM
)) {
152 String categoryId
= ce
.getAttribute(TmfTraceType
.ID_ATTR
);
153 sfTraceCategories
.put(categoryId
, ce
);
158 // ------------------------------------------------------------------------
160 // ------------------------------------------------------------------------
162 * Constructor. Creates trace model element under the trace folder.
167 * The trace resource.
169 * The parent element (trace folder)
171 public TmfTraceElement(String name
, IResource trace
, TmfTraceFolder parent
) {
172 this(name
, trace
, (TmfProjectModelElement
) parent
);
176 * Constructor. Creates trace model element under the experiment folder.
181 * The trace resource.
183 * The parent element (experiment folder)
185 public TmfTraceElement(String name
, IResource trace
, TmfExperimentElement parent
) {
186 this(name
, trace
, (TmfProjectModelElement
) parent
);
189 private TmfTraceElement(String name
, IResource trace
, TmfProjectModelElement parent
) {
190 super(name
, trace
, parent
);
191 parent
.addChild(this);
193 TmfSignalManager
.register(this);
196 // ------------------------------------------------------------------------
197 // TmfProjectModelElement
198 // ------------------------------------------------------------------------
201 void refreshChildren() {
203 /* Refreshes the analysis under this trace */
204 Map
<String
, TmfAnalysisElement
> childrenMap
= new HashMap
<>();
205 for (TmfAnalysisElement analysis
: getAvailableAnalysis()) {
206 childrenMap
.put(analysis
.getAnalysisId(), analysis
);
209 TraceTypeHelper helper
= TmfTraceType
.getInstance().getTraceType(getTraceType());
211 Class
<?
extends ITmfTrace
> traceClass
= null;
213 if (helper
== null && fTraceTypeId
!= null) {
214 if (fTraceTypeId
.startsWith(CustomTxtTrace
.class.getCanonicalName())) {
215 for (CustomTxtTraceDefinition def
: CustomTxtTraceDefinition
.loadAll()) {
216 if (fTraceTypeId
.equals(CustomTxtTrace
.class.getCanonicalName() + ":" + def
.definitionName
)) { //$NON-NLS-1$
217 traceClass
= CustomTxtTrace
.class;
221 if (fTraceTypeId
.startsWith(CustomXmlTrace
.class.getCanonicalName())) {
222 for (CustomXmlTraceDefinition def
: CustomXmlTraceDefinition
.loadAll()) {
223 if (fTraceTypeId
.equals(CustomXmlTrace
.class.getCanonicalName() + ":" + def
.definitionName
)) { //$NON-NLS-1$
224 traceClass
= CustomTxtTrace
.class;
228 } else if (helper
!= null) {
229 traceClass
= helper
.getTraceClass();
232 /* Remove all analysis and return */
233 if (traceClass
== null) {
234 for (TmfAnalysisElement analysis
: childrenMap
.values()) {
235 removeChild(analysis
);
240 /** Get the base path to put the resource to */
241 IPath path
= fResource
.getFullPath();
243 /* Add all new analysis modules or refresh outputs of existing ones */
244 for (IAnalysisModuleHelper module
: TmfAnalysisManager
.getAnalysisModules(traceClass
).values()) {
246 /* If the analysis is not a child of the trace, create it */
247 TmfAnalysisElement analysis
= childrenMap
.remove(module
.getId());
248 if (analysis
== null) {
250 * No need for the resource to exist, nothing will be done with
253 IFolder newresource
= ResourcesPlugin
.getWorkspace().getRoot().getFolder(path
.append(module
.getId()));
254 analysis
= new TmfAnalysisElement(module
.getName(), newresource
, this, module
.getId());
256 analysis
.refreshChildren();
259 /* Remove analysis that are not children of this trace anymore */
260 for (TmfAnalysisElement analysis
: childrenMap
.values()) {
261 removeChild(analysis
);
265 // ------------------------------------------------------------------------
267 // ------------------------------------------------------------------------
269 * Returns the trace type ID.
271 * @return trace type ID.
273 public String
getTraceType() {
278 * Refreshes the trace type filed by reading the trace type persistent
279 * property of the resource referenece.
281 public void refreshTraceType() {
283 fTraceTypeId
= getResource().getPersistentProperty(TmfCommonConstants
.TRACETYPE
);
284 } catch (CoreException e
) {
285 Activator
.getDefault().logError("Error refreshing trace type pesistent property for trace " + getName(), e
); //$NON-NLS-1$
290 * Instantiate a <code>ITmfTrace</code> object based on the trace type and
291 * the corresponding extension.
293 * @return the <code>ITmfTrace</code> or <code>null</code> for an error
295 public ITmfTrace
instantiateTrace() {
298 // make sure that supplementary folder exists
299 refreshSupplementaryFolder();
301 if (fTraceTypeId
!= null) {
302 if (fTraceTypeId
.startsWith(CustomTxtTrace
.class.getCanonicalName())) {
303 for (CustomTxtTraceDefinition def
: CustomTxtTraceDefinition
.loadAll()) {
304 if (fTraceTypeId
.equals(CustomTxtTrace
.class.getCanonicalName() + ":" + def
.definitionName
)) { //$NON-NLS-1$
305 return new CustomTxtTrace(def
);
309 if (fTraceTypeId
.startsWith(CustomXmlTrace
.class.getCanonicalName())) {
310 for (CustomXmlTraceDefinition def
: CustomXmlTraceDefinition
.loadAll()) {
311 if (fTraceTypeId
.equals(CustomXmlTrace
.class.getCanonicalName() + ":" + def
.definitionName
)) { //$NON-NLS-1$
312 return new CustomXmlTrace(def
);
316 IConfigurationElement ce
= sfTraceTypeAttributes
.get(fTraceTypeId
);
320 ITmfTrace trace
= (ITmfTrace
) ce
.createExecutableExtension(TmfTraceType
.TRACE_TYPE_ATTR
);
323 } catch (CoreException e
) {
324 Activator
.getDefault().logError("Error instantiating ITmfTrace object for trace " + getName(), e
); //$NON-NLS-1$
330 * Instantiate a <code>ITmfEvent</code> object based on the trace type and
331 * the corresponding extension.
333 * @return the <code>ITmfEvent</code> or <code>null</code> for an error
335 public ITmfEvent
instantiateEvent() {
337 if (fTraceTypeId
!= null) {
338 if (fTraceTypeId
.startsWith(CustomTxtTrace
.class.getCanonicalName())) {
339 for (CustomTxtTraceDefinition def
: CustomTxtTraceDefinition
.loadAll()) {
340 if (fTraceTypeId
.equals(CustomTxtTrace
.class.getCanonicalName() + ":" + def
.definitionName
)) { //$NON-NLS-1$
341 return new CustomTxtEvent(def
);
345 if (fTraceTypeId
.startsWith(CustomXmlTrace
.class.getCanonicalName())) {
346 for (CustomXmlTraceDefinition def
: CustomXmlTraceDefinition
.loadAll()) {
347 if (fTraceTypeId
.equals(CustomXmlTrace
.class.getCanonicalName() + ":" + def
.definitionName
)) { //$NON-NLS-1$
348 return new CustomXmlEvent(def
);
352 IConfigurationElement ce
= sfTraceTypeAttributes
.get(fTraceTypeId
);
356 ITmfEvent event
= (ITmfEvent
) ce
.createExecutableExtension(TmfTraceType
.EVENT_TYPE_ATTR
);
359 } catch (CoreException e
) {
360 Activator
.getDefault().logError("Error instantiating ITmfEvent object for trace " + getName(), e
); //$NON-NLS-1$
366 * Returns the optional editor ID from the trace type extension.
368 * @return the editor ID or <code>null</code> if not defined.
370 public String
getEditorId() {
371 if (fTraceTypeId
!= null) {
372 if (fTraceTypeId
.startsWith(CustomTxtTrace
.class.getCanonicalName())) {
373 return TmfEventsEditor
.ID
;
375 if (fTraceTypeId
.startsWith(CustomXmlTrace
.class.getCanonicalName())) {
376 return TmfEventsEditor
.ID
;
378 IConfigurationElement ce
= sfTraceTypeAttributes
.get(fTraceTypeId
);
379 IConfigurationElement
[] defaultEditorCE
= ce
.getChildren(TmfTraceType
.DEFAULT_EDITOR_ELEM
);
380 if (defaultEditorCE
.length
== 1) {
381 return defaultEditorCE
[0].getAttribute(TmfTraceType
.ID_ATTR
);
388 * Returns the file resource used to store bookmarks after creating it if
389 * necessary. If the trace resource is a file, it is returned directly. If
390 * the trace resource is a folder, a linked file is returned. The file will
391 * be created if it does not exist.
393 * @return the bookmarks file
394 * @throws CoreException
395 * if the bookmarks file cannot be created
398 public IFile
createBookmarksFile() throws CoreException
{
399 IFile file
= getBookmarksFile();
400 if (fResource
instanceof IFolder
) {
401 if (!file
.exists()) {
402 final IFile bookmarksFile
= getProject().getTracesFolder().getResource().getFile(BOOKMARKS_HIDDEN_FILE
);
403 if (!bookmarksFile
.exists()) {
404 final InputStream source
= new ByteArrayInputStream(new byte[0]);
405 bookmarksFile
.create(source
, true, null);
407 bookmarksFile
.setHidden(true);
408 file
.createLink(bookmarksFile
.getLocation(), IResource
.REPLACE
, null);
409 file
.setHidden(true);
410 file
.setPersistentProperty(TmfCommonConstants
.TRACETYPE
, TmfTrace
.class.getCanonicalName());
417 * Returns the file resource used to store bookmarks. The file may not
420 * @return the bookmarks file
423 public IFile
getBookmarksFile() {
425 if (fResource
instanceof IFile
) {
426 file
= (IFile
) fResource
;
427 } else if (fResource
instanceof IFolder
) {
428 final IFolder folder
= (IFolder
) fResource
;
429 file
= folder
.getFile(getName() + '_');
435 * Returns the <code>TmfTraceElement</code> located under the
436 * <code>TmfTracesFolder</code>.
438 * @return <code>this</code> if this element is under the
439 * <code>TmfTracesFolder</code> else the corresponding
440 * <code>TmfTraceElement</code> if this element is under
441 * <code>TmfExperimentElement</code>.
443 public TmfTraceElement
getElementUnderTraceFolder() {
445 // If trace is under an experiment, return original trace from the
447 if (getParent() instanceof TmfExperimentElement
) {
448 for (TmfTraceElement aTrace
: getProject().getTracesFolder().getTraces()) {
449 if (aTrace
.getName().equals(getName())) {
457 // ------------------------------------------------------------------------
459 // ------------------------------------------------------------------------
462 public boolean testAttribute(Object target
, String name
, String value
) {
463 if (name
.equals(IS_LINKED
)) {
464 boolean isLinked
= getResource().isLinked();
465 return Boolean
.toString(isLinked
).equals(value
);
470 // ------------------------------------------------------------------------
472 // ------------------------------------------------------------------------
475 public TmfProjectElement
getProject() {
476 if (getParent() instanceof TmfTraceFolder
) {
477 TmfTraceFolder folder
= (TmfTraceFolder
) getParent();
478 TmfProjectElement project
= (TmfProjectElement
) folder
.getParent();
481 if (getParent() instanceof TmfExperimentElement
) {
482 TmfExperimentElement experiment
= (TmfExperimentElement
) getParent();
483 TmfExperimentFolder folder
= (TmfExperimentFolder
) experiment
.getParent();
484 TmfProjectElement project
= (TmfProjectElement
) folder
.getParent();
490 // ------------------------------------------------------------------------
492 // ------------------------------------------------------------------------
495 public Object
getEditableValue() {
500 * Get the trace properties of this traceElement if the corresponding trace
501 * is opened in an editor
503 * @return a map with the names and values of the trace properties
504 * respectively as keys and values
506 private Map
<String
, String
> getTraceProperties() {
507 for (ITmfTrace openedTrace
: TmfTraceManager
.getInstance().getOpenedTraces()) {
508 for (ITmfTrace singleTrace
: TmfTraceManager
.getTraceSet(openedTrace
)) {
509 if (this.getLocation().toString().endsWith(singleTrace
.getPath())) {
510 if (singleTrace
instanceof ITmfTraceProperties
) {
511 ITmfTraceProperties traceProperties
= (ITmfTraceProperties
) singleTrace
;
512 return traceProperties
.getTraceProperties();
517 return new HashMap
<>();
521 public IPropertyDescriptor
[] getPropertyDescriptors() {
522 Map
<String
, String
> traceProperties
= getTraceProperties();
523 if (!traceProperties
.isEmpty()) {
524 IPropertyDescriptor
[] propertyDescriptorArray
= new IPropertyDescriptor
[traceProperties
.size() + sfDescriptors
.length
];
526 for (Map
.Entry
<String
, String
> varName
: traceProperties
.entrySet()) {
527 ReadOnlyTextPropertyDescriptor descriptor
= new ReadOnlyTextPropertyDescriptor(this.getName() + "_" + varName
.getKey(), varName
.getKey()); //$NON-NLS-1$
528 descriptor
.setCategory(sfTracePropertiesCategory
);
529 propertyDescriptorArray
[index
] = descriptor
;
532 for (int i
= 0; i
< sfDescriptors
.length
; i
++) {
533 propertyDescriptorArray
[index
] = sfDescriptors
[i
];
536 return propertyDescriptorArray
;
538 return Arrays
.copyOf(sfDescriptors
, sfDescriptors
.length
);
542 public Object
getPropertyValue(Object id
) {
544 if (sfName
.equals(id
)) {
548 if (sfPath
.equals(id
)) {
549 return getPath().toString();
552 if (sfLocation
.equals(id
)) {
553 return getLocation().toString();
556 if (sfIsLinked
.equals(id
)) {
557 return Boolean
.valueOf(getResource().isLinked()).toString();
560 if (sfEventType
.equals(id
)) {
561 if (fTraceTypeId
!= null) {
562 IConfigurationElement ce
= sfTraceTypeAttributes
.get(fTraceTypeId
);
563 return (ce
!= null) ?
(getCategory(ce
) + " : " + ce
.getAttribute(TmfTraceType
.NAME_ATTR
)) : ""; //$NON-NLS-1$ //$NON-NLS-2$
567 Map
<String
, String
> traceProperties
= getTraceProperties();
568 if (id
!= null && !traceProperties
.isEmpty()) {
569 String key
= (String
) id
;
570 key
= key
.replaceFirst(this.getName() + "_", ""); //$NON-NLS-1$ //$NON-NLS-2$
571 String value
= traceProperties
.get(key
);
578 private static String
getCategory(IConfigurationElement ce
) {
579 String categoryId
= ce
.getAttribute(TmfTraceType
.CATEGORY_ATTR
);
580 if (categoryId
!= null) {
581 IConfigurationElement category
= sfTraceCategories
.get(categoryId
);
582 if (category
!= null) {
583 return category
.getAttribute(TmfTraceType
.NAME_ATTR
);
586 return "[no category]"; //$NON-NLS-1$
590 public void resetPropertyValue(Object id
) {
594 public void setPropertyValue(Object id
, Object value
) {
598 public boolean isPropertyResettable(Object id
) {
603 public boolean isPropertySet(Object id
) {
608 * Copy this trace in the trace folder. No other parameters are mentioned so
609 * the trace is copied in this element's project trace folder
613 * @return the new Resource object
616 public TmfTraceElement
copy(String string
) {
617 TmfTraceFolder folder
= this.getProject().getTracesFolder();
618 IResource res
= super.copy(string
, false);
619 return new TmfTraceElement(string
, res
, folder
);
623 * Close opened editors associated with this trace.
627 public void closeEditors() {
628 // Close the trace if open
629 IFile file
= getBookmarksFile();
630 FileEditorInput input
= new FileEditorInput(file
);
631 IWorkbench wb
= PlatformUI
.getWorkbench();
632 for (IWorkbenchWindow wbWindow
: wb
.getWorkbenchWindows()) {
633 for (IWorkbenchPage wbPage
: wbWindow
.getPages()) {
634 for (IEditorReference editorReference
: wbPage
.getEditorReferences()) {
636 if (editorReference
.getEditorInput().equals(input
)) {
637 wbPage
.closeEditor(editorReference
.getEditor(false), false);
639 } catch (PartInitException e
) {
640 Activator
.getDefault().logError("Error closing editor for trace " + getName(), e
); //$NON-NLS-1$
646 // Close experiments that contain the trace if open
647 if (getParent() instanceof TmfTraceFolder
) {
648 TmfExperimentFolder experimentFolder
= getProject().getExperimentsFolder();
649 for (ITmfProjectModelElement experiment
: experimentFolder
.getChildren()) {
650 for (ITmfProjectModelElement child
: experiment
.getChildren()) {
651 if (child
.getName().equals(getName())) {
652 ((TmfExperimentElement
) experiment
).closeEditors();
657 } else if (getParent() instanceof TmfExperimentElement
) {
658 TmfExperimentElement experiment
= (TmfExperimentElement
) getParent();
659 experiment
.closeEditors();
664 * Delete the trace resource, remove it from experiments and delete its
665 * supplementary files
667 * @param progressMonitor
668 * a progress monitor, or null if progress reporting is not
671 * @throws CoreException
672 * thrown when IResource.delete fails
675 public void delete(IProgressMonitor progressMonitor
) throws CoreException
{
678 IPath path
= fResource
.getLocation();
679 if (path
!= null && (getParent() instanceof TmfTraceFolder
)) {
680 TmfExperimentFolder experimentFolder
= getProject().getExperimentsFolder();
682 // Propagate the removal to traces
683 for (ITmfProjectModelElement experiment
: experimentFolder
.getChildren()) {
684 List
<ITmfProjectModelElement
> toRemove
= new LinkedList
<>();
685 for (ITmfProjectModelElement child
: experiment
.getChildren()) {
686 if (child
.getName().equals(getName())) {
690 for (ITmfProjectModelElement child
: toRemove
) {
691 ((TmfExperimentElement
) experiment
).removeTrace((TmfTraceElement
) child
);
695 // Delete supplementary files
696 deleteSupplementaryFolder();
699 // Finally, delete the trace
700 fResource
.delete(true, progressMonitor
);
704 * Get the instantiated trace associated with this element.
706 * @return The instantiated trace or null if trace is not (yet) available
709 public ITmfTrace
getTrace() {
710 for (ITmfTrace trace
: TmfTraceManager
.getInstance().getOpenedTraces()) {
711 if (trace
.getResource().equals(getResource())) {
719 * Get the list of analysis model elements under this trace
721 * @return Array of analysis elements
724 public List
<TmfAnalysisElement
> getAvailableAnalysis() {
725 List
<ITmfProjectModelElement
> children
= getChildren();
726 List
<TmfAnalysisElement
> analysis
= new ArrayList
<>();
727 for (ITmfProjectModelElement child
: children
) {
728 if (child
instanceof TmfAnalysisElement
) {
729 analysis
.add((TmfAnalysisElement
) child
);
736 * Handler for the Trace Opened signal
739 * The incoming signal
743 public void traceOpened(TmfTraceOpenedSignal signal
) {
744 IResource resource
= signal
.getTrace().getResource();
745 if ((resource
== null) || !resource
.equals(getResource())) {
749 getParent().refresh();