Example usage for org.eclipse.jface.viewers StructuredSelection StructuredSelection

List of usage examples for org.eclipse.jface.viewers StructuredSelection StructuredSelection

Introduction

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

Prototype

public StructuredSelection(List elements) 

Source Link

Document

Creates a structured selection from the given List.

Usage

From source file:ch.parisi.e4.advancedlaunch.dialog.MultiLaunchConfigurationSelectionDialog.java

License:Open Source License

public void setInitialSelection(ILaunchConfiguration launchConfiguration) {
    fInitialSelection = new StructuredSelection(launchConfiguration);
}

From source file:ch.wess.ezclipse.tpl.editor.TPLEditor.java

License:Open Source License

/**
 * Return the selection that will be given to the selection change
 * listeners.//from  w  w w.  ja v a 2  s . c  o m
 * 
 * @return the current input file.
 */
@Override
public ISelection getSelection() {
    return new StructuredSelection(getInputFile());
}

From source file:cideplus.ui.astview.ASTView.java

License:Open Source License

private CompilationUnit internalSetInput(ITypeRoot input, int offset, int length, int astLevel)
        throws CoreException {
    if (input.getBuffer() == null) {
        throw new CoreException(getErrorStatus("Input has no buffer", null)); //$NON-NLS-1$
    }/*from  w ww  .  j  av  a2 s . c  om*/

    try {
        CompilationUnit root = createAST(input, astLevel, offset);
        resetView(root);
        if (root == null) {
            setContentDescription("AST could not be created."); //$NON-NLS-1$
            return null;
        }
        ASTNode node = NodeFinder.perform(root, offset, length);
        if (node != null) {
            fViewer.getTree().setRedraw(false);
            try {
                fASTLabelProvider.setSelectedRange(node.getStartPosition(), node.getLength());
                fViewer.setSelection(new StructuredSelection(node), true);
            } finally {
                fViewer.getTree().setRedraw(true);
            }
        }
        return root;

    } catch (RuntimeException e) {
        throw new CoreException(getErrorStatus("Could not create AST:\n" + e.getMessage(), e)); //$NON-NLS-1$
    }
}

From source file:cideplus.ui.astview.ASTView.java

License:Open Source License

private void doLinkWithEditor(ISelection selection) {
    ITextSelection textSelection = (ITextSelection) selection;
    int offset = textSelection.getOffset();
    int length = textSelection.getLength();

    NodeFinder finder = new NodeFinder(offset, length);
    fRoot.accept(finder);/*w w w .j  a v  a  2 s.  co m*/
    ASTNode covering = finder.getCoveringNode();
    if (covering != null) {
        fViewer.reveal(covering);
        fViewer.setSelection(new StructuredSelection(covering));
    }
}

From source file:cideplus.ui.astview.ASTView.java

License:Open Source License

protected void performFindDeclaringNode() {
    String msg = "Find Declaring Node from Key";
    String key = askForKey(msg);//from   w  w  w  . ja v  a  2 s  .c  o  m
    if (key == null)
        return;
    ASTNode node = fRoot.findDeclaringNode(key);
    if (node != null) {
        fViewer.setSelection(new StructuredSelection(node), true);
    } else {
        MessageDialog.openError(getSite().getShell(), "Find Declaring Node from Key",
                "The declaring node for key '" + key + "' could not be found");
    }
}

From source file:cideplus.ui.astview.ASTView.java

License:Open Source License

protected void performParseBindingFromKey() {
    String msg = "Parse Binding from Key";
    String key = askForKey(msg);//w ww  .j av a  2s .  c o  m
    if (key == null)
        return;
    ASTParser parser = ASTParser.newParser(fCurrentASTLevel);
    parser.setResolveBindings(true);
    parser.setProject(fTypeRoot.getJavaProject());
    class MyASTRequestor extends ASTRequestor {
        String fBindingKey;
        IBinding fBinding;

        @Override
        public void acceptBinding(String bindingKey, IBinding binding) {
            fBindingKey = bindingKey;
            fBinding = binding;
        }
    }
    MyASTRequestor requestor = new MyASTRequestor();
    ASTAttribute item;
    Object viewerInput = fViewer.getInput();
    try {
        parser.createASTs(new ICompilationUnit[0], new String[] { key }, requestor, null);
        if (requestor.fBindingKey != null) {
            String name = requestor.fBindingKey + ": " + Binding.getBindingLabel(requestor.fBinding);
            item = new Binding(viewerInput, name, requestor.fBinding, true);
        } else {
            item = new Error(viewerInput, "Key not resolved: " + key, null);
        }
    } catch (RuntimeException e) {
        item = new Error(viewerInput, "Error resolving key: " + key, e);
    }
    fViewer.add(viewerInput, item);
    fViewer.setSelection(new StructuredSelection(item), true);
}

From source file:cideplus.ui.astview.ASTView.java

License:Open Source License

