1 /*******************************************************************************
2 * Copyright (c) 2012, 2013 Ericsson
4 * All rights reserved. This program and the accompanying materials are made
5 * 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 * Patrick Tasse - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.tmf
.core
.event
;
15 import java
.util
.ArrayList
;
16 import java
.util
.List
;
18 import org
.eclipse
.linuxtools
.tmf
.core
.timestamp
.ITmfTimestamp
;
19 import org
.eclipse
.ui
.views
.properties
.IPropertyDescriptor
;
20 import org
.eclipse
.ui
.views
.properties
.IPropertySource
;
21 import org
.eclipse
.ui
.views
.properties
.PropertyDescriptor
;
24 * Property source for events
28 public class TmfEventPropertySource
implements IPropertySource
{
30 private static final String ID_TIMESTAMP
= "event_timestamp"; //$NON-NLS-1$
31 private static final String ID_SOURCE
= "event_source"; //$NON-NLS-1$
32 private static final String ID_TYPE
= "event_type"; //$NON-NLS-1$
33 private static final String ID_REFERENCE
= "event_reference"; //$NON-NLS-1$
34 private static final String ID_CONTENT
= "event_content"; //$NON-NLS-1$
35 private static final String NAME_TIMESTAMP
= "Timestamp"; //$NON-NLS-1$
36 private static final String NAME_SOURCE
= "Source"; //$NON-NLS-1$
37 private static final String NAME_TYPE
= "Type"; //$NON-NLS-1$
38 private static final String NAME_REFERENCE
= "Reference"; //$NON-NLS-1$
39 private static final String NAME_CONTENT
= "Content"; //$NON-NLS-1$
41 private ITmfEvent fEvent
;
43 private class TimestampPropertySource
implements IPropertySource
{
44 private static final String ID_TIMESTAMP_VALUE
= "timestamp_value"; //$NON-NLS-1$
45 private static final String ID_TIMESTAMP_SCALE
= "timestamp_scale"; //$NON-NLS-1$
46 private static final String ID_TIMESTAMP_PRECISION
= "timestamp_precision"; //$NON-NLS-1$
47 private static final String NAME_TIMESTAMP_VALUE
= "value"; //$NON-NLS-1$
48 private static final String NAME_TIMESTAMP_SCALE
= "scale"; //$NON-NLS-1$
49 private static final String NAME_TIMESTAMP_PRECISION
= "precision"; //$NON-NLS-1$
51 private ITmfTimestamp fTimestamp
;
53 public TimestampPropertySource(ITmfTimestamp timestamp
) {
54 fTimestamp
= timestamp
;
58 public Object
getEditableValue() {
59 return fTimestamp
.toString();
63 public IPropertyDescriptor
[] getPropertyDescriptors() {
64 IPropertyDescriptor
[] descriptors
= new IPropertyDescriptor
[3];
65 descriptors
[0] = new PropertyDescriptor(ID_TIMESTAMP_VALUE
, NAME_TIMESTAMP_VALUE
);
66 descriptors
[1] = new PropertyDescriptor(ID_TIMESTAMP_SCALE
, NAME_TIMESTAMP_SCALE
);
67 descriptors
[2] = new PropertyDescriptor(ID_TIMESTAMP_PRECISION
, NAME_TIMESTAMP_PRECISION
);
72 public Object
getPropertyValue(Object id
) {
73 if (id
.equals(ID_TIMESTAMP_VALUE
)) {
74 return Long
.toString(fTimestamp
.getValue());
75 } else if (id
.equals(ID_TIMESTAMP_SCALE
)) {
76 return Integer
.toString(fTimestamp
.getScale());
77 } else if (id
.equals(ID_TIMESTAMP_PRECISION
)) {
78 return Integer
.toString(fTimestamp
.getPrecision());
84 public boolean isPropertySet(Object id
) {
89 public void resetPropertyValue(Object id
) {
93 public void setPropertyValue(Object id
, Object value
) {
97 private class ContentPropertySource
implements IPropertySource
{
98 private ITmfEventField fContent
;
100 public ContentPropertySource(ITmfEventField content
) {
105 public Object
getEditableValue() {
106 return fContent
.toString();
110 public IPropertyDescriptor
[] getPropertyDescriptors() {
111 List
<IPropertyDescriptor
> descriptors
= new ArrayList
<IPropertyDescriptor
>(fContent
.getFields().length
);
112 for (ITmfEventField field
: fContent
.getFields()) {
114 descriptors
.add(new PropertyDescriptor(field
, field
.getName()));
117 return descriptors
.toArray(new IPropertyDescriptor
[0]);
121 public Object
getPropertyValue(Object id
) {
122 ITmfEventField field
= (ITmfEventField
) id
;
123 if (field
.getFields() != null && field
.getFields().length
> 0) {
124 return new ContentPropertySource(field
);
126 return field
.getValue();
130 public boolean isPropertySet(Object id
) {
135 public void resetPropertyValue(Object id
) {
139 public void setPropertyValue(Object id
, Object value
) {
144 * Default constructor
146 * @param event the event
148 public TmfEventPropertySource(ITmfEvent event
) {
154 public Object
getEditableValue() {
159 public IPropertyDescriptor
[] getPropertyDescriptors() {
160 IPropertyDescriptor
[] descriptors
= new IPropertyDescriptor
[5];
161 descriptors
[0] = new PropertyDescriptor(ID_TIMESTAMP
, NAME_TIMESTAMP
);
162 descriptors
[1] = new PropertyDescriptor(ID_SOURCE
, NAME_SOURCE
);
163 descriptors
[2] = new PropertyDescriptor(ID_TYPE
, NAME_TYPE
);
164 descriptors
[3] = new PropertyDescriptor(ID_REFERENCE
, NAME_REFERENCE
);
165 descriptors
[4] = new PropertyDescriptor(ID_CONTENT
, NAME_CONTENT
);
170 public Object
getPropertyValue(Object id
) {
171 if (id
.equals(ID_TIMESTAMP
) && fEvent
.getTimestamp() != null) {
172 return new TimestampPropertySource(fEvent
.getTimestamp());
173 } else if (id
.equals(ID_SOURCE
) && fEvent
.getSource() != null) {
174 return fEvent
.getSource().toString();
175 } else if (id
.equals(ID_TYPE
) && fEvent
.getType() != null) {
176 return fEvent
.getType().toString();
177 } else if (id
.equals(ID_REFERENCE
) && fEvent
.getReference() != null) {
178 return fEvent
.getReference().toString();
179 } else if (id
.equals(ID_CONTENT
) && fEvent
.getContent() != null) {
180 return new ContentPropertySource(fEvent
.getContent());
186 public boolean isPropertySet(Object id
) {
191 public void resetPropertyValue(Object id
) {
195 public void setPropertyValue(Object id
, Object value
) {