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