I have two TreeViewer
objects on a page (2 columns, one TreeViewer
in each column), and I want to vertically align a tree when the other is scrolled or selected.
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.swt.widgets.Tree;
I think the solution should look something like
treeViewer.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent arg0) {
TreeViewer mirrorTree = (treeViewer == treeVwrSource ? treeVwrTarget : treeVwrSource);
// find position of selected element (element x) in treeViewer
// set position of element x in mirrorTree, it is already selected.
}
});
Any advice?
From what I've read, scrolling tables or trees isn't directly possible (unless that has changed in the meantime). Programmatically changing the position of the thumb of the scrollbar would not change the viewport of the table/tree.
But you could try if the following snippet works for you:
You would call that code in a
SelectionListener
registered to the vertical scrollbar of your tree (tree.getVerticalBar()
).Synchronizing the selection is fairly easy (if both tree viewers display the same input/model):
(called by the
ISelectionChangedListener
from your question).