Contribute CNF based TMF project handling
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / project / model / TmfTraceElement.java
CommitLineData
12c155f5
FC
1/*******************************************************************************
2 * Copyright (c) 2010, 2011 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 * Francois Chouinard - Initial API and implementation
11 *******************************************************************************/
12
13package org.eclipse.linuxtools.tmf.ui.project.model;
14
15import java.util.HashMap;
16import java.util.Map;
17
18import org.eclipse.core.resources.IResource;
19import org.eclipse.core.runtime.CoreException;
20import org.eclipse.core.runtime.IConfigurationElement;
21import org.eclipse.core.runtime.Platform;
22import org.eclipse.core.runtime.QualifiedName;
23import org.eclipse.linuxtools.tmf.TmfCorePlugin;
24import org.eclipse.linuxtools.tmf.event.TmfEvent;
25import org.eclipse.linuxtools.tmf.trace.ITmfTrace;
26import org.eclipse.ui.IActionFilter;
27import org.eclipse.ui.views.properties.IPropertyDescriptor;
28import org.eclipse.ui.views.properties.IPropertySource2;
29import org.eclipse.ui.views.properties.TextPropertyDescriptor;
30
31/**
32 * <b><u>TmfTraceElement</u></b>
33 * <p>
34 */
35public class TmfTraceElement extends TmfProjectModelElement implements IActionFilter, IPropertySource2 {
36
37 // ------------------------------------------------------------------------
38 // Constants
39 // ------------------------------------------------------------------------
40
41 // Property keys
42 public static final QualifiedName TRACEBUNDLE = new QualifiedName("org.eclipse.linuxtools.tmf", "tracetype.bundle"); //$NON-NLS-1$//$NON-NLS-2$
43 public static final QualifiedName TRACETYPE = new QualifiedName("org.eclipse.linuxtools.tmf", "tracetype.id"); //$NON-NLS-1$//$NON-NLS-2$
44 public static final QualifiedName TRACEICON = new QualifiedName("org.eclipse.linuxtools.tmf", "tracetype.icon"); //$NON-NLS-1$//$NON-NLS-2$
45
46 // Extension point fields
47 public static final String TYPE = "type"; //$NON-NLS-1$
48 public static final String ID = "id"; //$NON-NLS-1$
49 public static final String CATEGORY = "category"; //$NON-NLS-1$
50 public static final String NAME = "name"; //$NON-NLS-1$
51 public static final String TRACE_TYPE = "trace_type"; //$NON-NLS-1$
52 public static final String EVENT_TYPE = "event_type"; //$NON-NLS-1$
53 public static final String ICON = "icon"; //$NON-NLS-1$
54
55 public static final String DEFAULT_EDITOR = "defaultEditor"; //$NON-NLS-1$
56 public static final String EVENTS_TABLE_TYPE = "eventsTableType"; //$NON-NLS-1$
57 public static final String CLASS = "class"; //$NON-NLS-1$
58
59 // Other attributes
60 public static final String BUNDLE = "bundle"; //$NON-NLS-1$
61 public static final String IS_LINKED = "isLinked"; //$NON-NLS-1$
62
63 // Property View stuff
64 private static final String sfInfoCategory = "Info"; //$NON-NLS-1$
65 private static final String sfName = "name"; //$NON-NLS-1$
66 private static final String sfPath = "path"; //$NON-NLS-1$
67 private static final String sfLocation = "location"; //$NON-NLS-1$
68 private static final String sfEventType = "type"; //$NON-NLS-1$
69 private static final String sfIsLinked = "linked"; //$NON-NLS-1$
70
71 private static final TextPropertyDescriptor sfNameDescriptor = new TextPropertyDescriptor(sfName, sfName);
72 private static final TextPropertyDescriptor sfPathDescriptor = new TextPropertyDescriptor(sfPath, sfPath);
73 private static final TextPropertyDescriptor sfLocationDescriptor = new TextPropertyDescriptor(sfLocation, sfLocation);
74 private static final TextPropertyDescriptor sfTypeDescriptor = new TextPropertyDescriptor(sfEventType, sfEventType);
75 private static final TextPropertyDescriptor sfIsLinkedDescriptor = new TextPropertyDescriptor(sfIsLinked, sfIsLinked);
76
77 private static final IPropertyDescriptor[] sfDescriptors = { sfNameDescriptor, sfPathDescriptor, sfLocationDescriptor,
78 sfTypeDescriptor, sfIsLinkedDescriptor };
79
80 static {
81 sfNameDescriptor.setCategory(sfInfoCategory);
82 sfPathDescriptor.setCategory(sfInfoCategory);
83 sfLocationDescriptor.setCategory(sfInfoCategory);
84 sfTypeDescriptor.setCategory(sfInfoCategory);
85 sfIsLinkedDescriptor.setCategory(sfInfoCategory);
86 }
87
88 // ------------------------------------------------------------------------
89 // Attributes
90 // ------------------------------------------------------------------------
91
92 // This trace type ID as defined in plugin.xml
93 private String fTraceTypeId = null;
94
95 // ------------------------------------------------------------------------
96 // Static initialization
97 // ------------------------------------------------------------------------
98
99 // The mapping of available trace type IDs to their corresponding configuration element
100 private static final Map<String, IConfigurationElement> sfTraceTypeAttributes = new HashMap<String, IConfigurationElement>();
101 private static final Map<String, IConfigurationElement> sfTraceCategories = new HashMap<String, IConfigurationElement>();
102
103 // Initialize statically at startup
104 public static void init() {
105 IConfigurationElement[] config = Platform.getExtensionRegistry().getConfigurationElementsFor(TmfCorePlugin.TMF_TRACE_TYPE_ID);
106 for (IConfigurationElement ce : config) {
107 String attribute = ce.getName();
108 if (attribute.equals(TYPE)) {
109 String traceTypeId = ce.getAttribute(ID);
110 sfTraceTypeAttributes.put(traceTypeId, ce);
111 } else if (attribute.equals(CATEGORY)) {
112 String categoryId = ce.getAttribute(ID);
113 sfTraceCategories.put(categoryId, ce);
114 }
115 }
116 }
117
118 // ------------------------------------------------------------------------
119 // Constructors
120 // ------------------------------------------------------------------------
121
122 public TmfTraceElement(String name, IResource trace, TmfTraceFolder parent) {
123 this(name, trace, (TmfProjectModelElement) parent);
124 }
125
126 public TmfTraceElement(String name, IResource trace, TmfExperimentElement parent) {
127 this(name, trace, (TmfProjectModelElement) parent);
128 }
129
130 private TmfTraceElement(String name, IResource trace, TmfProjectModelElement parent) {
131 super(name, trace, parent);
132 parent.addChild(this);
133 refreshTraceType();
134 }
135
136 // ------------------------------------------------------------------------
137 // Operations
138 // ------------------------------------------------------------------------
139
140 public String getTraceType() {
141 return fTraceTypeId;
142 }
143
144 public void refreshTraceType() {
145 try {
146 fTraceTypeId = getResource().getPersistentProperty(TRACETYPE);
147 } catch (CoreException e) {
148 e.printStackTrace();
149 }
150 }
151
152 public ITmfTrace<?> instantiateTrace() {
153 try {
154 if (fTraceTypeId != null) {
155 IConfigurationElement ce = sfTraceTypeAttributes.get(fTraceTypeId);
156 ITmfTrace<?> trace = (ITmfTrace<?>) ce.createExecutableExtension(TRACE_TYPE);
157 return trace;
158 }
159 } catch (CoreException e) {
160 e.printStackTrace();
161 }
162 return null;
163 }
164
165 public TmfEvent instantiateEvent() {
166 try {
167 if (fTraceTypeId != null) {
168 IConfigurationElement ce = sfTraceTypeAttributes.get(fTraceTypeId);
169 TmfEvent event = (TmfEvent) ce.createExecutableExtension(EVENT_TYPE);
170 return event;
171 }
172 } catch (CoreException e) {
173 e.printStackTrace();
174 }
175 return null;
176 }
177
178 public String getEditorId() {
179 if (fTraceTypeId != null) {
180 IConfigurationElement ce = sfTraceTypeAttributes.get(fTraceTypeId);
181 IConfigurationElement[] defaultEditorCE = ce.getChildren(DEFAULT_EDITOR);
182 if (defaultEditorCE.length == 1) {
183 return defaultEditorCE[0].getAttribute(ID);
184 }
185 }
186 return null;
187 }
188
189 // ------------------------------------------------------------------------
190 // IActionFilter
191 // ------------------------------------------------------------------------
192
193 @Override
194 public boolean testAttribute(Object target, String name, String value) {
195 if (name.equals(IS_LINKED)) {
196 boolean isLinked = getResource().isLinked();
197 return Boolean.toString(isLinked).equals(value);
198 }
199 return false;
200 }
201
202 // ------------------------------------------------------------------------
203 // TmfTraceElement
204 // ------------------------------------------------------------------------
205
206 @Override
207 public TmfProjectElement getProject() {
208 if (getParent() instanceof TmfTraceFolder) {
209 TmfTraceFolder folder = (TmfTraceFolder) getParent();
210 TmfProjectElement project = (TmfProjectElement) folder.getParent();
211 return project;
212 }
213 if (getParent() instanceof TmfExperimentElement) {
214 TmfExperimentElement experiment = (TmfExperimentElement) getParent();
215 TmfExperimentFolder folder = (TmfExperimentFolder) experiment.getParent();
216 TmfProjectElement project = (TmfProjectElement) folder.getParent();
217 return project;
218 }
219 return null;
220 }
221
222 // ------------------------------------------------------------------------
223 // IPropertySource2
224 // ------------------------------------------------------------------------
225
226 @Override
227 public Object getEditableValue() {
228 return null;
229 }
230
231 @Override
232 public IPropertyDescriptor[] getPropertyDescriptors() {
233 return sfDescriptors;
234 }
235
236 @Override
237 public Object getPropertyValue(Object id) {
238
239 if (sfName.equals(id))
240 return getName();
241
242 if (sfPath.equals(id))
243 return getPath().toString();
244
245 if (sfLocation.equals(id))
246 return getLocation().toString();
247
248 if (sfIsLinked.equals(id))
249 return Boolean.valueOf(getResource().isLinked()).toString();
250
251 if (sfEventType.equals(id)) {
252 if (fTraceTypeId != null) {
253 IConfigurationElement ce = sfTraceTypeAttributes.get(fTraceTypeId);
254 return (ce != null) ? (getCategory(ce) + " : " + ce.getAttribute(NAME)) : ""; //$NON-NLS-1$ //$NON-NLS-2$
255 }
256 }
257
258 return null;
259 }
260
261 private String getCategory(IConfigurationElement ce) {
262 String categoryId = ce.getAttribute(CATEGORY);
263 if (categoryId != null) {
264 IConfigurationElement category = sfTraceCategories.get(categoryId);
265 if (category != null && !category.equals("")) { //$NON-NLS-1$
266 return category.getAttribute(NAME);
267 }
268 }
269 return "[no category]"; //$NON-NLS-1$
270 }
271
272 @Override
273 public void resetPropertyValue(Object id) {
274 }
275
276 @Override
277 public void setPropertyValue(Object id, Object value) {
278 }
279
280 @Override
281 public boolean isPropertyResettable(Object id) {
282 return false;
283 }
284
285 @Override
286 public boolean isPropertySet(Object id) {
287 return false;
288 }
289
290}
This page took 0.03691 seconds and 5 git commands to generate.