Example usage for org.eclipse.jface.viewers TreeViewer setExpandedState

List of usage examples for org.eclipse.jface.viewers TreeViewer setExpandedState

Introduction

In this page you can find the example usage for org.eclipse.jface.viewers TreeViewer setExpandedState.

Prototype

public void setExpandedState(Object elementOrTreePath, boolean expanded) 

Source Link

Document

Sets whether the node corresponding to the given element or tree path is expanded or collapsed.

Usage

From source file:org.eclipse.birt.report.designer.ui.lib.explorer.LibraryExplorerTreeViewPage.java

License:Open Source License

/**
 * Handles a double-click event from the viewer.
 * /*ww  w .  ja  v  a 2s  .c  o  m*/
 * @param event
 *            the double-click event
 */
protected void handleDoubleClick(DoubleClickEvent event) {
    IStructuredSelection selection = (IStructuredSelection) event.getSelection();
    Object element = selection.getFirstElement();
    TreeViewer viewer = getTreeViewer();

    if (element instanceof ResourceEntryWrapper) {
        switch (((ResourceEntryWrapper) element).getType()) {
        case ResourceEntryWrapper.LIBRARY:
            return;

        case ResourceEntryWrapper.CSS_STYLE_SHEET:
        default:
            break;
        }
    }

    if (viewer.isExpandable(element)) {
        viewer.setExpandedState(element, !viewer.getExpandedState(element));
    }
}

From source file:org.eclipse.cdt.ui.tests.callhierarchy.CallHierarchyAcrossProjectsTest.java

License:Open Source License

public void testMethodsInMultipleFiles() throws Exception {
    StringBuilder[] content = getContentsForTest(3);
    String header = content[0].toString();
    String source1 = content[1].toString();
    String source2 = content[2].toString();
    IFile headerFile = createFile(fCProject.getProject(), "testMethods.h", header);
    IFile sourceFile1 = createFile(fCProject.getProject(), "testMethods1.cpp", source1);
    IFile sourceFile2 = createFile(fCProject2.getProject(), "testMethods2.cpp", source2);

    CEditor editor = openEditor(sourceFile1);
    waitUntilFileIsIndexed(fIndex, sourceFile2);

    editor.selectAndReveal(source1.indexOf("method3"), 2);
    openCallHierarchy(editor);// www . j ava  2  s.co m
    TreeViewer tv = getCHTreeViewer();

    checkTreeNode(tv.getTree(), 0, "MyClass::method3() : void");
    TreeItem item = checkTreeNode(tv.getTree(), 0, 0, "MyClass::method2() : void");
    checkTreeNode(tv.getTree(), 0, 1, null);
    tv.setExpandedState(item.getData(), true);
    TreeItem nextItem = checkTreeNode(item, 0, "MyClass::method1() : void");
    checkTreeNode(item, 1, null);
    item = nextItem;
    tv.setExpandedState(item.getData(), true);
    checkTreeNode(item, 0, null);
}

From source file:org.eclipse.cdt.ui.tests.callhierarchy.CallHierarchyAcrossProjectsTest.java

License:Open Source License

public void testMultipleImplsForMethod() throws Exception {
    StringBuilder[] content = getContentsForTest(3);
    String header = content[0].toString();
    String source1 = content[1].toString();
    String source2 = content[2].toString();
    IFile headerFile = createFile(getProject(), "testMethods.h", header);
    IFile sourceFile1 = createFile(fCProject2.getProject(), "testMethods1.cpp", source1);
    IFile sourceFile2 = createFile(getProject(), "testMethods2.cpp", source2);

    CEditor editor = openEditor(sourceFile1);
    waitUntilFileIsIndexed(fIndex, sourceFile1);
    waitUntilFileIsIndexed(fIndex, sourceFile2);

    editor.selectAndReveal(source1.indexOf("method3"), 2);
    openCallHierarchy(editor);//from   w  w  w  . jav a 2  s .  c  om
    TreeViewer tv = getCHTreeViewer();

    checkTreeNode(tv.getTree(), 0, "MyClass::method3() : void");
    TreeItem item0 = checkTreeNode(tv.getTree(), 0, 0, "MyClass::method1() : void");
    TreeItem item1 = checkTreeNode(tv.getTree(), 0, 1, "MyClass::method2() : void");
    checkTreeNode(tv.getTree(), 0, 2, null);

    // method 1
    tv.setExpandedState(item0.getData(), true);
    checkTreeNode(item0, 0, null);

    // method 2
    tv.setExpandedState(item1.getData(), true);
    TreeItem nextItem = checkTreeNode(item1, 0, "MyClass::method1() : void");
    checkTreeNode(item1, 1, null);
    item1 = nextItem;
    tv.setExpandedState(item1.getData(), true);
    checkTreeNode(item1, 0, null);
}

