tmf: Remove function name from ITmfCallsite
[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 15
0c65e461
AM
16import static org.eclipse.tracecompass.common.core.NonNullUtils.nullToEmptyString;
17
93bfd50a
PT
18import java.util.ArrayList;
19import java.util.List;
20
2bdf0193
AM
21import org.eclipse.tracecompass.tmf.core.event.ITmfCustomAttributes;
22import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
23import org.eclipse.tracecompass.tmf.core.event.ITmfEventField;
04ca66e5 24import org.eclipse.tracecompass.tmf.core.event.lookup.ITmfCallsite;
2bdf0193
AM
25import org.eclipse.tracecompass.tmf.core.event.lookup.ITmfModelLookup;
26import org.eclipse.tracecompass.tmf.core.event.lookup.ITmfSourceLookup;
27import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp;
28import org.eclipse.tracecompass.tmf.ui.properties.ReadOnlyTextPropertyDescriptor;
93bfd50a
PT
29import org.eclipse.ui.views.properties.IPropertyDescriptor;
30import org.eclipse.ui.views.properties.IPropertySource;
93bfd50a
PT
31
32/**
33 * Property source for events
93bfd50a
PT
34 */
35public class TmfEventPropertySource implements IPropertySource {
36
37 private static final String ID_TIMESTAMP = "event_timestamp"; //$NON-NLS-1$
93bfd50a 38 private static final String ID_TYPE = "event_type"; //$NON-NLS-1$
2544108c 39 private static final String ID_TRACE = "trace_attribute"; //$NON-NLS-1$
93bfd50a 40 private static final String ID_CONTENT = "event_content"; //$NON-NLS-1$
f47ed727
BH
41 private static final String ID_SOURCE_LOOKUP = "event_lookup"; //$NON-NLS-1$
42 private static final String ID_MODEL_URI = "model_uri"; //$NON-NLS-1$
860b76d4 43 private static final String ID_CUSTOM_ATTRIBUTE = "custom_attribute"; //$NON-NLS-1$
f47ed727 44
93bfd50a 45 private static final String NAME_TIMESTAMP = "Timestamp"; //$NON-NLS-1$
93bfd50a 46 private static final String NAME_TYPE = "Type"; //$NON-NLS-1$
2544108c 47 private static final String NAME_TRACE = "Trace"; //$NON-NLS-1$
93bfd50a 48 private static final String NAME_CONTENT = "Content"; //$NON-NLS-1$
860b76d4 49 private static final String NAME_SOURCE_LOOKUP = "Source Lookup"; //$NON-NLS-1$
f47ed727 50 private static final String NAME_MODEL_URI = "Model URI"; //$NON-NLS-1$
860b76d4 51 private static final String NAME_CUSTOM_ATTRIBUTES = "Custom Attributes"; //$NON-NLS-1$
f47ed727 52
860b76d4 53 private static final String EMPTY_STRING = ""; //$NON-NLS-1$
93bfd50a
PT
54
55 private ITmfEvent fEvent;
56
658e0268 57 private static class TimestampPropertySource implements IPropertySource {
93bfd50a
PT
58 private static final String ID_TIMESTAMP_VALUE = "timestamp_value"; //$NON-NLS-1$
59 private static final String ID_TIMESTAMP_SCALE = "timestamp_scale"; //$NON-NLS-1$
93bfd50a
PT
60 private static final String NAME_TIMESTAMP_VALUE = "value"; //$NON-NLS-1$
61 private static final String NAME_TIMESTAMP_SCALE = "scale"; //$NON-NLS-1$
93bfd50a
PT
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() {
065cc19b 76 IPropertyDescriptor[] descriptors = new IPropertyDescriptor[2];
0505c6fc
BH
77 descriptors[0] = new ReadOnlyTextPropertyDescriptor(ID_TIMESTAMP_VALUE, NAME_TIMESTAMP_VALUE);
78 descriptors[1] = new ReadOnlyTextPropertyDescriptor(ID_TIMESTAMP_SCALE, NAME_TIMESTAMP_SCALE);
93bfd50a
PT
79 return descriptors;
80 }
81
82 @Override
83 public Object getPropertyValue(Object id) {
84 if (id.equals(ID_TIMESTAMP_VALUE)) {
85 return Long.toString(fTimestamp.getValue());
86 } else if (id.equals(ID_TIMESTAMP_SCALE)) {
87 return Integer.toString(fTimestamp.getScale());
93bfd50a
PT
88 }
89 return null;
90 }
91
92 @Override
93 public boolean isPropertySet(Object id) {
94 return false;
95 }
96
97 @Override
98 public void resetPropertyValue(Object id) {
99 }
100
101 @Override
102 public void setPropertyValue(Object id, Object value) {
103 }
104 }
105
658e0268 106 private static class ContentPropertySource implements IPropertySource {
93bfd50a
PT
107 private ITmfEventField fContent;
108
109 public ContentPropertySource(ITmfEventField content) {
110 fContent = content;
111 }
112
113 @Override
114 public Object getEditableValue() {
115 return fContent.toString();
116 }
117
118 @Override
119 public IPropertyDescriptor[] getPropertyDescriptors() {
b742c196 120 List<IPropertyDescriptor> descriptors = new ArrayList<>(fContent.getFields().size());
93bfd50a
PT
121 for (ITmfEventField field : fContent.getFields()) {
122 if (field != null) {
0505c6fc 123 descriptors.add(new ReadOnlyTextPropertyDescriptor(field, field.getName()));
93bfd50a
PT
124 }
125 }
126 return descriptors.toArray(new IPropertyDescriptor[0]);
127 }
128
129 @Override
130 public Object getPropertyValue(Object id) {
131 ITmfEventField field = (ITmfEventField) id;
fafdd006 132 if (!field.getFields().isEmpty()) {
93bfd50a
PT
133 return new ContentPropertySource(field);
134 }
8f86c552 135 return field.getFormattedValue();
93bfd50a
PT
136 }
137
138 @Override
139 public boolean isPropertySet(Object id) {
140 return false;
141 }
142
143 @Override
144 public void resetPropertyValue(Object id) {
145 }
146
147 @Override
148 public void setPropertyValue(Object id, Object value) {
149 }
150 }
151
658e0268 152 private static class SourceLookupPropertySource implements IPropertySource {
f47ed727
BH
153
154 private static final String ID_FILE_NAME = "callsite_file"; //$NON-NLS-1$
f47ed727
BH
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$
f47ed727
BH
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
BH
182 }
183 return descriptors.toArray(new IPropertyDescriptor[0]);
184 }
185
186 @Override
1685d123 187 public String getPropertyValue(Object id) {
04ca66e5
AM
188 ITmfCallsite cs = fSourceLookup.getCallsite();
189 if (cs == null) {
190 /*
191 * The callsite should not be null here, we would not have
192 * created the descriptors otherwise
193 */
194 throw new IllegalStateException();
195 }
196
197 if (!(id instanceof String)) {
198 return null;
199 }
200
201 switch ((String) id) {
202 case ID_FILE_NAME:
203 return cs.getFileName();
04ca66e5 204 case ID_LINE_NUMBER:
0c65e461 205 return nullToEmptyString(cs.getLineNo());
04ca66e5
AM
206 default:
207 return null;
f47ed727 208 }
f47ed727
BH
209 }
210
211 @Override
212 public boolean isPropertySet(Object id) {
213 return false;
214 }
215
216 @Override
217 public void resetPropertyValue(Object id) {
218
219 }
220
221 @Override
222 public void setPropertyValue(Object id, Object value) {
223 }
224 }
225
860b76d4
SD
226 private class CustomAttributePropertySource implements IPropertySource {
227
228 private final ITmfCustomAttributes event;
229
230 public CustomAttributePropertySource(ITmfCustomAttributes event) {
231 this.event = event;
232 }
233
234 @Override
235 public Object getEditableValue() {
236 return EMPTY_STRING;
237 }
238
239 @Override
240 public IPropertyDescriptor[] getPropertyDescriptors() {
507b1336 241 List<IPropertyDescriptor> descriptors = new ArrayList<>();
860b76d4
SD
242
243 for (String customAttribute : event.listCustomAttributes()) {
244 descriptors.add(new ReadOnlyTextPropertyDescriptor(customAttribute, customAttribute));
245 }
246
247 return descriptors.toArray(new IPropertyDescriptor[0]);
248 }
249
250 @Override
251 public Object getPropertyValue(Object id) {
aa353506
AM
252 if (!(id instanceof String)) {
253 return null;
254 }
860b76d4
SD
255 return event.getCustomAttribute((String) id);
256 }
257
258 @Override
259 public boolean isPropertySet(Object id) {
260 return false;
261 }
262
263 @Override
264 public void resetPropertyValue(Object id) {
265 }
266
267 @Override
268 public void setPropertyValue(Object id, Object value) {
269 }
270 }
f47ed727 271
93bfd50a
PT
272 /**
273 * Default constructor
274 *
275 * @param event the event
276 */
277 public TmfEventPropertySource(ITmfEvent event) {
278 super();
279 this.fEvent = event;
280 }
281
282 @Override
283 public Object getEditableValue() {
284 return null;
285 }
286
287 @Override
288 public IPropertyDescriptor[] getPropertyDescriptors() {
507b1336 289 List<IPropertyDescriptor> descriptors= new ArrayList<>();
860b76d4
SD
290
291 /* Display basic event information */
0505c6fc 292 descriptors.add(new ReadOnlyTextPropertyDescriptor(ID_TIMESTAMP, NAME_TIMESTAMP));
0505c6fc 293 descriptors.add(new ReadOnlyTextPropertyDescriptor(ID_TYPE, NAME_TYPE));
2544108c 294 descriptors.add(new ReadOnlyTextPropertyDescriptor(ID_TRACE, NAME_TRACE));
860b76d4
SD
295
296 /* Display event fields */
297 descriptors.add(new ReadOnlyTextPropertyDescriptor(ID_CONTENT, NAME_CONTENT));
298
299 /* Display source lookup information, if the event supplies it */
f47ed727 300 if ((fEvent instanceof ITmfSourceLookup) && (((ITmfSourceLookup)fEvent).getCallsite() != null)) {
0505c6fc 301 descriptors.add(new ReadOnlyTextPropertyDescriptor(ID_SOURCE_LOOKUP, NAME_SOURCE_LOOKUP));
f47ed727 302 }
860b76d4
SD
303
304 /* Display Model URI information, if the event supplies it */
305 if ((fEvent instanceof ITmfModelLookup) && (((ITmfModelLookup) fEvent).getModelUri() != null)) {
0505c6fc 306 descriptors.add(new ReadOnlyTextPropertyDescriptor(ID_MODEL_URI, NAME_MODEL_URI));
f47ed727 307 }
860b76d4
SD
308
309 /* Display custom attributes, if available */
310 if (fEvent instanceof ITmfCustomAttributes) {
311 ITmfCustomAttributes event = (ITmfCustomAttributes) fEvent;
4c4e2816 312 if (!event.listCustomAttributes().isEmpty()) {
860b76d4
SD
313 descriptors.add(new ReadOnlyTextPropertyDescriptor(ID_CUSTOM_ATTRIBUTE, NAME_CUSTOM_ATTRIBUTES));
314 }
315 }
316
f47ed727 317 return descriptors.toArray(new IPropertyDescriptor[0]);
93bfd50a
PT
318 }
319
320 @Override
321 public Object getPropertyValue(Object id) {
cbf0057c 322 if (id.equals(ID_TIMESTAMP)) {
93bfd50a 323 return new TimestampPropertySource(fEvent.getTimestamp());
93bfd50a
PT
324 } else if (id.equals(ID_TYPE) && fEvent.getType() != null) {
325 return fEvent.getType().toString();
ca5b04ad 326 } else if (id.equals(ID_TRACE)) {
2544108c 327 return fEvent.getTrace().getName();
f47ed727
BH
328 } else if (id.equals(ID_MODEL_URI)) {
329 return ((ITmfModelLookup)fEvent).getModelUri();
330 } else if (id.equals(ID_SOURCE_LOOKUP)) {
331 return new SourceLookupPropertySource(((ITmfSourceLookup)fEvent));
93bfd50a
PT
332 } else if (id.equals(ID_CONTENT) && fEvent.getContent() != null) {
333 return new ContentPropertySource(fEvent.getContent());
860b76d4
SD
334 } else if (id.equals(ID_CUSTOM_ATTRIBUTE)) {
335 return new CustomAttributePropertySource((ITmfCustomAttributes) fEvent);
93bfd50a
PT
336 }
337 return null;
338 }
339
340 @Override
341 public boolean isPropertySet(Object id) {
342 return false;
343 }
344
345 @Override
346 public void resetPropertyValue(Object id) {
347 }
348
349 @Override
350 public void setPropertyValue(Object id, Object value) {
351 }
352
353}
This page took 0.144973 seconds and 5 git commands to generate.