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