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: | |
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; | |
22 | import org.eclipse.tracecompass.tmf.core.event.lookup.ITmfModelLookup; | |
23 | import org.eclipse.tracecompass.tmf.core.event.lookup.ITmfSourceLookup; | |
24 | import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp; | |
25 | import org.eclipse.tracecompass.tmf.ui.properties.ReadOnlyTextPropertyDescriptor; | |
93bfd50a PT |
26 | import org.eclipse.ui.views.properties.IPropertyDescriptor; |
27 | import org.eclipse.ui.views.properties.IPropertySource; | |
93bfd50a PT |
28 | |
29 | /** | |
30 | * Property source for events | |
31 | * | |
32 | * @since 2.0 | |
33 | */ | |
34 | public class TmfEventPropertySource implements IPropertySource { | |
35 | ||
36 | private static final String ID_TIMESTAMP = "event_timestamp"; //$NON-NLS-1$ | |
93bfd50a | 37 | private static final String ID_TYPE = "event_type"; //$NON-NLS-1$ |
2544108c | 38 | private static final String ID_TRACE = "trace_attribute"; //$NON-NLS-1$ |
93bfd50a | 39 | private static final String ID_CONTENT = "event_content"; //$NON-NLS-1$ |
f47ed727 BH |
40 | private static final String ID_SOURCE_LOOKUP = "event_lookup"; //$NON-NLS-1$ |
41 | private static final String ID_MODEL_URI = "model_uri"; //$NON-NLS-1$ | |
860b76d4 | 42 | private static final String ID_CUSTOM_ATTRIBUTE = "custom_attribute"; //$NON-NLS-1$ |
f47ed727 | 43 | |
93bfd50a | 44 | private static final String NAME_TIMESTAMP = "Timestamp"; //$NON-NLS-1$ |
93bfd50a | 45 | private static final String NAME_TYPE = "Type"; //$NON-NLS-1$ |
2544108c | 46 | private static final String NAME_TRACE = "Trace"; //$NON-NLS-1$ |
93bfd50a | 47 | private static final String NAME_CONTENT = "Content"; //$NON-NLS-1$ |
860b76d4 | 48 | private static final String NAME_SOURCE_LOOKUP = "Source Lookup"; //$NON-NLS-1$ |
f47ed727 | 49 | private static final String NAME_MODEL_URI = "Model URI"; //$NON-NLS-1$ |
860b76d4 | 50 | private static final String NAME_CUSTOM_ATTRIBUTES = "Custom Attributes"; //$NON-NLS-1$ |
f47ed727 | 51 | |
860b76d4 | 52 | private static final String EMPTY_STRING = ""; //$NON-NLS-1$ |
93bfd50a PT |
53 | |
54 | private ITmfEvent fEvent; | |
55 | ||
56 | private class TimestampPropertySource implements IPropertySource { | |
57 | private static final String ID_TIMESTAMP_VALUE = "timestamp_value"; //$NON-NLS-1$ | |
58 | private static final String ID_TIMESTAMP_SCALE = "timestamp_scale"; //$NON-NLS-1$ | |
93bfd50a PT |
59 | private static final String NAME_TIMESTAMP_VALUE = "value"; //$NON-NLS-1$ |
60 | private static final String NAME_TIMESTAMP_SCALE = "scale"; //$NON-NLS-1$ | |
93bfd50a PT |
61 | |
62 | private ITmfTimestamp fTimestamp; | |
63 | ||
64 | public TimestampPropertySource(ITmfTimestamp timestamp) { | |
65 | fTimestamp = timestamp; | |
66 | } | |
67 | ||
68 | @Override | |
69 | public Object getEditableValue() { | |
70 | return fTimestamp.toString(); | |
71 | } | |
72 | ||
73 | @Override | |
74 | public IPropertyDescriptor[] getPropertyDescriptors() { | |
065cc19b | 75 | IPropertyDescriptor[] descriptors = new IPropertyDescriptor[2]; |
0505c6fc BH |
76 | descriptors[0] = new ReadOnlyTextPropertyDescriptor(ID_TIMESTAMP_VALUE, NAME_TIMESTAMP_VALUE); |
77 | descriptors[1] = new ReadOnlyTextPropertyDescriptor(ID_TIMESTAMP_SCALE, NAME_TIMESTAMP_SCALE); | |
93bfd50a PT |
78 | return descriptors; |
79 | } | |
80 | ||
81 | @Override | |
82 | public Object getPropertyValue(Object id) { | |
83 | if (id.equals(ID_TIMESTAMP_VALUE)) { | |
84 | return Long.toString(fTimestamp.getValue()); | |
85 | } else if (id.equals(ID_TIMESTAMP_SCALE)) { | |
86 | return Integer.toString(fTimestamp.getScale()); | |
93bfd50a PT |
87 | } |
88 | return null; | |
89 | } | |
90 | ||
91 | @Override | |
92 | public boolean isPropertySet(Object id) { | |
93 | return false; | |
94 | } | |
95 | ||
96 | @Override | |
97 | public void resetPropertyValue(Object id) { | |
98 | } | |
99 | ||
100 | @Override | |
101 | public void setPropertyValue(Object id, Object value) { | |
102 | } | |
103 | } | |
104 | ||
105 | private class ContentPropertySource implements IPropertySource { | |
106 | private ITmfEventField fContent; | |
107 | ||
108 | public ContentPropertySource(ITmfEventField content) { | |
109 | fContent = content; | |
110 | } | |
111 | ||
112 | @Override | |
113 | public Object getEditableValue() { | |
114 | return fContent.toString(); | |
115 | } | |
116 | ||
117 | @Override | |
118 | public IPropertyDescriptor[] getPropertyDescriptors() { | |
b742c196 | 119 | List<IPropertyDescriptor> descriptors = new ArrayList<>(fContent.getFields().size()); |
93bfd50a PT |
120 | for (ITmfEventField field : fContent.getFields()) { |
121 | if (field != null) { | |
0505c6fc | 122 | descriptors.add(new ReadOnlyTextPropertyDescriptor(field, field.getName())); |
93bfd50a PT |
123 | } |
124 | } | |
125 | return descriptors.toArray(new IPropertyDescriptor[0]); | |
126 | } | |
127 | ||
128 | @Override | |
129 | public Object getPropertyValue(Object id) { | |
130 | ITmfEventField field = (ITmfEventField) id; | |
b742c196 | 131 | if (field.getFields() != null && field.getFields().size() > 0) { |
93bfd50a PT |
132 | return new ContentPropertySource(field); |
133 | } | |
8f86c552 | 134 | return field.getFormattedValue(); |
93bfd50a PT |
135 | } |
136 | ||
137 | @Override | |
138 | public boolean isPropertySet(Object id) { | |
139 | return false; | |
140 | } | |
141 | ||
142 | @Override | |
143 | public void resetPropertyValue(Object id) { | |
144 | } | |
145 | ||
146 | @Override | |
147 | public void setPropertyValue(Object id, Object value) { | |
148 | } | |
149 | } | |
150 | ||
f47ed727 BH |
151 | private class SourceLookupPropertySource implements IPropertySource { |
152 | ||
153 | private static final String ID_FILE_NAME = "callsite_file"; //$NON-NLS-1$ | |
154 | private static final String ID_FUNCTION_NAME = "callsite_function"; //$NON-NLS-1$ | |
155 | private static final String ID_LINE_NUMBER = "callsite_line"; //$NON-NLS-1$ | |
156 | ||
157 | private static final String NAME_FILE_NAME = "File"; //$NON-NLS-1$ | |
158 | private static final String NAME_FUNCTION_NAME = "Function"; //$NON-NLS-1$ | |
159 | private static final String NAME_LINE_NUMBER = "Line"; //$NON-NLS-1$ | |
160 | ||
161 | final private ITmfSourceLookup fSourceLookup; | |
162 | ||
163 | public SourceLookupPropertySource(ITmfSourceLookup lookup) { | |
164 | fSourceLookup = lookup; | |
165 | } | |
166 | ||
167 | @Override | |
168 | public Object getEditableValue() { | |
169 | if (fSourceLookup.getCallsite() != null) { | |
170 | return fSourceLookup.getCallsite().toString(); | |
171 | } | |
172 | return null; | |
173 | } | |
174 | ||
175 | @Override | |
176 | public IPropertyDescriptor[] getPropertyDescriptors() { | |
507b1336 | 177 | List<IPropertyDescriptor> descriptors= new ArrayList<>(); |
f47ed727 | 178 | if (fSourceLookup.getCallsite() != null) { |
0505c6fc BH |
179 | descriptors.add(new ReadOnlyTextPropertyDescriptor(ID_FILE_NAME, NAME_FILE_NAME)); |
180 | descriptors.add(new ReadOnlyTextPropertyDescriptor(ID_LINE_NUMBER, NAME_LINE_NUMBER)); | |
f47ed727 BH |
181 | // only display function if available |
182 | if (fSourceLookup.getCallsite().getFunctionName() != null) { | |
0505c6fc | 183 | descriptors.add(new ReadOnlyTextPropertyDescriptor(ID_FUNCTION_NAME, NAME_FUNCTION_NAME)); |
f47ed727 BH |
184 | } |
185 | } | |
186 | return descriptors.toArray(new IPropertyDescriptor[0]); | |
187 | } | |
188 | ||
189 | @Override | |
190 | public Object getPropertyValue(Object id) { | |
191 | if (id.equals(ID_FILE_NAME)) { | |
192 | return fSourceLookup.getCallsite().getFileName(); | |
193 | } else if (id.equals(ID_FUNCTION_NAME)) { | |
194 | return fSourceLookup.getCallsite().getFunctionName(); | |
195 | } else if (id.equals(ID_LINE_NUMBER)) { | |
196 | return Long.valueOf(fSourceLookup.getCallsite().getLineNumber()); | |
197 | } | |
198 | return null; | |
199 | } | |
200 | ||
201 | @Override | |
202 | public boolean isPropertySet(Object id) { | |
203 | return false; | |
204 | } | |
205 | ||
206 | @Override | |
207 | public void resetPropertyValue(Object id) { | |
208 | ||
209 | } | |
210 | ||
211 | @Override | |
212 | public void setPropertyValue(Object id, Object value) { | |
213 | } | |
214 | } | |
215 | ||
860b76d4 SD |
216 | private class CustomAttributePropertySource implements IPropertySource { |
217 | ||
218 | private final ITmfCustomAttributes event; | |
219 | ||
220 | public CustomAttributePropertySource(ITmfCustomAttributes event) { | |
221 | this.event = event; | |
222 | } | |
223 | ||
224 | @Override | |
225 | public Object getEditableValue() { | |
226 | return EMPTY_STRING; | |
227 | } | |
228 | ||
229 | @Override | |
230 | public IPropertyDescriptor[] getPropertyDescriptors() { | |
507b1336 | 231 | List<IPropertyDescriptor> descriptors = new ArrayList<>(); |
860b76d4 SD |
232 | |
233 | for (String customAttribute : event.listCustomAttributes()) { | |
234 | descriptors.add(new ReadOnlyTextPropertyDescriptor(customAttribute, customAttribute)); | |
235 | } | |
236 | ||
237 | return descriptors.toArray(new IPropertyDescriptor[0]); | |
238 | } | |
239 | ||
240 | @Override | |
241 | public Object getPropertyValue(Object id) { | |
242 | return event.getCustomAttribute((String) id); | |
243 | } | |
244 | ||
245 | @Override | |
246 | public boolean isPropertySet(Object id) { | |
247 | return false; | |
248 | } | |
249 | ||
250 | @Override | |
251 | public void resetPropertyValue(Object id) { | |
252 | } | |
253 | ||
254 | @Override | |
255 | public void setPropertyValue(Object id, Object value) { | |
256 | } | |
257 | } | |
f47ed727 | 258 | |
93bfd50a PT |
259 | /** |
260 | * Default constructor | |
261 | * | |
262 | * @param event the event | |
263 | */ | |
264 | public TmfEventPropertySource(ITmfEvent event) { | |
265 | super(); | |
266 | this.fEvent = event; | |
267 | } | |
268 | ||
269 | @Override | |
270 | public Object getEditableValue() { | |
271 | return null; | |
272 | } | |
273 | ||
274 | @Override | |
275 | public IPropertyDescriptor[] getPropertyDescriptors() { | |
507b1336 | 276 | List<IPropertyDescriptor> descriptors= new ArrayList<>(); |
860b76d4 SD |
277 | |
278 | /* Display basic event information */ | |
0505c6fc | 279 | descriptors.add(new ReadOnlyTextPropertyDescriptor(ID_TIMESTAMP, NAME_TIMESTAMP)); |
0505c6fc | 280 | descriptors.add(new ReadOnlyTextPropertyDescriptor(ID_TYPE, NAME_TYPE)); |
2544108c | 281 | descriptors.add(new ReadOnlyTextPropertyDescriptor(ID_TRACE, NAME_TRACE)); |
860b76d4 SD |
282 | |
283 | /* Display event fields */ | |
284 | descriptors.add(new ReadOnlyTextPropertyDescriptor(ID_CONTENT, NAME_CONTENT)); | |
285 | ||
286 | /* Display source lookup information, if the event supplies it */ | |
f47ed727 | 287 | if ((fEvent instanceof ITmfSourceLookup) && (((ITmfSourceLookup)fEvent).getCallsite() != null)) { |
0505c6fc | 288 | descriptors.add(new ReadOnlyTextPropertyDescriptor(ID_SOURCE_LOOKUP, NAME_SOURCE_LOOKUP)); |
f47ed727 | 289 | } |
860b76d4 SD |
290 | |
291 | /* Display Model URI information, if the event supplies it */ | |
292 | if ((fEvent instanceof ITmfModelLookup) && (((ITmfModelLookup) fEvent).getModelUri() != null)) { | |
0505c6fc | 293 | descriptors.add(new ReadOnlyTextPropertyDescriptor(ID_MODEL_URI, NAME_MODEL_URI)); |
f47ed727 | 294 | } |
860b76d4 SD |
295 | |
296 | /* Display custom attributes, if available */ | |
297 | if (fEvent instanceof ITmfCustomAttributes) { | |
298 | ITmfCustomAttributes event = (ITmfCustomAttributes) fEvent; | |
299 | if (event.listCustomAttributes() != null && !event.listCustomAttributes().isEmpty()) { | |
300 | descriptors.add(new ReadOnlyTextPropertyDescriptor(ID_CUSTOM_ATTRIBUTE, NAME_CUSTOM_ATTRIBUTES)); | |
301 | } | |
302 | } | |
303 | ||
f47ed727 | 304 | return descriptors.toArray(new IPropertyDescriptor[0]); |
93bfd50a PT |
305 | } |
306 | ||
307 | @Override | |
308 | public Object getPropertyValue(Object id) { | |
309 | if (id.equals(ID_TIMESTAMP) && fEvent.getTimestamp() != null) { | |
310 | return new TimestampPropertySource(fEvent.getTimestamp()); | |
93bfd50a PT |
311 | } else if (id.equals(ID_TYPE) && fEvent.getType() != null) { |
312 | return fEvent.getType().toString(); | |
ca5b04ad | 313 | } else if (id.equals(ID_TRACE)) { |
2544108c | 314 | return fEvent.getTrace().getName(); |
f47ed727 BH |
315 | } else if (id.equals(ID_MODEL_URI)) { |
316 | return ((ITmfModelLookup)fEvent).getModelUri(); | |
317 | } else if (id.equals(ID_SOURCE_LOOKUP)) { | |
318 | return new SourceLookupPropertySource(((ITmfSourceLookup)fEvent)); | |
93bfd50a PT |
319 | } else if (id.equals(ID_CONTENT) && fEvent.getContent() != null) { |
320 | return new ContentPropertySource(fEvent.getContent()); | |
860b76d4 SD |
321 | } else if (id.equals(ID_CUSTOM_ATTRIBUTE)) { |
322 | return new CustomAttributePropertySource((ITmfCustomAttributes) fEvent); | |
93bfd50a PT |
323 | } |
324 | return null; | |
325 | } | |
326 | ||
327 | @Override | |
328 | public boolean isPropertySet(Object id) { | |
329 | return false; | |
330 | } | |
331 | ||
332 | @Override | |
333 | public void resetPropertyValue(Object id) { | |
334 | } | |
335 | ||
336 | @Override | |
337 | public void setPropertyValue(Object id, Object value) { | |
338 | } | |
339 | ||
340 | } |