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

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

Introduction

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

Prototype

protected abstract void setSelection(List<Item> items);

Source Link

Document

Sets the selection to the given list of items.

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 a v a2  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.fusesource.ide.foundation.ui.util.Nodes.java

License:Open Source License

public static void selectPath(Viewer viewer, Node root, LinkedList<String> path) {
    List<Node> nodes = new ArrayList<Node>();
    Node node = root;//  ww w  .ja  v a  2s.  c o m
    nodes.add(node);
    for (String text : path) {
        node = findChild(node, text);
        if (node == null) {
            break;
        } else {
            nodes.add(node);
        }
    }
    if (node != null && viewer instanceof AbstractTreeViewer) {
        AbstractTreeViewer tv = (AbstractTreeViewer) viewer;
        Object[] expandElements = nodes.toArray();
        tv.setExpandedElements(expandElements);
        /*
        TreePath[] expandedTreePaths = tv.getExpandedTreePaths();
        boolean found = false;
        if (expandElements.length > 0) {
           Object expandRoot = expandElements[0];
           for (TreePath treePath : expandedTreePaths) {
              int count = treePath.getSegmentCount();
              for (int i = 0; i < count; i++) {
          Object first = treePath.getSegment(i);
          if (first == expandRoot) {
             // TODO do we need to add the previous nodes?
             found = true;
          }
                
              }
           }
        }
        if (!found) {
           Activator.getLogger().debug("Could not find root expanded path!!");
        }
         */
        tv.setSelection(new StructuredSelection(node));
    }
}