lttng.ust: Split the function name into its own aspect/column
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.ui / src / org / eclipse / tracecompass / tmf / ui / viewers / events / TmfEventPropertySource.java
CommitLineData
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 14package org.eclipse.tracecompass.tmf.ui.viewers.events;
93bfd50a
PT
15
16import java.util.ArrayList;
17import java.util.List;
18
2bdf0193
AM
19import org.eclipse.tracecompass.tmf.core.event.ITmfCustomAttributes;
20import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
21import org.eclipse.tracecompass.tmf.core.event.ITmfEventField;
04ca66e5 22import org.eclipse.tracecompass.tmf.core.event.lookup.ITmfCallsite;
2bdf0193
AM
23import org.eclipse.tracecompass.tmf.core.event.lookup.ITmfModelLookup;
24import org.eclipse.tracecompass.tmf.core.event.lookup.ITmfSourceLookup;
25import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp;
26import org.eclipse.tracecompass.tmf.ui.properties.ReadOnlyTextPropertyDescriptor;
93bfd50a
PT
27import org.eclipse.ui.views.properties.IPropertyDescriptor;
28import org.eclipse.ui.views.properties.IPropertySource;
93bfd50a
PT
29
30/**
31 * Property source for events
93bfd50a
PT
32 */
33public 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
658e0268 55 private static class TimestampPropertySource implements IPropertySource {
93bfd50a
PT
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
658e0268 104 private static class ContentPropertySource implements IPropertySource {
93bfd50a
PT
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
658e0268 150 private static class SourceLookupPropertySource implements IPropertySource {
f47ed727
BH
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) {
aa353506
AM
258 if (!(id instanceof String)) {
259 return null;
260 }
860b76d4
SD
261 return event.getCustomAttribute((String) id);
262 }
263
264 @Override
265 public boolean isPropertySet(Object id) {
266 return false;
267 }
268
269 @Override
270 public void resetPropertyValue(Object id) {
271 }
272
273 @Override
274 public void setPropertyValue(Object id, Object value) {
275 }
276 }
f47ed727 277
93bfd50a
PT
278 /**
279 * Default constructor
280 *
281 * @param event the event
282 */
283 public TmfEventPropertySource(ITmfEvent event) {
284 super();
285 this.fEvent = event;
286 }
287
288 @Override
289 public Object getEditableValue() {
290 return null;
291 }
292
293 @Override
294 public IPropertyDescriptor[] getPropertyDescriptors() {
507b1336 295 List<IPropertyDescriptor> descriptors= new ArrayList<>();
860b76d4
SD
296
297 /* Display basic event information */
0505c6fc 298 descriptors.add(new ReadOnlyTextPropertyDescriptor(ID_TIMESTAMP, NAME_TIMESTAMP));
0505c6fc 299 descriptors.add(new ReadOnlyTextPropertyDescriptor(ID_TYPE, NAME_TYPE));
2544108c 300 descriptors.add(new ReadOnlyTextPropertyDescriptor(ID_TRACE, NAME_TRACE));
860b76d4
SD
301
302 /* Display event fields */
303 descriptors.add(new ReadOnlyTextPropertyDescriptor(ID_CONTENT, NAME_CONTENT));
304
305 /* Display source lookup information, if the event supplies it */
f47ed727 306 if ((fEvent instanceof ITmfSourceLookup) && (((ITmfSourceLookup)fEvent).getCallsite() != null)) {
0505c6fc 307 descriptors.add(new ReadOnlyTextPropertyDescriptor(ID_SOURCE_LOOKUP, NAME_SOURCE_LOOKUP));
f47ed727 308 }
860b76d4
SD
309
310 /* Display Model URI information, if the event supplies it */
311 if ((fEvent instanceof ITmfModelLookup) && (((ITmfModelLookup) fEvent).getModelUri() != null)) {
0505c6fc 312 descriptors.add(new ReadOnlyTextPropertyDescriptor(ID_MODEL_URI, NAME_MODEL_URI));
f47ed727 313 }
860b76d4
SD
314
315 /* Display custom attributes, if available */
316 if (fEvent instanceof ITmfCustomAttributes) {
317 ITmfCustomAttributes event = (ITmfCustomAttributes) fEvent;
4c4e2816 318 if (!event.listCustomAttributes().isEmpty()) {
860b76d4
SD
319 descriptors.add(new ReadOnlyTextPropertyDescriptor(ID_CUSTOM_ATTRIBUTE, NAME_CUSTOM_ATTRIBUTES));
320 }
321 }
322
f47ed727 323 return descriptors.toArray(new IPropertyDescriptor[0]);
93bfd50a
PT
324 }
325
326 @Override
327 public Object getPropertyValue(Object id) {
cbf0057c 328 if (id.equals(ID_TIMESTAMP)) {
93bfd50a 329 return new TimestampPropertySource(fEvent.getTimestamp());
93bfd50a
PT
330 } else if (id.equals(ID_TYPE) && fEvent.getType() != null) {
331 return fEvent.getType().toString();
ca5b04ad 332 } else if (id.equals(ID_TRACE)) {
2544108c 333 return fEvent.getTrace().getName();
f47ed727
BH
334 } else if (id.equals(ID_MODEL_URI)) {
335 return ((ITmfModelLookup)fEvent).getModelUri();
336 } else if (id.equals(ID_SOURCE_LOOKUP)) {
337 return new SourceLookupPropertySource(((ITmfSourceLookup)fEvent));
93bfd50a
PT
338 } else if (id.equals(ID_CONTENT) && fEvent.getContent() != null) {
339 return new ContentPropertySource(fEvent.getContent());
860b76d4
SD
340 } else if (id.equals(ID_CUSTOM_ATTRIBUTE)) {
341 return new CustomAttributePropertySource((ITmfCustomAttributes) fEvent);
93bfd50a
PT
342 }
343 return null;
344 }
345
346 @Override
347 public boolean isPropertySet(Object id) {
348 return false;
349 }
350
351 @Override
352 public void resetPropertyValue(Object id) {
353 }
354
355 @Override
356 public void setPropertyValue(Object id, Object value) {
357 }
358
359}
This page took 0.120018 seconds and 5 git commands to generate.