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: | |
10 | * Patrick Tasse - Initial API and implementation | |
f47ed727 | 11 | * Bernd Hufmann - Added call site and model URI properties |
93bfd50a PT |
12 | *******************************************************************************/ |
13 | ||
14 | package org.eclipse.linuxtools.tmf.core.event; | |
15 | ||
16 | import java.util.ArrayList; | |
17 | import java.util.List; | |
18 | ||
f47ed727 BH |
19 | import org.eclipse.linuxtools.tmf.core.event.lookup.ITmfModelLookup; |
20 | import org.eclipse.linuxtools.tmf.core.event.lookup.ITmfSourceLookup; | |
3bd46eef | 21 | import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp; |
93bfd50a PT |
22 | import org.eclipse.ui.views.properties.IPropertyDescriptor; |
23 | import org.eclipse.ui.views.properties.IPropertySource; | |
24 | import org.eclipse.ui.views.properties.PropertyDescriptor; | |
25 | ||
26 | /** | |
27 | * Property source for events | |
28 | * | |
29 | * @since 2.0 | |
30 | */ | |
31 | public class TmfEventPropertySource implements IPropertySource { | |
32 | ||
33 | private static final String ID_TIMESTAMP = "event_timestamp"; //$NON-NLS-1$ | |
34 | private static final String ID_SOURCE = "event_source"; //$NON-NLS-1$ | |
35 | private static final String ID_TYPE = "event_type"; //$NON-NLS-1$ | |
36 | private static final String ID_REFERENCE = "event_reference"; //$NON-NLS-1$ | |
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$ | |
40 | ||
93bfd50a PT |
41 | private static final String NAME_TIMESTAMP = "Timestamp"; //$NON-NLS-1$ |
42 | private static final String NAME_SOURCE = "Source"; //$NON-NLS-1$ | |
43 | private static final String NAME_TYPE = "Type"; //$NON-NLS-1$ | |
44 | private static final String NAME_REFERENCE = "Reference"; //$NON-NLS-1$ | |
45 | private static final String NAME_CONTENT = "Content"; //$NON-NLS-1$ | |
f47ed727 BH |
46 | private static final String NAME_SOURCE_LOOKUP = "Call Site"; //$NON-NLS-1$ |
47 | private static final String NAME_MODEL_URI = "Model URI"; //$NON-NLS-1$ | |
48 | ||
93bfd50a PT |
49 | |
50 | private ITmfEvent fEvent; | |
51 | ||
52 | private class TimestampPropertySource implements IPropertySource { | |
53 | private static final String ID_TIMESTAMP_VALUE = "timestamp_value"; //$NON-NLS-1$ | |
54 | private static final String ID_TIMESTAMP_SCALE = "timestamp_scale"; //$NON-NLS-1$ | |
55 | private static final String ID_TIMESTAMP_PRECISION = "timestamp_precision"; //$NON-NLS-1$ | |
56 | private static final String NAME_TIMESTAMP_VALUE = "value"; //$NON-NLS-1$ | |
57 | private static final String NAME_TIMESTAMP_SCALE = "scale"; //$NON-NLS-1$ | |
58 | private static final String NAME_TIMESTAMP_PRECISION = "precision"; //$NON-NLS-1$ | |
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() { | |
73 | IPropertyDescriptor[] descriptors = new IPropertyDescriptor[3]; | |
74 | descriptors[0] = new PropertyDescriptor(ID_TIMESTAMP_VALUE, NAME_TIMESTAMP_VALUE); | |
75 | descriptors[1] = new PropertyDescriptor(ID_TIMESTAMP_SCALE, NAME_TIMESTAMP_SCALE); | |
76 | descriptors[2] = new PropertyDescriptor(ID_TIMESTAMP_PRECISION, NAME_TIMESTAMP_PRECISION); | |
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()); | |
86 | } else if (id.equals(ID_TIMESTAMP_PRECISION)) { | |
87 | return Integer.toString(fTimestamp.getPrecision()); | |
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 | ||
106 | private class ContentPropertySource implements IPropertySource { | |
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() { | |
120 | List<IPropertyDescriptor> descriptors= new ArrayList<IPropertyDescriptor>(fContent.getFields().length); | |
121 | for (ITmfEventField field : fContent.getFields()) { | |
122 | if (field != null) { | |
123 | descriptors.add(new PropertyDescriptor(field, field.getName())); | |
124 | } | |
125 | } | |
126 | return descriptors.toArray(new IPropertyDescriptor[0]); | |
127 | } | |
128 | ||
129 | @Override | |
130 | public Object getPropertyValue(Object id) { | |
131 | ITmfEventField field = (ITmfEventField) id; | |
132 | if (field.getFields() != null && field.getFields().length > 0) { | |
133 | return new ContentPropertySource(field); | |
134 | } | |
135 | return field.getValue(); | |
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 | ||
f47ed727 BH |
152 | private class SourceLookupPropertySource implements IPropertySource { |
153 | ||
154 | private static final String ID_FILE_NAME = "callsite_file"; //$NON-NLS-1$ | |
155 | private static final String ID_FUNCTION_NAME = "callsite_function"; //$NON-NLS-1$ | |
156 | private static final String ID_LINE_NUMBER = "callsite_line"; //$NON-NLS-1$ | |
157 | ||
158 | private static final String NAME_FILE_NAME = "File"; //$NON-NLS-1$ | |
159 | private static final String NAME_FUNCTION_NAME = "Function"; //$NON-NLS-1$ | |
160 | private static final String NAME_LINE_NUMBER = "Line"; //$NON-NLS-1$ | |
161 | ||
162 | final private ITmfSourceLookup fSourceLookup; | |
163 | ||
164 | public SourceLookupPropertySource(ITmfSourceLookup lookup) { | |
165 | fSourceLookup = lookup; | |
166 | } | |
167 | ||
168 | @Override | |
169 | public Object getEditableValue() { | |
170 | if (fSourceLookup.getCallsite() != null) { | |
171 | return fSourceLookup.getCallsite().toString(); | |
172 | } | |
173 | return null; | |
174 | } | |
175 | ||
176 | @Override | |
177 | public IPropertyDescriptor[] getPropertyDescriptors() { | |
178 | List<IPropertyDescriptor> descriptors= new ArrayList<IPropertyDescriptor>(); | |
179 | if (fSourceLookup.getCallsite() != null) { | |
180 | descriptors.add(new PropertyDescriptor(ID_FILE_NAME, NAME_FILE_NAME)); | |
181 | descriptors.add(new PropertyDescriptor(ID_LINE_NUMBER, NAME_LINE_NUMBER)); | |
182 | // only display function if available | |
183 | if (fSourceLookup.getCallsite().getFunctionName() != null) { | |
184 | descriptors.add(new PropertyDescriptor(ID_FUNCTION_NAME, NAME_FUNCTION_NAME)); | |
185 | } | |
186 | } | |
187 | return descriptors.toArray(new IPropertyDescriptor[0]); | |
188 | } | |
189 | ||
190 | @Override | |
191 | public Object getPropertyValue(Object id) { | |
192 | if (id.equals(ID_FILE_NAME)) { | |
193 | return fSourceLookup.getCallsite().getFileName(); | |
194 | } else if (id.equals(ID_FUNCTION_NAME)) { | |
195 | return fSourceLookup.getCallsite().getFunctionName(); | |
196 | } else if (id.equals(ID_LINE_NUMBER)) { | |
197 | return Long.valueOf(fSourceLookup.getCallsite().getLineNumber()); | |
198 | } | |
199 | return null; | |
200 | } | |
201 | ||
202 | @Override | |
203 | public boolean isPropertySet(Object id) { | |
204 | return false; | |
205 | } | |
206 | ||
207 | @Override | |
208 | public void resetPropertyValue(Object id) { | |
209 | ||
210 | } | |
211 | ||
212 | @Override | |
213 | public void setPropertyValue(Object id, Object value) { | |
214 | } | |
215 | } | |
216 | ||
217 | ||
93bfd50a PT |
218 | /** |
219 | * Default constructor | |
220 | * | |
221 | * @param event the event | |
222 | */ | |
223 | public TmfEventPropertySource(ITmfEvent event) { | |
224 | super(); | |
225 | this.fEvent = event; | |
226 | } | |
227 | ||
228 | @Override | |
229 | public Object getEditableValue() { | |
230 | return null; | |
231 | } | |
232 | ||
233 | @Override | |
234 | public IPropertyDescriptor[] getPropertyDescriptors() { | |
f47ed727 BH |
235 | List<IPropertyDescriptor> descriptors= new ArrayList<IPropertyDescriptor>(); |
236 | descriptors.add(new PropertyDescriptor(ID_TIMESTAMP, NAME_TIMESTAMP)); | |
237 | descriptors.add(new PropertyDescriptor(ID_SOURCE, NAME_SOURCE)); | |
238 | descriptors.add(new PropertyDescriptor(ID_TYPE, NAME_TYPE)); | |
239 | descriptors.add(new PropertyDescriptor(ID_REFERENCE, NAME_REFERENCE)); | |
240 | if ((fEvent instanceof ITmfSourceLookup) && (((ITmfSourceLookup)fEvent).getCallsite() != null)) { | |
241 | descriptors.add(new PropertyDescriptor(ID_SOURCE_LOOKUP, NAME_SOURCE_LOOKUP)); | |
242 | } | |
243 | if ((fEvent instanceof ITmfModelLookup) && (((ITmfModelLookup)fEvent).getModelUri() != null)) { | |
244 | descriptors.add(new PropertyDescriptor(ID_MODEL_URI, NAME_MODEL_URI)); | |
245 | } | |
246 | descriptors.add(new PropertyDescriptor(ID_CONTENT, NAME_CONTENT)); | |
247 | return descriptors.toArray(new IPropertyDescriptor[0]); | |
93bfd50a PT |
248 | } |
249 | ||
250 | @Override | |
251 | public Object getPropertyValue(Object id) { | |
252 | if (id.equals(ID_TIMESTAMP) && fEvent.getTimestamp() != null) { | |
253 | return new TimestampPropertySource(fEvent.getTimestamp()); | |
254 | } else if (id.equals(ID_SOURCE) && fEvent.getSource() != null) { | |
255 | return fEvent.getSource().toString(); | |
256 | } else if (id.equals(ID_TYPE) && fEvent.getType() != null) { | |
257 | return fEvent.getType().toString(); | |
258 | } else if (id.equals(ID_REFERENCE) && fEvent.getReference() != null) { | |
259 | return fEvent.getReference().toString(); | |
f47ed727 BH |
260 | } else if (id.equals(ID_MODEL_URI)) { |
261 | return ((ITmfModelLookup)fEvent).getModelUri(); | |
262 | } else if (id.equals(ID_SOURCE_LOOKUP)) { | |
263 | return new SourceLookupPropertySource(((ITmfSourceLookup)fEvent)); | |
93bfd50a PT |
264 | } else if (id.equals(ID_CONTENT) && fEvent.getContent() != null) { |
265 | return new ContentPropertySource(fEvent.getContent()); | |
266 | } | |
267 | return null; | |
268 | } | |
269 | ||
270 | @Override | |
271 | public boolean isPropertySet(Object id) { | |
272 | return false; | |
273 | } | |
274 | ||
275 | @Override | |
276 | public void resetPropertyValue(Object id) { | |
277 | } | |
278 | ||
279 | @Override | |
280 | public void setPropertyValue(Object id, Object value) { | |
281 | } | |
282 | ||
283 | } |