Commit | Line | Data |
---|---|---|
93bfd50a | 1 | /******************************************************************************* |
ed902a2b | 2 | * Copyright (c) 2012, 2014 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: | |
080600d9 MAL |
10 | * Patrick Tasse - Initial API and implementation |
11 | * Bernd Hufmann - Added call site and model URI properties | |
93bfd50a PT |
12 | *******************************************************************************/ |
13 | ||
2bdf0193 | 14 | package org.eclipse.tracecompass.tmf.ui.viewers.events; |
93bfd50a PT |
15 | |
16 | import java.util.ArrayList; | |
17 | import java.util.List; | |
18 | ||
2bdf0193 AM |
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; | |
04ca66e5 | 22 | import org.eclipse.tracecompass.tmf.core.event.lookup.ITmfCallsite; |
2bdf0193 AM |
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; | |
93bfd50a PT |
27 | import org.eclipse.ui.views.properties.IPropertyDescriptor; |
28 | import org.eclipse.ui.views.properties.IPropertySource; | |
93bfd50a PT |
29 | |
30 | /** | |
31 | * Property source for events | |
93bfd50a PT |
32 | */ |
33 | public class TmfEventPropertySource implements IPropertySource { | |
34 | ||
35 | private static final String ID_TIMESTAMP = "event_timestamp"; //$NON-NLS-1$ | |
93bfd50a | 36 | private static final String ID_TYPE = "event_type"; //$NON-NLS-1$ |
2544108c | 37 | private static final String ID_TRACE = "trace_attribute"; //$NON-NLS-1$ |
93bfd50a | 38 | private static final String ID_CONTENT = "event_content"; //$NON-NLS-1$ |
f47ed727 BH |
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$ | |
860b76d4 | 41 | private static final String ID_CUSTOM_ATTRIBUTE = "custom_attribute"; //$NON-NLS-1$ |
f47ed727 | 42 | |
93bfd50a | 43 | private static final String NAME_TIMESTAMP = "Timestamp"; //$NON-NLS-1$ |
93bfd50a | 44 | private static final String NAME_TYPE = "Type"; //$NON-NLS-1$ |
2544108c | 45 | private static final String NAME_TRACE = "Trace"; //$NON-NLS-1$ |
93bfd50a | 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$ | |
93bfd50a PT |
58 | private static final String NAME_TIMESTAMP_VALUE = "value"; //$NON-NLS-1$ |
59 | private static final String NAME_TIMESTAMP_SCALE = "scale"; //$NON-NLS-1$ | |
93bfd50a PT |
60 | |
61 | private ITmfTimestamp fTimestamp; | |
62 | ||
63 | public TimestampPropertySource(ITmfTimestamp timestamp) { | |
64 | fTimestamp = timestamp; | |
65 | } | |
66 | ||
67 | @Override | |
68 | public Object getEditableValue() { | |
69 | return fTimestamp.toString(); | |
70 | } | |
71 | ||
72 | @Override | |
73 | public IPropertyDescriptor[] getPropertyDescriptors() { | |
065cc19b | 74 | IPropertyDescriptor[] descriptors = new IPropertyDescriptor[2]; |
0505c6fc BH |
75 | descriptors[0] = new ReadOnlyTextPropertyDescriptor(ID_TIMESTAMP_VALUE, NAME_TIMESTAMP_VALUE); |
76 | descriptors[1] = new ReadOnlyTextPropertyDescriptor(ID_TIMESTAMP_SCALE, NAME_TIMESTAMP_SCALE); | |
93bfd50a PT |
77 | return descriptors; |
78 | } | |
79 | ||
80 | @Override | |
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()); | |
93bfd50a PT |
86 | } |
87 | return null; | |
88 | } | |
89 | ||
90 | @Override | |
91 | public boolean isPropertySet(Object id) { | |
92 | return false; | |
93 | } | |
94 | ||
95 | @Override | |
96 | public void resetPropertyValue(Object id) { | |
97 | } | |
98 | ||
99 | @Override | |
100 | public void setPropertyValue(Object id, Object value) { | |
101 | } | |
102 | } | |
103 | ||
104 | private class ContentPropertySource implements IPropertySource { | |
105 | private ITmfEventField fContent; | |
106 | ||
107 | public ContentPropertySource(ITmfEventField content) { | |
108 | fContent = content; | |
109 | } | |
110 | ||
111 | @Override | |
112 | public Object getEditableValue() { | |
113 | return fContent.toString(); | |
114 | } | |
115 | ||
116 | @Override | |
117 | public IPropertyDescriptor[] getPropertyDescriptors() { | |
b742c196 | 118 | List<IPropertyDescriptor> descriptors = new ArrayList<>(fContent.getFields().size()); |
93bfd50a PT |
119 | for (ITmfEventField field : fContent.getFields()) { |
120 | if (field != null) { | |
0505c6fc | 121 | descriptors.add(new ReadOnlyTextPropertyDescriptor(field, field.getName())); |
93bfd50a PT |
122 | } |
123 | } | |
124 | return descriptors.toArray(new IPropertyDescriptor[0]); | |
125 | } | |
126 | ||
127 | @Override | |
128 | public Object getPropertyValue(Object id) { | |
129 | ITmfEventField field = (ITmfEventField) id; | |
fafdd006 | 130 | if (!field.getFields().isEmpty()) { |
93bfd50a PT |
131 | return new ContentPropertySource(field); |
132 | } | |
8f86c552 | 133 | return field.getFormattedValue(); |
93bfd50a PT |
134 | } |
135 | ||
136 | @Override | |
137 | public boolean isPropertySet(Object id) { | |
138 | return false; | |
139 | } | |
140 | ||
141 | @Override | |
142 | public void resetPropertyValue(Object id) { | |
143 | } | |
144 | ||
145 | @Override | |
146 | public void setPropertyValue(Object id, Object value) { | |
147 | } | |
148 | } | |
149 | ||
f47ed727 BH |
150 | private class SourceLookupPropertySource implements IPropertySource { |
151 | ||
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$ | |
155 | ||
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$ | |
159 | ||
574f43ad | 160 | private final ITmfSourceLookup fSourceLookup; |
f47ed727 BH |
161 | |
162 | public SourceLookupPropertySource(ITmfSourceLookup lookup) { | |
163 | fSourceLookup = lookup; | |
164 | } | |
165 | ||
166 | @Override | |
167 | public Object getEditableValue() { | |
04ca66e5 AM |
168 | ITmfCallsite cs = fSourceLookup.getCallsite(); |
169 | if (cs != null) { | |
170 | return cs.toString(); | |
f47ed727 BH |
171 | } |
172 | return null; | |
173 | } | |
174 | ||
175 | @Override | |
176 | public IPropertyDescriptor[] getPropertyDescriptors() { | |
507b1336 | 177 | List<IPropertyDescriptor> descriptors= new ArrayList<>(); |
04ca66e5 AM |
178 | ITmfCallsite cs = fSourceLookup.getCallsite(); |
179 | if (cs != null) { | |
0505c6fc BH |
180 | descriptors.add(new ReadOnlyTextPropertyDescriptor(ID_FILE_NAME, NAME_FILE_NAME)); |
181 | descriptors.add(new ReadOnlyTextPropertyDescriptor(ID_LINE_NUMBER, NAME_LINE_NUMBER)); | |
f47ed727 | 182 | // only display function if available |
04ca66e5 | 183 | if (cs.getFunctionName() != null) { |
0505c6fc | 184 | descriptors.add(new ReadOnlyTextPropertyDescriptor(ID_FUNCTION_NAME, NAME_FUNCTION_NAME)); |
f47ed727 BH |
185 | } |
186 | } | |
187 | return descriptors.toArray(new IPropertyDescriptor[0]); | |
188 | } | |
189 | ||
190 | @Override | |
191 | public Object getPropertyValue(Object id) { | |
04ca66e5 AM |
192 | ITmfCallsite cs = fSourceLookup.getCallsite(); |
193 | if (cs == null) { | |
194 | /* | |
195 | * The callsite should not be null here, we would not have | |
196 | * created the descriptors otherwise | |
197 | */ | |
198 | throw new IllegalStateException(); | |
199 | } | |
200 | ||
201 | if (!(id instanceof String)) { | |
202 | return null; | |
203 | } | |
204 | ||
205 | switch ((String) id) { | |
206 | case ID_FILE_NAME: | |
207 | return cs.getFileName(); | |
208 | case ID_FUNCTION_NAME: | |
209 | return cs.getFunctionName(); | |
210 | case ID_LINE_NUMBER: | |
211 | return Long.valueOf(cs.getLineNumber()); | |
212 | default: | |
213 | return null; | |
f47ed727 | 214 | } |
f47ed727 BH |
215 | } |
216 | ||
217 | @Override | |
218 | public boolean isPropertySet(Object id) { | |
219 | return false; | |
220 | } | |
221 | ||
222 | @Override | |
223 | public void resetPropertyValue(Object id) { | |
224 | ||
225 | } | |
226 | ||
227 | @Override | |
228 | public void setPropertyValue(Object id, Object value) { | |
229 | } | |
230 | } | |
231 | ||
860b76d4 SD |
232 | private class CustomAttributePropertySource implements IPropertySource { |
233 | ||
234 | private final ITmfCustomAttributes event; | |
235 | ||
236 | public CustomAttributePropertySource(ITmfCustomAttributes event) { | |
237 | this.event = event; | |
238 | } | |
239 | ||
240 | @Override | |
241 | public Object getEditableValue() { | |
242 | return EMPTY_STRING; | |
243 | } | |
244 | ||
245 | @Override | |
246 | public IPropertyDescriptor[] getPropertyDescriptors() { | |
507b1336 | 247 | List<IPropertyDescriptor> descriptors = new ArrayList<>(); |
860b76d4 SD |
248 | |
249 | for (String customAttribute : event.listCustomAttributes()) { | |
250 | descriptors.add(new ReadOnlyTextPropertyDescriptor(customAttribute, customAttribute)); | |
251 | } | |
252 | ||
253 | return descriptors.toArray(new IPropertyDescriptor[0]); | |
254 | } | |
255 | ||
256 | @Override | |
257 | public Object getPropertyValue(Object id) { | |
258 | return event.getCustomAttribute((String) id); | |
259 | } | |
260 | ||
261 | @Override | |
262 | public boolean isPropertySet(Object id) { | |
263 | return false; | |
264 | } | |
265 | ||
266 | @Override | |
267 | public void resetPropertyValue(Object id) { | |
268 | } | |
269 | ||
270 | @Override | |
271 | public void setPropertyValue(Object id, Object value) { | |
272 | } | |
273 | } | |
f47ed727 | 274 | |
93bfd50a PT |
275 | /** |
276 | * Default constructor | |
277 | * | |
278 | * @param event the event | |
279 | */ | |
280 | public TmfEventPropertySource(ITmfEvent event) { | |
281 | super(); | |
282 | this.fEvent = event; | |
283 | } | |
284 | ||
285 | @Override | |
286 | public Object getEditableValue() { | |
287 | return null; | |
288 | } | |
289 | ||
290 | @Override | |
291 | public IPropertyDescriptor[] getPropertyDescriptors() { | |
507b1336 | 292 | List<IPropertyDescriptor> descriptors= new ArrayList<>(); |
860b76d4 SD |
293 | |
294 | /* Display basic event information */ | |
0505c6fc | 295 | descriptors.add(new ReadOnlyTextPropertyDescriptor(ID_TIMESTAMP, NAME_TIMESTAMP)); |
0505c6fc | 296 | descriptors.add(new ReadOnlyTextPropertyDescriptor(ID_TYPE, NAME_TYPE)); |
2544108c | 297 | descriptors.add(new ReadOnlyTextPropertyDescriptor(ID_TRACE, NAME_TRACE)); |
860b76d4 SD |
298 | |
299 | /* Display event fields */ | |
300 | descriptors.add(new ReadOnlyTextPropertyDescriptor(ID_CONTENT, NAME_CONTENT)); | |
301 | ||
302 | /* Display source lookup information, if the event supplies it */ | |
f47ed727 | 303 | if ((fEvent instanceof ITmfSourceLookup) && (((ITmfSourceLookup)fEvent).getCallsite() != null)) { |
0505c6fc | 304 | descriptors.add(new ReadOnlyTextPropertyDescriptor(ID_SOURCE_LOOKUP, NAME_SOURCE_LOOKUP)); |
f47ed727 | 305 | } |
860b76d4 SD |
306 | |
307 | /* Display Model URI information, if the event supplies it */ | |
308 | if ((fEvent instanceof ITmfModelLookup) && (((ITmfModelLookup) fEvent).getModelUri() != null)) { | |
0505c6fc | 309 | descriptors.add(new ReadOnlyTextPropertyDescriptor(ID_MODEL_URI, NAME_MODEL_URI)); |
f47ed727 | 310 | } |
860b76d4 SD |
311 | |
312 | /* Display custom attributes, if available */ | |
313 | if (fEvent instanceof ITmfCustomAttributes) { | |
314 | ITmfCustomAttributes event = (ITmfCustomAttributes) fEvent; | |
4c4e2816 | 315 | if (!event.listCustomAttributes().isEmpty()) { |
860b76d4 SD |
316 | descriptors.add(new ReadOnlyTextPropertyDescriptor(ID_CUSTOM_ATTRIBUTE, NAME_CUSTOM_ATTRIBUTES)); |
317 | } | |
318 | } | |
319 | ||
f47ed727 | 320 | return descriptors.toArray(new IPropertyDescriptor[0]); |
93bfd50a PT |
321 | } |
322 | ||
323 | @Override | |
324 | public Object getPropertyValue(Object id) { | |
cbf0057c | 325 | if (id.equals(ID_TIMESTAMP)) { |
93bfd50a | 326 | return new TimestampPropertySource(fEvent.getTimestamp()); |
93bfd50a PT |
327 | } else if (id.equals(ID_TYPE) && fEvent.getType() != null) { |
328 | return fEvent.getType().toString(); | |
ca5b04ad | 329 | } else if (id.equals(ID_TRACE)) { |
2544108c | 330 | return fEvent.getTrace().getName(); |
f47ed727 BH |
331 | } else if (id.equals(ID_MODEL_URI)) { |
332 | return ((ITmfModelLookup)fEvent).getModelUri(); | |
333 | } else if (id.equals(ID_SOURCE_LOOKUP)) { | |
334 | return new SourceLookupPropertySource(((ITmfSourceLookup)fEvent)); | |
93bfd50a PT |
335 | } else if (id.equals(ID_CONTENT) && fEvent.getContent() != null) { |
336 | return new ContentPropertySource(fEvent.getContent()); | |
860b76d4 SD |
337 | } else if (id.equals(ID_CUSTOM_ATTRIBUTE)) { |
338 | return new CustomAttributePropertySource((ITmfCustomAttributes) fEvent); | |
93bfd50a PT |
339 | } |
340 | return null; | |
341 | } | |
342 | ||
343 | @Override | |
344 | public boolean isPropertySet(Object id) { | |
345 | return false; | |
346 | } | |
347 | ||
348 | @Override | |
349 | public void resetPropertyValue(Object id) { | |
350 | } | |
351 | ||
352 | @Override | |
353 | public void setPropertyValue(Object id, Object value) { | |
354 | } | |
355 | ||
356 | } |