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:cn.dockerfoundry.ide.eclipse.server.ui.internal.EnvironmentVariablesPart.java

License:Open Source License

protected void setViewerSelection(EnvironmentVariable var) {
    if (var != null) {
        envVariablesViewer.setSelection(new StructuredSelection(var));
    }//from w w w. j  a va 2s .  c  o  m
}

From source file:cn.ieclipse.adt.ext.actions.OpenWizardAction.java

License:Apache License

public void run(IAction action) {
    IWorkbench workbench = (this.mWorkbench != null) ? this.mWorkbench : PlatformUI.getWorkbench();
    IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();

    ISelection selection = this.mSelection;
    if (selection == null) {
        selection = window.getSelectionService().getSelection();
    }//www.  j av  a  2  s  . co m

    IStructuredSelection selectionToPass = StructuredSelection.EMPTY;
    if (selection instanceof IStructuredSelection) {
        selectionToPass = (IStructuredSelection) selection;
    } else {
        IWorkbenchPart part = window.getPartService().getActivePart();
        if (part instanceof IEditorPart) {
            IEditorInput input = ((IEditorPart) part).getEditorInput();
            Class fileClass = LegacyResourceSupport.getFileClass();
            if ((input != null) && (fileClass != null)) {
                Object file = Util.getAdapter(input, fileClass);
                if (file != null) {
                    selectionToPass = new StructuredSelection(file);
                }
            }

        }

    }

    this.mWizard = instanciateWizard(action);
    this.mWizard.init(workbench, selectionToPass);

    Shell parent = window.getShell();
    WizardDialog dialog = new WizardDialog(parent, this.mWizard);
    dialog.create();

    // Point defaultSize = dialog.getShell().getSize();
    // dialog.getShell().setSize(
    // Math.max(500, defaultSize.x),
    // Math.max(500, defaultSize.y));
    window.getWorkbench().getHelpSystem().setHelp(dialog.getShell(),
            "org.eclipse.ui.new_wizard_shortcut_context");

    this.mDialogResult = dialog.open();
}

From source file:co.turnus.analysis.profiler.orcc.ui.OrccDynamicProfilerLaunchShortcut.java

License:Open Source License

private void chooseAndLaunch(IFile file, ILaunchConfiguration[] configs, String mode) {
    ILaunchConfiguration config = null;/*from  w  ww  .  j a  v a 2 s . com*/
    if (configs.length == 0) {
        config = createConfiguration(file);
    } else if (configs.length == 1) {
        config = configs[0];
    } else {
        config = chooseConfiguration(configs);
    }

    if (config != null) {
        Shell shell = getShell();
        DebugUITools.openLaunchConfigurationDialogOnGroup(shell, new StructuredSelection(config),
                IDebugUIConstants.ID_RUN_LAUNCH_GROUP);
    }
}

From source file:codeshine.utils.TableFieldEditor.java

License:Open Source License

/**
 * </p>/* w w  w  . j  av  a2  s  .c  o m*/
 * Sets the selection of this <code>TableFieldEditor</code> to
 * the row or element matching the specified <code>selectionStr</code>.
 * </p>
 * 
 * @param selectionStr the <code>String</code> that identifies the
 * row or element to select
 */
private void setSelection(String selectionStr) {
    if (this.viewer != null) {
        Object[] items = this.contentProvider.getElements(this.viewer.getInput());
        boolean selected = false;
        if (this.selectionColumn == -1) {
            for (int i = 0; i < items.length && !selected; i++) {
                if (selectionStr.equals(items[i].toString())) {
                    StructuredSelection selection = new StructuredSelection(items[i]);
                    this.viewer.setSelection(selection);
                    selected = true;
                }
            }
        } else {
            for (int i = 0; i < items.length && !selected; i++) {
                if (selectionStr.equals(this.labelProvider.getColumnText(items[i], this.selectionColumn))) {
                    StructuredSelection selection = new StructuredSelection(items[i]);
                    this.viewer.setSelection(selection);
                    selected = true;
                }
            }
        }
    }
}

From source file:coloredide.astview.ASTView.java

License:Open Source License

private CompilationUnit internalSetInput(IColoredJavaSourceFile input, int offset, int length)
        throws CoreException {
    // if (input.getBuffer() == null) {
    // throw new CoreException(getErrorStatus("Input has no buffer", null));
    // //$NON-NLS-1$
    // }/*from  w w w . ja  v  a 2 s  . c o  m*/

    try {
        CompilationUnit root = input.getAST();
        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);
            fASTLabelProvider.setSelectedRange(node.getStartPosition(), node.getLength());
            fViewer.setSelection(new StructuredSelection(node), true);
            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:coloredide.astview.ASTView.java

License:Open Source License

protected void performCreateBindingFromElement() {
    InputDialog dialog = new InputDialog(getSite().getShell(), "Create Binding from Java Element",
            "IJavaElement#getHandleIdentifier():", "", null);
    if (dialog.open() != Window.OK)
        return;// ww w  .j a  va  2  s  .  co  m

    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(ColoredIDEPlugin.AST_VERSION);
        parser.setProject(project);
        IBinding[] bindings = parser.createBindings(new IJavaElement[] { handle }, null);
        item = new Binding(viewerInput, handleIdentifier, bindings[0], true);
    }
    fViewer.add(viewerInput, item);
    fViewer.setSelection(new StructuredSelection(item), true);
}

From source file:coloredide.astview.ASTView.java

License:Open Source License

protected void performDoubleClick() {
    if (fEditor == null) {
        return;/*from  w  w  w  .j  a va2 s.c  o m*/
    }

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

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

    if (obj instanceof ExceptionAttribute) {
        RuntimeException 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:coloredide.astview.ASTView.java

License:Open Source License

protected void performTrayDoubleClick() {
    IStructuredSelection selection = (IStructuredSelection) fTray.getSelection();
    if (selection.size() != 1)
        return;//  w  w  w . j av a2s .c  om
    Object obj = selection.getFirstElement();
    if (obj instanceof ExceptionAttribute) {
        RuntimeException 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:coloredide.astview.ASTView.java

License:Open Source License

protected void performDelete() {
    IStructuredSelection selection = (IStructuredSelection) fTray.getSelection();
    if (selection.size() != 1)
        return;/* w w  w  . j a  va 2s.c o  m*/
    Object obj = selection.getFirstElement();
    if (obj instanceof Binding) {
        int index = fTrayRoots.indexOf(obj);
        if (index != -1) {
            fTrayRoots.remove(index);
            fTray.setInput(fTrayRoots);
            int newSize = fTrayRoots.size();
            if (newSize == 0)
                return;
            else if (index == newSize)
                setTraySelection(new StructuredSelection(fTrayRoots.get(newSize - 1)));
            else
                setTraySelection(new StructuredSelection(fTrayRoots.get(index)));
        }
    }
}

From source file:com.alibaba.antx.config.gui.dialog.SettingsDialog.java

License:Open Source License

private void addFolder() {
    DirectoryDialog dialog = new DirectoryDialog(getShell(), SWT.NONE);

    dialog.setText(Resources.getText("dialog.settings.addFolder"));
    dialog.setMessage(Resources.getText("dialog.settings.addFolder.message"));
    dialog.setFilterPath(getCurrentDir().getAbsolutePath());

    String folder = dialog.open();

    if (folder != null) {
        File folderFile = new File(folder);
        files.add(new File(folder));
        filesViewer.refresh();/*from w  w  w . ja va 2s .  c  o m*/
        filesViewer.setSelection(new StructuredSelection(folderFile));
        updateCommandLine();
    }
}