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
.ITmfPropertiesProvider
;
53 import org
.eclipse
.tracecompass
.tmf
.core
.project
.model
.TmfTraceType
;
54 import org
.eclipse
.tracecompass
.tmf
.core
.project
.model
.TraceTypeHelper
;
55 import org
.eclipse
.tracecompass
.tmf
.core
.synchronization
.TimestampTransformFactory
;
56 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.TmfTimestampFormat
;
57 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfTrace
;
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 RESOURCE_PROPERTIES_CATEGORY
= Messages
.TmfTraceElement_ResourceProperties
;
94 private static final String NAME
= Messages
.TmfTraceElement_Name
;
95 private static final String PATH
= Messages
.TmfTraceElement_Path
;
96 private static final String LOCATION
= Messages
.TmfTraceElement_Location
;
97 private static final String TRACE_TYPE
= Messages
.TmfTraceElement_EventType
;
98 private static final String IS_LINKED_PROPERTY
= Messages
.TmfTraceElement_IsLinked
;
99 private static final String SOURCE_LOCATION
= Messages
.TmfTraceElement_SourceLocation
;
100 private static final String TIME_OFFSET
= Messages
.TmfTraceElement_TimeOffset
;
101 private static final String LAST_MODIFIED
= Messages
.TmfTraceElement_LastModified
;
102 private static final String SIZE
= Messages
.TmfTraceElement_Size
;
103 private static final String TRACE_PROPERTIES_CATEGORY
= Messages
.TmfTraceElement_TraceProperties
;
105 private static final ReadOnlyTextPropertyDescriptor NAME_DESCRIPTOR
= new ReadOnlyTextPropertyDescriptor(NAME
, NAME
);
106 private static final ReadOnlyTextPropertyDescriptor PATH_DESCRIPTOR
= new ReadOnlyTextPropertyDescriptor(PATH
, PATH
);
107 private static final ReadOnlyTextPropertyDescriptor LOCATION_DESCRIPTOR
= new ReadOnlyTextPropertyDescriptor(LOCATION
, LOCATION
);
108 private static final ReadOnlyTextPropertyDescriptor TYPE_DESCRIPTOR
= new ReadOnlyTextPropertyDescriptor(TRACE_TYPE
, TRACE_TYPE
);
109 private static final ReadOnlyTextPropertyDescriptor IS_LINKED_DESCRIPTOR
= new ReadOnlyTextPropertyDescriptor(IS_LINKED_PROPERTY
, IS_LINKED_PROPERTY
);
110 private static final ReadOnlyTextPropertyDescriptor SOURCE_LOCATION_DESCRIPTOR
= new ReadOnlyTextPropertyDescriptor(SOURCE_LOCATION
, SOURCE_LOCATION
);
111 private static final ReadOnlyTextPropertyDescriptor TIME_OFFSET_DESCRIPTOR
= new ReadOnlyTextPropertyDescriptor(TIME_OFFSET
, TIME_OFFSET
);
112 private static final ReadOnlyTextPropertyDescriptor LAST_MODIFIED_DESCRIPTOR
= new ReadOnlyTextPropertyDescriptor(LAST_MODIFIED
, LAST_MODIFIED
);
113 private static final ReadOnlyTextPropertyDescriptor SIZE_DESCRIPTOR
= new ReadOnlyTextPropertyDescriptor(SIZE
, SIZE
);
115 private static final IPropertyDescriptor
[] sfDescriptors
= { NAME_DESCRIPTOR
, PATH_DESCRIPTOR
, LOCATION_DESCRIPTOR
,
116 TYPE_DESCRIPTOR
, IS_LINKED_DESCRIPTOR
, SOURCE_LOCATION_DESCRIPTOR
,
117 TIME_OFFSET_DESCRIPTOR
, LAST_MODIFIED_DESCRIPTOR
, SIZE_DESCRIPTOR
};
120 NAME_DESCRIPTOR
.setCategory(RESOURCE_PROPERTIES_CATEGORY
);
121 PATH_DESCRIPTOR
.setCategory(RESOURCE_PROPERTIES_CATEGORY
);
122 LOCATION_DESCRIPTOR
.setCategory(RESOURCE_PROPERTIES_CATEGORY
);
123 TYPE_DESCRIPTOR
.setCategory(RESOURCE_PROPERTIES_CATEGORY
);
124 IS_LINKED_DESCRIPTOR
.setCategory(RESOURCE_PROPERTIES_CATEGORY
);
125 SOURCE_LOCATION_DESCRIPTOR
.setCategory(RESOURCE_PROPERTIES_CATEGORY
);
126 TIME_OFFSET_DESCRIPTOR
.setCategory(RESOURCE_PROPERTIES_CATEGORY
);
127 LAST_MODIFIED_DESCRIPTOR
.setCategory(RESOURCE_PROPERTIES_CATEGORY
);
128 SIZE_DESCRIPTOR
.setCategory(RESOURCE_PROPERTIES_CATEGORY
);
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
> TRACE_TYPE_ATTRIBUTES
= new HashMap
<>();
142 private static final Map
<String
, IConfigurationElement
> TRACE_TYPE_UI_ATTRIBUTES
= new HashMap
<>();
143 private static final Map
<String
, IConfigurationElement
> TRACE_CATEGORIES
= 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 TRACE_TYPE_ATTRIBUTES
.put(traceTypeId
, ce
);
158 case TmfTraceType
.CATEGORY_ELEM
:
159 String categoryId
= ce
.getAttribute(TmfTraceType
.ID_ATTR
);
160 TRACE_CATEGORIES
.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 TRACE_TYPE_UI_ATTRIBUTES
.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 String traceTypeId
= getTraceType();
245 if (traceTypeId
!= null) {
246 if (CustomTxtTrace
.isCustomTraceTypeId(traceTypeId
)) {
247 for (CustomTxtTraceDefinition def
: CustomTxtTraceDefinition
.loadAll()) {
248 String id
= CustomTxtTrace
.buildTraceTypeId(def
.categoryName
, def
.definitionName
);
249 if (traceTypeId
.equals(id
)) {
250 return new CustomTxtTrace(def
);
254 if (CustomXmlTrace
.isCustomTraceTypeId(traceTypeId
)) {
255 for (CustomXmlTraceDefinition def
: CustomXmlTraceDefinition
.loadAll()) {
256 String id
= CustomXmlTrace
.buildTraceTypeId(def
.categoryName
, def
.definitionName
);
257 if (traceTypeId
.equals(id
)) {
258 return new CustomXmlTrace(def
);
262 IConfigurationElement ce
= TRACE_TYPE_ATTRIBUTES
.get(traceTypeId
);
266 ITmfTrace trace
= (ITmfTrace
) ce
.createExecutableExtension(TmfTraceType
.TRACE_TYPE_ATTR
);
269 } catch (CoreException e
) {
270 Activator
.getDefault().logError("Error instantiating ITmfTrace object for trace " + getName(), e
); //$NON-NLS-1$
276 * Instantiate a <code>ITmfEvent</code> object based on the trace type and
277 * the corresponding extension.
279 * @return the <code>ITmfEvent</code> or <code>null</code> for an error
281 public ITmfEvent
instantiateEvent() {
283 String traceTypeId
= getTraceType();
284 if (traceTypeId
!= null) {
285 if (CustomTxtTrace
.isCustomTraceTypeId(traceTypeId
)) {
286 for (CustomTxtTraceDefinition def
: CustomTxtTraceDefinition
.loadAll()) {
287 String id
= CustomTxtTrace
.buildTraceTypeId(def
.categoryName
, def
.definitionName
);
288 if (traceTypeId
.equals(id
)) {
289 return new CustomTxtEvent(def
);
293 if (CustomXmlTrace
.isCustomTraceTypeId(traceTypeId
)) {
294 for (CustomXmlTraceDefinition def
: CustomXmlTraceDefinition
.loadAll()) {
295 String id
= CustomXmlTrace
.buildTraceTypeId(def
.categoryName
, def
.definitionName
);
296 if (traceTypeId
.equals(id
)) {
297 return new CustomXmlEvent(def
);
301 IConfigurationElement ce
= TRACE_TYPE_ATTRIBUTES
.get(traceTypeId
);
305 ITmfEvent event
= (ITmfEvent
) ce
.createExecutableExtension(TmfTraceType
.EVENT_TYPE_ATTR
);
308 } catch (CoreException e
) {
309 Activator
.getDefault().logError("Error instantiating ITmfEvent object for trace " + getName(), e
); //$NON-NLS-1$
315 public String
getEditorId() {
316 String traceTypeId
= getTraceType();
317 if (traceTypeId
!= null) {
318 if (CustomTxtTrace
.isCustomTraceTypeId(traceTypeId
) || CustomXmlTrace
.isCustomTraceTypeId(traceTypeId
)) {
319 return TmfEventsEditor
.ID
;
322 IConfigurationElement ce
= TRACE_TYPE_UI_ATTRIBUTES
.get(getTraceType());
324 /* This trace type does not define UI attributes */
327 IConfigurationElement
[] defaultEditorCE
= ce
.getChildren(TmfTraceTypeUIUtils
.DEFAULT_EDITOR_ELEM
);
328 if (defaultEditorCE
.length
== 1) {
329 return defaultEditorCE
[0].getAttribute(TmfTraceType
.ID_ATTR
);
336 * Returns the file resource used to store bookmarks after creating it if
337 * necessary. If the trace resource is a file, it is returned directly. If
338 * the trace resource is a folder, a linked file is returned. The file will
339 * be created if it does not exist.
341 * @return the bookmarks file
342 * @throws CoreException
343 * if the bookmarks file cannot be created
346 public IFile
createBookmarksFile() throws CoreException
{
347 IFile file
= getBookmarksFile();
348 if (getResource() instanceof IFolder
) {
349 return createBookmarksFile(getProject().getTracesFolder().getResource(), ITmfEventsEditorConstants
.TRACE_EDITOR_INPUT_TYPE
);
355 * Returns the file resource used to store bookmarks. The file may not
358 * @return the bookmarks file
361 public IFile
getBookmarksFile() {
363 IResource resource
= getResource();
364 if (resource
instanceof IFile
) {
365 file
= (IFile
) resource
;
366 } else if (resource
instanceof IFolder
) {
367 final IFolder folder
= (IFolder
) resource
;
368 file
= folder
.getFile(getName() + '_');
374 * Returns the <code>TmfTraceElement</code> located under the
375 * <code>TmfTracesFolder</code>.
377 * @return <code>this</code> if this element is under the
378 * <code>TmfTracesFolder</code> else the corresponding
379 * <code>TmfTraceElement</code> if this element is under
380 * <code>TmfExperimentElement</code>.
382 public TmfTraceElement
getElementUnderTraceFolder() {
384 // If trace is under an experiment, return original trace from the
386 if (getParent() instanceof TmfExperimentElement
) {
387 for (TmfTraceElement aTrace
: getProject().getTracesFolder().getTraces()) {
388 if (aTrace
.getElementPath().equals(getElementPath())) {
397 public String
getTypeName() {
398 return Messages
.TmfTraceElement_TypeName
;
401 // ------------------------------------------------------------------------
403 // ------------------------------------------------------------------------
406 public boolean testAttribute(Object target
, String name
, String value
) {
407 if (name
.equals(IS_LINKED
)) {
408 boolean isLinked
= getResource().isLinked();
409 return Boolean
.toString(isLinked
).equals(value
);
414 // ------------------------------------------------------------------------
416 // ------------------------------------------------------------------------
419 public Object
getEditableValue() {
424 * Get the trace properties of this traceElement if the corresponding trace
425 * is opened in an editor
427 * @return a map with the names and values of the trace properties
428 * respectively as keys and values
430 private Map
<String
, String
> getTraceProperties() {
431 for (ITmfTrace openedTrace
: TmfTraceManager
.getInstance().getOpenedTraces()) {
432 for (ITmfTrace singleTrace
: TmfTraceManager
.getTraceSet(openedTrace
)) {
433 if (getElementUnderTraceFolder().getResource().equals(singleTrace
.getResource())) {
434 if (singleTrace
instanceof ITmfPropertiesProvider
) {
435 ITmfPropertiesProvider traceProperties
= (ITmfPropertiesProvider
) singleTrace
;
436 return traceProperties
.getProperties();
441 return new HashMap
<>();
445 public IPropertyDescriptor
[] getPropertyDescriptors() {
446 Map
<String
, String
> traceProperties
= getTraceProperties();
447 if (!traceProperties
.isEmpty()) {
448 IPropertyDescriptor
[] propertyDescriptorArray
= new IPropertyDescriptor
[traceProperties
.size() + sfDescriptors
.length
];
450 for (Map
.Entry
<String
, String
> varName
: traceProperties
.entrySet()) {
451 ReadOnlyTextPropertyDescriptor descriptor
= new ReadOnlyTextPropertyDescriptor(this.getName() + "_" + varName
.getKey(), varName
.getKey()); //$NON-NLS-1$
452 descriptor
.setCategory(TRACE_PROPERTIES_CATEGORY
);
453 propertyDescriptorArray
[index
] = descriptor
;
456 for (int i
= 0; i
< sfDescriptors
.length
; i
++) {
457 propertyDescriptorArray
[index
] = sfDescriptors
[i
];
460 return propertyDescriptorArray
;
462 return Arrays
.copyOf(sfDescriptors
, sfDescriptors
.length
);
466 public Object
getPropertyValue(Object id
) {
468 if (NAME
.equals(id
)) {
472 if (PATH
.equals(id
)) {
473 return getPath().toString();
476 if (LOCATION
.equals(id
)) {
477 return URIUtil
.toUnencodedString(getLocation());
480 if (IS_LINKED_PROPERTY
.equals(id
)) {
481 return Boolean
.valueOf(getResource().isLinked()).toString();
484 if (SOURCE_LOCATION
.equals(id
)) {
486 String sourceLocation
= getElementUnderTraceFolder().getResource().getPersistentProperty(TmfCommonConstants
.SOURCE_LOCATION
);
487 if (sourceLocation
!= null) {
488 return sourceLocation
;
490 } catch (CoreException e
) {
492 return ""; //$NON-NLS-1$
495 if (LAST_MODIFIED
.equals(id
)) {
496 FileInfo fileInfo
= getFileInfo();
497 if (fileInfo
== null) {
498 return ""; //$NON-NLS-1$
500 long date
= fileInfo
.lastModified
;
501 DateFormat format
= DateFormat
.getDateTimeInstance(DateFormat
.LONG
, DateFormat
.MEDIUM
);
502 return format
.format(new Date(date
));
505 if (SIZE
.equals(id
)) {
506 FileInfo fileInfo
= getFileInfo();
507 if (fileInfo
== null) {
508 return ""; //$NON-NLS-1$
510 if (getResource() instanceof IFolder
) {
511 if (fileInfo
.count
<= FOLDER_MAX_COUNT
) {
512 return NLS
.bind(Messages
.TmfTraceElement_FolderSizeString
,
513 NumberFormat
.getInstance().format(fileInfo
.size
), fileInfo
.count
);
515 return NLS
.bind(Messages
.TmfTraceElement_FolderSizeOverflowString
,
516 NumberFormat
.getInstance().format(fileInfo
.size
), FOLDER_MAX_COUNT
);
518 return NLS
.bind(Messages
.TmfTraceElement_FileSizeString
, NumberFormat
.getInstance().format(fileInfo
.size
));
521 if (TRACE_TYPE
.equals(id
)) {
522 if (getTraceType() != null) {
523 TraceTypeHelper helper
= TmfTraceType
.getTraceType(getTraceType());
524 if (helper
!= null) {
525 return helper
.getLabel();
528 return ""; //$NON-NLS-1$
531 if (TIME_OFFSET
.equals(id
)) {
532 long offset
= TimestampTransformFactory
.getTimestampTransform(getElementUnderTraceFolder().getResource()).transform(0);
534 return OFFSET_FORMAT
.format(offset
);
536 return ""; //$NON-NLS-1$
539 Map
<String
, String
> traceProperties
= getTraceProperties();
540 if (id
!= null && !traceProperties
.isEmpty()) {
541 String key
= (String
) id
;
542 key
= key
.substring(this.getName().length() + 1); // remove name_
543 String value
= traceProperties
.get(key
);
550 private FileInfo
getFileInfo() {
551 /* FileInfo is needed for both 'last modified' and 'size' properties.
552 * It is freshly computed for one, and reused for the other, then
553 * cleared so that the information can be refreshed the next time.
556 if (fFileInfo
== null) {
558 fileInfo
= computeFileInfo(new FileInfo(), getResource());
559 } catch (CoreException e
) {
562 fFileInfo
= fileInfo
;
564 fileInfo
= fFileInfo
;
570 private FileInfo
computeFileInfo(FileInfo fileInfo
, IResource resource
) throws CoreException
{
571 if (fileInfo
== null || fileInfo
.count
> FOLDER_MAX_COUNT
) {
574 if (resource
instanceof IFolder
) {
575 IFolder folder
= (IFolder
) resource
;
576 for (IResource member
: folder
.members()) {
577 computeFileInfo(fileInfo
, member
);
581 IFileInfo info
= EFS
.getStore(resource
.getLocationURI()).fetchInfo();
582 fileInfo
.lastModified
= Math
.max(fileInfo
.lastModified
, info
.getLastModified());
583 fileInfo
.size
+= info
.getLength();
589 public void resetPropertyValue(Object id
) {
593 public void setPropertyValue(Object id
, Object value
) {
597 public boolean isPropertyResettable(Object id
) {
602 public boolean isPropertySet(Object id
) {
607 * Copy this trace in the trace folder. No other parameters are mentioned so
608 * the trace is copied in this element's project trace folder
612 * @return the new Resource object
614 public TmfTraceElement
copy(String newName
) {
615 TmfTraceFolder folder
= (TmfTraceFolder
) getParent();
616 IResource res
= super.copy(newName
, false);
617 for (TmfTraceElement trace
: folder
.getTraces()) {
618 if (trace
.getResource().equals(res
)) {
626 * Close opened editors associated with this trace.
629 public void closeEditors() {
630 super.closeEditors();
632 // Close experiments that contain the trace if open
633 if (getParent() instanceof TmfTraceFolder
) {
634 TmfExperimentFolder experimentsFolder
= getProject().getExperimentsFolder();
635 for (TmfExperimentElement experiment
: experimentsFolder
.getExperiments()) {
636 for (TmfTraceElement trace
: experiment
.getTraces()) {
637 if (trace
.getElementPath().equals(getElementPath())) {
638 experiment
.closeEditors();
643 } else if (getParent() instanceof TmfExperimentElement
) {
644 TmfExperimentElement experiment
= (TmfExperimentElement
) getParent();
645 experiment
.closeEditors();
650 * Delete the trace resource, remove it from experiments and delete its
651 * supplementary files
653 * @param progressMonitor
654 * a progress monitor, or null if progress reporting is not
657 * @throws CoreException
658 * 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
= getResource().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 getResource().delete(true, progressMonitor
);