1 /*******************************************************************************
2 * Copyright (c) 2012 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
.ui
.views
.properties
.IPropertyDescriptor
;
19 import org
.eclipse
.ui
.views
.properties
.IPropertySource
;
20 import org
.eclipse
.ui
.views
.properties
.PropertyDescriptor
;
23 * Property source for events
27 public class TmfEventPropertySource
implements IPropertySource
{
29 private static final String ID_TIMESTAMP
= "event_timestamp"; //$NON-NLS-1$
30 private static final String ID_SOURCE
= "event_source"; //$NON-NLS-1$
31 private static final String ID_TYPE
= "event_type"; //$NON-NLS-1$
32 private static final String ID_REFERENCE
= "event_reference"; //$NON-NLS-1$
33 private static final String ID_CONTENT
= "event_content"; //$NON-NLS-1$
34 private static final String NAME_TIMESTAMP
= "Timestamp"; //$NON-NLS-1$
35 private static final String NAME_SOURCE
= "Source"; //$NON-NLS-1$
36 private static final String NAME_TYPE
= "Type"; //$NON-NLS-1$
37 private static final String NAME_REFERENCE
= "Reference"; //$NON-NLS-1$
38 private static final String NAME_CONTENT
= "Content"; //$NON-NLS-1$
40 private ITmfEvent fEvent
;
42 private class TimestampPropertySource
implements IPropertySource
{
43 private static final String ID_TIMESTAMP_VALUE
= "timestamp_value"; //$NON-NLS-1$
44 private static final String ID_TIMESTAMP_SCALE
= "timestamp_scale"; //$NON-NLS-1$
45 private static final String ID_TIMESTAMP_PRECISION
= "timestamp_precision"; //$NON-NLS-1$
46 private static final String NAME_TIMESTAMP_VALUE
= "value"; //$NON-NLS-1$
47 private static final String NAME_TIMESTAMP_SCALE
= "scale"; //$NON-NLS-1$
48 private static final String NAME_TIMESTAMP_PRECISION
= "precision"; //$NON-NLS-1$
50 private ITmfTimestamp fTimestamp
;
52 public TimestampPropertySource(ITmfTimestamp timestamp
) {
53 fTimestamp
= timestamp
;
57 public Object
getEditableValue() {
58 return fTimestamp
.toString();
62 public IPropertyDescriptor
[] getPropertyDescriptors() {
63 IPropertyDescriptor
[] descriptors
= new IPropertyDescriptor
[3];
64 descriptors
[0] = new PropertyDescriptor(ID_TIMESTAMP_VALUE
, NAME_TIMESTAMP_VALUE
);
65 descriptors
[1] = new PropertyDescriptor(ID_TIMESTAMP_SCALE
, NAME_TIMESTAMP_SCALE
);
66 descriptors
[2] = new PropertyDescriptor(ID_TIMESTAMP_PRECISION
, NAME_TIMESTAMP_PRECISION
);
71 public Object
getPropertyValue(Object id
) {
72 if (id
.equals(ID_TIMESTAMP_VALUE
)) {
73 return Long
.toString(fTimestamp
.getValue());
74 } else if (id
.equals(ID_TIMESTAMP_SCALE
)) {
75 return Integer
.toString(fTimestamp
.getScale());
76 } else if (id
.equals(ID_TIMESTAMP_PRECISION
)) {
77 return Integer
.toString(fTimestamp
.getPrecision());
83 public boolean isPropertySet(Object id
) {
88 public void resetPropertyValue(Object id
) {
92 public void setPropertyValue(Object id
, Object value
) {
96 private class ContentPropertySource
implements IPropertySource
{
97 private ITmfEventField fContent
;
99 public ContentPropertySource(ITmfEventField content
) {
104 public Object
getEditableValue() {
105 return fContent
.toString();
109 public IPropertyDescriptor
[] getPropertyDescriptors() {
110 List
<IPropertyDescriptor
> descriptors
= new ArrayList
<IPropertyDescriptor
>(fContent
.getFields().length
);
111 for (ITmfEventField field
: fContent
.getFields()) {
113 descriptors
.add(new PropertyDescriptor(field
, field
.getName()));
116 return descriptors
.toArray(new IPropertyDescriptor
[0]);
120 public Object
getPropertyValue(Object id
) {
121 ITmfEventField field
= (ITmfEventField
) id
;
122 if (field
.getFields() != null && field
.getFields().length
> 0) {
123 return new ContentPropertySource(field
);
125 return field
.getValue();
129 public boolean isPropertySet(Object id
) {
134 public void resetPropertyValue(Object id
) {
138 public void setPropertyValue(Object id
, Object value
) {
143 * Default constructor
145 * @param event the event
147 public TmfEventPropertySource(ITmfEvent event
) {
153 public Object
getEditableValue() {
158 public IPropertyDescriptor
[] getPropertyDescriptors() {
159 IPropertyDescriptor
[] descriptors
= new IPropertyDescriptor
[5];
160 descriptors
[0] = new PropertyDescriptor(ID_TIMESTAMP
, NAME_TIMESTAMP
);
161 descriptors
[1] = new PropertyDescriptor(ID_SOURCE
, NAME_SOURCE
);
162 descriptors
[2] = new PropertyDescriptor(ID_TYPE
, NAME_TYPE
);
163 descriptors
[3] = new PropertyDescriptor(ID_REFERENCE
, NAME_REFERENCE
);
164 descriptors
[4] = new PropertyDescriptor(ID_CONTENT
, NAME_CONTENT
);
169 public Object
getPropertyValue(Object id
) {
170 if (id
.equals(ID_TIMESTAMP
) && fEvent
.getTimestamp() != null) {
171 return new TimestampPropertySource(fEvent
.getTimestamp());
172 } else if (id
.equals(ID_SOURCE
) && fEvent
.getSource() != null) {
173 return fEvent
.getSource().toString();
174 } else if (id
.equals(ID_TYPE
) && fEvent
.getType() != null) {
175 return fEvent
.getType().toString();
176 } else if (id
.equals(ID_REFERENCE
) && fEvent
.getReference() != null) {
177 return fEvent
.getReference().toString();
178 } else if (id
.equals(ID_CONTENT
) && fEvent
.getContent() != null) {
179 return new ContentPropertySource(fEvent
.getContent());
185 public boolean isPropertySet(Object id
) {
190 public void resetPropertyValue(Object id
) {
194 public void setPropertyValue(Object id
, Object value
) {