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