1 /*******************************************************************************
2 * Copyright (c) 2012, 2015 Ericsson, others
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
10 * Patrick Tasse - Initial API and implementation
11 * François Rajotte - Filter implementation
12 * Geneviève Bastien - Add event links between entries
13 * Christian Mansky - Add check active / uncheck inactive buttons
14 *******************************************************************************/
16 package org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
;
18 import java
.util
.ArrayList
;
19 import java
.util
.Arrays
;
20 import java
.util
.HashMap
;
21 import java
.util
.HashSet
;
22 import java
.util
.List
;
26 import org
.eclipse
.jdt
.annotation
.NonNull
;
27 import org
.eclipse
.jface
.viewers
.AbstractTreeViewer
;
28 import org
.eclipse
.jface
.viewers
.ILabelProviderListener
;
29 import org
.eclipse
.jface
.viewers
.ISelectionChangedListener
;
30 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
31 import org
.eclipse
.jface
.viewers
.ITableLabelProvider
;
32 import org
.eclipse
.jface
.viewers
.ITreeContentProvider
;
33 import org
.eclipse
.jface
.viewers
.ITreeViewerListener
;
34 import org
.eclipse
.jface
.viewers
.SelectionChangedEvent
;
35 import org
.eclipse
.jface
.viewers
.StructuredSelection
;
36 import org
.eclipse
.jface
.viewers
.TreeExpansionEvent
;
37 import org
.eclipse
.jface
.viewers
.TreeViewer
;
38 import org
.eclipse
.jface
.viewers
.Viewer
;
39 import org
.eclipse
.jface
.viewers
.ViewerFilter
;
40 import org
.eclipse
.swt
.SWT
;
41 import org
.eclipse
.swt
.custom
.SashForm
;
42 import org
.eclipse
.swt
.events
.ControlAdapter
;
43 import org
.eclipse
.swt
.events
.ControlEvent
;
44 import org
.eclipse
.swt
.events
.MouseEvent
;
45 import org
.eclipse
.swt
.events
.MouseTrackAdapter
;
46 import org
.eclipse
.swt
.events
.MouseWheelListener
;
47 import org
.eclipse
.swt
.events
.PaintEvent
;
48 import org
.eclipse
.swt
.events
.PaintListener
;
49 import org
.eclipse
.swt
.events
.SelectionAdapter
;
50 import org
.eclipse
.swt
.events
.SelectionEvent
;
51 import org
.eclipse
.swt
.graphics
.Image
;
52 import org
.eclipse
.swt
.graphics
.Point
;
53 import org
.eclipse
.swt
.graphics
.Rectangle
;
54 import org
.eclipse
.swt
.layout
.FillLayout
;
55 import org
.eclipse
.swt
.layout
.GridLayout
;
56 import org
.eclipse
.swt
.widgets
.Composite
;
57 import org
.eclipse
.swt
.widgets
.Control
;
58 import org
.eclipse
.swt
.widgets
.Display
;
59 import org
.eclipse
.swt
.widgets
.Event
;
60 import org
.eclipse
.swt
.widgets
.Listener
;
61 import org
.eclipse
.swt
.widgets
.Sash
;
62 import org
.eclipse
.swt
.widgets
.Slider
;
63 import org
.eclipse
.swt
.widgets
.Tree
;
64 import org
.eclipse
.swt
.widgets
.TreeColumn
;
65 import org
.eclipse
.swt
.widgets
.TreeItem
;
66 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfSignalManager
;
67 import org
.eclipse
.tracecompass
.tmf
.ui
.signal
.TmfTimeViewAlignmentInfo
;
68 import org
.eclipse
.tracecompass
.tmf
.ui
.signal
.TmfTimeViewAlignmentSignal
;
69 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.ITmfTimeAligned
;
70 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.dialogs
.ITimeGraphEntryActiveProvider
;
71 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.dialogs
.ShowFilterDialogAction
;
72 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.ILinkEvent
;
73 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.ITimeGraphEntry
;
75 import com
.google
.common
.collect
.Iterables
;
78 * Time graph "combo" view (with the list/tree on the left and the gantt chart
81 * @author Patrick Tasse
83 public class TimeGraphCombo
extends Composite
{
85 // ------------------------------------------------------------------------
87 // ------------------------------------------------------------------------
89 /** Constant indicating that all levels of the time graph should be expanded */
90 public static final int ALL_LEVELS
= AbstractTreeViewer
.ALL_LEVELS
;
92 private static final Object FILLER
= new Object();
94 // ------------------------------------------------------------------------
96 // ------------------------------------------------------------------------
98 /** The tree viewer */
99 private TreeViewer fTreeViewer
;
101 /** The time viewer */
102 private @NonNull TimeGraphViewer fTimeGraphViewer
;
104 /** The selection listener map */
105 private final Map
<ITimeGraphSelectionListener
, SelectionListenerWrapper
> fSelectionListenerMap
= new HashMap
<>();
107 /** The map of viewer filters to viewer filter wrappers */
108 private final Map
<ViewerFilter
, ViewerFilter
> fViewerFilterMap
= new HashMap
<>();
111 * Flag to block the tree selection changed listener when triggered by the
114 private boolean fInhibitTreeSelection
= false;
116 /** Number of filler rows used by the tree content provider */
117 private int fNumFillerRows
;
119 /** Calculated item height for Linux workaround */
120 private int fLinuxItemHeight
= 0;
122 /** The action that opens the filter dialog */
123 private ShowFilterDialogAction fShowFilterDialogAction
;
125 /** Default weight of each part of the sash */
126 private static final int[] DEFAULT_WEIGHTS
= { 1, 1 };
128 /** List of all expanded items whose parents are also expanded */
129 private List
<TreeItem
> fVisibleExpandedItems
= null;
131 private Listener fSashDragListener
;
132 private SashForm fSashForm
;
134 // ------------------------------------------------------------------------
136 // ------------------------------------------------------------------------
139 * The TreeContentProviderWrapper is used to insert filler items after
140 * the elements of the tree's real content provider.
142 private class TreeContentProviderWrapper
implements ITreeContentProvider
{
143 private final ITreeContentProvider contentProvider
;
145 public TreeContentProviderWrapper(ITreeContentProvider contentProvider
) {
146 this.contentProvider
= contentProvider
;
150 public void dispose() {
151 contentProvider
.dispose();
155 public void inputChanged(Viewer viewer
, Object oldInput
, Object newInput
) {
156 contentProvider
.inputChanged(viewer
, oldInput
, newInput
);
160 public Object
[] getElements(Object inputElement
) {
161 Object
[] elements
= contentProvider
.getElements(inputElement
);
162 // add filler elements to ensure alignment with time analysis viewer
163 Object
[] oElements
= Arrays
.copyOf(elements
, elements
.length
+ fNumFillerRows
, Object
[].class);
164 for (int i
= 0; i
< fNumFillerRows
; i
++) {
165 oElements
[elements
.length
+ i
] = FILLER
;
171 public Object
[] getChildren(Object parentElement
) {
172 if (parentElement
instanceof ITimeGraphEntry
) {
173 return contentProvider
.getChildren(parentElement
);
175 return new Object
[0];
179 public Object
getParent(Object element
) {
180 if (element
instanceof ITimeGraphEntry
) {
181 return contentProvider
.getParent(element
);
187 public boolean hasChildren(Object element
) {
188 if (element
instanceof ITimeGraphEntry
) {
189 return contentProvider
.hasChildren(element
);
196 * The TreeLabelProviderWrapper is used to intercept the filler items
197 * from the calls to the tree's real label provider.
199 private class TreeLabelProviderWrapper
implements ITableLabelProvider
{
200 private final ITableLabelProvider labelProvider
;
202 public TreeLabelProviderWrapper(ITableLabelProvider labelProvider
) {
203 this.labelProvider
= labelProvider
;
207 public void addListener(ILabelProviderListener listener
) {
208 labelProvider
.addListener(listener
);
212 public void dispose() {
213 labelProvider
.dispose();
217 public boolean isLabelProperty(Object element
, String property
) {
218 if (element
instanceof ITimeGraphEntry
) {
219 return labelProvider
.isLabelProperty(element
, property
);
225 public void removeListener(ILabelProviderListener listener
) {
226 labelProvider
.removeListener(listener
);
230 public Image
getColumnImage(Object element
, int columnIndex
) {
231 if (element
instanceof ITimeGraphEntry
) {
232 return labelProvider
.getColumnImage(element
, columnIndex
);
238 public String
getColumnText(Object element
, int columnIndex
) {
239 if (element
instanceof ITimeGraphEntry
) {
240 return labelProvider
.getColumnText(element
, columnIndex
);
248 * The SelectionListenerWrapper is used to intercept the filler items from
249 * the time graph combo's real selection listener, and to prevent double
250 * notifications from being sent when selection changes in both tree and
251 * time graph at the same time.
253 private class SelectionListenerWrapper
implements ISelectionChangedListener
, ITimeGraphSelectionListener
{
254 private final ITimeGraphSelectionListener listener
;
255 private ITimeGraphEntry selection
= null;
257 public SelectionListenerWrapper(ITimeGraphSelectionListener listener
) {
258 this.listener
= listener
;
262 public void selectionChanged(SelectionChangedEvent event
) {
263 if (fInhibitTreeSelection
) {
266 Object element
= ((IStructuredSelection
) event
.getSelection()).getFirstElement();
267 if (element
instanceof ITimeGraphEntry
) {
268 ITimeGraphEntry entry
= (ITimeGraphEntry
) element
;
269 if (entry
!= selection
) {
271 listener
.selectionChanged(new TimeGraphSelectionEvent(event
.getSource(), selection
));
277 public void selectionChanged(TimeGraphSelectionEvent event
) {
278 ITimeGraphEntry entry
= event
.getSelection();
279 if (entry
!= selection
) {
281 listener
.selectionChanged(new TimeGraphSelectionEvent(event
.getSource(), selection
));
287 * The ViewerFilterWrapper is used to intercept the filler items from
288 * the time graph combo's real ViewerFilters. These filler items should
291 private class ViewerFilterWrapper
extends ViewerFilter
{
293 private ViewerFilter fWrappedFilter
;
295 ViewerFilterWrapper(ViewerFilter filter
) {
297 this.fWrappedFilter
= filter
;
301 public boolean select(Viewer viewer
, Object parentElement
, Object element
) {
302 if (element
instanceof ITimeGraphEntry
) {
303 return fWrappedFilter
.select(viewer
, parentElement
, element
);
310 // ------------------------------------------------------------------------
312 // ------------------------------------------------------------------------
315 * Constructs a new instance of this class given its parent
316 * and a style value describing its behavior and appearance.
318 * @param parent a widget which will be the parent of the new instance (cannot be null)
319 * @param style the style of widget to construct
321 public TimeGraphCombo(Composite parent
, int style
) {
322 this(parent
, style
, DEFAULT_WEIGHTS
);
326 * Constructs a new instance of this class given its parent and a style
327 * value describing its behavior and appearance.
330 * a widget which will be the parent of the new instance (cannot
333 * the style of widget to construct
335 * The array (length 2) of relative weights of each side of the sash form
337 public TimeGraphCombo(Composite parent
, int style
, int[] weights
) {
338 super(parent
, style
);
339 setLayout(new FillLayout());
341 fSashForm
= new SashForm(this, SWT
.NONE
);
343 fTreeViewer
= new TreeViewer(fSashForm
, SWT
.FULL_SELECTION
| SWT
.H_SCROLL
);
344 fTreeViewer
.setAutoExpandLevel(AbstractTreeViewer
.ALL_LEVELS
);
345 final Tree tree
= fTreeViewer
.getTree();
346 tree
.setHeaderVisible(true);
347 tree
.setLinesVisible(true);
349 fTimeGraphViewer
= new TimeGraphViewer(fSashForm
, SWT
.NONE
);
350 fTimeGraphViewer
.setItemHeight(getItemHeight(tree
));
351 fTimeGraphViewer
.setHeaderHeight(tree
.getHeaderHeight());
352 fTimeGraphViewer
.setBorderWidth(tree
.getBorderWidth());
353 fTimeGraphViewer
.setNameWidthPref(0);
355 // Feature in Windows. The tree vertical bar reappears when
356 // the control is resized so we need to hide it again.
357 tree
.addControlListener(new ControlAdapter() {
358 private int depth
= 0;
360 public void controlResized(ControlEvent e
) {
363 tree
.getVerticalBar().setEnabled(false);
364 // this can trigger controlResized recursively
365 tree
.getVerticalBar().setVisible(false);
370 // Bug in Linux. The tree header height is 0 in constructor,
371 // so we need to reset it later when the control is painted.
372 // This work around used to be done on control resized but the header
373 // height was not initialized on the initial resize on GTK3.
374 tree
.addPaintListener(new PaintListener() {
376 public void paintControl(PaintEvent e
) {
377 int headerHeight
= tree
.getHeaderHeight();
378 if (headerHeight
> 0) {
379 fTimeGraphViewer
.setHeaderHeight(headerHeight
);
380 tree
.removePaintListener(this);
385 // ensure synchronization of expanded items between tree and time graph
386 fTreeViewer
.addTreeListener(new ITreeViewerListener() {
388 public void treeCollapsed(TreeExpansionEvent event
) {
389 fTimeGraphViewer
.setExpandedState((ITimeGraphEntry
) event
.getElement(), false);
390 // queue the alignment update because the tree items may only be
391 // actually collapsed after the listeners have been notified
392 fVisibleExpandedItems
= null; // invalidate the cache
393 getDisplay().asyncExec(new Runnable() {
396 alignTreeItems(true);
401 public void treeExpanded(TreeExpansionEvent event
) {
402 ITimeGraphEntry entry
= (ITimeGraphEntry
) event
.getElement();
403 fTimeGraphViewer
.setExpandedState(entry
, true);
404 Set
<Object
> expandedElements
= new HashSet
<>(Arrays
.asList(fTreeViewer
.getExpandedElements()));
405 for (ITimeGraphEntry child
: entry
.getChildren()) {
406 if (child
.hasChildren()) {
407 boolean expanded
= expandedElements
.contains(child
);
408 fTimeGraphViewer
.setExpandedState(child
, expanded
);
411 // queue the alignment update because the tree items may only be
412 // actually expanded after the listeners have been notified
413 fVisibleExpandedItems
= null; // invalidate the cache
414 getDisplay().asyncExec(new Runnable() {
417 alignTreeItems(true);
422 // ensure synchronization of expanded items between tree and time graph
423 fTimeGraphViewer
.addTreeListener(new ITimeGraphTreeListener() {
425 public void treeCollapsed(TimeGraphTreeExpansionEvent event
) {
426 fTreeViewer
.setExpandedState(event
.getEntry(), false);
427 alignTreeItems(true);
431 public void treeExpanded(TimeGraphTreeExpansionEvent event
) {
432 ITimeGraphEntry entry
= event
.getEntry();
433 fTreeViewer
.setExpandedState(entry
, true);
434 Set
<Object
> expandedElements
= new HashSet
<>(Arrays
.asList(fTreeViewer
.getExpandedElements()));
435 for (ITimeGraphEntry child
: entry
.getChildren()) {
436 if (child
.hasChildren()) {
437 boolean expanded
= expandedElements
.contains(child
);
438 fTimeGraphViewer
.setExpandedState(child
, expanded
);
441 alignTreeItems(true);
445 // prevent mouse button from selecting a filler tree item
446 tree
.addListener(SWT
.MouseDown
, new Listener() {
448 public void handleEvent(Event event
) {
449 TreeItem treeItem
= tree
.getItem(new Point(event
.x
, event
.y
));
450 if (treeItem
== null || treeItem
.getData() == FILLER
) {
452 List
<TreeItem
> treeItems
= getVisibleExpandedItems(tree
, false);
453 if (treeItems
.size() == 0) {
454 fTreeViewer
.setSelection(new StructuredSelection());
455 fTimeGraphViewer
.setSelection(null);
458 // this prevents from scrolling up when selecting
459 // the partially visible tree item at the bottom
460 tree
.select(treeItems
.get(treeItems
.size() - 1));
461 fTreeViewer
.setSelection(new StructuredSelection());
462 fTimeGraphViewer
.setSelection(null);
467 // prevent mouse wheel from scrolling down into filler tree items
468 tree
.addListener(SWT
.MouseWheel
, new Listener() {
470 public void handleEvent(Event event
) {
472 Slider scrollBar
= fTimeGraphViewer
.getVerticalBar();
473 fTimeGraphViewer
.setTopIndex(scrollBar
.getSelection() - event
.count
);
474 alignTreeItems(false);
478 // prevent key stroke from selecting a filler tree item
479 tree
.addListener(SWT
.KeyDown
, new Listener() {
481 public void handleEvent(Event event
) {
482 List
<TreeItem
> treeItems
= getVisibleExpandedItems(tree
, false);
483 if (treeItems
.size() == 0) {
484 fTreeViewer
.setSelection(new StructuredSelection());
488 if (event
.keyCode
== SWT
.ARROW_DOWN
) {
489 int index
= Math
.min(fTimeGraphViewer
.getSelectionIndex() + 1, treeItems
.size() - 1);
490 fTimeGraphViewer
.setSelection((ITimeGraphEntry
) treeItems
.get(index
).getData());
492 } else if (event
.keyCode
== SWT
.PAGE_DOWN
) {
493 int height
= tree
.getSize().y
- tree
.getHeaderHeight() - tree
.getHorizontalBar().getSize().y
;
494 int countPerPage
= height
/ getItemHeight(tree
);
495 int index
= Math
.min(fTimeGraphViewer
.getSelectionIndex() + countPerPage
- 1, treeItems
.size() - 1);
496 fTimeGraphViewer
.setSelection((ITimeGraphEntry
) treeItems
.get(index
).getData());
498 } else if (event
.keyCode
== SWT
.END
) {
499 fTimeGraphViewer
.setSelection((ITimeGraphEntry
) treeItems
.get(treeItems
.size() - 1).getData());
502 if (fTimeGraphViewer
.getSelectionIndex() >= 0) {
503 fTreeViewer
.setSelection(new StructuredSelection(fTimeGraphViewer
.getSelection()));
505 fTreeViewer
.setSelection(new StructuredSelection());
507 alignTreeItems(false);
511 // ensure alignment of top item between tree and time graph
512 fTimeGraphViewer
.getTimeGraphControl().addControlListener(new ControlAdapter() {
514 public void controlResized(ControlEvent e
) {
515 alignTreeItems(false);
519 // ensure synchronization of selected item between tree and time graph
520 fTreeViewer
.addSelectionChangedListener(new ISelectionChangedListener() {
522 public void selectionChanged(SelectionChangedEvent event
) {
523 if (fInhibitTreeSelection
) {
526 if (event
.getSelection() instanceof IStructuredSelection
) {
527 Object selection
= ((IStructuredSelection
) event
.getSelection()).getFirstElement();
528 if (selection
instanceof ITimeGraphEntry
) {
529 fTimeGraphViewer
.setSelection((ITimeGraphEntry
) selection
);
531 alignTreeItems(false);
536 // ensure synchronization of selected item between tree and time graph
537 fTimeGraphViewer
.addSelectionListener(new ITimeGraphSelectionListener() {
539 public void selectionChanged(TimeGraphSelectionEvent event
) {
540 ITimeGraphEntry entry
= fTimeGraphViewer
.getSelection();
541 fInhibitTreeSelection
= true; // block the tree selection changed listener
543 StructuredSelection selection
= new StructuredSelection(entry
);
544 fTreeViewer
.setSelection(selection
);
546 fTreeViewer
.setSelection(new StructuredSelection());
548 fInhibitTreeSelection
= false;
549 alignTreeItems(false);
553 // ensure alignment of top item between tree and time graph
554 fTimeGraphViewer
.getVerticalBar().addSelectionListener(new SelectionAdapter() {
556 public void widgetSelected(SelectionEvent e
) {
557 alignTreeItems(false);
561 // ensure alignment of top item between tree and time graph
562 fTimeGraphViewer
.getTimeGraphControl().addMouseWheelListener(new MouseWheelListener() {
564 public void mouseScrolled(MouseEvent e
) {
565 alignTreeItems(false);
569 // ensure the tree has focus control when mouse is over it if the time graph had control
570 fTreeViewer
.getControl().addMouseTrackListener(new MouseTrackAdapter() {
572 public void mouseEnter(MouseEvent e
) {
573 if (fTimeGraphViewer
.getTimeGraphControl().isFocusControl()) {
574 fTreeViewer
.getControl().setFocus();
579 // ensure the time graph has focus control when mouse is over it if the tree had control
580 fTimeGraphViewer
.getTimeGraphControl().addMouseTrackListener(new MouseTrackAdapter() {
582 public void mouseEnter(MouseEvent e
) {
583 if (fTreeViewer
.getControl().isFocusControl()) {
584 fTimeGraphViewer
.getTimeGraphControl().setFocus();
588 fTimeGraphViewer
.getTimeGraphScale().addMouseTrackListener(new MouseTrackAdapter() {
590 public void mouseEnter(MouseEvent e
) {
591 if (fTreeViewer
.getControl().isFocusControl()) {
592 fTimeGraphViewer
.getTimeGraphControl().setFocus();
597 // The filler rows are required to ensure alignment when the tree does not have a
598 // visible horizontal scroll bar. The tree does not allow its top item to be set
599 // to a value that would cause blank space to be drawn at the bottom of the tree.
600 fNumFillerRows
= Display
.getDefault().getBounds().height
/ getItemHeight(tree
);
602 fSashForm
.setWeights(weights
);
604 fTimeGraphViewer
.getTimeGraphControl().addPaintListener(new PaintListener() {
606 public void paintControl(PaintEvent e
) {
607 // Sashes in a SashForm are being created on layout so add the
608 // drag listener here
609 if (fSashDragListener
== null) {
610 for (Control control
: fSashForm
.getChildren()) {
611 if (control
instanceof Sash
) {
612 fSashDragListener
= new Listener() {
615 public void handleEvent(Event event
) {
616 sendTimeViewAlignmentChanged();
620 control
.removePaintListener(this);
621 control
.addListener(SWT
.Selection
, fSashDragListener
);
622 // There should be only one sash
631 private void sendTimeViewAlignmentChanged() {
632 TmfSignalManager
.dispatchSignal(new TmfTimeViewAlignmentSignal(fSashForm
, getTimeViewAlignmentInfo()));
635 // ------------------------------------------------------------------------
637 // ------------------------------------------------------------------------
640 * Returns this time graph combo's tree viewer.
642 * @return the tree viewer
644 public TreeViewer
getTreeViewer() {
649 * Returns this time graph combo's time graph viewer.
651 * @return the time graph viewer
653 public @NonNull TimeGraphViewer
getTimeGraphViewer() {
654 return fTimeGraphViewer
;
658 * Get the show filter dialog action.
660 * @return The Action object
663 public ShowFilterDialogAction
getShowFilterDialogAction() {
664 if (fShowFilterDialogAction
== null) {
665 fShowFilterDialogAction
= new ShowFilterDialogAction(fTimeGraphViewer
) {
667 protected void addFilter(ViewerFilter filter
) {
668 /* add filter to the combo instead of the viewer */
669 TimeGraphCombo
.this.addFilter(filter
);
673 protected void removeFilter(ViewerFilter filter
) {
674 /* remove filter from the combo instead of the viewer */
675 TimeGraphCombo
.this.removeFilter(filter
);
679 protected void refresh() {
680 /* refresh the combo instead of the viewer */
681 TimeGraphCombo
.this.refresh();
685 return fShowFilterDialogAction
;
688 // ------------------------------------------------------------------------
690 // ------------------------------------------------------------------------
693 public void redraw() {
694 fTimeGraphViewer
.getControl().redraw();
698 // ------------------------------------------------------------------------
700 // ------------------------------------------------------------------------
703 * Sets the tree content provider used by this time graph combo.
705 * @param contentProvider the tree content provider
707 public void setTreeContentProvider(ITreeContentProvider contentProvider
) {
708 fTreeViewer
.setContentProvider(new TreeContentProviderWrapper(contentProvider
));
712 * Sets the tree label provider used by this time graph combo.
714 * @param labelProvider the tree label provider
716 public void setTreeLabelProvider(ITableLabelProvider labelProvider
) {
717 fTreeViewer
.setLabelProvider(new TreeLabelProviderWrapper(labelProvider
));
721 * Sets the tree content provider used by the filter dialog
723 * @param contentProvider the tree content provider
725 public void setFilterContentProvider(ITreeContentProvider contentProvider
) {
726 getShowFilterDialogAction().getFilterDialog().setContentProvider(contentProvider
);
730 * Sets the tree label provider used by the filter dialog
732 * @param labelProvider the tree label provider
734 public void setFilterLabelProvider(ITableLabelProvider labelProvider
) {
735 getShowFilterDialogAction().getFilterDialog().setLabelProvider(labelProvider
);
739 * Adds a "check active" button used by the filter dialog
741 * @param activeProvider
742 * Additional button info specific to a certain view.
745 public void addTimeGraphFilterCheckActiveButton(ITimeGraphEntryActiveProvider activeProvider
) {
746 getShowFilterDialogAction().getFilterDialog().addTimeGraphFilterCheckActiveButton(activeProvider
);
750 * Adds an "uncheck inactive" button used by the filter dialog
752 * @param inactiveProvider
753 * Additional button info specific to a certain view.
756 public void addTimeGraphFilterUncheckInactiveButton(ITimeGraphEntryActiveProvider inactiveProvider
) {
757 getShowFilterDialogAction().getFilterDialog().addTimeGraphFilterUncheckInactiveButton(inactiveProvider
);
761 * Sets the tree columns for this time graph combo.
763 * @param columnNames the tree column names
765 public void setTreeColumns(String
[] columnNames
) {
766 final Tree tree
= fTreeViewer
.getTree();
767 for (String columnName
: columnNames
) {
768 TreeColumn column
= new TreeColumn(tree
, SWT
.LEFT
);
769 column
.setText(columnName
);
775 * Sets the tree columns for this time graph combo's filter dialog.
777 * @param columnNames the tree column names
779 public void setFilterColumns(String
[] columnNames
) {
780 getShowFilterDialogAction().getFilterDialog().setColumnNames(columnNames
);
784 * Sets the time graph content provider used by this time graph combo.
786 * @param timeGraphContentProvider
787 * the time graph content provider
789 public void setTimeGraphContentProvider(ITimeGraphContentProvider timeGraphContentProvider
) {
790 fTimeGraphViewer
.setTimeGraphContentProvider(timeGraphContentProvider
);
794 * Sets the time graph presentation provider used by this time graph combo.
796 * @param timeGraphProvider the time graph provider
798 public void setTimeGraphProvider(ITimeGraphPresentationProvider timeGraphProvider
) {
799 fTimeGraphViewer
.setTimeGraphProvider(timeGraphProvider
);
803 * Sets or clears the input for this time graph combo.
805 * @param input the input of this time graph combo, or <code>null</code> if none
807 public void setInput(Object input
) {
808 fInhibitTreeSelection
= true;
809 fTreeViewer
.setInput(input
);
810 for (SelectionListenerWrapper listenerWrapper
: fSelectionListenerMap
.values()) {
811 listenerWrapper
.selection
= null;
813 fInhibitTreeSelection
= false;
814 fTreeViewer
.getTree().getVerticalBar().setEnabled(false);
815 fTreeViewer
.getTree().getVerticalBar().setVisible(false);
816 fTimeGraphViewer
.setInput(input
);
817 fTimeGraphViewer
.setItemHeight(getItemHeight(fTreeViewer
.getTree()));
818 // queue the alignment update because in Linux the item bounds are not
819 // set properly until the tree has been painted at least once
820 fVisibleExpandedItems
= null; // invalidate the cache
821 getDisplay().asyncExec(new Runnable() {
824 alignTreeItems(true);
829 * Gets the input for this time graph combo.
831 * @return The input of this time graph combo, or <code>null</code> if none
833 public Object
getInput() {
834 return fTreeViewer
.getInput();
838 * Sets or clears the list of links to display on this combo
840 * @param links the links to display in this time graph combo
842 public void setLinks(List
<ILinkEvent
> links
) {
843 fTimeGraphViewer
.setLinks(links
);
847 * @param filter The filter object to be attached to the view
849 public void addFilter(ViewerFilter filter
) {
850 fInhibitTreeSelection
= true;
851 ViewerFilter wrapper
= new ViewerFilterWrapper(filter
);
852 fTreeViewer
.addFilter(wrapper
);
853 fTimeGraphViewer
.addFilter(filter
);
854 fViewerFilterMap
.put(filter
, wrapper
);
855 alignTreeItems(true);
856 fInhibitTreeSelection
= false;
860 * @param filter The filter object to be removed from the view
862 public void removeFilter(ViewerFilter filter
) {
863 fInhibitTreeSelection
= true;
864 ViewerFilter wrapper
= fViewerFilterMap
.get(filter
);
865 fTreeViewer
.removeFilter(wrapper
);
866 fTimeGraphViewer
.removeFilter(filter
);
867 fViewerFilterMap
.remove(filter
);
868 alignTreeItems(true);
869 fInhibitTreeSelection
= false;
873 * Returns this viewer's filters.
875 * @return an array of viewer filters
878 public ViewerFilter
[] getFilters() {
879 return fTimeGraphViewer
.getFilters();
883 * Sets the filters, replacing any previous filters, and triggers
884 * refiltering of the elements.
887 * an array of viewer filters, or null
890 public void setFilters(ViewerFilter
[] filters
) {
891 fInhibitTreeSelection
= true;
892 fViewerFilterMap
.clear();
893 if (filters
== null) {
894 fTreeViewer
.resetFilters();
896 for (ViewerFilter filter
: filters
) {
897 ViewerFilter wrapper
= new ViewerFilterWrapper(filter
);
898 fViewerFilterMap
.put(filter
, wrapper
);
900 ViewerFilter
[] wrappers
= Iterables
.toArray(fViewerFilterMap
.values(), ViewerFilter
.class);
901 fTreeViewer
.setFilters(wrappers
);
903 fTimeGraphViewer
.setFilters(filters
);
904 alignTreeItems(true);
905 fInhibitTreeSelection
= false;
909 * Refreshes this time graph completely with information freshly obtained from its model.
911 public void refresh() {
912 fInhibitTreeSelection
= true;
913 Tree tree
= fTreeViewer
.getTree();
915 tree
.setRedraw(false);
916 fTreeViewer
.refresh();
918 tree
.setRedraw(true);
920 fTimeGraphViewer
.refresh();
921 alignTreeItems(true);
922 fInhibitTreeSelection
= false;
926 * Adds a listener for selection changes in this time graph combo.
928 * @param listener a selection listener
930 public void addSelectionListener(ITimeGraphSelectionListener listener
) {
931 SelectionListenerWrapper listenerWrapper
= new SelectionListenerWrapper(listener
);
932 fTreeViewer
.addSelectionChangedListener(listenerWrapper
);
933 fSelectionListenerMap
.put(listener
, listenerWrapper
);
934 fTimeGraphViewer
.addSelectionListener(listenerWrapper
);
938 * Removes the given selection listener from this time graph combo.
940 * @param listener a selection changed listener
942 public void removeSelectionListener(ITimeGraphSelectionListener listener
) {
943 SelectionListenerWrapper listenerWrapper
= fSelectionListenerMap
.remove(listener
);
944 fTreeViewer
.removeSelectionChangedListener(listenerWrapper
);
945 fTimeGraphViewer
.removeSelectionListener(listenerWrapper
);
949 * Sets the current selection for this time graph combo.
951 * @param selection the new selection
953 public void setSelection(ITimeGraphEntry selection
) {
954 fTimeGraphViewer
.setSelection(selection
);
955 fInhibitTreeSelection
= true; // block the tree selection changed listener
956 if (selection
!= null) {
957 StructuredSelection structuredSelection
= new StructuredSelection(selection
);
958 fTreeViewer
.setSelection(structuredSelection
);
960 fTreeViewer
.setSelection(new StructuredSelection());
962 fInhibitTreeSelection
= false;
963 alignTreeItems(false);
967 * Sets the auto-expand level to be used for new entries discovered when
968 * calling {@link #setInput(Object)} or {@link #refresh()}. The value 0
969 * means that there is no auto-expand; 1 means that top-level entries are
970 * expanded, but not their children; 2 means that top-level entries are
971 * expanded, and their children, but not grand-children; and so on.
973 * The value {@link #ALL_LEVELS} means that all subtrees should be expanded.
977 * non-negative level, or <code>ALL_LEVELS</code> to expand all
980 public void setAutoExpandLevel(int level
) {
981 fTimeGraphViewer
.setAutoExpandLevel(level
);
983 fTreeViewer
.setAutoExpandLevel(level
);
985 fTreeViewer
.setAutoExpandLevel(level
+ 1);
990 * Returns the auto-expand level.
992 * @return non-negative level, or <code>ALL_LEVELS</code> if all levels of
993 * the tree are expanded automatically
994 * @see #setAutoExpandLevel
996 public int getAutoExpandLevel() {
997 return fTimeGraphViewer
.getAutoExpandLevel();
1001 * Set the expanded state of an entry
1004 * The entry to expand/collapse
1006 * True for expanded, false for collapsed
1008 public void setExpandedState(ITimeGraphEntry entry
, boolean expanded
) {
1009 fTimeGraphViewer
.setExpandedState(entry
, expanded
);
1010 fTreeViewer
.setExpandedState(entry
, expanded
);
1011 alignTreeItems(true);
1015 * Collapses all nodes of the viewer's tree, starting with the root.
1017 public void collapseAll() {
1018 fTimeGraphViewer
.collapseAll();
1019 fTreeViewer
.collapseAll();
1020 alignTreeItems(true);
1024 * Expands all nodes of the viewer's tree, starting with the root.
1026 public void expandAll() {
1027 fTimeGraphViewer
.expandAll();
1028 fTreeViewer
.expandAll();
1029 alignTreeItems(true);
1032 // ------------------------------------------------------------------------
1034 // ------------------------------------------------------------------------
1036 private List
<TreeItem
> getVisibleExpandedItems(Tree tree
, boolean refresh
) {
1037 if (fVisibleExpandedItems
== null || refresh
) {
1038 List
<TreeItem
> visibleExpandedItems
= new ArrayList
<>();
1039 addVisibleExpandedItems(visibleExpandedItems
, tree
.getItems());
1040 fVisibleExpandedItems
= visibleExpandedItems
;
1042 return fVisibleExpandedItems
;
1045 private void addVisibleExpandedItems(List
<TreeItem
> visibleExpandedItems
, TreeItem
[] items
) {
1046 for (TreeItem item
: items
) {
1047 Object data
= item
.getData();
1048 if (data
== FILLER
) {
1051 visibleExpandedItems
.add(item
);
1052 boolean expandedState
= fTimeGraphViewer
.getExpandedState((ITimeGraphEntry
) data
);
1053 if (item
.getExpanded() != expandedState
) {
1054 /* synchronize the expanded state of both viewers */
1055 fTreeViewer
.setExpandedState(data
, expandedState
);
1057 if (expandedState
) {
1058 addVisibleExpandedItems(visibleExpandedItems
, item
.getItems());
1063 private int getItemHeight(final Tree tree
) {
1065 * Bug in Linux. The method getItemHeight doesn't always return the correct value.
1067 if (fLinuxItemHeight
>= 0 && System
.getProperty("os.name").contains("Linux")) { //$NON-NLS-1$ //$NON-NLS-2$
1068 if (fLinuxItemHeight
!= 0) {
1069 return fLinuxItemHeight
;
1072 if (getVisibleExpandedItems(tree
, true).size() > 1) {
1073 PaintListener paintListener
= new PaintListener() {
1075 public void paintControl(PaintEvent e
) {
1076 // get the treeItems here to have all items
1077 List
<TreeItem
> treeItems
= getVisibleExpandedItems(tree
, true);
1078 if (treeItems
.size() < 2) {
1081 final TreeItem treeItem0
= treeItems
.get(0);
1082 final TreeItem treeItem1
= treeItems
.get(1);
1083 tree
.removePaintListener(this);
1084 int y0
= treeItem0
.getBounds().y
;
1085 int y1
= treeItem1
.getBounds().y
;
1086 int itemHeight
= y1
- y0
;
1087 if (itemHeight
> 0) {
1088 fLinuxItemHeight
= itemHeight
;
1089 fTimeGraphViewer
.setItemHeight(itemHeight
);
1093 tree
.addPaintListener(paintListener
);
1096 fLinuxItemHeight
= -1; // Not Linux, don't perform os.name check anymore
1098 return tree
.getItemHeight();
1101 private void alignTreeItems(boolean refreshExpandedItems
) {
1102 // align the tree top item with the time graph top item
1103 Tree tree
= fTreeViewer
.getTree();
1104 List
<TreeItem
> treeItems
= getVisibleExpandedItems(tree
, refreshExpandedItems
);
1105 int topIndex
= fTimeGraphViewer
.getTopIndex();
1106 if (topIndex
>= treeItems
.size()) {
1109 TreeItem item
= treeItems
.get(topIndex
);
1110 tree
.setTopItem(item
);
1112 // ensure the time graph item heights are equal to the tree item heights
1113 int treeHeight
= fTreeViewer
.getTree().getBounds().height
;
1114 int index
= topIndex
;
1115 Rectangle bounds
= item
.getBounds();
1116 while (index
< treeItems
.size() - 1) {
1117 if (bounds
.y
> treeHeight
) {
1121 * Bug in Linux. The method getBounds doesn't always return the correct height.
1122 * Use the difference of y position between items to calculate the height.
1124 TreeItem nextItem
= treeItems
.get(index
+ 1);
1125 Rectangle nextBounds
= nextItem
.getBounds();
1126 Integer itemHeight
= nextBounds
.y
- bounds
.y
;
1127 if (itemHeight
> 0) {
1128 ITimeGraphEntry entry
= (ITimeGraphEntry
) item
.getData();
1129 fTimeGraphViewer
.getTimeGraphControl().setItemHeight(entry
, itemHeight
);
1133 bounds
= nextBounds
;
1138 * Return the time alignment information
1140 * @return the time alignment information
1142 * @see ITmfTimeAligned
1146 public TmfTimeViewAlignmentInfo
getTimeViewAlignmentInfo() {
1147 Point location
= fSashForm
.toDisplay(0, 0);
1148 int timeAxisOffset
= fTreeViewer
.getControl().getSize().x
+ fSashForm
.getSashWidth();
1149 return new TmfTimeViewAlignmentInfo(fSashForm
.getShell(), location
, timeAxisOffset
);
1153 * Return the available width for the time-axis.
1155 * @see ITmfTimeAligned
1157 * @param requestedOffset
1158 * the requested offset
1159 * @return the available width for the time-axis
1163 public int getAvailableWidth(int requestedOffset
) {
1164 int vBarWidth
= ((fTimeGraphViewer
.getVerticalBar() != null) && (fTimeGraphViewer
.getVerticalBar().isVisible())) ? fTimeGraphViewer
.getVerticalBar().getSize().x
: 0;
1165 int totalWidth
= fSashForm
.getBounds().width
;
1166 return Math
.min(totalWidth
, Math
.max(0, totalWidth
- requestedOffset
- vBarWidth
));
1170 * Perform the alignment operation.
1173 * the alignment offset
1175 * the alignment width
1177 * @see ITmfTimeAligned
1181 public void performAlign(int offset
, int width
) {
1182 int total
= fSashForm
.getBounds().width
;
1183 int timeAxisOffset
= Math
.min(offset
, total
);
1184 int width1
= Math
.max(0, timeAxisOffset
- fSashForm
.getSashWidth());
1185 int width2
= total
- timeAxisOffset
;
1186 fSashForm
.setWeights(new int[] { width1
, width2
});
1189 Composite composite
= fTimeGraphViewer
.getTimeAlignedComposite();
1190 GridLayout layout
= (GridLayout
) composite
.getLayout();
1191 int timeBasedControlsWidth
= composite
.getSize().x
;
1192 int marginSize
= timeBasedControlsWidth
- width
;
1193 layout
.marginRight
= Math
.max(0, marginSize
);