Commit | Line | Data |
---|---|---|
12c155f5 | 1 | /******************************************************************************* |
58ffe079 | 2 | * Copyright (c) 2010, 2015 Ericsson, École Polytechnique de Montréal |
c4c81d91 | 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 | |
c4c81d91 | 8 | * |
12c155f5 FC |
9 | * Contributors: |
10 | * Francois Chouinard - Initial API and implementation | |
beb19106 | 11 | * Geneviève Bastien - Copied code to add/remove traces in this class |
a72a6830 | 12 | * Patrick Tasse - Close editors to release resources |
8f5221c2 | 13 | * Geneviève Bastien - Experiment instantiated with trace type |
12c155f5 FC |
14 | *******************************************************************************/ |
15 | ||
2bdf0193 | 16 | package org.eclipse.tracecompass.tmf.ui.project.model; |
12c155f5 | 17 | |
5c727157 AM |
18 | import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull; |
19 | ||
12c155f5 | 20 | import java.util.ArrayList; |
5a5c2fc7 | 21 | import java.util.Arrays; |
dca8b422 BH |
22 | import java.util.Collections; |
23 | import java.util.Comparator; | |
f537c959 | 24 | import java.util.HashMap; |
12c155f5 | 25 | import java.util.List; |
beb19106 | 26 | import java.util.Map; |
12c155f5 | 27 | |
339d539c | 28 | import org.eclipse.core.resources.IContainer; |
c4c81d91 | 29 | import org.eclipse.core.resources.IFile; |
12c155f5 | 30 | import org.eclipse.core.resources.IFolder; |
c4c81d91 | 31 | import org.eclipse.core.resources.IResource; |
339d539c PT |
32 | import org.eclipse.core.resources.IResourceProxy; |
33 | import org.eclipse.core.resources.IResourceProxyVisitor; | |
beb19106 GB |
34 | import org.eclipse.core.resources.IWorkspace; |
35 | import org.eclipse.core.resources.ResourcesPlugin; | |
c4c81d91 | 36 | import org.eclipse.core.runtime.CoreException; |
8f5221c2 | 37 | import org.eclipse.core.runtime.IConfigurationElement; |
beb19106 | 38 | import org.eclipse.core.runtime.IPath; |
977ca87f | 39 | import org.eclipse.core.runtime.IStatus; |
8f5221c2 | 40 | import org.eclipse.core.runtime.InvalidRegistryObjectException; |
339d539c | 41 | import org.eclipse.core.runtime.NullProgressMonitor; |
8f5221c2 | 42 | import org.eclipse.core.runtime.Platform; |
dff70ccd | 43 | import org.eclipse.jdt.annotation.NonNull; |
8f5221c2 | 44 | import org.eclipse.osgi.util.NLS; |
dff70ccd | 45 | import org.eclipse.swt.graphics.Image; |
ea01e5a2 | 46 | import org.eclipse.swt.widgets.Display; |
2bdf0193 | 47 | import org.eclipse.tracecompass.internal.tmf.ui.Activator; |
58ffe079 | 48 | import org.eclipse.tracecompass.internal.tmf.ui.editors.ITmfEventsEditorConstants; |
2bdf0193 | 49 | import org.eclipse.tracecompass.tmf.core.TmfCommonConstants; |
ff7b95a5 GB |
50 | import org.eclipse.tracecompass.tmf.core.analysis.IAnalysisModuleHelper; |
51 | import org.eclipse.tracecompass.tmf.core.analysis.TmfAnalysisManager; | |
2bdf0193 AM |
52 | import org.eclipse.tracecompass.tmf.core.project.model.TmfTraceType; |
53 | import org.eclipse.tracecompass.tmf.core.project.model.TraceTypeHelper; | |
ff7b95a5 | 54 | import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace; |
5c5fa260 | 55 | import org.eclipse.tracecompass.tmf.core.trace.experiment.TmfExperiment; |
2bdf0193 AM |
56 | import org.eclipse.tracecompass.tmf.ui.editors.TmfEventsEditor; |
57 | import org.eclipse.tracecompass.tmf.ui.properties.ReadOnlyTextPropertyDescriptor; | |
12c155f5 FC |
58 | import org.eclipse.ui.views.properties.IPropertyDescriptor; |
59 | import org.eclipse.ui.views.properties.IPropertySource2; | |
12c155f5 FC |
60 | |
61 | /** | |
b544077e | 62 | * Implementation of TMF Experiment Model Element. |
12c155f5 | 63 | * <p> |
dc62dbee | 64 | * |
b544077e BH |
65 | * @version 1.0 |
66 | * @author Francois Chouinard | |
c4c81d91 | 67 | * |
12c155f5 | 68 | */ |
16036bc2 | 69 | public class TmfExperimentElement extends TmfCommonProjectElement implements IPropertySource2 { |
12c155f5 FC |
70 | |
71 | // ------------------------------------------------------------------------ | |
72 | // Constants | |
73 | // ------------------------------------------------------------------------ | |
74 | ||
75 | // Property View stuff | |
067cd9de BH |
76 | private static final String INFO_CATEGORY = "Info"; //$NON-NLS-1$ |
77 | private static final String NAME = "name"; //$NON-NLS-1$ | |
78 | private static final String PATH = "path"; //$NON-NLS-1$ | |
79 | private static final String LOCATION = "location"; //$NON-NLS-1$ | |
80 | private static final String FOLDER_SUFFIX = "_exp"; //$NON-NLS-1$ | |
81 | private static final String EXPERIMENT_TYPE = "type"; //$NON-NLS-1$ | |
12ec416d | 82 | private static final String EXPERIMENT_TYPE_ID = "type ID"; //$NON-NLS-1$ |
067cd9de BH |
83 | |
84 | private static final ReadOnlyTextPropertyDescriptor NAME_DESCRIPTOR = new ReadOnlyTextPropertyDescriptor(NAME, NAME); | |
85 | private static final ReadOnlyTextPropertyDescriptor PATH_DESCRIPTOR = new ReadOnlyTextPropertyDescriptor(PATH, PATH); | |
86 | private static final ReadOnlyTextPropertyDescriptor LOCATION_DESCRIPTOR = new ReadOnlyTextPropertyDescriptor(LOCATION, | |
87 | LOCATION); | |
88 | private static final ReadOnlyTextPropertyDescriptor TYPE_DESCRIPTOR = new ReadOnlyTextPropertyDescriptor(EXPERIMENT_TYPE, EXPERIMENT_TYPE); | |
12ec416d | 89 | private static final ReadOnlyTextPropertyDescriptor TYPE_ID_DESCRIPTOR = new ReadOnlyTextPropertyDescriptor(EXPERIMENT_TYPE_ID, EXPERIMENT_TYPE_ID); |
067cd9de BH |
90 | |
91 | private static final IPropertyDescriptor[] DESCRIPTORS = { NAME_DESCRIPTOR, PATH_DESCRIPTOR, | |
12ec416d | 92 | LOCATION_DESCRIPTOR, TYPE_DESCRIPTOR, TYPE_ID_DESCRIPTOR }; |
12c155f5 FC |
93 | |
94 | static { | |
067cd9de BH |
95 | NAME_DESCRIPTOR.setCategory(INFO_CATEGORY); |
96 | PATH_DESCRIPTOR.setCategory(INFO_CATEGORY); | |
97 | LOCATION_DESCRIPTOR.setCategory(INFO_CATEGORY); | |
98 | TYPE_DESCRIPTOR.setCategory(INFO_CATEGORY); | |
12ec416d | 99 | TYPE_ID_DESCRIPTOR.setCategory(INFO_CATEGORY); |
12c155f5 FC |
100 | } |
101 | ||
8f5221c2 GB |
102 | // The mapping of available trace type IDs to their corresponding |
103 | // configuration element | |
067cd9de BH |
104 | private static final Map<String, IConfigurationElement> TRACE_TYPE_ATTRIBUTES = new HashMap<>(); |
105 | private static final Map<String, IConfigurationElement> TRACE_TYPE_UI_ATTRIBUTES = new HashMap<>(); | |
106 | private static final Map<String, IConfigurationElement> TRACE_CATEGORIES = new HashMap<>(); | |
8f5221c2 GB |
107 | |
108 | // ------------------------------------------------------------------------ | |
109 | // Static initialization | |
110 | // ------------------------------------------------------------------------ | |
111 | ||
112 | /** | |
113 | * Initialize statically at startup by getting extensions from the platform | |
114 | * extension registry. | |
8f5221c2 GB |
115 | */ |
116 | public static void init() { | |
117 | IConfigurationElement[] config = Platform.getExtensionRegistry().getConfigurationElementsFor(TmfTraceType.TMF_TRACE_TYPE_ID); | |
118 | for (IConfigurationElement ce : config) { | |
119 | String elementName = ce.getName(); | |
120 | if (elementName.equals(TmfTraceType.EXPERIMENT_ELEM)) { | |
121 | String traceTypeId = ce.getAttribute(TmfTraceType.ID_ATTR); | |
067cd9de | 122 | TRACE_TYPE_ATTRIBUTES.put(traceTypeId, ce); |
8f5221c2 GB |
123 | } else if (elementName.equals(TmfTraceType.CATEGORY_ELEM)) { |
124 | String categoryId = ce.getAttribute(TmfTraceType.ID_ATTR); | |
067cd9de | 125 | TRACE_CATEGORIES.put(categoryId, ce); |
8f5221c2 GB |
126 | } |
127 | } | |
128 | ||
129 | /* | |
130 | * Read the corresponding tmf.ui "tracetypeui" extension point for this | |
131 | * trace type, if it exists. | |
132 | */ | |
133 | config = Platform.getExtensionRegistry().getConfigurationElementsFor(TmfTraceTypeUIUtils.TMF_TRACE_TYPE_UI_ID); | |
134 | for (IConfigurationElement ce : config) { | |
135 | String elemName = ce.getName(); | |
136 | if (TmfTraceTypeUIUtils.EXPERIMENT_ELEM.equals(elemName)) { | |
137 | String traceType = ce.getAttribute(TmfTraceTypeUIUtils.TRACETYPE_ATTR); | |
067cd9de | 138 | TRACE_TYPE_UI_ATTRIBUTES.put(traceType, ce); |
8f5221c2 GB |
139 | } |
140 | } | |
141 | } | |
c4c81d91 | 142 | |
12c155f5 FC |
143 | // ------------------------------------------------------------------------ |
144 | // Constructors | |
145 | // ------------------------------------------------------------------------ | |
b544077e | 146 | /** |
c4c81d91 | 147 | * Constructor |
dc62dbee CB |
148 | * |
149 | * @param name | |
150 | * The name of the experiment | |
151 | * @param folder | |
152 | * The folder reference | |
153 | * @param parent | |
154 | * The experiment folder reference. | |
b544077e | 155 | */ |
12c155f5 FC |
156 | public TmfExperimentElement(String name, IFolder folder, TmfExperimentFolder parent) { |
157 | super(name, folder, parent); | |
12c155f5 FC |
158 | } |
159 | ||
160 | // ------------------------------------------------------------------------ | |
161 | // TmfProjectModelElement | |
162 | // ------------------------------------------------------------------------ | |
163 | ||
164 | @Override | |
165 | public IFolder getResource() { | |
b3e4798c | 166 | return (IFolder) super.getResource(); |
12c155f5 FC |
167 | } |
168 | ||
b3e4798c AM |
169 | /** |
170 | * @since 2.0 | |
171 | */ | |
f537c959 | 172 | @Override |
b3e4798c | 173 | protected void refreshChildren() { |
f537c959 PT |
174 | IFolder folder = getResource(); |
175 | ||
8f5221c2 | 176 | /* Update the trace children of this experiment */ |
f537c959 PT |
177 | // Get the children from the model |
178 | Map<String, ITmfProjectModelElement> childrenMap = new HashMap<>(); | |
339d539c PT |
179 | for (TmfTraceElement trace : getTraces()) { |
180 | childrenMap.put(trace.getElementPath(), trace); | |
f537c959 PT |
181 | } |
182 | ||
339d539c PT |
183 | List<IResource> members = getTraceResources(); |
184 | for (IResource resource : members) { | |
185 | String name = resource.getName(); | |
186 | String elementPath = resource.getFullPath().makeRelativeTo(folder.getFullPath()).toString(); | |
187 | ITmfProjectModelElement element = childrenMap.get(elementPath); | |
188 | if (element instanceof TmfTraceElement) { | |
189 | childrenMap.remove(elementPath); | |
190 | } else { | |
191 | element = new TmfTraceElement(name, resource, this); | |
b3e4798c | 192 | addChild(element); |
f537c959 | 193 | } |
f537c959 PT |
194 | } |
195 | ||
196 | // Cleanup dangling children from the model | |
197 | for (ITmfProjectModelElement danglingChild : childrenMap.values()) { | |
198 | removeChild(danglingChild); | |
199 | } | |
8f5221c2 | 200 | |
8f5221c2 | 201 | /* Update the analysis under this experiment */ |
9928ddeb | 202 | super.refreshChildren(); |
ff7b95a5 GB |
203 | |
204 | /* | |
205 | * If the experiment is opened, add any analysis that was not added by | |
206 | * the parent if it is available with the experiment | |
207 | */ | |
208 | ITmfTrace experiment = getTrace(); | |
209 | if (experiment == null) { | |
210 | return; | |
211 | } | |
5c727157 AM |
212 | |
213 | /* super.refreshChildren() above should have set this */ | |
214 | TmfViewsElement viewsElement = checkNotNull(getChildElementViews()); | |
215 | ||
ff7b95a5 GB |
216 | Map<String, TmfAnalysisElement> analysisMap = new HashMap<>(); |
217 | for (TmfAnalysisElement analysis : getAvailableAnalysis()) { | |
218 | analysisMap.put(analysis.getAnalysisId(), analysis); | |
219 | } | |
220 | for (IAnalysisModuleHelper module : TmfAnalysisManager.getAnalysisModules().values()) { | |
221 | if (!analysisMap.containsKey(module.getId()) && module.appliesToExperiment() && (experiment.getAnalysisModule(module.getId()) != null)) { | |
b3e4798c | 222 | IFolder newresource = ResourcesPlugin.getWorkspace().getRoot().getFolder(getResource().getFullPath().append(module.getId())); |
5c727157 AM |
223 | TmfAnalysisElement analysis = new TmfAnalysisElement(module.getName(), newresource, viewsElement, module); |
224 | viewsElement.addChild(analysis); | |
ff7b95a5 GB |
225 | analysis.refreshChildren(); |
226 | analysisMap.put(module.getId(), analysis); | |
227 | } | |
228 | } | |
f537c959 PT |
229 | } |
230 | ||
339d539c PT |
231 | private List<IResource> getTraceResources() { |
232 | IFolder folder = getResource(); | |
233 | final List<IResource> list = new ArrayList<>(); | |
234 | try { | |
235 | folder.accept(new IResourceProxyVisitor() { | |
236 | @Override | |
237 | public boolean visit(IResourceProxy resource) throws CoreException { | |
238 | if (resource.isLinked()) { | |
239 | list.add(resource.requestResource()); | |
240 | } | |
241 | return true; | |
242 | } | |
243 | }, IResource.NONE); | |
244 | } catch (CoreException e) { | |
245 | } | |
dca8b422 BH |
246 | Comparator<IResource> comparator = new Comparator<IResource>() { |
247 | @Override | |
248 | public int compare(IResource o1, IResource o2) { | |
249 | return o1.getFullPath().toString().compareTo(o2.getFullPath().toString()); | |
250 | } | |
251 | }; | |
252 | Collections.sort(list, comparator); | |
339d539c PT |
253 | return list; |
254 | } | |
255 | ||
dff70ccd AM |
256 | /** |
257 | * @since 2.0 | |
258 | */ | |
259 | @Override | |
260 | public @NonNull Image getIcon() { | |
261 | Image icon = super.getIcon(); | |
262 | return (icon == null ? TmfProjectModelIcons.DEFAULT_EXPERIMENT_ICON : icon); | |
263 | } | |
264 | ||
265 | /** | |
266 | * @since 2.0 | |
267 | */ | |
268 | @Override | |
269 | public String getLabelText() { | |
270 | return getName() + " [" + getTraces().size() + "]"; //$NON-NLS-1$ //$NON-NLS-2$ | |
271 | } | |
272 | ||
12c155f5 FC |
273 | // ------------------------------------------------------------------------ |
274 | // Operations | |
275 | // ------------------------------------------------------------------------ | |
11252342 | 276 | |
8f5221c2 GB |
277 | /** |
278 | * Refreshes the trace type filed by reading the trace type persistent | |
279 | * property of the resource reference. | |
280 | * | |
281 | * If trace type is null after refresh, set it to the generic trace type | |
282 | * (for seamless upgrade) | |
283 | */ | |
284 | @Override | |
285 | public void refreshTraceType() { | |
286 | super.refreshTraceType(); | |
287 | if (getTraceType() == null) { | |
a4a116c3 | 288 | IConfigurationElement ce = TmfTraceType.getTraceAttributes(TmfTraceType.DEFAULT_EXPERIMENT_TYPE); |
8f5221c2 GB |
289 | if (ce != null) { |
290 | try { | |
291 | IFolder experimentFolder = getResource(); | |
292 | experimentFolder.setPersistentProperty(TmfCommonConstants.TRACETYPE, ce.getAttribute(TmfTraceType.ID_ATTR)); | |
293 | super.refreshTraceType(); | |
294 | } catch (InvalidRegistryObjectException | CoreException e) { | |
295 | } | |
296 | } | |
297 | } | |
298 | } | |
299 | ||
b544077e BH |
300 | /** |
301 | * Returns a list of TmfTraceElements contained in this experiment. | |
dc62dbee | 302 | * |
b544077e BH |
303 | * @return a list of TmfTraceElements |
304 | */ | |
8f5221c2 | 305 | @Override |
12c155f5 FC |
306 | public List<TmfTraceElement> getTraces() { |
307 | List<ITmfProjectModelElement> children = getChildren(); | |
507b1336 | 308 | List<TmfTraceElement> traces = new ArrayList<>(); |
12c155f5 FC |
309 | for (ITmfProjectModelElement child : children) { |
310 | if (child instanceof TmfTraceElement) { | |
311 | traces.add((TmfTraceElement) child); | |
312 | } | |
313 | } | |
314 | return traces; | |
315 | } | |
316 | ||
beb19106 GB |
317 | /** |
318 | * Adds a trace to the experiment | |
319 | * | |
dc62dbee CB |
320 | * @param trace |
321 | * The trace element to add | |
beb19106 GB |
322 | */ |
323 | public void addTrace(TmfTraceElement trace) { | |
38dfaec4 BH |
324 | addTrace(trace, true); |
325 | } | |
326 | ||
327 | /** | |
328 | * Adds a trace to the experiment | |
329 | * | |
dc62dbee CB |
330 | * @param trace |
331 | * The trace element to add | |
332 | * @param refresh | |
333 | * Flag for refreshing the project | |
38dfaec4 BH |
334 | */ |
335 | public void addTrace(TmfTraceElement trace, boolean refresh) { | |
beb19106 GB |
336 | /** |
337 | * Create a link to the actual trace and set the trace type | |
338 | */ | |
339 | IFolder experiment = getResource(); | |
340 | IResource resource = trace.getResource(); | |
341 | IPath location = resource.getLocation(); | |
342 | IWorkspace workspace = ResourcesPlugin.getWorkspace(); | |
343 | try { | |
4b3b667b | 344 | String traceTypeId = TmfTraceType.getTraceTypeId(trace.getResource()); |
a4a116c3 | 345 | TraceTypeHelper traceType = TmfTraceType.getTraceType(traceTypeId); |
beb19106 GB |
346 | |
347 | if (resource instanceof IFolder) { | |
339d539c PT |
348 | IFolder folder = experiment.getFolder(trace.getElementPath()); |
349 | TraceUtils.createFolder((IFolder) folder.getParent(), new NullProgressMonitor()); | |
977ca87f PT |
350 | IStatus result = workspace.validateLinkLocation(folder, location); |
351 | if (result.isOK() || result.matches(IStatus.INFO | IStatus.WARNING)) { | |
beb19106 | 352 | folder.createLink(location, IResource.REPLACE, null); |
5f398902 | 353 | if (traceType != null) { |
38dfaec4 | 354 | TmfTraceTypeUIUtils.setTraceType(folder, traceType, refresh); |
5f398902 | 355 | } |
beb19106 GB |
356 | |
357 | } else { | |
358 | Activator.getDefault().logError("Error creating link. Invalid trace location " + location); //$NON-NLS-1$ | |
359 | } | |
360 | } else { | |
339d539c PT |
361 | IFile file = experiment.getFile(trace.getElementPath()); |
362 | TraceUtils.createFolder((IFolder) file.getParent(), new NullProgressMonitor()); | |
977ca87f PT |
363 | IStatus result = workspace.validateLinkLocation(file, location); |
364 | if (result.isOK() || result.matches(IStatus.INFO | IStatus.WARNING)) { | |
beb19106 | 365 | file.createLink(location, IResource.REPLACE, null); |
5f398902 | 366 | if (traceType != null) { |
38dfaec4 | 367 | TmfTraceTypeUIUtils.setTraceType(file, traceType, refresh); |
5f398902 | 368 | } |
beb19106 GB |
369 | } else { |
370 | Activator.getDefault().logError("Error creating link. Invalid trace location " + location); //$NON-NLS-1$ | |
371 | } | |
372 | } | |
373 | } catch (CoreException e) { | |
374 | Activator.getDefault().logError("Error creating link to location " + location, e); //$NON-NLS-1$ | |
375 | } | |
376 | ||
377 | } | |
378 | ||
379 | /** | |
380 | * Removes a trace from an experiment | |
381 | * | |
dc62dbee CB |
382 | * @param trace |
383 | * The trace to remove | |
384 | * @throws CoreException | |
385 | * exception | |
beb19106 GB |
386 | */ |
387 | public void removeTrace(TmfTraceElement trace) throws CoreException { | |
388 | ||
ea01e5a2 PT |
389 | // Close editors in UI Thread |
390 | Display.getDefault().syncExec(new Runnable() { | |
391 | @Override | |
392 | public void run() { | |
393 | closeEditors(); | |
394 | } | |
395 | }); | |
beb19106 | 396 | |
dc62dbee | 397 | /* Finally, remove the trace from experiment */ |
beb19106 | 398 | removeChild(trace); |
339d539c | 399 | deleteTraceResource(trace.getResource()); |
d9030b38 | 400 | deleteSupplementaryResources(); |
beb19106 GB |
401 | } |
402 | ||
339d539c PT |
403 | private void deleteTraceResource(IResource resource) throws CoreException { |
404 | resource.delete(true, null); | |
405 | IContainer parent = resource.getParent(); | |
406 | // delete empty folders up to the parent experiment folder | |
407 | if (!parent.equals(getResource()) && parent.members().length == 0) { | |
408 | deleteTraceResource(parent); | |
409 | } | |
410 | } | |
411 | ||
8f5221c2 | 412 | @Override |
81fe3479 | 413 | public IFile createBookmarksFile() throws CoreException { |
58ffe079 | 414 | return createBookmarksFile(getProject().getExperimentsFolder().getResource(), ITmfEventsEditorConstants.EXPERIMENT_EDITOR_INPUT_TYPE); |
8f5221c2 GB |
415 | } |
416 | ||
417 | @Override | |
418 | public String getEditorId() { | |
419 | /* See if a default editor was set for this experiment type */ | |
420 | if (getTraceType() != null) { | |
067cd9de | 421 | IConfigurationElement ce = TRACE_TYPE_UI_ATTRIBUTES.get(getTraceType()); |
c1c0dfd0 GB |
422 | if (ce != null) { |
423 | IConfigurationElement[] defaultEditorCE = ce.getChildren(TmfTraceTypeUIUtils.DEFAULT_EDITOR_ELEM); | |
424 | if (defaultEditorCE.length == 1) { | |
425 | return defaultEditorCE[0].getAttribute(TmfTraceType.ID_ATTR); | |
426 | } | |
81fe3479 | 427 | } |
c4c81d91 | 428 | } |
8f5221c2 GB |
429 | |
430 | /* No default editor, try to find a common editor for all traces */ | |
431 | final List<TmfTraceElement> traceEntries = getTraces(); | |
432 | String commonEditorId = null; | |
433 | ||
434 | for (TmfTraceElement element : traceEntries) { | |
435 | // If all traces use the same editorId, use it, otherwise use the | |
436 | // default | |
437 | final String editorId = element.getEditorId(); | |
438 | if (commonEditorId == null) { | |
439 | commonEditorId = (editorId != null) ? editorId : TmfEventsEditor.ID; | |
440 | } else if (!commonEditorId.equals(editorId)) { | |
441 | commonEditorId = TmfEventsEditor.ID; | |
442 | } | |
443 | } | |
444 | return null; | |
81fe3479 PT |
445 | } |
446 | ||
447 | /** | |
8f5221c2 GB |
448 | * Instantiate a {@link TmfExperiment} object based on the experiment type |
449 | * and the corresponding extension. | |
450 | * | |
451 | * @return the {@link TmfExperiment} or <code>null</code> for an error | |
81fe3479 | 452 | */ |
8f5221c2 GB |
453 | @Override |
454 | public TmfExperiment instantiateTrace() { | |
455 | try { | |
456 | ||
457 | // make sure that supplementary folder exists | |
458 | refreshSupplementaryFolder(); | |
459 | ||
460 | if (getTraceType() != null) { | |
461 | ||
067cd9de | 462 | IConfigurationElement ce = TRACE_TYPE_ATTRIBUTES.get(getTraceType()); |
8f5221c2 GB |
463 | if (ce == null) { |
464 | return null; | |
465 | } | |
466 | TmfExperiment experiment = (TmfExperiment) ce.createExecutableExtension(TmfTraceType.EXPERIMENT_TYPE_ATTR); | |
467 | return experiment; | |
468 | } | |
469 | } catch (CoreException e) { | |
470 | Activator.getDefault().logError(NLS.bind(Messages.TmfExperimentElement_ErrorInstantiatingTrace, getName()), e); | |
471 | } | |
472 | return null; | |
473 | } | |
474 | ||
475 | @Override | |
476 | public String getTypeName() { | |
477 | return Messages.TmfExperimentElement_TypeName; | |
c4c81d91 PT |
478 | } |
479 | ||
12c155f5 FC |
480 | // ------------------------------------------------------------------------ |
481 | // IPropertySource2 | |
482 | // ------------------------------------------------------------------------ | |
483 | ||
484 | @Override | |
485 | public Object getEditableValue() { | |
486 | return null; | |
487 | } | |
488 | ||
489 | @Override | |
490 | public IPropertyDescriptor[] getPropertyDescriptors() { | |
067cd9de | 491 | return Arrays.copyOf(DESCRIPTORS, DESCRIPTORS.length); |
12c155f5 FC |
492 | } |
493 | ||
494 | @Override | |
495 | public Object getPropertyValue(Object id) { | |
496 | ||
067cd9de | 497 | if (NAME.equals(id)) { |
12c155f5 | 498 | return getName(); |
c4c81d91 | 499 | } |
12c155f5 | 500 | |
067cd9de | 501 | if (PATH.equals(id)) { |
12c155f5 | 502 | return getPath().toString(); |
c4c81d91 | 503 | } |
12c155f5 | 504 | |
067cd9de | 505 | if (LOCATION.equals(id)) { |
12c155f5 | 506 | return getLocation().toString(); |
c4c81d91 | 507 | } |
12c155f5 | 508 | |
067cd9de | 509 | if (EXPERIMENT_TYPE.equals(id)) { |
8f5221c2 | 510 | if (getTraceType() != null) { |
067cd9de | 511 | IConfigurationElement ce = TRACE_TYPE_ATTRIBUTES.get(getTraceType()); |
8f5221c2 GB |
512 | if (ce == null) { |
513 | return ""; //$NON-NLS-1$ | |
514 | } | |
515 | String categoryId = ce.getAttribute(TmfTraceType.CATEGORY_ATTR); | |
516 | if (categoryId != null) { | |
067cd9de | 517 | IConfigurationElement category = TRACE_CATEGORIES.get(categoryId); |
8f5221c2 GB |
518 | if (category != null) { |
519 | return category.getAttribute(TmfTraceType.NAME_ATTR) + ':' + ce.getAttribute(TmfTraceType.NAME_ATTR); | |
520 | } | |
521 | } | |
522 | return ce.getAttribute(TmfTraceType.NAME_ATTR); | |
523 | } | |
524 | } | |
12ec416d BH |
525 | if (EXPERIMENT_TYPE_ID.equals(id)) { |
526 | if (getTraceType() != null) { | |
527 | IConfigurationElement ce = TRACE_TYPE_ATTRIBUTES.get(getTraceType()); | |
528 | if (ce == null) { | |
529 | return ""; //$NON-NLS-1$ | |
530 | } | |
531 | return ce.getAttribute(TmfTraceType.ID_ATTR); | |
532 | } | |
533 | } | |
8f5221c2 | 534 | |
12c155f5 FC |
535 | return null; |
536 | } | |
c4c81d91 | 537 | |
12c155f5 FC |
538 | @Override |
539 | public void resetPropertyValue(Object id) { | |
540 | } | |
541 | ||
542 | @Override | |
543 | public void setPropertyValue(Object id, Object value) { | |
544 | } | |
545 | ||
546 | @Override | |
547 | public boolean isPropertyResettable(Object id) { | |
548 | return false; | |
549 | } | |
550 | ||
551 | @Override | |
552 | public boolean isPropertySet(Object id) { | |
553 | return false; | |
554 | } | |
555 | ||
99504bb8 GB |
556 | /** |
557 | * Return the suffix for resource names | |
dc62dbee | 558 | * |
99504bb8 GB |
559 | * @return The folder suffix |
560 | */ | |
561 | @Override | |
562 | public String getSuffix() { | |
067cd9de | 563 | return FOLDER_SUFFIX; |
99504bb8 GB |
564 | } |
565 | ||
12c155f5 | 566 | } |