Commit | Line | Data |
---|---|---|
4999a196 GB |
1 | /******************************************************************************* |
2 | * Copyright (c) 2012, 2013 Ericsson, École Polytechnique de Montréal | |
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 | * Patrick Tasse - Initial API and implementation | |
11 | * Bernd Hufmann - Updated signal handling | |
12 | * Geneviève Bastien - Move code to provide base classes for time graph view | |
c1cd9635 | 13 | * Marc-Andre Laperle - Add time zone preference |
4999a196 GB |
14 | *******************************************************************************/ |
15 | ||
16 | package org.eclipse.linuxtools.tmf.ui.views.timegraph; | |
17 | ||
18 | import java.util.ArrayList; | |
19 | import java.util.Arrays; | |
20 | import java.util.Collections; | |
21 | import java.util.Comparator; | |
22 | import java.util.HashMap; | |
23 | import java.util.List; | |
24 | import java.util.Map; | |
25 | ||
26 | import org.eclipse.core.runtime.IProgressMonitor; | |
27 | import org.eclipse.core.runtime.NullProgressMonitor; | |
28 | import org.eclipse.jface.action.Action; | |
0fcf3b09 | 29 | import org.eclipse.jface.action.IStatusLineManager; |
4999a196 GB |
30 | import org.eclipse.jface.action.IToolBarManager; |
31 | import org.eclipse.jface.action.Separator; | |
32 | import org.eclipse.jface.viewers.ILabelProviderListener; | |
33 | import org.eclipse.jface.viewers.ITableLabelProvider; | |
34 | import org.eclipse.jface.viewers.ITreeContentProvider; | |
35 | import org.eclipse.jface.viewers.Viewer; | |
36 | import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfTimestamp; | |
37 | import org.eclipse.linuxtools.tmf.core.signal.TmfRangeSynchSignal; | |
38 | import org.eclipse.linuxtools.tmf.core.signal.TmfSignalHandler; | |
39 | import org.eclipse.linuxtools.tmf.core.signal.TmfTimeSynchSignal; | |
c1cd9635 | 40 | import org.eclipse.linuxtools.tmf.core.signal.TmfTimestampFormatUpdateSignal; |
4999a196 GB |
41 | import org.eclipse.linuxtools.tmf.core.signal.TmfTraceClosedSignal; |
42 | import org.eclipse.linuxtools.tmf.core.signal.TmfTraceOpenedSignal; | |
43 | import org.eclipse.linuxtools.tmf.core.signal.TmfTraceSelectedSignal; | |
44 | import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp; | |
45 | import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimeRange; | |
4999a196 GB |
46 | import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace; |
47 | import org.eclipse.linuxtools.tmf.ui.views.TmfView; | |
48 | import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphRangeListener; | |
49 | import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphSelectionListener; | |
50 | import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphTimeListener; | |
51 | import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TimeGraphCombo; | |
52 | import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TimeGraphPresentationProvider; | |
53 | import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TimeGraphRangeUpdateEvent; | |
54 | import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TimeGraphSelectionEvent; | |
55 | import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TimeGraphTimeEvent; | |
56 | import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent; | |
57 | import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeGraphEntry; | |
58 | import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.TimeGraphEntry; | |
59 | import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.Utils.TimeFormat; | |
60 | import org.eclipse.swt.SWT; | |
61 | import org.eclipse.swt.graphics.Image; | |
62 | import org.eclipse.swt.widgets.Composite; | |
63 | import org.eclipse.swt.widgets.Display; | |
64 | import org.eclipse.swt.widgets.TreeColumn; | |
65 | import org.eclipse.ui.IActionBars; | |
66 | ||
67 | /** | |
68 | * An abstract view all time graph views can inherit | |
69 | * | |
70 | * This view contains a time graph combo, divided between a treeview on the | |
71 | * left, showing entries and a canvas on the right to draw something for these | |
72 | * entries. | |
73 | * | |
74 | * @since 2.1 | |
75 | */ | |
76 | public abstract class AbstractTimeGraphView extends TmfView { | |
77 | ||
78 | private final String[] fColumns; | |
79 | private final String[] fFilterColumns; | |
80 | ||
81 | /** | |
82 | * Redraw state enum | |
83 | */ | |
84 | private enum State { | |
85 | IDLE, BUSY, PENDING | |
86 | } | |
87 | ||
88 | // ------------------------------------------------------------------------ | |
89 | // Fields | |
90 | // ------------------------------------------------------------------------ | |
91 | ||
92 | /** The timegraph combo */ | |
93 | private TimeGraphCombo fTimeGraphCombo; | |
94 | ||
95 | /** The selected trace */ | |
96 | private ITmfTrace fTrace; | |
97 | ||
98 | /** The timegraph entry list */ | |
99 | private List<TimeGraphEntry> fEntryList; | |
100 | ||
101 | /** The trace to entry list hash map */ | |
102 | private final Map<ITmfTrace, List<TimeGraphEntry>> fEntryListMap = new HashMap<ITmfTrace, List<TimeGraphEntry>>(); | |
103 | ||
104 | /* The trace to build thread hash map */ | |
105 | private final Map<ITmfTrace, BuildThread> fBuildThreadMap = new HashMap<ITmfTrace, BuildThread>(); | |
106 | ||
107 | /** The start time */ | |
108 | private long fStartTime; | |
109 | ||
110 | /** The end time */ | |
111 | private long fEndTime; | |
112 | ||
113 | /** The display width */ | |
114 | private final int fDisplayWidth; | |
115 | ||
116 | /** The zoom thread */ | |
117 | private ZoomThread fZoomThread; | |
118 | ||
119 | /** The next resource action */ | |
120 | private Action fNextResourceAction; | |
121 | ||
122 | /** The previous resource action */ | |
123 | private Action fPreviousResourceAction; | |
124 | ||
125 | /** The relative weight of the sash */ | |
126 | private int[] fWeight = { 1, 1 }; | |
127 | ||
128 | /** A comparator class */ | |
129 | private Comparator<ITimeGraphEntry> fEntryComparator = null; | |
130 | ||
131 | /** The redraw state used to prevent unnecessary queuing of display runnables */ | |
132 | private State fRedrawState = State.IDLE; | |
133 | ||
134 | /** The redraw synchronization object */ | |
135 | private final Object fSyncObj = new Object(); | |
136 | ||
137 | /** The presentation provider for this view */ | |
138 | private final TimeGraphPresentationProvider fPresentation; | |
139 | ||
140 | private TreeLabelProvider fLabelProvider = new TreeLabelProvider(); | |
141 | ||
142 | // ------------------------------------------------------------------------ | |
143 | // Getters and setters | |
144 | // ------------------------------------------------------------------------ | |
145 | ||
146 | /** | |
147 | * Getter for the time graph combo | |
148 | * | |
149 | * @return The Time graph combo | |
150 | */ | |
151 | protected TimeGraphCombo getTimeGraphCombo() { | |
152 | return fTimeGraphCombo; | |
153 | } | |
154 | ||
155 | /** | |
156 | * Sets the tree label provider | |
157 | * | |
158 | * @param tlp | |
159 | * The tree label provider | |
160 | */ | |
161 | protected void setTreeLabelProvider(final TreeLabelProvider tlp) { | |
162 | fLabelProvider = tlp; | |
163 | } | |
164 | ||
165 | /** | |
166 | * Sets the relative weight of each part of the time graph combo | |
167 | * | |
168 | * @param weights | |
169 | * The array of relative weights of each part of the combo | |
170 | */ | |
171 | protected void setWeight(final int[] weights) { | |
172 | fWeight = weights; | |
173 | } | |
174 | ||
175 | /** | |
176 | * Gets the display width | |
177 | * | |
178 | * @return the display width | |
179 | */ | |
180 | protected int getDisplayWidth() { | |
181 | return fDisplayWidth; | |
182 | } | |
183 | ||
184 | /** | |
185 | * Gets the comparator for the entries | |
186 | * | |
187 | * @return The entry comparator | |
188 | */ | |
189 | protected Comparator<ITimeGraphEntry> getEntryComparator() { | |
190 | return fEntryComparator; | |
191 | } | |
192 | ||
193 | /** | |
194 | * Sets the comparator class for the entries * Gets the display width | |
195 | * | |
196 | * @param comparator | |
197 | * A comparator object | |
198 | */ | |
199 | protected void setEntryComparator(final Comparator<ITimeGraphEntry> comparator) { | |
200 | fEntryComparator = comparator; | |
201 | } | |
202 | ||
203 | /** | |
204 | * Gets the trace displayed in the view | |
205 | * | |
206 | * @return The trace | |
207 | */ | |
208 | protected ITmfTrace getTrace() { | |
209 | return fTrace; | |
210 | } | |
211 | ||
212 | /** | |
213 | * Sets the trace to display | |
214 | * | |
215 | * @param trace | |
216 | * The trace | |
217 | */ | |
218 | protected void setTrace(final ITmfTrace trace) { | |
219 | fTrace = trace; | |
220 | } | |
221 | ||
222 | /** | |
223 | * Gets the start time | |
224 | * | |
225 | * @return The start time | |
226 | */ | |
227 | protected long getStartTime() { | |
228 | return fStartTime; | |
229 | } | |
230 | ||
231 | /** | |
232 | * Sets the start time | |
233 | * | |
234 | * @param time | |
235 | * The start time | |
236 | */ | |
237 | protected void setStartTime(long time) { | |
238 | fStartTime = time; | |
239 | } | |
240 | ||
241 | /** | |
242 | * Gets the end time | |
243 | * | |
244 | * @return The end time | |
245 | */ | |
246 | protected long getEndTime() { | |
247 | return fEndTime; | |
248 | } | |
249 | ||
250 | /** | |
251 | * Sets the end time | |
252 | * | |
253 | * @param time | |
254 | * The end time | |
255 | */ | |
256 | protected void setEndTime(long time) { | |
257 | fEndTime = time; | |
258 | } | |
259 | ||
260 | /** | |
261 | * Gets the entry list map | |
262 | * | |
263 | * @return the entry list map | |
264 | */ | |
265 | protected Map<ITmfTrace, List<TimeGraphEntry>> getEntryListMap() { | |
266 | return Collections.unmodifiableMap(fEntryListMap); | |
267 | } | |
268 | ||
269 | /** | |
270 | * Adds an entry to the entry list | |
271 | * | |
272 | * @param trace | |
273 | * the trace to add | |
274 | * @param list | |
275 | * The list of time graph entries | |
276 | */ | |
277 | protected void putEntryList(ITmfTrace trace, List<TimeGraphEntry> list) { | |
278 | synchronized(fEntryListMap) { | |
279 | fEntryListMap.put(trace, list); | |
280 | } | |
281 | } | |
282 | ||
283 | /** | |
284 | * Text for the "next" button | |
285 | * | |
286 | * @return The "next" button text | |
287 | */ | |
288 | protected String getNextText() { | |
289 | return Messages.AbstractTimeGraphtView_NextText; | |
290 | } | |
291 | ||
292 | /** | |
293 | * Tooltip for the "next" button | |
294 | * | |
295 | * @return Tooltip for the "next" button | |
296 | */ | |
297 | protected String getNextTooltip() { | |
298 | return Messages.AbstractTimeGraphView_NextTooltip; | |
299 | } | |
300 | ||
301 | /** | |
302 | * Text for the "Previous" button | |
303 | * | |
304 | * @return The "Previous" button text | |
305 | */ | |
306 | protected String getPrevText() { | |
307 | return Messages.AbstractTimeGraphView_PreviousText; | |
308 | } | |
309 | ||
310 | /** | |
311 | * Tooltip for the "previous" button | |
312 | * | |
313 | * @return Tooltip for the "previous" button | |
314 | */ | |
315 | protected String getPrevTooltip() { | |
316 | return Messages.AbstractTimeGraphView_PreviousTooltip; | |
317 | } | |
318 | ||
319 | // ------------------------------------------------------------------------ | |
320 | // Classes | |
321 | // ------------------------------------------------------------------------ | |
322 | ||
323 | private class TreeContentProvider implements ITreeContentProvider { | |
324 | ||
325 | @Override | |
326 | public void dispose() { | |
327 | } | |
328 | ||
329 | @Override | |
330 | public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { | |
331 | } | |
332 | ||
333 | @Override | |
334 | public Object[] getElements(Object inputElement) { | |
335 | return (ITimeGraphEntry[]) inputElement; | |
336 | } | |
337 | ||
338 | @Override | |
339 | public Object[] getChildren(Object parentElement) { | |
340 | ITimeGraphEntry entry = (ITimeGraphEntry) parentElement; | |
341 | List<? extends ITimeGraphEntry> children = entry.getChildren(); | |
342 | return children.toArray(new ITimeGraphEntry[children.size()]); | |
343 | } | |
344 | ||
345 | @Override | |
346 | public Object getParent(Object element) { | |
347 | ITimeGraphEntry entry = (ITimeGraphEntry) element; | |
348 | return entry.getParent(); | |
349 | } | |
350 | ||
351 | @Override | |
352 | public boolean hasChildren(Object element) { | |
353 | ITimeGraphEntry entry = (ITimeGraphEntry) element; | |
354 | return entry.hasChildren(); | |
355 | } | |
356 | ||
357 | } | |
358 | ||
359 | /** | |
360 | * Base class to provide the labels for the left tree view entry. Views | |
361 | * extending this class typically need to override the getColumnText method | |
362 | * if they have more than one column to display | |
363 | */ | |
364 | protected static class TreeLabelProvider implements ITableLabelProvider { | |
365 | ||
366 | @Override | |
367 | public void addListener(ILabelProviderListener listener) { | |
368 | } | |
369 | ||
370 | @Override | |
371 | public void dispose() { | |
372 | } | |
373 | ||
374 | @Override | |
375 | public boolean isLabelProperty(Object element, String property) { | |
376 | return false; | |
377 | } | |
378 | ||
379 | @Override | |
380 | public void removeListener(ILabelProviderListener listener) { | |
381 | } | |
382 | ||
383 | @Override | |
384 | public Image getColumnImage(Object element, int columnIndex) { | |
385 | return null; | |
386 | } | |
387 | ||
388 | @Override | |
389 | public String getColumnText(Object element, int columnIndex) { | |
390 | TimeGraphEntry entry = (TimeGraphEntry) element; | |
391 | if (columnIndex == 0) { | |
392 | return entry.getName(); | |
393 | } | |
394 | return ""; //$NON-NLS-1$ | |
395 | } | |
396 | ||
397 | } | |
398 | ||
399 | private class BuildThread extends Thread { | |
400 | private final ITmfTrace fBuildTrace; | |
401 | private final IProgressMonitor fMonitor; | |
402 | ||
403 | public BuildThread(final ITmfTrace trace, final String name) { | |
404 | super(name + " build"); //$NON-NLS-1$ | |
405 | fBuildTrace = trace; | |
406 | fMonitor = new NullProgressMonitor(); | |
407 | } | |
408 | ||
409 | @Override | |
410 | public void run() { | |
411 | buildEventList(fBuildTrace, fMonitor); | |
412 | synchronized (fBuildThreadMap) { | |
413 | fBuildThreadMap.remove(this); | |
414 | } | |
415 | } | |
416 | ||
417 | public void cancel() { | |
418 | fMonitor.setCanceled(true); | |
419 | } | |
420 | } | |
421 | ||
422 | private class ZoomThread extends Thread { | |
423 | private final List<TimeGraphEntry> fZoomEntryList; | |
424 | private final long fZoomStartTime; | |
425 | private final long fZoomEndTime; | |
426 | private final long fResolution; | |
427 | private final IProgressMonitor fMonitor; | |
428 | ||
429 | public ZoomThread(List<TimeGraphEntry> entryList, long startTime, long endTime, String name) { | |
430 | super(name + " zoom"); //$NON-NLS-1$ | |
431 | fZoomEntryList = entryList; | |
432 | fZoomStartTime = startTime; | |
433 | fZoomEndTime = endTime; | |
434 | fResolution = Math.max(1, (fZoomEndTime - fZoomStartTime) / fDisplayWidth); | |
435 | fMonitor = new NullProgressMonitor(); | |
436 | } | |
437 | ||
438 | @Override | |
439 | public void run() { | |
440 | if (fZoomEntryList == null) { | |
441 | return; | |
442 | } | |
443 | for (TimeGraphEntry entry : fZoomEntryList) { | |
444 | if (fMonitor.isCanceled()) { | |
445 | break; | |
446 | } | |
447 | zoom(entry, fMonitor); | |
448 | } | |
449 | } | |
450 | ||
451 | private void zoom(TimeGraphEntry entry, IProgressMonitor monitor) { | |
452 | if (fZoomStartTime <= fStartTime && fZoomEndTime >= fEndTime) { | |
453 | entry.setZoomedEventList(null); | |
454 | } else { | |
455 | List<ITimeEvent> zoomedEventList = getEventList(entry, fZoomStartTime, fZoomEndTime, fResolution, monitor); | |
456 | if (zoomedEventList != null) { | |
457 | entry.setZoomedEventList(zoomedEventList); | |
458 | } | |
459 | } | |
460 | redraw(); | |
461 | for (TimeGraphEntry child : entry.getChildren()) { | |
462 | if (fMonitor.isCanceled()) { | |
463 | return; | |
464 | } | |
465 | zoom(child, monitor); | |
466 | } | |
467 | } | |
468 | ||
469 | public void cancel() { | |
470 | fMonitor.setCanceled(true); | |
471 | } | |
472 | } | |
473 | ||
474 | // ------------------------------------------------------------------------ | |
475 | // Constructors | |
476 | // ------------------------------------------------------------------------ | |
477 | ||
478 | /** | |
479 | * Constructor | |
480 | * | |
481 | * @param id | |
482 | * The id of the view | |
483 | * @param cols | |
484 | * The columns to display in the tree view on the left | |
485 | * @param filterCols | |
486 | * The columns list to filter the view | |
487 | * @param pres | |
488 | * The presentation provider | |
489 | */ | |
490 | public AbstractTimeGraphView(String id, String[] cols, String[] filterCols, | |
491 | TimeGraphPresentationProvider pres) { | |
492 | super(id); | |
493 | fColumns = cols; | |
494 | fFilterColumns = filterCols; | |
495 | fPresentation = pres; | |
496 | fDisplayWidth = Display.getDefault().getBounds().width; | |
497 | } | |
498 | ||
499 | // ------------------------------------------------------------------------ | |
500 | // ViewPart | |
501 | // ------------------------------------------------------------------------ | |
502 | ||
503 | @Override | |
504 | public void createPartControl(Composite parent) { | |
505 | fTimeGraphCombo = new TimeGraphCombo(parent, SWT.NONE, fWeight); | |
506 | ||
507 | fTimeGraphCombo.setTreeContentProvider(new TreeContentProvider()); | |
508 | ||
509 | fTimeGraphCombo.setTreeLabelProvider(fLabelProvider); | |
510 | ||
511 | fTimeGraphCombo.setTimeGraphProvider(fPresentation); | |
512 | ||
513 | fTimeGraphCombo.setTreeColumns(fColumns); | |
514 | ||
515 | fTimeGraphCombo.setFilterContentProvider(new TreeContentProvider()); | |
516 | ||
517 | fTimeGraphCombo.setFilterLabelProvider(new TreeLabelProvider()); | |
518 | ||
519 | fTimeGraphCombo.setFilterColumns(fFilterColumns); | |
520 | ||
521 | fTimeGraphCombo.getTimeGraphViewer().addRangeListener(new ITimeGraphRangeListener() { | |
522 | @Override | |
523 | public void timeRangeUpdated(TimeGraphRangeUpdateEvent event) { | |
524 | final long startTime = event.getStartTime(); | |
525 | final long endTime = event.getEndTime(); | |
526 | TmfTimeRange range = new TmfTimeRange(new CtfTmfTimestamp(startTime), new CtfTmfTimestamp(endTime)); | |
0fcf3b09 | 527 | broadcast(new TmfRangeSynchSignal(AbstractTimeGraphView.this, range)); |
4999a196 GB |
528 | if (fZoomThread != null) { |
529 | fZoomThread.cancel(); | |
530 | } | |
531 | startZoomThread(startTime, endTime); | |
532 | } | |
533 | }); | |
534 | ||
535 | fTimeGraphCombo.getTimeGraphViewer().addTimeListener(new ITimeGraphTimeListener() { | |
536 | @Override | |
537 | public void timeSelected(TimeGraphTimeEvent event) { | |
0fcf3b09 PT |
538 | CtfTmfTimestamp startTime = new CtfTmfTimestamp(event.getBeginTime()); |
539 | CtfTmfTimestamp endTime = new CtfTmfTimestamp(event.getEndTime()); | |
540 | broadcast(new TmfTimeSynchSignal(AbstractTimeGraphView.this, startTime, endTime)); | |
4999a196 GB |
541 | } |
542 | }); | |
543 | ||
544 | fTimeGraphCombo.addSelectionListener(new ITimeGraphSelectionListener() { | |
545 | @Override | |
546 | public void selectionChanged(TimeGraphSelectionEvent event) { | |
547 | // ITimeGraphEntry selection = event.getSelection(); | |
548 | } | |
549 | }); | |
550 | ||
551 | fTimeGraphCombo.getTimeGraphViewer().setTimeFormat(TimeFormat.CALENDAR); | |
552 | ||
0fcf3b09 PT |
553 | IStatusLineManager statusLineManager = getViewSite().getActionBars().getStatusLineManager(); |
554 | fTimeGraphCombo.getTimeGraphViewer().getTimeGraphControl().setStatusLineManager(statusLineManager); | |
555 | ||
4999a196 GB |
556 | // View Action Handling |
557 | makeActions(); | |
558 | contributeToActionBars(); | |
559 | ||
560 | ITmfTrace trace = getActiveTrace(); | |
561 | if (trace != null) { | |
562 | traceSelected(new TmfTraceSelectedSignal(this, trace)); | |
563 | } | |
564 | ||
565 | // make selection available to other views | |
566 | getSite().setSelectionProvider(fTimeGraphCombo.getTreeViewer()); | |
567 | } | |
568 | ||
569 | @Override | |
570 | public void setFocus() { | |
571 | fTimeGraphCombo.setFocus(); | |
572 | } | |
573 | ||
574 | // ------------------------------------------------------------------------ | |
575 | // Signal handlers | |
576 | // ------------------------------------------------------------------------ | |
577 | ||
578 | /** | |
579 | * Handler for the trace opened signal. | |
580 | * | |
581 | * @param signal | |
582 | * The incoming signal | |
583 | * @since 2.0 | |
584 | */ | |
585 | @TmfSignalHandler | |
586 | public void traceOpened(TmfTraceOpenedSignal signal) { | |
587 | fTrace = signal.getTrace(); | |
588 | loadTrace(); | |
589 | } | |
590 | ||
591 | /** | |
592 | * Handler for the trace selected signal | |
593 | * | |
594 | * @param signal | |
595 | * The incoming signal | |
596 | */ | |
597 | @TmfSignalHandler | |
598 | public void traceSelected(final TmfTraceSelectedSignal signal) { | |
599 | if (signal.getTrace() == fTrace) { | |
600 | return; | |
601 | } | |
602 | fTrace = signal.getTrace(); | |
603 | ||
604 | loadTrace(); | |
605 | } | |
606 | ||
607 | /** | |
608 | * Trace is closed: clear the data structures and the view | |
609 | * | |
610 | * @param signal | |
611 | * the signal received | |
612 | */ | |
613 | @TmfSignalHandler | |
614 | public void traceClosed(final TmfTraceClosedSignal signal) { | |
615 | synchronized (fBuildThreadMap) { | |
616 | BuildThread buildThread = fBuildThreadMap.remove(signal.getTrace()); | |
617 | if (buildThread != null) { | |
618 | buildThread.cancel(); | |
619 | } | |
620 | } | |
621 | synchronized (fEntryListMap) { | |
622 | fEntryListMap.remove(signal.getTrace()); | |
623 | } | |
624 | if (signal.getTrace() == fTrace) { | |
625 | fTrace = null; | |
626 | fStartTime = 0; | |
627 | fEndTime = 0; | |
628 | if (fZoomThread != null) { | |
629 | fZoomThread.cancel(); | |
630 | } | |
631 | refresh(); | |
632 | } | |
633 | } | |
634 | ||
635 | /** | |
0fcf3b09 | 636 | * Handler for the time synch signal |
4999a196 GB |
637 | * |
638 | * @param signal | |
639 | * The signal that's received | |
640 | */ | |
641 | @TmfSignalHandler | |
642 | public void synchToTime(final TmfTimeSynchSignal signal) { | |
643 | if (signal.getSource() == this || fTrace == null) { | |
644 | return; | |
645 | } | |
0fcf3b09 PT |
646 | final long beginTime = signal.getBeginTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue(); |
647 | final long endTime = signal.getEndTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue(); | |
4999a196 GB |
648 | |
649 | Display.getDefault().asyncExec(new Runnable() { | |
650 | @Override | |
651 | public void run() { | |
652 | if (fTimeGraphCombo.isDisposed()) { | |
653 | return; | |
654 | } | |
0fcf3b09 PT |
655 | if (beginTime == endTime) { |
656 | fTimeGraphCombo.getTimeGraphViewer().setSelectedTime(beginTime, true); | |
657 | } else { | |
658 | fTimeGraphCombo.getTimeGraphViewer().setSelectionRange(beginTime, endTime); | |
659 | } | |
4999a196 GB |
660 | startZoomThread(fTimeGraphCombo.getTimeGraphViewer().getTime0(), fTimeGraphCombo.getTimeGraphViewer().getTime1()); |
661 | ||
0fcf3b09 | 662 | synchingToTime(beginTime); |
4999a196 GB |
663 | } |
664 | }); | |
665 | } | |
666 | ||
667 | /** | |
0fcf3b09 | 668 | * Handler for the range synch signal |
4999a196 GB |
669 | * |
670 | * @param signal | |
671 | * The signal that's received | |
672 | */ | |
673 | @TmfSignalHandler | |
674 | public void synchToRange(final TmfRangeSynchSignal signal) { | |
675 | if (signal.getSource() == this || fTrace == null) { | |
676 | return; | |
677 | } | |
678 | if (signal.getCurrentRange().getIntersection(fTrace.getTimeRange()) == null) { | |
679 | return; | |
680 | } | |
681 | final long startTime = signal.getCurrentRange().getStartTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue(); | |
682 | final long endTime = signal.getCurrentRange().getEndTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue(); | |
4999a196 GB |
683 | Display.getDefault().asyncExec(new Runnable() { |
684 | @Override | |
685 | public void run() { | |
686 | if (fTimeGraphCombo.isDisposed()) { | |
687 | return; | |
688 | } | |
689 | fTimeGraphCombo.getTimeGraphViewer().setStartFinishTime(startTime, endTime); | |
4999a196 GB |
690 | startZoomThread(startTime, endTime); |
691 | } | |
692 | }); | |
693 | } | |
694 | ||
c1cd9635 MAL |
695 | /** |
696 | * @param signal the format of the timestamps was updated. | |
697 | */ | |
698 | @TmfSignalHandler | |
699 | public void updateTimeFormat( final TmfTimestampFormatUpdateSignal signal){ | |
700 | this.fTimeGraphCombo.refresh(); | |
701 | } | |
702 | ||
4999a196 GB |
703 | // ------------------------------------------------------------------------ |
704 | // Internal | |
705 | // ------------------------------------------------------------------------ | |
706 | ||
707 | private void loadTrace() { | |
708 | synchronized (fEntryListMap) { | |
709 | fEntryList = fEntryListMap.get(fTrace); | |
710 | if (fEntryList == null) { | |
711 | synchronized (fBuildThreadMap) { | |
712 | BuildThread buildThread = new BuildThread(fTrace, this.getName()); | |
713 | fBuildThreadMap.put(fTrace, buildThread); | |
714 | buildThread.start(); | |
715 | } | |
716 | } else { | |
717 | fStartTime = fTrace.getStartTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue(); | |
718 | fEndTime = fTrace.getEndTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue(); | |
719 | refresh(); | |
720 | } | |
721 | } | |
722 | } | |
723 | ||
724 | /** | |
725 | * Method called when synching to a given timestamp. Inheriting classes can | |
726 | * perform actions here to update the view at the given timestamp. | |
727 | * | |
728 | * @param time | |
729 | * The currently selected time | |
730 | */ | |
731 | protected void synchingToTime(long time) { | |
732 | ||
733 | } | |
734 | ||
735 | /** | |
736 | * Build the entries list to show in this time graph | |
737 | * | |
738 | * Called from the BuildThread | |
739 | * | |
740 | * @param trace | |
741 | * The trace being built | |
742 | * @param monitor | |
743 | * The progress monitor object | |
744 | */ | |
745 | protected abstract void buildEventList(final ITmfTrace trace, IProgressMonitor monitor); | |
746 | ||
747 | /** | |
748 | * Gets the list of event for an entry in a given timerange | |
749 | * | |
750 | * @param entry | |
751 | * The entry to get events for | |
752 | * @param startTime | |
753 | * Start of the time range | |
754 | * @param endTime | |
755 | * End of the time range | |
756 | * @param resolution | |
757 | * The resolution | |
758 | * @param monitor | |
759 | * The progress monitor object | |
760 | * @return The list of events for the entry | |
761 | */ | |
762 | protected abstract List<ITimeEvent> getEventList(TimeGraphEntry entry, | |
763 | long startTime, long endTime, long resolution, | |
764 | IProgressMonitor monitor); | |
765 | ||
766 | /** | |
767 | * Refresh the display | |
768 | */ | |
769 | protected void refresh() { | |
770 | Display.getDefault().asyncExec(new Runnable() { | |
771 | @Override | |
772 | public void run() { | |
773 | if (fTimeGraphCombo.isDisposed()) { | |
774 | return; | |
775 | } | |
776 | ITimeGraphEntry[] entries = null; | |
777 | synchronized (fEntryListMap) { | |
778 | fEntryList = fEntryListMap.get(fTrace); | |
779 | if (fEntryList == null) { | |
780 | fEntryList = new ArrayList<TimeGraphEntry>(); | |
781 | } | |
782 | entries = fEntryList.toArray(new ITimeGraphEntry[0]); | |
783 | } | |
784 | if (fEntryComparator != null) { | |
785 | Arrays.sort(entries, fEntryComparator); | |
786 | } | |
787 | fTimeGraphCombo.setInput(entries); | |
788 | fTimeGraphCombo.getTimeGraphViewer().setTimeBounds(fStartTime, fEndTime); | |
789 | ||
0fcf3b09 PT |
790 | long selectionBeginTime = fTrace == null ? 0 : fTraceManager.getSelectionBeginTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue(); |
791 | long selectionEndTime = fTrace == null ? 0 : fTraceManager.getSelectionEndTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue(); | |
4999a196 GB |
792 | long startTime = fTrace == null ? 0 : fTraceManager.getCurrentRange().getStartTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue(); |
793 | long endTime = fTrace == null ? 0 : fTraceManager.getCurrentRange().getEndTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue(); | |
794 | startTime = Math.max(startTime, fStartTime); | |
795 | endTime = Math.min(endTime, fEndTime); | |
0fcf3b09 | 796 | fTimeGraphCombo.getTimeGraphViewer().setSelectionRange(selectionBeginTime, selectionEndTime); |
4999a196 GB |
797 | fTimeGraphCombo.getTimeGraphViewer().setStartFinishTime(startTime, endTime); |
798 | ||
799 | for (TreeColumn column : fTimeGraphCombo.getTreeViewer().getTree().getColumns()) { | |
800 | column.pack(); | |
801 | } | |
802 | ||
803 | startZoomThread(startTime, endTime); | |
804 | } | |
805 | }); | |
806 | } | |
807 | ||
808 | /** | |
809 | * Redraw the canvas | |
810 | */ | |
811 | protected void redraw() { | |
812 | synchronized (fSyncObj) { | |
813 | if (fRedrawState == State.IDLE) { | |
814 | fRedrawState = State.BUSY; | |
815 | } else { | |
816 | fRedrawState = State.PENDING; | |
817 | return; | |
818 | } | |
819 | } | |
820 | Display.getDefault().asyncExec(new Runnable() { | |
821 | @Override | |
822 | public void run() { | |
823 | if (fTimeGraphCombo.isDisposed()) { | |
824 | return; | |
825 | } | |
826 | fTimeGraphCombo.redraw(); | |
827 | fTimeGraphCombo.update(); | |
828 | synchronized (fSyncObj) { | |
829 | if (fRedrawState == State.PENDING) { | |
830 | fRedrawState = State.IDLE; | |
831 | redraw(); | |
832 | } else { | |
833 | fRedrawState = State.IDLE; | |
834 | } | |
835 | } | |
836 | } | |
837 | }); | |
838 | } | |
839 | ||
840 | private void startZoomThread(long startTime, long endTime) { | |
841 | if (fZoomThread != null) { | |
842 | fZoomThread.cancel(); | |
843 | } | |
844 | fZoomThread = new ZoomThread(fEntryList, startTime, endTime, getName()); | |
845 | fZoomThread.start(); | |
846 | } | |
847 | ||
848 | private void makeActions() { | |
849 | fPreviousResourceAction = fTimeGraphCombo.getTimeGraphViewer().getPreviousItemAction(); | |
850 | fPreviousResourceAction.setText(getPrevText()); | |
851 | fPreviousResourceAction.setToolTipText(getPrevTooltip()); | |
852 | fNextResourceAction = fTimeGraphCombo.getTimeGraphViewer().getNextItemAction(); | |
853 | fNextResourceAction.setText(getNextText()); | |
854 | fNextResourceAction.setToolTipText(getNextTooltip()); | |
855 | } | |
856 | ||
857 | private void contributeToActionBars() { | |
858 | IActionBars bars = getViewSite().getActionBars(); | |
859 | fillLocalToolBar(bars.getToolBarManager()); | |
860 | } | |
861 | ||
862 | private void fillLocalToolBar(IToolBarManager manager) { | |
863 | if (fFilterColumns.length > 0) { | |
864 | manager.add(fTimeGraphCombo.getShowFilterAction()); | |
865 | } | |
866 | manager.add(fTimeGraphCombo.getTimeGraphViewer().getShowLegendAction()); | |
867 | manager.add(new Separator()); | |
868 | manager.add(fTimeGraphCombo.getTimeGraphViewer().getResetScaleAction()); | |
869 | manager.add(fTimeGraphCombo.getTimeGraphViewer().getPreviousEventAction()); | |
870 | manager.add(fTimeGraphCombo.getTimeGraphViewer().getNextEventAction()); | |
871 | manager.add(fPreviousResourceAction); | |
872 | manager.add(fNextResourceAction); | |
873 | manager.add(fTimeGraphCombo.getTimeGraphViewer().getZoomInAction()); | |
874 | manager.add(fTimeGraphCombo.getTimeGraphViewer().getZoomOutAction()); | |
875 | manager.add(new Separator()); | |
876 | } | |
877 | } |