tmf: Switch tmf.ui to Java 7 + fix warnings
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / views / timegraph / AbstractTimeGraphView.java
CommitLineData
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
bec1f1ac 14 * Geneviève Bastien - Add event links between entries
4999a196
GB
15 *******************************************************************************/
16
17package org.eclipse.linuxtools.tmf.ui.views.timegraph;
18
19import java.util.ArrayList;
20import java.util.Arrays;
21import java.util.Collections;
22import java.util.Comparator;
23import java.util.HashMap;
24import java.util.List;
25import java.util.Map;
26
27import org.eclipse.core.runtime.IProgressMonitor;
28import org.eclipse.core.runtime.NullProgressMonitor;
29import org.eclipse.jface.action.Action;
747adf5c 30import org.eclipse.jface.action.IAction;
0fcf3b09 31import org.eclipse.jface.action.IStatusLineManager;
4999a196
GB
32import org.eclipse.jface.action.IToolBarManager;
33import org.eclipse.jface.action.Separator;
34import org.eclipse.jface.viewers.ILabelProviderListener;
747adf5c 35import org.eclipse.jface.viewers.ISelectionProvider;
4999a196
GB
36import org.eclipse.jface.viewers.ITableLabelProvider;
37import org.eclipse.jface.viewers.ITreeContentProvider;
747adf5c 38import org.eclipse.jface.viewers.TreeViewer;
4999a196 39import org.eclipse.jface.viewers.Viewer;
4999a196
GB
40import org.eclipse.linuxtools.tmf.core.signal.TmfRangeSynchSignal;
41import org.eclipse.linuxtools.tmf.core.signal.TmfSignalHandler;
42import org.eclipse.linuxtools.tmf.core.signal.TmfTimeSynchSignal;
c1cd9635 43import org.eclipse.linuxtools.tmf.core.signal.TmfTimestampFormatUpdateSignal;
4999a196
GB
44import org.eclipse.linuxtools.tmf.core.signal.TmfTraceClosedSignal;
45import org.eclipse.linuxtools.tmf.core.signal.TmfTraceOpenedSignal;
46import org.eclipse.linuxtools.tmf.core.signal.TmfTraceSelectedSignal;
47import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp;
f566d40a 48import org.eclipse.linuxtools.tmf.core.timestamp.TmfNanoTimestamp;
4999a196 49import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimeRange;
4999a196
GB
50import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
51import org.eclipse.linuxtools.tmf.ui.views.TmfView;
52import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphRangeListener;
53import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphSelectionListener;
54import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphTimeListener;
55import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TimeGraphCombo;
56import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TimeGraphPresentationProvider;
57import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TimeGraphRangeUpdateEvent;
58import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TimeGraphSelectionEvent;
59import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TimeGraphTimeEvent;
747adf5c 60import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TimeGraphViewer;
bec1f1ac 61import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ILinkEvent;
4999a196
GB
62import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent;
63import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeGraphEntry;
64import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.TimeGraphEntry;
65import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.Utils.TimeFormat;
66import org.eclipse.swt.SWT;
67import org.eclipse.swt.graphics.Image;
68import org.eclipse.swt.widgets.Composite;
69import org.eclipse.swt.widgets.Display;
70import org.eclipse.swt.widgets.TreeColumn;
71import org.eclipse.ui.IActionBars;
72
73/**
74 * An abstract view all time graph views can inherit
75 *
747adf5c
PT
76 * This view contains either a time graph viewer, or a time graph combo which is
77 * divided between a tree viewer on the left and a time graph viewer on the right.
4999a196 78 *
4b121c48 79 * @since 2.1
4999a196
GB
80 */
81public abstract class AbstractTimeGraphView extends TmfView {
82
4999a196
GB
83 /**
84 * Redraw state enum
85 */
86 private enum State {
87 IDLE, BUSY, PENDING
88 }
89
90 // ------------------------------------------------------------------------
91 // Fields
92 // ------------------------------------------------------------------------
93
747adf5c
PT
94 /** The timegraph wrapper */
95 private ITimeGraphWrapper fTimeGraphWrapper;
4999a196
GB
96
97 /** The selected trace */
98 private ITmfTrace fTrace;
99
100 /** The timegraph entry list */
101 private List<TimeGraphEntry> fEntryList;
102
103 /** The trace to entry list hash map */
507b1336 104 private final Map<ITmfTrace, List<TimeGraphEntry>> fEntryListMap = new HashMap<>();
4999a196
GB
105
106 /* The trace to build thread hash map */
507b1336 107 private final Map<ITmfTrace, BuildThread> fBuildThreadMap = new HashMap<>();
4999a196
GB
108
109 /** The start time */
110 private long fStartTime;
111
112 /** The end time */
113 private long fEndTime;
114
115 /** The display width */
116 private final int fDisplayWidth;
117
118 /** The zoom thread */
119 private ZoomThread fZoomThread;
120
121 /** The next resource action */
122 private Action fNextResourceAction;
123
124 /** The previous resource action */
125 private Action fPreviousResourceAction;
126
4999a196
GB
127 /** A comparator class */
128 private Comparator<ITimeGraphEntry> fEntryComparator = null;
129
130 /** The redraw state used to prevent unnecessary queuing of display runnables */
131 private State fRedrawState = State.IDLE;
132
133 /** The redraw synchronization object */
134 private final Object fSyncObj = new Object();
135
136 /** The presentation provider for this view */
137 private final TimeGraphPresentationProvider fPresentation;
138
747adf5c
PT
139 /** The tree column label array, or null if combo is not used */
140 private String[] fColumns;
141
142 /** The tree label provider, or null if combo is not used */
143 private TreeLabelProvider fLabelProvider = null;
144
145 /** The relative weight of the sash, ignored if combo is not used */
146 private int[] fWeight = { 1, 1 };
147
148 /** The filter column label array, or null if filter is not used */
149 private String[] fFilterColumns;
4999a196
GB
150
151 // ------------------------------------------------------------------------
747adf5c 152 // Classes
4999a196
GB
153 // ------------------------------------------------------------------------
154
747adf5c 155 private interface ITimeGraphWrapper {
4999a196 156
747adf5c 157 void setTimeGraphProvider(TimeGraphPresentationProvider fPresentation);
4999a196 158
747adf5c 159 TimeGraphViewer getTimeGraphViewer();
4999a196 160
747adf5c 161 void addSelectionListener(ITimeGraphSelectionListener iTimeGraphSelectionListener);
4999a196 162
747adf5c 163 ISelectionProvider getSelectionProvider();
4999a196 164
747adf5c 165 void setFocus();
4999a196 166
747adf5c 167 boolean isDisposed();
4999a196 168
747adf5c 169 void refresh();
4999a196 170
747adf5c 171 void setInput(ITimeGraphEntry[] entries);
4999a196 172
747adf5c 173 void redraw();
4999a196 174
747adf5c 175 void update();
4999a196 176
4999a196
GB
177 }
178
747adf5c
PT
179 private class TimeGraphViewerWrapper implements ITimeGraphWrapper {
180 private TimeGraphViewer viewer;
4999a196 181
747adf5c
PT
182 private TimeGraphViewerWrapper(Composite parent, int style) {
183 viewer = new TimeGraphViewer(parent, style);
4999a196 184 }
4999a196 185
747adf5c
PT
186 @Override
187 public void setTimeGraphProvider(TimeGraphPresentationProvider timeGraphProvider) {
188 viewer.setTimeGraphProvider(timeGraphProvider);
189 }
4999a196 190
747adf5c
PT
191 @Override
192 public TimeGraphViewer getTimeGraphViewer() {
193 return viewer;
194 }
4999a196 195
747adf5c
PT
196 @Override
197 public void addSelectionListener(ITimeGraphSelectionListener listener) {
198 viewer.addSelectionListener(listener);
199 }
4999a196 200
747adf5c
PT
201 @Override
202 public ISelectionProvider getSelectionProvider() {
203 return viewer.getSelectionProvider();
204 }
205
206 @Override
207 public void setFocus() {
208 viewer.setFocus();
209 }
210
211 @Override
212 public boolean isDisposed() {
213 return viewer.getControl().isDisposed();
214 }
215
216 @Override
217 public void setInput(ITimeGraphEntry[] input) {
218 viewer.setInput(input);
219 }
220
221 @Override
222 public void refresh() {
223 viewer.refresh();
224 }
225
226 @Override
227 public void redraw() {
228 viewer.getControl().redraw();
229 }
230
231 @Override
232 public void update() {
233 viewer.getControl().update();
234 }
4999a196
GB
235 }
236
747adf5c
PT
237 private class TimeGraphComboWrapper implements ITimeGraphWrapper {
238 private TimeGraphCombo combo;
239
240 private TimeGraphComboWrapper(Composite parent, int style) {
241 combo = new TimeGraphCombo(parent, style, fWeight);
242 }
243
244 @Override
245 public void setTimeGraphProvider(TimeGraphPresentationProvider timeGraphProvider) {
246 combo.setTimeGraphProvider(timeGraphProvider);
247 }
248
249 @Override
250 public TimeGraphViewer getTimeGraphViewer() {
251 return combo.getTimeGraphViewer();
252 }
253
254 @Override
255 public void addSelectionListener(ITimeGraphSelectionListener listener) {
256 combo.addSelectionListener(listener);
257 }
258
259 @Override
260 public ISelectionProvider getSelectionProvider() {
261 return combo.getTreeViewer();
262 }
263
264 @Override
265 public void setFocus() {
266 combo.setFocus();
267 }
268
269 @Override
270 public boolean isDisposed() {
271 return combo.isDisposed();
272 }
273
274 @Override
275 public void setInput(ITimeGraphEntry[] input) {
276 combo.setInput(input);
277 }
278
279 @Override
280 public void refresh() {
281 combo.refresh();
282 }
283
284 @Override
285 public void redraw() {
286 combo.redraw();
287 }
288
289 @Override
290 public void update() {
291 combo.update();
292 }
293
294 TimeGraphCombo getTimeGraphCombo() {
295 return combo;
296 }
297
298 TreeViewer getTreeViewer() {
299 return combo.getTreeViewer();
300 }
301
302 IAction getShowFilterAction() {
303 return combo.getShowFilterAction();
304 }
305 }
4999a196
GB
306
307 private class TreeContentProvider implements ITreeContentProvider {
308
309 @Override
310 public void dispose() {
311 }
312
313 @Override
314 public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
315 }
316
317 @Override
318 public Object[] getElements(Object inputElement) {
319 return (ITimeGraphEntry[]) inputElement;
320 }
321
322 @Override
323 public Object[] getChildren(Object parentElement) {
324 ITimeGraphEntry entry = (ITimeGraphEntry) parentElement;
325 List<? extends ITimeGraphEntry> children = entry.getChildren();
326 return children.toArray(new ITimeGraphEntry[children.size()]);
327 }
328
329 @Override
330 public Object getParent(Object element) {
331 ITimeGraphEntry entry = (ITimeGraphEntry) element;
332 return entry.getParent();
333 }
334
335 @Override
336 public boolean hasChildren(Object element) {
337 ITimeGraphEntry entry = (ITimeGraphEntry) element;
338 return entry.hasChildren();
339 }
340
341 }
342
343 /**
747adf5c
PT
344 * Base class to provide the labels for the tree viewer. Views extending
345 * this class typically need to override the getColumnText method if they
346 * have more than one column to display
4999a196
GB
347 */
348 protected static class TreeLabelProvider implements ITableLabelProvider {
349
350 @Override
351 public void addListener(ILabelProviderListener listener) {
352 }
353
354 @Override
355 public void dispose() {
356 }
357
358 @Override
359 public boolean isLabelProperty(Object element, String property) {
360 return false;
361 }
362
363 @Override
364 public void removeListener(ILabelProviderListener listener) {
365 }
366
367 @Override
368 public Image getColumnImage(Object element, int columnIndex) {
369 return null;
370 }
371
372 @Override
373 public String getColumnText(Object element, int columnIndex) {
374 TimeGraphEntry entry = (TimeGraphEntry) element;
375 if (columnIndex == 0) {
376 return entry.getName();
377 }
76fccfb0 378 return new String();
4999a196
GB
379 }
380
381 }
382
383 private class BuildThread extends Thread {
384 private final ITmfTrace fBuildTrace;
385 private final IProgressMonitor fMonitor;
386
387 public BuildThread(final ITmfTrace trace, final String name) {
388 super(name + " build"); //$NON-NLS-1$
389 fBuildTrace = trace;
390 fMonitor = new NullProgressMonitor();
391 }
392
393 @Override
394 public void run() {
395 buildEventList(fBuildTrace, fMonitor);
396 synchronized (fBuildThreadMap) {
397 fBuildThreadMap.remove(this);
398 }
399 }
400
401 public void cancel() {
402 fMonitor.setCanceled(true);
403 }
404 }
405
406 private class ZoomThread extends Thread {
407 private final List<TimeGraphEntry> fZoomEntryList;
408 private final long fZoomStartTime;
409 private final long fZoomEndTime;
410 private final long fResolution;
411 private final IProgressMonitor fMonitor;
412
413 public ZoomThread(List<TimeGraphEntry> entryList, long startTime, long endTime, String name) {
414 super(name + " zoom"); //$NON-NLS-1$
415 fZoomEntryList = entryList;
416 fZoomStartTime = startTime;
417 fZoomEndTime = endTime;
418 fResolution = Math.max(1, (fZoomEndTime - fZoomStartTime) / fDisplayWidth);
419 fMonitor = new NullProgressMonitor();
420 }
421
422 @Override
423 public void run() {
424 if (fZoomEntryList == null) {
425 return;
426 }
427 for (TimeGraphEntry entry : fZoomEntryList) {
428 if (fMonitor.isCanceled()) {
79ec0b89 429 return;
4999a196
GB
430 }
431 zoom(entry, fMonitor);
432 }
bec1f1ac
GB
433 /* Refresh the arrows when zooming */
434 List<ILinkEvent> events = getLinkList(fZoomStartTime, fZoomEndTime, fResolution, fMonitor);
79ec0b89 435 if (events != null) {
747adf5c 436 fTimeGraphWrapper.getTimeGraphViewer().setLinks(events);
79ec0b89
PT
437 redraw();
438 }
4999a196
GB
439 }
440
441 private void zoom(TimeGraphEntry entry, IProgressMonitor monitor) {
442 if (fZoomStartTime <= fStartTime && fZoomEndTime >= fEndTime) {
443 entry.setZoomedEventList(null);
444 } else {
445 List<ITimeEvent> zoomedEventList = getEventList(entry, fZoomStartTime, fZoomEndTime, fResolution, monitor);
446 if (zoomedEventList != null) {
447 entry.setZoomedEventList(zoomedEventList);
448 }
449 }
450 redraw();
451 for (TimeGraphEntry child : entry.getChildren()) {
452 if (fMonitor.isCanceled()) {
453 return;
454 }
455 zoom(child, monitor);
456 }
457 }
458
459 public void cancel() {
460 fMonitor.setCanceled(true);
461 }
462 }
463
464 // ------------------------------------------------------------------------
465 // Constructors
466 // ------------------------------------------------------------------------
467
468 /**
747adf5c
PT
469 * Constructs a time graph view that contains either a time graph viewer or
470 * a time graph combo.
471 *
472 * By default, the view uses a time graph viewer. To use a time graph combo,
473 * the subclass constructor must call {@link #setTreeColumns(String[])} and
474 * {@link #setTreeLabelProvider(TreeLabelProvider)}.
4999a196
GB
475 *
476 * @param id
477 * The id of the view
4999a196
GB
478 * @param pres
479 * The presentation provider
480 */
747adf5c 481 public AbstractTimeGraphView(String id, TimeGraphPresentationProvider pres) {
4999a196 482 super(id);
4999a196
GB
483 fPresentation = pres;
484 fDisplayWidth = Display.getDefault().getBounds().width;
485 }
486
487 // ------------------------------------------------------------------------
747adf5c 488 // Getters and setters
4999a196
GB
489 // ------------------------------------------------------------------------
490
747adf5c
PT
491 /**
492 * Getter for the time graph combo
493 *
494 * @return The time graph combo, or null if combo is not used
495 */
496 protected TimeGraphCombo getTimeGraphCombo() {
497 if (fTimeGraphWrapper instanceof TimeGraphComboWrapper) {
498 return ((TimeGraphComboWrapper) fTimeGraphWrapper).getTimeGraphCombo();
499 }
500 return null;
501 }
4999a196 502
747adf5c
PT
503 /**
504 * Getter for the time graph viewer
505 *
506 * @return The time graph viewer
507 */
508 protected TimeGraphViewer getTimeGraphViewer() {
509 return fTimeGraphWrapper.getTimeGraphViewer();
510 }
511
512 /**
513 * Sets the tree column labels.
514 * This should be called from the constructor.
515 *
516 * @param columns
517 * The array of tree column labels
518 */
519 protected void setTreeColumns(final String[] columns) {
520 fColumns = columns;
521 }
522
523 /**
524 * Sets the tree label provider.
525 * This should be called from the constructor.
526 *
527 * @param tlp
528 * The tree label provider
529 */
530 protected void setTreeLabelProvider(final TreeLabelProvider tlp) {
531 fLabelProvider = tlp;
532 }
533
534 /**
535 * Sets the relative weight of each part of the time graph combo.
536 * This should be called from the constructor.
537 *
538 * @param weights
539 * The array (length 2) of relative weights of each part of the combo
540 */
541 protected void setWeight(final int[] weights) {
542 fWeight = weights;
543 }
4999a196 544
747adf5c
PT
545 /**
546 * Sets the filter column labels.
547 * This should be called from the constructor.
548 *
549 * @param filterColumns
550 * The array of filter column labels
551 */
552 protected void setFilterColumns(final String[] filterColumns) {
553 fFilterColumns = filterColumns;
554 }
4999a196 555
747adf5c
PT
556 /**
557 * Gets the display width
558 *
559 * @return the display width
560 */
561 protected int getDisplayWidth() {
562 return fDisplayWidth;
563 }
4999a196 564
747adf5c
PT
565 /**
566 * Gets the comparator for the entries
567 *
568 * @return The entry comparator
569 */
570 protected Comparator<ITimeGraphEntry> getEntryComparator() {
571 return fEntryComparator;
572 }
4999a196 573
747adf5c
PT
574 /**
575 * Sets the comparator class for the entries
576 *
577 * @param comparator
578 * A comparator object
579 */
580 protected void setEntryComparator(final Comparator<ITimeGraphEntry> comparator) {
581 fEntryComparator = comparator;
582 }
4999a196 583
747adf5c
PT
584 /**
585 * Gets the trace displayed in the view
586 *
587 * @return The trace
588 */
589 protected ITmfTrace getTrace() {
590 return fTrace;
591 }
4999a196 592
747adf5c
PT
593 /**
594 * Gets the start time
595 *
596 * @return The start time
597 */
598 protected long getStartTime() {
599 return fStartTime;
600 }
4999a196 601
747adf5c
PT
602 /**
603 * Sets the start time
604 *
605 * @param time
606 * The start time
607 */
608 protected void setStartTime(long time) {
609 fStartTime = time;
610 }
611
612 /**
613 * Gets the end time
614 *
615 * @return The end time
616 */
617 protected long getEndTime() {
618 return fEndTime;
619 }
620
621 /**
622 * Sets the end time
623 *
624 * @param time
625 * The end time
626 */
627 protected void setEndTime(long time) {
628 fEndTime = time;
629 }
630
631 /**
632 * Gets the entry list map
633 *
634 * @return the entry list map
635 */
636 protected Map<ITmfTrace, List<TimeGraphEntry>> getEntryListMap() {
637 return Collections.unmodifiableMap(fEntryListMap);
638 }
639
640 /**
641 * Adds an entry to the entry list
642 *
643 * @param trace
644 * the trace to add
645 * @param list
646 * The list of time graph entries
647 */
648 protected void putEntryList(ITmfTrace trace, List<TimeGraphEntry> list) {
649 synchronized(fEntryListMap) {
650 fEntryListMap.put(trace, list);
651 }
652 }
4999a196 653
747adf5c
PT
654 /**
655 * Text for the "next" button
656 *
657 * @return The "next" button text
658 */
659 protected String getNextText() {
660 return Messages.AbstractTimeGraphtView_NextText;
661 }
4999a196 662
747adf5c
PT
663 /**
664 * Tooltip for the "next" button
665 *
666 * @return Tooltip for the "next" button
667 */
668 protected String getNextTooltip() {
669 return Messages.AbstractTimeGraphView_NextTooltip;
670 }
4999a196 671
747adf5c
PT
672 /**
673 * Text for the "Previous" button
674 *
675 * @return The "Previous" button text
676 */
677 protected String getPrevText() {
678 return Messages.AbstractTimeGraphView_PreviousText;
679 }
4999a196 680
747adf5c
PT
681 /**
682 * Tooltip for the "previous" button
683 *
684 * @return Tooltip for the "previous" button
685 */
686 protected String getPrevTooltip() {
687 return Messages.AbstractTimeGraphView_PreviousTooltip;
688 }
4999a196 689
747adf5c
PT
690 // ------------------------------------------------------------------------
691 // ViewPart
692 // ------------------------------------------------------------------------
4999a196 693
747adf5c
PT
694 @Override
695 public void createPartControl(Composite parent) {
696 if (fColumns == null || fLabelProvider == null) {
697 fTimeGraphWrapper = new TimeGraphViewerWrapper(parent, SWT.NONE);
698 } else {
699 TimeGraphComboWrapper wrapper = new TimeGraphComboWrapper(parent, SWT.NONE);
700 fTimeGraphWrapper = wrapper;
701 TimeGraphCombo combo = wrapper.getTimeGraphCombo();
702 combo.setTreeContentProvider(new TreeContentProvider());
703 combo.setTreeLabelProvider(fLabelProvider);
704 combo.setTreeColumns(fColumns);
705 combo.setFilterContentProvider(new TreeContentProvider());
706 combo.setFilterLabelProvider(new TreeLabelProvider());
707 combo.setFilterColumns(fFilterColumns);
708 }
4999a196 709
747adf5c 710 fTimeGraphWrapper.setTimeGraphProvider(fPresentation);
4999a196 711
747adf5c 712 fTimeGraphWrapper.getTimeGraphViewer().addRangeListener(new ITimeGraphRangeListener() {
4999a196
GB
713 @Override
714 public void timeRangeUpdated(TimeGraphRangeUpdateEvent event) {
715 final long startTime = event.getStartTime();
716 final long endTime = event.getEndTime();
f566d40a 717 TmfTimeRange range = new TmfTimeRange(new TmfNanoTimestamp(startTime), new TmfNanoTimestamp(endTime));
0fcf3b09 718 broadcast(new TmfRangeSynchSignal(AbstractTimeGraphView.this, range));
4999a196
GB
719 if (fZoomThread != null) {
720 fZoomThread.cancel();
721 }
722 startZoomThread(startTime, endTime);
723 }
724 });
725
747adf5c 726 fTimeGraphWrapper.getTimeGraphViewer().addTimeListener(new ITimeGraphTimeListener() {
4999a196
GB
727 @Override
728 public void timeSelected(TimeGraphTimeEvent event) {
f566d40a
PT
729 TmfNanoTimestamp startTime = new TmfNanoTimestamp(event.getBeginTime());
730 TmfNanoTimestamp endTime = new TmfNanoTimestamp(event.getEndTime());
0fcf3b09 731 broadcast(new TmfTimeSynchSignal(AbstractTimeGraphView.this, startTime, endTime));
4999a196
GB
732 }
733 });
734
747adf5c 735 fTimeGraphWrapper.addSelectionListener(new ITimeGraphSelectionListener() {
4999a196
GB
736 @Override
737 public void selectionChanged(TimeGraphSelectionEvent event) {
738 // ITimeGraphEntry selection = event.getSelection();
739 }
740 });
741
747adf5c 742 fTimeGraphWrapper.getTimeGraphViewer().setTimeFormat(TimeFormat.CALENDAR);
4999a196 743
0fcf3b09 744 IStatusLineManager statusLineManager = getViewSite().getActionBars().getStatusLineManager();
747adf5c 745 fTimeGraphWrapper.getTimeGraphViewer().getTimeGraphControl().setStatusLineManager(statusLineManager);
0fcf3b09 746
4999a196
GB
747 // View Action Handling
748 makeActions();
749 contributeToActionBars();
750
751 ITmfTrace trace = getActiveTrace();
752 if (trace != null) {
753 traceSelected(new TmfTraceSelectedSignal(this, trace));
754 }
755
756 // make selection available to other views
747adf5c 757 getSite().setSelectionProvider(fTimeGraphWrapper.getSelectionProvider());
4999a196
GB
758 }
759
760 @Override
761 public void setFocus() {
747adf5c 762 fTimeGraphWrapper.setFocus();
4999a196
GB
763 }
764
765 // ------------------------------------------------------------------------
766 // Signal handlers
767 // ------------------------------------------------------------------------
768
769 /**
770 * Handler for the trace opened signal.
771 *
772 * @param signal
773 * The incoming signal
774 * @since 2.0
775 */
776 @TmfSignalHandler
777 public void traceOpened(TmfTraceOpenedSignal signal) {
778 fTrace = signal.getTrace();
779 loadTrace();
780 }
781
782 /**
783 * Handler for the trace selected signal
784 *
785 * @param signal
786 * The incoming signal
787 */
788 @TmfSignalHandler
789 public void traceSelected(final TmfTraceSelectedSignal signal) {
790 if (signal.getTrace() == fTrace) {
791 return;
792 }
793 fTrace = signal.getTrace();
794
795 loadTrace();
796 }
797
798 /**
799 * Trace is closed: clear the data structures and the view
800 *
801 * @param signal
802 * the signal received
803 */
804 @TmfSignalHandler
805 public void traceClosed(final TmfTraceClosedSignal signal) {
806 synchronized (fBuildThreadMap) {
807 BuildThread buildThread = fBuildThreadMap.remove(signal.getTrace());
808 if (buildThread != null) {
809 buildThread.cancel();
810 }
811 }
812 synchronized (fEntryListMap) {
813 fEntryListMap.remove(signal.getTrace());
814 }
815 if (signal.getTrace() == fTrace) {
816 fTrace = null;
817 fStartTime = 0;
818 fEndTime = 0;
819 if (fZoomThread != null) {
820 fZoomThread.cancel();
821 }
822 refresh();
823 }
824 }
825
826 /**
0fcf3b09 827 * Handler for the time synch signal
4999a196
GB
828 *
829 * @param signal
830 * The signal that's received
831 */
832 @TmfSignalHandler
833 public void synchToTime(final TmfTimeSynchSignal signal) {
834 if (signal.getSource() == this || fTrace == null) {
835 return;
836 }
0fcf3b09
PT
837 final long beginTime = signal.getBeginTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue();
838 final long endTime = signal.getEndTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue();
4999a196
GB
839
840 Display.getDefault().asyncExec(new Runnable() {
841 @Override
842 public void run() {
747adf5c 843 if (fTimeGraphWrapper.isDisposed()) {
4999a196
GB
844 return;
845 }
0fcf3b09 846 if (beginTime == endTime) {
747adf5c 847 fTimeGraphWrapper.getTimeGraphViewer().setSelectedTime(beginTime, true);
0fcf3b09 848 } else {
747adf5c 849 fTimeGraphWrapper.getTimeGraphViewer().setSelectionRange(beginTime, endTime);
0fcf3b09 850 }
747adf5c 851 startZoomThread(fTimeGraphWrapper.getTimeGraphViewer().getTime0(), fTimeGraphWrapper.getTimeGraphViewer().getTime1());
4999a196 852
0fcf3b09 853 synchingToTime(beginTime);
4999a196
GB
854 }
855 });
856 }
857
858 /**
0fcf3b09 859 * Handler for the range synch signal
4999a196
GB
860 *
861 * @param signal
862 * The signal that's received
863 */
864 @TmfSignalHandler
865 public void synchToRange(final TmfRangeSynchSignal signal) {
866 if (signal.getSource() == this || fTrace == null) {
867 return;
868 }
869 if (signal.getCurrentRange().getIntersection(fTrace.getTimeRange()) == null) {
870 return;
871 }
872 final long startTime = signal.getCurrentRange().getStartTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue();
873 final long endTime = signal.getCurrentRange().getEndTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue();
4999a196
GB
874 Display.getDefault().asyncExec(new Runnable() {
875 @Override
876 public void run() {
747adf5c 877 if (fTimeGraphWrapper.isDisposed()) {
4999a196
GB
878 return;
879 }
747adf5c 880 fTimeGraphWrapper.getTimeGraphViewer().setStartFinishTime(startTime, endTime);
4999a196
GB
881 startZoomThread(startTime, endTime);
882 }
883 });
884 }
885
c1cd9635
MAL
886 /**
887 * @param signal the format of the timestamps was updated.
bec1f1ac 888 * @since 2.1
c1cd9635
MAL
889 */
890 @TmfSignalHandler
891 public void updateTimeFormat( final TmfTimestampFormatUpdateSignal signal){
747adf5c 892 fTimeGraphWrapper.refresh();
c1cd9635
MAL
893 }
894
4999a196
GB
895 // ------------------------------------------------------------------------
896 // Internal
897 // ------------------------------------------------------------------------
898
899 private void loadTrace() {
900 synchronized (fEntryListMap) {
901 fEntryList = fEntryListMap.get(fTrace);
902 if (fEntryList == null) {
903 synchronized (fBuildThreadMap) {
747adf5c 904 BuildThread buildThread = new BuildThread(fTrace, getName());
4999a196
GB
905 fBuildThreadMap.put(fTrace, buildThread);
906 buildThread.start();
907 }
908 } else {
909 fStartTime = fTrace.getStartTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue();
910 fEndTime = fTrace.getEndTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue();
911 refresh();
912 }
913 }
914 }
915
916 /**
917 * Method called when synching to a given timestamp. Inheriting classes can
918 * perform actions here to update the view at the given timestamp.
919 *
920 * @param time
921 * The currently selected time
922 */
923 protected void synchingToTime(long time) {
924
925 }
926
927 /**
928 * Build the entries list to show in this time graph
929 *
930 * Called from the BuildThread
931 *
932 * @param trace
933 * The trace being built
934 * @param monitor
935 * The progress monitor object
936 */
937 protected abstract void buildEventList(final ITmfTrace trace, IProgressMonitor monitor);
938
939 /**
940 * Gets the list of event for an entry in a given timerange
941 *
942 * @param entry
943 * The entry to get events for
944 * @param startTime
945 * Start of the time range
946 * @param endTime
947 * End of the time range
948 * @param resolution
949 * The resolution
950 * @param monitor
951 * The progress monitor object
952 * @return The list of events for the entry
953 */
954 protected abstract List<ITimeEvent> getEventList(TimeGraphEntry entry,
955 long startTime, long endTime, long resolution,
956 IProgressMonitor monitor);
957
bec1f1ac
GB
958 /**
959 * Gets the list of links (displayed as arrows) for a trace in a given
960 * timerange. Default implementation returns an empty list.
961 *
962 * @param startTime
963 * Start of the time range
964 * @param endTime
965 * End of the time range
966 * @param resolution
967 * The resolution
968 * @param monitor
969 * The progress monitor object
970 * @return The list of link events
971 * @since 2.1
972 */
973 protected List<ILinkEvent> getLinkList(long startTime, long endTime,
974 long resolution, IProgressMonitor monitor) {
507b1336 975 return new ArrayList<>();
bec1f1ac
GB
976 }
977
978
4999a196
GB
979 /**
980 * Refresh the display
981 */
982 protected void refresh() {
983 Display.getDefault().asyncExec(new Runnable() {
984 @Override
985 public void run() {
747adf5c 986 if (fTimeGraphWrapper.isDisposed()) {
4999a196
GB
987 return;
988 }
989 ITimeGraphEntry[] entries = null;
990 synchronized (fEntryListMap) {
991 fEntryList = fEntryListMap.get(fTrace);
992 if (fEntryList == null) {
507b1336 993 fEntryList = new ArrayList<>();
4999a196
GB
994 }
995 entries = fEntryList.toArray(new ITimeGraphEntry[0]);
996 }
997 if (fEntryComparator != null) {
998 Arrays.sort(entries, fEntryComparator);
999 }
747adf5c
PT
1000 fTimeGraphWrapper.setInput(entries);
1001 fTimeGraphWrapper.getTimeGraphViewer().setTimeBounds(fStartTime, fEndTime);
4999a196 1002
0fcf3b09
PT
1003 long selectionBeginTime = fTrace == null ? 0 : fTraceManager.getSelectionBeginTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue();
1004 long selectionEndTime = fTrace == null ? 0 : fTraceManager.getSelectionEndTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue();
4999a196
GB
1005 long startTime = fTrace == null ? 0 : fTraceManager.getCurrentRange().getStartTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue();
1006 long endTime = fTrace == null ? 0 : fTraceManager.getCurrentRange().getEndTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue();
1007 startTime = Math.max(startTime, fStartTime);
1008 endTime = Math.min(endTime, fEndTime);
747adf5c
PT
1009 fTimeGraphWrapper.getTimeGraphViewer().setSelectionRange(selectionBeginTime, selectionEndTime);
1010 fTimeGraphWrapper.getTimeGraphViewer().setStartFinishTime(startTime, endTime);
4999a196 1011
747adf5c
PT
1012 if (fTimeGraphWrapper instanceof TimeGraphComboWrapper) {
1013 for (TreeColumn column : ((TimeGraphComboWrapper) fTimeGraphWrapper).getTreeViewer().getTree().getColumns()) {
1014 column.pack();
1015 }
4999a196
GB
1016 }
1017
1018 startZoomThread(startTime, endTime);
1019 }
1020 });
1021 }
1022
1023 /**
1024 * Redraw the canvas
1025 */
1026 protected void redraw() {
1027 synchronized (fSyncObj) {
1028 if (fRedrawState == State.IDLE) {
1029 fRedrawState = State.BUSY;
1030 } else {
1031 fRedrawState = State.PENDING;
1032 return;
1033 }
1034 }
1035 Display.getDefault().asyncExec(new Runnable() {
1036 @Override
1037 public void run() {
747adf5c 1038 if (fTimeGraphWrapper.isDisposed()) {
4999a196
GB
1039 return;
1040 }
747adf5c
PT
1041 fTimeGraphWrapper.redraw();
1042 fTimeGraphWrapper.update();
4999a196
GB
1043 synchronized (fSyncObj) {
1044 if (fRedrawState == State.PENDING) {
1045 fRedrawState = State.IDLE;
1046 redraw();
1047 } else {
1048 fRedrawState = State.IDLE;
1049 }
1050 }
1051 }
1052 });
1053 }
1054
1055 private void startZoomThread(long startTime, long endTime) {
1056 if (fZoomThread != null) {
1057 fZoomThread.cancel();
1058 }
1059 fZoomThread = new ZoomThread(fEntryList, startTime, endTime, getName());
1060 fZoomThread.start();
1061 }
1062
1063 private void makeActions() {
747adf5c 1064 fPreviousResourceAction = fTimeGraphWrapper.getTimeGraphViewer().getPreviousItemAction();
4999a196
GB
1065 fPreviousResourceAction.setText(getPrevText());
1066 fPreviousResourceAction.setToolTipText(getPrevTooltip());
747adf5c 1067 fNextResourceAction = fTimeGraphWrapper.getTimeGraphViewer().getNextItemAction();
4999a196
GB
1068 fNextResourceAction.setText(getNextText());
1069 fNextResourceAction.setToolTipText(getNextTooltip());
1070 }
1071
1072 private void contributeToActionBars() {
1073 IActionBars bars = getViewSite().getActionBars();
1074 fillLocalToolBar(bars.getToolBarManager());
1075 }
1076
79ec0b89
PT
1077 /**
1078 * Add actions to local tool bar manager
1079 *
1080 * @param manager the tool bar manager
1081 */
1082 protected void fillLocalToolBar(IToolBarManager manager) {
747adf5c
PT
1083 if (fTimeGraphWrapper instanceof TimeGraphComboWrapper) {
1084 if (fFilterColumns.length > 0) {
1085 manager.add(((TimeGraphComboWrapper) fTimeGraphWrapper).getShowFilterAction());
1086 }
4999a196 1087 }
747adf5c 1088 manager.add(fTimeGraphWrapper.getTimeGraphViewer().getShowLegendAction());
4999a196 1089 manager.add(new Separator());
747adf5c
PT
1090 manager.add(fTimeGraphWrapper.getTimeGraphViewer().getResetScaleAction());
1091 manager.add(fTimeGraphWrapper.getTimeGraphViewer().getPreviousEventAction());
1092 manager.add(fTimeGraphWrapper.getTimeGraphViewer().getNextEventAction());
4999a196
GB
1093 manager.add(fPreviousResourceAction);
1094 manager.add(fNextResourceAction);
747adf5c
PT
1095 manager.add(fTimeGraphWrapper.getTimeGraphViewer().getZoomInAction());
1096 manager.add(fTimeGraphWrapper.getTimeGraphViewer().getZoomOutAction());
4999a196
GB
1097 manager.add(new Separator());
1098 }
1099}
This page took 0.087304 seconds and 5 git commands to generate.