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
.ui
.views
.properties
.IPropertyDescriptor
;
23 import org
.eclipse
.ui
.views
.properties
.IPropertySource
;
24 import org
.eclipse
.ui
.views
.properties
.PropertyDescriptor
;
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$
41 private static final String NAME_TIMESTAMP
= "Timestamp"; //$NON-NLS-1$
42 private static final String NAME_SOURCE
= "Source"; //$NON-NLS-1$
43 private static final String NAME_TYPE
= "Type"; //$NON-NLS-1$
44 private static final String NAME_REFERENCE
= "Reference"; //$NON-NLS-1$
45 private static final String NAME_CONTENT
= "Content"; //$NON-NLS-1$
46 private static final String NAME_SOURCE_LOOKUP
= "Call Site"; //$NON-NLS-1$
47 private static final String NAME_MODEL_URI
= "Model URI"; //$NON-NLS-1$
50 private ITmfEvent fEvent
;
52 private class TimestampPropertySource
implements IPropertySource
{
53 private static final String ID_TIMESTAMP_VALUE
= "timestamp_value"; //$NON-NLS-1$
54 private static final String ID_TIMESTAMP_SCALE
= "timestamp_scale"; //$NON-NLS-1$
55 private static final String ID_TIMESTAMP_PRECISION
= "timestamp_precision"; //$NON-NLS-1$
56 private static final String NAME_TIMESTAMP_VALUE
= "value"; //$NON-NLS-1$
57 private static final String NAME_TIMESTAMP_SCALE
= "scale"; //$NON-NLS-1$
58 private static final String NAME_TIMESTAMP_PRECISION
= "precision"; //$NON-NLS-1$
60 private ITmfTimestamp fTimestamp
;
62 public TimestampPropertySource(ITmfTimestamp timestamp
) {
63 fTimestamp
= timestamp
;
67 public Object
getEditableValue() {
68 return fTimestamp
.toString();
72 public IPropertyDescriptor
[] getPropertyDescriptors() {
73 IPropertyDescriptor
[] descriptors
= new IPropertyDescriptor
[3];
74 descriptors
[0] = new PropertyDescriptor(ID_TIMESTAMP_VALUE
, NAME_TIMESTAMP_VALUE
);
75 descriptors
[1] = new PropertyDescriptor(ID_TIMESTAMP_SCALE
, NAME_TIMESTAMP_SCALE
);
76 descriptors
[2] = new PropertyDescriptor(ID_TIMESTAMP_PRECISION
, NAME_TIMESTAMP_PRECISION
);
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());
86 } else if (id
.equals(ID_TIMESTAMP_PRECISION
)) {
87 return Integer
.toString(fTimestamp
.getPrecision());
93 public boolean isPropertySet(Object id
) {
98 public void resetPropertyValue(Object id
) {
102 public void setPropertyValue(Object id
, Object value
) {
106 private 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
<IPropertyDescriptor
>(fContent
.getFields().length
);
121 for (ITmfEventField field
: fContent
.getFields()) {
123 descriptors
.add(new PropertyDescriptor(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() != null && field
.getFields().length
> 0) {
133 return new ContentPropertySource(field
);
135 return field
.getValue();
139 public boolean isPropertySet(Object id
) {
144 public void resetPropertyValue(Object id
) {
148 public void setPropertyValue(Object id
, Object value
) {
152 private class SourceLookupPropertySource
implements IPropertySource
{
154 private static final String ID_FILE_NAME
= "callsite_file"; //$NON-NLS-1$
155 private static final String ID_FUNCTION_NAME
= "callsite_function"; //$NON-NLS-1$
156 private static final String ID_LINE_NUMBER
= "callsite_line"; //$NON-NLS-1$
158 private static final String NAME_FILE_NAME
= "File"; //$NON-NLS-1$
159 private static final String NAME_FUNCTION_NAME
= "Function"; //$NON-NLS-1$
160 private static final String NAME_LINE_NUMBER
= "Line"; //$NON-NLS-1$
162 final private ITmfSourceLookup fSourceLookup
;
164 public SourceLookupPropertySource(ITmfSourceLookup lookup
) {
165 fSourceLookup
= lookup
;
169 public Object
getEditableValue() {
170 if (fSourceLookup
.getCallsite() != null) {
171 return fSourceLookup
.getCallsite().toString();
177 public IPropertyDescriptor
[] getPropertyDescriptors() {
178 List
<IPropertyDescriptor
> descriptors
= new ArrayList
<IPropertyDescriptor
>();
179 if (fSourceLookup
.getCallsite() != null) {
180 descriptors
.add(new PropertyDescriptor(ID_FILE_NAME
, NAME_FILE_NAME
));
181 descriptors
.add(new PropertyDescriptor(ID_LINE_NUMBER
, NAME_LINE_NUMBER
));
182 // only display function if available
183 if (fSourceLookup
.getCallsite().getFunctionName() != null) {
184 descriptors
.add(new PropertyDescriptor(ID_FUNCTION_NAME
, NAME_FUNCTION_NAME
));
187 return descriptors
.toArray(new IPropertyDescriptor
[0]);
191 public Object
getPropertyValue(Object id
) {
192 if (id
.equals(ID_FILE_NAME
)) {
193 return fSourceLookup
.getCallsite().getFileName();
194 } else if (id
.equals(ID_FUNCTION_NAME
)) {
195 return fSourceLookup
.getCallsite().getFunctionName();
196 } else if (id
.equals(ID_LINE_NUMBER
)) {
197 return Long
.valueOf(fSourceLookup
.getCallsite().getLineNumber());
203 public boolean isPropertySet(Object id
) {
208 public void resetPropertyValue(Object id
) {
213 public void setPropertyValue(Object id
, Object value
) {
219 * Default constructor
221 * @param event the event
223 public TmfEventPropertySource(ITmfEvent event
) {
229 public Object
getEditableValue() {
234 public IPropertyDescriptor
[] getPropertyDescriptors() {
235 List
<IPropertyDescriptor
> descriptors
= new ArrayList
<IPropertyDescriptor
>();
236 descriptors
.add(new PropertyDescriptor(ID_TIMESTAMP
, NAME_TIMESTAMP
));
237 descriptors
.add(new PropertyDescriptor(ID_SOURCE
, NAME_SOURCE
));
238 descriptors
.add(new PropertyDescriptor(ID_TYPE
, NAME_TYPE
));
239 descriptors
.add(new PropertyDescriptor(ID_REFERENCE
, NAME_REFERENCE
));
240 if ((fEvent
instanceof ITmfSourceLookup
) && (((ITmfSourceLookup
)fEvent
).getCallsite() != null)) {
241 descriptors
.add(new PropertyDescriptor(ID_SOURCE_LOOKUP
, NAME_SOURCE_LOOKUP
));
243 if ((fEvent
instanceof ITmfModelLookup
) && (((ITmfModelLookup
)fEvent
).getModelUri() != null)) {
244 descriptors
.add(new PropertyDescriptor(ID_MODEL_URI
, NAME_MODEL_URI
));
246 descriptors
.add(new PropertyDescriptor(ID_CONTENT
, NAME_CONTENT
));
247 return descriptors
.toArray(new IPropertyDescriptor
[0]);
251 public Object
getPropertyValue(Object id
) {
252 if (id
.equals(ID_TIMESTAMP
) && fEvent
.getTimestamp() != null) {
253 return new TimestampPropertySource(fEvent
.getTimestamp());
254 } else if (id
.equals(ID_SOURCE
) && fEvent
.getSource() != null) {
255 return fEvent
.getSource().toString();
256 } else if (id
.equals(ID_TYPE
) && fEvent
.getType() != null) {
257 return fEvent
.getType().toString();
258 } else if (id
.equals(ID_REFERENCE
) && fEvent
.getReference() != null) {
259 return fEvent
.getReference().toString();
260 } else if (id
.equals(ID_MODEL_URI
)) {
261 return ((ITmfModelLookup
)fEvent
).getModelUri();
262 } else if (id
.equals(ID_SOURCE_LOOKUP
)) {
263 return new SourceLookupPropertySource(((ITmfSourceLookup
)fEvent
));
264 } else if (id
.equals(ID_CONTENT
) && fEvent
.getContent() != null) {
265 return new ContentPropertySource(fEvent
.getContent());
271 public boolean isPropertySet(Object id
) {
276 public void resetPropertyValue(Object id
) {
280 public void setPropertyValue(Object id
, Object value
) {