Commit | Line | Data |
---|---|---|
93bfd50a PT |
1 | /******************************************************************************* |
2 | * Copyright (c) 2012 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.ui.views.properties.IPropertyDescriptor; | |
19 | import org.eclipse.ui.views.properties.IPropertySource; | |
20 | import org.eclipse.ui.views.properties.PropertyDescriptor; | |
21 | ||
22 | /** | |
23 | * Property source for events | |
24 | * | |
25 | * @since 2.0 | |
26 | */ | |
27 | public class TmfEventPropertySource implements IPropertySource { | |
28 | ||
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$ | |
39 | ||
40 | private ITmfEvent fEvent; | |
41 | ||
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$ | |
49 | ||
50 | private ITmfTimestamp fTimestamp; | |
51 | ||
52 | public TimestampPropertySource(ITmfTimestamp timestamp) { | |
53 | fTimestamp = timestamp; | |
54 | } | |
55 | ||
56 | @Override | |
57 | public Object getEditableValue() { | |
58 | return fTimestamp.toString(); | |
59 | } | |
60 | ||
61 | @Override | |
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); | |
67 | return descriptors; | |
68 | } | |
69 | ||
70 | @Override | |
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()); | |
78 | } | |
79 | return null; | |
80 | } | |
81 | ||
82 | @Override | |
83 | public boolean isPropertySet(Object id) { | |
84 | return false; | |
85 | } | |
86 | ||
87 | @Override | |
88 | public void resetPropertyValue(Object id) { | |
89 | } | |
90 | ||
91 | @Override | |
92 | public void setPropertyValue(Object id, Object value) { | |
93 | } | |
94 | } | |
95 | ||
96 | private class ContentPropertySource implements IPropertySource { | |
97 | private ITmfEventField fContent; | |
98 | ||
99 | public ContentPropertySource(ITmfEventField content) { | |
100 | fContent = content; | |
101 | } | |
102 | ||
103 | @Override | |
104 | public Object getEditableValue() { | |
105 | return fContent.toString(); | |
106 | } | |
107 | ||
108 | @Override | |
109 | public IPropertyDescriptor[] getPropertyDescriptors() { | |
110 | List<IPropertyDescriptor> descriptors= new ArrayList<IPropertyDescriptor>(fContent.getFields().length); | |
111 | for (ITmfEventField field : fContent.getFields()) { | |
112 | if (field != null) { | |
113 | descriptors.add(new PropertyDescriptor(field, field.getName())); | |
114 | } | |
115 | } | |
116 | return descriptors.toArray(new IPropertyDescriptor[0]); | |
117 | } | |
118 | ||
119 | @Override | |
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); | |
124 | } | |
125 | return field.getValue(); | |
126 | } | |
127 | ||
128 | @Override | |
129 | public boolean isPropertySet(Object id) { | |
130 | return false; | |
131 | } | |
132 | ||
133 | @Override | |
134 | public void resetPropertyValue(Object id) { | |
135 | } | |
136 | ||
137 | @Override | |
138 | public void setPropertyValue(Object id, Object value) { | |
139 | } | |
140 | } | |
141 | ||
142 | /** | |
143 | * Default constructor | |
144 | * | |
145 | * @param event the event | |
146 | */ | |
147 | public TmfEventPropertySource(ITmfEvent event) { | |
148 | super(); | |
149 | this.fEvent = event; | |
150 | } | |
151 | ||
152 | @Override | |
153 | public Object getEditableValue() { | |
154 | return null; | |
155 | } | |
156 | ||
157 | @Override | |
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); | |
165 | return descriptors; | |
166 | } | |
167 | ||
168 | @Override | |
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()); | |
180 | } | |
181 | return null; | |
182 | } | |
183 | ||
184 | @Override | |
185 | public boolean isPropertySet(Object id) { | |
186 | return false; | |
187 | } | |
188 | ||
189 | @Override | |
190 | public void resetPropertyValue(Object id) { | |
191 | } | |
192 | ||
193 | @Override | |
194 | public void setPropertyValue(Object id, Object value) { | |
195 | } | |
196 | ||
197 | } |