Commit | Line | Data |
---|---|---|
93bfd50a | 1 | /******************************************************************************* |
61759503 | 2 | * Copyright (c) 2012, 2013 Ericsson |
93bfd50a PT |
3 | * |
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 | |
8 | * | |
9 | * Contributors: | |
10 | * Patrick Tasse - Initial API and implementation | |
f47ed727 | 11 | * Bernd Hufmann - Added call site and model URI properties |
93bfd50a PT |
12 | *******************************************************************************/ |
13 | ||
14 | package org.eclipse.linuxtools.tmf.core.event; | |
15 | ||
16 | import java.util.ArrayList; | |
17 | import java.util.List; | |
18 | ||
f47ed727 BH |
19 | import org.eclipse.linuxtools.tmf.core.event.lookup.ITmfModelLookup; |
20 | import org.eclipse.linuxtools.tmf.core.event.lookup.ITmfSourceLookup; | |
3bd46eef | 21 | import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp; |
0505c6fc | 22 | import org.eclipse.linuxtools.tmf.core.util.ReadOnlyTextPropertyDescriptor; |
93bfd50a PT |
23 | import org.eclipse.ui.views.properties.IPropertyDescriptor; |
24 | import org.eclipse.ui.views.properties.IPropertySource; | |
93bfd50a PT |
25 | |
26 | /** | |
27 | * Property source for events | |
28 | * | |
29 | * @since 2.0 | |
30 | */ | |
31 | public class TmfEventPropertySource implements IPropertySource { | |
32 | ||
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$ | |
f47ed727 BH |
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$ | |
860b76d4 | 40 | private static final String ID_CUSTOM_ATTRIBUTE = "custom_attribute"; //$NON-NLS-1$ |
f47ed727 | 41 | |
93bfd50a PT |
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$ | |
860b76d4 | 47 | private static final String NAME_SOURCE_LOOKUP = "Source Lookup"; //$NON-NLS-1$ |
f47ed727 | 48 | private static final String NAME_MODEL_URI = "Model URI"; //$NON-NLS-1$ |
860b76d4 | 49 | private static final String NAME_CUSTOM_ATTRIBUTES = "Custom Attributes"; //$NON-NLS-1$ |
f47ed727 | 50 | |
860b76d4 | 51 | private static final String EMPTY_STRING = ""; //$NON-NLS-1$ |
93bfd50a PT |
52 | |
53 | private ITmfEvent fEvent; | |
54 | ||
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$ | |
62 | ||
63 | private ITmfTimestamp fTimestamp; | |
64 | ||
65 | public TimestampPropertySource(ITmfTimestamp timestamp) { | |
66 | fTimestamp = timestamp; | |
67 | } | |
68 | ||
69 | @Override | |
70 | public Object getEditableValue() { | |
71 | return fTimestamp.toString(); | |
72 | } | |
73 | ||
74 | @Override | |
75 | public IPropertyDescriptor[] getPropertyDescriptors() { | |
76 | IPropertyDescriptor[] descriptors = new IPropertyDescriptor[3]; | |
0505c6fc BH |
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); | |
93bfd50a PT |
80 | return descriptors; |
81 | } | |
82 | ||
83 | @Override | |
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()); | |
91 | } | |
92 | return null; | |
93 | } | |
94 | ||
95 | @Override | |
96 | public boolean isPropertySet(Object id) { | |
97 | return false; | |
98 | } | |
99 | ||
100 | @Override | |
101 | public void resetPropertyValue(Object id) { | |
102 | } | |
103 | ||
104 | @Override | |
105 | public void setPropertyValue(Object id, Object value) { | |
106 | } | |
107 | } | |
108 | ||
109 | private class ContentPropertySource implements IPropertySource { | |
110 | private ITmfEventField fContent; | |
111 | ||
112 | public ContentPropertySource(ITmfEventField content) { | |
113 | fContent = content; | |
114 | } | |
115 | ||
116 | @Override | |
117 | public Object getEditableValue() { | |
118 | return fContent.toString(); | |
119 | } | |
120 | ||
121 | @Override | |
122 | public IPropertyDescriptor[] getPropertyDescriptors() { | |
123 | List<IPropertyDescriptor> descriptors= new ArrayList<IPropertyDescriptor>(fContent.getFields().length); | |
124 | for (ITmfEventField field : fContent.getFields()) { | |
125 | if (field != null) { | |
0505c6fc | 126 | descriptors.add(new ReadOnlyTextPropertyDescriptor(field, field.getName())); |
93bfd50a PT |
127 | } |
128 | } | |
129 | return descriptors.toArray(new IPropertyDescriptor[0]); | |
130 | } | |
131 | ||
132 | @Override | |
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); | |
137 | } | |
8f86c552 | 138 | return field.getFormattedValue(); |
93bfd50a PT |
139 | } |
140 | ||
141 | @Override | |
142 | public boolean isPropertySet(Object id) { | |
143 | return false; | |
144 | } | |
145 | ||
146 | @Override | |
147 | public void resetPropertyValue(Object id) { | |
148 | } | |
149 | ||
150 | @Override | |
151 | public void setPropertyValue(Object id, Object value) { | |
152 | } | |
153 | } | |
154 | ||
f47ed727 BH |
155 | private class SourceLookupPropertySource implements IPropertySource { |
156 | ||
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$ | |
160 | ||
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$ | |
164 | ||
165 | final private ITmfSourceLookup fSourceLookup; | |
166 | ||
167 | public SourceLookupPropertySource(ITmfSourceLookup lookup) { | |
168 | fSourceLookup = lookup; | |
169 | } | |
170 | ||
171 | @Override | |
172 | public Object getEditableValue() { | |
173 | if (fSourceLookup.getCallsite() != null) { | |
174 | return fSourceLookup.getCallsite().toString(); | |
175 | } | |
176 | return null; | |
177 | } | |
178 | ||
179 | @Override | |
180 | public IPropertyDescriptor[] getPropertyDescriptors() { | |
181 | List<IPropertyDescriptor> descriptors= new ArrayList<IPropertyDescriptor>(); | |
182 | if (fSourceLookup.getCallsite() != null) { | |
0505c6fc BH |
183 | descriptors.add(new ReadOnlyTextPropertyDescriptor(ID_FILE_NAME, NAME_FILE_NAME)); |
184 | descriptors.add(new ReadOnlyTextPropertyDescriptor(ID_LINE_NUMBER, NAME_LINE_NUMBER)); | |
f47ed727 BH |
185 | // only display function if available |
186 | if (fSourceLookup.getCallsite().getFunctionName() != null) { | |
0505c6fc | 187 | descriptors.add(new ReadOnlyTextPropertyDescriptor(ID_FUNCTION_NAME, NAME_FUNCTION_NAME)); |
f47ed727 BH |
188 | } |
189 | } | |
190 | return descriptors.toArray(new IPropertyDescriptor[0]); | |
191 | } | |
192 | ||
193 | @Override | |
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()); | |
201 | } | |
202 | return null; | |
203 | } | |
204 | ||
205 | @Override | |
206 | public boolean isPropertySet(Object id) { | |
207 | return false; | |
208 | } | |
209 | ||
210 | @Override | |
211 | public void resetPropertyValue(Object id) { | |
212 | ||
213 | } | |
214 | ||
215 | @Override | |
216 | public void setPropertyValue(Object id, Object value) { | |
217 | } | |
218 | } | |
219 | ||
860b76d4 SD |
220 | private class CustomAttributePropertySource implements IPropertySource { |
221 | ||
222 | private final ITmfCustomAttributes event; | |
223 | ||
224 | public CustomAttributePropertySource(ITmfCustomAttributes event) { | |
225 | this.event = event; | |
226 | } | |
227 | ||
228 | @Override | |
229 | public Object getEditableValue() { | |
230 | return EMPTY_STRING; | |
231 | } | |
232 | ||
233 | @Override | |
234 | public IPropertyDescriptor[] getPropertyDescriptors() { | |
235 | List<IPropertyDescriptor> descriptors = new ArrayList<IPropertyDescriptor>(); | |
236 | ||
237 | for (String customAttribute : event.listCustomAttributes()) { | |
238 | descriptors.add(new ReadOnlyTextPropertyDescriptor(customAttribute, customAttribute)); | |
239 | } | |
240 | ||
241 | return descriptors.toArray(new IPropertyDescriptor[0]); | |
242 | } | |
243 | ||
244 | @Override | |
245 | public Object getPropertyValue(Object id) { | |
246 | return event.getCustomAttribute((String) id); | |
247 | } | |
248 | ||
249 | @Override | |
250 | public boolean isPropertySet(Object id) { | |
251 | return false; | |
252 | } | |
253 | ||
254 | @Override | |
255 | public void resetPropertyValue(Object id) { | |
256 | } | |
257 | ||
258 | @Override | |
259 | public void setPropertyValue(Object id, Object value) { | |
260 | } | |
261 | } | |
f47ed727 | 262 | |
93bfd50a PT |
263 | /** |
264 | * Default constructor | |
265 | * | |
266 | * @param event the event | |
267 | */ | |
268 | public TmfEventPropertySource(ITmfEvent event) { | |
269 | super(); | |
270 | this.fEvent = event; | |
271 | } | |
272 | ||
273 | @Override | |
274 | public Object getEditableValue() { | |
275 | return null; | |
276 | } | |
277 | ||
278 | @Override | |
279 | public IPropertyDescriptor[] getPropertyDescriptors() { | |
f47ed727 | 280 | List<IPropertyDescriptor> descriptors= new ArrayList<IPropertyDescriptor>(); |
860b76d4 SD |
281 | |
282 | /* Display basic event information */ | |
0505c6fc BH |
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)); | |
860b76d4 SD |
287 | |
288 | /* Display event fields */ | |
289 | descriptors.add(new ReadOnlyTextPropertyDescriptor(ID_CONTENT, NAME_CONTENT)); | |
290 | ||
291 | /* Display source lookup information, if the event supplies it */ | |
f47ed727 | 292 | if ((fEvent instanceof ITmfSourceLookup) && (((ITmfSourceLookup)fEvent).getCallsite() != null)) { |
0505c6fc | 293 | descriptors.add(new ReadOnlyTextPropertyDescriptor(ID_SOURCE_LOOKUP, NAME_SOURCE_LOOKUP)); |
f47ed727 | 294 | } |
860b76d4 SD |
295 | |
296 | /* Display Model URI information, if the event supplies it */ | |
297 | if ((fEvent instanceof ITmfModelLookup) && (((ITmfModelLookup) fEvent).getModelUri() != null)) { | |
0505c6fc | 298 | descriptors.add(new ReadOnlyTextPropertyDescriptor(ID_MODEL_URI, NAME_MODEL_URI)); |
f47ed727 | 299 | } |
860b76d4 SD |
300 | |
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)); | |
306 | } | |
307 | } | |
308 | ||
f47ed727 | 309 | return descriptors.toArray(new IPropertyDescriptor[0]); |
93bfd50a PT |
310 | } |
311 | ||
312 | @Override | |
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(); | |
f47ed727 BH |
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)); | |
93bfd50a PT |
326 | } else if (id.equals(ID_CONTENT) && fEvent.getContent() != null) { |
327 | return new ContentPropertySource(fEvent.getContent()); | |
860b76d4 SD |
328 | } else if (id.equals(ID_CUSTOM_ATTRIBUTE)) { |
329 | return new CustomAttributePropertySource((ITmfCustomAttributes) fEvent); | |
93bfd50a PT |
330 | } |
331 | return null; | |
332 | } | |
333 | ||
334 | @Override | |
335 | public boolean isPropertySet(Object id) { | |
336 | return false; | |
337 | } | |
338 | ||
339 | @Override | |
340 | public void resetPropertyValue(Object id) { | |
341 | } | |
342 | ||
343 | @Override | |
344 | public void setPropertyValue(Object id, Object value) { | |
345 | } | |
346 | ||
347 | } |