Commit | Line | Data |
---|---|---|
6e512b93 | 1 | /******************************************************************************* |
8035003b | 2 | * Copyright (c) 2009 Ericsson |
6e512b93 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.lttng.ui.views.timeframe; | |
14 | ||
e31e01e8 | 15 | import org.eclipse.linuxtools.lttng.event.LttngEvent; |
6e512b93 ASL |
16 | import org.eclipse.linuxtools.tmf.event.TmfTimeRange; |
17 | import org.eclipse.linuxtools.tmf.event.TmfTimestamp; | |
e31e01e8 FC |
18 | import org.eclipse.linuxtools.tmf.experiment.TmfExperiment; |
19 | import org.eclipse.linuxtools.tmf.experiment.TmfExperimentSelectedSignal; | |
20 | import org.eclipse.linuxtools.tmf.experiment.TmfExperimentUpdatedSignal; | |
6e512b93 ASL |
21 | import org.eclipse.linuxtools.tmf.signal.TmfSignalHandler; |
22 | import org.eclipse.linuxtools.tmf.signal.TmfTimeSynchSignal; | |
6d848cce | 23 | import org.eclipse.linuxtools.tmf.ui.views.TmfView; |
6e512b93 ASL |
24 | import org.eclipse.swt.SWT; |
25 | import org.eclipse.swt.layout.GridData; | |
26 | import org.eclipse.swt.layout.GridLayout; | |
27 | import org.eclipse.swt.widgets.Composite; | |
62d1696a FC |
28 | import org.eclipse.swt.widgets.Event; |
29 | import org.eclipse.swt.widgets.Listener; | |
6e512b93 ASL |
30 | import org.eclipse.swt.widgets.Slider; |
31 | ||
32 | /** | |
33 | * <b><u>TimeFrameView</u></b> | |
34 | * <p> | |
35 | * The TimeFrameView provides a set of spinners to monitor and set the start | |
36 | * time, end time, the current time interval and current time of the trace | |
37 | * set at the nanosecond level. | |
38 | * <p> | |
39 | * It ensures that the following relations are always true: | |
40 | * <p> | |
41 | * <li>[ startTime >= start time of the trace ] | |
42 | * <li>[ endTime <= end time of the trace ] | |
43 | * <li>[ startTime <= currentTime <= endTime ] | |
44 | * <li>[ interval == (endTime - startTime) ] | |
45 | * </li> | |
46 | * <p> | |
47 | * It provides a slider to rapidly set the current time within the time range | |
48 | * (i.e. between startTime and endTime). | |
49 | * <p> | |
50 | * Finally, it allows modification of the time range and the current time. This | |
51 | * triggers notifications to the other LTTng views. | |
52 | * <p> | |
53 | * FIXME: The slider is very jumpy due to the large number of async updates | |
54 | * FIXME: Revisit the control flow between View, Spinners and Slider | |
55 | */ | |
6d848cce | 56 | public class TimeFrameView extends TmfView { |
6e512b93 | 57 | |
62d1696a | 58 | public static final String ID = "org.eclipse.linuxtools.lttng.ui.views.timeframe"; |
6e512b93 ASL |
59 | |
60 | // ======================================================================== | |
61 | // TimeFrameView | |
62 | // ======================================================================== | |
63 | ||
64 | // The event log timestamp characteristics | |
8d2e2848 FC |
65 | private TmfTimestamp fTraceStartTime = new TmfTimestamp(); |
66 | private TmfTimestamp fTraceEndTime = new TmfTimestamp(); | |
6e512b93 | 67 | |
8d2e2848 | 68 | private TmfTimestamp fCurrentTime = new TmfTimestamp(); |
6e512b93 ASL |
69 | |
70 | private TmfTimeRange fTraceTimeRange = new TmfTimeRange(fTraceStartTime, fTraceEndTime); | |
71 | private TmfTimeRange fTraceSpan = new TmfTimeRange(fTraceStartTime, fTraceEndTime); | |
72 | private byte fScale = 0; | |
73 | ||
62d1696a FC |
74 | // Labels |
75 | private static final String START_TIME_LABEL = "Start Time"; | |
76 | private static final String END_TIME_LABEL = "End Time"; | |
77 | private static final String TIME_RANGE_LABEL = "Interval"; | |
78 | private static final String CURRENT_TIME_LABEL = "Current Time"; | |
79 | ||
6e512b93 ASL |
80 | private static final int SLIDER_RANGE = 10000; |
81 | ||
82 | private SpinnerGroup fStartGroup; | |
83 | private SpinnerGroup fEndGroup; | |
84 | private SpinnerGroup fRangeGroup; | |
85 | private SpinnerGroup fCurrentGroup; | |
86 | ||
87 | // The slider | |
88 | private Slider fSlider; | |
89 | ||
62d1696a | 90 | // The current experiment |
e31e01e8 | 91 | TmfExperiment<LttngEvent> fExperiment = null; |
6e512b93 ASL |
92 | |
93 | /** | |
94 | * Constructor | |
95 | */ | |
96 | public TimeFrameView() { | |
fc6ccf6f | 97 | super("TimeFrameView"); |
6e512b93 ASL |
98 | } |
99 | ||
100 | /* (non-Javadoc) | |
101 | * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite) | |
102 | */ | |
6d848cce | 103 | @Override |
6e512b93 ASL |
104 | public void createPartControl(Composite parent) { |
105 | ||
106 | // Set the view layout | |
107 | GridLayout layout = new GridLayout(4, true); | |
108 | parent.setLayout(layout); | |
109 | ||
62d1696a FC |
110 | fStartGroup = new SpinnerGroup(this, parent, START_TIME_LABEL, fTraceTimeRange, fTraceStartTime); |
111 | fEndGroup = new SpinnerGroup(this, parent, END_TIME_LABEL, fTraceTimeRange, fTraceEndTime); | |
112 | fRangeGroup = new SpinnerGroup(this, parent, TIME_RANGE_LABEL, fTraceTimeRange, fTraceEndTime); | |
113 | fCurrentGroup = new SpinnerGroup(this, parent, CURRENT_TIME_LABEL, fTraceTimeRange, fTraceStartTime); | |
6e512b93 ASL |
114 | |
115 | // Create the slider | |
116 | createSlider(parent); | |
117 | } | |
118 | ||
119 | /* (non-Javadoc) | |
120 | * @see org.eclipse.ui.part.WorkbenchPart#setFocus() | |
121 | */ | |
6d848cce | 122 | @Override |
6e512b93 ASL |
123 | public void setFocus() { |
124 | // TODO Auto-generated method stub | |
125 | } | |
126 | ||
127 | // ======================================================================== | |
128 | // Operators | |
129 | // ======================================================================== | |
130 | ||
131 | /** | |
132 | * One of the spinners has been updated. Synchronize the other widgets. | |
133 | */ | |
134 | public void synchTimeFrameWidgets(SpinnerGroup trigger) { | |
6e512b93 ASL |
135 | |
136 | // Collect the data | |
137 | TmfTimestamp startTime = fStartGroup.getCurrentTime(); | |
138 | TmfTimestamp endTime = fEndGroup.getCurrentTime(); | |
139 | TmfTimestamp timeRange = fRangeGroup.getCurrentTime(); | |
140 | TmfTimestamp currentTime = fCurrentGroup.getCurrentTime(); | |
141 | ||
142 | // If startTime was set beyond endTime, adjust endTime and interval | |
143 | if (trigger == fStartGroup) { | |
144 | if (startTime.compareTo(endTime, false) > 0) { | |
145 | endTime = startTime; | |
6e512b93 ASL |
146 | } |
147 | } | |
148 | ||
149 | // If endTime was set beyond startTime, adjust startTime and interval | |
150 | if (trigger == fEndGroup) { | |
151 | if (endTime.compareTo(startTime, false) < 0) { | |
152 | startTime = endTime; | |
6e512b93 ASL |
153 | } |
154 | } | |
155 | ||
156 | // If timeRange was set, adjust endTime | |
157 | if (trigger == fRangeGroup) { | |
158 | long start = startTime.getValue(); | |
159 | long span = timeRange.getValue(); | |
160 | TmfTimestamp ts = new TmfTimestamp(start + span, startTime.getScale(), 0); | |
161 | if (ts.compareTo(fTraceEndTime, false) > 0) { | |
162 | ts = fTraceEndTime.synchronize(fTraceEndTime.getValue(), startTime.getScale()); | |
163 | } | |
164 | endTime = ts; | |
6e512b93 ASL |
165 | } |
166 | ||
167 | // Compute the new time range | |
168 | TmfTimeRange subrange = new TmfTimeRange(startTime, endTime); | |
8035003b | 169 | TmfTimestamp interval = new TmfTimestamp(startTime.getAdjustment(endTime), startTime.getScale(), 0); |
6e512b93 ASL |
170 | |
171 | // Update the spinner groups | |
172 | fStartGroup.setContent(fTraceTimeRange, startTime); | |
173 | fEndGroup.setContent(fTraceTimeRange, endTime); | |
174 | fRangeGroup.setContent(fTraceSpan, interval); | |
175 | fCurrentGroup.setContent(subrange, currentTime); | |
176 | ||
177 | updateSlider(subrange, currentTime); | |
6e512b93 | 178 | |
8035003b ASL |
179 | // Notify other views |
180 | if (!fCurrentTime.equals(currentTime)) { | |
181 | fCurrentTime = currentTime; | |
e31e01e8 | 182 | broadcast(new TmfTimeSynchSignal(this, currentTime)); |
6e512b93 ASL |
183 | } |
184 | } | |
185 | ||
186 | // ======================================================================== | |
187 | // Slider Handling | |
188 | // ======================================================================== | |
189 | ||
190 | /** | |
191 | * @param parent | |
192 | */ | |
193 | private void createSlider(Composite parent) { | |
194 | fSlider = new Slider(parent, SWT.SMOOTH | SWT.FILL); | |
62d1696a | 195 | fSlider.setMinimum(0); |
6e512b93 | 196 | fSlider.setMaximum(SLIDER_RANGE + fSlider.getThumb()); |
62d1696a FC |
197 | fSlider.setIncrement(SLIDER_RANGE / 100); |
198 | fSlider.setPageIncrement(SLIDER_RANGE / 10); | |
199 | fSlider.setSelection(0); | |
6e512b93 ASL |
200 | |
201 | GridData gridData = new GridData(SWT.LEFT, SWT.TOP, true, false); | |
202 | gridData.horizontalAlignment = SWT.FILL; | |
203 | gridData.horizontalSpan = 4; | |
204 | fSlider.setLayoutData(gridData); | |
205 | ||
62d1696a FC |
206 | fSlider.addListener(SWT.Selection, new Listener() { |
207 | public void handleEvent(Event event) { | |
208 | int ratio = fSlider.getSelection(); | |
209 | TmfTimestamp span = fCurrentGroup.getSpan(); | |
210 | long value = span.getValue() * ratio / SLIDER_RANGE; | |
211 | TmfTimestamp start = fCurrentGroup.getStartTime(); | |
212 | TmfTimestamp current = new TmfTimestamp(start.getValue() + value, start.getScale(), 0); | |
213 | fCurrentGroup.setValue(current); | |
214 | } | |
215 | }); | |
bf5aa8e4 | 216 | |
6e512b93 ASL |
217 | } |
218 | ||
219 | /** | |
220 | * @param range | |
8d2e2848 | 221 | * @param timestamp |
6e512b93 | 222 | */ |
8d2e2848 | 223 | private void updateSlider(TmfTimeRange range, TmfTimestamp timestamp) { |
6e512b93 ASL |
224 | |
225 | // Determine the new relative position | |
8035003b | 226 | long total = range.getStartTime().getAdjustment(range.getEndTime()); |
8d2e2848 | 227 | long relative = range.getStartTime().getAdjustment(timestamp); |
6e512b93 ASL |
228 | |
229 | // Set the slider value | |
230 | final long position = (total > 0) ? (relative * SLIDER_RANGE / total) : 0; | |
231 | ||
232 | // Update the slider on the UI thread | |
8d2e2848 FC |
233 | long current = fSlider.getSelection(); |
234 | if (position != current) { | |
235 | fSlider.getDisplay().asyncExec(new Runnable() { | |
236 | public void run() { | |
237 | fSlider.setSelection((int) position); | |
238 | } | |
239 | }); | |
240 | } | |
8b29a712 FC |
241 | } |
242 | ||
8d2e2848 FC |
243 | /* (non-Javadoc) |
244 | * @see java.lang.Object#toString() | |
245 | */ | |
246 | @Override | |
247 | public String toString() { | |
248 | return "[TimeFrameView]"; | |
249 | } | |
250 | ||
6e512b93 ASL |
251 | // ======================================================================== |
252 | // TMF Signal Handling | |
253 | // ======================================================================== | |
254 | ||
e31e01e8 FC |
255 | @SuppressWarnings("unchecked") |
256 | /** | |
6e512b93 ASL |
257 | * @param signal |
258 | */ | |
6e512b93 | 259 | @TmfSignalHandler |
951d134a | 260 | public void experimentSelected(TmfExperimentSelectedSignal<LttngEvent> signal) { |
6e512b93 ASL |
261 | |
262 | // Update the trace reference | |
e31e01e8 | 263 | fExperiment = (TmfExperiment<LttngEvent>) signal.getExperiment(); |
6e512b93 ASL |
264 | |
265 | // Update the time frame | |
62d1696a | 266 | fTraceTimeRange = fExperiment.getTimeRange(); |
6e512b93 ASL |
267 | fTraceStartTime = fTraceTimeRange.getStartTime(); |
268 | fTraceEndTime = fTraceTimeRange.getEndTime(); | |
269 | fScale = fTraceStartTime.getScale(); | |
270 | ||
271 | // Update the widgets | |
272 | fStartGroup.setContent(fTraceTimeRange, fTraceStartTime); | |
273 | fEndGroup.setContent(fTraceTimeRange, fTraceEndTime); | |
274 | fCurrentGroup.setContent(fTraceTimeRange, fTraceStartTime); | |
275 | ||
276 | fCurrentTime = fTraceStartTime; | |
277 | ||
8035003b | 278 | TmfTimestamp delta = new TmfTimestamp(fTraceStartTime.getAdjustment(fTraceEndTime), fScale, 0); |
6e512b93 | 279 | fTraceSpan = new TmfTimeRange(new TmfTimestamp(0, fScale, 0), delta); |
8035003b | 280 | fRangeGroup.setContent(fTraceSpan, delta); |
6e512b93 ASL |
281 | } |
282 | ||
283 | /** | |
284 | * @param signal | |
285 | */ | |
286 | @TmfSignalHandler | |
6d848cce | 287 | public void experimentUpdated(TmfExperimentUpdatedSignal signal) { |
6e512b93 ASL |
288 | |
289 | // Update the time frame | |
290 | fTraceTimeRange = signal.getTrace().getTimeRange(); | |
291 | fTraceStartTime = fTraceTimeRange.getStartTime(); | |
292 | fTraceEndTime = fTraceTimeRange.getEndTime(); | |
293 | fScale = fTraceStartTime.getScale(); | |
294 | ||
295 | // Update the widgets | |
296 | fStartGroup.setContent(fTraceTimeRange, fStartGroup.getCurrentTime()); | |
62d1696a | 297 | fEndGroup.setContent(fTraceTimeRange, fTraceEndTime); |
6e512b93 ASL |
298 | fCurrentGroup.setContent(fTraceTimeRange, fCurrentGroup.getCurrentTime()); |
299 | ||
8035003b | 300 | TmfTimestamp delta = new TmfTimestamp(fTraceStartTime.getAdjustment(fTraceEndTime), fScale, 0); |
6e512b93 ASL |
301 | fTraceSpan = new TmfTimeRange(new TmfTimestamp(0, fScale, 0), delta); |
302 | fRangeGroup.setContent(fTraceSpan, delta); | |
303 | } | |
304 | ||
6e512b93 ASL |
305 | /** |
306 | * @param signal | |
307 | */ | |
308 | @TmfSignalHandler | |
309 | public void currentTimeUpdated(TmfTimeSynchSignal signal) { | |
310 | if (signal.getSource() != this) { | |
8d2e2848 | 311 | fCurrentTime = signal.getCurrentTime().synchronize(0, fStartGroup.getCurrentTime().getScale()); |
6e512b93 ASL |
312 | if (fStartGroup.getCurrentTime().compareTo(fCurrentTime, false) > 0) { |
313 | fStartGroup.setContent(new TmfTimeRange(fCurrentTime, fEndGroup.getCurrentTime()), fCurrentTime); | |
314 | } | |
315 | if (fEndGroup.getCurrentTime().compareTo(fCurrentTime, false) < 0) { | |
316 | fEndGroup.setContent(new TmfTimeRange(fStartGroup.getCurrentTime(), fCurrentTime), fCurrentTime); | |
317 | } | |
318 | fCurrentGroup.setContent(null, fCurrentTime); | |
319 | updateSlider(fCurrentGroup.getTimeRange(), fCurrentTime); | |
6e512b93 ASL |
320 | } |
321 | } | |
322 | ||
bf5aa8e4 | 323 | } |