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