From source file:org.eclipse.cdt.ui.tests.callhierarchy.CallHierarchyAcrossProjectsTest.java

License:Open Source License

public void testReverseMultipleImplsForMethod() throws Exception {
    StringBuilder[] content = getContentsForTest(3);
    String header = content[0].toString();
    String source1 = content[1].toString();
    String source2 = content[2].toString();
    IFile headerFile = createFile(getProject(), "testMethods.h", header);
    IFile sourceFile1 = createFile(getProject(), "testMethods1.cpp", source1);
    IFile sourceFile2 = createFile(getProject(), "testMethods2.cpp", source2);

    CEditor editor = openEditor(sourceFile2);
    waitUntilFileIsIndexed(fIndex, sourceFile2);

    editor.selectAndReveal(source2.indexOf("main"), 2);
    openCallHierarchy(editor, false);/*  w w  w.j ava  2s.c om*/
    TreeViewer tv = getCHTreeViewer();

    final Tree tree = tv.getTree();
    checkTreeNode(tree, 0, "main() : void");
    TreeItem item = checkTreeNode(tree, 0, 0, "MyClass::method1() : void");
    checkTreeNode(tree, 0, 1, null);
    tv.setExpandedState(item.getData(), true);

    TreeItem item0 = checkTreeNode(item, 0, "MyClass::method1() : void");
    TreeItem item1 = checkTreeNode(item, 1, "MyClass::method1() : void");
    checkTreeNode(item, 2, null);
    item = null;

    try {
        tv.setExpandedState(item0.getData(), true);
        checkTreeNode(item0, 0, "MyClass::method2() : void");
    } catch (Throwable e) {
        TreeItem tmp = item0;
        item0 = item1;
        item1 = tmp;
    }

    // method 1
    tv.setExpandedState(item0.getData(), true);
    TreeItem nextItem = checkTreeNode(item0, 0, "MyClass::method2() : void");
    checkTreeNode(item0, 1, null);
    item0 = nextItem;
    tv.setExpandedState(item0.getData(), true);
    checkTreeNode(item0, 0, null);

    // method 2
    tv.setExpandedState(item1.getData(), true);
    nextItem = checkTreeNode(item1, 0, "MyClass::method3() : void");
    checkTreeNode(item1, 1, null);
    item1 = nextItem;
    tv.setExpandedState(item1.getData(), true);
    checkTreeNode(item1, 0, null);
}

From source file:org.eclipse.cdt.ui.tests.callhierarchy.CppCallHierarchyTest.java

License:Open Source License

public void testMethodsInMultipleFiles() throws Exception {
    CharSequence[] content = getContentsForTest(3);
    String header = content[0].toString();
    String source1 = content[1].toString();
    String source2 = content[2].toString();
    IFile headerFile = createFile(getProject(), "testMethods.h", header);
    IFile sourceFile1 = createFile(getProject(), "testMethods1.cpp", source1);
    IFile sourceFile2 = createFile(getProject(), "testMethods2.cpp", source2);

    CEditor editor = openEditor(sourceFile1);
    waitUntilFileIsIndexed(fIndex, sourceFile2);

    editor.selectAndReveal(source1.indexOf("method3"), 2);
    openCallHierarchy(editor);// www  . j a  va2s.  co  m
    TreeViewer tv = getCHTreeViewer();

    checkTreeNode(tv.getTree(), 0, "MyClass::method3() : void");
    TreeItem item = checkTreeNode(tv.getTree(), 0, 0, "MyClass::method2() : void");
    checkTreeNode(tv.getTree(), 0, 1, null);
    tv.setExpandedState(item.getData(), true);
    TreeItem nextItem = checkTreeNode(item, 0, "MyClass::method1() : void");
    checkTreeNode(item, 1, null);
    item = nextItem;
    tv.setExpandedState(item.getData(), true);
    checkTreeNode(item, 0, null);
}

