1 /*******************************************************************************
2 * Copyright (c) 2012, 2013 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
.linuxtools
.tmf
.core
.event
;
16 import java
.util
.ArrayList
;
17 import java
.util
.List
;
19 import org
.eclipse
.linuxtools
.tmf
.core
.event
.lookup
.ITmfModelLookup
;
20 import org
.eclipse
.linuxtools
.tmf
.core
.event
.lookup
.ITmfSourceLookup
;
21 import org
.eclipse
.linuxtools
.tmf
.core
.timestamp
.ITmfTimestamp
;
22 import org
.eclipse
.linuxtools
.tmf
.core
.util
.ReadOnlyTextPropertyDescriptor
;
23 import org
.eclipse
.ui
.views
.properties
.IPropertyDescriptor
;
24 import org
.eclipse
.ui
.views
.properties
.IPropertySource
;
27 * Property source for events
31 public class TmfEventPropertySource
implements IPropertySource
{
33 private static final String ID_TIMESTAMP
= "event_timestamp"; //$NON-NLS-1$
34 private static final String ID_SOURCE
= "event_source"; //$NON-NLS-1$
35 private static final String ID_TYPE
= "event_type"; //$NON-NLS-1$
36 private static final String ID_REFERENCE
= "event_reference"; //$NON-NLS-1$
37 private static final String ID_CONTENT
= "event_content"; //$NON-NLS-1$
38 private static final String ID_SOURCE_LOOKUP
= "event_lookup"; //$NON-NLS-1$
39 private static final String ID_MODEL_URI
= "model_uri"; //$NON-NLS-1$
40 private static final String ID_CUSTOM_ATTRIBUTE
= "custom_attribute"; //$NON-NLS-1$
42 private static final String NAME_TIMESTAMP
= "Timestamp"; //$NON-NLS-1$
43 private static final String NAME_SOURCE
= "Source"; //$NON-NLS-1$
44 private static final String NAME_TYPE
= "Type"; //$NON-NLS-1$
45 private static final String NAME_REFERENCE
= "Reference"; //$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 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 ID_TIMESTAMP_PRECISION
= "timestamp_precision"; //$NON-NLS-1$
59 private static final String NAME_TIMESTAMP_VALUE
= "value"; //$NON-NLS-1$
60 private static final String NAME_TIMESTAMP_SCALE
= "scale"; //$NON-NLS-1$
61 private static final String NAME_TIMESTAMP_PRECISION
= "precision"; //$NON-NLS-1$
63 private ITmfTimestamp fTimestamp
;
65 public TimestampPropertySource(ITmfTimestamp timestamp
) {
66 fTimestamp
= timestamp
;
70 public Object
getEditableValue() {
71 return fTimestamp
.toString();
75 public IPropertyDescriptor
[] getPropertyDescriptors() {
76 IPropertyDescriptor
[] descriptors
= new IPropertyDescriptor
[3];
77 descriptors
[0] = new ReadOnlyTextPropertyDescriptor(ID_TIMESTAMP_VALUE
, NAME_TIMESTAMP_VALUE
);
78 descriptors
[1] = new ReadOnlyTextPropertyDescriptor(ID_TIMESTAMP_SCALE
, NAME_TIMESTAMP_SCALE
);
79 descriptors
[2] = new ReadOnlyTextPropertyDescriptor(ID_TIMESTAMP_PRECISION
, NAME_TIMESTAMP_PRECISION
);
84 public Object
getPropertyValue(Object id
) {
85 if (id
.equals(ID_TIMESTAMP_VALUE
)) {
86 return Long
.toString(fTimestamp
.getValue());
87 } else if (id
.equals(ID_TIMESTAMP_SCALE
)) {
88 return Integer
.toString(fTimestamp
.getScale());
89 } else if (id
.equals(ID_TIMESTAMP_PRECISION
)) {
90 return Integer
.toString(fTimestamp
.getPrecision());
96 public boolean isPropertySet(Object id
) {
101 public void resetPropertyValue(Object id
) {
105 public void setPropertyValue(Object id
, Object value
) {
109 private class ContentPropertySource
implements IPropertySource
{
110 private ITmfEventField fContent
;
112 public ContentPropertySource(ITmfEventField content
) {
117 public Object
getEditableValue() {
118 return fContent
.toString();
122 public IPropertyDescriptor
[] getPropertyDescriptors() {
123 List
<IPropertyDescriptor
> descriptors
= new ArrayList
<IPropertyDescriptor
>(fContent
.getFields().length
);
124 for (ITmfEventField field
: fContent
.getFields()) {
126 descriptors
.add(new ReadOnlyTextPropertyDescriptor(field
, field
.getName()));
129 return descriptors
.toArray(new IPropertyDescriptor
[0]);
133 public Object
getPropertyValue(Object id
) {
134 ITmfEventField field
= (ITmfEventField
) id
;
135 if (field
.getFields() != null && field
.getFields().length
> 0) {
136 return new ContentPropertySource(field
);
138 return field
.getFormattedValue();
142 public boolean isPropertySet(Object id
) {
147 public void resetPropertyValue(Object id
) {
151 public void setPropertyValue(Object id
, Object value
) {
155 private class SourceLookupPropertySource
implements IPropertySource
{
157 private static final String ID_FILE_NAME
= "callsite_file"; //$NON-NLS-1$
158 private static final String ID_FUNCTION_NAME
= "callsite_function"; //$NON-NLS-1$
159 private static final String ID_LINE_NUMBER
= "callsite_line"; //$NON-NLS-1$
161 private static final String NAME_FILE_NAME
= "File"; //$NON-NLS-1$
162 private static final String NAME_FUNCTION_NAME
= "Function"; //$NON-NLS-1$
163 private static final String NAME_LINE_NUMBER
= "Line"; //$NON-NLS-1$
165 final private ITmfSourceLookup fSourceLookup
;
167 public SourceLookupPropertySource(ITmfSourceLookup lookup
) {
168 fSourceLookup
= lookup
;
172 public Object
getEditableValue() {
173 if (fSourceLookup
.getCallsite() != null) {
174 return fSourceLookup
.getCallsite().toString();
180 public IPropertyDescriptor
[] getPropertyDescriptors() {
181 List
<IPropertyDescriptor
> descriptors
= new ArrayList
<IPropertyDescriptor
>();
182 if (fSourceLookup
.getCallsite() != null) {
183 descriptors
.add(new ReadOnlyTextPropertyDescriptor(ID_FILE_NAME
, NAME_FILE_NAME
));
184 descriptors
.add(new ReadOnlyTextPropertyDescriptor(ID_LINE_NUMBER
, NAME_LINE_NUMBER
));
185 // only display function if available
186 if (fSourceLookup
.getCallsite().getFunctionName() != null) {
187 descriptors
.add(new ReadOnlyTextPropertyDescriptor(ID_FUNCTION_NAME
, NAME_FUNCTION_NAME
));
190 return descriptors
.toArray(new IPropertyDescriptor
[0]);
194 public Object
getPropertyValue(Object id
) {
195 if (id
.equals(ID_FILE_NAME
)) {
196 return fSourceLookup
.getCallsite().getFileName();
197 } else if (id
.equals(ID_FUNCTION_NAME
)) {
198 return fSourceLookup
.getCallsite().getFunctionName();
199 } else if (id
.equals(ID_LINE_NUMBER
)) {
200 return Long
.valueOf(fSourceLookup
.getCallsite().getLineNumber());
206 public boolean isPropertySet(Object id
) {
211 public void resetPropertyValue(Object id
) {
216 public void setPropertyValue(Object id
, Object value
) {
220 private class CustomAttributePropertySource
implements IPropertySource
{
222 private final ITmfCustomAttributes event
;
224 public CustomAttributePropertySource(ITmfCustomAttributes event
) {
229 public Object
getEditableValue() {
234 public IPropertyDescriptor
[] getPropertyDescriptors() {
235 List
<IPropertyDescriptor
> descriptors
= new ArrayList
<IPropertyDescriptor
>();
237 for (String customAttribute
: event
.listCustomAttributes()) {
238 descriptors
.add(new ReadOnlyTextPropertyDescriptor(customAttribute
, customAttribute
));
241 return descriptors
.toArray(new IPropertyDescriptor
[0]);
245 public Object
getPropertyValue(Object id
) {
246 return event
.getCustomAttribute((String
) id
);
250 public boolean isPropertySet(Object id
) {
255 public void resetPropertyValue(Object id
) {
259 public void setPropertyValue(Object id
, Object value
) {
264 * Default constructor
266 * @param event the event
268 public TmfEventPropertySource(ITmfEvent event
) {
274 public Object
getEditableValue() {
279 public IPropertyDescriptor
[] getPropertyDescriptors() {
280 List
<IPropertyDescriptor
> descriptors
= new ArrayList
<IPropertyDescriptor
>();
282 /* Display basic event information */
283 descriptors
.add(new ReadOnlyTextPropertyDescriptor(ID_TIMESTAMP
, NAME_TIMESTAMP
));
284 descriptors
.add(new ReadOnlyTextPropertyDescriptor(ID_SOURCE
, NAME_SOURCE
));
285 descriptors
.add(new ReadOnlyTextPropertyDescriptor(ID_TYPE
, NAME_TYPE
));
286 descriptors
.add(new ReadOnlyTextPropertyDescriptor(ID_REFERENCE
, NAME_REFERENCE
));
288 /* Display event fields */
289 descriptors
.add(new ReadOnlyTextPropertyDescriptor(ID_CONTENT
, NAME_CONTENT
));
291 /* Display source lookup information, if the event supplies it */
292 if ((fEvent
instanceof ITmfSourceLookup
) && (((ITmfSourceLookup
)fEvent
).getCallsite() != null)) {
293 descriptors
.add(new ReadOnlyTextPropertyDescriptor(ID_SOURCE_LOOKUP
, NAME_SOURCE_LOOKUP
));
296 /* Display Model URI information, if the event supplies it */
297 if ((fEvent
instanceof ITmfModelLookup
) && (((ITmfModelLookup
) fEvent
).getModelUri() != null)) {
298 descriptors
.add(new ReadOnlyTextPropertyDescriptor(ID_MODEL_URI
, NAME_MODEL_URI
));
301 /* Display custom attributes, if available */
302 if (fEvent
instanceof ITmfCustomAttributes
) {
303 ITmfCustomAttributes event
= (ITmfCustomAttributes
) fEvent
;
304 if (event
.listCustomAttributes() != null && !event
.listCustomAttributes().isEmpty()) {
305 descriptors
.add(new ReadOnlyTextPropertyDescriptor(ID_CUSTOM_ATTRIBUTE
, NAME_CUSTOM_ATTRIBUTES
));
309 return descriptors
.toArray(new IPropertyDescriptor
[0]);
313 public Object
getPropertyValue(Object id
) {
314 if (id
.equals(ID_TIMESTAMP
) && fEvent
.getTimestamp() != null) {
315 return new TimestampPropertySource(fEvent
.getTimestamp());
316 } else if (id
.equals(ID_SOURCE
) && fEvent
.getSource() != null) {
317 return fEvent
.getSource().toString();
318 } else if (id
.equals(ID_TYPE
) && fEvent
.getType() != null) {
319 return fEvent
.getType().toString();
320 } else if (id
.equals(ID_REFERENCE
) && fEvent
.getReference() != null) {
321 return fEvent
.getReference().toString();
322 } else if (id
.equals(ID_MODEL_URI
)) {
323 return ((ITmfModelLookup
)fEvent
).getModelUri();
324 } else if (id
.equals(ID_SOURCE_LOOKUP
)) {
325 return new SourceLookupPropertySource(((ITmfSourceLookup
)fEvent
));
326 } else if (id
.equals(ID_CONTENT
) && fEvent
.getContent() != null) {
327 return new ContentPropertySource(fEvent
.getContent());
328 } else if (id
.equals(ID_CUSTOM_ATTRIBUTE
)) {
329 return new CustomAttributePropertySource((ITmfCustomAttributes
) fEvent
);
335 public boolean isPropertySet(Object id
) {
340 public void resetPropertyValue(Object id
) {
344 public void setPropertyValue(Object id
, Object value
) {