1 /*******************************************************************************
2 * Copyright (c) 2012, 2014 Ericsson
4 * All rights reserved. This program and the accompanying materials are made
5 * 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 * Patrick Tasse - Initial API and implementation
11 * Bernd Hufmann - Added call site and model URI properties
12 *******************************************************************************/
14 package org
.eclipse
.tracecompass
.tmf
.ui
.viewers
.events
;
16 import java
.util
.ArrayList
;
17 import java
.util
.List
;
19 import org
.eclipse
.tracecompass
.tmf
.core
.event
.ITmfCustomAttributes
;
20 import org
.eclipse
.tracecompass
.tmf
.core
.event
.ITmfEvent
;
21 import org
.eclipse
.tracecompass
.tmf
.core
.event
.ITmfEventField
;
22 import org
.eclipse
.tracecompass
.tmf
.core
.event
.lookup
.ITmfCallsite
;
23 import org
.eclipse
.tracecompass
.tmf
.core
.event
.lookup
.ITmfModelLookup
;
24 import org
.eclipse
.tracecompass
.tmf
.core
.event
.lookup
.ITmfSourceLookup
;
25 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.ITmfTimestamp
;
26 import org
.eclipse
.tracecompass
.tmf
.ui
.properties
.ReadOnlyTextPropertyDescriptor
;
27 import org
.eclipse
.ui
.views
.properties
.IPropertyDescriptor
;
28 import org
.eclipse
.ui
.views
.properties
.IPropertySource
;
31 * Property source for events
33 public class TmfEventPropertySource
implements IPropertySource
{
35 private static final String ID_TIMESTAMP
= "event_timestamp"; //$NON-NLS-1$
36 private static final String ID_TYPE
= "event_type"; //$NON-NLS-1$
37 private static final String ID_TRACE
= "trace_attribute"; //$NON-NLS-1$
38 private static final String ID_CONTENT
= "event_content"; //$NON-NLS-1$
39 private static final String ID_SOURCE_LOOKUP
= "event_lookup"; //$NON-NLS-1$
40 private static final String ID_MODEL_URI
= "model_uri"; //$NON-NLS-1$
41 private static final String ID_CUSTOM_ATTRIBUTE
= "custom_attribute"; //$NON-NLS-1$
43 private static final String NAME_TIMESTAMP
= "Timestamp"; //$NON-NLS-1$
44 private static final String NAME_TYPE
= "Type"; //$NON-NLS-1$
45 private static final String NAME_TRACE
= "Trace"; //$NON-NLS-1$
46 private static final String NAME_CONTENT
= "Content"; //$NON-NLS-1$
47 private static final String NAME_SOURCE_LOOKUP
= "Source Lookup"; //$NON-NLS-1$
48 private static final String NAME_MODEL_URI
= "Model URI"; //$NON-NLS-1$
49 private static final String NAME_CUSTOM_ATTRIBUTES
= "Custom Attributes"; //$NON-NLS-1$
51 private static final String EMPTY_STRING
= ""; //$NON-NLS-1$
53 private ITmfEvent fEvent
;
55 private static class TimestampPropertySource
implements IPropertySource
{
56 private static final String ID_TIMESTAMP_VALUE
= "timestamp_value"; //$NON-NLS-1$
57 private static final String ID_TIMESTAMP_SCALE
= "timestamp_scale"; //$NON-NLS-1$
58 private static final String NAME_TIMESTAMP_VALUE
= "value"; //$NON-NLS-1$
59 private static final String NAME_TIMESTAMP_SCALE
= "scale"; //$NON-NLS-1$
61 private ITmfTimestamp fTimestamp
;
63 public TimestampPropertySource(ITmfTimestamp timestamp
) {
64 fTimestamp
= timestamp
;
68 public Object
getEditableValue() {
69 return fTimestamp
.toString();
73 public IPropertyDescriptor
[] getPropertyDescriptors() {
74 IPropertyDescriptor
[] descriptors
= new IPropertyDescriptor
[2];
75 descriptors
[0] = new ReadOnlyTextPropertyDescriptor(ID_TIMESTAMP_VALUE
, NAME_TIMESTAMP_VALUE
);
76 descriptors
[1] = new ReadOnlyTextPropertyDescriptor(ID_TIMESTAMP_SCALE
, NAME_TIMESTAMP_SCALE
);
81 public Object
getPropertyValue(Object id
) {
82 if (id
.equals(ID_TIMESTAMP_VALUE
)) {
83 return Long
.toString(fTimestamp
.getValue());
84 } else if (id
.equals(ID_TIMESTAMP_SCALE
)) {
85 return Integer
.toString(fTimestamp
.getScale());
91 public boolean isPropertySet(Object id
) {
96 public void resetPropertyValue(Object id
) {
100 public void setPropertyValue(Object id
, Object value
) {
104 private static class ContentPropertySource
implements IPropertySource
{
105 private ITmfEventField fContent
;
107 public ContentPropertySource(ITmfEventField content
) {
112 public Object
getEditableValue() {
113 return fContent
.toString();
117 public IPropertyDescriptor
[] getPropertyDescriptors() {
118 List
<IPropertyDescriptor
> descriptors
= new ArrayList
<>(fContent
.getFields().size());
119 for (ITmfEventField field
: fContent
.getFields()) {
121 descriptors
.add(new ReadOnlyTextPropertyDescriptor(field
, field
.getName()));
124 return descriptors
.toArray(new IPropertyDescriptor
[0]);
128 public Object
getPropertyValue(Object id
) {
129 ITmfEventField field
= (ITmfEventField
) id
;
130 if (!field
.getFields().isEmpty()) {
131 return new ContentPropertySource(field
);
133 return field
.getFormattedValue();
137 public boolean isPropertySet(Object id
) {
142 public void resetPropertyValue(Object id
) {
146 public void setPropertyValue(Object id
, Object value
) {
150 private static class SourceLookupPropertySource
implements IPropertySource
{
152 private static final String ID_FILE_NAME
= "callsite_file"; //$NON-NLS-1$
153 private static final String ID_FUNCTION_NAME
= "callsite_function"; //$NON-NLS-1$
154 private static final String ID_LINE_NUMBER
= "callsite_line"; //$NON-NLS-1$
156 private static final String NAME_FILE_NAME
= "File"; //$NON-NLS-1$
157 private static final String NAME_FUNCTION_NAME
= "Function"; //$NON-NLS-1$
158 private static final String NAME_LINE_NUMBER
= "Line"; //$NON-NLS-1$
160 private final ITmfSourceLookup fSourceLookup
;
162 public SourceLookupPropertySource(ITmfSourceLookup lookup
) {
163 fSourceLookup
= lookup
;
167 public Object
getEditableValue() {
168 ITmfCallsite cs
= fSourceLookup
.getCallsite();
170 return cs
.toString();
176 public IPropertyDescriptor
[] getPropertyDescriptors() {
177 List
<IPropertyDescriptor
> descriptors
= new ArrayList
<>();
178 ITmfCallsite cs
= fSourceLookup
.getCallsite();
180 descriptors
.add(new ReadOnlyTextPropertyDescriptor(ID_FILE_NAME
, NAME_FILE_NAME
));
181 descriptors
.add(new ReadOnlyTextPropertyDescriptor(ID_LINE_NUMBER
, NAME_LINE_NUMBER
));
182 // only display function if available
183 if (cs
.getFunctionName() != null) {
184 descriptors
.add(new ReadOnlyTextPropertyDescriptor(ID_FUNCTION_NAME
, NAME_FUNCTION_NAME
));
187 return descriptors
.toArray(new IPropertyDescriptor
[0]);
191 public Object
getPropertyValue(Object id
) {
192 ITmfCallsite cs
= fSourceLookup
.getCallsite();
195 * The callsite should not be null here, we would not have
196 * created the descriptors otherwise
198 throw new IllegalStateException();
201 if (!(id
instanceof String
)) {
205 switch ((String
) id
) {
207 return cs
.getFileName();
208 case ID_FUNCTION_NAME
:
209 return cs
.getFunctionName();
211 return Long
.valueOf(cs
.getLineNumber());
218 public boolean isPropertySet(Object id
) {
223 public void resetPropertyValue(Object id
) {
228 public void setPropertyValue(Object id
, Object value
) {
232 private class CustomAttributePropertySource
implements IPropertySource
{
234 private final ITmfCustomAttributes event
;
236 public CustomAttributePropertySource(ITmfCustomAttributes event
) {
241 public Object
getEditableValue() {
246 public IPropertyDescriptor
[] getPropertyDescriptors() {
247 List
<IPropertyDescriptor
> descriptors
= new ArrayList
<>();
249 for (String customAttribute
: event
.listCustomAttributes()) {
250 descriptors
.add(new ReadOnlyTextPropertyDescriptor(customAttribute
, customAttribute
));
253 return descriptors
.toArray(new IPropertyDescriptor
[0]);
257 public Object
getPropertyValue(Object id
) {
258 if (!(id
instanceof String
)) {
261 return event
.getCustomAttribute((String
) id
);
265 public boolean isPropertySet(Object id
) {
270 public void resetPropertyValue(Object id
) {
274 public void setPropertyValue(Object id
, Object value
) {
279 * Default constructor
281 * @param event the event
283 public TmfEventPropertySource(ITmfEvent event
) {
289 public Object
getEditableValue() {
294 public IPropertyDescriptor
[] getPropertyDescriptors() {
295 List
<IPropertyDescriptor
> descriptors
= new ArrayList
<>();
297 /* Display basic event information */
298 descriptors
.add(new ReadOnlyTextPropertyDescriptor(ID_TIMESTAMP
, NAME_TIMESTAMP
));
299 descriptors
.add(new ReadOnlyTextPropertyDescriptor(ID_TYPE
, NAME_TYPE
));
300 descriptors
.add(new ReadOnlyTextPropertyDescriptor(ID_TRACE
, NAME_TRACE
));
302 /* Display event fields */
303 descriptors
.add(new ReadOnlyTextPropertyDescriptor(ID_CONTENT
, NAME_CONTENT
));
305 /* Display source lookup information, if the event supplies it */
306 if ((fEvent
instanceof ITmfSourceLookup
) && (((ITmfSourceLookup
)fEvent
).getCallsite() != null)) {
307 descriptors
.add(new ReadOnlyTextPropertyDescriptor(ID_SOURCE_LOOKUP
, NAME_SOURCE_LOOKUP
));
310 /* Display Model URI information, if the event supplies it */
311 if ((fEvent
instanceof ITmfModelLookup
) && (((ITmfModelLookup
) fEvent
).getModelUri() != null)) {
312 descriptors
.add(new ReadOnlyTextPropertyDescriptor(ID_MODEL_URI
, NAME_MODEL_URI
));
315 /* Display custom attributes, if available */
316 if (fEvent
instanceof ITmfCustomAttributes
) {
317 ITmfCustomAttributes event
= (ITmfCustomAttributes
) fEvent
;
318 if (!event
.listCustomAttributes().isEmpty()) {
319 descriptors
.add(new ReadOnlyTextPropertyDescriptor(ID_CUSTOM_ATTRIBUTE
, NAME_CUSTOM_ATTRIBUTES
));
323 return descriptors
.toArray(new IPropertyDescriptor
[0]);
327 public Object
getPropertyValue(Object id
) {
328 if (id
.equals(ID_TIMESTAMP
)) {
329 return new TimestampPropertySource(fEvent
.getTimestamp());
330 } else if (id
.equals(ID_TYPE
) && fEvent
.getType() != null) {
331 return fEvent
.getType().toString();
332 } else if (id
.equals(ID_TRACE
)) {
333 return fEvent
.getTrace().getName();
334 } else if (id
.equals(ID_MODEL_URI
)) {
335 return ((ITmfModelLookup
)fEvent
).getModelUri();
336 } else if (id
.equals(ID_SOURCE_LOOKUP
)) {
337 return new SourceLookupPropertySource(((ITmfSourceLookup
)fEvent
));
338 } else if (id
.equals(ID_CONTENT
) && fEvent
.getContent() != null) {
339 return new ContentPropertySource(fEvent
.getContent());
340 } else if (id
.equals(ID_CUSTOM_ATTRIBUTE
)) {
341 return new CustomAttributePropertySource((ITmfCustomAttributes
) fEvent
);
347 public boolean isPropertySet(Object id
) {
352 public void resetPropertyValue(Object id
) {
356 public void setPropertyValue(Object id
, Object value
) {