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