tmf: Support folders in package import
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / internal / tmf / ui / project / wizards / tracepkg / TracePackageTraceElement.java
1 /*******************************************************************************
2 * Copyright (c) 2013 Ericsson
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 * Marc-Andre Laperle - Initial API and implementation
11 *******************************************************************************/
12
13 package org.eclipse.linuxtools.internal.tmf.ui.project.wizards.tracepkg;
14
15 import org.eclipse.core.runtime.IPath;
16 import org.eclipse.core.runtime.Path;
17 import org.eclipse.linuxtools.tmf.ui.project.model.TmfCommonProjectElement;
18 import org.eclipse.linuxtools.tmf.ui.project.model.TmfNavigatorLabelProvider;
19 import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceElement;
20 import org.eclipse.swt.graphics.Image;
21
22 /**
23 * An ExportTraceElement associated to a TmfTraceElement. This will be the
24 * parent of other elements (events, supplementary files, bookmarks, etc).
25 *
26 * @author Marc-Andre Laperle
27 */
28 public class TracePackageTraceElement extends TracePackageElement {
29
30 private final TmfTraceElement fTraceElement;
31 private final String fImportName;
32 private final String fTraceType;
33
34 /**
35 * Construct an instance associated to a TmfTraceElement. For exporting.
36 *
37 * @param parent
38 * the parent of this element, can be set to null
39 * @param traceElement
40 * the associated TmfTraceElement
41 */
42 public TracePackageTraceElement(TracePackageElement parent, TmfTraceElement traceElement) {
43 super(parent);
44 fTraceElement = traceElement;
45 fImportName = null;
46 fTraceType = null;
47 }
48
49 /**
50 * Construct an instance associated to a TmfTraceElement. For importing.
51 *
52 * @param parent
53 * the parent of this element, can be set to null
54 * @param importName
55 * the name to use to identify this trace
56 * @param traceType
57 * the trace type to set for this trace
58 */
59 public TracePackageTraceElement(TracePackageElement parent, String importName, String traceType) {
60 super(parent);
61 fImportName = importName;
62 fTraceElement = null;
63 fTraceType = traceType;
64 }
65
66 @Override
67 public String getText() {
68 return fTraceElement != null ? fTraceElement.getElementPath() : getDestinationElementPath();
69 }
70
71 /**
72 * Return the target TmfCommonProjectElement element path for a given trace
73 * package element. {@link TmfCommonProjectElement#getElementPath()}
74 *
75 * @return the element path
76 */
77 public String getDestinationElementPath() {
78 String traceName = getImportName();
79 for (TracePackageElement element : getChildren()) {
80 if (element instanceof TracePackageFilesElement) {
81 TracePackageFilesElement tracePackageFilesElement = (TracePackageFilesElement) element;
82 IPath filePath = new Path(tracePackageFilesElement.getFileName());
83 return filePath.removeLastSegments(1).append(traceName).toString();
84 }
85 }
86
87 return traceName;
88 }
89
90 /**
91 * @return the associated TmfTraceElement
92 */
93 public TmfTraceElement getTraceElement() {
94 return fTraceElement;
95 }
96
97 /**
98 * @return the import name
99 */
100 public String getImportName() {
101 return fImportName;
102 }
103
104 /**
105 * @return the trace type of this trace
106 */
107 public String getTraceType() {
108 return fTraceType;
109 }
110
111 @Override
112 public Image getImage() {
113 TmfNavigatorLabelProvider tmfNavigatorLabelProvider = new TmfNavigatorLabelProvider();
114 return tmfNavigatorLabelProvider.getImage(fTraceElement);
115 }
116 }
This page took 0.047664 seconds and 5 git commands to generate.