1 /*******************************************************************************
2 * Copyright (c) 2014, 2015 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 * Patrick Tasse - Update properties
12 *******************************************************************************/
14 package org
.eclipse
.tracecompass
.btf
.ui
;
16 import java
.util
.Arrays
;
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
;
29 * Btf event property source
31 * @author Matthew Khouzam
33 public class BtfEventPropertySource
extends TmfEventPropertySource
{
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$
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$
53 private final BtfEvent fEvent
;
56 * Btf Event property source
61 public BtfEventPropertySource(@NonNull BtfEvent event
) {
68 public IPropertyDescriptor
[] getPropertyDescriptors() {
69 if (fEvent
.getContent().getField(BtfColumnNames
.NOTES
.toString()) == null) {
70 return DESCRIPTORS_WITHOUT_NOTES
;
75 private static class EntityPropertySource
implements IPropertySource
{
76 private final String fName
;
77 private final String fInstance
;
79 public EntityPropertySource(String name
, String instance
) {
85 public Object
getEditableValue() {
90 public IPropertyDescriptor
[] getPropertyDescriptors() {
91 return new IPropertyDescriptor
[] {
92 new ReadOnlyTextPropertyDescriptor(INSTANCE
, INSTANCE
)
97 public Object
getPropertyValue(Object id
) {
98 if (INSTANCE
.equals(id
)) {
105 public boolean isPropertySet(Object id
) {
110 public void resetPropertyValue(Object id
) {
114 public void setPropertyValue(Object id
, Object value
) {
119 private static class TypePropertySource
implements IPropertySource
{
120 private final String fType
;
121 private final String fDescr
;
123 public TypePropertySource(String type
, String descr
) {
129 public Object
getEditableValue() {
134 public IPropertyDescriptor
[] getPropertyDescriptors() {
135 IPropertyDescriptor
[] descriptors
= new IPropertyDescriptor
[1];
136 descriptors
[0] = new ReadOnlyTextPropertyDescriptor(DESCRIPTION
, DESCRIPTION
);
141 public Object
getPropertyValue(Object id
) {
142 if (DESCRIPTION
.equals(id
)) {
149 public boolean isPropertySet(Object id
) {
154 public void resetPropertyValue(Object id
) {
158 public void setPropertyValue(Object id
, Object value
) {
162 private static class EventPropertySource
implements IPropertySource
{
163 private final ITmfEventField fEventField
;
165 public EventPropertySource(ITmfEventField eventField
) {
166 fEventField
= eventField
;
170 public Object
getEditableValue() {
171 return fEventField
.getValue();
175 public IPropertyDescriptor
[] getPropertyDescriptors() {
176 return new IPropertyDescriptor
[] {
177 new ReadOnlyTextPropertyDescriptor(DESCRIPTION
, DESCRIPTION
)
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();
191 public boolean isPropertySet(Object id
) {
196 public void resetPropertyValue(Object id
) {
200 public void setPropertyValue(Object id
, Object value
) {
206 public Object
getPropertyValue(Object id
) {
207 if (id
instanceof String
) {
208 String id2
= (String
) id
;
209 final ITmfEventField content
= fEvent
.getContent();
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());
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());
222 ITmfEventField event
= content
.getField(BtfColumnNames
.EVENT
.toString());
223 return event
== null ?
null : new EventPropertySource(event
);
225 ITmfEventField notes
= content
.getField(BtfColumnNames
.NOTES
.toString());
226 return notes
== null ?
null : notes
.getValue();
231 return super.getPropertyValue(id
);