tmf: Update event properties to use aspects
[deliverable/tracecompass.git] / btf / org.eclipse.tracecompass.btf.ui / src / org / eclipse / tracecompass / btf / ui / BtfEventPropertySource.java
1 /*******************************************************************************
2 * Copyright (c) 2014, 2015 Ericsson
3 *
4 * All rights reserved. This program and the accompanying materials are
5 * made 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 * Matthew Khouzam - Initial API and implementation
11 * Patrick Tasse - Update properties
12 *******************************************************************************/
13
14 package org.eclipse.tracecompass.btf.ui;
15
16 import java.util.Arrays;
17
18 import org.eclipse.jdt.annotation.NonNull;
19 import org.eclipse.tracecompass.btf.core.event.BTFPayload;
20 import org.eclipse.tracecompass.btf.core.event.BtfEvent;
21 import org.eclipse.tracecompass.btf.core.trace.BtfColumnNames;
22 import org.eclipse.tracecompass.tmf.core.event.ITmfEventField;
23 import org.eclipse.tracecompass.tmf.ui.properties.ReadOnlyTextPropertyDescriptor;
24 import org.eclipse.tracecompass.tmf.ui.viewers.events.TmfEventPropertySource;
25 import org.eclipse.ui.views.properties.IPropertyDescriptor;
26 import org.eclipse.ui.views.properties.IPropertySource;
27
28 /**
29 * Btf event property source
30 *
31 * @author Matthew Khouzam
32 */
33 public class BtfEventPropertySource extends TmfEventPropertySource {
34
35 private static final String ID_EVENT_EVENT = "event_event"; //$NON-NLS-1$
36 private static final String ID_EVENT_TIMESTAMP = "event_timestamp"; //$NON-NLS-1$
37 private static final String ID_EVENT_SOURCE = "event_source"; //$NON-NLS-1$
38 private static final String ID_EVENT_TYPE = "event_type"; //$NON-NLS-1$
39 private static final String ID_EVENT_TARGET = "event_target"; //$NON-NLS-1$
40 private static final String ID_EVENT_NOTES = "event_notes"; //$NON-NLS-1$
41 private static final IPropertyDescriptor[] DESCRIPTORS = new IPropertyDescriptor[] {
42 new ReadOnlyTextPropertyDescriptor(ID_EVENT_TIMESTAMP, "Timestamp"), //$NON-NLS-1$
43 new ReadOnlyTextPropertyDescriptor(ID_EVENT_SOURCE, "Source"), //$NON-NLS-1$
44 new ReadOnlyTextPropertyDescriptor(ID_EVENT_TYPE, "Type"), //$NON-NLS-1$
45 new ReadOnlyTextPropertyDescriptor(ID_EVENT_TARGET, "Target"), //$NON-NLS-1$
46 new ReadOnlyTextPropertyDescriptor(ID_EVENT_EVENT, "Event"), //$NON-NLS-1$
47 new ReadOnlyTextPropertyDescriptor(ID_EVENT_NOTES, "Notes") //$NON-NLS-1$
48 };
49 private static final IPropertyDescriptor[] DESCRIPTORS_WITHOUT_NOTES = Arrays.copyOf(DESCRIPTORS, DESCRIPTORS.length - 1);
50 private static final String DESCRIPTION = "Description"; //$NON-NLS-1$
51 private static final String INSTANCE = "Instance"; //$NON-NLS-1$
52
53 private final BtfEvent fEvent;
54
55 /**
56 * Btf Event property source
57 *
58 * @param event
59 * the event
60 */
61 public BtfEventPropertySource(@NonNull BtfEvent event) {
62 super(event);
63 fEvent = event;
64
65 }
66
67 @Override
68 public IPropertyDescriptor[] getPropertyDescriptors() {
69 if (fEvent.getContent().getField(BtfColumnNames.NOTES.toString()) == null) {
70 return DESCRIPTORS_WITHOUT_NOTES;
71 }
72 return DESCRIPTORS;
73 }
74
75 private static class EntityPropertySource implements IPropertySource {
76 private final String fName;
77 private final String fInstance;
78
79 public EntityPropertySource(String name, String instance) {
80 fName = name;
81 fInstance = instance;
82 }
83
84 @Override
85 public Object getEditableValue() {
86 return fName;
87 }
88
89 @Override
90 public IPropertyDescriptor[] getPropertyDescriptors() {
91 return new IPropertyDescriptor[] {
92 new ReadOnlyTextPropertyDescriptor(INSTANCE, INSTANCE)
93 };
94 }
95
96 @Override
97 public Object getPropertyValue(Object id) {
98 if (INSTANCE.equals(id)) {
99 return fInstance;
100 }
101 return null;
102 }
103
104 @Override
105 public boolean isPropertySet(Object id) {
106 return false;
107 }
108
109 @Override
110 public void resetPropertyValue(Object id) {
111 }
112
113 @Override
114 public void setPropertyValue(Object id, Object value) {
115 }
116
117 }
118
119 private static class TypePropertySource implements IPropertySource {
120 private final String fType;
121 private final String fDescr;
122
123 public TypePropertySource(String type, String descr) {
124 fType = type;
125 fDescr = descr;
126 }
127
128 @Override
129 public Object getEditableValue() {
130 return fType;
131 }
132
133 @Override
134 public IPropertyDescriptor[] getPropertyDescriptors() {
135 IPropertyDescriptor[] descriptors = new IPropertyDescriptor[1];
136 descriptors[0] = new ReadOnlyTextPropertyDescriptor(DESCRIPTION, DESCRIPTION);
137 return descriptors;
138 }
139
140 @Override
141 public Object getPropertyValue(Object id) {
142 if (DESCRIPTION.equals(id)) {
143 return fDescr;
144 }
145 return null;
146 }
147
148 @Override
149 public boolean isPropertySet(Object id) {
150 return false;
151 }
152
153 @Override
154 public void resetPropertyValue(Object id) {
155 }
156
157 @Override
158 public void setPropertyValue(Object id, Object value) {
159 }
160 }
161
162 private static class EventPropertySource implements IPropertySource {
163 private final ITmfEventField fEventField;
164
165 public EventPropertySource(ITmfEventField eventField) {
166 fEventField = eventField;
167 }
168
169 @Override
170 public Object getEditableValue() {
171 return fEventField.getValue();
172 }
173
174 @Override
175 public IPropertyDescriptor[] getPropertyDescriptors() {
176 return new IPropertyDescriptor[] {
177 new ReadOnlyTextPropertyDescriptor(DESCRIPTION, DESCRIPTION)
178 };
179 }
180
181 @Override
182 public Object getPropertyValue(Object id) {
183 if (DESCRIPTION.equals(id)) {
184 ITmfEventField description = fEventField.getField(BTFPayload.DESCRIPTION);
185 return description == null ? null : description.getValue();
186 }
187 return null;
188 }
189
190 @Override
191 public boolean isPropertySet(Object id) {
192 return false;
193 }
194
195 @Override
196 public void resetPropertyValue(Object id) {
197 }
198
199 @Override
200 public void setPropertyValue(Object id, Object value) {
201 }
202
203 }
204
205 @Override
206 public Object getPropertyValue(Object id) {
207 if (id instanceof String) {
208 String id2 = (String) id;
209 final ITmfEventField content = fEvent.getContent();
210 switch (id2) {
211 case ID_EVENT_SOURCE:
212 String source = fEvent.getSource();
213 ITmfEventField sourceInstance = content.getField(BtfColumnNames.SOURCE_INSTANCE.toString());
214 return new EntityPropertySource(source, sourceInstance.getValue().toString());
215 case ID_EVENT_TYPE:
216 return new TypePropertySource(fEvent.getType().getName(), fEvent.getEventDescription());
217 case ID_EVENT_TARGET:
218 String target = fEvent.getTarget();
219 ITmfEventField targetInstance = content.getField(BtfColumnNames.TARGET_INSTANCE.toString());
220 return new EntityPropertySource(target, targetInstance.getValue().toString());
221 case ID_EVENT_EVENT:
222 ITmfEventField event = content.getField(BtfColumnNames.EVENT.toString());
223 return event == null ? null : new EventPropertySource(event);
224 case ID_EVENT_NOTES:
225 ITmfEventField notes = content.getField(BtfColumnNames.NOTES.toString());
226 return notes == null ? null : notes.getValue();
227 default:
228 break;
229 }
230 }
231 return super.getPropertyValue(id);
232 }
233 }
This page took 0.03785 seconds and 5 git commands to generate.