1 /*******************************************************************************
2 * Copyright (c) 2010, 2015 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 * Geneviève Bastien - Moved trace type related methods to parent class
18 *******************************************************************************/
20 package org
.eclipse
.tracecompass
.tmf
.ui
.project
.model
;
22 import java
.util
.Arrays
;
23 import java
.util
.Date
;
24 import java
.util
.HashMap
;
25 import java
.util
.LinkedList
;
26 import java
.util
.List
;
29 import org
.eclipse
.core
.filesystem
.EFS
;
30 import org
.eclipse
.core
.filesystem
.IFileInfo
;
31 import org
.eclipse
.core
.resources
.IFile
;
32 import org
.eclipse
.core
.resources
.IFolder
;
33 import org
.eclipse
.core
.resources
.IResource
;
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
.core
.runtime
.URIUtil
;
40 import org
.eclipse
.osgi
.util
.NLS
;
41 import org
.eclipse
.swt
.widgets
.Display
;
42 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.Activator
;
43 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.editors
.ITmfEventsEditorConstants
;
44 import org
.eclipse
.tracecompass
.tmf
.core
.TmfCommonConstants
;
45 import org
.eclipse
.tracecompass
.tmf
.core
.event
.ITmfEvent
;
46 import org
.eclipse
.tracecompass
.tmf
.core
.parsers
.custom
.CustomTxtEvent
;
47 import org
.eclipse
.tracecompass
.tmf
.core
.parsers
.custom
.CustomTxtTrace
;
48 import org
.eclipse
.tracecompass
.tmf
.core
.parsers
.custom
.CustomTxtTraceDefinition
;
49 import org
.eclipse
.tracecompass
.tmf
.core
.parsers
.custom
.CustomXmlEvent
;
50 import org
.eclipse
.tracecompass
.tmf
.core
.parsers
.custom
.CustomXmlTrace
;
51 import org
.eclipse
.tracecompass
.tmf
.core
.parsers
.custom
.CustomXmlTraceDefinition
;
52 import org
.eclipse
.tracecompass
.tmf
.core
.project
.model
.TmfTraceType
;
53 import org
.eclipse
.tracecompass
.tmf
.core
.project
.model
.TraceTypeHelper
;
54 import org
.eclipse
.tracecompass
.tmf
.core
.synchronization
.TimestampTransformFactory
;
55 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.TmfTimestampFormat
;
56 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfTrace
;
57 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfTraceProperties
;
58 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.TmfTraceManager
;
59 import org
.eclipse
.tracecompass
.tmf
.ui
.editors
.TmfEventsEditor
;
60 import org
.eclipse
.tracecompass
.tmf
.ui
.properties
.ReadOnlyTextPropertyDescriptor
;
61 import org
.eclipse
.ui
.IActionFilter
;
62 import org
.eclipse
.ui
.views
.properties
.IPropertyDescriptor
;
63 import org
.eclipse
.ui
.views
.properties
.IPropertySource2
;
65 import com
.ibm
.icu
.text
.DateFormat
;
66 import com
.ibm
.icu
.text
.NumberFormat
;
69 * Implementation of trace model element representing a trace. It provides
70 * methods to instantiate <code>ITmfTrace</code> and <code>ITmfEvent</code> as
71 * well as editor ID from the trace type extension definition.
74 * @author Francois Chouinard
76 public class TmfTraceElement
extends TmfCommonProjectElement
implements IActionFilter
, IPropertySource2
{
78 // ------------------------------------------------------------------------
80 // ------------------------------------------------------------------------
84 * Bundle attribute name
86 public static final String BUNDLE
= "bundle"; //$NON-NLS-1$
88 * IsLinked attribute name.
90 public static final String IS_LINKED
= "isLinked"; //$NON-NLS-1$
92 // Property View stuff
93 private static final String sfResourcePropertiesCategory
= Messages
.TmfTraceElement_ResourceProperties
;
94 private static final String sfName
= Messages
.TmfTraceElement_Name
;
95 private static final String sfPath
= Messages
.TmfTraceElement_Path
;
96 private static final String sfLocation
= Messages
.TmfTraceElement_Location
;
97 private static final String sfTraceType
= Messages
.TmfTraceElement_EventType
;
98 private static final String sfIsLinked
= Messages
.TmfTraceElement_IsLinked
;
99 private static final String sfSourceLocation
= Messages
.TmfTraceElement_SourceLocation
;
100 private static final String sfTimeOffset
= Messages
.TmfTraceElement_TimeOffset
;
101 private static final String sfLastModified
= Messages
.TmfTraceElement_LastModified
;
102 private static final String sfSize
= Messages
.TmfTraceElement_Size
;
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(sfTraceType
, sfTraceType
);
109 private static final ReadOnlyTextPropertyDescriptor sfIsLinkedDescriptor
= new ReadOnlyTextPropertyDescriptor(sfIsLinked
, sfIsLinked
);
110 private static final ReadOnlyTextPropertyDescriptor sfSourceLocationDescriptor
= new ReadOnlyTextPropertyDescriptor(sfSourceLocation
, sfSourceLocation
);
111 private static final ReadOnlyTextPropertyDescriptor sfTimeOffsetDescriptor
= new ReadOnlyTextPropertyDescriptor(sfTimeOffset
, sfTimeOffset
);
112 private static final ReadOnlyTextPropertyDescriptor sfLastModifiedDescriptor
= new ReadOnlyTextPropertyDescriptor(sfLastModified
, sfLastModified
);
113 private static final ReadOnlyTextPropertyDescriptor sfSizeDescriptor
= new ReadOnlyTextPropertyDescriptor(sfSize
, sfSize
);
115 private static final IPropertyDescriptor
[] sfDescriptors
= { sfNameDescriptor
, sfPathDescriptor
, sfLocationDescriptor
,
116 sfTypeDescriptor
, sfIsLinkedDescriptor
, sfSourceLocationDescriptor
,
117 sfTimeOffsetDescriptor
, sfLastModifiedDescriptor
, sfSizeDescriptor
};
120 sfNameDescriptor
.setCategory(sfResourcePropertiesCategory
);
121 sfPathDescriptor
.setCategory(sfResourcePropertiesCategory
);
122 sfLocationDescriptor
.setCategory(sfResourcePropertiesCategory
);
123 sfTypeDescriptor
.setCategory(sfResourcePropertiesCategory
);
124 sfIsLinkedDescriptor
.setCategory(sfResourcePropertiesCategory
);
125 sfSourceLocationDescriptor
.setCategory(sfResourcePropertiesCategory
);
126 sfTimeOffsetDescriptor
.setCategory(sfResourcePropertiesCategory
);
127 sfLastModifiedDescriptor
.setCategory(sfResourcePropertiesCategory
);
128 sfSizeDescriptor
.setCategory(sfResourcePropertiesCategory
);
131 private static final TmfTimestampFormat OFFSET_FORMAT
= new TmfTimestampFormat("T.SSS SSS SSS s"); //$NON-NLS-1$
133 private static final int FOLDER_MAX_COUNT
= 1024;
135 // ------------------------------------------------------------------------
136 // Static initialization
137 // ------------------------------------------------------------------------
139 // The mapping of available trace type IDs to their corresponding
140 // configuration element
141 private static final Map
<String
, IConfigurationElement
> sfTraceTypeAttributes
= new HashMap
<>();
142 private static final Map
<String
, IConfigurationElement
> sfTraceTypeUIAttributes
= new HashMap
<>();
143 private static final Map
<String
, IConfigurationElement
> sfTraceCategories
= new HashMap
<>();
146 * Initialize statically at startup by getting extensions from the platform
147 * extension registry.
149 public static void init() {
150 /* Read the tmf.core "tracetype" extension point */
151 IConfigurationElement
[] config
= Platform
.getExtensionRegistry().getConfigurationElementsFor(TmfTraceType
.TMF_TRACE_TYPE_ID
);
152 for (IConfigurationElement ce
: config
) {
153 switch (ce
.getName()) {
154 case TmfTraceType
.TYPE_ELEM
:
155 String traceTypeId
= ce
.getAttribute(TmfTraceType
.ID_ATTR
);
156 sfTraceTypeAttributes
.put(traceTypeId
, ce
);
158 case TmfTraceType
.CATEGORY_ELEM
:
159 String categoryId
= ce
.getAttribute(TmfTraceType
.ID_ATTR
);
160 sfTraceCategories
.put(categoryId
, ce
);
167 * Read the corresponding tmf.ui "tracetypeui" extension point for this
168 * trace type, if it exists.
170 config
= Platform
.getExtensionRegistry().getConfigurationElementsFor(TmfTraceTypeUIUtils
.TMF_TRACE_TYPE_UI_ID
);
171 for (IConfigurationElement ce
: config
) {
172 String elemName
= ce
.getName();
173 if (TmfTraceTypeUIUtils
.TYPE_ELEM
.equals(elemName
)) {
174 String traceType
= ce
.getAttribute(TmfTraceTypeUIUtils
.TRACETYPE_ATTR
);
175 sfTraceTypeUIAttributes
.put(traceType
, ce
);
180 // ------------------------------------------------------------------------
182 // ------------------------------------------------------------------------
184 private class FileInfo
{
190 // ------------------------------------------------------------------------
192 // ------------------------------------------------------------------------
194 private FileInfo fFileInfo
;
196 // ------------------------------------------------------------------------
198 // ------------------------------------------------------------------------
200 * Constructor. Creates trace model element under the trace folder.
205 * The trace resource.
207 * The parent element (trace folder)
209 public TmfTraceElement(String name
, IResource trace
, TmfTraceFolder parent
) {
210 super(name
, trace
, parent
);
214 * Constructor. Creates trace model element under the experiment folder.
219 * The trace resource.
221 * The parent element (experiment folder)
223 public TmfTraceElement(String name
, IResource trace
, TmfExperimentElement parent
) {
224 super(name
, trace
, parent
);
227 // ------------------------------------------------------------------------
229 // ------------------------------------------------------------------------
232 * Instantiate a <code>ITmfTrace</code> object based on the trace type and
233 * the corresponding extension.
235 * @return the <code>ITmfTrace</code> or <code>null</code> for an error
238 public ITmfTrace
instantiateTrace() {
241 // make sure that supplementary folder exists
242 refreshSupplementaryFolder();
244 if (getTraceType() != null) {
245 if (getTraceType().startsWith(CustomTxtTrace
.class.getCanonicalName())) {
246 for (CustomTxtTraceDefinition def
: CustomTxtTraceDefinition
.loadAll()) {
247 if (getTraceType().equals(CustomTxtTrace
.class.getCanonicalName() + ':' + def
.categoryName
+ ':' + def
.definitionName
)) {
248 return new CustomTxtTrace(def
);
252 if (getTraceType().startsWith(CustomXmlTrace
.class.getCanonicalName())) {
253 for (CustomXmlTraceDefinition def
: CustomXmlTraceDefinition
.loadAll()) {
254 if (getTraceType().equals(CustomXmlTrace
.class.getCanonicalName() + ':' + def
.categoryName
+ ':' + def
.definitionName
)) {
255 return new CustomXmlTrace(def
);
259 IConfigurationElement ce
= sfTraceTypeAttributes
.get(getTraceType());
263 ITmfTrace trace
= (ITmfTrace
) ce
.createExecutableExtension(TmfTraceType
.TRACE_TYPE_ATTR
);
266 } catch (CoreException e
) {
267 Activator
.getDefault().logError("Error instantiating ITmfTrace object for trace " + getName(), e
); //$NON-NLS-1$
273 * Instantiate a <code>ITmfEvent</code> object based on the trace type and
274 * the corresponding extension.
276 * @return the <code>ITmfEvent</code> or <code>null</code> for an error
278 public ITmfEvent
instantiateEvent() {
280 if (getTraceType() != null) {
281 if (getTraceType().startsWith(CustomTxtTrace
.class.getCanonicalName())) {
282 for (CustomTxtTraceDefinition def
: CustomTxtTraceDefinition
.loadAll()) {
283 if (getTraceType().equals(CustomTxtTrace
.class.getCanonicalName() + ':' + def
.categoryName
+ ':' + def
.definitionName
)) {
284 return new CustomTxtEvent(def
);
288 if (getTraceType().startsWith(CustomXmlTrace
.class.getCanonicalName())) {
289 for (CustomXmlTraceDefinition def
: CustomXmlTraceDefinition
.loadAll()) {
290 if (getTraceType().equals(CustomXmlTrace
.class.getCanonicalName() + ':' + def
.categoryName
+ ':' + def
.definitionName
)) {
291 return new CustomXmlEvent(def
);
295 IConfigurationElement ce
= sfTraceTypeAttributes
.get(getTraceType());
299 ITmfEvent event
= (ITmfEvent
) ce
.createExecutableExtension(TmfTraceType
.EVENT_TYPE_ATTR
);
302 } catch (CoreException e
) {
303 Activator
.getDefault().logError("Error instantiating ITmfEvent object for trace " + getName(), e
); //$NON-NLS-1$
309 public String
getEditorId() {
310 if (getTraceType() != null) {
311 if (getTraceType().startsWith(CustomTxtTrace
.class.getCanonicalName())) {
312 return TmfEventsEditor
.ID
;
314 if (getTraceType().startsWith(CustomXmlTrace
.class.getCanonicalName())) {
315 return TmfEventsEditor
.ID
;
317 IConfigurationElement ce
= sfTraceTypeUIAttributes
.get(getTraceType());
319 /* This trace type does not define UI attributes */
322 IConfigurationElement
[] defaultEditorCE
= ce
.getChildren(TmfTraceTypeUIUtils
.DEFAULT_EDITOR_ELEM
);
323 if (defaultEditorCE
.length
== 1) {
324 return defaultEditorCE
[0].getAttribute(TmfTraceType
.ID_ATTR
);
331 * Returns the file resource used to store bookmarks after creating it if
332 * necessary. If the trace resource is a file, it is returned directly. If
333 * the trace resource is a folder, a linked file is returned. The file will
334 * be created if it does not exist.
336 * @return the bookmarks file
337 * @throws CoreException
338 * if the bookmarks file cannot be created
342 public IFile
createBookmarksFile() throws CoreException
{
343 IFile file
= getBookmarksFile();
344 if (fResource
instanceof IFolder
) {
345 return createBookmarksFile(getProject().getTracesFolder().getResource(), ITmfEventsEditorConstants
.TRACE_EDITOR_INPUT_TYPE
);
351 * Returns the file resource used to store bookmarks. The file may not
354 * @return the bookmarks file
358 public IFile
getBookmarksFile() {
360 if (fResource
instanceof IFile
) {
361 file
= (IFile
) fResource
;
362 } else if (fResource
instanceof IFolder
) {
363 final IFolder folder
= (IFolder
) fResource
;
364 file
= folder
.getFile(getName() + '_');
370 * Returns the <code>TmfTraceElement</code> located under the
371 * <code>TmfTracesFolder</code>.
373 * @return <code>this</code> if this element is under the
374 * <code>TmfTracesFolder</code> else the corresponding
375 * <code>TmfTraceElement</code> if this element is under
376 * <code>TmfExperimentElement</code>.
378 public TmfTraceElement
getElementUnderTraceFolder() {
380 // If trace is under an experiment, return original trace from the
382 if (getParent() instanceof TmfExperimentElement
) {
383 for (TmfTraceElement aTrace
: getProject().getTracesFolder().getTraces()) {
384 if (aTrace
.getElementPath().equals(getElementPath())) {
393 public String
getTypeName() {
394 return Messages
.TmfTraceElement_TypeName
;
397 // ------------------------------------------------------------------------
399 // ------------------------------------------------------------------------
402 public boolean testAttribute(Object target
, String name
, String value
) {
403 if (name
.equals(IS_LINKED
)) {
404 boolean isLinked
= getResource().isLinked();
405 return Boolean
.toString(isLinked
).equals(value
);
410 // ------------------------------------------------------------------------
412 // ------------------------------------------------------------------------
415 public Object
getEditableValue() {
420 * Get the trace properties of this traceElement if the corresponding trace
421 * is opened in an editor
423 * @return a map with the names and values of the trace properties
424 * respectively as keys and values
426 private Map
<String
, String
> getTraceProperties() {
427 for (ITmfTrace openedTrace
: TmfTraceManager
.getInstance().getOpenedTraces()) {
428 for (ITmfTrace singleTrace
: TmfTraceManager
.getTraceSet(openedTrace
)) {
429 if (getElementUnderTraceFolder().getResource().equals(singleTrace
.getResource())) {
430 if (singleTrace
instanceof ITmfTraceProperties
) {
431 ITmfTraceProperties traceProperties
= (ITmfTraceProperties
) singleTrace
;
432 return traceProperties
.getTraceProperties();
437 return new HashMap
<>();
441 public IPropertyDescriptor
[] getPropertyDescriptors() {
442 Map
<String
, String
> traceProperties
= getTraceProperties();
443 if (!traceProperties
.isEmpty()) {
444 IPropertyDescriptor
[] propertyDescriptorArray
= new IPropertyDescriptor
[traceProperties
.size() + sfDescriptors
.length
];
446 for (Map
.Entry
<String
, String
> varName
: traceProperties
.entrySet()) {
447 ReadOnlyTextPropertyDescriptor descriptor
= new ReadOnlyTextPropertyDescriptor(this.getName() + "_" + varName
.getKey(), varName
.getKey()); //$NON-NLS-1$
448 descriptor
.setCategory(sfTracePropertiesCategory
);
449 propertyDescriptorArray
[index
] = descriptor
;
452 for (int i
= 0; i
< sfDescriptors
.length
; i
++) {
453 propertyDescriptorArray
[index
] = sfDescriptors
[i
];
456 return propertyDescriptorArray
;
458 return Arrays
.copyOf(sfDescriptors
, sfDescriptors
.length
);
462 public Object
getPropertyValue(Object id
) {
464 if (sfName
.equals(id
)) {
468 if (sfPath
.equals(id
)) {
469 return getPath().toString();
472 if (sfLocation
.equals(id
)) {
473 return URIUtil
.toUnencodedString(getLocation());
476 if (sfIsLinked
.equals(id
)) {
477 return Boolean
.valueOf(getResource().isLinked()).toString();
480 if (sfSourceLocation
.equals(id
)) {
482 String sourceLocation
= getElementUnderTraceFolder().getResource().getPersistentProperty(TmfCommonConstants
.SOURCE_LOCATION
);
483 if (sourceLocation
!= null) {
484 return sourceLocation
;
486 } catch (CoreException e
) {
488 return ""; //$NON-NLS-1$
491 if (sfLastModified
.equals(id
)) {
492 FileInfo fileInfo
= getFileInfo();
493 if (fileInfo
== null) {
494 return ""; //$NON-NLS-1$
496 long date
= fileInfo
.lastModified
;
497 DateFormat format
= DateFormat
.getDateTimeInstance(DateFormat
.LONG
, DateFormat
.MEDIUM
);
498 return format
.format(new Date(date
));
501 if (sfSize
.equals(id
)) {
502 FileInfo fileInfo
= getFileInfo();
503 if (fileInfo
== null) {
504 return ""; //$NON-NLS-1$
506 if (getResource() instanceof IFolder
) {
507 if (fileInfo
.count
<= FOLDER_MAX_COUNT
) {
508 return NLS
.bind(Messages
.TmfTraceElement_FolderSizeString
,
509 NumberFormat
.getInstance().format(fileInfo
.size
), fileInfo
.count
);
511 return NLS
.bind(Messages
.TmfTraceElement_FolderSizeOverflowString
,
512 NumberFormat
.getInstance().format(fileInfo
.size
), FOLDER_MAX_COUNT
);
514 return NLS
.bind(Messages
.TmfTraceElement_FileSizeString
, NumberFormat
.getInstance().format(fileInfo
.size
));
517 if (sfTraceType
.equals(id
)) {
518 if (getTraceType() != null) {
519 TraceTypeHelper helper
= TmfTraceType
.getTraceType(getTraceType());
520 if (helper
!= null) {
521 return helper
.getLabel();
524 return ""; //$NON-NLS-1$
527 if (sfTimeOffset
.equals(id
)) {
528 long offset
= TimestampTransformFactory
.getTimestampTransform(getElementUnderTraceFolder().getResource()).transform(0);
530 return OFFSET_FORMAT
.format(offset
);
532 return ""; //$NON-NLS-1$
535 Map
<String
, String
> traceProperties
= getTraceProperties();
536 if (id
!= null && !traceProperties
.isEmpty()) {
537 String key
= (String
) id
;
538 key
= key
.substring(this.getName().length() + 1); // remove name_
539 String value
= traceProperties
.get(key
);
546 private FileInfo
getFileInfo() {
547 /* FileInfo is needed for both 'last modified' and 'size' properties.
548 * It is freshly computed for one, and reused for the other, then
549 * cleared so that the information can be refreshed the next time.
552 if (fFileInfo
== null) {
554 fileInfo
= computeFileInfo(new FileInfo(), getResource());
555 } catch (CoreException e
) {
558 fFileInfo
= fileInfo
;
560 fileInfo
= fFileInfo
;
566 private FileInfo
computeFileInfo(FileInfo fileInfo
, IResource resource
) throws CoreException
{
567 if (fileInfo
== null || fileInfo
.count
> FOLDER_MAX_COUNT
) {
570 if (resource
instanceof IFolder
) {
571 IFolder folder
= (IFolder
) resource
;
572 for (IResource member
: folder
.members()) {
573 computeFileInfo(fileInfo
, member
);
577 IFileInfo info
= EFS
.getStore(resource
.getLocationURI()).fetchInfo();
578 fileInfo
.lastModified
= Math
.max(fileInfo
.lastModified
, info
.getLastModified());
579 fileInfo
.size
+= info
.getLength();
585 public void resetPropertyValue(Object id
) {
589 public void setPropertyValue(Object id
, Object value
) {
593 public boolean isPropertyResettable(Object id
) {
598 public boolean isPropertySet(Object id
) {
603 * Copy this trace in the trace folder. No other parameters are mentioned so
604 * the trace is copied in this element's project trace folder
608 * @return the new Resource object
611 public TmfTraceElement
copy(String newName
) {
612 TmfTraceFolder folder
= (TmfTraceFolder
) getParent();
613 IResource res
= super.copy(newName
, false);
614 for (TmfTraceElement trace
: folder
.getTraces()) {
615 if (trace
.getResource().equals(res
)) {
623 * Close opened editors associated with this trace.
628 public void closeEditors() {
629 super.closeEditors();
631 // Close experiments that contain the trace if open
632 if (getParent() instanceof TmfTraceFolder
) {
633 TmfExperimentFolder experimentsFolder
= getProject().getExperimentsFolder();
634 for (TmfExperimentElement experiment
: experimentsFolder
.getExperiments()) {
635 for (TmfTraceElement trace
: experiment
.getTraces()) {
636 if (trace
.getElementPath().equals(getElementPath())) {
637 experiment
.closeEditors();
642 } else if (getParent() instanceof TmfExperimentElement
) {
643 TmfExperimentElement experiment
= (TmfExperimentElement
) getParent();
644 experiment
.closeEditors();
649 * Delete the trace resource, remove it from experiments and delete its
650 * supplementary files
652 * @param progressMonitor
653 * a progress monitor, or null if progress reporting is not
656 * @throws CoreException
657 * thrown when IResource.delete fails
660 public void delete(IProgressMonitor progressMonitor
) throws CoreException
{
661 // Close editors in UI Thread
662 Display
.getDefault().syncExec(new Runnable() {
669 IPath path
= fResource
.getLocation();
671 if (getParent() instanceof TmfTraceFolder
) {
672 TmfExperimentFolder experimentFolder
= getProject().getExperimentsFolder();
674 // Propagate the removal to traces
675 for (TmfExperimentElement experiment
: experimentFolder
.getExperiments()) {
676 List
<TmfTraceElement
> toRemove
= new LinkedList
<>();
677 for (TmfTraceElement trace
: experiment
.getTraces()) {
678 if (trace
.getElementPath().equals(getElementPath())) {
682 for (TmfTraceElement child
: toRemove
) {
683 experiment
.removeTrace(child
);
687 // Delete supplementary files
688 deleteSupplementaryFolder();
690 } else if (getParent() instanceof TmfExperimentElement
) {
691 TmfExperimentElement experimentElement
= (TmfExperimentElement
) getParent();
692 experimentElement
.removeTrace(this);
696 // Finally, delete the trace
697 fResource
.delete(true, progressMonitor
);