From source file:org.eclipse.cdt.ui.tests.callhierarchy.CppCallHierarchyTest.java

License:Open Source License

public void testMultipleImplsForMethod() throws Exception {
    CharSequence[] content = getContentsForTest(3);
    String header = content[0].toString();
    String source1 = content[1].toString();
    String source2 = content[2].toString();
    IFile headerFile = createFile(getProject(), "testMethods.h", header);
    IFile sourceFile1 = createFile(getProject(), "testMethods1.cpp", source1);
    IFile sourceFile2 = createFile(getProject(), "testMethods2.cpp", source2);

    waitUntilFileIsIndexed(fIndex, sourceFile2);

    CEditor editor = openEditor(sourceFile1);
    editor.selectAndReveal(source1.indexOf("method3"), 2);
    openCallHierarchy(editor);//from  w w  w  .j  ava 2s .c o  m
    TreeViewer tv = getCHTreeViewer();

    TreeItem item = checkTreeNode(tv.getTree(), 0, "MyClass::method3() : void");
    TreeItem item0 = checkTreeNode(tv.getTree(), 0, 0, "MyClass::method1() : void");
    TreeItem item1 = checkTreeNode(tv.getTree(), 0, 1, "MyClass::method2() : void");
    checkTreeNode(tv.getTree(), 0, 2, null);
    item = null;

    // method 1
    tv.setExpandedState(item0.getData(), true);
    checkTreeNode(item0, 0, null);

    // method 2
    tv.setExpandedState(item1.getData(), true);
    TreeItem nextItem = checkTreeNode(item1, 0, "MyClass::method1() : void");
    checkTreeNode(item1, 1, null);
    item1 = nextItem;
    tv.setExpandedState(item1.getData(), true);
    checkTreeNode(item1, 0, null);
}

From source file:org.eclipse.cdt.ui.tests.callhierarchy.CppCallHierarchyTest.java

License:Open Source License

public void testReverseMultipleImplsForMethod() throws Exception {
    CharSequence[] content = getContentsForTest(3);
    String header = content[0].toString();
    String source1 = content[1].toString();
    String source2 = content[2].toString();
    IFile headerFile = createFile(getProject(), "testMethods.h", header);
    IFile sourceFile1 = createFile(getProject(), "testMethods1.cpp", source1);
    IFile sourceFile2 = createFile(getProject(), "testMethods2.cpp", source2);

    CEditor editor = openEditor(sourceFile2);
    waitUntilFileIsIndexed(fIndex, sourceFile2);

    editor.selectAndReveal(source2.indexOf("main"), 2);
    openCallHierarchy(editor, false);//from www . j a va  2  s .com
    TreeViewer tv = getCHTreeViewer();

    checkTreeNode(tv.getTree(), 0, "main() : void");
    TreeItem item = checkTreeNode(tv.getTree(), 0, 0, "MyClass::method1() : void");
    checkTreeNode(tv.getTree(), 0, 1, null);
    tv.setExpandedState(item.getData(), true);

    TreeItem item0 = checkTreeNode(item, 0, "MyClass::method1() : void");
    TreeItem item1 = checkTreeNode(item, 1, "MyClass::method1() : void");
    checkTreeNode(item, 2, null);
    item = null;

    // method 1
    try {
        tv.setExpandedState(item0.getData(), true);
        checkTreeNode(item0, 0, "MyClass::method2() : void");
    } catch (Throwable e) {
        TreeItem tmp = item0;
        item0 = item1;
        item1 = tmp;
    }
    expandTreeItem(item0);
    item = checkTreeNode(item0, 0, "MyClass::method2() : void");
    checkTreeNode(item0, 1, null);
    item0 = item;
    tv.setExpandedState(item0.getData(), true);
    checkTreeNode(item0, 0, null);

    // method 2
    tv.setExpandedState(item1.getData(), true);
    item = checkTreeNode(item1, 0, "MyClass::method3() : void");
    checkTreeNode(item1, 1, null);
    item1 = item;
    tv.setExpandedState(item1.getData(), true);
    checkTreeNode(item1, 0, null);
}

