Example usage for org.eclipse.jface.viewers AbstractTreeViewer getSelection

List of usage examples for org.eclipse.jface.viewers AbstractTreeViewer getSelection

Introduction

In this page you can find the example usage for org.eclipse.jface.viewers AbstractTreeViewer getSelection.

Prototype

@Override
public ISelection getSelection() 

Source Link

Document

The AbstractTreeViewer implementation of this method returns the result as an ITreeSelection.

Usage

From source file:org.eclipse.jubula.client.ui.rcp.businessprocess.UINodeBP.java

License:Open Source License

/**
 * Tries to select the given node in the given TreeViewer.
 * //from  w  w  w .j ava2  s  .c  o m
 * @param o
 *            The Object to select
 * @param tv
 *            the TreeViewer
 * @return the object which should be selected if found in tree viewer, null
 *         otherwise
 */
public static Object selectNodeInTree(Object o, AbstractTreeViewer tv) {
    ISelection oldSelection = tv.getSelection();
    if (o != null) {
        tv.refresh();
        tv.expandToLevel(o, 0);
        tv.reveal(o);
        StructuredSelection newSelection = new StructuredSelection(o);
        tv.setSelection(newSelection);
        InteractionEventDispatcher.getDefault().fireProgammableSelectionEvent(newSelection);
        ISelection currSelection = tv.getSelection();
        if (currSelection instanceof StructuredSelection) {
            Object currObj = ((StructuredSelection) currSelection).getFirstElement();
            IElementComparer comparer = tv.getComparer();
            if (comparer != null) {
                if (comparer.equals(o, currObj)) {
                    return o;
                }
            } else {
                if (o.equals(currObj)) {
                    return o;
                }
            }
        }
    }
    tv.setSelection(oldSelection);
    return null;
}

From source file:org.eclipse.team.internal.ui.synchronize.actions.ExpandAllAction.java

License:Open Source License

protected void expandAllFromSelection() {
    AbstractTreeViewer tree = viewer;
    if (tree == null)
        return;/*from   w  w  w  .java 2 s.  c  o  m*/
    ISelection selection = tree.getSelection();
    if (!selection.isEmpty()) {
        Iterator elements = ((IStructuredSelection) selection).iterator();
        try {
            tree.getControl().setRedraw(false);
            while (elements.hasNext()) {
                Object next = elements.next();
                tree.expandToLevel(next, AbstractTreeViewer.ALL_LEVELS);
            }
        } finally {
            tree.getControl().setRedraw(true);
        }
    }
}