Commit | Line | Data |
---|---|---|
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 | ||
20 | package org.eclipse.linuxtools.tmf.ui.project.model; | |
21 | ||
5a5c2fc7 | 22 | import java.util.Arrays; |
12c155f5 | 23 | import java.util.HashMap; |
6e651d8b | 24 | import java.util.LinkedList; |
c068a752 | 25 | import java.util.List; |
12c155f5 FC |
26 | import java.util.Map; |
27 | ||
c4c81d91 | 28 | import org.eclipse.core.resources.IFile; |
5e4bf87d | 29 | import org.eclipse.core.resources.IFolder; |
12c155f5 FC |
30 | import org.eclipse.core.resources.IResource; |
31 | import org.eclipse.core.runtime.CoreException; | |
32 | import org.eclipse.core.runtime.IConfigurationElement; | |
c068a752 | 33 | import org.eclipse.core.runtime.IPath; |
6e651d8b | 34 | import org.eclipse.core.runtime.IProgressMonitor; |
12c155f5 | 35 | import org.eclipse.core.runtime.Platform; |
13f2a21a | 36 | import org.eclipse.core.runtime.URIUtil; |
8fd82db5 | 37 | import org.eclipse.linuxtools.internal.tmf.ui.Activator; |
89730b51 | 38 | import org.eclipse.linuxtools.tmf.core.TmfCommonConstants; |
ce2388e0 | 39 | import org.eclipse.linuxtools.tmf.core.event.ITmfEvent; |
47aafe74 AM |
40 | import org.eclipse.linuxtools.tmf.core.parsers.custom.CustomTxtEvent; |
41 | import org.eclipse.linuxtools.tmf.core.parsers.custom.CustomTxtTrace; | |
42 | import org.eclipse.linuxtools.tmf.core.parsers.custom.CustomTxtTraceDefinition; | |
43 | import org.eclipse.linuxtools.tmf.core.parsers.custom.CustomXmlEvent; | |
44 | import org.eclipse.linuxtools.tmf.core.parsers.custom.CustomXmlTrace; | |
45 | import org.eclipse.linuxtools.tmf.core.parsers.custom.CustomXmlTraceDefinition; | |
46 | import org.eclipse.linuxtools.tmf.core.project.model.TmfTraceType; | |
6c13869b | 47 | import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace; |
4962833a | 48 | import org.eclipse.linuxtools.tmf.core.trace.ITmfTraceProperties; |
c4c81d91 | 49 | import org.eclipse.linuxtools.tmf.core.trace.TmfTrace; |
4962833a | 50 | import org.eclipse.linuxtools.tmf.core.trace.TmfTraceManager; |
4bf17f4a | 51 | import org.eclipse.linuxtools.tmf.ui.editors.TmfEventsEditor; |
080600d9 | 52 | import org.eclipse.linuxtools.tmf.ui.properties.ReadOnlyTextPropertyDescriptor; |
12c155f5 FC |
53 | import org.eclipse.ui.IActionFilter; |
54 | import org.eclipse.ui.views.properties.IPropertyDescriptor; | |
55 | import 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 | 65 | public 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 | 168 | public TmfTraceElement(String name, IResource trace, TmfTraceFolder parent) { |
339d539c | 169 | super(name, trace, parent); |
12c155f5 | 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 | 182 | public TmfTraceElement(String name, IResource trace, TmfExperimentElement parent) { |
12c155f5 | 183 | super(name, trace, parent); |
f537c959 PT |
184 | } |
185 | ||
12c155f5 FC |
186 | // ------------------------------------------------------------------------ |
187 | // Operations | |
188 | // ------------------------------------------------------------------------ | |
12c155f5 | 189 | |
b544077e | 190 | /** |
d04ec5a7 MK |
191 | * Instantiate a <code>ITmfTrace</code> object based on the trace type and |
192 | * the corresponding extension. | |
abbdd66a | 193 | * |
b544077e BH |
194 | * @return the <code>ITmfTrace</code> or <code>null</code> for an error |
195 | */ | |
8f5221c2 | 196 | @Override |
6256d8ad | 197 | public ITmfTrace instantiateTrace() { |
12c155f5 | 198 | try { |
e12ecd30 BH |
199 | |
200 | // make sure that supplementary folder exists | |
201 | refreshSupplementaryFolder(); | |
202 | ||
8f5221c2 GB |
203 | if (getTraceType() != null) { |
204 | if (getTraceType().startsWith(CustomTxtTrace.class.getCanonicalName())) { | |
4bf17f4a | 205 | for (CustomTxtTraceDefinition def : CustomTxtTraceDefinition.loadAll()) { |
8f5221c2 | 206 | if (getTraceType().equals(CustomTxtTrace.class.getCanonicalName() + ":" + def.definitionName)) { //$NON-NLS-1$ |
4bf17f4a | 207 | return new CustomTxtTrace(def); |
208 | } | |
209 | } | |
210 | } | |
8f5221c2 | 211 | if (getTraceType().startsWith(CustomXmlTrace.class.getCanonicalName())) { |
4bf17f4a | 212 | for (CustomXmlTraceDefinition def : CustomXmlTraceDefinition.loadAll()) { |
8f5221c2 | 213 | if (getTraceType().equals(CustomXmlTrace.class.getCanonicalName() + ":" + def.definitionName)) { //$NON-NLS-1$ |
4bf17f4a | 214 | return new CustomXmlTrace(def); |
215 | } | |
216 | } | |
217 | } | |
8f5221c2 | 218 | IConfigurationElement ce = sfTraceTypeAttributes.get(getTraceType()); |
d04ec5a7 MK |
219 | if (ce == null) { |
220 | return null; | |
221 | } | |
6256d8ad | 222 | ITmfTrace trace = (ITmfTrace) ce.createExecutableExtension(TmfTraceType.TRACE_TYPE_ATTR); |
12c155f5 FC |
223 | return trace; |
224 | } | |
225 | } catch (CoreException e) { | |
8fd82db5 | 226 | Activator.getDefault().logError("Error instantiating ITmfTrace object for trace " + getName(), e); //$NON-NLS-1$ |
12c155f5 FC |
227 | } |
228 | return null; | |
229 | } | |
230 | ||
b544077e | 231 | /** |
d04ec5a7 MK |
232 | * Instantiate a <code>ITmfEvent</code> object based on the trace type and |
233 | * the corresponding extension. | |
abbdd66a | 234 | * |
b544077e BH |
235 | * @return the <code>ITmfEvent</code> or <code>null</code> for an error |
236 | */ | |
ce2388e0 | 237 | public ITmfEvent instantiateEvent() { |
12c155f5 | 238 | try { |
8f5221c2 GB |
239 | if (getTraceType() != null) { |
240 | if (getTraceType().startsWith(CustomTxtTrace.class.getCanonicalName())) { | |
4bf17f4a | 241 | for (CustomTxtTraceDefinition def : CustomTxtTraceDefinition.loadAll()) { |
8f5221c2 | 242 | if (getTraceType().equals(CustomTxtTrace.class.getCanonicalName() + ":" + def.definitionName)) { //$NON-NLS-1$ |
4bf17f4a | 243 | return new CustomTxtEvent(def); |
244 | } | |
245 | } | |
246 | } | |
8f5221c2 | 247 | if (getTraceType().startsWith(CustomXmlTrace.class.getCanonicalName())) { |
4bf17f4a | 248 | for (CustomXmlTraceDefinition def : CustomXmlTraceDefinition.loadAll()) { |
8f5221c2 | 249 | if (getTraceType().equals(CustomXmlTrace.class.getCanonicalName() + ":" + def.definitionName)) { //$NON-NLS-1$ |
4bf17f4a | 250 | return new CustomXmlEvent(def); |
251 | } | |
252 | } | |
253 | } | |
8f5221c2 | 254 | IConfigurationElement ce = sfTraceTypeAttributes.get(getTraceType()); |
d04ec5a7 MK |
255 | if (ce == null) { |
256 | return null; | |
257 | } | |
ce2388e0 | 258 | ITmfEvent event = (ITmfEvent) ce.createExecutableExtension(TmfTraceType.EVENT_TYPE_ATTR); |
12c155f5 FC |
259 | return event; |
260 | } | |
261 | } catch (CoreException e) { | |
8fd82db5 | 262 | Activator.getDefault().logError("Error instantiating ITmfEvent object for trace " + getName(), e); //$NON-NLS-1$ |
12c155f5 FC |
263 | } |
264 | return null; | |
265 | } | |
266 | ||
8f5221c2 | 267 | @Override |
12c155f5 | 268 | public String getEditorId() { |
8f5221c2 GB |
269 | if (getTraceType() != null) { |
270 | if (getTraceType().startsWith(CustomTxtTrace.class.getCanonicalName())) { | |
4bf17f4a | 271 | return TmfEventsEditor.ID; |
272 | } | |
8f5221c2 | 273 | if (getTraceType().startsWith(CustomXmlTrace.class.getCanonicalName())) { |
4bf17f4a | 274 | return TmfEventsEditor.ID; |
275 | } | |
8f5221c2 | 276 | IConfigurationElement ce = sfTraceTypeUIAttributes.get(getTraceType()); |
a926c25c AM |
277 | if (ce == null) { |
278 | /* This trace type does not define UI attributes */ | |
279 | return null; | |
280 | } | |
281 | IConfigurationElement[] defaultEditorCE = ce.getChildren(TmfTraceTypeUIUtils.DEFAULT_EDITOR_ELEM); | |
12c155f5 | 282 | if (defaultEditorCE.length == 1) { |
4bf17f4a | 283 | return defaultEditorCE[0].getAttribute(TmfTraceType.ID_ATTR); |
12c155f5 FC |
284 | } |
285 | } | |
286 | return null; | |
287 | } | |
e12ecd30 | 288 | |
c4c81d91 | 289 | /** |
d04ec5a7 MK |
290 | * Returns the file resource used to store bookmarks after creating it if |
291 | * necessary. If the trace resource is a file, it is returned directly. If | |
292 | * the trace resource is a folder, a linked file is returned. The file will | |
293 | * be created if it does not exist. | |
294 | * | |
c4c81d91 | 295 | * @return the bookmarks file |
d04ec5a7 MK |
296 | * @throws CoreException |
297 | * if the bookmarks file cannot be created | |
c4c81d91 PT |
298 | * @since 2.0 |
299 | */ | |
8f5221c2 | 300 | @Override |
81fe3479 PT |
301 | public IFile createBookmarksFile() throws CoreException { |
302 | IFile file = getBookmarksFile(); | |
303 | if (fResource instanceof IFolder) { | |
8f5221c2 | 304 | return createBookmarksFile(getProject().getTracesFolder().getResource(), TmfTrace.class.getCanonicalName()); |
81fe3479 PT |
305 | } |
306 | return file; | |
307 | } | |
308 | ||
309 | /** | |
d04ec5a7 MK |
310 | * Returns the file resource used to store bookmarks. The file may not |
311 | * exist. | |
312 | * | |
81fe3479 PT |
313 | * @return the bookmarks file |
314 | * @since 2.0 | |
315 | */ | |
8f5221c2 | 316 | @Override |
81fe3479 | 317 | public IFile getBookmarksFile() { |
c4c81d91 PT |
318 | IFile file = null; |
319 | if (fResource instanceof IFile) { | |
320 | file = (IFile) fResource; | |
321 | } else if (fResource instanceof IFolder) { | |
c4c81d91 PT |
322 | final IFolder folder = (IFolder) fResource; |
323 | file = folder.getFile(getName() + '_'); | |
c4c81d91 PT |
324 | } |
325 | return file; | |
326 | } | |
327 | ||
e12ecd30 | 328 | /** |
d04ec5a7 MK |
329 | * Returns the <code>TmfTraceElement</code> located under the |
330 | * <code>TmfTracesFolder</code>. | |
6256d8ad | 331 | * |
d04ec5a7 MK |
332 | * @return <code>this</code> if this element is under the |
333 | * <code>TmfTracesFolder</code> else the corresponding | |
334 | * <code>TmfTraceElement</code> if this element is under | |
e12ecd30 BH |
335 | * <code>TmfExperimentElement</code>. |
336 | */ | |
5e4bf87d | 337 | public TmfTraceElement getElementUnderTraceFolder() { |
e12ecd30 | 338 | |
d04ec5a7 MK |
339 | // If trace is under an experiment, return original trace from the |
340 | // traces folder | |
5e4bf87d BH |
341 | if (getParent() instanceof TmfExperimentElement) { |
342 | for (TmfTraceElement aTrace : getProject().getTracesFolder().getTraces()) { | |
339d539c | 343 | if (aTrace.getElementPath().equals(getElementPath())) { |
5e4bf87d BH |
344 | return aTrace; |
345 | } | |
346 | } | |
347 | } | |
348 | return this; | |
349 | } | |
6256d8ad | 350 | |
8f5221c2 GB |
351 | @Override |
352 | public String getTypeName() { | |
353 | return Messages.TmfTraceElement_TypeName; | |
354 | } | |
355 | ||
12c155f5 FC |
356 | // ------------------------------------------------------------------------ |
357 | // IActionFilter | |
358 | // ------------------------------------------------------------------------ | |
359 | ||
360 | @Override | |
361 | public boolean testAttribute(Object target, String name, String value) { | |
362 | if (name.equals(IS_LINKED)) { | |
363 | boolean isLinked = getResource().isLinked(); | |
364 | return Boolean.toString(isLinked).equals(value); | |
365 | } | |
366 | return false; | |
367 | } | |
368 | ||
12c155f5 FC |
369 | // ------------------------------------------------------------------------ |
370 | // IPropertySource2 | |
371 | // ------------------------------------------------------------------------ | |
372 | ||
373 | @Override | |
374 | public Object getEditableValue() { | |
375 | return null; | |
376 | } | |
377 | ||
4962833a JCK |
378 | /** |
379 | * Get the trace properties of this traceElement if the corresponding trace | |
380 | * is opened in an editor | |
381 | * | |
382 | * @return a map with the names and values of the trace properties | |
383 | * respectively as keys and values | |
384 | */ | |
385 | private Map<String, String> getTraceProperties() { | |
8d534d69 JCK |
386 | for (ITmfTrace openedTrace : TmfTraceManager.getInstance().getOpenedTraces()) { |
387 | for (ITmfTrace singleTrace : TmfTraceManager.getTraceSet(openedTrace)) { | |
13f2a21a | 388 | if (this.getLocation().getPath().endsWith(singleTrace.getPath())) { |
8d534d69 JCK |
389 | if (singleTrace instanceof ITmfTraceProperties) { |
390 | ITmfTraceProperties traceProperties = (ITmfTraceProperties) singleTrace; | |
391 | return traceProperties.getTraceProperties(); | |
392 | } | |
4962833a JCK |
393 | } |
394 | } | |
395 | } | |
507b1336 | 396 | return new HashMap<>(); |
4962833a JCK |
397 | } |
398 | ||
12c155f5 FC |
399 | @Override |
400 | public IPropertyDescriptor[] getPropertyDescriptors() { | |
4962833a JCK |
401 | Map<String, String> traceProperties = getTraceProperties(); |
402 | if (!traceProperties.isEmpty()) { | |
403 | IPropertyDescriptor[] propertyDescriptorArray = new IPropertyDescriptor[traceProperties.size() + sfDescriptors.length]; | |
404 | int index = 0; | |
405 | for (Map.Entry<String, String> varName : traceProperties.entrySet()) { | |
406 | ReadOnlyTextPropertyDescriptor descriptor = new ReadOnlyTextPropertyDescriptor(this.getName() + "_" + varName.getKey(), varName.getKey()); //$NON-NLS-1$ | |
407 | descriptor.setCategory(sfTracePropertiesCategory); | |
408 | propertyDescriptorArray[index] = descriptor; | |
409 | index++; | |
410 | } | |
411 | for (int i = 0; i < sfDescriptors.length; i++) { | |
412 | propertyDescriptorArray[index] = sfDescriptors[i]; | |
413 | index++; | |
414 | } | |
415 | return propertyDescriptorArray; | |
416 | } | |
77fdc5df | 417 | return Arrays.copyOf(sfDescriptors, sfDescriptors.length); |
12c155f5 FC |
418 | } |
419 | ||
420 | @Override | |
421 | public Object getPropertyValue(Object id) { | |
422 | ||
ce2388e0 | 423 | if (sfName.equals(id)) { |
12c155f5 | 424 | return getName(); |
ce2388e0 | 425 | } |
12c155f5 | 426 | |
ce2388e0 | 427 | if (sfPath.equals(id)) { |
12c155f5 | 428 | return getPath().toString(); |
ce2388e0 | 429 | } |
12c155f5 | 430 | |
ce2388e0 | 431 | if (sfLocation.equals(id)) { |
13f2a21a | 432 | return URIUtil.toUnencodedString(getLocation()); |
ce2388e0 | 433 | } |
12c155f5 | 434 | |
933ff94f PT |
435 | if (sfIsLinked.equals(id)) { |
436 | return Boolean.valueOf(getResource().isLinked()).toString(); | |
437 | } | |
438 | ||
89730b51 PT |
439 | if (sfSourceLocation.equals(id)) { |
440 | try { | |
441 | String sourceLocation = getElementUnderTraceFolder().getResource().getPersistentProperty(TmfCommonConstants.SOURCE_LOCATION); | |
442 | if (sourceLocation != null) { | |
443 | return sourceLocation; | |
444 | } | |
445 | } catch (CoreException e) { | |
446 | } | |
447 | return ""; //$NON-NLS-1$ | |
ce2388e0 | 448 | } |
12c155f5 FC |
449 | |
450 | if (sfEventType.equals(id)) { | |
8f5221c2 GB |
451 | if (getTraceType() != null) { |
452 | IConfigurationElement ce = sfTraceTypeAttributes.get(getTraceType()); | |
4bf17f4a | 453 | return (ce != null) ? (getCategory(ce) + " : " + ce.getAttribute(TmfTraceType.NAME_ATTR)) : ""; //$NON-NLS-1$ //$NON-NLS-2$ |
12c155f5 | 454 | } |
339d539c | 455 | return ""; //$NON-NLS-1$ |
12c155f5 FC |
456 | } |
457 | ||
4962833a JCK |
458 | Map<String, String> traceProperties = getTraceProperties(); |
459 | if (id != null && !traceProperties.isEmpty()) { | |
460 | String key = (String) id; | |
e48bd720 | 461 | key = key.substring(this.getName().length() + 1); // remove name_ |
4962833a JCK |
462 | String value = traceProperties.get(key); |
463 | return value; | |
464 | } | |
465 | ||
12c155f5 FC |
466 | return null; |
467 | } | |
468 | ||
abbdd66a | 469 | private static String getCategory(IConfigurationElement ce) { |
4bf17f4a | 470 | String categoryId = ce.getAttribute(TmfTraceType.CATEGORY_ATTR); |
12c155f5 FC |
471 | if (categoryId != null) { |
472 | IConfigurationElement category = sfTraceCategories.get(categoryId); | |
4bf17f4a | 473 | if (category != null) { |
474 | return category.getAttribute(TmfTraceType.NAME_ATTR); | |
12c155f5 FC |
475 | } |
476 | } | |
477 | return "[no category]"; //$NON-NLS-1$ | |
478 | } | |
479 | ||
480 | @Override | |
481 | public void resetPropertyValue(Object id) { | |
482 | } | |
483 | ||
484 | @Override | |
485 | public void setPropertyValue(Object id, Object value) { | |
486 | } | |
487 | ||
488 | @Override | |
489 | public boolean isPropertyResettable(Object id) { | |
490 | return false; | |
491 | } | |
492 | ||
493 | @Override | |
494 | public boolean isPropertySet(Object id) { | |
495 | return false; | |
496 | } | |
497 | ||
beb19106 GB |
498 | /** |
499 | * Copy this trace in the trace folder. No other parameters are mentioned so | |
500 | * the trace is copied in this element's project trace folder | |
501 | * | |
502 | * @param string | |
503 | * The new trace name | |
504 | * @return the new Resource object | |
505 | * @since 2.0 | |
506 | */ | |
507 | public TmfTraceElement copy(String string) { | |
508 | TmfTraceFolder folder = this.getProject().getTracesFolder(); | |
509 | IResource res = super.copy(string, false); | |
510 | return new TmfTraceElement(string, res, folder); | |
511 | } | |
512 | ||
a72a6830 PT |
513 | /** |
514 | * Close opened editors associated with this trace. | |
4962833a | 515 | * |
a72a6830 PT |
516 | * @since 2.0 |
517 | */ | |
8f5221c2 | 518 | @Override |
a72a6830 | 519 | public void closeEditors() { |
8f5221c2 | 520 | super.closeEditors(); |
a72a6830 PT |
521 | |
522 | // Close experiments that contain the trace if open | |
523 | if (getParent() instanceof TmfTraceFolder) { | |
339d539c PT |
524 | TmfExperimentFolder experimentsFolder = getProject().getExperimentsFolder(); |
525 | for (TmfExperimentElement experiment : experimentsFolder.getExperiments()) { | |
526 | for (TmfTraceElement trace : experiment.getTraces()) { | |
527 | if (trace.getElementPath().equals(getElementPath())) { | |
528 | experiment.closeEditors(); | |
a72a6830 PT |
529 | break; |
530 | } | |
531 | } | |
532 | } | |
533 | } else if (getParent() instanceof TmfExperimentElement) { | |
534 | TmfExperimentElement experiment = (TmfExperimentElement) getParent(); | |
535 | experiment.closeEditors(); | |
536 | } | |
e5a800b3 AM |
537 | |
538 | /* | |
539 | * We will be closing a trace shortly. Invoke GC to release | |
540 | * MappedByteBuffer objects, which some trace types, like CTF, use. | |
541 | * (see Java bug JDK-4724038) | |
542 | */ | |
543 | System.gc(); | |
a72a6830 | 544 | } |
8dcdf263 | 545 | |
6e651d8b MAL |
546 | /** |
547 | * Delete the trace resource, remove it from experiments and delete its | |
548 | * supplementary files | |
549 | * | |
550 | * @param progressMonitor | |
551 | * a progress monitor, or null if progress reporting is not | |
552 | * desired | |
553 | * | |
554 | * @throws CoreException | |
555 | * thrown when IResource.delete fails | |
556 | * @since 2.2 | |
557 | */ | |
558 | public void delete(IProgressMonitor progressMonitor) throws CoreException { | |
559 | closeEditors(); | |
560 | ||
561 | IPath path = fResource.getLocation(); | |
2bb6a6b8 BH |
562 | if (path != null) { |
563 | if (getParent() instanceof TmfTraceFolder) { | |
564 | TmfExperimentFolder experimentFolder = getProject().getExperimentsFolder(); | |
565 | ||
566 | // Propagate the removal to traces | |
339d539c PT |
567 | for (TmfExperimentElement experiment : experimentFolder.getExperiments()) { |
568 | List<TmfTraceElement> toRemove = new LinkedList<>(); | |
569 | for (TmfTraceElement trace : experiment.getTraces()) { | |
570 | if (trace.getElementPath().equals(getElementPath())) { | |
571 | toRemove.add(trace); | |
2bb6a6b8 BH |
572 | } |
573 | } | |
339d539c PT |
574 | for (TmfTraceElement child : toRemove) { |
575 | experiment.removeTrace(child); | |
6e651d8b MAL |
576 | } |
577 | } | |
6e651d8b | 578 | |
2bb6a6b8 BH |
579 | // Delete supplementary files |
580 | deleteSupplementaryFolder(); | |
581 | ||
582 | } else if (getParent() instanceof TmfExperimentElement) { | |
583 | TmfExperimentElement experimentElement = (TmfExperimentElement) getParent(); | |
584 | experimentElement.removeTrace(this); | |
585 | } | |
6e651d8b MAL |
586 | } |
587 | ||
588 | // Finally, delete the trace | |
589 | fResource.delete(true, progressMonitor); | |
590 | } | |
591 | ||
12c155f5 | 592 | } |