ctf: Rename packages to org.eclipse.tracecompass.*
[deliverable/tracecompass.git] / org.eclipse.tracecompass.btf.ui / src / org / eclipse / linuxtools / btf / ui / BtfEventPropertySource.java
CommitLineData
ff71e543
MK
1/*******************************************************************************
2 * Copyright (c) 2014 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 *******************************************************************************/
12
13package org.eclipse.linuxtools.btf.ui;
14
15import java.util.ArrayList;
16import java.util.List;
17
18import org.eclipse.linuxtools.btf.core.event.BtfEvent;
2bdf0193
AM
19import org.eclipse.tracecompass.tmf.core.event.ITmfEventField;
20import org.eclipse.tracecompass.tmf.ui.properties.ReadOnlyTextPropertyDescriptor;
21import org.eclipse.tracecompass.tmf.ui.viewers.events.TmfEventPropertySource;
ff71e543
MK
22import org.eclipse.ui.views.properties.IPropertyDescriptor;
23import org.eclipse.ui.views.properties.IPropertySource;
24
25/**
26 * Btf event property source
27 *
28 * @author Matthew Khouzam
29 */
30public class BtfEventPropertySource extends TmfEventPropertySource {
31
32 private static final String ID_EVENT_EVENT = "event_event"; //$NON-NLS-1$
33 private static final String ID_EVENT_TIMESTAMP = "event_timestamp"; //$NON-NLS-1$
34 private static final String ID_EVENT_SOURCE = "event_source"; //$NON-NLS-1$
35 private static final String ID_EVENT_TYPE = "event_type"; //$NON-NLS-1$
36 private static final String ID_EVENT_TARGET = "event_target"; //$NON-NLS-1$
37 private final BtfEvent fEvent;
38
39 /**
40 * Btf Event property source
41 *
42 * @param event
43 * the event
44 */
45 public BtfEventPropertySource(BtfEvent event) {
46 super(event);
47 fEvent = event;
48
49 }
50
51 @Override
52 public IPropertyDescriptor[] getPropertyDescriptors() {
53 return new IPropertyDescriptor[] {
54 new ReadOnlyTextPropertyDescriptor(ID_EVENT_TIMESTAMP, "Timestamp"), //$NON-NLS-1$
55 new ReadOnlyTextPropertyDescriptor(ID_EVENT_SOURCE, "Source"), //$NON-NLS-1$
56 new ReadOnlyTextPropertyDescriptor(ID_EVENT_TYPE, "Type"), //$NON-NLS-1$
57 new ReadOnlyTextPropertyDescriptor(ID_EVENT_TARGET, "Target"), //$NON-NLS-1$
58 new ReadOnlyTextPropertyDescriptor(ID_EVENT_EVENT, "event") //$NON-NLS-1$
59 };
60 }
61
62 private class TargetPropertySource implements IPropertySource {
63 private static final String INSTANCE = "Instance"; //$NON-NLS-1$
64 private final String fTarget;
65 private final String fInstance;
66
67 public TargetPropertySource(String target, String instance) {
68 fTarget = target;
69 fInstance = instance;
70 }
71
72 @Override
73 public Object getEditableValue() {
74 return fTarget;
75 }
76
77 @Override
78 public IPropertyDescriptor[] getPropertyDescriptors() {
79 return new IPropertyDescriptor[] {
80 new ReadOnlyTextPropertyDescriptor(INSTANCE, INSTANCE)
81 };
82 }
83
84 @Override
85 public Object getPropertyValue(Object id) {
86 if (INSTANCE.equals(id)) {
87 return fInstance;
88 }
89 return null;
90 }
91
92 @Override
93 public boolean isPropertySet(Object id) {
94 return INSTANCE.equals(id);
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
107 private class TypePropertySource implements IPropertySource {
108 private static final String DESCRIPTION = "Description"; //$NON-NLS-1$
109 private final String fType;
110 private final String fDescr;
111
112 public TypePropertySource(String type, String descr) {
113 fType = type;
114 fDescr = descr;
115 }
116
117 @Override
118 public Object getEditableValue() {
119 return fType;
120 }
121
122 @Override
123 public IPropertyDescriptor[] getPropertyDescriptors() {
124 IPropertyDescriptor[] descriptors = new IPropertyDescriptor[1];
125 descriptors[0] = new ReadOnlyTextPropertyDescriptor(DESCRIPTION, DESCRIPTION);
126 return descriptors;
127 }
128
129 @Override
130 public Object getPropertyValue(Object id) {
131 if (DESCRIPTION.equals(id)) {
132 return fDescr;
133 }
134 return null;
135 }
136
137 @Override
138 public boolean isPropertySet(Object id) {
139 return DESCRIPTION.equals(id);
140 }
141
142 @Override
143 public void resetPropertyValue(Object id) {
144 }
145
146 @Override
147 public void setPropertyValue(Object id, Object value) {
148 }
149 }
150
151 private class EventPropertySource implements IPropertySource {
152 private static final String DESCRIPTION = "Description"; //$NON-NLS-1$
153 private static final String NOTE = "Note"; //$NON-NLS-1$
154 final String fEventName;
155 final String fNote;
156 final String fEventDescription;
157
158 public EventPropertySource(String event, String note) {
159 fEventName = event;
160 fNote = note;
161
162 ITmfEventField content = fEvent.getContent();
163 String first = content.getFieldNames().iterator().next();
164 content = content.getField(first);
165 first = content.getFieldNames().iterator().next();
166 fEventDescription = content.getField(first).getValue().toString();
167 }
168
169 @Override
170 public Object getEditableValue() {
171 return fEventName;
172 }
173
174 @Override
175 public IPropertyDescriptor[] getPropertyDescriptors() {
176 if (fNote == null) {
177 return new IPropertyDescriptor[] {
178 new ReadOnlyTextPropertyDescriptor(DESCRIPTION, DESCRIPTION)
179 };
180 }
181 return new IPropertyDescriptor[] {
182 new ReadOnlyTextPropertyDescriptor(DESCRIPTION, DESCRIPTION),
183 new ReadOnlyTextPropertyDescriptor(NOTE, NOTE)
184 };
185 }
186
187 @Override
188 public Object getPropertyValue(Object id) {
189 if (NOTE.equals(id)) {
190 return fNote;
191 } else if (DESCRIPTION.equals(id)) {
192 return fEventDescription;
193 }
194 return null;
195 }
196
197 @Override
198 public boolean isPropertySet(Object id) {
199 return false;
200 }
201
202 @Override
203 public void resetPropertyValue(Object id) {
204 }
205
206 @Override
207 public void setPropertyValue(Object id, Object value) {
208 }
209
210 }
211
212 @Override
213 public Object getPropertyValue(Object id) {
214 if (id instanceof String) {
215 String id2 = (String) id;
216 final ITmfEventField content = fEvent.getContent();
217 List<String> fieldNames = new ArrayList<>(content.getFieldNames());
218 switch (id2) {
219 case ID_EVENT_TARGET:
220 return new TargetPropertySource(fEvent.getReference(), content.getField(fieldNames.get(2)).toString());
221 case ID_EVENT_SOURCE:
222 return new TargetPropertySource(fEvent.getSource(), content.getField(fieldNames.get(1)).toString());
223 case ID_EVENT_TYPE:
224 return new TypePropertySource(fEvent.getType().getName(), fEvent.getEventDescription());
225 case ID_EVENT_EVENT:
226 ITmfEventField noteField = (fieldNames.size() > 3) ? content.getField(fieldNames.get(3)) : null;
227 return new EventPropertySource(content.getField(fieldNames.get(0)).getValue().toString(), (noteField == null) ? null : noteField.getValue().toString());
228 default:
229 break;
230 }
231 }
232 return super.getPropertyValue(id);
233 }
234}
This page took 0.065511 seconds and 5 git commands to generate.