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 * Marc-Andre Laperle - Add time zone preference
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;
29 import org.eclipse.jface.action.IToolBarManager;
30 import org.eclipse.jface.action.Separator;
31 import org.eclipse.jface.viewers.ILabelProviderListener;
32 import org.eclipse.jface.viewers.ITableLabelProvider;
33 import org.eclipse.jface.viewers.ITreeContentProvider;
34 import org.eclipse.jface.viewers.Viewer;
35 import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfTimestamp;
36 import org.eclipse.linuxtools.tmf.core.signal.TmfRangeSynchSignal;
37 import org.eclipse.linuxtools.tmf.core.signal.TmfSignalHandler;
38 import org.eclipse.linuxtools.tmf.core.signal.TmfTimeSynchSignal;
39 import org.eclipse.linuxtools.tmf.core.signal.TmfTimestampFormatUpdateSignal;
40 import org.eclipse.linuxtools.tmf.core.signal.TmfTraceClosedSignal;
41 import org.eclipse.linuxtools.tmf.core.signal.TmfTraceOpenedSignal;
42 import org.eclipse.linuxtools.tmf.core.signal.TmfTraceSelectedSignal;
43 import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp;
44 import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimeRange;
45 import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimestamp;
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 3.0
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));
527 TmfTimestamp time = new CtfTmfTimestamp(fTimeGraphCombo.getTimeGraphViewer().getSelectedTime());
528 broadcast(new TmfRangeSynchSignal(AbstractTimeGraphView.this, range, time));
529 if (fZoomThread != null) {
530 fZoomThread.cancel();
531 }
532 startZoomThread(startTime, endTime);
533 }
534 });
535
536 fTimeGraphCombo.getTimeGraphViewer().addTimeListener(new ITimeGraphTimeListener() {
537 @Override
538 public void timeSelected(TimeGraphTimeEvent event) {
539 long time = event.getTime();
540 broadcast(new TmfTimeSynchSignal(AbstractTimeGraphView.this, new CtfTmfTimestamp(time)));
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
553 // View Action Handling
554 makeActions();
555 contributeToActionBars();
556
557 ITmfTrace trace = getActiveTrace();
558 if (trace != null) {
559 traceSelected(new TmfTraceSelectedSignal(this, trace));
560 }
561
562 // make selection available to other views
563 getSite().setSelectionProvider(fTimeGraphCombo.getTreeViewer());
564 }
565
566 @Override
567 public void setFocus() {
568 fTimeGraphCombo.setFocus();
569 }
570
571 // ------------------------------------------------------------------------
572 // Signal handlers
573 // ------------------------------------------------------------------------
574
575 /**
576 * Handler for the trace opened signal.
577 *
578 * @param signal
579 * The incoming signal
580 * @since 2.0
581 */
582 @TmfSignalHandler
583 public void traceOpened(TmfTraceOpenedSignal signal) {
584 fTrace = signal.getTrace();
585 loadTrace();
586 }
587
588 /**
589 * Handler for the trace selected signal
590 *
591 * @param signal
592 * The incoming signal
593 */
594 @TmfSignalHandler
595 public void traceSelected(final TmfTraceSelectedSignal signal) {
596 if (signal.getTrace() == fTrace) {
597 return;
598 }
599 fTrace = signal.getTrace();
600
601 loadTrace();
602 }
603
604 /**
605 * Trace is closed: clear the data structures and the view
606 *
607 * @param signal
608 * the signal received
609 */
610 @TmfSignalHandler
611 public void traceClosed(final TmfTraceClosedSignal signal) {
612 synchronized (fBuildThreadMap) {
613 BuildThread buildThread = fBuildThreadMap.remove(signal.getTrace());
614 if (buildThread != null) {
615 buildThread.cancel();
616 }
617 }
618 synchronized (fEntryListMap) {
619 fEntryListMap.remove(signal.getTrace());
620 }
621 if (signal.getTrace() == fTrace) {
622 fTrace = null;
623 fStartTime = 0;
624 fEndTime = 0;
625 if (fZoomThread != null) {
626 fZoomThread.cancel();
627 }
628 refresh();
629 }
630 }
631
632 /**
633 * Handler for the synch signal
634 *
635 * @param signal
636 * The signal that's received
637 */
638 @TmfSignalHandler
639 public void synchToTime(final TmfTimeSynchSignal signal) {
640 if (signal.getSource() == this || fTrace == null) {
641 return;
642 }
643 final long time = signal.getCurrentTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue();
644
645 Display.getDefault().asyncExec(new Runnable() {
646 @Override
647 public void run() {
648 if (fTimeGraphCombo.isDisposed()) {
649 return;
650 }
651 fTimeGraphCombo.getTimeGraphViewer().setSelectedTime(time, true);
652 startZoomThread(fTimeGraphCombo.getTimeGraphViewer().getTime0(), fTimeGraphCombo.getTimeGraphViewer().getTime1());
653
654 synchingToTime(time);
655 }
656 });
657 }
658
659 /**
660 * Handler for the range sync signal
661 *
662 * @param signal
663 * The signal that's received
664 */
665 @TmfSignalHandler
666 public void synchToRange(final TmfRangeSynchSignal signal) {
667 if (signal.getSource() == this || fTrace == null) {
668 return;
669 }
670 if (signal.getCurrentRange().getIntersection(fTrace.getTimeRange()) == null) {
671 return;
672 }
673 final long startTime = signal.getCurrentRange().getStartTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue();
674 final long endTime = signal.getCurrentRange().getEndTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue();
675 final long time = signal.getCurrentTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue();
676 Display.getDefault().asyncExec(new Runnable() {
677 @Override
678 public void run() {
679 if (fTimeGraphCombo.isDisposed()) {
680 return;
681 }
682 fTimeGraphCombo.getTimeGraphViewer().setStartFinishTime(startTime, endTime);
683 fTimeGraphCombo.getTimeGraphViewer().setSelectedTime(time, false);
684 startZoomThread(startTime, endTime);
685 }
686 });
687 }
688
689 /**
690 * @param signal the format of the timestamps was updated.
691 */
692 @TmfSignalHandler
693 public void updateTimeFormat( final TmfTimestampFormatUpdateSignal signal){
694 this.fTimeGraphCombo.refresh();
695 }
696
697 // ------------------------------------------------------------------------
698 // Internal
699 // ------------------------------------------------------------------------
700
701 private void loadTrace() {
702 synchronized (fEntryListMap) {
703 fEntryList = fEntryListMap.get(fTrace);
704 if (fEntryList == null) {
705 synchronized (fBuildThreadMap) {
706 BuildThread buildThread = new BuildThread(fTrace, this.getName());
707 fBuildThreadMap.put(fTrace, buildThread);
708 buildThread.start();
709 }
710 } else {
711 fStartTime = fTrace.getStartTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue();
712 fEndTime = fTrace.getEndTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue();
713 refresh();
714 }
715 }
716 }
717
718 /**
719 * Method called when synching to a given timestamp. Inheriting classes can
720 * perform actions here to update the view at the given timestamp.
721 *
722 * @param time
723 * The currently selected time
724 */
725 protected void synchingToTime(long time) {
726
727 }
728
729 /**
730 * Build the entries list to show in this time graph
731 *
732 * Called from the BuildThread
733 *
734 * @param trace
735 * The trace being built
736 * @param monitor
737 * The progress monitor object
738 */
739 protected abstract void buildEventList(final ITmfTrace trace, IProgressMonitor monitor);
740
741 /**
742 * Gets the list of event for an entry in a given timerange
743 *
744 * @param entry
745 * The entry to get events for
746 * @param startTime
747 * Start of the time range
748 * @param endTime
749 * End of the time range
750 * @param resolution
751 * The resolution
752 * @param monitor
753 * The progress monitor object
754 * @return The list of events for the entry
755 */
756 protected abstract List<ITimeEvent> getEventList(TimeGraphEntry entry,
757 long startTime, long endTime, long resolution,
758 IProgressMonitor monitor);
759
760 /**
761 * Refresh the display
762 */
763 protected void refresh() {
764 Display.getDefault().asyncExec(new Runnable() {
765 @Override
766 public void run() {
767 if (fTimeGraphCombo.isDisposed()) {
768 return;
769 }
770 ITimeGraphEntry[] entries = null;
771 synchronized (fEntryListMap) {
772 fEntryList = fEntryListMap.get(fTrace);
773 if (fEntryList == null) {
774 fEntryList = new ArrayList<TimeGraphEntry>();
775 }
776 entries = fEntryList.toArray(new ITimeGraphEntry[0]);
777 }
778 if (fEntryComparator != null) {
779 Arrays.sort(entries, fEntryComparator);
780 }
781 fTimeGraphCombo.setInput(entries);
782 fTimeGraphCombo.getTimeGraphViewer().setTimeBounds(fStartTime, fEndTime);
783
784 long timestamp = fTrace == null ? 0 : fTraceManager.getCurrentTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue();
785 long startTime = fTrace == null ? 0 : fTraceManager.getCurrentRange().getStartTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue();
786 long endTime = fTrace == null ? 0 : fTraceManager.getCurrentRange().getEndTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue();
787 startTime = Math.max(startTime, fStartTime);
788 endTime = Math.min(endTime, fEndTime);
789 fTimeGraphCombo.getTimeGraphViewer().setSelectedTime(timestamp, false);
790 fTimeGraphCombo.getTimeGraphViewer().setStartFinishTime(startTime, endTime);
791
792 for (TreeColumn column : fTimeGraphCombo.getTreeViewer().getTree().getColumns()) {
793 column.pack();
794 }
795
796 startZoomThread(startTime, endTime);
797 }
798 });
799 }
800
801 /**
802 * Redraw the canvas
803 */
804 protected void redraw() {
805 synchronized (fSyncObj) {
806 if (fRedrawState == State.IDLE) {
807 fRedrawState = State.BUSY;
808 } else {
809 fRedrawState = State.PENDING;
810 return;
811 }
812 }
813 Display.getDefault().asyncExec(new Runnable() {
814 @Override
815 public void run() {
816 if (fTimeGraphCombo.isDisposed()) {
817 return;
818 }
819 fTimeGraphCombo.redraw();
820 fTimeGraphCombo.update();
821 synchronized (fSyncObj) {
822 if (fRedrawState == State.PENDING) {
823 fRedrawState = State.IDLE;
824 redraw();
825 } else {
826 fRedrawState = State.IDLE;
827 }
828 }
829 }
830 });
831 }
832
833 private void startZoomThread(long startTime, long endTime) {
834 if (fZoomThread != null) {
835 fZoomThread.cancel();
836 }
837 fZoomThread = new ZoomThread(fEntryList, startTime, endTime, getName());
838 fZoomThread.start();
839 }
840
841 private void makeActions() {
842 fPreviousResourceAction = fTimeGraphCombo.getTimeGraphViewer().getPreviousItemAction();
843 fPreviousResourceAction.setText(getPrevText());
844 fPreviousResourceAction.setToolTipText(getPrevTooltip());
845 fNextResourceAction = fTimeGraphCombo.getTimeGraphViewer().getNextItemAction();
846 fNextResourceAction.setText(getNextText());
847 fNextResourceAction.setToolTipText(getNextTooltip());
848 }
849
850 private void contributeToActionBars() {
851 IActionBars bars = getViewSite().getActionBars();
852 fillLocalToolBar(bars.getToolBarManager());
853 }
854
855 private void fillLocalToolBar(IToolBarManager manager) {
856 if (fFilterColumns.length > 0) {
857 manager.add(fTimeGraphCombo.getShowFilterAction());
858 }
859 manager.add(fTimeGraphCombo.getTimeGraphViewer().getShowLegendAction());
860 manager.add(new Separator());
861 manager.add(fTimeGraphCombo.getTimeGraphViewer().getResetScaleAction());
862 manager.add(fTimeGraphCombo.getTimeGraphViewer().getPreviousEventAction());
863 manager.add(fTimeGraphCombo.getTimeGraphViewer().getNextEventAction());
864 manager.add(fPreviousResourceAction);
865 manager.add(fNextResourceAction);
866 manager.add(fTimeGraphCombo.getTimeGraphViewer().getZoomInAction());
867 manager.add(fTimeGraphCombo.getTimeGraphViewer().getZoomOutAction());
868 manager.add(new Separator());
869 }
870 }
This page took 0.051642 seconds and 6 git commands to generate.