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 static org
.eclipse
.tracecompass
.common
.core
.NonNullUtils
.nullToEmptyString
;
18 import java
.util
.ArrayList
;
19 import java
.util
.List
;
21 import org
.eclipse
.tracecompass
.tmf
.core
.event
.ITmfCustomAttributes
;
22 import org
.eclipse
.tracecompass
.tmf
.core
.event
.ITmfEvent
;
23 import org
.eclipse
.tracecompass
.tmf
.core
.event
.ITmfEventField
;
24 import org
.eclipse
.tracecompass
.tmf
.core
.event
.lookup
.ITmfCallsite
;
25 import org
.eclipse
.tracecompass
.tmf
.core
.event
.lookup
.ITmfModelLookup
;
26 import org
.eclipse
.tracecompass
.tmf
.core
.event
.lookup
.ITmfSourceLookup
;
27 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.ITmfTimestamp
;
28 import org
.eclipse
.tracecompass
.tmf
.ui
.properties
.ReadOnlyTextPropertyDescriptor
;
29 import org
.eclipse
.ui
.views
.properties
.IPropertyDescriptor
;
30 import org
.eclipse
.ui
.views
.properties
.IPropertySource
;
33 * Property source for events
35 public class TmfEventPropertySource
implements IPropertySource
{
37 private static final String ID_TIMESTAMP
= "event_timestamp"; //$NON-NLS-1$
38 private static final String ID_TYPE
= "event_type"; //$NON-NLS-1$
39 private static final String ID_TRACE
= "trace_attribute"; //$NON-NLS-1$
40 private static final String ID_CONTENT
= "event_content"; //$NON-NLS-1$
41 private static final String ID_SOURCE_LOOKUP
= "event_lookup"; //$NON-NLS-1$
42 private static final String ID_MODEL_URI
= "model_uri"; //$NON-NLS-1$
43 private static final String ID_CUSTOM_ATTRIBUTE
= "custom_attribute"; //$NON-NLS-1$
45 private static final String NAME_TIMESTAMP
= "Timestamp"; //$NON-NLS-1$
46 private static final String NAME_TYPE
= "Type"; //$NON-NLS-1$
47 private static final String NAME_TRACE
= "Trace"; //$NON-NLS-1$
48 private static final String NAME_CONTENT
= "Content"; //$NON-NLS-1$
49 private static final String NAME_SOURCE_LOOKUP
= "Source Lookup"; //$NON-NLS-1$
50 private static final String NAME_MODEL_URI
= "Model URI"; //$NON-NLS-1$
51 private static final String NAME_CUSTOM_ATTRIBUTES
= "Custom Attributes"; //$NON-NLS-1$
53 private static final String EMPTY_STRING
= ""; //$NON-NLS-1$
55 private ITmfEvent fEvent
;
57 private static class TimestampPropertySource
implements IPropertySource
{
58 private static final String ID_TIMESTAMP_VALUE
= "timestamp_value"; //$NON-NLS-1$
59 private static final String ID_TIMESTAMP_SCALE
= "timestamp_scale"; //$NON-NLS-1$
60 private static final String NAME_TIMESTAMP_VALUE
= "value"; //$NON-NLS-1$
61 private static final String NAME_TIMESTAMP_SCALE
= "scale"; //$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
[2];
77 descriptors
[0] = new ReadOnlyTextPropertyDescriptor(ID_TIMESTAMP_VALUE
, NAME_TIMESTAMP_VALUE
);
78 descriptors
[1] = new ReadOnlyTextPropertyDescriptor(ID_TIMESTAMP_SCALE
, NAME_TIMESTAMP_SCALE
);
83 public Object
getPropertyValue(Object id
) {
84 if (id
.equals(ID_TIMESTAMP_VALUE
)) {
85 return Long
.toString(fTimestamp
.getValue());
86 } else if (id
.equals(ID_TIMESTAMP_SCALE
)) {
87 return Integer
.toString(fTimestamp
.getScale());
93 public boolean isPropertySet(Object id
) {
98 public void resetPropertyValue(Object id
) {
102 public void setPropertyValue(Object id
, Object value
) {
106 private static class ContentPropertySource
implements IPropertySource
{
107 private ITmfEventField fContent
;
109 public ContentPropertySource(ITmfEventField content
) {
114 public Object
getEditableValue() {
115 return fContent
.toString();
119 public IPropertyDescriptor
[] getPropertyDescriptors() {
120 List
<IPropertyDescriptor
> descriptors
= new ArrayList
<>(fContent
.getFields().size());
121 for (ITmfEventField field
: fContent
.getFields()) {
123 descriptors
.add(new ReadOnlyTextPropertyDescriptor(field
, field
.getName()));
126 return descriptors
.toArray(new IPropertyDescriptor
[0]);
130 public Object
getPropertyValue(Object id
) {
131 ITmfEventField field
= (ITmfEventField
) id
;
132 if (!field
.getFields().isEmpty()) {
133 return new ContentPropertySource(field
);
135 return field
.getFormattedValue();
139 public boolean isPropertySet(Object id
) {
144 public void resetPropertyValue(Object id
) {
148 public void setPropertyValue(Object id
, Object value
) {
152 private static class SourceLookupPropertySource
implements IPropertySource
{
154 private static final String ID_FILE_NAME
= "callsite_file"; //$NON-NLS-1$
155 private static final String ID_LINE_NUMBER
= "callsite_line"; //$NON-NLS-1$
157 private static final String NAME_FILE_NAME
= "File"; //$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
));
183 return descriptors
.toArray(new IPropertyDescriptor
[0]);
187 public String
getPropertyValue(Object id
) {
188 ITmfCallsite cs
= fSourceLookup
.getCallsite();
191 * The callsite should not be null here, we would not have
192 * created the descriptors otherwise
194 throw new IllegalStateException();
197 if (!(id
instanceof String
)) {
201 switch ((String
) id
) {
203 return cs
.getFileName();
205 return nullToEmptyString(cs
.getLineNo());
212 public boolean isPropertySet(Object id
) {
217 public void resetPropertyValue(Object id
) {
222 public void setPropertyValue(Object id
, Object value
) {
226 private class CustomAttributePropertySource
implements IPropertySource
{
228 private final ITmfCustomAttributes event
;
230 public CustomAttributePropertySource(ITmfCustomAttributes event
) {
235 public Object
getEditableValue() {
240 public IPropertyDescriptor
[] getPropertyDescriptors() {
241 List
<IPropertyDescriptor
> descriptors
= new ArrayList
<>();
243 for (String customAttribute
: event
.listCustomAttributes()) {
244 descriptors
.add(new ReadOnlyTextPropertyDescriptor(customAttribute
, customAttribute
));
247 return descriptors
.toArray(new IPropertyDescriptor
[0]);
251 public Object
getPropertyValue(Object id
) {
252 if (!(id
instanceof String
)) {
255 return event
.getCustomAttribute((String
) id
);
259 public boolean isPropertySet(Object id
) {
264 public void resetPropertyValue(Object id
) {
268 public void setPropertyValue(Object id
, Object value
) {
273 * Default constructor
275 * @param event the event
277 public TmfEventPropertySource(ITmfEvent event
) {
283 public Object
getEditableValue() {
288 public IPropertyDescriptor
[] getPropertyDescriptors() {
289 List
<IPropertyDescriptor
> descriptors
= new ArrayList
<>();
291 /* Display basic event information */
292 descriptors
.add(new ReadOnlyTextPropertyDescriptor(ID_TIMESTAMP
, NAME_TIMESTAMP
));
293 descriptors
.add(new ReadOnlyTextPropertyDescriptor(ID_TYPE
, NAME_TYPE
));
294 descriptors
.add(new ReadOnlyTextPropertyDescriptor(ID_TRACE
, NAME_TRACE
));
296 /* Display event fields */
297 descriptors
.add(new ReadOnlyTextPropertyDescriptor(ID_CONTENT
, NAME_CONTENT
));
299 /* Display source lookup information, if the event supplies it */
300 if ((fEvent
instanceof ITmfSourceLookup
) && (((ITmfSourceLookup
)fEvent
).getCallsite() != null)) {
301 descriptors
.add(new ReadOnlyTextPropertyDescriptor(ID_SOURCE_LOOKUP
, NAME_SOURCE_LOOKUP
));
304 /* Display Model URI information, if the event supplies it */
305 if ((fEvent
instanceof ITmfModelLookup
) && (((ITmfModelLookup
) fEvent
).getModelUri() != null)) {
306 descriptors
.add(new ReadOnlyTextPropertyDescriptor(ID_MODEL_URI
, NAME_MODEL_URI
));
309 /* Display custom attributes, if available */
310 if (fEvent
instanceof ITmfCustomAttributes
) {
311 ITmfCustomAttributes event
= (ITmfCustomAttributes
) fEvent
;
312 if (!event
.listCustomAttributes().isEmpty()) {
313 descriptors
.add(new ReadOnlyTextPropertyDescriptor(ID_CUSTOM_ATTRIBUTE
, NAME_CUSTOM_ATTRIBUTES
));
317 return descriptors
.toArray(new IPropertyDescriptor
[0]);
321 public Object
getPropertyValue(Object id
) {
322 if (id
.equals(ID_TIMESTAMP
)) {
323 return new TimestampPropertySource(fEvent
.getTimestamp());
324 } else if (id
.equals(ID_TYPE
) && fEvent
.getType() != null) {
325 return fEvent
.getType().toString();
326 } else if (id
.equals(ID_TRACE
)) {
327 return fEvent
.getTrace().getName();
328 } else if (id
.equals(ID_MODEL_URI
)) {
329 return ((ITmfModelLookup
)fEvent
).getModelUri();
330 } else if (id
.equals(ID_SOURCE_LOOKUP
)) {
331 return new SourceLookupPropertySource(((ITmfSourceLookup
)fEvent
));
332 } else if (id
.equals(ID_CONTENT
) && fEvent
.getContent() != null) {
333 return new ContentPropertySource(fEvent
.getContent());
334 } else if (id
.equals(ID_CUSTOM_ATTRIBUTE
)) {
335 return new CustomAttributePropertySource((ITmfCustomAttributes
) fEvent
);
341 public boolean isPropertySet(Object id
) {
346 public void resetPropertyValue(Object id
) {
350 public void setPropertyValue(Object id
, Object value
) {