From source file:org.eclipse.datatools.connectivity.ui.actions.ConnectAction.java

License:Open Source License

/**
 * This method blocks until the connection has been created.
 * //ww w  .j av a 2  s  . c o  m
 * @param profile
 * @param viewer
 * 
 * @deprecated use IConnectionProfile.connect(). The caller is now
 *             responsible for updating their view themselves. Note, if you
 *             are using a servers viewer, you should not need to update the
 *             view as the view listens for connect events and updates
 *             itself.
 */
public static void connectAndRefresh(IConnectionProfile profile, TreeViewer viewer) {
    profile.connect();

    viewer.refresh(profile);
    viewer.setExpandedState(profile, true);
}

From source file:org.eclipse.dltk.internal.ui.scriptview.ScriptExplorerActionGroup.java

License:Open Source License

protected void handleDoubleClick(DoubleClickEvent event) {
    TreeViewer viewer = fPart.getTreeViewer();
    IStructuredSelection selection = (IStructuredSelection) event.getSelection();
    Object element = selection.getFirstElement();
    if (viewer.isExpandable(element)) {
        if (doubleClickGoesInto()) {
            // don't zoom into compilation units and class files
            if (element instanceof ISourceModule)
                return;
            if (element instanceof IOpenable || element instanceof IContainer
                    || element instanceof IWorkingSet) {
                fZoomInAction.run();//from  w ww.j a  v  a  2 s.c om
            }
        } else {
            IAction openAction = fNavigateActionGroup.getOpenAction();
            if (openAction != null && openAction.isEnabled()
                    && OpenStrategy.getOpenMethod() == OpenStrategy.DOUBLE_CLICK)
                return;
            if (selection instanceof ITreeSelection) {
                TreePath[] paths = ((ITreeSelection) selection).getPathsFor(element);
                for (int i = 0; i < paths.length; i++) {
                    viewer.setExpandedState(paths[i], !viewer.getExpandedState(paths[i]));
                }
            } else {
                viewer.setExpandedState(element, !viewer.getExpandedState(element));
            }
        }
    } else if (element instanceof IProject && !((IProject) element).isOpen()) {
        OpenProjectAction openProjectAction = fProjectActionGroup.getOpenProjectAction();
        if (openProjectAction.isEnabled()) {
            openProjectAction.run();
        }
    }
}

From source file:org.eclipse.dltk.mod.internal.ui.scriptview.ScriptExplorerActionGroup.java

License:Open Source License

void handleDoubleClick(DoubleClickEvent event) {
    TreeViewer viewer = fPart.getTreeViewer();
    IStructuredSelection selection = (IStructuredSelection) event.getSelection();
    Object element = selection.getFirstElement();
    if (viewer.isExpandable(element)) {
        if (doubleClickGoesInto()) {
            // don't zoom into compilation units and class files
            if (element instanceof ISourceModule)
                return;
            if (element instanceof IOpenable || element instanceof IContainer
                    || element instanceof IWorkingSet) {
                fZoomInAction.run();/*  w ww.ja v a 2  s .c o m*/
            }
        } else {
            IAction openAction = fNavigateActionGroup.getOpenAction();
            if (openAction != null && openAction.isEnabled()
                    && OpenStrategy.getOpenMethod() == OpenStrategy.DOUBLE_CLICK)
                return;
            if (selection instanceof ITreeSelection) {
                TreePath[] paths = ((ITreeSelection) selection).getPathsFor(element);
                for (int i = 0; i < paths.length; i++) {
                    viewer.setExpandedState(paths[i], !viewer.getExpandedState(paths[i]));
                }
            } else {
                viewer.setExpandedState(element, !viewer.getExpandedState(element));
            }
        }
    }
}