1 /*******************************************************************************
2 * Copyright (c) 2014 Ericsson
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
10 * Matthew Khouzam - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.btf
.ui
;
15 import java
.util
.ArrayList
;
16 import java
.util
.List
;
18 import org
.eclipse
.linuxtools
.btf
.core
.event
.BtfEvent
;
19 import org
.eclipse
.tracecompass
.tmf
.core
.event
.ITmfEventField
;
20 import org
.eclipse
.tracecompass
.tmf
.ui
.properties
.ReadOnlyTextPropertyDescriptor
;
21 import org
.eclipse
.tracecompass
.tmf
.ui
.viewers
.events
.TmfEventPropertySource
;
22 import org
.eclipse
.ui
.views
.properties
.IPropertyDescriptor
;
23 import org
.eclipse
.ui
.views
.properties
.IPropertySource
;
26 * Btf event property source
28 * @author Matthew Khouzam
30 public class BtfEventPropertySource
extends TmfEventPropertySource
{
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
;
40 * Btf Event property source
45 public BtfEventPropertySource(BtfEvent event
) {
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$
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
;
67 public TargetPropertySource(String target
, String instance
) {
73 public Object
getEditableValue() {
78 public IPropertyDescriptor
[] getPropertyDescriptors() {
79 return new IPropertyDescriptor
[] {
80 new ReadOnlyTextPropertyDescriptor(INSTANCE
, INSTANCE
)
85 public Object
getPropertyValue(Object id
) {
86 if (INSTANCE
.equals(id
)) {
93 public boolean isPropertySet(Object id
) {
94 return INSTANCE
.equals(id
);
98 public void resetPropertyValue(Object id
) {
102 public void setPropertyValue(Object id
, Object value
) {
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
;
112 public TypePropertySource(String type
, String descr
) {
118 public Object
getEditableValue() {
123 public IPropertyDescriptor
[] getPropertyDescriptors() {
124 IPropertyDescriptor
[] descriptors
= new IPropertyDescriptor
[1];
125 descriptors
[0] = new ReadOnlyTextPropertyDescriptor(DESCRIPTION
, DESCRIPTION
);
130 public Object
getPropertyValue(Object id
) {
131 if (DESCRIPTION
.equals(id
)) {
138 public boolean isPropertySet(Object id
) {
139 return DESCRIPTION
.equals(id
);
143 public void resetPropertyValue(Object id
) {
147 public void setPropertyValue(Object id
, Object value
) {
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
;
156 final String fEventDescription
;
158 public EventPropertySource(String event
, String note
) {
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();
170 public Object
getEditableValue() {
175 public IPropertyDescriptor
[] getPropertyDescriptors() {
177 return new IPropertyDescriptor
[] {
178 new ReadOnlyTextPropertyDescriptor(DESCRIPTION
, DESCRIPTION
)
181 return new IPropertyDescriptor
[] {
182 new ReadOnlyTextPropertyDescriptor(DESCRIPTION
, DESCRIPTION
),
183 new ReadOnlyTextPropertyDescriptor(NOTE
, NOTE
)
188 public Object
getPropertyValue(Object id
) {
189 if (NOTE
.equals(id
)) {
191 } else if (DESCRIPTION
.equals(id
)) {
192 return fEventDescription
;
198 public boolean isPropertySet(Object id
) {
203 public void resetPropertyValue(Object id
) {
207 public void setPropertyValue(Object id
, Object value
) {
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());
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());
224 return new TypePropertySource(fEvent
.getType().getName(), fEvent
.getEventDescription());
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());
232 return super.getPropertyValue(id
);