protected void performParseBindingFromElement() {
    InputDialog dialog = new InputDialog(getSite().getShell(), "Parse Binding from Java Element",
            "IJavaElement#getHandleIdentifier():", "", null);
    if (dialog.open() != Window.OK)
        return;/* w  w w  .  java 2s.com*/

    String handleIdentifier = dialog.getValue();
    IJavaElement handle = JavaCore.create(handleIdentifier);

    Object viewerInput = fViewer.getInput();
    ASTAttribute item;
    if (handle == null) {
        item = new Error(viewerInput, "handleIdentifier not resolved: " + handleIdentifier, null);
    } else if (!handle.exists()) {
        item = new Error(viewerInput, "element does not exist: " + handleIdentifier, null);
    } else if (handle.getJavaProject() == null) {
        item = new Error(viewerInput, "getJavaProject() is null: " + handleIdentifier, null);
    } else {
        IJavaProject project = handle.getJavaProject();
        ASTParser parser = ASTParser.newParser(fCurrentASTLevel);
        parser.setProject(project);
        IBinding[] bindings = parser.createBindings(new IJavaElement[] { handle }, null);
        String name = handleIdentifier + ": " + Binding.getBindingLabel(bindings[0]);
        item = new Binding(viewerInput, name, bindings[0], true);
    }
    fViewer.add(viewerInput, item);
    fViewer.setSelection(new StructuredSelection(item), true);
}

From source file:cideplus.ui.astview.ASTView.java

License:Open Source License

protected void performDoubleClick() {
    if (fEditor == null) {
        return;/*from w ww.  j  a va  2s  .  co  m*/
    }

    ISelection selection = fViewer.getSelection();
    Object obj = ((IStructuredSelection) selection).getFirstElement();

    boolean isTripleClick = (obj == fPreviousDouble);
    fPreviousDouble = isTripleClick ? null : obj;

    if (obj instanceof ExceptionAttribute) {
        Throwable exception = ((ExceptionAttribute) obj).getException();
        if (exception != null) {
            String label = ((ExceptionAttribute) obj).getLabel();
            showAndLogError("An error occurred while calculating an AST View Label:\n" + label, exception); //$NON-NLS-1$
            return;
        }
    }

    ASTNode node = null;
    if (obj instanceof ASTNode) {
        node = (ASTNode) obj;

    } else if (obj instanceof NodeProperty) {
        Object val = ((NodeProperty) obj).getNode();
        if (val instanceof ASTNode) {
            node = (ASTNode) val;
        }

    } else if (obj instanceof Binding) {
        IBinding binding = ((Binding) obj).getBinding();
        ASTNode declaring = fRoot.findDeclaringNode(binding);
        if (declaring != null) {
            fViewer.reveal(declaring);
            fViewer.setSelection(new StructuredSelection(declaring));
        } else {
            fViewer.getTree().getDisplay().beep();
        }
        return;

    } else if (obj instanceof ProblemNode) {
        ProblemNode problemNode = (ProblemNode) obj;
        EditorUtility.selectInEditor(fEditor, problemNode.getOffset(), problemNode.getLength());
        return;

    } else if (obj instanceof JavaElement) {
        IJavaElement javaElement = ((JavaElement) obj).getJavaElement();
        if (javaElement instanceof IPackageFragment) {
            ShowInPackageViewAction showInPackageViewAction = new ShowInPackageViewAction(getViewSite());
            showInPackageViewAction.run(javaElement);
        } else {
            try {
                IEditorPart editorPart = JavaUI.openInEditor(javaElement);
                if (editorPart != null)
                    JavaUI.revealInEditor(editorPart, javaElement);
            } catch (PartInitException e) {
                showAndLogError("Could not open editor.", e); //$NON-NLS-1$
            } catch (JavaModelException e) {
                showAndLogError("Could not open editor.", e); //$NON-NLS-1$
            }
        }
        return;
    }

    if (node != null) {
        int offset = isTripleClick ? fRoot.getExtendedStartPosition(node) : node.getStartPosition();
        int length = isTripleClick ? fRoot.getExtendedLength(node) : node.getLength();

        EditorUtility.selectInEditor(fEditor, offset, length);
    }
}

From source file:cideplus.ui.astview.ASTView.java

License:Open Source License

protected void performTrayDoubleClick() {
    IStructuredSelection selection = (IStructuredSelection) fTray.getSelection();
    if (selection.size() != 1)
        return;//from  ww w.j a  va  2s . com
    Object obj = selection.getFirstElement();
    if (obj instanceof ExceptionAttribute) {
        Throwable exception = ((ExceptionAttribute) obj).getException();
        if (exception != null) {
            String label = ((ExceptionAttribute) obj).getLabel();
            showAndLogError("An error occurred while calculating an AST View Label:\n" + label, exception); //$NON-NLS-1$
            return;
        }
    }
    if (obj instanceof Binding) {
        Binding binding = (Binding) obj;
        fViewer.setSelection(new StructuredSelection(binding), true);
    }
}

From source file:cn.dockerfoundry.ide.eclipse.server.ui.internal.editor.DockerFoundryApplicationsEditorPage.java

License:Open Source License

public void selectAndReveal(IModule module) {
    // Refresh the UI immediately with the cached information for the module
    masterDetailsBlock.refreshUI(RefreshArea.MASTER);
    TableViewer viewer = masterDetailsBlock.getMasterPart().getApplicationsViewer();
    viewer.setSelection(new StructuredSelection(module));

    // Launch a fresh operation that will update the module. As this is
    // longer/*from   w w  w  .j  av a2s . co m*/
    // running, it will eventually refresh the UI via events
    refresh(RefreshArea.DETAIL);
}