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

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

Introduction

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

Prototype

int expandToLevel

To view the source code for org.eclipse.jface.viewers AbstractTreeViewer expandToLevel.

Click Source Link

Document

The level to which the tree is automatically expanded each time the viewer's input is changed (that is, by setInput).

Usage

From source file:com.aptana.workbench.hyperlink.EditorLineHyperlink.java

License:Open Source License

protected void openDirectory(IWorkbenchPage page, IFileStore store) throws CoreException {
    URI uri = store.toURI();// w  w  w.j av a  2s.  c  o  m
    if (!SCHEME_FILE.equals(uri.getScheme())) {
        return;
    }
    File file = store.toLocalFile(EFS.NONE, new NullProgressMonitor());
    IContainer container = ResourcesPlugin.getWorkspace().getRoot()
            .getContainerForLocation(Path.fromOSString(file.getAbsolutePath()));
    if (container == null) {
        // If this is an external directory, open it in the "finder" - OpenInFinderHandler.open(uri)
        IHandlerService service = (IHandlerService) page.getActivePart().getSite()
                .getService(IHandlerService.class);
        ICommandService commandService = (ICommandService) page.getActivePart().getSite()
                .getService(ICommandService.class);
        Command command = commandService.getCommand(IUIConstants.OPEN_IN_OS_FILE_MANAGER_ID);
        ParameterizedCommand pc = ParameterizedCommand.generateCommand(command, null);
        List<Object> list = new ArrayList<Object>();
        list.add(store);
        IEvaluationContext context = new EvaluationContext(service.getCurrentState(), list);
        context.addVariable(ISources.SHOW_IN_SELECTION, new StructuredSelection(list));
        try {
            service.executeCommandInContext(pc, null, context);
        } catch (Exception e) {
            // ignore
        }
        return;
    }
    // Select in the App Explorer
    IViewReference[] viewRefs = page.getViewReferences();
    for (IViewReference ref : viewRefs) {
        if (IExplorerUIConstants.VIEW_ID.equals(ref.getId())) {
            IViewPart part = (IViewPart) ref.getPart(false);
            if (part != null && part instanceof ISetSelectionTarget) {
                // Select the directory!
                ISetSelectionTarget target = (ISetSelectionTarget) part;
                target.selectReveal(new StructuredSelection(container));
            }
            // Also expand it, if possible
            if (part != null && part instanceof CommonNavigator) {
                CommonNavigator navigator = (CommonNavigator) part;
                AbstractTreeViewer treeViewer = navigator.getCommonViewer();
                treeViewer.expandToLevel(container, 1);
            }
        }
    }
}

From source file:com.nokia.carbide.cpp.internal.project.ui.mmpEditor.TreeViewerHandler.java

License:Open Source License

public void refreshElement(Object element) {
    AbstractTreeViewer tv = treeViewer();
    tv.refresh(element);
    tv.expandToLevel(expandLevel);
}

From source file:de.walware.ecommons.ui.util.ViewerUtil.java

License:Open Source License

/**
 * {@link AbstractTreeViewer#expandToLevel(Object, int)}
 * // w w  w  .  jav a2  s.com
 * Workaround for E bug #54116
 */
public static void expandToLevel(final AbstractTreeViewer viewer, final Object element, final int level) {
    viewer.expandToLevel(element, level);
    for (TreeItem item = (TreeItem) viewer.testFindItem(element); item != null; item = item.getParentItem()) {
        item.setExpanded(true);
    }
}

From source file:org.cs3.pdt.common.search.PrologSearchResultPage.java

License:Open Source License

@Override
protected void configureTreeViewer(TreeViewer viewer) {
    viewer.setLabelProvider(new DecoratingPrologSearchLabelProvider(new PrologSearchLabelProvider()));
    ColumnViewerToolTipSupport.enableFor(viewer, ToolTip.NO_RECREATE);
    //      viewer.setLabelProvider(new DecoratingLabelProvider(new PrologSearchLabelProvider(), 
    //            PlatformUI.getWorkbench().getDecoratorManager().getLabelDecorator()));
    fContentProvider = new PrologSearchTreeContentProvider(this);
    viewer.setContentProvider(fContentProvider);
    viewer.addDoubleClickListener(new IDoubleClickListener() {
        @Override//from www .ja  va 2 s. co m
        public void doubleClick(DoubleClickEvent event) {
            ISelection selection = event.getSelection();
            if (selection instanceof TreeSelection) {
                Object firstElement = ((TreeSelection) selection).getFirstElement();
                Match m = null;
                if (firstElement instanceof SearchModuleElement) {
                    m = ((SearchModuleElement) firstElement).getMatch();
                } else if (firstElement instanceof SearchPredicateElement) {
                    m = ((SearchPredicateElement) firstElement).getFirstOccurrence();
                } else if (firstElement instanceof SearchFileTreeElement) {
                    m = ((SearchFileTreeElement) firstElement).getFirstMatch();
                }
                if (m != null) {
                    final Match match = m;
                    UIJob job = new UIJob("Show Match") {
                        @Override
                        public IStatus runInUIThread(IProgressMonitor monitor) {
                            try {
                                showMatch(match, match.getOffset(), match.getLength(), true);
                            } catch (PartInitException e) {
                                Debug.report(e);
                            }
                            return Status.OK_STATUS;
                        }
                    };
                    job.schedule();
                }
            }
        }
    });
    viewer.addTreeListener(new ITreeViewerListener() {
        @Override
        public void treeExpanded(TreeExpansionEvent event) {
            final AbstractTreeViewer treeViewer = event.getTreeViewer();
            PrologSearchTreeContentProvider contentProvider = (PrologSearchTreeContentProvider) treeViewer
                    .getContentProvider();
            final Object element = event.getElement();
            int expandLevel = 1;
            Object[] children = contentProvider.getChildren(element);
            while (children.length == 1) {
                expandLevel++;
                children = contentProvider.getChildren(children[0]);
            }
            if (expandLevel > 1) {
                final int finalExpandLevel = expandLevel;
                treeViewer.getControl().getDisplay().asyncExec(new Runnable() {
                    @Override
                    public void run() {
                        treeViewer.expandToLevel(element, finalExpandLevel);
                    }
                });
            }
        }

        @Override
        public void treeCollapsed(TreeExpansionEvent event) {
        }
    });
}

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   ww  w  . j  av a2  s . co 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;/*w w  w .j  a v a  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);
        }
    }
}

From source file:org.eclipse.wst.dtd.ui.views.contentoutline.DTDTreeContentProvider.java

License:Open Source License

private void expandToNode(DTDNode node) {
    DTDFile dtdFile = node.getDTDFile();
    // first expand the root
    AbstractTreeViewer viewer = (AbstractTreeViewer) fViewer;
    viewer.expandToLevel(dtdFile, 1);
    NodeList listToExpand = null;
    if (node instanceof Element || node instanceof ParameterEntityReference) {
        listToExpand = dtdFile.getElementsAndParameterEntityReferences();
    } else if (node instanceof Notation) {
        listToExpand = dtdFile.getNotations();
    } else if (node instanceof Entity) {
        listToExpand = dtdFile.getEntities();
    } else if (node instanceof Comment) {
        listToExpand = dtdFile.getComments();
    }//from w w  w . j  a va2s.c o  m
    if (listToExpand != null) {
        viewer.expandToLevel(listToExpand, 1);
    }
    viewer.expandToLevel(node, 0);
}