Commit | Line | Data |
---|---|---|
b0d3496e | 1 | /******************************************************************************* |
3231fbd9 | 2 | * Copyright (c) 2009 Ericsson |
b0d3496e ASL |
3 | * |
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 | |
8 | * | |
9 | * Contributors: | |
10 | * Francois Chouinard - Initial API and implementation | |
11 | *******************************************************************************/ | |
12 | ||
13 | package org.eclipse.linuxtools.tmf.ui.views; | |
14 | ||
15 | import org.eclipse.linuxtools.tmf.event.TmfEvent; | |
16 | import org.eclipse.linuxtools.tmf.event.TmfTimestamp; | |
b0d3496e | 17 | import org.eclipse.linuxtools.tmf.request.TmfDataRequest; |
b0d3496e | 18 | import org.eclipse.linuxtools.tmf.signal.TmfSignalHandler; |
3231fbd9 | 19 | import org.eclipse.linuxtools.tmf.signal.TmfSignalManager; |
b0d3496e | 20 | import org.eclipse.linuxtools.tmf.signal.TmfTimeSynchSignal; |
62d1696a FC |
21 | import org.eclipse.linuxtools.tmf.trace.TmfExperiment; |
22 | import org.eclipse.linuxtools.tmf.trace.TmfExperimentSelectedSignal; | |
4e3aa37d | 23 | import org.eclipse.linuxtools.tmf.trace.TmfExperimentUpdatedSignal; |
b0d3496e | 24 | import org.eclipse.swt.SWT; |
b0d3496e | 25 | import org.eclipse.swt.events.SelectionEvent; |
3231fbd9 | 26 | import org.eclipse.swt.events.SelectionListener; |
b0d3496e ASL |
27 | import org.eclipse.swt.layout.GridData; |
28 | import org.eclipse.swt.widgets.Composite; | |
29 | import org.eclipse.swt.widgets.Event; | |
30 | import org.eclipse.swt.widgets.Listener; | |
31 | import org.eclipse.swt.widgets.Table; | |
32 | import org.eclipse.swt.widgets.TableColumn; | |
33 | import org.eclipse.swt.widgets.TableItem; | |
34 | ||
35 | /** | |
36 | * <b><u>TmfEventsView</u></b> | |
37 | * <p> | |
38 | * | |
39 | * TODO: Implement me. Please. | |
40 | * TODO: Handle column selection, sort, ... generically (nothing less...) | |
41 | * TODO: Implement hide/display columns | |
42 | */ | |
79a3a76e | 43 | public class TmfEventsView extends TmfView { |
b0d3496e | 44 | |
3231fbd9 | 45 | public static final String ID = "org.eclipse.linuxtools.tmf.ui.viewer.events"; |
b0d3496e | 46 | |
62d1696a FC |
47 | private TmfExperiment fExperiment; |
48 | private String fTitlePrefix; | |
b0d3496e | 49 | |
3231fbd9 | 50 | // ======================================================================== |
b0d3496e | 51 | // Table data |
3231fbd9 | 52 | // ======================================================================== |
b0d3496e ASL |
53 | |
54 | private Table fTable; | |
55 | ||
56 | // Table column names | |
57 | private final String TIMESTAMP_COLUMN = "Timestamp"; | |
58 | private final String SOURCE_COLUMN = "Source"; | |
59 | private final String TYPE_COLUMN = "Type"; | |
60 | private final String REFERENCE_COLUMN = "File"; | |
61 | private final String CONTENT_COLUMN = "Content"; | |
62 | private final String[] columnProperties = new String[] { | |
3231fbd9 | 63 | TIMESTAMP_COLUMN, |
b0d3496e ASL |
64 | SOURCE_COLUMN, |
65 | TYPE_COLUMN, | |
66 | REFERENCE_COLUMN, | |
67 | CONTENT_COLUMN | |
68 | }; | |
69 | ||
70 | // Column data | |
71 | private class ColumnData { | |
72 | public final String header; | |
73 | public final int width; | |
74 | public final int alignment; | |
75 | ||
76 | public ColumnData(String h, int w, int a) { | |
77 | header = h; | |
78 | width = w; | |
79 | alignment = a; | |
80 | } | |
81 | }; | |
82 | ||
83 | private ColumnData[] columnData = new ColumnData[] { | |
84 | new ColumnData(columnProperties[0], 100, SWT.LEFT), | |
85 | new ColumnData(columnProperties[1], 100, SWT.LEFT), | |
86 | new ColumnData(columnProperties[2], 100, SWT.LEFT), | |
87 | new ColumnData(columnProperties[3], 100, SWT.LEFT), | |
88 | new ColumnData(columnProperties[4], 100, SWT.LEFT) | |
89 | }; | |
90 | ||
3231fbd9 | 91 | // ======================================================================== |
b0d3496e | 92 | // Constructor |
3231fbd9 | 93 | // ======================================================================== |
b0d3496e ASL |
94 | |
95 | public TmfEventsView() { | |
3231fbd9 | 96 | super(); |
b0d3496e ASL |
97 | } |
98 | ||
3231fbd9 FC |
99 | /* (non-Javadoc) |
100 | * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite) | |
101 | */ | |
102 | @Override | |
b0d3496e ASL |
103 | public void createPartControl(Composite parent) { |
104 | ||
105 | // Create a virtual table | |
106 | // TODO: change SINGLE to MULTI line selection and adjust the selection listener | |
107 | final int style = SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER | SWT.VIRTUAL; | |
108 | fTable = new Table(parent, style); | |
109 | ||
110 | // Set the table layout | |
111 | GridData layoutData = new GridData(SWT.FILL, SWT.FILL, true, true); | |
3231fbd9 | 112 | layoutData.horizontalSpan= columnData.length; |
b0d3496e ASL |
113 | fTable.setLayoutData(layoutData); |
114 | ||
115 | // Some cosmetic enhancements | |
116 | fTable.setHeaderVisible(true); | |
117 | fTable.setLinesVisible(true); | |
118 | ||
119 | // Set the columns | |
3231fbd9 | 120 | setColumnHeaders(fTable); |
b0d3496e ASL |
121 | |
122 | // Handle the table item requests | |
3231fbd9 FC |
123 | fTable.addSelectionListener(new SelectionListener() { |
124 | ||
125 | public void widgetDefaultSelected(SelectionEvent e) { | |
126 | // TODO Auto-generated method stub | |
127 | } | |
b0d3496e | 128 | |
b0d3496e | 129 | public void widgetSelected(SelectionEvent e) { |
3231fbd9 FC |
130 | // Get the timestamp string |
131 | String time = fTable.getSelection()[0].getText(); | |
132 | ||
133 | // Compose a timestamp | |
134 | int pos = time.indexOf('.'); | |
135 | String integer = time.substring(0, pos); | |
136 | String fraction = time.substring(pos + 1); | |
137 | ||
138 | byte exponent = (byte) -fraction.length(); | |
139 | String value = integer + fraction; | |
140 | TmfTimestamp ts = new TmfTimestamp(new Long(value), exponent); | |
141 | ||
142 | // Generate the synchronization event | |
143 | TmfSignalManager.dispatchSignal(new TmfTimeSynchSignal(fTable, ts)); | |
b0d3496e ASL |
144 | } |
145 | }); | |
146 | ||
147 | // Handle the table item requests | |
148 | fTable.addListener(SWT.SetData, new Listener() { | |
b0d3496e | 149 | public void handleEvent(Event event) { |
3231fbd9 FC |
150 | TableItem item = (TableItem) event.item; |
151 | int index = fTable.indexOf(item); | |
152 | final TmfEvent[] evt = new TmfEvent[1]; | |
153 | TmfDataRequest<TmfEvent> request = new TmfDataRequest<TmfEvent>(index, 0, 1) { | |
b0d3496e ASL |
154 | @Override |
155 | public void handleData() { | |
3231fbd9 FC |
156 | TmfEvent[] result = getData(); |
157 | evt[0] = (result.length > 0) ? result[0] : null; | |
b0d3496e ASL |
158 | } |
159 | }; | |
62d1696a | 160 | fExperiment.processRequest(request, true); |
3231fbd9 | 161 | item.setText(extractItemFields(evt[0])); |
b0d3496e ASL |
162 | } |
163 | }); | |
164 | ||
165 | fTable.setItemCount(0); | |
62d1696a | 166 | fTitlePrefix = getTitle(); |
b0d3496e ASL |
167 | } |
168 | ||
169 | /** | |
170 | * @param table | |
171 | * | |
172 | * FIXME: Add support for column selection | |
173 | */ | |
3231fbd9 | 174 | protected void setColumnHeaders(Table table) { |
b0d3496e ASL |
175 | for (int i = 0; i < columnData.length; i++) { |
176 | TableColumn column = new TableColumn(table, columnData[i].alignment, i); | |
177 | column.setText(columnData[i].header); | |
178 | column.setWidth(columnData[i].width); | |
179 | } | |
180 | } | |
181 | ||
182 | /** | |
183 | * @param event | |
184 | * @return | |
185 | * | |
186 | * FIXME: Add support for column selection | |
187 | */ | |
188 | protected String[] extractItemFields(TmfEvent event) { | |
189 | String[] fields = new String[0]; | |
190 | if (event != null) { | |
191 | fields = new String[] { | |
192 | new Long(event.getTimestamp().getValue()).toString(), | |
193 | event.getSource().getSourceId().toString(), | |
194 | event.getType().getTypeId().toString(), | |
3231fbd9 FC |
195 | event.getReference().getValue().toString(), |
196 | event.getContent().getContent() | |
b0d3496e ASL |
197 | }; |
198 | } | |
199 | return fields; | |
200 | } | |
201 | ||
202 | /* (non-Javadoc) | |
203 | * @see org.eclipse.ui.part.WorkbenchPart#setFocus() | |
204 | */ | |
205 | @Override | |
206 | public void setFocus() { | |
207 | } | |
208 | ||
3231fbd9 | 209 | // ======================================================================== |
b0d3496e | 210 | // Signal handlers |
3231fbd9 | 211 | // ======================================================================== |
b0d3496e | 212 | |
b0d3496e | 213 | @TmfSignalHandler |
62d1696a | 214 | public void experimentSelected(TmfExperimentSelectedSignal signal) { |
b0d3496e | 215 | // Update the trace reference |
62d1696a FC |
216 | fExperiment = signal.getExperiment(); |
217 | setPartName(fTitlePrefix + " - " + fExperiment.getExperimentId()); | |
b0d3496e ASL |
218 | |
219 | // Perform the updates on the UI thread | |
220 | fTable.getDisplay().asyncExec(new Runnable() { | |
221 | public void run() { | |
b0d3496e | 222 | fTable.clearAll(); |
62d1696a | 223 | fTable.setItemCount(fExperiment.getNbEvents()); |
b0d3496e ASL |
224 | } |
225 | }); | |
226 | } | |
227 | ||
228 | @TmfSignalHandler | |
4e3aa37d | 229 | public void experimentUpdated(TmfExperimentUpdatedSignal signal) { |
b0d3496e ASL |
230 | // Perform the refresh on the UI thread |
231 | fTable.getDisplay().asyncExec(new Runnable() { | |
232 | public void run() { | |
4e3aa37d | 233 | if (!fTable.isDisposed() && fExperiment != null) { |
62d1696a | 234 | fTable.setItemCount(fExperiment.getNbEvents()); |
b0d3496e ASL |
235 | } |
236 | } | |
237 | }); | |
238 | } | |
239 | ||
3231fbd9 FC |
240 | @TmfSignalHandler |
241 | public void currentTimeUpdated(TmfTimeSynchSignal signal) { | |
4e3aa37d FC |
242 | if (signal.getSource() != fTable && fExperiment != null) { |
243 | final int index = (int) fExperiment.getIndex(signal.getCurrentTime()); | |
3231fbd9 FC |
244 | // Perform the updates on the UI thread |
245 | fTable.getDisplay().asyncExec(new Runnable() { | |
246 | public void run() { | |
247 | fTable.setSelection(index); | |
248 | } | |
249 | }); | |
250 | } | |
9aae0442 ASL |
251 | } |
252 | ||
b0d3496e | 253 | } |