~ubuntu-branches/ubuntu/vivid/eclipse-linuxtools/vivid-proposed

« back to all changes in this revision

Viewing changes to lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfTraceElement.java

  • Committer: Package Import Robot
  • Author(s): Jakub Adam, Jakub Adam, tony mancill
  • Date: 2014-10-11 11:44:05 UTC
  • mfrom: (1.2.4)
  • Revision ID: package-import@ubuntu.com-20141011114405-yazjvxfzzhmi5sgj
Tags: 3.1.0-1
[ Jakub Adam ]
* New upstream release (Closes: #761524).
* Refreshed d/patches.
* Don't build removed feature org.eclipse.linuxtools.tools.launch
  - merged into org.eclipse.linuxtools.profiling.
* Use javac target 1.7.
* Build new feature org.eclipse.linuxtools.dataviewers.feature
  - required by Valgrind integration.
* Build-depend on eclipse-remote-services-api and eclipse-cdt-autotools.
* Bump Standards-Version to 3.9.6.
* Override incompatible-java-bytecode-format - linuxtools needs Java 7.
* Remove unused codeless-jar override.

[ tony mancill ]
* Tweak short package description to make lintian happy.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*******************************************************************************
2
 
 * Copyright (c) 2010, 2013 Ericsson, École Polytechnique de Montréal
 
2
 * Copyright (c) 2010, 2014 Ericsson, École Polytechnique de Montréal
3
3
 *
4
4
 * All rights reserved. This program and the accompanying materials are
5
5
 * made available under the terms of the Eclipse Public License v1.0 which
14
14
 *   Patrick Tasse - Close editors to release resources
15
15
 *   Jean-Christian Kouame - added trace properties to be shown into
16
16
 *                           the properties view
 
17
 *   Geneviève Bastien - Moved trace type related methods to parent class
17
18
 *******************************************************************************/
18
19
 
19
20
package org.eclipse.linuxtools.tmf.ui.project.model;
20
21
 
21
 
import java.io.ByteArrayInputStream;
22
 
import java.io.InputStream;
23
22
import java.util.Arrays;
24
23
import java.util.HashMap;
25
24
import java.util.LinkedList;
34
33
import org.eclipse.core.runtime.IPath;
35
34
import org.eclipse.core.runtime.IProgressMonitor;
36
35
import org.eclipse.core.runtime.Platform;
 
36
import org.eclipse.core.runtime.URIUtil;
37
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
38
import org.eclipse.linuxtools.tmf.core.TmfCommonConstants;
45
39
import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
 
40
import org.eclipse.linuxtools.tmf.core.parsers.custom.CustomTxtEvent;
 
41
import org.eclipse.linuxtools.tmf.core.parsers.custom.CustomTxtTrace;
 
42
import org.eclipse.linuxtools.tmf.core.parsers.custom.CustomTxtTraceDefinition;
 
43
import org.eclipse.linuxtools.tmf.core.parsers.custom.CustomXmlEvent;
 
44
import org.eclipse.linuxtools.tmf.core.parsers.custom.CustomXmlTrace;
 
45
import org.eclipse.linuxtools.tmf.core.parsers.custom.CustomXmlTraceDefinition;
 
46
import org.eclipse.linuxtools.tmf.core.project.model.TmfTraceType;
 
47
import org.eclipse.linuxtools.tmf.core.project.model.TraceTypeHelper;
46
48
import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
47
49
import org.eclipse.linuxtools.tmf.core.trace.ITmfTraceProperties;
48
50
import org.eclipse.linuxtools.tmf.core.trace.TmfTrace;
50
52
import org.eclipse.linuxtools.tmf.ui.editors.TmfEventsEditor;
51
53
import org.eclipse.linuxtools.tmf.ui.properties.ReadOnlyTextPropertyDescriptor;
52
54
import org.eclipse.ui.IActionFilter;
53
 
import org.eclipse.ui.IEditorReference;
54
 
import org.eclipse.ui.IWorkbench;
55
 
import org.eclipse.ui.IWorkbenchPage;
56
 
import org.eclipse.ui.IWorkbenchWindow;
57
 
import org.eclipse.ui.PartInitException;
58
 
import org.eclipse.ui.PlatformUI;
59
 
import org.eclipse.ui.part.FileEditorInput;
60
55
import org.eclipse.ui.views.properties.IPropertyDescriptor;
61
56
import org.eclipse.ui.views.properties.IPropertySource2;
62
57
 
68
63
 * @version 1.0
69
64
 * @author Francois Chouinard
70
65
 */
71
 
public class TmfTraceElement extends TmfWithFolderElement implements IActionFilter, IPropertySource2 {
 
66
public class TmfTraceElement extends TmfCommonProjectElement implements IActionFilter, IPropertySource2 {
72
67
 
73
68
    // ------------------------------------------------------------------------
74
69
    // Constants
89
84
    private static final String sfName = Messages.TmfTraceElement_Name;
90
85
    private static final String sfPath = Messages.TmfTraceElement_Path;
91
86
    private static final String sfLocation = Messages.TmfTraceElement_Location;
92
 
    private static final String sfEventType = Messages.TmfTraceElement_EventType;
 
87
    private static final String sfTraceType = Messages.TmfTraceElement_EventType;
93
88
    private static final String sfIsLinked = Messages.TmfTraceElement_IsLinked;
 
89
    private static final String sfSourceLocation = Messages.TmfTraceElement_SourceLocation;
94
90
    private static final String sfTracePropertiesCategory = Messages.TmfTraceElement_TraceProperties;
95
91
 
96
92
    private static final ReadOnlyTextPropertyDescriptor sfNameDescriptor = new ReadOnlyTextPropertyDescriptor(sfName, sfName);
97
93
    private static final ReadOnlyTextPropertyDescriptor sfPathDescriptor = new ReadOnlyTextPropertyDescriptor(sfPath, sfPath);
98
94
    private static final ReadOnlyTextPropertyDescriptor sfLocationDescriptor = new ReadOnlyTextPropertyDescriptor(sfLocation, sfLocation);
99
 
    private static final ReadOnlyTextPropertyDescriptor sfTypeDescriptor = new ReadOnlyTextPropertyDescriptor(sfEventType, sfEventType);
 
95
    private static final ReadOnlyTextPropertyDescriptor sfTypeDescriptor = new ReadOnlyTextPropertyDescriptor(sfTraceType, sfTraceType);
100
96
    private static final ReadOnlyTextPropertyDescriptor sfIsLinkedDescriptor = new ReadOnlyTextPropertyDescriptor(sfIsLinked, sfIsLinked);
 
97
    private static final ReadOnlyTextPropertyDescriptor sfSourceLocationDescriptor = new ReadOnlyTextPropertyDescriptor(sfSourceLocation, sfSourceLocation);
101
98
 
102
99
    private static final IPropertyDescriptor[] sfDescriptors = { sfNameDescriptor, sfPathDescriptor, sfLocationDescriptor,
103
 
            sfTypeDescriptor, sfIsLinkedDescriptor };
 
100
            sfTypeDescriptor, sfIsLinkedDescriptor, sfSourceLocationDescriptor };
104
101
 
105
102
    static {
106
103
        sfNameDescriptor.setCategory(sfResourcePropertiesCategory);
108
105
        sfLocationDescriptor.setCategory(sfResourcePropertiesCategory);
109
106
        sfTypeDescriptor.setCategory(sfResourcePropertiesCategory);
110
107
        sfIsLinkedDescriptor.setCategory(sfResourcePropertiesCategory);
 
108
        sfSourceLocationDescriptor.setCategory(sfResourcePropertiesCategory);
111
109
    }
112
110
 
113
 
    private static final String BOOKMARKS_HIDDEN_FILE = ".bookmarks"; //$NON-NLS-1$
114
 
 
115
 
    // ------------------------------------------------------------------------
116
 
    // Attributes
117
 
    // ------------------------------------------------------------------------
118
 
 
119
 
    // This trace type ID as defined in plugin.xml
120
 
    private String fTraceTypeId = null;
121
 
 
122
111
    // ------------------------------------------------------------------------
123
112
    // Static initialization
124
113
    // ------------------------------------------------------------------------
125
114
 
126
115
    // The mapping of available trace type IDs to their corresponding
127
116
    // configuration element
128
 
    private static final Map<String, IConfigurationElement> sfTraceTypeAttributes = new HashMap<String, IConfigurationElement>();
129
 
    private static final Map<String, IConfigurationElement> sfTraceCategories = new HashMap<String, IConfigurationElement>();
 
117
    private static final Map<String, IConfigurationElement> sfTraceTypeAttributes = new HashMap<>();
 
118
    private static final Map<String, IConfigurationElement> sfTraceTypeUIAttributes = new HashMap<>();
 
119
    private static final Map<String, IConfigurationElement> sfTraceCategories = new HashMap<>();
130
120
 
131
121
    /**
132
122
     * Initialize statically at startup by getting extensions from the platform
133
123
     * extension registry.
134
124
     */
135
125
    public static void init() {
 
126
        /* Read the tmf.core "tracetype" extension point */
136
127
        IConfigurationElement[] config = Platform.getExtensionRegistry().getConfigurationElementsFor(TmfTraceType.TMF_TRACE_TYPE_ID);
137
128
        for (IConfigurationElement ce : config) {
138
 
            String elementName = ce.getName();
139
 
            if (elementName.equals(TmfTraceType.TYPE_ELEM)) {
 
129
            switch (ce.getName()) {
 
130
            case TmfTraceType.TYPE_ELEM:
140
131
                String traceTypeId = ce.getAttribute(TmfTraceType.ID_ATTR);
141
132
                sfTraceTypeAttributes.put(traceTypeId, ce);
142
 
            } else if (elementName.equals(TmfTraceType.CATEGORY_ELEM)) {
 
133
                break;
 
134
            case TmfTraceType.CATEGORY_ELEM:
143
135
                String categoryId = ce.getAttribute(TmfTraceType.ID_ATTR);
144
136
                sfTraceCategories.put(categoryId, ce);
 
137
                break;
 
138
            default:
 
139
            }
 
140
        }
 
141
 
 
142
        /*
 
143
         * Read the corresponding tmf.ui "tracetypeui" extension point for this
 
144
         * trace type, if it exists.
 
145
         */
 
146
        config = Platform.getExtensionRegistry().getConfigurationElementsFor(TmfTraceTypeUIUtils.TMF_TRACE_TYPE_UI_ID);
 
147
        for (IConfigurationElement ce : config) {
 
148
            String elemName = ce.getName();
 
149
            if (TmfTraceTypeUIUtils.TYPE_ELEM.equals(elemName)) {
 
150
                String traceType = ce.getAttribute(TmfTraceTypeUIUtils.TRACETYPE_ATTR);
 
151
                sfTraceTypeUIAttributes.put(traceType, ce);
145
152
            }
146
153
        }
147
154
    }
160
167
     *            The parent element (trace folder)
161
168
     */
162
169
    public TmfTraceElement(String name, IResource trace, TmfTraceFolder parent) {
163
 
        this(name, trace, (TmfProjectModelElement) parent);
 
170
        super(name, trace, parent);
164
171
    }
165
172
 
166
173
    /**
174
181
     *            The parent element (experiment folder)
175
182
     */
176
183
    public TmfTraceElement(String name, IResource trace, TmfExperimentElement parent) {
177
 
        this(name, trace, (TmfProjectModelElement) parent);
178
 
    }
179
 
 
180
 
    private TmfTraceElement(String name, IResource trace, TmfProjectModelElement parent) {
181
184
        super(name, trace, parent);
182
 
        parent.addChild(this);
183
 
        refreshTraceType();
184
185
    }
185
186
 
186
187
    // ------------------------------------------------------------------------
187
188
    // Operations
188
189
    // ------------------------------------------------------------------------
189
 
    /**
190
 
     * Returns the trace type ID.
191
 
     *
192
 
     * @return trace type ID.
193
 
     */
194
 
    public String getTraceType() {
195
 
        return fTraceTypeId;
196
 
    }
197
 
 
198
 
    /**
199
 
     * Refreshes the trace type filed by reading the trace type persistent
200
 
     * property of the resource referenece.
201
 
     */
202
 
    public void refreshTraceType() {
203
 
        try {
204
 
            fTraceTypeId = getResource().getPersistentProperty(TmfCommonConstants.TRACETYPE);
205
 
        } catch (CoreException e) {
206
 
            Activator.getDefault().logError("Error refreshing trace type pesistent property for trace " + getName(), e); //$NON-NLS-1$
207
 
        }
208
 
    }
209
190
 
210
191
    /**
211
192
     * Instantiate a <code>ITmfTrace</code> object based on the trace type and
213
194
     *
214
195
     * @return the <code>ITmfTrace</code> or <code>null</code> for an error
215
196
     */
 
197
    @Override
216
198
    public ITmfTrace instantiateTrace() {
217
199
        try {
218
200
 
219
201
            // make sure that supplementary folder exists
220
202
            refreshSupplementaryFolder();
221
203
 
222
 
            if (fTraceTypeId != null) {
223
 
                if (fTraceTypeId.startsWith(CustomTxtTrace.class.getCanonicalName())) {
 
204
            if (getTraceType() != null) {
 
205
                if (getTraceType().startsWith(CustomTxtTrace.class.getCanonicalName())) {
224
206
                    for (CustomTxtTraceDefinition def : CustomTxtTraceDefinition.loadAll()) {
225
 
                        if (fTraceTypeId.equals(CustomTxtTrace.class.getCanonicalName() + ":" + def.definitionName)) { //$NON-NLS-1$
 
207
                        if (getTraceType().equals(CustomTxtTrace.class.getCanonicalName() + ":" + def.definitionName)) { //$NON-NLS-1$
226
208
                            return new CustomTxtTrace(def);
227
209
                        }
228
210
                    }
229
211
                }
230
 
                if (fTraceTypeId.startsWith(CustomXmlTrace.class.getCanonicalName())) {
 
212
                if (getTraceType().startsWith(CustomXmlTrace.class.getCanonicalName())) {
231
213
                    for (CustomXmlTraceDefinition def : CustomXmlTraceDefinition.loadAll()) {
232
 
                        if (fTraceTypeId.equals(CustomXmlTrace.class.getCanonicalName() + ":" + def.definitionName)) { //$NON-NLS-1$
 
214
                        if (getTraceType().equals(CustomXmlTrace.class.getCanonicalName() + ":" + def.definitionName)) { //$NON-NLS-1$
233
215
                            return new CustomXmlTrace(def);
234
216
                        }
235
217
                    }
236
218
                }
237
 
                IConfigurationElement ce = sfTraceTypeAttributes.get(fTraceTypeId);
 
219
                IConfigurationElement ce = sfTraceTypeAttributes.get(getTraceType());
238
220
                if (ce == null) {
239
221
                    return null;
240
222
                }
255
237
     */
256
238
    public ITmfEvent instantiateEvent() {
257
239
        try {
258
 
            if (fTraceTypeId != null) {
259
 
                if (fTraceTypeId.startsWith(CustomTxtTrace.class.getCanonicalName())) {
 
240
            if (getTraceType() != null) {
 
241
                if (getTraceType().startsWith(CustomTxtTrace.class.getCanonicalName())) {
260
242
                    for (CustomTxtTraceDefinition def : CustomTxtTraceDefinition.loadAll()) {
261
 
                        if (fTraceTypeId.equals(CustomTxtTrace.class.getCanonicalName() + ":" + def.definitionName)) { //$NON-NLS-1$
 
243
                        if (getTraceType().equals(CustomTxtTrace.class.getCanonicalName() + ":" + def.definitionName)) { //$NON-NLS-1$
262
244
                            return new CustomTxtEvent(def);
263
245
                        }
264
246
                    }
265
247
                }
266
 
                if (fTraceTypeId.startsWith(CustomXmlTrace.class.getCanonicalName())) {
 
248
                if (getTraceType().startsWith(CustomXmlTrace.class.getCanonicalName())) {
267
249
                    for (CustomXmlTraceDefinition def : CustomXmlTraceDefinition.loadAll()) {
268
 
                        if (fTraceTypeId.equals(CustomXmlTrace.class.getCanonicalName() + ":" + def.definitionName)) { //$NON-NLS-1$
 
250
                        if (getTraceType().equals(CustomXmlTrace.class.getCanonicalName() + ":" + def.definitionName)) { //$NON-NLS-1$
269
251
                            return new CustomXmlEvent(def);
270
252
                        }
271
253
                    }
272
254
                }
273
 
                IConfigurationElement ce = sfTraceTypeAttributes.get(fTraceTypeId);
 
255
                IConfigurationElement ce = sfTraceTypeAttributes.get(getTraceType());
274
256
                if (ce == null) {
275
257
                    return null;
276
258
                }
283
265
        return null;
284
266
    }
285
267
 
286
 
    /**
287
 
     * Returns the optional editor ID from the trace type extension.
288
 
     *
289
 
     * @return the editor ID or <code>null</code> if not defined.
290
 
     */
 
268
    @Override
291
269
    public String getEditorId() {
292
 
        if (fTraceTypeId != null) {
293
 
            if (fTraceTypeId.startsWith(CustomTxtTrace.class.getCanonicalName())) {
294
 
                return TmfEventsEditor.ID;
295
 
            }
296
 
            if (fTraceTypeId.startsWith(CustomXmlTrace.class.getCanonicalName())) {
297
 
                return TmfEventsEditor.ID;
298
 
            }
299
 
            IConfigurationElement ce = sfTraceTypeAttributes.get(fTraceTypeId);
300
 
            IConfigurationElement[] defaultEditorCE = ce.getChildren(TmfTraceType.DEFAULT_EDITOR_ELEM);
 
270
        if (getTraceType() != null) {
 
271
            if (getTraceType().startsWith(CustomTxtTrace.class.getCanonicalName())) {
 
272
                return TmfEventsEditor.ID;
 
273
            }
 
274
            if (getTraceType().startsWith(CustomXmlTrace.class.getCanonicalName())) {
 
275
                return TmfEventsEditor.ID;
 
276
            }
 
277
            IConfigurationElement ce = sfTraceTypeUIAttributes.get(getTraceType());
 
278
            if (ce == null) {
 
279
                /* This trace type does not define UI attributes */
 
280
                return null;
 
281
            }
 
282
            IConfigurationElement[] defaultEditorCE = ce.getChildren(TmfTraceTypeUIUtils.DEFAULT_EDITOR_ELEM);
301
283
            if (defaultEditorCE.length == 1) {
302
284
                return defaultEditorCE[0].getAttribute(TmfTraceType.ID_ATTR);
303
285
            }
316
298
     *             if the bookmarks file cannot be created
317
299
     * @since 2.0
318
300
     */
 
301
    @Override
319
302
    public IFile createBookmarksFile() throws CoreException {
320
303
        IFile file = getBookmarksFile();
321
304
        if (fResource instanceof IFolder) {
322
 
            if (!file.exists()) {
323
 
                final IFile bookmarksFile = getProject().getTracesFolder().getResource().getFile(BOOKMARKS_HIDDEN_FILE);
324
 
                if (!bookmarksFile.exists()) {
325
 
                    final InputStream source = new ByteArrayInputStream(new byte[0]);
326
 
                    bookmarksFile.create(source, true, null);
327
 
                }
328
 
                bookmarksFile.setHidden(true);
329
 
                file.createLink(bookmarksFile.getLocation(), IResource.REPLACE, null);
330
 
                file.setHidden(true);
331
 
                file.setPersistentProperty(TmfCommonConstants.TRACETYPE, TmfTrace.class.getCanonicalName());
332
 
            }
 
305
            return createBookmarksFile(getProject().getTracesFolder().getResource(), TmfTrace.class.getCanonicalName());
333
306
        }
334
307
        return file;
335
308
    }
341
314
     * @return the bookmarks file
342
315
     * @since 2.0
343
316
     */
 
317
    @Override
344
318
    public IFile getBookmarksFile() {
345
319
        IFile file = null;
346
320
        if (fResource instanceof IFile) {
367
341
        // traces folder
368
342
        if (getParent() instanceof TmfExperimentElement) {
369
343
            for (TmfTraceElement aTrace : getProject().getTracesFolder().getTraces()) {
370
 
                if (aTrace.getName().equals(getName())) {
 
344
                if (aTrace.getElementPath().equals(getElementPath())) {
371
345
                    return aTrace;
372
346
                }
373
347
            }
375
349
        return this;
376
350
    }
377
351
 
 
352
    @Override
 
353
    public String getTypeName() {
 
354
        return Messages.TmfTraceElement_TypeName;
 
355
    }
 
356
 
378
357
    // ------------------------------------------------------------------------
379
358
    // IActionFilter
380
359
    // ------------------------------------------------------------------------
389
368
    }
390
369
 
391
370
    // ------------------------------------------------------------------------
392
 
    // TmfTraceElement
393
 
    // ------------------------------------------------------------------------
394
 
 
395
 
    @Override
396
 
    public TmfProjectElement getProject() {
397
 
        if (getParent() instanceof TmfTraceFolder) {
398
 
            TmfTraceFolder folder = (TmfTraceFolder) getParent();
399
 
            TmfProjectElement project = (TmfProjectElement) folder.getParent();
400
 
            return project;
401
 
        }
402
 
        if (getParent() instanceof TmfExperimentElement) {
403
 
            TmfExperimentElement experiment = (TmfExperimentElement) getParent();
404
 
            TmfExperimentFolder folder = (TmfExperimentFolder) experiment.getParent();
405
 
            TmfProjectElement project = (TmfProjectElement) folder.getParent();
406
 
            return project;
407
 
        }
408
 
        return null;
409
 
    }
410
 
 
411
 
    // ------------------------------------------------------------------------
412
371
    // IPropertySource2
413
372
    // ------------------------------------------------------------------------
414
373
 
427
386
    private Map<String, String> getTraceProperties() {
428
387
        for (ITmfTrace openedTrace : TmfTraceManager.getInstance().getOpenedTraces()) {
429
388
            for (ITmfTrace singleTrace : TmfTraceManager.getTraceSet(openedTrace)) {
430
 
                if (this.getLocation().toString().endsWith(singleTrace.getPath())) {
 
389
                if (this.getLocation().getPath().endsWith(singleTrace.getPath())) {
431
390
                    if (singleTrace instanceof ITmfTraceProperties) {
432
391
                        ITmfTraceProperties traceProperties = (ITmfTraceProperties) singleTrace;
433
392
                        return traceProperties.getTraceProperties();
435
394
                }
436
395
            }
437
396
        }
438
 
        return new HashMap<String, String>();
 
397
        return new HashMap<>();
439
398
    }
440
399
 
441
400
    @Override
471
430
        }
472
431
 
473
432
        if (sfLocation.equals(id)) {
474
 
            return getLocation().toString();
 
433
            return URIUtil.toUnencodedString(getLocation());
475
434
        }
476
435
 
477
436
        if (sfIsLinked.equals(id)) {
478
437
            return Boolean.valueOf(getResource().isLinked()).toString();
479
438
        }
480
439
 
481
 
        if (sfEventType.equals(id)) {
482
 
            if (fTraceTypeId != null) {
483
 
                IConfigurationElement ce = sfTraceTypeAttributes.get(fTraceTypeId);
484
 
                return (ce != null) ? (getCategory(ce) + " : " + ce.getAttribute(TmfTraceType.NAME_ATTR)) : ""; //$NON-NLS-1$ //$NON-NLS-2$
485
 
            }
 
440
        if (sfSourceLocation.equals(id)) {
 
441
            try {
 
442
                String sourceLocation = getElementUnderTraceFolder().getResource().getPersistentProperty(TmfCommonConstants.SOURCE_LOCATION);
 
443
                if (sourceLocation != null) {
 
444
                    return sourceLocation;
 
445
                }
 
446
            } catch (CoreException e) {
 
447
            }
 
448
            return ""; //$NON-NLS-1$
 
449
        }
 
450
 
 
451
        if (sfTraceType.equals(id)) {
 
452
            if (getTraceType() != null) {
 
453
                TraceTypeHelper helper = TmfTraceType.getTraceTypeHelper(getTraceType());
 
454
                if (helper != null) {
 
455
                    return helper.getCategoryName() + " : " + helper.getName(); //$NON-NLS-1$
 
456
                }
 
457
            }
 
458
            return ""; //$NON-NLS-1$
486
459
        }
487
460
 
488
461
        Map<String, String> traceProperties = getTraceProperties();
489
462
        if (id != null && !traceProperties.isEmpty()) {
490
463
            String key = (String) id;
491
 
            key = key.replaceFirst(this.getName() + "_", ""); //$NON-NLS-1$ //$NON-NLS-2$
 
464
            key = key.substring(this.getName().length() + 1); // remove name_
492
465
            String value = traceProperties.get(key);
493
466
            return value;
494
467
        }
496
469
        return null;
497
470
    }
498
471
 
499
 
    private static String getCategory(IConfigurationElement ce) {
500
 
        String categoryId = ce.getAttribute(TmfTraceType.CATEGORY_ATTR);
501
 
        if (categoryId != null) {
502
 
            IConfigurationElement category = sfTraceCategories.get(categoryId);
503
 
            if (category != null) {
504
 
                return category.getAttribute(TmfTraceType.NAME_ATTR);
505
 
            }
506
 
        }
507
 
        return "[no category]"; //$NON-NLS-1$
508
 
    }
509
 
 
510
472
    @Override
511
473
    public void resetPropertyValue(Object id) {
512
474
    }
529
491
     * Copy this trace in the trace folder. No other parameters are mentioned so
530
492
     * the trace is copied in this element's project trace folder
531
493
     *
532
 
     * @param string
 
494
     * @param newName
533
495
     *            The new trace name
534
496
     * @return the new Resource object
535
497
     * @since 2.0
536
498
     */
537
 
    public TmfTraceElement copy(String string) {
538
 
        TmfTraceFolder folder = this.getProject().getTracesFolder();
539
 
        IResource res = super.copy(string, false);
540
 
        return new TmfTraceElement(string, res, folder);
 
499
    public TmfTraceElement copy(String newName) {
 
500
        TmfTraceFolder folder = (TmfTraceFolder) getParent();
 
501
        IResource res = super.copy(newName, false);
 
502
        for (TmfTraceElement trace : folder.getTraces()) {
 
503
            if (trace.getResource().equals(res)) {
 
504
                return trace;
 
505
            }
 
506
        }
 
507
        return null;
541
508
    }
542
509
 
543
510
    /**
545
512
     *
546
513
     * @since 2.0
547
514
     */
 
515
    @Override
548
516
    public void closeEditors() {
549
 
        // Close the trace if open
550
 
        IFile file = getBookmarksFile();
551
 
        FileEditorInput input = new FileEditorInput(file);
552
 
        IWorkbench wb = PlatformUI.getWorkbench();
553
 
        for (IWorkbenchWindow wbWindow : wb.getWorkbenchWindows()) {
554
 
            for (IWorkbenchPage wbPage : wbWindow.getPages()) {
555
 
                for (IEditorReference editorReference : wbPage.getEditorReferences()) {
556
 
                    try {
557
 
                        if (editorReference.getEditorInput().equals(input)) {
558
 
                            wbPage.closeEditor(editorReference.getEditor(false), false);
559
 
                        }
560
 
                    } catch (PartInitException e) {
561
 
                        Activator.getDefault().logError("Error closing editor for trace " + getName(), e); //$NON-NLS-1$
562
 
                    }
563
 
                }
564
 
            }
565
 
        }
 
517
        super.closeEditors();
566
518
 
567
519
        // Close experiments that contain the trace if open
568
520
        if (getParent() instanceof TmfTraceFolder) {
569
 
            TmfExperimentFolder experimentFolder = getProject().getExperimentsFolder();
570
 
            for (ITmfProjectModelElement experiment : experimentFolder.getChildren()) {
571
 
                for (ITmfProjectModelElement child : experiment.getChildren()) {
572
 
                    if (child.getName().equals(getName())) {
573
 
                        ((TmfExperimentElement) experiment).closeEditors();
 
521
            TmfExperimentFolder experimentsFolder = getProject().getExperimentsFolder();
 
522
            for (TmfExperimentElement experiment : experimentsFolder.getExperiments()) {
 
523
                for (TmfTraceElement trace : experiment.getTraces()) {
 
524
                    if (trace.getElementPath().equals(getElementPath())) {
 
525
                        experiment.closeEditors();
574
526
                        break;
575
527
                    }
576
528
                }
579
531
            TmfExperimentElement experiment = (TmfExperimentElement) getParent();
580
532
            experiment.closeEditors();
581
533
        }
 
534
 
 
535
        /*
 
536
         * We will be closing a trace shortly. Invoke GC to release
 
537
         * MappedByteBuffer objects, which some trace types, like CTF, use.
 
538
         * (see Java bug JDK-4724038)
 
539
         */
 
540
        System.gc();
582
541
    }
583
542
 
584
543
    /**
597
556
        closeEditors();
598
557
 
599
558
        IPath path = fResource.getLocation();
600
 
        if (path != null && (getParent() instanceof TmfTraceFolder)) {
601
 
            TmfExperimentFolder experimentFolder = getProject().getExperimentsFolder();
602
 
 
603
 
            // Propagate the removal to traces
604
 
            for (ITmfProjectModelElement experiment : experimentFolder.getChildren()) {
605
 
                List<ITmfProjectModelElement> toRemove = new LinkedList<ITmfProjectModelElement>();
606
 
                for (ITmfProjectModelElement child : experiment.getChildren()) {
607
 
                    if (child.getName().equals(getName())) {
608
 
                        toRemove.add(child);
609
 
                    }
610
 
                }
611
 
                for (ITmfProjectModelElement child : toRemove) {
612
 
                    ((TmfExperimentElement) experiment).removeTrace((TmfTraceElement) child);
613
 
                }
 
559
        if (path != null) {
 
560
            if (getParent() instanceof TmfTraceFolder) {
 
561
                TmfExperimentFolder experimentFolder = getProject().getExperimentsFolder();
 
562
 
 
563
                // Propagate the removal to traces
 
564
                for (TmfExperimentElement experiment : experimentFolder.getExperiments()) {
 
565
                    List<TmfTraceElement> toRemove = new LinkedList<>();
 
566
                    for (TmfTraceElement trace : experiment.getTraces()) {
 
567
                        if (trace.getElementPath().equals(getElementPath())) {
 
568
                            toRemove.add(trace);
 
569
                        }
 
570
                    }
 
571
                    for (TmfTraceElement child : toRemove) {
 
572
                        experiment.removeTrace(child);
 
573
                    }
 
574
                }
 
575
 
 
576
                // Delete supplementary files
 
577
                deleteSupplementaryFolder();
 
578
 
 
579
            } else if (getParent() instanceof TmfExperimentElement) {
 
580
                TmfExperimentElement experimentElement = (TmfExperimentElement) getParent();
 
581
                experimentElement.removeTrace(this);
614
582
            }
615
 
 
616
 
            // Delete supplementary files
617
 
            deleteSupplementaryFolder();
618
583
        }
619
584
 
620
585
        // Finally, delete the trace
621
586
        fResource.delete(true, progressMonitor);
622
587
    }
623
588
 
624
 
    /**
625
 
     * Get the instantiated trace associated with this element.
626
 
     *
627
 
     * @return The instantiated trace or null if trace is not (yet) available
628
 
     * @since 2.1
629
 
     */
630
 
    public ITmfTrace getTrace() {
631
 
        for (ITmfTrace trace : TmfTraceManager.getInstance().getOpenedTraces()) {
632
 
            if (trace.getResource().equals(getResource())) {
633
 
                return trace;
634
 
            }
635
 
        }
636
 
        return null;
637
 
    }
638
589
}