1 /*******************************************************************************
2 * Copyright (c) 2010, 2011 Ericsson
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
10 * Francois Chouinard - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.tmf
.ui
.project
.model
;
15 import java
.util
.HashMap
;
18 import org
.eclipse
.core
.resources
.IResource
;
19 import org
.eclipse
.core
.runtime
.CoreException
;
20 import org
.eclipse
.core
.runtime
.IConfigurationElement
;
21 import org
.eclipse
.core
.runtime
.Platform
;
22 import org
.eclipse
.core
.runtime
.QualifiedName
;
23 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfEvent
;
24 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfTrace
;
25 import org
.eclipse
.linuxtools
.tmf
.core
.util
.TmfTraceType
;
26 import org
.eclipse
.linuxtools
.tmf
.ui
.editors
.TmfEventsEditor
;
27 import org
.eclipse
.linuxtools
.tmf
.ui
.parsers
.custom
.CustomTxtEvent
;
28 import org
.eclipse
.linuxtools
.tmf
.ui
.parsers
.custom
.CustomTxtTrace
;
29 import org
.eclipse
.linuxtools
.tmf
.ui
.parsers
.custom
.CustomTxtTraceDefinition
;
30 import org
.eclipse
.linuxtools
.tmf
.ui
.parsers
.custom
.CustomXmlEvent
;
31 import org
.eclipse
.linuxtools
.tmf
.ui
.parsers
.custom
.CustomXmlTrace
;
32 import org
.eclipse
.linuxtools
.tmf
.ui
.parsers
.custom
.CustomXmlTraceDefinition
;
33 import org
.eclipse
.ui
.IActionFilter
;
34 import org
.eclipse
.ui
.views
.properties
.IPropertyDescriptor
;
35 import org
.eclipse
.ui
.views
.properties
.IPropertySource2
;
36 import org
.eclipse
.ui
.views
.properties
.TextPropertyDescriptor
;
39 * <b><u>TmfTraceElement</u></b>
42 public class TmfTraceElement
extends TmfProjectModelElement
implements IActionFilter
, IPropertySource2
{
44 // ------------------------------------------------------------------------
46 // ------------------------------------------------------------------------
49 public static final QualifiedName TRACEBUNDLE
= new QualifiedName("org.eclipse.linuxtools.tmf", "tracetype.bundle"); //$NON-NLS-1$//$NON-NLS-2$
50 public static final QualifiedName TRACETYPE
= new QualifiedName("org.eclipse.linuxtools.tmf", "tracetype.id"); //$NON-NLS-1$//$NON-NLS-2$
51 public static final QualifiedName TRACEICON
= new QualifiedName("org.eclipse.linuxtools.tmf", "tracetype.icon"); //$NON-NLS-1$//$NON-NLS-2$
54 public static final String BUNDLE
= "bundle"; //$NON-NLS-1$
55 public static final String IS_LINKED
= "isLinked"; //$NON-NLS-1$
57 // Property View stuff
58 private static final String sfInfoCategory
= "Info"; //$NON-NLS-1$
59 private static final String sfName
= "name"; //$NON-NLS-1$
60 private static final String sfPath
= "path"; //$NON-NLS-1$
61 private static final String sfLocation
= "location"; //$NON-NLS-1$
62 private static final String sfEventType
= "type"; //$NON-NLS-1$
63 private static final String sfIsLinked
= "linked"; //$NON-NLS-1$
65 private static final TextPropertyDescriptor sfNameDescriptor
= new TextPropertyDescriptor(sfName
, sfName
);
66 private static final TextPropertyDescriptor sfPathDescriptor
= new TextPropertyDescriptor(sfPath
, sfPath
);
67 private static final TextPropertyDescriptor sfLocationDescriptor
= new TextPropertyDescriptor(sfLocation
, sfLocation
);
68 private static final TextPropertyDescriptor sfTypeDescriptor
= new TextPropertyDescriptor(sfEventType
, sfEventType
);
69 private static final TextPropertyDescriptor sfIsLinkedDescriptor
= new TextPropertyDescriptor(sfIsLinked
, sfIsLinked
);
71 private static final IPropertyDescriptor
[] sfDescriptors
= { sfNameDescriptor
, sfPathDescriptor
, sfLocationDescriptor
,
72 sfTypeDescriptor
, sfIsLinkedDescriptor
};
75 sfNameDescriptor
.setCategory(sfInfoCategory
);
76 sfPathDescriptor
.setCategory(sfInfoCategory
);
77 sfLocationDescriptor
.setCategory(sfInfoCategory
);
78 sfTypeDescriptor
.setCategory(sfInfoCategory
);
79 sfIsLinkedDescriptor
.setCategory(sfInfoCategory
);
82 // ------------------------------------------------------------------------
84 // ------------------------------------------------------------------------
86 // This trace type ID as defined in plugin.xml
87 private String fTraceTypeId
= null;
89 // ------------------------------------------------------------------------
90 // Static initialization
91 // ------------------------------------------------------------------------
93 // The mapping of available trace type IDs to their corresponding configuration element
94 private static final Map
<String
, IConfigurationElement
> sfTraceTypeAttributes
= new HashMap
<String
, IConfigurationElement
>();
95 private static final Map
<String
, IConfigurationElement
> sfTraceCategories
= new HashMap
<String
, IConfigurationElement
>();
97 // Initialize statically at startup
98 public static void init() {
99 IConfigurationElement
[] config
= Platform
.getExtensionRegistry().getConfigurationElementsFor(TmfTraceType
.TMF_TRACE_TYPE_ID
);
100 for (IConfigurationElement ce
: config
) {
101 String elementName
= ce
.getName();
102 if (elementName
.equals(TmfTraceType
.TYPE_ELEM
)) {
103 String traceTypeId
= ce
.getAttribute(TmfTraceType
.ID_ATTR
);
104 sfTraceTypeAttributes
.put(traceTypeId
, ce
);
105 } else if (elementName
.equals(TmfTraceType
.CATEGORY_ELEM
)) {
106 String categoryId
= ce
.getAttribute(TmfTraceType
.ID_ATTR
);
107 sfTraceCategories
.put(categoryId
, ce
);
112 // ------------------------------------------------------------------------
114 // ------------------------------------------------------------------------
116 public TmfTraceElement(String name
, IResource trace
, TmfTraceFolder parent
) {
117 this(name
, trace
, (TmfProjectModelElement
) parent
);
120 public TmfTraceElement(String name
, IResource trace
, TmfExperimentElement parent
) {
121 this(name
, trace
, (TmfProjectModelElement
) parent
);
124 private TmfTraceElement(String name
, IResource trace
, TmfProjectModelElement parent
) {
125 super(name
, trace
, parent
);
126 parent
.addChild(this);
130 // ------------------------------------------------------------------------
132 // ------------------------------------------------------------------------
134 public String
getTraceType() {
138 public void refreshTraceType() {
140 fTraceTypeId
= getResource().getPersistentProperty(TRACETYPE
);
141 } catch (CoreException e
) {
146 public ITmfTrace
<?
> instantiateTrace() {
148 if (fTraceTypeId
!= null) {
149 if (fTraceTypeId
.startsWith(CustomTxtTrace
.class.getCanonicalName())) {
150 for (CustomTxtTraceDefinition def
: CustomTxtTraceDefinition
.loadAll()) {
151 if (fTraceTypeId
.equals(CustomTxtTrace
.class.getCanonicalName() + ":" + def
.definitionName
)) { //$NON-NLS-1$
152 return new CustomTxtTrace(def
);
156 if (fTraceTypeId
.startsWith(CustomXmlTrace
.class.getCanonicalName())) {
157 for (CustomXmlTraceDefinition def
: CustomXmlTraceDefinition
.loadAll()) {
158 if (fTraceTypeId
.equals(CustomXmlTrace
.class.getCanonicalName() + ":" + def
.definitionName
)) { //$NON-NLS-1$
159 return new CustomXmlTrace(def
);
163 IConfigurationElement ce
= sfTraceTypeAttributes
.get(fTraceTypeId
);
164 ITmfTrace
<?
> trace
= (ITmfTrace
<?
>) ce
.createExecutableExtension(TmfTraceType
.TRACE_TYPE_ATTR
);
167 } catch (CoreException e
) {
173 public TmfEvent
instantiateEvent() {
175 if (fTraceTypeId
!= null) {
176 if (fTraceTypeId
.startsWith(CustomTxtTrace
.class.getCanonicalName())) {
177 for (CustomTxtTraceDefinition def
: CustomTxtTraceDefinition
.loadAll()) {
178 if (fTraceTypeId
.equals(CustomTxtTrace
.class.getCanonicalName() + ":" + def
.definitionName
)) { //$NON-NLS-1$
179 return new CustomTxtEvent(def
);
183 if (fTraceTypeId
.startsWith(CustomXmlTrace
.class.getCanonicalName())) {
184 for (CustomXmlTraceDefinition def
: CustomXmlTraceDefinition
.loadAll()) {
185 if (fTraceTypeId
.equals(CustomXmlTrace
.class.getCanonicalName() + ":" + def
.definitionName
)) { //$NON-NLS-1$
186 return new CustomXmlEvent(def
);
190 IConfigurationElement ce
= sfTraceTypeAttributes
.get(fTraceTypeId
);
191 TmfEvent event
= (TmfEvent
) ce
.createExecutableExtension(TmfTraceType
.EVENT_TYPE_ATTR
);
194 } catch (CoreException e
) {
200 public String
getEditorId() {
201 if (fTraceTypeId
!= null) {
202 if (fTraceTypeId
.startsWith(CustomTxtTrace
.class.getCanonicalName())) {
203 return TmfEventsEditor
.ID
;
205 if (fTraceTypeId
.startsWith(CustomXmlTrace
.class.getCanonicalName())) {
206 return TmfEventsEditor
.ID
;
208 IConfigurationElement ce
= sfTraceTypeAttributes
.get(fTraceTypeId
);
209 IConfigurationElement
[] defaultEditorCE
= ce
.getChildren(TmfTraceType
.DEFAULT_EDITOR_ELEM
);
210 if (defaultEditorCE
.length
== 1) {
211 return defaultEditorCE
[0].getAttribute(TmfTraceType
.ID_ATTR
);
217 // ------------------------------------------------------------------------
219 // ------------------------------------------------------------------------
222 public boolean testAttribute(Object target
, String name
, String value
) {
223 if (name
.equals(IS_LINKED
)) {
224 boolean isLinked
= getResource().isLinked();
225 return Boolean
.toString(isLinked
).equals(value
);
230 // ------------------------------------------------------------------------
232 // ------------------------------------------------------------------------
235 public TmfProjectElement
getProject() {
236 if (getParent() instanceof TmfTraceFolder
) {
237 TmfTraceFolder folder
= (TmfTraceFolder
) getParent();
238 TmfProjectElement project
= (TmfProjectElement
) folder
.getParent();
241 if (getParent() instanceof TmfExperimentElement
) {
242 TmfExperimentElement experiment
= (TmfExperimentElement
) getParent();
243 TmfExperimentFolder folder
= (TmfExperimentFolder
) experiment
.getParent();
244 TmfProjectElement project
= (TmfProjectElement
) folder
.getParent();
250 // ------------------------------------------------------------------------
252 // ------------------------------------------------------------------------
255 public Object
getEditableValue() {
260 public IPropertyDescriptor
[] getPropertyDescriptors() {
261 return sfDescriptors
;
265 public Object
getPropertyValue(Object id
) {
267 if (sfName
.equals(id
))
270 if (sfPath
.equals(id
))
271 return getPath().toString();
273 if (sfLocation
.equals(id
))
274 return getLocation().toString();
276 if (sfIsLinked
.equals(id
))
277 return Boolean
.valueOf(getResource().isLinked()).toString();
279 if (sfEventType
.equals(id
)) {
280 if (fTraceTypeId
!= null) {
281 IConfigurationElement ce
= sfTraceTypeAttributes
.get(fTraceTypeId
);
282 return (ce
!= null) ?
(getCategory(ce
) + " : " + ce
.getAttribute(TmfTraceType
.NAME_ATTR
)) : ""; //$NON-NLS-1$ //$NON-NLS-2$
289 private String
getCategory(IConfigurationElement ce
) {
290 String categoryId
= ce
.getAttribute(TmfTraceType
.CATEGORY_ATTR
);
291 if (categoryId
!= null) {
292 IConfigurationElement category
= sfTraceCategories
.get(categoryId
);
293 if (category
!= null) {
294 return category
.getAttribute(TmfTraceType
.NAME_ATTR
);
297 return "[no category]"; //$NON-NLS-1$
301 public void resetPropertyValue(Object id
) {
305 public void setPropertyValue(Object id
, Object value
) {
309 public boolean isPropertyResettable(Object id
) {
314 public boolean isPropertySet(Object id
) {