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
.Arrays
;
16 import java
.util
.HashMap
;
19 import org
.eclipse
.core
.resources
.IResource
;
20 import org
.eclipse
.core
.runtime
.CoreException
;
21 import org
.eclipse
.core
.runtime
.IConfigurationElement
;
22 import org
.eclipse
.core
.runtime
.Platform
;
23 import org
.eclipse
.core
.runtime
.QualifiedName
;
24 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.parsers
.custom
.CustomTxtEvent
;
25 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.parsers
.custom
.CustomTxtTrace
;
26 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.parsers
.custom
.CustomTxtTraceDefinition
;
27 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.parsers
.custom
.CustomXmlEvent
;
28 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.parsers
.custom
.CustomXmlTrace
;
29 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.parsers
.custom
.CustomXmlTraceDefinition
;
30 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfEvent
;
31 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfTrace
;
32 import org
.eclipse
.linuxtools
.tmf
.core
.util
.TmfTraceType
;
33 import org
.eclipse
.linuxtools
.tmf
.ui
.editors
.TmfEventsEditor
;
34 import org
.eclipse
.ui
.IActionFilter
;
35 import org
.eclipse
.ui
.views
.properties
.IPropertyDescriptor
;
36 import org
.eclipse
.ui
.views
.properties
.IPropertySource2
;
37 import org
.eclipse
.ui
.views
.properties
.TextPropertyDescriptor
;
40 * <b><u>TmfTraceElement</u></b>
43 public class TmfTraceElement
extends TmfProjectModelElement
implements IActionFilter
, IPropertySource2
{
45 // ------------------------------------------------------------------------
47 // ------------------------------------------------------------------------
50 public static final QualifiedName TRACEBUNDLE
= new QualifiedName("org.eclipse.linuxtools.tmf", "tracetype.bundle"); //$NON-NLS-1$//$NON-NLS-2$
51 public static final QualifiedName TRACETYPE
= new QualifiedName("org.eclipse.linuxtools.tmf", "tracetype.id"); //$NON-NLS-1$//$NON-NLS-2$
52 public static final QualifiedName TRACEICON
= new QualifiedName("org.eclipse.linuxtools.tmf", "tracetype.icon"); //$NON-NLS-1$//$NON-NLS-2$
55 public static final String BUNDLE
= "bundle"; //$NON-NLS-1$
56 public static final String IS_LINKED
= "isLinked"; //$NON-NLS-1$
58 // Property View stuff
59 private static final String sfInfoCategory
= "Info"; //$NON-NLS-1$
60 private static final String sfName
= "name"; //$NON-NLS-1$
61 private static final String sfPath
= "path"; //$NON-NLS-1$
62 private static final String sfLocation
= "location"; //$NON-NLS-1$
63 private static final String sfEventType
= "type"; //$NON-NLS-1$
64 private static final String sfIsLinked
= "linked"; //$NON-NLS-1$
66 private static final TextPropertyDescriptor sfNameDescriptor
= new TextPropertyDescriptor(sfName
, sfName
);
67 private static final TextPropertyDescriptor sfPathDescriptor
= new TextPropertyDescriptor(sfPath
, sfPath
);
68 private static final TextPropertyDescriptor sfLocationDescriptor
= new TextPropertyDescriptor(sfLocation
, sfLocation
);
69 private static final TextPropertyDescriptor sfTypeDescriptor
= new TextPropertyDescriptor(sfEventType
, sfEventType
);
70 private static final TextPropertyDescriptor sfIsLinkedDescriptor
= new TextPropertyDescriptor(sfIsLinked
, sfIsLinked
);
72 private static final IPropertyDescriptor
[] sfDescriptors
= { sfNameDescriptor
, sfPathDescriptor
, sfLocationDescriptor
,
73 sfTypeDescriptor
, sfIsLinkedDescriptor
};
76 sfNameDescriptor
.setCategory(sfInfoCategory
);
77 sfPathDescriptor
.setCategory(sfInfoCategory
);
78 sfLocationDescriptor
.setCategory(sfInfoCategory
);
79 sfTypeDescriptor
.setCategory(sfInfoCategory
);
80 sfIsLinkedDescriptor
.setCategory(sfInfoCategory
);
83 // ------------------------------------------------------------------------
85 // ------------------------------------------------------------------------
87 // This trace type ID as defined in plugin.xml
88 private String fTraceTypeId
= null;
90 // ------------------------------------------------------------------------
91 // Static initialization
92 // ------------------------------------------------------------------------
94 // The mapping of available trace type IDs to their corresponding configuration element
95 private static final Map
<String
, IConfigurationElement
> sfTraceTypeAttributes
= new HashMap
<String
, IConfigurationElement
>();
96 private static final Map
<String
, IConfigurationElement
> sfTraceCategories
= new HashMap
<String
, IConfigurationElement
>();
98 // Initialize statically at startup
99 public static void init() {
100 IConfigurationElement
[] config
= Platform
.getExtensionRegistry().getConfigurationElementsFor(TmfTraceType
.TMF_TRACE_TYPE_ID
);
101 for (IConfigurationElement ce
: config
) {
102 String elementName
= ce
.getName();
103 if (elementName
.equals(TmfTraceType
.TYPE_ELEM
)) {
104 String traceTypeId
= ce
.getAttribute(TmfTraceType
.ID_ATTR
);
105 sfTraceTypeAttributes
.put(traceTypeId
, ce
);
106 } else if (elementName
.equals(TmfTraceType
.CATEGORY_ELEM
)) {
107 String categoryId
= ce
.getAttribute(TmfTraceType
.ID_ATTR
);
108 sfTraceCategories
.put(categoryId
, ce
);
113 // ------------------------------------------------------------------------
115 // ------------------------------------------------------------------------
117 public TmfTraceElement(String name
, IResource trace
, TmfTraceFolder parent
) {
118 this(name
, trace
, (TmfProjectModelElement
) parent
);
121 public TmfTraceElement(String name
, IResource trace
, TmfExperimentElement parent
) {
122 this(name
, trace
, (TmfProjectModelElement
) parent
);
125 private TmfTraceElement(String name
, IResource trace
, TmfProjectModelElement parent
) {
126 super(name
, trace
, parent
);
127 parent
.addChild(this);
131 // ------------------------------------------------------------------------
133 // ------------------------------------------------------------------------
135 public String
getTraceType() {
139 public void refreshTraceType() {
141 fTraceTypeId
= getResource().getPersistentProperty(TRACETYPE
);
142 } catch (CoreException e
) {
147 public ITmfTrace
<?
> instantiateTrace() {
149 if (fTraceTypeId
!= null) {
150 if (fTraceTypeId
.startsWith(CustomTxtTrace
.class.getCanonicalName())) {
151 for (CustomTxtTraceDefinition def
: CustomTxtTraceDefinition
.loadAll()) {
152 if (fTraceTypeId
.equals(CustomTxtTrace
.class.getCanonicalName() + ":" + def
.definitionName
)) { //$NON-NLS-1$
153 return new CustomTxtTrace(def
);
157 if (fTraceTypeId
.startsWith(CustomXmlTrace
.class.getCanonicalName())) {
158 for (CustomXmlTraceDefinition def
: CustomXmlTraceDefinition
.loadAll()) {
159 if (fTraceTypeId
.equals(CustomXmlTrace
.class.getCanonicalName() + ":" + def
.definitionName
)) { //$NON-NLS-1$
160 return new CustomXmlTrace(def
);
164 IConfigurationElement ce
= sfTraceTypeAttributes
.get(fTraceTypeId
);
165 ITmfTrace
<?
> trace
= (ITmfTrace
<?
>) ce
.createExecutableExtension(TmfTraceType
.TRACE_TYPE_ATTR
);
168 } catch (CoreException e
) {
174 public TmfEvent
instantiateEvent() {
176 if (fTraceTypeId
!= null) {
177 if (fTraceTypeId
.startsWith(CustomTxtTrace
.class.getCanonicalName())) {
178 for (CustomTxtTraceDefinition def
: CustomTxtTraceDefinition
.loadAll()) {
179 if (fTraceTypeId
.equals(CustomTxtTrace
.class.getCanonicalName() + ":" + def
.definitionName
)) { //$NON-NLS-1$
180 return new CustomTxtEvent(def
);
184 if (fTraceTypeId
.startsWith(CustomXmlTrace
.class.getCanonicalName())) {
185 for (CustomXmlTraceDefinition def
: CustomXmlTraceDefinition
.loadAll()) {
186 if (fTraceTypeId
.equals(CustomXmlTrace
.class.getCanonicalName() + ":" + def
.definitionName
)) { //$NON-NLS-1$
187 return new CustomXmlEvent(def
);
191 IConfigurationElement ce
= sfTraceTypeAttributes
.get(fTraceTypeId
);
192 TmfEvent event
= (TmfEvent
) ce
.createExecutableExtension(TmfTraceType
.EVENT_TYPE_ATTR
);
195 } catch (CoreException e
) {
201 public String
getEditorId() {
202 if (fTraceTypeId
!= null) {
203 if (fTraceTypeId
.startsWith(CustomTxtTrace
.class.getCanonicalName())) {
204 return TmfEventsEditor
.ID
;
206 if (fTraceTypeId
.startsWith(CustomXmlTrace
.class.getCanonicalName())) {
207 return TmfEventsEditor
.ID
;
209 IConfigurationElement ce
= sfTraceTypeAttributes
.get(fTraceTypeId
);
210 IConfigurationElement
[] defaultEditorCE
= ce
.getChildren(TmfTraceType
.DEFAULT_EDITOR_ELEM
);
211 if (defaultEditorCE
.length
== 1) {
212 return defaultEditorCE
[0].getAttribute(TmfTraceType
.ID_ATTR
);
218 // ------------------------------------------------------------------------
220 // ------------------------------------------------------------------------
223 public boolean testAttribute(Object target
, String name
, String value
) {
224 if (name
.equals(IS_LINKED
)) {
225 boolean isLinked
= getResource().isLinked();
226 return Boolean
.toString(isLinked
).equals(value
);
231 // ------------------------------------------------------------------------
233 // ------------------------------------------------------------------------
236 public TmfProjectElement
getProject() {
237 if (getParent() instanceof TmfTraceFolder
) {
238 TmfTraceFolder folder
= (TmfTraceFolder
) getParent();
239 TmfProjectElement project
= (TmfProjectElement
) folder
.getParent();
242 if (getParent() instanceof TmfExperimentElement
) {
243 TmfExperimentElement experiment
= (TmfExperimentElement
) getParent();
244 TmfExperimentFolder folder
= (TmfExperimentFolder
) experiment
.getParent();
245 TmfProjectElement project
= (TmfProjectElement
) folder
.getParent();
251 // ------------------------------------------------------------------------
253 // ------------------------------------------------------------------------
256 public Object
getEditableValue() {
261 public IPropertyDescriptor
[] getPropertyDescriptors() {
262 return (sfDescriptors
!= null) ? Arrays
.copyOf(sfDescriptors
, sfDescriptors
.length
) : null;
266 public Object
getPropertyValue(Object id
) {
268 if (sfName
.equals(id
))
271 if (sfPath
.equals(id
))
272 return getPath().toString();
274 if (sfLocation
.equals(id
))
275 return getLocation().toString();
277 if (sfIsLinked
.equals(id
))
278 return Boolean
.valueOf(getResource().isLinked()).toString();
280 if (sfEventType
.equals(id
)) {
281 if (fTraceTypeId
!= null) {
282 IConfigurationElement ce
= sfTraceTypeAttributes
.get(fTraceTypeId
);
283 return (ce
!= null) ?
(getCategory(ce
) + " : " + ce
.getAttribute(TmfTraceType
.NAME_ATTR
)) : ""; //$NON-NLS-1$ //$NON-NLS-2$
290 private String
getCategory(IConfigurationElement ce
) {
291 String categoryId
= ce
.getAttribute(TmfTraceType
.CATEGORY_ATTR
);
292 if (categoryId
!= null) {
293 IConfigurationElement category
= sfTraceCategories
.get(categoryId
);
294 if (category
!= null) {
295 return category
.getAttribute(TmfTraceType
.NAME_ATTR
);
298 return "[no category]"; //$NON-NLS-1$
302 public void resetPropertyValue(Object id
) {
306 public void setPropertyValue(Object id
, Object value
) {
310 public boolean isPropertyResettable(Object id
) {
315 public boolean isPropertySet(Object id
) {