tmf: Add the view ID to some JUL log statements of time graph views
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.ui / src / org / eclipse / tracecompass / tmf / ui / views / timegraph / AbstractTimeGraphView.java
1 /*******************************************************************************
2 * Copyright (c) 2012, 2016 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 * Geneviève Bastien - Add event links between entries
15 *******************************************************************************/
16
17 package org.eclipse.tracecompass.tmf.ui.views.timegraph;
18
19 import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull;
20
21 import java.util.ArrayList;
22 import java.util.Collections;
23 import java.util.Comparator;
24 import java.util.HashMap;
25 import java.util.LinkedHashSet;
26 import java.util.List;
27 import java.util.Map;
28 import java.util.Set;
29 import java.util.concurrent.CopyOnWriteArrayList;
30 import java.util.concurrent.atomic.AtomicInteger;
31 import java.util.logging.Logger;
32 import java.util.regex.Matcher;
33 import java.util.regex.Pattern;
34
35 import org.eclipse.core.resources.IFile;
36 import org.eclipse.core.resources.IMarker;
37 import org.eclipse.core.resources.IMarkerDelta;
38 import org.eclipse.core.resources.IResource;
39 import org.eclipse.core.resources.IResourceChangeEvent;
40 import org.eclipse.core.resources.IResourceChangeListener;
41 import org.eclipse.core.resources.IWorkspaceRunnable;
42 import org.eclipse.core.resources.ResourcesPlugin;
43 import org.eclipse.core.runtime.CoreException;
44 import org.eclipse.core.runtime.IProgressMonitor;
45 import org.eclipse.core.runtime.IStatus;
46 import org.eclipse.core.runtime.NullProgressMonitor;
47 import org.eclipse.core.runtime.Status;
48 import org.eclipse.core.runtime.jobs.Job;
49 import org.eclipse.jdt.annotation.NonNull;
50 import org.eclipse.jdt.annotation.Nullable;
51 import org.eclipse.jface.action.Action;
52 import org.eclipse.jface.action.GroupMarker;
53 import org.eclipse.jface.action.IAction;
54 import org.eclipse.jface.action.IMenuListener;
55 import org.eclipse.jface.action.IMenuManager;
56 import org.eclipse.jface.action.IStatusLineManager;
57 import org.eclipse.jface.action.IToolBarManager;
58 import org.eclipse.jface.action.MenuManager;
59 import org.eclipse.jface.action.Separator;
60 import org.eclipse.jface.commands.ActionHandler;
61 import org.eclipse.jface.viewers.AbstractTreeViewer;
62 import org.eclipse.jface.viewers.ILabelProvider;
63 import org.eclipse.jface.viewers.ILabelProviderListener;
64 import org.eclipse.jface.viewers.ISelectionProvider;
65 import org.eclipse.jface.viewers.ITableLabelProvider;
66 import org.eclipse.jface.viewers.ITreeContentProvider;
67 import org.eclipse.jface.viewers.TreeSelection;
68 import org.eclipse.jface.viewers.TreeViewer;
69 import org.eclipse.jface.viewers.ViewerFilter;
70 import org.eclipse.osgi.util.NLS;
71 import org.eclipse.swt.SWT;
72 import org.eclipse.swt.events.MenuDetectEvent;
73 import org.eclipse.swt.events.MenuDetectListener;
74 import org.eclipse.swt.events.SelectionAdapter;
75 import org.eclipse.swt.events.SelectionEvent;
76 import org.eclipse.swt.graphics.Image;
77 import org.eclipse.swt.graphics.Point;
78 import org.eclipse.swt.graphics.RGBA;
79 import org.eclipse.swt.widgets.Composite;
80 import org.eclipse.swt.widgets.Display;
81 import org.eclipse.swt.widgets.Menu;
82 import org.eclipse.swt.widgets.Shell;
83 import org.eclipse.swt.widgets.Tree;
84 import org.eclipse.swt.widgets.TreeColumn;
85 import org.eclipse.tracecompass.common.core.NonNullUtils;
86 import org.eclipse.tracecompass.common.core.log.TraceCompassLog;
87 import org.eclipse.tracecompass.internal.tmf.ui.Activator;
88 import org.eclipse.tracecompass.tmf.core.resources.ITmfMarker;
89 import org.eclipse.tracecompass.tmf.core.signal.TmfMarkerEventSourceUpdatedSignal;
90 import org.eclipse.tracecompass.tmf.core.signal.TmfSelectionRangeUpdatedSignal;
91 import org.eclipse.tracecompass.tmf.core.signal.TmfSignalHandler;
92 import org.eclipse.tracecompass.tmf.core.signal.TmfTimestampFormatUpdateSignal;
93 import org.eclipse.tracecompass.tmf.core.signal.TmfTraceClosedSignal;
94 import org.eclipse.tracecompass.tmf.core.signal.TmfTraceOpenedSignal;
95 import org.eclipse.tracecompass.tmf.core.signal.TmfTraceSelectedSignal;
96 import org.eclipse.tracecompass.tmf.core.signal.TmfWindowRangeUpdatedSignal;
97 import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp;
98 import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange;
99 import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestamp;
100 import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
101 import org.eclipse.tracecompass.tmf.core.trace.TmfTraceAdapterManager;
102 import org.eclipse.tracecompass.tmf.core.trace.TmfTraceContext;
103 import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager;
104 import org.eclipse.tracecompass.tmf.ui.TmfUiRefreshHandler;
105 import org.eclipse.tracecompass.tmf.ui.signal.TmfTimeViewAlignmentInfo;
106 import org.eclipse.tracecompass.tmf.ui.views.ITmfTimeAligned;
107 import org.eclipse.tracecompass.tmf.ui.views.TmfView;
108 import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.ITimeGraphBookmarkListener;
109 import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.ITimeGraphContentProvider;
110 import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.ITimeGraphPresentationProvider2;
111 import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.ITimeGraphRangeListener;
112 import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.ITimeGraphSelectionListener;
113 import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.ITimeGraphTimeListener;
114 import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.TimeGraphBookmarkEvent;
115 import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.TimeGraphCombo;
116 import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.TimeGraphContentProvider;
117 import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.TimeGraphPresentationProvider;
118 import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.TimeGraphRangeUpdateEvent;
119 import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.TimeGraphTimeEvent;
120 import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.TimeGraphViewer;
121 import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ILinkEvent;
122 import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.IMarkerEvent;
123 import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.IMarkerEventSource;
124 import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeEvent;
125 import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeGraphEntry;
126 import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.MarkerEvent;
127 import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.TimeGraphEntry;
128 import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.TimeGraphControl;
129 import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.Utils.TimeFormat;
130 import org.eclipse.ui.IActionBars;
131 import org.eclipse.ui.IPartListener;
132 import org.eclipse.ui.IWorkbenchActionConstants;
133 import org.eclipse.ui.IWorkbenchPart;
134 import org.eclipse.ui.PlatformUI;
135 import org.eclipse.ui.actions.ActionFactory;
136 import org.eclipse.ui.handlers.IHandlerActivation;
137 import org.eclipse.ui.handlers.IHandlerService;
138
139 /**
140 * An abstract view all time graph views can inherit
141 *
142 * This view contains either a time graph viewer, or a time graph combo which is
143 * divided between a tree viewer on the left and a time graph viewer on the right.
144 */
145 public abstract class AbstractTimeGraphView extends TmfView implements ITmfTimeAligned, IResourceChangeListener {
146
147 /** Constant indicating that all levels of the time graph should be expanded */
148 protected static final int ALL_LEVELS = AbstractTreeViewer.ALL_LEVELS;
149
150 private static final Pattern RGBA_PATTERN = Pattern.compile("RGBA \\{(\\d+), (\\d+), (\\d+), (\\d+)\\}"); //$NON-NLS-1$
151
152 private static final Logger LOGGER = TraceCompassLog.getLogger(AbstractTimeGraphView.class);
153 private static final String LOG_STRING_WITH_PARAM = "[TimeGraphView:%s] viewId=%s, %s"; //$NON-NLS-1$
154 private static final String LOG_STRING = "[TimeGraphView:%s] viewId=%s"; //$NON-NLS-1$
155
156 /**
157 * Redraw state enum
158 */
159 private enum State {
160 IDLE, BUSY, PENDING
161 }
162
163 // ------------------------------------------------------------------------
164 // Fields
165 // ------------------------------------------------------------------------
166
167 /** The timegraph wrapper */
168 private ITimeGraphWrapper fTimeGraphWrapper;
169
170 private AtomicInteger fDirty = new AtomicInteger();
171
172 private final Object fZoomThreadResultLock = new Object();
173
174 /** The selected trace */
175 private ITmfTrace fTrace;
176
177 /** The selected trace editor file*/
178 private IFile fEditorFile;
179
180 /** The timegraph entry list */
181 private List<TimeGraphEntry> fEntryList;
182
183 /** The trace to entry list hash map */
184 private final Map<ITmfTrace, List<TimeGraphEntry>> fEntryListMap = new HashMap<>();
185
186 /** The trace to filters hash map */
187 private final Map<ITmfTrace, @NonNull ViewerFilter[]> fFiltersMap = new HashMap<>();
188
189 /** The trace to view context hash map */
190 private final Map<ITmfTrace, ViewContext> fViewContext = new HashMap<>();
191
192 /** The trace to marker event sources hash map */
193 private final Map<ITmfTrace, List<IMarkerEventSource>> fMarkerEventSourcesMap = new HashMap<>();
194
195 /** The trace to build thread hash map */
196 private final Map<ITmfTrace, Job> fBuildJobMap = new HashMap<>();
197
198 /** The start time */
199 private long fStartTime = SWT.DEFAULT;
200
201 /** The end time */
202 private long fEndTime = SWT.DEFAULT;
203
204 /** The display width */
205 private final int fDisplayWidth;
206
207 /** The zoom thread */
208 private ZoomThread fZoomThread;
209
210 /** The next resource action */
211 private Action fNextResourceAction;
212
213 /** The previous resource action */
214 private Action fPreviousResourceAction;
215
216 /** A comparator class */
217 private Comparator<ITimeGraphEntry> fEntryComparator = null;
218
219 /** The redraw state used to prevent unnecessary queuing of display runnables */
220 private State fRedrawState = State.IDLE;
221
222 /** The redraw synchronization object */
223 private final Object fSyncObj = new Object();
224
225 /** The presentation provider for this view */
226 private final TimeGraphPresentationProvider fPresentation;
227
228 /** The tree column label array, or null if combo is not used */
229 private String[] fColumns;
230
231 private Comparator<ITimeGraphEntry>[] fColumnComparators;
232
233 /** The tree label provider, or null if combo is not used */
234 private TreeLabelProvider fLabelProvider = null;
235
236 /** The time graph content provider */
237 private @NonNull ITimeGraphContentProvider fTimeGraphContentProvider = new TimeGraphContentProvider();
238
239 /** The relative weight of the sash, ignored if combo is not used */
240 private int[] fWeight = { 1, 3 };
241
242 /** The filter column label array, or null if filter is not used */
243 private String[] fFilterColumns;
244
245 /** The pack done flag */
246 private boolean fPackDone = false;
247
248 /** The filter content provider, or null if filter is not used */
249 private ITreeContentProvider fFilterContentProvider;
250
251 /** The filter label provider, or null if filter is not used */
252 private TreeLabelProvider fFilterLabelProvider;
253
254 private int fAutoExpandLevel = ALL_LEVELS;
255
256 /** The default column index for sorting */
257 private int fInitialSortColumn = 0;
258
259 /** The default column index for sorting */
260 private int fCurrentSortColumn = 0;
261
262 /** The current sort direction */
263 private int fSortDirection = SWT.DOWN;
264
265 /** Flag to indicate to reveal selection */
266 private volatile boolean fIsRevealSelection = false;
267
268 /**
269 * Menu Manager for context-sensitive menu for time graph entries.
270 * This will be used on the tree viewer in case of the time graph combo
271 * or the on the namespace in case of a single time graph viewer.
272 */
273 private final @NonNull MenuManager fEntryMenuManager = new MenuManager();
274
275 /** Time Graph View part listener */
276 private TimeGraphPartListener fPartListener;
277
278 /** Action for the find command. There is only one for all Time Graph views */
279 private static final ShowFindDialogAction FIND_ACTION = new ShowFindDialogAction();
280
281 /** The find action handler */
282 private ActionHandler fFindActionHandler;
283
284 /** The find handler activation */
285 private IHandlerActivation fFindHandlerActivation;
286
287 /** The find target to use */
288 private final FindTarget fFindTarget;
289
290 // ------------------------------------------------------------------------
291 // Classes
292 // ------------------------------------------------------------------------
293
294 private interface ITimeGraphWrapper {
295
296 void setTimeGraphContentProvider(ITimeGraphContentProvider timeGraphContentProvider);
297
298 void setTimeGraphPresentationProvider(TimeGraphPresentationProvider timeGraphPresentationProvider);
299
300 TimeGraphViewer getTimeGraphViewer();
301
302 void addSelectionListener(ITimeGraphSelectionListener listener);
303
304 ISelectionProvider getSelectionProvider();
305
306 void setFocus();
307
308 boolean isDisposed();
309
310 void refresh();
311
312 void setInput(Object input);
313
314 Object getInput();
315
316 void setFilters(@NonNull ViewerFilter[] filters);
317
318 @NonNull ViewerFilter[] getFilters();
319
320 void redraw();
321
322 void update();
323
324 void setAutoExpandLevel(int level);
325
326 boolean getExpandedState(ITimeGraphEntry entry);
327
328 void setExpandedState(ITimeGraphEntry entry, boolean expanded);
329
330 void setFilterColumns(String[] columnNames);
331
332 void setFilterContentProvider(ITreeContentProvider contentProvider);
333
334 void setFilterLabelProvider(ITableLabelProvider labelProvider);
335
336 IAction getShowFilterDialogAction();
337
338 void performAlign(int offset, int width);
339
340 TmfTimeViewAlignmentInfo getTimeViewAlignmentInfo();
341
342 int getAvailableWidth(int requestedOffset);
343
344 ITimeGraphEntry getSelection();
345
346 void setSelection(ITimeGraphEntry selection);
347
348 void selectAndReveal(@NonNull ITimeGraphEntry selection);
349
350 }
351
352 private class TimeGraphViewerWrapper implements ITimeGraphWrapper {
353 private TimeGraphViewer viewer;
354
355 private TimeGraphViewerWrapper(Composite parent, int style) {
356 viewer = new TimeGraphViewer(parent, style);
357 }
358
359 @Override
360 public void setTimeGraphContentProvider(ITimeGraphContentProvider timeGraphContentProvider) {
361 viewer.setTimeGraphContentProvider(timeGraphContentProvider);
362 }
363
364 @Override
365 public void setTimeGraphPresentationProvider(TimeGraphPresentationProvider timeGraphPresentationProvider) {
366 viewer.setTimeGraphProvider(timeGraphPresentationProvider);
367 }
368
369 @Override
370 public TimeGraphViewer getTimeGraphViewer() {
371 return viewer;
372 }
373
374 @Override
375 public void addSelectionListener(ITimeGraphSelectionListener listener) {
376 viewer.addSelectionListener(listener);
377 }
378
379 @Override
380 public ISelectionProvider getSelectionProvider() {
381 return viewer.getSelectionProvider();
382 }
383
384 @Override
385 public void setFocus() {
386 viewer.setFocus();
387 }
388
389 @Override
390 public boolean isDisposed() {
391 return viewer.getControl().isDisposed();
392 }
393
394 @Override
395 public void setInput(Object input) {
396 viewer.setInput(input);
397 }
398
399 @Override
400 public Object getInput() {
401 return viewer.getInput();
402 }
403
404 @Override
405 public void setFilterColumns(String[] columnNames) {
406 viewer.setFilterColumns(columnNames);
407 }
408
409 @Override
410 public void setFilterContentProvider(ITreeContentProvider contentProvider) {
411 viewer.setFilterContentProvider(contentProvider);
412 }
413
414 @Override
415 public void setFilterLabelProvider(ITableLabelProvider labelProvider) {
416 viewer.setFilterLabelProvider(labelProvider);
417 }
418
419 @Override
420 public void setFilters(@NonNull ViewerFilter[] filters) {
421 viewer.setFilters(filters);
422 }
423
424 @Override
425 public @NonNull ViewerFilter[] getFilters() {
426 return viewer.getFilters();
427 }
428
429 @Override
430 public IAction getShowFilterDialogAction() {
431 return viewer.getShowFilterDialogAction();
432 }
433
434 @Override
435 public void refresh() {
436 viewer.refresh();
437 }
438
439 @Override
440 public void redraw() {
441 viewer.getControl().redraw();
442 }
443
444 @Override
445 public void update() {
446 viewer.getControl().update();
447 }
448
449 @Override
450 public void setAutoExpandLevel(int level) {
451 viewer.setAutoExpandLevel(level);
452 }
453
454 @Override
455 public boolean getExpandedState(ITimeGraphEntry entry) {
456 return viewer.getExpandedState(entry);
457 }
458
459 @Override
460 public void setExpandedState(ITimeGraphEntry entry, boolean expanded) {
461 viewer.setExpandedState(entry, expanded);
462 }
463
464 @Override
465 public void performAlign(int offset, int width) {
466 viewer.performAlign(offset, width);
467 }
468
469 @Override
470 public TmfTimeViewAlignmentInfo getTimeViewAlignmentInfo() {
471 return viewer.getTimeViewAlignmentInfo();
472 }
473
474 @Override
475 public int getAvailableWidth(int requestedOffset) {
476 return viewer.getAvailableWidth(requestedOffset);
477 }
478
479 @Override
480 public ITimeGraphEntry getSelection() {
481 return viewer.getSelection();
482 }
483
484 @Override
485 public void setSelection(ITimeGraphEntry selection) {
486 viewer.setSelection(selection);
487 }
488
489 @Override
490 public void selectAndReveal(@NonNull ITimeGraphEntry selection) {
491 viewer.selectAndReveal(selection);
492 }
493 }
494
495 private class TimeGraphComboWrapper implements ITimeGraphWrapper {
496 private TimeGraphCombo combo;
497
498 private TimeGraphComboWrapper(Composite parent, int style) {
499 combo = new TimeGraphCombo(parent, style, fWeight);
500 }
501
502 @Override
503 public void setTimeGraphContentProvider(ITimeGraphContentProvider timeGraphContentProvider) {
504 combo.setTimeGraphContentProvider(timeGraphContentProvider);
505 }
506
507 @Override
508 public void setTimeGraphPresentationProvider(TimeGraphPresentationProvider timeGraphPresentationProvider) {
509 combo.setTimeGraphProvider(timeGraphPresentationProvider);
510 }
511
512 @Override
513 public TimeGraphViewer getTimeGraphViewer() {
514 return combo.getTimeGraphViewer();
515 }
516
517 @Override
518 public void addSelectionListener(ITimeGraphSelectionListener listener) {
519 combo.addSelectionListener(listener);
520 }
521
522 @Override
523 public ISelectionProvider getSelectionProvider() {
524 return combo.getTreeViewer();
525 }
526
527 @Override
528 public void setFocus() {
529 combo.setFocus();
530 }
531
532 @Override
533 public boolean isDisposed() {
534 return combo.isDisposed();
535 }
536
537 @Override
538 public void setInput(Object input) {
539 combo.setInput(input);
540 }
541
542 @Override
543 public Object getInput() {
544 return combo.getInput();
545 }
546
547 @Override
548 public void setFilterColumns(String[] columnNames) {
549 combo.setFilterColumns(columnNames);
550 }
551
552 @Override
553 public void setFilterContentProvider(ITreeContentProvider contentProvider) {
554 combo.setFilterContentProvider(contentProvider);
555 }
556
557 @Override
558 public void setFilterLabelProvider(ITableLabelProvider labelProvider) {
559 combo.setFilterLabelProvider(labelProvider);
560 }
561
562 @Override
563 public void setFilters(@NonNull ViewerFilter[] filters) {
564 combo.setFilters(filters);
565 }
566
567 @Override
568 public @NonNull ViewerFilter[] getFilters() {
569 return combo.getFilters();
570 }
571
572 @Override
573 public IAction getShowFilterDialogAction() {
574 return combo.getShowFilterDialogAction();
575 }
576
577 @Override
578 public void refresh() {
579 combo.refresh();
580 }
581
582 @Override
583 public void redraw() {
584 combo.redraw();
585 }
586
587 @Override
588 public void update() {
589 combo.update();
590 }
591
592 @Override
593 public void setAutoExpandLevel(int level) {
594 combo.setAutoExpandLevel(level);
595 }
596
597 @Override
598 public boolean getExpandedState(ITimeGraphEntry entry) {
599 return combo.getExpandedState(entry);
600 }
601
602 @Override
603 public void setExpandedState(ITimeGraphEntry entry, boolean expanded) {
604 combo.setExpandedState(entry, expanded);
605 }
606
607 TimeGraphCombo getTimeGraphCombo() {
608 return combo;
609 }
610
611 TreeViewer getTreeViewer() {
612 return combo.getTreeViewer();
613 }
614
615 @Override
616 public void performAlign(int offset, int width) {
617 combo.performAlign(offset, width);
618 }
619
620 @Override
621 public TmfTimeViewAlignmentInfo getTimeViewAlignmentInfo() {
622 return combo.getTimeViewAlignmentInfo();
623 }
624
625 @Override
626 public int getAvailableWidth(int requestedOffset) {
627 return combo.getAvailableWidth(requestedOffset);
628 }
629
630 @Override
631 public ITimeGraphEntry getSelection() {
632 return combo.getTimeGraphViewer().getSelection();
633 }
634
635 @Override
636 public void setSelection(ITimeGraphEntry selection) {
637 combo.setSelection(selection);
638 }
639
640 @Override
641 public void selectAndReveal(@NonNull ITimeGraphEntry selection) {
642 combo.selectAndReveal(selection);
643 }
644 }
645
646 /**
647 * Base class to provide the labels for the tree viewer. Views extending
648 * this class typically need to override the getColumnText method if they
649 * have more than one column to display
650 */
651 protected static class TreeLabelProvider implements ITableLabelProvider, ILabelProvider {
652
653 @Override
654 public void addListener(ILabelProviderListener listener) {
655 }
656
657 @Override
658 public void dispose() {
659 }
660
661 @Override
662 public boolean isLabelProperty(Object element, String property) {
663 return false;
664 }
665
666 @Override
667 public void removeListener(ILabelProviderListener listener) {
668 }
669
670 @Override
671 public Image getColumnImage(Object element, int columnIndex) {
672 return null;
673 }
674
675 @Override
676 public String getColumnText(Object element, int columnIndex) {
677 TimeGraphEntry entry = (TimeGraphEntry) element;
678 if (columnIndex == 0) {
679 return entry.getName();
680 }
681 return new String();
682 }
683
684 @Override
685 public Image getImage(Object element) {
686 return null;
687 }
688
689 @Override
690 public String getText(Object element) {
691 TimeGraphEntry entry = (TimeGraphEntry) element;
692 return entry.getName();
693 }
694
695 }
696
697 // TODO: This can implement ICoreRunnable once support for Eclipse 4.5. is not necessary anymore.
698 private class BuildRunnable {
699 private final @NonNull ITmfTrace fBuildTrace;
700 private final @NonNull ITmfTrace fParentTrace;
701
702 public BuildRunnable(final @NonNull ITmfTrace trace, final @NonNull ITmfTrace parentTrace) {
703 fBuildTrace = trace;
704 fParentTrace = parentTrace;
705 }
706
707 public void run(IProgressMonitor monitor) {
708 LOGGER.info(() -> getLogMessage("BuildThreadStart", "trace=" + fBuildTrace.getName())); //$NON-NLS-1$ //$NON-NLS-2$
709
710 buildEntryList(fBuildTrace, fParentTrace, NonNullUtils.checkNotNull(monitor));
711 synchronized (fBuildJobMap) {
712 fBuildJobMap.remove(fBuildTrace);
713 }
714
715 LOGGER.info(() -> getLogMessage("BuildThreadEnd", null)); //$NON-NLS-1$
716 }
717 }
718
719 /**
720 * Zoom thread
721 * @since 1.1
722 */
723 protected abstract class ZoomThread extends Thread {
724 private final long fZoomStartTime;
725 private final long fZoomEndTime;
726 private final long fResolution;
727 private final @NonNull IProgressMonitor fMonitor;
728
729 /**
730 * Constructor
731 *
732 * @param startTime
733 * the start time
734 * @param endTime
735 * the end time
736 * @param resolution
737 * the resolution
738 */
739 public ZoomThread(long startTime, long endTime, long resolution) {
740 super(AbstractTimeGraphView.this.getName() + " zoom"); //$NON-NLS-1$
741 fZoomStartTime = startTime;
742 fZoomEndTime = endTime;
743 fResolution = resolution;
744 fMonitor = new NullProgressMonitor();
745 }
746
747 /**
748 * @return the zoom start time
749 */
750 public long getZoomStartTime() {
751 return fZoomStartTime;
752 }
753
754 /**
755 * @return the zoom end time
756 */
757 public long getZoomEndTime() {
758 return fZoomEndTime;
759 }
760
761 /**
762 * @return the resolution
763 */
764 public long getResolution() {
765 return fResolution;
766 }
767
768 /**
769 * @return the monitor
770 */
771 public @NonNull IProgressMonitor getMonitor() {
772 return fMonitor;
773 }
774
775 /**
776 * Cancel the zoom thread
777 */
778 public void cancel() {
779 fMonitor.setCanceled(true);
780 }
781
782 @Override
783 public final void run() {
784 LOGGER.info(() -> getLogMessage("ZoomThreadStart", "start=" + fZoomStartTime + ", end=" + fZoomEndTime)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
785
786 doRun();
787 fDirty.decrementAndGet();
788
789 LOGGER.info(() -> getLogMessage("ZoomThreadEnd", null)); //$NON-NLS-1$
790 }
791
792 /**
793 * Applies the results of the ZoomThread calculations.
794 *
795 * Note: This method makes sure that only the results of the last
796 * created ZoomThread are applied.
797 *
798 * @param runnable
799 * the code to run in order to apply the results
800 * @since 2.0
801 */
802 protected void applyResults(Runnable runnable) {
803 synchronized (fZoomThreadResultLock) {
804 if (this == fZoomThread) {
805 runnable.run();
806 }
807 }
808 }
809
810 /**
811 * Run the zoom operation.
812 * @since 2.0
813 */
814 public abstract void doRun();
815 }
816
817 private class ZoomThreadByEntry extends ZoomThread {
818 private final @NonNull List<TimeGraphEntry> fZoomEntryList;
819
820 public ZoomThreadByEntry(@NonNull List<TimeGraphEntry> entryList, long startTime, long endTime, long resolution) {
821 super(startTime, endTime, resolution);
822 fZoomEntryList = entryList;
823 }
824
825 @Override
826 public void doRun() {
827 LOGGER.config(() -> getLogMessage("ZoomThreadGettingStates", null)); //$NON-NLS-1$
828
829 for (TimeGraphEntry entry : fZoomEntryList) {
830 if (getMonitor().isCanceled()) {
831 LOGGER.info(() -> getLogMessage("ZoomThreadCanceled", null)); //$NON-NLS-1$
832 return;
833 }
834 if (entry == null) {
835 break;
836 }
837 zoom(entry, getMonitor());
838 }
839 /* Refresh the arrows when zooming */
840 LOGGER.config(() -> getLogMessage("ZoomThreadGettingLinks", null)); //$NON-NLS-1$
841 List<ILinkEvent> events = getLinkList(getZoomStartTime(), getZoomEndTime(), getResolution(), getMonitor());
842
843 /* Refresh the view-specific markers when zooming */
844 LOGGER.config(() -> getLogMessage("ZoomThreadGettingMarkers", null)); //$NON-NLS-1$
845 List<IMarkerEvent> markers = new ArrayList<>(getViewMarkerList(getZoomStartTime(), getZoomEndTime(), getResolution(), getMonitor()));
846 /* Refresh the trace-specific markers when zooming */
847 markers.addAll(getTraceMarkerList(getZoomStartTime(), getZoomEndTime(), getResolution(), getMonitor()));
848 applyResults(() -> {
849 if (events != null) {
850 fTimeGraphWrapper.getTimeGraphViewer().setLinks(events);
851 }
852 fTimeGraphWrapper.getTimeGraphViewer().setMarkerCategories(getMarkerCategories());
853 fTimeGraphWrapper.getTimeGraphViewer().setMarkers(markers);
854 redraw();
855 });
856 }
857
858 private void zoom(@NonNull TimeGraphEntry entry, @NonNull IProgressMonitor monitor) {
859 if (getZoomStartTime() <= fStartTime && getZoomEndTime() >= fEndTime) {
860 applyResults(() -> {
861 entry.setZoomedEventList(null);
862 });
863 } else {
864 List<ITimeEvent> zoomedEventList = getEventList(entry, getZoomStartTime(), getZoomEndTime(), getResolution(), monitor);
865 if (zoomedEventList != null) {
866 applyResults(() -> {
867 entry.setZoomedEventList(zoomedEventList);
868 });
869 }
870 }
871 redraw();
872 for (TimeGraphEntry child : entry.getChildren()) {
873 if (monitor.isCanceled()) {
874 return;
875 }
876 zoom(child, monitor);
877 }
878 }
879
880 }
881
882 // ------------------------------------------------------------------------
883 // Constructors
884 // ------------------------------------------------------------------------
885
886 /**
887 * Constructs a time graph view that contains either a time graph viewer or
888 * a time graph combo.
889 *
890 * By default, the view uses a time graph viewer. To use a time graph combo,
891 * the subclass constructor must call {@link #setTreeColumns(String[])} and
892 * {@link #setTreeLabelProvider(TreeLabelProvider)}.
893 *
894 * @param id
895 * The id of the view
896 * @param pres
897 * The presentation provider
898 */
899 public AbstractTimeGraphView(String id, TimeGraphPresentationProvider pres) {
900 super(id);
901 fPresentation = pres;
902 fDisplayWidth = Display.getDefault().getBounds().width;
903 fFindTarget = new FindTarget();
904 }
905
906 // ------------------------------------------------------------------------
907 // Getters and setters
908 // ------------------------------------------------------------------------
909
910 /**
911 * Getter for the time graph combo
912 *
913 * @return The time graph combo, or null if combo is not used
914 */
915 protected TimeGraphCombo getTimeGraphCombo() {
916 if (fTimeGraphWrapper instanceof TimeGraphComboWrapper) {
917 return ((TimeGraphComboWrapper) fTimeGraphWrapper).getTimeGraphCombo();
918 }
919 return null;
920 }
921
922 /**
923 * Getter for the time graph viewer
924 *
925 * @return The time graph viewer
926 */
927 protected TimeGraphViewer getTimeGraphViewer() {
928 return fTimeGraphWrapper.getTimeGraphViewer();
929 }
930
931 /**
932 * Getter for the presentation provider
933 *
934 * @return The time graph presentation provider
935 */
936 protected ITimeGraphPresentationProvider2 getPresentationProvider() {
937 return fPresentation;
938 }
939
940 /**
941 * Sets the tree column labels.
942 * <p>
943 * This should be called from the constructor.
944 *
945 * @param columns
946 * The array of tree column labels
947 */
948 protected void setTreeColumns(final String[] columns) {
949 setTreeColumns(columns, null, 0);
950 }
951
952 /**
953 * Sets the tree column labels.
954 * <p>
955 * This should be called from the constructor.
956 *
957 * @param columns
958 * The array of tree column labels
959 * @param comparators
960 * An array of column comparators for sorting of columns when
961 * clicking on column header
962 * @param initialSortColumn
963 * Index of column to sort initially
964 * @since 2.0
965 */
966 protected void setTreeColumns(final String[] columns, final Comparator<ITimeGraphEntry>[] comparators, int initialSortColumn) {
967 checkPartNotCreated();
968 fColumns = columns;
969 fColumnComparators = comparators;
970 fInitialSortColumn = initialSortColumn;
971 }
972
973 /**
974 * Sets the tree label provider.
975 * <p>
976 * This should be called from the constructor.
977 *
978 * @param tlp
979 * The tree label provider
980 */
981 protected void setTreeLabelProvider(final TreeLabelProvider tlp) {
982 checkPartNotCreated();
983 fLabelProvider = tlp;
984 }
985
986 /**
987 * Sets the time graph content provider.
988 * <p>
989 * This should be called from the constructor.
990 *
991 * @param tgcp
992 * The time graph content provider
993 * @since 1.0
994 */
995 protected void setTimeGraphContentProvider(final @NonNull ITimeGraphContentProvider tgcp) {
996 checkPartNotCreated();
997 fTimeGraphContentProvider = tgcp;
998 }
999
1000 /**
1001 * Sets the relative weight of each part of the time graph combo.
1002 * <p>
1003 * This should be called from the constructor.
1004 *
1005 * @param weights
1006 * The array (length 2) of relative weights of each part of the combo
1007 */
1008 protected void setWeight(final int[] weights) {
1009 checkPartNotCreated();
1010 fWeight = weights;
1011 }
1012
1013 /**
1014 * Sets the filter column labels.
1015 * <p>
1016 * This should be called from the constructor.
1017 *
1018 * @param filterColumns
1019 * The array of filter column labels
1020 */
1021 protected void setFilterColumns(final String[] filterColumns) {
1022 checkPartNotCreated();
1023 fFilterColumns = filterColumns;
1024 }
1025
1026 /**
1027 * Sets the filter content provider.
1028 * <p>
1029 * This should be called from the constructor.
1030 *
1031 * @param contentProvider
1032 * The filter content provider
1033 * @since 1.2
1034 */
1035 protected void setFilterContentProvider(final ITreeContentProvider contentProvider) {
1036 checkPartNotCreated();
1037 fFilterContentProvider = contentProvider;
1038 }
1039
1040 /**
1041 * Sets the filter label provider.
1042 * <p>
1043 * This should be called from the constructor.
1044 *
1045 * @param labelProvider
1046 * The filter label provider
1047 */
1048 protected void setFilterLabelProvider(final TreeLabelProvider labelProvider) {
1049 checkPartNotCreated();
1050 fFilterLabelProvider = labelProvider;
1051 }
1052
1053 private void checkPartNotCreated() {
1054 if (getParentComposite() != null) {
1055 throw new IllegalStateException("This method must be called before createPartControl."); //$NON-NLS-1$
1056 }
1057 }
1058
1059 /**
1060 * Gets the display width
1061 *
1062 * @return the display width
1063 */
1064 protected int getDisplayWidth() {
1065 return fDisplayWidth;
1066 }
1067
1068 /**
1069 * Gets the comparator for the entries
1070 *
1071 * @return The entry comparator
1072 */
1073 protected Comparator<ITimeGraphEntry> getEntryComparator() {
1074 return fEntryComparator;
1075 }
1076
1077 /**
1078 * Sets the comparator class for the entries.
1079 * <p>
1080 * This comparator will apply recursively to entries that implement
1081 * {@link TimeGraphEntry#sortChildren(Comparator)}.
1082 *
1083 * @param comparator
1084 * A comparator object
1085 */
1086 protected void setEntryComparator(final Comparator<ITimeGraphEntry> comparator) {
1087 fEntryComparator = comparator;
1088 }
1089
1090 /**
1091 * Gets the trace displayed in the view
1092 *
1093 * @return The trace
1094 */
1095 protected ITmfTrace getTrace() {
1096 return fTrace;
1097 }
1098
1099 /**
1100 * Gets the start time
1101 *
1102 * @return The start time
1103 */
1104 protected long getStartTime() {
1105 return fStartTime;
1106 }
1107
1108 /**
1109 * Sets the start time
1110 *
1111 * @param time
1112 * The start time
1113 */
1114 protected void setStartTime(long time) {
1115 fStartTime = time;
1116 }
1117
1118 /**
1119 * Gets the end time
1120 *
1121 * @return The end time
1122 */
1123 protected long getEndTime() {
1124 return fEndTime;
1125 }
1126
1127 /**
1128 * Sets the end time
1129 *
1130 * @param time
1131 * The end time
1132 */
1133 protected void setEndTime(long time) {
1134 fEndTime = time;
1135 }
1136
1137 /**
1138 * Sets the auto-expand level to be used for the input of the view. The
1139 * value 0 means that there is no auto-expand; 1 means that top-level
1140 * elements are expanded, but not their children; 2 means that top-level
1141 * elements are expanded, and their children, but not grand-children; and so
1142 * on.
1143 * <p>
1144 * The value {@link #ALL_LEVELS} means that all subtrees should be expanded.
1145 * </p>
1146 *
1147 * @param level
1148 * non-negative level, or <code>ALL_LEVELS</code> to expand all
1149 * levels of the tree
1150 */
1151 protected void setAutoExpandLevel(int level) {
1152 fAutoExpandLevel = level;
1153 ITimeGraphWrapper tgWrapper = fTimeGraphWrapper;
1154 if (tgWrapper != null) {
1155 tgWrapper.setAutoExpandLevel(level);
1156 }
1157 }
1158
1159 /**
1160 * Gets the entry list for a trace
1161 *
1162 * @param trace
1163 * the trace
1164 *
1165 * @return the entry list map
1166 */
1167 protected List<TimeGraphEntry> getEntryList(ITmfTrace trace) {
1168 synchronized (fEntryListMap) {
1169 return fEntryListMap.get(trace);
1170 }
1171 }
1172
1173 /**
1174 * Adds a trace entry list to the entry list map
1175 *
1176 * @param trace
1177 * the trace to add
1178 * @param list
1179 * the list of time graph entries
1180 */
1181 protected void putEntryList(ITmfTrace trace, List<TimeGraphEntry> list) {
1182 synchronized (fEntryListMap) {
1183 fEntryListMap.put(trace, new CopyOnWriteArrayList<>(list));
1184 }
1185 }
1186
1187 /**
1188 * Adds a list of entries to a trace's entry list
1189 *
1190 * @param trace
1191 * the trace
1192 * @param list
1193 * the list of time graph entries to add
1194 */
1195 protected void addToEntryList(ITmfTrace trace, List<TimeGraphEntry> list) {
1196 synchronized (fEntryListMap) {
1197 List<TimeGraphEntry> entryList = fEntryListMap.get(trace);
1198 if (entryList == null) {
1199 fEntryListMap.put(trace, new CopyOnWriteArrayList<>(list));
1200 } else {
1201 entryList.addAll(list);
1202 }
1203 }
1204 }
1205
1206 /**
1207 * Removes a list of entries from a trace's entry list
1208 *
1209 * @param trace
1210 * the trace
1211 * @param list
1212 * the list of time graph entries to remove
1213 */
1214 protected void removeFromEntryList(ITmfTrace trace, List<TimeGraphEntry> list) {
1215 synchronized (fEntryListMap) {
1216 List<TimeGraphEntry> entryList = fEntryListMap.get(trace);
1217 if (entryList != null) {
1218 entryList.removeAll(list);
1219 }
1220 }
1221 }
1222
1223 /**
1224 * Text for the "next" button
1225 *
1226 * @return The "next" button text
1227 */
1228 protected String getNextText() {
1229 return Messages.AbstractTimeGraphtView_NextText;
1230 }
1231
1232 /**
1233 * Tooltip for the "next" button
1234 *
1235 * @return Tooltip for the "next" button
1236 */
1237 protected String getNextTooltip() {
1238 return Messages.AbstractTimeGraphView_NextTooltip;
1239 }
1240
1241 /**
1242 * Text for the "Previous" button
1243 *
1244 * @return The "Previous" button text
1245 */
1246 protected String getPrevText() {
1247 return Messages.AbstractTimeGraphView_PreviousText;
1248 }
1249
1250 /**
1251 * Tooltip for the "previous" button
1252 *
1253 * @return Tooltip for the "previous" button
1254 */
1255 protected String getPrevTooltip() {
1256 return Messages.AbstractTimeGraphView_PreviousTooltip;
1257 }
1258
1259
1260 FindTarget getFindTarget() {
1261 return fFindTarget;
1262 }
1263
1264 /**
1265 * Formats a log message for this class
1266 *
1267 * @param event
1268 * The event to log, that will be appended to the class name to
1269 * make the full event name
1270 * @param parameters
1271 * The string of extra parameters to add to the log message, in
1272 * the format name=value[, name=value]*, or <code>null</code> for
1273 * no params
1274 * @return The complete log message for this class
1275 */
1276 private String getLogMessage(String event, @Nullable String parameters) {
1277 if (parameters == null) {
1278 return String.format(LOG_STRING, event, getViewId());
1279 }
1280 return String.format(LOG_STRING_WITH_PARAM, event, getViewId(), parameters);
1281 }
1282
1283 // ------------------------------------------------------------------------
1284 // ViewPart
1285 // ------------------------------------------------------------------------
1286
1287 @Override
1288 public void createPartControl(Composite parent) {
1289 super.createPartControl(parent);
1290 if (fColumns == null || fLabelProvider == null) {
1291 fTimeGraphWrapper = new TimeGraphViewerWrapper(parent, SWT.NONE);
1292 } else {
1293 TimeGraphComboWrapper wrapper = new TimeGraphComboWrapper(parent, SWT.NONE);
1294 fTimeGraphWrapper = wrapper;
1295 TimeGraphCombo combo = wrapper.getTimeGraphCombo();
1296 combo.setTreeContentProvider(fTimeGraphContentProvider);
1297 combo.setTreeLabelProvider(fLabelProvider);
1298 combo.setTreeColumns(fColumns);
1299 if (fColumnComparators != null) {
1300 createColumnSelectionListener(combo.getTreeViewer());
1301 }
1302 // Add double click listener to tree viewer
1303 createDoubleClickListener(combo.getTreeViewer());
1304 }
1305 fTimeGraphWrapper.setTimeGraphContentProvider(fTimeGraphContentProvider);
1306 fTimeGraphWrapper.setFilterContentProvider(fFilterContentProvider != null ? fFilterContentProvider : fTimeGraphContentProvider);
1307 fTimeGraphWrapper.setFilterLabelProvider(fFilterLabelProvider);
1308 fTimeGraphWrapper.setFilterColumns(fFilterColumns);
1309
1310 fTimeGraphWrapper.setTimeGraphPresentationProvider(fPresentation);
1311 fTimeGraphWrapper.setAutoExpandLevel(fAutoExpandLevel);
1312
1313 fTimeGraphWrapper.getTimeGraphViewer().addRangeListener(new ITimeGraphRangeListener() {
1314 @Override
1315 public void timeRangeUpdated(TimeGraphRangeUpdateEvent event) {
1316 final long startTime = event.getStartTime();
1317 final long endTime = event.getEndTime();
1318 TmfTimeRange range = new TmfTimeRange(TmfTimestamp.fromNanos(startTime), TmfTimestamp.fromNanos(endTime));
1319 broadcast(new TmfWindowRangeUpdatedSignal(AbstractTimeGraphView.this, range));
1320 startZoomThread(startTime, endTime);
1321 }
1322 });
1323
1324 fTimeGraphWrapper.getTimeGraphViewer().addTimeListener(new ITimeGraphTimeListener() {
1325 @Override
1326 public void timeSelected(TimeGraphTimeEvent event) {
1327 ITmfTimestamp startTime = TmfTimestamp.fromNanos(event.getBeginTime());
1328 ITmfTimestamp endTime = TmfTimestamp.fromNanos(event.getEndTime());
1329 broadcast(new TmfSelectionRangeUpdatedSignal(AbstractTimeGraphView.this, startTime, endTime));
1330 }
1331 });
1332
1333 fTimeGraphWrapper.getTimeGraphViewer().addBookmarkListener(new ITimeGraphBookmarkListener() {
1334 @Override
1335 public void bookmarkAdded(final TimeGraphBookmarkEvent event) {
1336 try {
1337 ResourcesPlugin.getWorkspace().run(new IWorkspaceRunnable() {
1338 @Override
1339 public void run(IProgressMonitor monitor) throws CoreException {
1340 IMarkerEvent bookmark = event.getBookmark();
1341 IMarker marker = fEditorFile.createMarker(IMarker.BOOKMARK);
1342 marker.setAttribute(IMarker.MESSAGE, bookmark.getLabel());
1343 marker.setAttribute(ITmfMarker.MARKER_TIME, Long.toString(bookmark.getTime()));
1344 if (bookmark.getDuration() > 0) {
1345 marker.setAttribute(ITmfMarker.MARKER_DURATION, Long.toString(bookmark.getDuration()));
1346 marker.setAttribute(IMarker.LOCATION,
1347 NLS.bind(org.eclipse.tracecompass.internal.tmf.ui.Messages.TmfMarker_LocationTimeRange,
1348 TmfTimestamp.fromNanos(bookmark.getTime()),
1349 TmfTimestamp.fromNanos(bookmark.getTime() + bookmark.getDuration())));
1350 } else {
1351 marker.setAttribute(IMarker.LOCATION,
1352 NLS.bind(org.eclipse.tracecompass.internal.tmf.ui.Messages.TmfMarker_LocationTime,
1353 TmfTimestamp.fromNanos(bookmark.getTime())));
1354 }
1355 marker.setAttribute(ITmfMarker.MARKER_COLOR, bookmark.getColor().toString());
1356 }
1357 }, null);
1358 } catch (CoreException e) {
1359 Activator.getDefault().logError(e.getMessage());
1360 }
1361 }
1362
1363 @Override
1364 public void bookmarkRemoved(TimeGraphBookmarkEvent event) {
1365 try {
1366 IMarkerEvent bookmark = event.getBookmark();
1367 IMarker[] markers = fEditorFile.findMarkers(IMarker.BOOKMARK, false, IResource.DEPTH_ZERO);
1368 for (IMarker marker : markers) {
1369 if (bookmark.getLabel().equals(marker.getAttribute(IMarker.MESSAGE)) &&
1370 Long.toString(bookmark.getTime()).equals(marker.getAttribute(ITmfMarker.MARKER_TIME, (String) null)) &&
1371 Long.toString(bookmark.getDuration()).equals(marker.getAttribute(ITmfMarker.MARKER_DURATION, Long.toString(0))) &&
1372 bookmark.getColor().toString().equals(marker.getAttribute(ITmfMarker.MARKER_COLOR))) {
1373 marker.delete();
1374 break;
1375 }
1376 }
1377 } catch (CoreException e) {
1378 Activator.getDefault().logError(e.getMessage());
1379 }
1380 }
1381 });
1382
1383 fTimeGraphWrapper.getTimeGraphViewer().setTimeFormat(TimeFormat.CALENDAR);
1384
1385 IStatusLineManager statusLineManager = getViewSite().getActionBars().getStatusLineManager();
1386 fTimeGraphWrapper.getTimeGraphViewer().getTimeGraphControl().setStatusLineManager(statusLineManager);
1387
1388 // View Action Handling
1389 makeActions();
1390 contributeToActionBars();
1391
1392 ITmfTrace trace = TmfTraceManager.getInstance().getActiveTrace();
1393 if (trace != null) {
1394 traceSelected(new TmfTraceSelectedSignal(this, trace));
1395 }
1396
1397 // make selection available to other views
1398 getSite().setSelectionProvider(fTimeGraphWrapper.getSelectionProvider());
1399
1400 ResourcesPlugin.getWorkspace().addResourceChangeListener(this, IResourceChangeEvent.POST_CHANGE);
1401
1402 createContextMenu();
1403 fPartListener = new TimeGraphPartListener();
1404 getSite().getPage().addPartListener(fPartListener);
1405 }
1406
1407 @Override
1408 public void setFocus() {
1409 fTimeGraphWrapper.setFocus();
1410 }
1411
1412 @Override
1413 public void dispose() {
1414 super.dispose();
1415 synchronized (fBuildJobMap) {
1416 fBuildJobMap.values().forEach(buildJob -> {
1417 buildJob.cancel();
1418 });
1419 }
1420 if (fZoomThread != null) {
1421 fZoomThread.cancel();
1422 }
1423 ResourcesPlugin.getWorkspace().removeResourceChangeListener(this);
1424 getSite().getPage().removePartListener(fPartListener);
1425 }
1426
1427 /**
1428 * @since 2.0
1429 */
1430 @Override
1431 public void resourceChanged(final IResourceChangeEvent event) {
1432 for (final IMarkerDelta delta : event.findMarkerDeltas(IMarker.BOOKMARK, false)) {
1433 if (delta.getResource().equals(fEditorFile)) {
1434 fTimeGraphWrapper.getTimeGraphViewer().setBookmarks(refreshBookmarks(fEditorFile));
1435 redraw();
1436 return;
1437 }
1438 }
1439 }
1440
1441 private static List<IMarkerEvent> refreshBookmarks(final IFile editorFile) {
1442 List<IMarkerEvent> bookmarks = new ArrayList<>();
1443 if (editorFile == null || !editorFile.exists()) {
1444 return bookmarks;
1445 }
1446 try {
1447 IMarker[] markers = editorFile.findMarkers(IMarker.BOOKMARK, false, IResource.DEPTH_ZERO);
1448 for (IMarker marker : markers) {
1449 String label = marker.getAttribute(IMarker.MESSAGE, (String) null);
1450 String time = marker.getAttribute(ITmfMarker.MARKER_TIME, (String) null);
1451 String duration = marker.getAttribute(ITmfMarker.MARKER_DURATION, Long.toString(0));
1452 String rgba = marker.getAttribute(ITmfMarker.MARKER_COLOR, (String) null);
1453 if (label != null && time != null && rgba != null) {
1454 Matcher matcher = RGBA_PATTERN.matcher(rgba);
1455 if (matcher.matches()) {
1456 try {
1457 int red = Integer.valueOf(matcher.group(1));
1458 int green = Integer.valueOf(matcher.group(2));
1459 int blue = Integer.valueOf(matcher.group(3));
1460 int alpha = Integer.valueOf(matcher.group(4));
1461 RGBA color = new RGBA(red, green, blue, alpha);
1462 bookmarks.add(new MarkerEvent(null, Long.valueOf(time), Long.valueOf(duration), IMarkerEvent.BOOKMARKS, color, label, true));
1463 } catch (NumberFormatException e) {
1464 Activator.getDefault().logError(e.getMessage());
1465 }
1466 }
1467 }
1468 }
1469 } catch (CoreException e) {
1470 Activator.getDefault().logError(e.getMessage());
1471 }
1472 return bookmarks;
1473 }
1474
1475
1476
1477 // ------------------------------------------------------------------------
1478 // Signal handlers
1479 // ------------------------------------------------------------------------
1480
1481 /**
1482 * Handler for the trace opened signal.
1483 *
1484 * @param signal
1485 * The incoming signal
1486 */
1487 @TmfSignalHandler
1488 public void traceOpened(TmfTraceOpenedSignal signal) {
1489 loadTrace(signal.getTrace());
1490 }
1491
1492 /**
1493 * Handler for the trace selected signal
1494 *
1495 * @param signal
1496 * The incoming signal
1497 */
1498 @TmfSignalHandler
1499 public void traceSelected(final TmfTraceSelectedSignal signal) {
1500 if (signal.getTrace() == fTrace) {
1501 return;
1502 }
1503 loadTrace(signal.getTrace());
1504 }
1505
1506 /**
1507 * Trace is closed: clear the data structures and the view
1508 *
1509 * @param signal
1510 * the signal received
1511 */
1512 @TmfSignalHandler
1513 public void traceClosed(final TmfTraceClosedSignal signal) {
1514 resetView(signal.getTrace());
1515 if (signal.getTrace() == fTrace) {
1516 fTrace = null;
1517 fEditorFile = null;
1518 setStartTime(SWT.DEFAULT);
1519 setEndTime(SWT.DEFAULT);
1520 refresh();
1521 }
1522 }
1523
1524 /**
1525 * Handler for the selection range signal.
1526 *
1527 * @param signal
1528 * The signal that's received
1529 * @since 1.0
1530 */
1531 @TmfSignalHandler
1532 public void selectionRangeUpdated(final TmfSelectionRangeUpdatedSignal signal) {
1533 if (signal.getSource() == this || fTrace == null) {
1534 return;
1535 }
1536 final long beginTime = signal.getBeginTime().toNanos();
1537 final long endTime = signal.getEndTime().toNanos();
1538
1539 Display.getDefault().asyncExec(new Runnable() {
1540 @Override
1541 public void run() {
1542 if (fTimeGraphWrapper.isDisposed()) {
1543 return;
1544 }
1545 if (beginTime == endTime) {
1546 fTimeGraphWrapper.getTimeGraphViewer().setSelectedTime(beginTime, true);
1547 } else {
1548 fTimeGraphWrapper.getTimeGraphViewer().setSelectionRange(beginTime, endTime, true);
1549 }
1550 synchingToTime(fTimeGraphWrapper.getTimeGraphViewer().getSelectionBegin());
1551 }
1552 });
1553 }
1554
1555 /**
1556 * Handler for the window range signal.
1557 *
1558 * @param signal
1559 * The signal that's received
1560 * @since 1.0
1561 */
1562 @TmfSignalHandler
1563 public void windowRangeUpdated(final TmfWindowRangeUpdatedSignal signal) {
1564 if (signal.getSource() == this || fTrace == null) {
1565 return;
1566 }
1567 if (signal.getCurrentRange().getIntersection(fTrace.getTimeRange()) == null) {
1568 return;
1569 }
1570 final long startTime = signal.getCurrentRange().getStartTime().toNanos();
1571 final long endTime = signal.getCurrentRange().getEndTime().toNanos();
1572 Display.getDefault().asyncExec(new Runnable() {
1573 @Override
1574 public void run() {
1575 if (fTimeGraphWrapper.isDisposed()) {
1576 return;
1577 }
1578 fTimeGraphWrapper.getTimeGraphViewer().setStartFinishTime(startTime, endTime);
1579 startZoomThread(startTime, endTime);
1580 }
1581 });
1582 }
1583
1584 /**
1585 * @param signal the format of the timestamps was updated.
1586 */
1587 @TmfSignalHandler
1588 public void updateTimeFormat( final TmfTimestampFormatUpdateSignal signal){
1589 fTimeGraphWrapper.refresh();
1590 }
1591
1592 /**
1593 * A marker event source has been updated
1594 *
1595 * @param signal
1596 * the signal
1597 * @since 2.1
1598 */
1599 @TmfSignalHandler
1600 public void markerEventSourceUpdated(final TmfMarkerEventSourceUpdatedSignal signal) {
1601 getTimeGraphViewer().setMarkerCategories(getMarkerCategories());
1602 getTimeGraphViewer().setMarkers(null);
1603 refresh();
1604 }
1605
1606 // ------------------------------------------------------------------------
1607 // Internal
1608 // ------------------------------------------------------------------------
1609
1610 private void loadTrace(final ITmfTrace trace) {
1611 if (fZoomThread != null) {
1612 fZoomThread.cancel();
1613 fZoomThread = null;
1614 }
1615 if (fTrace != null) {
1616 /* save the filters of the previous trace */
1617 fFiltersMap.put(fTrace, fTimeGraphWrapper.getFilters());
1618 fViewContext.put(fTrace, new ViewContext(fCurrentSortColumn, fSortDirection, fTimeGraphWrapper.getSelection()));
1619 }
1620 fTrace = trace;
1621
1622 LOGGER.info(() -> getLogMessage("LoadingTrace", "trace=" + trace.getName())); //$NON-NLS-1$ //$NON-NLS-2$
1623
1624 restoreViewContext();
1625 fEditorFile = TmfTraceManager.getInstance().getTraceEditorFile(trace);
1626 synchronized (fEntryListMap) {
1627 fEntryList = fEntryListMap.get(fTrace);
1628 if (fEntryList == null) {
1629 rebuild();
1630 } else {
1631 setStartTime(fTrace.getStartTime().toNanos());
1632 setEndTime(fTrace.getEndTime().toNanos());
1633 refresh();
1634 }
1635 }
1636 }
1637
1638 /**
1639 * Forces a rebuild of the entries list, even if entries already exist for this trace
1640 */
1641 protected void rebuild() {
1642 setStartTime(Long.MAX_VALUE);
1643 setEndTime(Long.MIN_VALUE);
1644 refresh();
1645 ITmfTrace viewTrace = fTrace;
1646 if (viewTrace == null) {
1647 return;
1648 }
1649 resetView(viewTrace);
1650
1651 List<IMarkerEventSource> markerEventSources = new ArrayList<>();
1652 synchronized (fBuildJobMap) {
1653 for (ITmfTrace trace : getTracesToBuild(viewTrace)) {
1654 if (trace == null) {
1655 break;
1656 }
1657 markerEventSources.addAll(TmfTraceAdapterManager.getAdapters(trace, IMarkerEventSource.class));
1658 Job buildJob = new Job(getTitle() + Messages.AbstractTimeGraphView_BuildJob) {
1659 @Override
1660 protected IStatus run(IProgressMonitor monitor) {
1661 new BuildRunnable(trace, viewTrace).run(monitor);
1662 monitor.done();
1663 return Status.OK_STATUS;
1664 }
1665 };
1666 fBuildJobMap.put(trace, buildJob);
1667 buildJob.schedule();
1668 }
1669 }
1670 fMarkerEventSourcesMap.put(viewTrace, markerEventSources);
1671 }
1672
1673 /**
1674 * Method called when synching to a given timestamp. Inheriting classes can
1675 * perform actions here to update the view at the given timestamp.
1676 *
1677 * @param time
1678 * The currently selected time
1679 */
1680 protected void synchingToTime(long time) {
1681
1682 }
1683
1684 /**
1685 * Return the list of traces whose data or analysis results will be used to
1686 * populate the view. By default, if the trace is an experiment, the traces
1687 * under it will be returned, otherwise, the trace itself is returned.
1688 *
1689 * A build thread will be started for each trace returned by this method,
1690 * some of which may receive events in live streaming mode.
1691 *
1692 * @param trace
1693 * The trace associated with this view, can be null
1694 * @return List of traces with data to display
1695 */
1696 protected @NonNull Iterable<ITmfTrace> getTracesToBuild(@Nullable ITmfTrace trace) {
1697 return TmfTraceManager.getTraceSet(trace);
1698 }
1699
1700 /**
1701 * Build the entry list to show in this time graph view.
1702 * <p>
1703 * Called from the BuildJob for each trace returned by
1704 * {@link #getTracesToBuild(ITmfTrace)}. The full event list is also
1705 * normally computed for every entry that is created.
1706 *
1707 * @param trace
1708 * The trace being built
1709 * @param parentTrace
1710 * The parent of the trace set, or the trace itself
1711 * @param monitor
1712 * The progress monitor object
1713 * @since 2.0
1714 */
1715 protected abstract void buildEntryList(@NonNull ITmfTrace trace, @NonNull ITmfTrace parentTrace, @NonNull IProgressMonitor monitor);
1716
1717 /**
1718 * Gets the list of event for an entry in a given time range.
1719 * <p>
1720 * Called from the ZoomThread for every entry to update the zoomed event
1721 * list. Can be an empty implementation if the view does not support zoomed
1722 * event lists. Can also be used to compute the full event list.
1723 *
1724 * @param entry
1725 * The entry to get events for
1726 * @param startTime
1727 * Start of the time range
1728 * @param endTime
1729 * End of the time range
1730 * @param resolution
1731 * The resolution
1732 * @param monitor
1733 * The progress monitor object
1734 * @return The list of events for the entry
1735 */
1736 protected abstract @Nullable List<@NonNull ITimeEvent> getEventList(@NonNull TimeGraphEntry entry,
1737 long startTime, long endTime, long resolution,
1738 @NonNull IProgressMonitor monitor);
1739
1740 /**
1741 * Gets the list of links (displayed as arrows) for a trace in a given
1742 * timerange. Default implementation returns an empty list.
1743 *
1744 * @param startTime
1745 * Start of the time range
1746 * @param endTime
1747 * End of the time range
1748 * @param resolution
1749 * The resolution
1750 * @param monitor
1751 * The progress monitor object
1752 * @return The list of link events
1753 */
1754 protected @Nullable List<@NonNull ILinkEvent> getLinkList(long startTime, long endTime,
1755 long resolution, @NonNull IProgressMonitor monitor) {
1756 return new ArrayList<>();
1757 }
1758
1759 /**
1760 * Gets the list of view-specific marker categories. Default implementation
1761 * returns an empty list.
1762 *
1763 * @return The list of marker categories
1764 * @since 2.0
1765 */
1766 protected @NonNull List<String> getViewMarkerCategories() {
1767 return new ArrayList<>();
1768 }
1769
1770 /**
1771 * Gets the list of view-specific markers for a trace in a given time range.
1772 * Default implementation returns an empty list.
1773 *
1774 * @param startTime
1775 * Start of the time range
1776 * @param endTime
1777 * End of the time range
1778 * @param resolution
1779 * The resolution
1780 * @param monitor
1781 * The progress monitor object
1782 * @return The list of marker events
1783 * @since 2.0
1784 */
1785 protected @NonNull List<IMarkerEvent> getViewMarkerList(long startTime, long endTime,
1786 long resolution, @NonNull IProgressMonitor monitor) {
1787 return new ArrayList<>();
1788 }
1789
1790 /**
1791 * Gets the list of trace-specific markers for a trace in a given time range.
1792 *
1793 * @param startTime
1794 * Start of the time range
1795 * @param endTime
1796 * End of the time range
1797 * @param resolution
1798 * The resolution
1799 * @param monitor
1800 * The progress monitor object
1801 * @return The list of marker events
1802 * @since 2.0
1803 */
1804 protected @NonNull List<IMarkerEvent> getTraceMarkerList(long startTime, long endTime,
1805 long resolution, @NonNull IProgressMonitor monitor) {
1806 List<IMarkerEvent> markers = new ArrayList<>();
1807 for (IMarkerEventSource markerEventSource : getMarkerEventSources(fTrace)) {
1808 for (String category : markerEventSource.getMarkerCategories()) {
1809 if (monitor.isCanceled()) {
1810 break;
1811 }
1812 markers.addAll(markerEventSource.getMarkerList(category, startTime, endTime, resolution, monitor));
1813 }
1814 }
1815 return markers;
1816 }
1817
1818 /**
1819 * Get the list of current marker categories.
1820 *
1821 * @return The list of marker categories
1822 * @since 2.1
1823 */
1824 protected @NonNull List<String> getMarkerCategories() {
1825 Set<String> categories = new LinkedHashSet<>(getViewMarkerCategories());
1826 for (IMarkerEventSource markerEventSource : getMarkerEventSources(fTrace)) {
1827 categories.addAll(markerEventSource.getMarkerCategories());
1828 }
1829 return new ArrayList<>(categories);
1830 }
1831
1832 /**
1833 * Gets the list of marker event sources for a given trace.
1834 *
1835 * @param trace
1836 * The trace
1837 * @return The list of marker event sources
1838 * @since 2.0
1839 */
1840 private @NonNull List<IMarkerEventSource> getMarkerEventSources(ITmfTrace trace) {
1841 List<IMarkerEventSource> markerEventSources = fMarkerEventSourcesMap.get(trace);
1842 if (markerEventSources == null) {
1843 markerEventSources = Collections.emptyList();
1844 }
1845 return markerEventSources;
1846 }
1847
1848 /**
1849 * Refresh the display
1850 */
1851 protected void refresh() {
1852 LOGGER.info(() -> getLogMessage("RefreshRequested", null)); //$NON-NLS-1$
1853 final boolean zoomThread = Thread.currentThread() instanceof ZoomThread;
1854 TmfUiRefreshHandler.getInstance().queueUpdate(this, new Runnable() {
1855 @Override
1856 public void run() {
1857 LOGGER.info(() -> getLogMessage("RefreshStart", null)); //$NON-NLS-1$
1858 if (fTimeGraphWrapper.isDisposed()) {
1859 return;
1860 }
1861 fDirty.incrementAndGet();
1862
1863 boolean hasEntries = false;
1864 synchronized (fEntryListMap) {
1865 fEntryList = fEntryListMap.get(fTrace);
1866 if (fEntryList == null) {
1867 fEntryList = new CopyOnWriteArrayList<>();
1868 } else if (fEntryComparator != null) {
1869 List<TimeGraphEntry> list = new ArrayList<>(fEntryList);
1870 Collections.sort(list, fEntryComparator);
1871 for (ITimeGraphEntry entry : list) {
1872 sortChildren(entry, fEntryComparator);
1873 }
1874 fEntryList.clear();
1875 fEntryList.addAll(list);
1876 }
1877 hasEntries = !fEntryList.isEmpty();
1878 }
1879 boolean inputChanged = fEntryList != fTimeGraphWrapper.getInput();
1880 TimeGraphCombo combo = getTimeGraphCombo();
1881 try {
1882 // Set redraw to false to only draw once
1883 if (combo != null) {
1884 combo.getTreeViewer().getTree().setRedraw(false);
1885 }
1886 getTimeGraphViewer().getTimeGraphControl().setRedraw(false);
1887 if (inputChanged) {
1888 fTimeGraphWrapper.setInput(fEntryList);
1889 /* restore the previously saved filters, if any */
1890 fTimeGraphWrapper.setFilters(fFiltersMap.get(fTrace));
1891 fTimeGraphWrapper.getTimeGraphViewer().setLinks(null);
1892 fTimeGraphWrapper.getTimeGraphViewer().setBookmarks(refreshBookmarks(fEditorFile));
1893 fTimeGraphWrapper.getTimeGraphViewer().setMarkerCategories(getMarkerCategories());
1894 fTimeGraphWrapper.getTimeGraphViewer().setMarkers(null);
1895 applyViewContext();
1896 } else {
1897 fTimeGraphWrapper.refresh();
1898 }
1899 // reveal selection
1900 if (fIsRevealSelection) {
1901 fIsRevealSelection = false;
1902 ITimeGraphEntry entry1 = fTimeGraphWrapper.getSelection();
1903 fTimeGraphWrapper.setSelection(entry1);
1904 }
1905 } finally {
1906 if (combo != null) {
1907 combo.getTreeViewer().getTree().setRedraw(true);
1908 }
1909 getTimeGraphViewer().getTimeGraphControl().setRedraw(true);
1910 }
1911 long startBound = (fStartTime == Long.MAX_VALUE ? SWT.DEFAULT : fStartTime);
1912 long endBound = (fEndTime == Long.MIN_VALUE ? SWT.DEFAULT : fEndTime);
1913 fTimeGraphWrapper.getTimeGraphViewer().setTimeBounds(startBound, endBound);
1914
1915 TmfTraceContext ctx = TmfTraceManager.getInstance().getCurrentTraceContext();
1916 long selectionBeginTime = fTrace == null ? SWT.DEFAULT : ctx.getSelectionRange().getStartTime().toNanos();
1917 long selectionEndTime = fTrace == null ? SWT.DEFAULT : ctx.getSelectionRange().getEndTime().toNanos();
1918 long startTime = fTrace == null ? SWT.DEFAULT : ctx.getWindowRange().getStartTime().toNanos();
1919 long endTime = fTrace == null ? SWT.DEFAULT : ctx.getWindowRange().getEndTime().toNanos();
1920 startTime = (fStartTime == Long.MAX_VALUE ? SWT.DEFAULT : Math.max(startTime, fStartTime));
1921 endTime = (fEndTime == Long.MIN_VALUE ? SWT.DEFAULT : Math.min(endTime, fEndTime));
1922 fTimeGraphWrapper.getTimeGraphViewer().setSelectionRange(selectionBeginTime, selectionEndTime, false);
1923 fTimeGraphWrapper.getTimeGraphViewer().setStartFinishTime(startTime, endTime);
1924
1925 if (inputChanged && selectionBeginTime != SWT.DEFAULT) {
1926 synchingToTime(selectionBeginTime);
1927 }
1928
1929 if (fTimeGraphWrapper instanceof TimeGraphComboWrapper && !fPackDone) {
1930 for (TreeColumn column : ((TimeGraphComboWrapper) fTimeGraphWrapper).getTreeViewer().getTree().getColumns()) {
1931 column.pack();
1932 }
1933 if (hasEntries) {
1934 fPackDone = true;
1935 }
1936 }
1937
1938 if (!zoomThread) {
1939 startZoomThread(startTime, endTime);
1940 }
1941 fDirty.decrementAndGet();
1942 LOGGER.info(() -> getLogMessage("RefreshEnd", null)); //$NON-NLS-1$
1943 }
1944 });
1945 }
1946
1947 /**
1948 * Redraw the canvas
1949 */
1950 protected void redraw() {
1951 synchronized (fSyncObj) {
1952 if (fRedrawState == State.IDLE) {
1953 fRedrawState = State.BUSY;
1954 } else {
1955 fRedrawState = State.PENDING;
1956 return;
1957 }
1958 }
1959 LOGGER.info(() -> getLogMessage("RedrawRequested", null)); //$NON-NLS-1$
1960 Display.getDefault().asyncExec(new Runnable() {
1961 @Override
1962 public void run() {
1963 LOGGER.info(() -> getLogMessage("RedrawStart", null)); //$NON-NLS-1$
1964 if (fTimeGraphWrapper.isDisposed()) {
1965 return;
1966 }
1967 fTimeGraphWrapper.redraw();
1968 fTimeGraphWrapper.update();
1969 synchronized (fSyncObj) {
1970 if (fRedrawState == State.PENDING) {
1971 fRedrawState = State.IDLE;
1972 redraw();
1973 } else {
1974 fRedrawState = State.IDLE;
1975 }
1976 }
1977 LOGGER.info(() -> getLogMessage("RedrawEnd", null)); //$NON-NLS-1$
1978 }
1979 });
1980 }
1981
1982 private void sortChildren(ITimeGraphEntry entry, Comparator<ITimeGraphEntry> comparator) {
1983 if (entry instanceof TimeGraphEntry) {
1984 ((TimeGraphEntry) entry).sortChildren(comparator);
1985 }
1986 for (ITimeGraphEntry child : entry.getChildren()) {
1987 sortChildren(child, comparator);
1988 }
1989 }
1990
1991 /**
1992 * Start or restart the zoom thread.
1993 *
1994 * @param startTime
1995 * the zoom start time
1996 * @param endTime
1997 * the zoom end time
1998 * @since 2.0
1999 */
2000 protected final void startZoomThread(long startTime, long endTime) {
2001 long clampedStartTime = (fStartTime == Long.MAX_VALUE ? startTime : Math.min(Math.max(startTime, fStartTime), fEndTime));
2002 long clampedEndTime = (fEndTime == Long.MIN_VALUE ? endTime : Math.max(Math.min(endTime, fEndTime), fStartTime));
2003 fDirty.incrementAndGet();
2004 boolean restart = false;
2005 if (fZoomThread != null) {
2006 fZoomThread.cancel();
2007 if (fZoomThread.fZoomStartTime == clampedStartTime && fZoomThread.fZoomEndTime == clampedEndTime) {
2008 restart = true;
2009 }
2010 }
2011 long resolution = Math.max(1, (clampedEndTime - clampedStartTime) / fDisplayWidth);
2012 fZoomThread = createZoomThread(clampedStartTime, clampedEndTime, resolution, restart);
2013 if (fZoomThread != null) {
2014 // Don't start a new thread right away if results are being applied
2015 // from an old ZoomThread. Otherwise, the old results might
2016 // overwrite the new results if it finishes after.
2017 synchronized (fZoomThreadResultLock) {
2018 fZoomThread.start();
2019 }
2020 } else {
2021 fDirty.decrementAndGet();
2022 }
2023 }
2024
2025 /**
2026 * Create a zoom thread.
2027 *
2028 * @param startTime
2029 * the zoom start time
2030 * @param endTime
2031 * the zoom end time
2032 * @param resolution
2033 * the resolution
2034 * @param restart
2035 * true if restarting zoom for the same time range
2036 * @return a zoom thread
2037 * @since 1.1
2038 */
2039 protected @Nullable ZoomThread createZoomThread(long startTime, long endTime, long resolution, boolean restart) {
2040 final List<TimeGraphEntry> entryList = fEntryList;
2041 if (entryList == null) {
2042 return null;
2043 }
2044 return new ZoomThreadByEntry(entryList, startTime, endTime, resolution);
2045 }
2046
2047 private void makeActions() {
2048 fPreviousResourceAction = fTimeGraphWrapper.getTimeGraphViewer().getPreviousItemAction();
2049 fPreviousResourceAction.setText(getPrevText());
2050 fPreviousResourceAction.setToolTipText(getPrevTooltip());
2051 fNextResourceAction = fTimeGraphWrapper.getTimeGraphViewer().getNextItemAction();
2052 fNextResourceAction.setText(getNextText());
2053 fNextResourceAction.setToolTipText(getNextTooltip());
2054 }
2055
2056 private void contributeToActionBars() {
2057 IActionBars bars = getViewSite().getActionBars();
2058 fillLocalToolBar(bars.getToolBarManager());
2059 fillLocalMenu(bars.getMenuManager());
2060 }
2061
2062 /**
2063 * Add actions to local tool bar manager
2064 *
2065 * @param manager the tool bar manager
2066 */
2067 protected void fillLocalToolBar(IToolBarManager manager) {
2068 if (fFilterColumns != null && fFilterLabelProvider != null && fFilterColumns.length > 0) {
2069 manager.add(fTimeGraphWrapper.getShowFilterDialogAction());
2070 }
2071 manager.add(fTimeGraphWrapper.getTimeGraphViewer().getShowLegendAction());
2072 manager.add(new Separator());
2073 manager.add(fTimeGraphWrapper.getTimeGraphViewer().getResetScaleAction());
2074 manager.add(fTimeGraphWrapper.getTimeGraphViewer().getPreviousEventAction());
2075 manager.add(fTimeGraphWrapper.getTimeGraphViewer().getNextEventAction());
2076 manager.add(new Separator());
2077 manager.add(fTimeGraphWrapper.getTimeGraphViewer().getToggleBookmarkAction());
2078 manager.add(fTimeGraphWrapper.getTimeGraphViewer().getPreviousMarkerAction());
2079 manager.add(fTimeGraphWrapper.getTimeGraphViewer().getNextMarkerAction());
2080 manager.add(new Separator());
2081 manager.add(fPreviousResourceAction);
2082 manager.add(fNextResourceAction);
2083 manager.add(fTimeGraphWrapper.getTimeGraphViewer().getZoomInAction());
2084 manager.add(fTimeGraphWrapper.getTimeGraphViewer().getZoomOutAction());
2085 manager.add(new Separator());
2086 }
2087
2088 /**
2089 * Add actions to local menu manager
2090 *
2091 * @param manager the tool bar manager
2092 * @since 2.0
2093 */
2094 protected void fillLocalMenu(IMenuManager manager) {
2095 manager.add(fTimeGraphWrapper.getTimeGraphViewer().getMarkersMenu());
2096 }
2097
2098 /**
2099 * @since 1.0
2100 */
2101 @Override
2102 public TmfTimeViewAlignmentInfo getTimeViewAlignmentInfo() {
2103 if (fTimeGraphWrapper == null) {
2104 return null;
2105 }
2106 return fTimeGraphWrapper.getTimeViewAlignmentInfo();
2107 }
2108
2109 /**
2110 * @since 1.0
2111 */
2112 @Override
2113 public int getAvailableWidth(int requestedOffset) {
2114 if (fTimeGraphWrapper == null) {
2115 return 0;
2116 }
2117 return fTimeGraphWrapper.getAvailableWidth(requestedOffset);
2118 }
2119
2120 /**
2121 * @since 1.0
2122 */
2123 @Override
2124 public void performAlign(int offset, int width) {
2125 if (fTimeGraphWrapper != null) {
2126 fTimeGraphWrapper.performAlign(offset, width);
2127 }
2128 }
2129
2130 /**
2131 * Returns whether or not the time graph view is dirty. The time graph view
2132 * is considered dirty if it has yet to completely update its model.
2133 *
2134 * This method is meant to be used by tests in order to know when it is safe
2135 * to proceed.
2136 *
2137 * Note: If a trace is smaller than the initial window range (see
2138 * {@link ITmfTrace#getInitialRangeOffset}) this method will return true
2139 * forever.
2140 *
2141 * @return true if the time graph view has yet to completely update its
2142 * model, false otherwise
2143 * @since 2.0
2144 */
2145 public boolean isDirty() {
2146 if (fTrace == null) {
2147 return false;
2148 }
2149
2150 TmfTraceContext ctx = TmfTraceManager.getInstance().getCurrentTraceContext();
2151 long startTime = ctx.getWindowRange().getStartTime().toNanos();
2152 long endTime = ctx.getWindowRange().getEndTime().toNanos();
2153
2154 // If the time graph control hasn't updated all the way to the end of
2155 // the window range then it's dirty. A refresh should happen later.
2156 if (fTimeGraphWrapper.getTimeGraphViewer().getTime0() != startTime || fTimeGraphWrapper.getTimeGraphViewer().getTime1() != endTime) {
2157 return true;
2158 }
2159
2160 if (fZoomThread == null) {
2161 // The zoom thread is null but we might be just about to create it (refresh called).
2162 return fDirty.get() != 0;
2163 }
2164 // Dirty if the zoom thread is not done or if it hasn't zoomed all the
2165 // way to the end of the window range. In the latter case, there should be
2166 // a subsequent zoom thread that will be triggered.
2167 return fDirty.get() != 0 || fZoomThread.getZoomStartTime() != startTime || fZoomThread.getZoomEndTime() != endTime;
2168 }
2169
2170 private void createColumnSelectionListener(TreeViewer treeViewer) {
2171 for (int i = 0; i < fColumnComparators.length; i++) {
2172 final int index = i;
2173 final Comparator<ITimeGraphEntry> comp = fColumnComparators[index];
2174 final Tree tree = treeViewer.getTree();
2175 final TreeColumn column = tree.getColumn(i);
2176
2177 if (comp != null) {
2178 column.addSelectionListener(new SelectionAdapter() {
2179 @Override
2180 public void widgetSelected(SelectionEvent e) {
2181 TreeColumn prevSortcolumn = tree.getSortColumn();
2182 int direction = tree.getSortDirection();
2183 if (prevSortcolumn == column) {
2184 direction = (direction == SWT.DOWN) ? SWT.UP : SWT.DOWN;
2185 } else {
2186 direction = SWT.DOWN;
2187 }
2188 tree.setSortColumn(column);
2189 tree.setSortDirection(direction);
2190 fSortDirection = direction;
2191 fCurrentSortColumn = index;
2192 Comparator<ITimeGraphEntry> comparator = comp;
2193
2194 if (comparator instanceof ITimeGraphEntryComparator) {
2195 ((ITimeGraphEntryComparator) comparator).setDirection(direction);
2196 }
2197 if (direction != SWT.DOWN) {
2198 comparator = checkNotNull(Collections.reverseOrder(comparator));
2199 }
2200 setEntryComparator(comparator);
2201 fIsRevealSelection = true;
2202 if (fTimeGraphWrapper instanceof TimeGraphComboWrapper) {
2203 ((TimeGraphComboWrapper) fTimeGraphWrapper).getTreeViewer().getControl().setFocus();
2204 }
2205 refresh();
2206 }
2207 });
2208 }
2209 }
2210 }
2211
2212 private void createDoubleClickListener(TreeViewer treeViewer) {
2213 treeViewer.addDoubleClickListener(event -> {
2214 if (event.getSelection() instanceof TreeSelection) {
2215 TreeSelection selection = (TreeSelection) event.getSelection();
2216 if (selection.getFirstElement() instanceof ITimeGraphEntry) {
2217 ITimeGraphEntry entry = (ITimeGraphEntry) selection.getFirstElement();
2218 if (entry.hasChildren()) {
2219 fTimeGraphWrapper.setExpandedState(entry, !fTimeGraphWrapper.getExpandedState(entry));
2220 }
2221 }
2222 }
2223 });
2224 }
2225
2226
2227 private void restoreViewContext() {
2228 TimeGraphCombo combo = getTimeGraphCombo();
2229 ViewContext viewContext = fViewContext.get(fTrace);
2230 if (combo != null) {
2231 if (fColumnComparators != null) {
2232 // restore sort settings
2233 fSortDirection = SWT.DOWN;
2234 fCurrentSortColumn = fInitialSortColumn;
2235 if (viewContext != null) {
2236 fSortDirection = viewContext.getSortDirection();
2237 fCurrentSortColumn = viewContext.getSortColumn();
2238 }
2239 if ((fCurrentSortColumn < fColumnComparators.length) && (fColumnComparators[fCurrentSortColumn] != null)) {
2240 Comparator<ITimeGraphEntry> comparator = fColumnComparators[fCurrentSortColumn];
2241 if (comparator instanceof ITimeGraphEntryComparator) {
2242 ((ITimeGraphEntryComparator) comparator).setDirection(fSortDirection);
2243 }
2244 if (fSortDirection != SWT.DOWN) {
2245 comparator = checkNotNull(Collections.reverseOrder(comparator));
2246 }
2247 setEntryComparator(comparator);
2248 }
2249 }
2250 }
2251 }
2252
2253 private void applyViewContext() {
2254 TimeGraphCombo combo = getTimeGraphCombo();
2255 ViewContext viewContext = fViewContext.get(fTrace);
2256 if (combo != null) {
2257 TreeViewer treeViewer = combo.getTreeViewer();
2258 final Tree tree = treeViewer.getTree();
2259 final TreeColumn column = tree.getColumn(fCurrentSortColumn);
2260 tree.setSortDirection(fSortDirection);
2261 tree.setSortColumn(column);
2262 combo.getTreeViewer().getControl().setFocus();
2263 }
2264 // restore and reveal selection
2265 if ((viewContext != null) && (viewContext.getSelection() != null)) {
2266 fTimeGraphWrapper.setSelection(viewContext.getSelection());
2267 }
2268 fViewContext.remove(fTrace);
2269 }
2270
2271 private static class ViewContext {
2272 private int fSortColumnIndex;
2273 private int fSortDirection;
2274 private @Nullable ITimeGraphEntry fSelection;
2275
2276 ViewContext(int sortColunm, int sortDirection, ITimeGraphEntry selection) {
2277 fSortColumnIndex = sortColunm;
2278 fSortDirection = sortDirection;
2279 fSelection = selection;
2280 }
2281 /**
2282 * @return the sortColumn
2283 */
2284 public int getSortColumn() {
2285 return fSortColumnIndex;
2286 }
2287 /**
2288 * @return the sortDirection
2289 */
2290 public int getSortDirection() {
2291 return fSortDirection;
2292 }
2293 /**
2294 * @return the selection
2295 */
2296 public ITimeGraphEntry getSelection() {
2297 return fSelection;
2298 }
2299 }
2300
2301 /**
2302 * Method to reset the view internal data for a given trace.
2303 *
2304 * When overriding this method make sure to call the super
2305 * implementation.
2306 *
2307 * @param viewTrace
2308 * trace to reset the view for.
2309 * @since 2.0
2310 */
2311 protected void resetView(ITmfTrace viewTrace) {
2312 if (viewTrace == null) {
2313 return;
2314 }
2315 synchronized (fBuildJobMap) {
2316 for (ITmfTrace trace : getTracesToBuild(viewTrace)) {
2317 Job buildJob = fBuildJobMap.remove(trace);
2318 if (buildJob != null) {
2319 buildJob.cancel();
2320 }
2321 }
2322 }
2323 synchronized (fEntryListMap) {
2324 fEntryListMap.remove(viewTrace);
2325 }
2326 fViewContext.remove(viewTrace);
2327 fFiltersMap.remove(viewTrace);
2328 fMarkerEventSourcesMap.remove(viewTrace);
2329 if (viewTrace == fTrace) {
2330 if (fZoomThread != null) {
2331 fZoomThread.cancel();
2332 fZoomThread = null;
2333 }
2334 }
2335 }
2336
2337 private void createContextMenu() {
2338 TimeGraphCombo combo = getTimeGraphCombo();
2339 fEntryMenuManager.setRemoveAllWhenShown(true);
2340 if (combo != null) {
2341 TreeViewer treeViewer = combo.getTreeViewer();
2342 Tree tree = treeViewer.getTree();
2343 Menu menu = fEntryMenuManager.createContextMenu(tree);
2344 tree.setMenu(menu);
2345 } else {
2346 TimeGraphControl timeGraphControl = getTimeGraphViewer().getTimeGraphControl();
2347 final Menu entryMenu = fEntryMenuManager.createContextMenu(timeGraphControl);
2348 timeGraphControl.addTimeGraphEntryMenuListener(new MenuDetectListener() {
2349 @Override
2350 public void menuDetected(MenuDetectEvent event) {
2351 Point p = timeGraphControl.toControl(event.x, event.y);
2352 /*
2353 * The TimeGraphControl will call the TimeGraphEntryMenuListener
2354 * before the TimeEventMenuListener. If the event is
2355 * triggered on the namespace then show the menu else
2356 * clear the menu.
2357 */
2358 if (p.x < getTimeGraphViewer().getNameSpace()) {
2359 timeGraphControl.setMenu(entryMenu);
2360 } else {
2361 timeGraphControl.setMenu(null);
2362 event.doit = false;
2363 }
2364 }
2365 });
2366 }
2367 fEntryMenuManager.addMenuListener(new IMenuListener() {
2368 @Override
2369 public void menuAboutToShow(IMenuManager manager) {
2370 fillTimeGraphEntryContextMenu(fEntryMenuManager);
2371 fEntryMenuManager.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
2372 }
2373 });
2374 getSite().registerContextMenu(fEntryMenuManager, fTimeGraphWrapper.getSelectionProvider());
2375 }
2376
2377 /**
2378 * Fill context menu
2379 *
2380 * @param menuManager
2381 * a menuManager to fill
2382 * @since 2.0
2383 */
2384 protected void fillTimeGraphEntryContextMenu (@NonNull IMenuManager menuManager) {
2385 }
2386
2387 /*
2388 * Inner classes used for searching
2389 */
2390 class FindTarget {
2391 public ITimeGraphEntry getSelection() {
2392 return fTimeGraphWrapper.getSelection();
2393 }
2394
2395 public void selectAndReveal(@NonNull ITimeGraphEntry entry) {
2396 fTimeGraphWrapper.selectAndReveal(entry);
2397 }
2398
2399 public ITimeGraphEntry[] getEntries() {
2400 TimeGraphViewer viewer = getTimeGraphViewer();
2401 return viewer.getTimeGraphContentProvider().getElements(viewer.getInput());
2402 }
2403
2404 public Shell getShell() {
2405 return getSite().getShell();
2406 }
2407 }
2408
2409 class TimeGraphPartListener implements IPartListener {
2410 @Override
2411 public void partActivated(IWorkbenchPart part) {
2412 if (part == AbstractTimeGraphView.this) {
2413 synchronized (FIND_ACTION) {
2414 if (fFindActionHandler == null) {
2415 fFindActionHandler = new ActionHandler(FIND_ACTION);
2416 }
2417 if (fFindHandlerActivation == null) {
2418 final Object service = PlatformUI.getWorkbench().getService(IHandlerService.class);
2419 fFindHandlerActivation = ((IHandlerService) service).activateHandler(ActionFactory.FIND.getCommandId(), fFindActionHandler);
2420 }
2421 }
2422 }
2423 // Notify action for all parts
2424 FIND_ACTION.partActivated(part);
2425 }
2426 @Override
2427 public void partDeactivated(IWorkbenchPart part) {
2428 if ((part == AbstractTimeGraphView.this) && (fFindHandlerActivation != null)) {
2429 final Object service = PlatformUI.getWorkbench().getService(IHandlerService.class);
2430 ((IHandlerService) service).deactivateHandler(fFindHandlerActivation);
2431 fFindHandlerActivation = null;
2432 }
2433 }
2434 @Override
2435 public void partBroughtToTop(IWorkbenchPart part) {
2436 }
2437 @Override
2438 public void partClosed(IWorkbenchPart part) {
2439 }
2440 @Override
2441 public void partOpened(IWorkbenchPart part) {
2442 }
2443 }
2444 }
This page took 0.087936 seconds and 6 git commands to generate.