lttng: Add a view for the CPU usage analysis
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / project / model / TmfTraceElement.java
CommitLineData
12c155f5 1/*******************************************************************************
60ae41e1 2 * Copyright (c) 2010, 2014 Ericsson, École Polytechnique de Montréal
ce2388e0 3 *
12c155f5
FC
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
ce2388e0 8 *
12c155f5
FC
9 * Contributors:
10 * Francois Chouinard - Initial API and implementation
b544077e 11 * Bernd Hufmann - Added supplementary files handling
a72a6830
PT
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
4962833a
JCK
15 * Jean-Christian Kouame - added trace properties to be shown into
16 * the properties view
8f5221c2 17 * Geneviève Bastien - Moved trace type related methods to parent class
12c155f5
FC
18 *******************************************************************************/
19
20package org.eclipse.linuxtools.tmf.ui.project.model;
21
5a5c2fc7 22import java.util.Arrays;
12c155f5 23import java.util.HashMap;
6e651d8b 24import java.util.LinkedList;
c068a752 25import java.util.List;
12c155f5
FC
26import java.util.Map;
27
c4c81d91 28import org.eclipse.core.resources.IFile;
5e4bf87d 29import org.eclipse.core.resources.IFolder;
12c155f5
FC
30import org.eclipse.core.resources.IResource;
31import org.eclipse.core.runtime.CoreException;
32import org.eclipse.core.runtime.IConfigurationElement;
c068a752 33import org.eclipse.core.runtime.IPath;
6e651d8b 34import org.eclipse.core.runtime.IProgressMonitor;
12c155f5 35import org.eclipse.core.runtime.Platform;
13f2a21a 36import org.eclipse.core.runtime.URIUtil;
8fd82db5 37import org.eclipse.linuxtools.internal.tmf.ui.Activator;
89730b51 38import org.eclipse.linuxtools.tmf.core.TmfCommonConstants;
ce2388e0 39import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
47aafe74
AM
40import org.eclipse.linuxtools.tmf.core.parsers.custom.CustomTxtEvent;
41import org.eclipse.linuxtools.tmf.core.parsers.custom.CustomTxtTrace;
42import org.eclipse.linuxtools.tmf.core.parsers.custom.CustomTxtTraceDefinition;
43import org.eclipse.linuxtools.tmf.core.parsers.custom.CustomXmlEvent;
44import org.eclipse.linuxtools.tmf.core.parsers.custom.CustomXmlTrace;
45import org.eclipse.linuxtools.tmf.core.parsers.custom.CustomXmlTraceDefinition;
46import org.eclipse.linuxtools.tmf.core.project.model.TmfTraceType;
6c13869b 47import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
4962833a 48import org.eclipse.linuxtools.tmf.core.trace.ITmfTraceProperties;
c4c81d91 49import org.eclipse.linuxtools.tmf.core.trace.TmfTrace;
4962833a 50import org.eclipse.linuxtools.tmf.core.trace.TmfTraceManager;
4bf17f4a 51import org.eclipse.linuxtools.tmf.ui.editors.TmfEventsEditor;
080600d9 52import org.eclipse.linuxtools.tmf.ui.properties.ReadOnlyTextPropertyDescriptor;
12c155f5
FC
53import org.eclipse.ui.IActionFilter;
54import org.eclipse.ui.views.properties.IPropertyDescriptor;
55import org.eclipse.ui.views.properties.IPropertySource2;
12c155f5
FC
56
57/**
d04ec5a7
MK
58 * Implementation of trace model element representing a trace. It provides
59 * methods to instantiate <code>ITmfTrace</code> and <code>ITmfEvent</code> as
60 * well as editor ID from the trace type extension definition.
abbdd66a 61 *
b544077e
BH
62 * @version 1.0
63 * @author Francois Chouinard
12c155f5 64 */
16036bc2 65public class TmfTraceElement extends TmfCommonProjectElement implements IActionFilter, IPropertySource2 {
12c155f5
FC
66
67 // ------------------------------------------------------------------------
68 // Constants
69 // ------------------------------------------------------------------------
70
12c155f5 71 // Other attributes
b544077e
BH
72 /**
73 * Bundle attribute name
74 */
12c155f5 75 public static final String BUNDLE = "bundle"; //$NON-NLS-1$
b544077e
BH
76 /**
77 * IsLinked attribute name.
78 */
12c155f5
FC
79 public static final String IS_LINKED = "isLinked"; //$NON-NLS-1$
80
81 // Property View stuff
4962833a
JCK
82 private static final String sfResourcePropertiesCategory = Messages.TmfTraceElement_ResourceProperties;
83 private static final String sfName = Messages.TmfTraceElement_Name;
84 private static final String sfPath = Messages.TmfTraceElement_Path;
85 private static final String sfLocation = Messages.TmfTraceElement_Location;
86 private static final String sfEventType = Messages.TmfTraceElement_EventType;
87 private static final String sfIsLinked = Messages.TmfTraceElement_IsLinked;
89730b51 88 private static final String sfSourceLocation = Messages.TmfTraceElement_SourceLocation;
4962833a 89 private static final String sfTracePropertiesCategory = Messages.TmfTraceElement_TraceProperties;
12c155f5 90
253d5be1
BH
91 private static final ReadOnlyTextPropertyDescriptor sfNameDescriptor = new ReadOnlyTextPropertyDescriptor(sfName, sfName);
92 private static final ReadOnlyTextPropertyDescriptor sfPathDescriptor = new ReadOnlyTextPropertyDescriptor(sfPath, sfPath);
93 private static final ReadOnlyTextPropertyDescriptor sfLocationDescriptor = new ReadOnlyTextPropertyDescriptor(sfLocation, sfLocation);
94 private static final ReadOnlyTextPropertyDescriptor sfTypeDescriptor = new ReadOnlyTextPropertyDescriptor(sfEventType, sfEventType);
95 private static final ReadOnlyTextPropertyDescriptor sfIsLinkedDescriptor = new ReadOnlyTextPropertyDescriptor(sfIsLinked, sfIsLinked);
89730b51 96 private static final ReadOnlyTextPropertyDescriptor sfSourceLocationDescriptor = new ReadOnlyTextPropertyDescriptor(sfSourceLocation, sfSourceLocation);
12c155f5
FC
97
98 private static final IPropertyDescriptor[] sfDescriptors = { sfNameDescriptor, sfPathDescriptor, sfLocationDescriptor,
89730b51 99 sfTypeDescriptor, sfIsLinkedDescriptor, sfSourceLocationDescriptor };
12c155f5
FC
100
101 static {
4962833a
JCK
102 sfNameDescriptor.setCategory(sfResourcePropertiesCategory);
103 sfPathDescriptor.setCategory(sfResourcePropertiesCategory);
104 sfLocationDescriptor.setCategory(sfResourcePropertiesCategory);
105 sfTypeDescriptor.setCategory(sfResourcePropertiesCategory);
106 sfIsLinkedDescriptor.setCategory(sfResourcePropertiesCategory);
89730b51 107 sfSourceLocationDescriptor.setCategory(sfResourcePropertiesCategory);
12c155f5 108 }
6256d8ad 109
12c155f5
FC
110 // ------------------------------------------------------------------------
111 // Static initialization
112 // ------------------------------------------------------------------------
113
d04ec5a7
MK
114 // The mapping of available trace type IDs to their corresponding
115 // configuration element
507b1336 116 private static final Map<String, IConfigurationElement> sfTraceTypeAttributes = new HashMap<>();
a926c25c 117 private static final Map<String, IConfigurationElement> sfTraceTypeUIAttributes = new HashMap<>();
507b1336 118 private static final Map<String, IConfigurationElement> sfTraceCategories = new HashMap<>();
12c155f5 119
b544077e 120 /**
d04ec5a7
MK
121 * Initialize statically at startup by getting extensions from the platform
122 * extension registry.
b544077e 123 */
12c155f5 124 public static void init() {
a926c25c 125 /* Read the tmf.core "tracetype" extension point */
4bf17f4a 126 IConfigurationElement[] config = Platform.getExtensionRegistry().getConfigurationElementsFor(TmfTraceType.TMF_TRACE_TYPE_ID);
12c155f5 127 for (IConfigurationElement ce : config) {
a926c25c
AM
128 switch (ce.getName()) {
129 case TmfTraceType.TYPE_ELEM:
4bf17f4a 130 String traceTypeId = ce.getAttribute(TmfTraceType.ID_ATTR);
12c155f5 131 sfTraceTypeAttributes.put(traceTypeId, ce);
a926c25c
AM
132 break;
133 case TmfTraceType.CATEGORY_ELEM:
4bf17f4a 134 String categoryId = ce.getAttribute(TmfTraceType.ID_ATTR);
12c155f5 135 sfTraceCategories.put(categoryId, ce);
a926c25c
AM
136 break;
137 default:
138 }
139 }
140
141 /*
142 * Read the corresponding tmf.ui "tracetypeui" extension point for this
143 * trace type, if it exists.
144 */
145 config = Platform.getExtensionRegistry().getConfigurationElementsFor(TmfTraceTypeUIUtils.TMF_TRACE_TYPE_UI_ID);
146 for (IConfigurationElement ce : config) {
147 String elemName = ce.getName();
148 if (TmfTraceTypeUIUtils.TYPE_ELEM.equals(elemName)) {
149 String traceType = ce.getAttribute(TmfTraceTypeUIUtils.TRACETYPE_ATTR);
150 sfTraceTypeUIAttributes.put(traceType, ce);
12c155f5
FC
151 }
152 }
153 }
154
155 // ------------------------------------------------------------------------
156 // Constructors
157 // ------------------------------------------------------------------------
b544077e 158 /**
d04ec5a7
MK
159 * Constructor. Creates trace model element under the trace folder.
160 *
161 * @param name
162 * The name of trace
163 * @param trace
164 * The trace resource.
165 * @param parent
166 * The parent element (trace folder)
b544077e 167 */
12c155f5
FC
168 public TmfTraceElement(String name, IResource trace, TmfTraceFolder parent) {
169 this(name, trace, (TmfProjectModelElement) parent);
170 }
d04ec5a7 171
b544077e 172 /**
d04ec5a7
MK
173 * Constructor. Creates trace model element under the experiment folder.
174 *
175 * @param name
176 * The name of trace
177 * @param trace
178 * The trace resource.
179 * @param parent
180 * The parent element (experiment folder)
b544077e 181 */
12c155f5
FC
182 public TmfTraceElement(String name, IResource trace, TmfExperimentElement parent) {
183 this(name, trace, (TmfProjectModelElement) parent);
184 }
185
186 private TmfTraceElement(String name, IResource trace, TmfProjectModelElement parent) {
187 super(name, trace, parent);
f537c959
PT
188 }
189
12c155f5
FC
190 // ------------------------------------------------------------------------
191 // Operations
192 // ------------------------------------------------------------------------
12c155f5 193
b544077e 194 /**
d04ec5a7
MK
195 * Instantiate a <code>ITmfTrace</code> object based on the trace type and
196 * the corresponding extension.
abbdd66a 197 *
b544077e
BH
198 * @return the <code>ITmfTrace</code> or <code>null</code> for an error
199 */
8f5221c2 200 @Override
6256d8ad 201 public ITmfTrace instantiateTrace() {
12c155f5 202 try {
e12ecd30
BH
203
204 // make sure that supplementary folder exists
205 refreshSupplementaryFolder();
206
8f5221c2
GB
207 if (getTraceType() != null) {
208 if (getTraceType().startsWith(CustomTxtTrace.class.getCanonicalName())) {
4bf17f4a 209 for (CustomTxtTraceDefinition def : CustomTxtTraceDefinition.loadAll()) {
8f5221c2 210 if (getTraceType().equals(CustomTxtTrace.class.getCanonicalName() + ":" + def.definitionName)) { //$NON-NLS-1$
4bf17f4a 211 return new CustomTxtTrace(def);
212 }
213 }
214 }
8f5221c2 215 if (getTraceType().startsWith(CustomXmlTrace.class.getCanonicalName())) {
4bf17f4a 216 for (CustomXmlTraceDefinition def : CustomXmlTraceDefinition.loadAll()) {
8f5221c2 217 if (getTraceType().equals(CustomXmlTrace.class.getCanonicalName() + ":" + def.definitionName)) { //$NON-NLS-1$
4bf17f4a 218 return new CustomXmlTrace(def);
219 }
220 }
221 }
8f5221c2 222 IConfigurationElement ce = sfTraceTypeAttributes.get(getTraceType());
d04ec5a7
MK
223 if (ce == null) {
224 return null;
225 }
6256d8ad 226 ITmfTrace trace = (ITmfTrace) ce.createExecutableExtension(TmfTraceType.TRACE_TYPE_ATTR);
12c155f5
FC
227 return trace;
228 }
229 } catch (CoreException e) {
8fd82db5 230 Activator.getDefault().logError("Error instantiating ITmfTrace object for trace " + getName(), e); //$NON-NLS-1$
12c155f5
FC
231 }
232 return null;
233 }
234
b544077e 235 /**
d04ec5a7
MK
236 * Instantiate a <code>ITmfEvent</code> object based on the trace type and
237 * the corresponding extension.
abbdd66a 238 *
b544077e
BH
239 * @return the <code>ITmfEvent</code> or <code>null</code> for an error
240 */
ce2388e0 241 public ITmfEvent instantiateEvent() {
12c155f5 242 try {
8f5221c2
GB
243 if (getTraceType() != null) {
244 if (getTraceType().startsWith(CustomTxtTrace.class.getCanonicalName())) {
4bf17f4a 245 for (CustomTxtTraceDefinition def : CustomTxtTraceDefinition.loadAll()) {
8f5221c2 246 if (getTraceType().equals(CustomTxtTrace.class.getCanonicalName() + ":" + def.definitionName)) { //$NON-NLS-1$
4bf17f4a 247 return new CustomTxtEvent(def);
248 }
249 }
250 }
8f5221c2 251 if (getTraceType().startsWith(CustomXmlTrace.class.getCanonicalName())) {
4bf17f4a 252 for (CustomXmlTraceDefinition def : CustomXmlTraceDefinition.loadAll()) {
8f5221c2 253 if (getTraceType().equals(CustomXmlTrace.class.getCanonicalName() + ":" + def.definitionName)) { //$NON-NLS-1$
4bf17f4a 254 return new CustomXmlEvent(def);
255 }
256 }
257 }
8f5221c2 258 IConfigurationElement ce = sfTraceTypeAttributes.get(getTraceType());
d04ec5a7
MK
259 if (ce == null) {
260 return null;
261 }
ce2388e0 262 ITmfEvent event = (ITmfEvent) ce.createExecutableExtension(TmfTraceType.EVENT_TYPE_ATTR);
12c155f5
FC
263 return event;
264 }
265 } catch (CoreException e) {
8fd82db5 266 Activator.getDefault().logError("Error instantiating ITmfEvent object for trace " + getName(), e); //$NON-NLS-1$
12c155f5
FC
267 }
268 return null;
269 }
270
8f5221c2 271 @Override
12c155f5 272 public String getEditorId() {
8f5221c2
GB
273 if (getTraceType() != null) {
274 if (getTraceType().startsWith(CustomTxtTrace.class.getCanonicalName())) {
4bf17f4a 275 return TmfEventsEditor.ID;
276 }
8f5221c2 277 if (getTraceType().startsWith(CustomXmlTrace.class.getCanonicalName())) {
4bf17f4a 278 return TmfEventsEditor.ID;
279 }
8f5221c2 280 IConfigurationElement ce = sfTraceTypeUIAttributes.get(getTraceType());
a926c25c
AM
281 if (ce == null) {
282 /* This trace type does not define UI attributes */
283 return null;
284 }
285 IConfigurationElement[] defaultEditorCE = ce.getChildren(TmfTraceTypeUIUtils.DEFAULT_EDITOR_ELEM);
12c155f5 286 if (defaultEditorCE.length == 1) {
4bf17f4a 287 return defaultEditorCE[0].getAttribute(TmfTraceType.ID_ATTR);
12c155f5
FC
288 }
289 }
290 return null;
291 }
e12ecd30 292
c4c81d91 293 /**
d04ec5a7
MK
294 * Returns the file resource used to store bookmarks after creating it if
295 * necessary. If the trace resource is a file, it is returned directly. If
296 * the trace resource is a folder, a linked file is returned. The file will
297 * be created if it does not exist.
298 *
c4c81d91 299 * @return the bookmarks file
d04ec5a7
MK
300 * @throws CoreException
301 * if the bookmarks file cannot be created
c4c81d91
PT
302 * @since 2.0
303 */
8f5221c2 304 @Override
81fe3479
PT
305 public IFile createBookmarksFile() throws CoreException {
306 IFile file = getBookmarksFile();
307 if (fResource instanceof IFolder) {
8f5221c2 308 return createBookmarksFile(getProject().getTracesFolder().getResource(), TmfTrace.class.getCanonicalName());
81fe3479
PT
309 }
310 return file;
311 }
312
313 /**
d04ec5a7
MK
314 * Returns the file resource used to store bookmarks. The file may not
315 * exist.
316 *
81fe3479
PT
317 * @return the bookmarks file
318 * @since 2.0
319 */
8f5221c2 320 @Override
81fe3479 321 public IFile getBookmarksFile() {
c4c81d91
PT
322 IFile file = null;
323 if (fResource instanceof IFile) {
324 file = (IFile) fResource;
325 } else if (fResource instanceof IFolder) {
c4c81d91
PT
326 final IFolder folder = (IFolder) fResource;
327 file = folder.getFile(getName() + '_');
c4c81d91
PT
328 }
329 return file;
330 }
331
e12ecd30 332 /**
d04ec5a7
MK
333 * Returns the <code>TmfTraceElement</code> located under the
334 * <code>TmfTracesFolder</code>.
6256d8ad 335 *
d04ec5a7
MK
336 * @return <code>this</code> if this element is under the
337 * <code>TmfTracesFolder</code> else the corresponding
338 * <code>TmfTraceElement</code> if this element is under
e12ecd30
BH
339 * <code>TmfExperimentElement</code>.
340 */
5e4bf87d 341 public TmfTraceElement getElementUnderTraceFolder() {
e12ecd30 342
d04ec5a7
MK
343 // If trace is under an experiment, return original trace from the
344 // traces folder
5e4bf87d
BH
345 if (getParent() instanceof TmfExperimentElement) {
346 for (TmfTraceElement aTrace : getProject().getTracesFolder().getTraces()) {
347 if (aTrace.getName().equals(getName())) {
348 return aTrace;
349 }
350 }
351 }
352 return this;
353 }
6256d8ad 354
8f5221c2
GB
355 @Override
356 public String getTypeName() {
357 return Messages.TmfTraceElement_TypeName;
358 }
359
12c155f5
FC
360 // ------------------------------------------------------------------------
361 // IActionFilter
362 // ------------------------------------------------------------------------
363
364 @Override
365 public boolean testAttribute(Object target, String name, String value) {
366 if (name.equals(IS_LINKED)) {
367 boolean isLinked = getResource().isLinked();
368 return Boolean.toString(isLinked).equals(value);
369 }
370 return false;
371 }
372
373 // ------------------------------------------------------------------------
374 // TmfTraceElement
375 // ------------------------------------------------------------------------
11252342 376
12c155f5
FC
377 @Override
378 public TmfProjectElement getProject() {
379 if (getParent() instanceof TmfTraceFolder) {
380 TmfTraceFolder folder = (TmfTraceFolder) getParent();
381 TmfProjectElement project = (TmfProjectElement) folder.getParent();
382 return project;
383 }
384 if (getParent() instanceof TmfExperimentElement) {
385 TmfExperimentElement experiment = (TmfExperimentElement) getParent();
386 TmfExperimentFolder folder = (TmfExperimentFolder) experiment.getParent();
387 TmfProjectElement project = (TmfProjectElement) folder.getParent();
388 return project;
389 }
390 return null;
391 }
392
393 // ------------------------------------------------------------------------
394 // IPropertySource2
395 // ------------------------------------------------------------------------
396
397 @Override
398 public Object getEditableValue() {
399 return null;
400 }
401
4962833a
JCK
402 /**
403 * Get the trace properties of this traceElement if the corresponding trace
404 * is opened in an editor
405 *
406 * @return a map with the names and values of the trace properties
407 * respectively as keys and values
408 */
409 private Map<String, String> getTraceProperties() {
8d534d69
JCK
410 for (ITmfTrace openedTrace : TmfTraceManager.getInstance().getOpenedTraces()) {
411 for (ITmfTrace singleTrace : TmfTraceManager.getTraceSet(openedTrace)) {
13f2a21a 412 if (this.getLocation().getPath().endsWith(singleTrace.getPath())) {
8d534d69
JCK
413 if (singleTrace instanceof ITmfTraceProperties) {
414 ITmfTraceProperties traceProperties = (ITmfTraceProperties) singleTrace;
415 return traceProperties.getTraceProperties();
416 }
4962833a
JCK
417 }
418 }
419 }
507b1336 420 return new HashMap<>();
4962833a
JCK
421 }
422
12c155f5
FC
423 @Override
424 public IPropertyDescriptor[] getPropertyDescriptors() {
4962833a
JCK
425 Map<String, String> traceProperties = getTraceProperties();
426 if (!traceProperties.isEmpty()) {
427 IPropertyDescriptor[] propertyDescriptorArray = new IPropertyDescriptor[traceProperties.size() + sfDescriptors.length];
428 int index = 0;
429 for (Map.Entry<String, String> varName : traceProperties.entrySet()) {
430 ReadOnlyTextPropertyDescriptor descriptor = new ReadOnlyTextPropertyDescriptor(this.getName() + "_" + varName.getKey(), varName.getKey()); //$NON-NLS-1$
431 descriptor.setCategory(sfTracePropertiesCategory);
432 propertyDescriptorArray[index] = descriptor;
433 index++;
434 }
435 for (int i = 0; i < sfDescriptors.length; i++) {
436 propertyDescriptorArray[index] = sfDescriptors[i];
437 index++;
438 }
439 return propertyDescriptorArray;
440 }
77fdc5df 441 return Arrays.copyOf(sfDescriptors, sfDescriptors.length);
12c155f5
FC
442 }
443
444 @Override
445 public Object getPropertyValue(Object id) {
446
ce2388e0 447 if (sfName.equals(id)) {
12c155f5 448 return getName();
ce2388e0 449 }
12c155f5 450
ce2388e0 451 if (sfPath.equals(id)) {
12c155f5 452 return getPath().toString();
ce2388e0 453 }
12c155f5 454
ce2388e0 455 if (sfLocation.equals(id)) {
13f2a21a 456 return URIUtil.toUnencodedString(getLocation());
ce2388e0 457 }
12c155f5 458
933ff94f
PT
459 if (sfIsLinked.equals(id)) {
460 return Boolean.valueOf(getResource().isLinked()).toString();
461 }
462
89730b51
PT
463 if (sfSourceLocation.equals(id)) {
464 try {
465 String sourceLocation = getElementUnderTraceFolder().getResource().getPersistentProperty(TmfCommonConstants.SOURCE_LOCATION);
466 if (sourceLocation != null) {
467 return sourceLocation;
468 }
469 } catch (CoreException e) {
470 }
471 return ""; //$NON-NLS-1$
ce2388e0 472 }
12c155f5
FC
473
474 if (sfEventType.equals(id)) {
8f5221c2
GB
475 if (getTraceType() != null) {
476 IConfigurationElement ce = sfTraceTypeAttributes.get(getTraceType());
4bf17f4a 477 return (ce != null) ? (getCategory(ce) + " : " + ce.getAttribute(TmfTraceType.NAME_ATTR)) : ""; //$NON-NLS-1$ //$NON-NLS-2$
12c155f5
FC
478 }
479 }
480
4962833a
JCK
481 Map<String, String> traceProperties = getTraceProperties();
482 if (id != null && !traceProperties.isEmpty()) {
483 String key = (String) id;
e48bd720 484 key = key.substring(this.getName().length() + 1); // remove name_
4962833a
JCK
485 String value = traceProperties.get(key);
486 return value;
487 }
488
12c155f5
FC
489 return null;
490 }
491
abbdd66a 492 private static String getCategory(IConfigurationElement ce) {
4bf17f4a 493 String categoryId = ce.getAttribute(TmfTraceType.CATEGORY_ATTR);
12c155f5
FC
494 if (categoryId != null) {
495 IConfigurationElement category = sfTraceCategories.get(categoryId);
4bf17f4a 496 if (category != null) {
497 return category.getAttribute(TmfTraceType.NAME_ATTR);
12c155f5
FC
498 }
499 }
500 return "[no category]"; //$NON-NLS-1$
501 }
502
503 @Override
504 public void resetPropertyValue(Object id) {
505 }
506
507 @Override
508 public void setPropertyValue(Object id, Object value) {
509 }
510
511 @Override
512 public boolean isPropertyResettable(Object id) {
513 return false;
514 }
515
516 @Override
517 public boolean isPropertySet(Object id) {
518 return false;
519 }
520
beb19106
GB
521 /**
522 * Copy this trace in the trace folder. No other parameters are mentioned so
523 * the trace is copied in this element's project trace folder
524 *
525 * @param string
526 * The new trace name
527 * @return the new Resource object
528 * @since 2.0
529 */
530 public TmfTraceElement copy(String string) {
531 TmfTraceFolder folder = this.getProject().getTracesFolder();
532 IResource res = super.copy(string, false);
533 return new TmfTraceElement(string, res, folder);
534 }
535
a72a6830
PT
536 /**
537 * Close opened editors associated with this trace.
4962833a 538 *
a72a6830
PT
539 * @since 2.0
540 */
8f5221c2 541 @Override
a72a6830 542 public void closeEditors() {
8f5221c2 543 super.closeEditors();
a72a6830
PT
544
545 // Close experiments that contain the trace if open
546 if (getParent() instanceof TmfTraceFolder) {
547 TmfExperimentFolder experimentFolder = getProject().getExperimentsFolder();
548 for (ITmfProjectModelElement experiment : experimentFolder.getChildren()) {
549 for (ITmfProjectModelElement child : experiment.getChildren()) {
550 if (child.getName().equals(getName())) {
551 ((TmfExperimentElement) experiment).closeEditors();
552 break;
553 }
554 }
555 }
556 } else if (getParent() instanceof TmfExperimentElement) {
557 TmfExperimentElement experiment = (TmfExperimentElement) getParent();
558 experiment.closeEditors();
559 }
560 }
8dcdf263 561
6e651d8b
MAL
562 /**
563 * Delete the trace resource, remove it from experiments and delete its
564 * supplementary files
565 *
566 * @param progressMonitor
567 * a progress monitor, or null if progress reporting is not
568 * desired
569 *
570 * @throws CoreException
571 * thrown when IResource.delete fails
572 * @since 2.2
573 */
574 public void delete(IProgressMonitor progressMonitor) throws CoreException {
575 closeEditors();
576
577 IPath path = fResource.getLocation();
2bb6a6b8
BH
578 if (path != null) {
579 if (getParent() instanceof TmfTraceFolder) {
580 TmfExperimentFolder experimentFolder = getProject().getExperimentsFolder();
581
582 // Propagate the removal to traces
583 for (ITmfProjectModelElement experiment : experimentFolder.getChildren()) {
584 List<ITmfProjectModelElement> toRemove = new LinkedList<>();
585 for (ITmfProjectModelElement child : experiment.getChildren()) {
586 if (child.getName().equals(getName())) {
587 toRemove.add(child);
588 }
589 }
590 for (ITmfProjectModelElement child : toRemove) {
591 ((TmfExperimentElement) experiment).removeTrace((TmfTraceElement) child);
6e651d8b
MAL
592 }
593 }
6e651d8b 594
2bb6a6b8
BH
595 // Delete supplementary files
596 deleteSupplementaryFolder();
597
598 } else if (getParent() instanceof TmfExperimentElement) {
599 TmfExperimentElement experimentElement = (TmfExperimentElement) getParent();
600 experimentElement.removeTrace(this);
601 }
6e651d8b
MAL
602 }
603
604 // Finally, delete the trace
605 fResource.delete(true, progressMonitor);
606 }
607
12c155f5 608}
This page took 0.079024 seconds and 5 git commands to generate.