tmf: Update copyright headers in tmf.core
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core / src / org / eclipse / linuxtools / tmf / core / event / TmfEventPropertySource.java
1 /*******************************************************************************
2 * Copyright (c) 2012, 2013 Ericsson
3 *
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
8 *
9 * Contributors:
10 * Patrick Tasse - Initial API and implementation
11 *******************************************************************************/
12
13 package org.eclipse.linuxtools.tmf.core.event;
14
15 import java.util.ArrayList;
16 import java.util.List;
17
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;
22
23 /**
24 * Property source for events
25 *
26 * @since 2.0
27 */
28 public class TmfEventPropertySource implements IPropertySource {
29
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$
40
41 private ITmfEvent fEvent;
42
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$
50
51 private ITmfTimestamp fTimestamp;
52
53 public TimestampPropertySource(ITmfTimestamp timestamp) {
54 fTimestamp = timestamp;
55 }
56
57 @Override
58 public Object getEditableValue() {
59 return fTimestamp.toString();
60 }
61
62 @Override
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);
68 return descriptors;
69 }
70
71 @Override
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());
79 }
80 return null;
81 }
82
83 @Override
84 public boolean isPropertySet(Object id) {
85 return false;
86 }
87
88 @Override
89 public void resetPropertyValue(Object id) {
90 }
91
92 @Override
93 public void setPropertyValue(Object id, Object value) {
94 }
95 }
96
97 private class ContentPropertySource implements IPropertySource {
98 private ITmfEventField fContent;
99
100 public ContentPropertySource(ITmfEventField content) {
101 fContent = content;
102 }
103
104 @Override
105 public Object getEditableValue() {
106 return fContent.toString();
107 }
108
109 @Override
110 public IPropertyDescriptor[] getPropertyDescriptors() {
111 List<IPropertyDescriptor> descriptors= new ArrayList<IPropertyDescriptor>(fContent.getFields().length);
112 for (ITmfEventField field : fContent.getFields()) {
113 if (field != null) {
114 descriptors.add(new PropertyDescriptor(field, field.getName()));
115 }
116 }
117 return descriptors.toArray(new IPropertyDescriptor[0]);
118 }
119
120 @Override
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);
125 }
126 return field.getValue();
127 }
128
129 @Override
130 public boolean isPropertySet(Object id) {
131 return false;
132 }
133
134 @Override
135 public void resetPropertyValue(Object id) {
136 }
137
138 @Override
139 public void setPropertyValue(Object id, Object value) {
140 }
141 }
142
143 /**
144 * Default constructor
145 *
146 * @param event the event
147 */
148 public TmfEventPropertySource(ITmfEvent event) {
149 super();
150 this.fEvent = event;
151 }
152
153 @Override
154 public Object getEditableValue() {
155 return null;
156 }
157
158 @Override
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);
166 return descriptors;
167 }
168
169 @Override
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());
181 }
182 return null;
183 }
184
185 @Override
186 public boolean isPropertySet(Object id) {
187 return false;
188 }
189
190 @Override
191 public void resetPropertyValue(Object id) {
192 }
193
194 @Override
195 public void setPropertyValue(Object id, Object value) {
196 }
197
198 }
This page took 0.03615 seconds and 6 git commands to generate.