1 /*******************************************************************************
2 * Copyright (c) 2010, 2014 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 TmfCommonProjectElement
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
> sfTraceTypeUIAttributes
= new HashMap
<>();
139 private static final Map
<String
, IConfigurationElement
> sfTraceCategories
= new HashMap
<>();
142 * Initialize statically at startup by getting extensions from the platform
143 * extension registry.
145 public static void init() {
146 /* Read the tmf.core "tracetype" extension point */
147 IConfigurationElement
[] config
= Platform
.getExtensionRegistry().getConfigurationElementsFor(TmfTraceType
.TMF_TRACE_TYPE_ID
);
148 for (IConfigurationElement ce
: config
) {
149 switch (ce
.getName()) {
150 case TmfTraceType
.TYPE_ELEM
:
151 String traceTypeId
= ce
.getAttribute(TmfTraceType
.ID_ATTR
);
152 sfTraceTypeAttributes
.put(traceTypeId
, ce
);
154 case TmfTraceType
.CATEGORY_ELEM
:
155 String categoryId
= ce
.getAttribute(TmfTraceType
.ID_ATTR
);
156 sfTraceCategories
.put(categoryId
, ce
);
163 * Read the corresponding tmf.ui "tracetypeui" extension point for this
164 * trace type, if it exists.
166 config
= Platform
.getExtensionRegistry().getConfigurationElementsFor(TmfTraceTypeUIUtils
.TMF_TRACE_TYPE_UI_ID
);
167 for (IConfigurationElement ce
: config
) {
168 String elemName
= ce
.getName();
169 if (TmfTraceTypeUIUtils
.TYPE_ELEM
.equals(elemName
)) {
170 String traceType
= ce
.getAttribute(TmfTraceTypeUIUtils
.TRACETYPE_ATTR
);
171 sfTraceTypeUIAttributes
.put(traceType
, ce
);
176 // ------------------------------------------------------------------------
178 // ------------------------------------------------------------------------
180 * Constructor. Creates trace model element under the trace folder.
185 * The trace resource.
187 * The parent element (trace folder)
189 public TmfTraceElement(String name
, IResource trace
, TmfTraceFolder parent
) {
190 this(name
, trace
, (TmfProjectModelElement
) parent
);
194 * Constructor. Creates trace model element under the experiment folder.
199 * The trace resource.
201 * The parent element (experiment folder)
203 public TmfTraceElement(String name
, IResource trace
, TmfExperimentElement parent
) {
204 this(name
, trace
, (TmfProjectModelElement
) parent
);
207 private TmfTraceElement(String name
, IResource trace
, TmfProjectModelElement parent
) {
208 super(name
, trace
, parent
);
209 parent
.addChild(this);
211 TmfSignalManager
.register(this);
214 // ------------------------------------------------------------------------
215 // TmfProjectModelElement
216 // ------------------------------------------------------------------------
219 void refreshChildren() {
221 /* Refreshes the analysis under this trace */
222 Map
<String
, TmfAnalysisElement
> childrenMap
= new HashMap
<>();
223 for (TmfAnalysisElement analysis
: getAvailableAnalysis()) {
224 childrenMap
.put(analysis
.getAnalysisId(), analysis
);
227 TraceTypeHelper helper
= TmfTraceType
.getInstance().getTraceType(getTraceType());
229 Class
<?
extends ITmfTrace
> traceClass
= null;
231 if (helper
== null && fTraceTypeId
!= null) {
232 if (fTraceTypeId
.startsWith(CustomTxtTrace
.class.getCanonicalName())) {
233 for (CustomTxtTraceDefinition def
: CustomTxtTraceDefinition
.loadAll()) {
234 if (fTraceTypeId
.equals(CustomTxtTrace
.class.getCanonicalName() + ":" + def
.definitionName
)) { //$NON-NLS-1$
235 traceClass
= CustomTxtTrace
.class;
239 if (fTraceTypeId
.startsWith(CustomXmlTrace
.class.getCanonicalName())) {
240 for (CustomXmlTraceDefinition def
: CustomXmlTraceDefinition
.loadAll()) {
241 if (fTraceTypeId
.equals(CustomXmlTrace
.class.getCanonicalName() + ":" + def
.definitionName
)) { //$NON-NLS-1$
242 traceClass
= CustomTxtTrace
.class;
246 } else if (helper
!= null) {
247 traceClass
= helper
.getTraceClass();
250 /* Remove all analysis and return */
251 if (traceClass
== null) {
252 for (TmfAnalysisElement analysis
: childrenMap
.values()) {
253 removeChild(analysis
);
258 /** Get the base path to put the resource to */
259 IPath path
= fResource
.getFullPath();
261 /* Add all new analysis modules or refresh outputs of existing ones */
262 for (IAnalysisModuleHelper module
: TmfAnalysisManager
.getAnalysisModules(traceClass
).values()) {
264 /* If the analysis is not a child of the trace, create it */
265 TmfAnalysisElement analysis
= childrenMap
.remove(module
.getId());
266 if (analysis
== null) {
268 * No need for the resource to exist, nothing will be done with
271 IFolder newresource
= ResourcesPlugin
.getWorkspace().getRoot().getFolder(path
.append(module
.getId()));
272 analysis
= new TmfAnalysisElement(module
.getName(), newresource
, this, module
.getId());
274 analysis
.refreshChildren();
277 /* Remove analysis that are not children of this trace anymore */
278 for (TmfAnalysisElement analysis
: childrenMap
.values()) {
279 removeChild(analysis
);
283 // ------------------------------------------------------------------------
285 // ------------------------------------------------------------------------
287 * Returns the trace type ID.
289 * @return trace type ID.
291 public String
getTraceType() {
296 * Refreshes the trace type filed by reading the trace type persistent
297 * property of the resource referenece.
299 public void refreshTraceType() {
301 fTraceTypeId
= getResource().getPersistentProperty(TmfCommonConstants
.TRACETYPE
);
302 } catch (CoreException e
) {
303 Activator
.getDefault().logError("Error refreshing trace type pesistent property for trace " + getName(), e
); //$NON-NLS-1$
308 * Instantiate a <code>ITmfTrace</code> object based on the trace type and
309 * the corresponding extension.
311 * @return the <code>ITmfTrace</code> or <code>null</code> for an error
313 public ITmfTrace
instantiateTrace() {
316 // make sure that supplementary folder exists
317 refreshSupplementaryFolder();
319 if (fTraceTypeId
!= null) {
320 if (fTraceTypeId
.startsWith(CustomTxtTrace
.class.getCanonicalName())) {
321 for (CustomTxtTraceDefinition def
: CustomTxtTraceDefinition
.loadAll()) {
322 if (fTraceTypeId
.equals(CustomTxtTrace
.class.getCanonicalName() + ":" + def
.definitionName
)) { //$NON-NLS-1$
323 return new CustomTxtTrace(def
);
327 if (fTraceTypeId
.startsWith(CustomXmlTrace
.class.getCanonicalName())) {
328 for (CustomXmlTraceDefinition def
: CustomXmlTraceDefinition
.loadAll()) {
329 if (fTraceTypeId
.equals(CustomXmlTrace
.class.getCanonicalName() + ":" + def
.definitionName
)) { //$NON-NLS-1$
330 return new CustomXmlTrace(def
);
334 IConfigurationElement ce
= sfTraceTypeAttributes
.get(fTraceTypeId
);
338 ITmfTrace trace
= (ITmfTrace
) ce
.createExecutableExtension(TmfTraceType
.TRACE_TYPE_ATTR
);
341 } catch (CoreException e
) {
342 Activator
.getDefault().logError("Error instantiating ITmfTrace object for trace " + getName(), e
); //$NON-NLS-1$
348 * Instantiate a <code>ITmfEvent</code> object based on the trace type and
349 * the corresponding extension.
351 * @return the <code>ITmfEvent</code> or <code>null</code> for an error
353 public ITmfEvent
instantiateEvent() {
355 if (fTraceTypeId
!= null) {
356 if (fTraceTypeId
.startsWith(CustomTxtTrace
.class.getCanonicalName())) {
357 for (CustomTxtTraceDefinition def
: CustomTxtTraceDefinition
.loadAll()) {
358 if (fTraceTypeId
.equals(CustomTxtTrace
.class.getCanonicalName() + ":" + def
.definitionName
)) { //$NON-NLS-1$
359 return new CustomTxtEvent(def
);
363 if (fTraceTypeId
.startsWith(CustomXmlTrace
.class.getCanonicalName())) {
364 for (CustomXmlTraceDefinition def
: CustomXmlTraceDefinition
.loadAll()) {
365 if (fTraceTypeId
.equals(CustomXmlTrace
.class.getCanonicalName() + ":" + def
.definitionName
)) { //$NON-NLS-1$
366 return new CustomXmlEvent(def
);
370 IConfigurationElement ce
= sfTraceTypeAttributes
.get(fTraceTypeId
);
374 ITmfEvent event
= (ITmfEvent
) ce
.createExecutableExtension(TmfTraceType
.EVENT_TYPE_ATTR
);
377 } catch (CoreException e
) {
378 Activator
.getDefault().logError("Error instantiating ITmfEvent object for trace " + getName(), e
); //$NON-NLS-1$
384 * Returns the optional editor ID from the trace type extension.
386 * @return the editor ID or <code>null</code> if not defined.
388 public String
getEditorId() {
389 if (fTraceTypeId
!= null) {
390 if (fTraceTypeId
.startsWith(CustomTxtTrace
.class.getCanonicalName())) {
391 return TmfEventsEditor
.ID
;
393 if (fTraceTypeId
.startsWith(CustomXmlTrace
.class.getCanonicalName())) {
394 return TmfEventsEditor
.ID
;
396 IConfigurationElement ce
= sfTraceTypeUIAttributes
.get(fTraceTypeId
);
398 /* This trace type does not define UI attributes */
401 IConfigurationElement
[] defaultEditorCE
= ce
.getChildren(TmfTraceTypeUIUtils
.DEFAULT_EDITOR_ELEM
);
402 if (defaultEditorCE
.length
== 1) {
403 return defaultEditorCE
[0].getAttribute(TmfTraceType
.ID_ATTR
);
410 * Returns the file resource used to store bookmarks after creating it if
411 * necessary. If the trace resource is a file, it is returned directly. If
412 * the trace resource is a folder, a linked file is returned. The file will
413 * be created if it does not exist.
415 * @return the bookmarks file
416 * @throws CoreException
417 * if the bookmarks file cannot be created
420 public IFile
createBookmarksFile() throws CoreException
{
421 IFile file
= getBookmarksFile();
422 if (fResource
instanceof IFolder
) {
423 if (!file
.exists()) {
424 final IFile bookmarksFile
= getProject().getTracesFolder().getResource().getFile(BOOKMARKS_HIDDEN_FILE
);
425 if (!bookmarksFile
.exists()) {
426 final InputStream source
= new ByteArrayInputStream(new byte[0]);
427 bookmarksFile
.create(source
, true, null);
429 bookmarksFile
.setHidden(true);
430 file
.createLink(bookmarksFile
.getLocation(), IResource
.REPLACE
, null);
431 file
.setHidden(true);
432 file
.setPersistentProperty(TmfCommonConstants
.TRACETYPE
, TmfTrace
.class.getCanonicalName());
439 * Returns the file resource used to store bookmarks. The file may not
442 * @return the bookmarks file
445 public IFile
getBookmarksFile() {
447 if (fResource
instanceof IFile
) {
448 file
= (IFile
) fResource
;
449 } else if (fResource
instanceof IFolder
) {
450 final IFolder folder
= (IFolder
) fResource
;
451 file
= folder
.getFile(getName() + '_');
457 * Returns the <code>TmfTraceElement</code> located under the
458 * <code>TmfTracesFolder</code>.
460 * @return <code>this</code> if this element is under the
461 * <code>TmfTracesFolder</code> else the corresponding
462 * <code>TmfTraceElement</code> if this element is under
463 * <code>TmfExperimentElement</code>.
465 public TmfTraceElement
getElementUnderTraceFolder() {
467 // If trace is under an experiment, return original trace from the
469 if (getParent() instanceof TmfExperimentElement
) {
470 for (TmfTraceElement aTrace
: getProject().getTracesFolder().getTraces()) {
471 if (aTrace
.getName().equals(getName())) {
479 // ------------------------------------------------------------------------
481 // ------------------------------------------------------------------------
484 public boolean testAttribute(Object target
, String name
, String value
) {
485 if (name
.equals(IS_LINKED
)) {
486 boolean isLinked
= getResource().isLinked();
487 return Boolean
.toString(isLinked
).equals(value
);
492 // ------------------------------------------------------------------------
494 // ------------------------------------------------------------------------
497 public TmfProjectElement
getProject() {
498 if (getParent() instanceof TmfTraceFolder
) {
499 TmfTraceFolder folder
= (TmfTraceFolder
) getParent();
500 TmfProjectElement project
= (TmfProjectElement
) folder
.getParent();
503 if (getParent() instanceof TmfExperimentElement
) {
504 TmfExperimentElement experiment
= (TmfExperimentElement
) getParent();
505 TmfExperimentFolder folder
= (TmfExperimentFolder
) experiment
.getParent();
506 TmfProjectElement project
= (TmfProjectElement
) folder
.getParent();
512 // ------------------------------------------------------------------------
514 // ------------------------------------------------------------------------
517 public Object
getEditableValue() {
522 * Get the trace properties of this traceElement if the corresponding trace
523 * is opened in an editor
525 * @return a map with the names and values of the trace properties
526 * respectively as keys and values
528 private Map
<String
, String
> getTraceProperties() {
529 for (ITmfTrace openedTrace
: TmfTraceManager
.getInstance().getOpenedTraces()) {
530 for (ITmfTrace singleTrace
: TmfTraceManager
.getTraceSet(openedTrace
)) {
531 if (this.getLocation().toString().endsWith(singleTrace
.getPath())) {
532 if (singleTrace
instanceof ITmfTraceProperties
) {
533 ITmfTraceProperties traceProperties
= (ITmfTraceProperties
) singleTrace
;
534 return traceProperties
.getTraceProperties();
539 return new HashMap
<>();
543 public IPropertyDescriptor
[] getPropertyDescriptors() {
544 Map
<String
, String
> traceProperties
= getTraceProperties();
545 if (!traceProperties
.isEmpty()) {
546 IPropertyDescriptor
[] propertyDescriptorArray
= new IPropertyDescriptor
[traceProperties
.size() + sfDescriptors
.length
];
548 for (Map
.Entry
<String
, String
> varName
: traceProperties
.entrySet()) {
549 ReadOnlyTextPropertyDescriptor descriptor
= new ReadOnlyTextPropertyDescriptor(this.getName() + "_" + varName
.getKey(), varName
.getKey()); //$NON-NLS-1$
550 descriptor
.setCategory(sfTracePropertiesCategory
);
551 propertyDescriptorArray
[index
] = descriptor
;
554 for (int i
= 0; i
< sfDescriptors
.length
; i
++) {
555 propertyDescriptorArray
[index
] = sfDescriptors
[i
];
558 return propertyDescriptorArray
;
560 return Arrays
.copyOf(sfDescriptors
, sfDescriptors
.length
);
564 public Object
getPropertyValue(Object id
) {
566 if (sfName
.equals(id
)) {
570 if (sfPath
.equals(id
)) {
571 return getPath().toString();
574 if (sfLocation
.equals(id
)) {
575 return getLocation().toString();
578 if (sfIsLinked
.equals(id
)) {
579 return Boolean
.valueOf(getResource().isLinked()).toString();
582 if (sfEventType
.equals(id
)) {
583 if (fTraceTypeId
!= null) {
584 IConfigurationElement ce
= sfTraceTypeAttributes
.get(fTraceTypeId
);
585 return (ce
!= null) ?
(getCategory(ce
) + " : " + ce
.getAttribute(TmfTraceType
.NAME_ATTR
)) : ""; //$NON-NLS-1$ //$NON-NLS-2$
589 Map
<String
, String
> traceProperties
= getTraceProperties();
590 if (id
!= null && !traceProperties
.isEmpty()) {
591 String key
= (String
) id
;
592 key
= key
.replaceFirst(this.getName() + "_", ""); //$NON-NLS-1$ //$NON-NLS-2$
593 String value
= traceProperties
.get(key
);
600 private static String
getCategory(IConfigurationElement ce
) {
601 String categoryId
= ce
.getAttribute(TmfTraceType
.CATEGORY_ATTR
);
602 if (categoryId
!= null) {
603 IConfigurationElement category
= sfTraceCategories
.get(categoryId
);
604 if (category
!= null) {
605 return category
.getAttribute(TmfTraceType
.NAME_ATTR
);
608 return "[no category]"; //$NON-NLS-1$
612 public void resetPropertyValue(Object id
) {
616 public void setPropertyValue(Object id
, Object value
) {
620 public boolean isPropertyResettable(Object id
) {
625 public boolean isPropertySet(Object id
) {
630 * Copy this trace in the trace folder. No other parameters are mentioned so
631 * the trace is copied in this element's project trace folder
635 * @return the new Resource object
638 public TmfTraceElement
copy(String string
) {
639 TmfTraceFolder folder
= this.getProject().getTracesFolder();
640 IResource res
= super.copy(string
, false);
641 return new TmfTraceElement(string
, res
, folder
);
645 * Close opened editors associated with this trace.
649 public void closeEditors() {
650 // Close the trace if open
651 IFile file
= getBookmarksFile();
652 FileEditorInput input
= new FileEditorInput(file
);
653 IWorkbench wb
= PlatformUI
.getWorkbench();
654 for (IWorkbenchWindow wbWindow
: wb
.getWorkbenchWindows()) {
655 for (IWorkbenchPage wbPage
: wbWindow
.getPages()) {
656 for (IEditorReference editorReference
: wbPage
.getEditorReferences()) {
658 if (editorReference
.getEditorInput().equals(input
)) {
659 wbPage
.closeEditor(editorReference
.getEditor(false), false);
661 } catch (PartInitException e
) {
662 Activator
.getDefault().logError("Error closing editor for trace " + getName(), e
); //$NON-NLS-1$
668 // Close experiments that contain the trace if open
669 if (getParent() instanceof TmfTraceFolder
) {
670 TmfExperimentFolder experimentFolder
= getProject().getExperimentsFolder();
671 for (ITmfProjectModelElement experiment
: experimentFolder
.getChildren()) {
672 for (ITmfProjectModelElement child
: experiment
.getChildren()) {
673 if (child
.getName().equals(getName())) {
674 ((TmfExperimentElement
) experiment
).closeEditors();
679 } else if (getParent() instanceof TmfExperimentElement
) {
680 TmfExperimentElement experiment
= (TmfExperimentElement
) getParent();
681 experiment
.closeEditors();
686 * Delete the trace resource, remove it from experiments and delete its
687 * supplementary files
689 * @param progressMonitor
690 * a progress monitor, or null if progress reporting is not
693 * @throws CoreException
694 * thrown when IResource.delete fails
697 public void delete(IProgressMonitor progressMonitor
) throws CoreException
{
700 IPath path
= fResource
.getLocation();
701 if (path
!= null && (getParent() instanceof TmfTraceFolder
)) {
702 TmfExperimentFolder experimentFolder
= getProject().getExperimentsFolder();
704 // Propagate the removal to traces
705 for (ITmfProjectModelElement experiment
: experimentFolder
.getChildren()) {
706 List
<ITmfProjectModelElement
> toRemove
= new LinkedList
<>();
707 for (ITmfProjectModelElement child
: experiment
.getChildren()) {
708 if (child
.getName().equals(getName())) {
712 for (ITmfProjectModelElement child
: toRemove
) {
713 ((TmfExperimentElement
) experiment
).removeTrace((TmfTraceElement
) child
);
717 // Delete supplementary files
718 deleteSupplementaryFolder();
721 // Finally, delete the trace
722 fResource
.delete(true, progressMonitor
);
726 * Get the instantiated trace associated with this element.
728 * @return The instantiated trace or null if trace is not (yet) available
731 public ITmfTrace
getTrace() {
732 for (ITmfTrace trace
: TmfTraceManager
.getInstance().getOpenedTraces()) {
733 if (trace
.getResource().equals(getResource())) {
741 * Get the list of analysis model elements under this trace
743 * @return Array of analysis elements
746 public List
<TmfAnalysisElement
> getAvailableAnalysis() {
747 List
<ITmfProjectModelElement
> children
= getChildren();
748 List
<TmfAnalysisElement
> analysis
= new ArrayList
<>();
749 for (ITmfProjectModelElement child
: children
) {
750 if (child
instanceof TmfAnalysisElement
) {
751 analysis
.add((TmfAnalysisElement
) child
);
758 * Handler for the Trace Opened signal
761 * The incoming signal
765 public void traceOpened(TmfTraceOpenedSignal signal
) {
766 IResource resource
= signal
.getTrace().getResource();
767 if ((resource
== null) || !resource
.equals(getResource())) {
771 getParent().refresh();