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