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