Example usage for org.eclipse.jface.viewers IStructuredSelection iterator

List of usage examples for org.eclipse.jface.viewers IStructuredSelection iterator

Introduction

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

Prototype

@Override
public Iterator iterator();

Source Link

Document

Returns an iterator over the elements of this selection.

Usage

From source file:ch.ngiger.elexis.text.utilities.handlers.StressTestAllDocuments.java

License:Open Source License

/**
 * the command has been executed, so extract extract the needed information from the application
 * context./* w  ww.ja  v a2 s. co  m*/
 */
public Object execute(ExecutionEvent event) throws ExecutionException {
    window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
    if (!Preferences.getMustRunStressTest()) {
        MessageDialog.openInformation(window.getShell(), Messages.Stresstest,
                Messages.StresstestInPreferencesDisallowed);
        return null;
    }
    selection = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage().getSelection();

    if (selection != null & selection instanceof IStructuredSelection) {
        IStructuredSelection strucSelection = (IStructuredSelection) selection;
        for (Iterator<Object> iterator = strucSelection.iterator(); iterator.hasNext();) {
            Object element = iterator.next();
        }
    }
    try {
        tv = (TextView) HandlerUtil.getActiveWorkbenchWindow(event).getActivePage().showView(TextView.ID);
    } catch (PartInitException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    stressTestAction.run();
    return null;
}

From source file:ch.unibe.iam.scg.archie.commands.CopySelected.java

License:Open Source License

/**
 * {@inheritDoc}/*  w w  w  .  ja v  a  2s  .c  o m*/
 */
@SuppressWarnings("unchecked")
public Object execute(ExecutionEvent event) throws ExecutionException {
    IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event);
    IWorkbenchPage page = window.getActivePage();
    IViewPart view = (IViewPart) page.findView(StatisticsView.ID);
    ISelection selection = view.getSite().getSelectionProvider().getSelection();
    if (selection == null)
        return null;

    // build selection string
    StringBuilder builder = new StringBuilder();
    if (selection instanceof IStructuredSelection) {
        IStructuredSelection strucSelection = (IStructuredSelection) selection;
        for (Iterator<Object> iterator = strucSelection.iterator(); iterator.hasNext();) {
            Comparable<?>[] row = (Comparable<?>[]) iterator.next();
            builder.append(this.datasetRowToString(row));
        }
    }

    // create clipboard contents
    Clipboard clipboard = new Clipboard(Display.getDefault());
    TextTransfer transfer = TextTransfer.getInstance();
    clipboard.setContents(new Object[] { builder.toString() }, new Transfer[] { transfer });

    return null;
}

From source file:ch.uzh.ifi.seal.permo.performance.main.ui.trigger.SelectedMethods.java

License:Apache License

/**
 * Checks whether the given {@link IStructuredSelection} points to a single Java method. If yes, the appropriate
 * {@link IMethod} is returned.//from   ww w .j a  va  2  s  . com
 * 
 * @param structuredSelection
 *          the {@link IStructuredSelection} to be checked
 * @return the appropriate {@link IMethod} if the {@link IStructuredSelection} points to a Java method,
 *         {@link Optional#empty()} otherwise
 */
public static Optional<IMethod> getSelectedMethod(final IStructuredSelection structuredSelection) {
    final Iterator<?> iterator = structuredSelection.iterator();
    if (iterator.hasNext()) {
        final Object selectedElement = iterator.next();
        // Currently, only a single selected method is supported. Therefore the check below is required.
        if (!iterator.hasNext()) {
            if (selectedElement instanceof IMethod) {
                return Optional.of((IMethod) selectedElement);
            }
        }
    }
    return Optional.empty();
}

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

License:Open Source License

protected void performDelete() {
    boolean removed = false;
    IStructuredSelection selection = (IStructuredSelection) fTray.getSelection();
    for (Iterator iter = selection.iterator(); iter.hasNext();) {
        Object obj = iter.next();
        if (obj instanceof DynamicAttributeProperty)
            obj = ((DynamicAttributeProperty) obj).getParent();
        if (obj instanceof DynamicBindingProperty)
            obj = ((DynamicBindingProperty) obj).getParent();

        removed |= fTrayRoots.remove(obj);
    }//  w w w.j av a  2  s  .co  m
    if (removed)
        fTray.setInput(fTrayRoots);
}

From source file:coloredide.astview.ASTView.java

License:Open Source License

private List<ASTNode> getSelection() {
    List<ASTNode> result = new ArrayList<ASTNode>();
    IStructuredSelection selection = (IStructuredSelection) fViewer.getSelection();
    for (Iterator iter = selection.iterator(); iter.hasNext();) {
        Object element = iter.next();
        if (element instanceof ASTNode) {
            result.add((ASTNode) element);
        }/*from  w w  w  . jav a2 s  .  c o m*/
    }
    return result;
}

From source file:com.amalto.workbench.actions.XSDCopyConceptAction.java

License:Open Source License

public void run() {
    try {//from w w w. j  ava  2  s  .  c om
        WorkbenchClipboard.getWorkbenchClipboard().conceptsReset();
        WorkbenchClipboard.getWorkbenchClipboard().particlesReset();
        IStructuredSelection selection = (IStructuredSelection) page.getTreeViewer().getSelection();
        if (selection.getFirstElement() instanceof XSDElementDeclaration) {
            for (Iterator<XSDElementDeclaration> iter = selection.iterator(); iter.hasNext();) {
                XSDElementDeclaration concept = iter.next();

                if (concept instanceof XSDElementDeclaration)
                    WorkbenchClipboard.getWorkbenchClipboard().add(concept);
            }
        } else if (selection.getFirstElement() instanceof XSDParticle) {
            for (Iterator<XSDParticle> iter = selection.iterator(); iter.hasNext();) {
                XSDParticle particle = iter.next();

                if (particle instanceof XSDParticle)
                    WorkbenchClipboard.getWorkbenchClipboard().add(particle);
            }
        }

    } catch (Exception e) {
        log.error(e.getMessage(), e);
        MessageDialog.openError(page.getSite().getShell(), Messages._Error,
                Messages.bind(Messages.XSDCopyConceptAction_ErrorMsg, e.getLocalizedMessage()));

    }
    // return true;
}

From source file:com.amalto.workbench.actions.XSDDeleteTypeDefinition.java

License:Open Source License

@Override
public IStatus doAction() {
    IStructuredSelection selection = (IStructuredSelection) page.getTreeViewer().getSelection();
    ArrayList<Object> objList = new ArrayList<Object>();
    Util.getAllObject(page.getSite(), objList, (IStructuredContentProvider) page.getSchemaContentProvider());
    Util.getAllObject(page.getSite(), objList, (IStructuredContentProvider) page.getTypeContentProvider());

    XSDTypeDefinition usingElement = findUsingElement(selection, objList);
    if (usingElement != null) {
        String message = getInfoDialogMessage(usingElement);
        MessageDialog.openInformation(page.getSite().getShell(), Messages.XSDDeleteTypeDefinition_ConfirmDel,
                message);//from w  w  w .ja  v  a2  s. c  om
        return Status.CANCEL_STATUS;
    }
    // edit by ymli; fix the bug:0012228. Made the multiple types can be deleted.
    for (Iterator<XSDTypeDefinition> iter = selection.iterator(); iter.hasNext();) {
        XSDTypeDefinition type = iter.next();
        if (type instanceof XSDSimpleTypeDefinition) {
            XSDSimpleTypeDefinition simpleType = (XSDSimpleTypeDefinition) type;
            if (xsdSimpType != null) {
                simpleType = xsdSimpType;
            }
            schema.getContents().remove(simpleType);
        } else {
            XSDComplexTypeDefinition complxType = (XSDComplexTypeDefinition) type;
            if (xsdCmpexType != null) {
                complxType = xsdCmpexType;
            }
            schema.getContents().remove(complxType);
        }
    }
    xsdSimpType = null;
    xsdCmpexType = null;
    page.refresh();
    page.markDirty();
    return Status.OK_STATUS;
}

From source file:com.amalto.workbench.actions.XSDDeleteTypeDefinition.java

License:Open Source License

private XSDTypeDefinition findUsingElement(IStructuredSelection selection, ArrayList<Object> objList) {
    for (Iterator<XSDTypeDefinition> iter = selection.iterator(); iter.hasNext();) {
        XSDTypeDefinition type = iter.next();
        boolean find = Util.findElementsUsingType(objList, type);
        if (find) {
            return type;
        }/*from   w  w  w .  j  a va  2  s.com*/
    }
    return null;
}

From source file:com.amalto.workbench.dialogs.MDMXSDSchemaEntryDialog.java

License:Open Source License

@Override
protected Control createDialogArea(Composite parent) {
    parent.getShell().setText(this.title);

    Composite composite = (Composite) super.createDialogArea(parent);
    GridLayout layout = (GridLayout) composite.getLayout();
    layout.numColumns = 1;/*from w ww  .  ja  va  2  s  .co  m*/

    wcListViewer = new ListViewer(composite,
            SWT.BORDER | SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION);
    wcListViewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
    ((GridData) wcListViewer.getControl().getLayoutData()).minimumHeight = 200;

    wcListViewer.setContentProvider(new IStructuredContentProvider() {

        public void dispose() {
        }

        public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
        }

        public Object[] getElements(Object inputElement) {
            return ((ArrayList) inputElement).toArray(new String[] {});
        }
    });

    wcListViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {
            importedUrls.clear();
            IStructuredSelection selection = (IStructuredSelection) event.getSelection();
            Iterator iter = selection.iterator();
            while (iter.hasNext()) {
                String url = (String) iter.next();
                importedUrls.add(url);
            }
            getButton(IDialogConstants.OK_ID).setEnabled(!selection.isEmpty());
        }
    });
    wcListViewer.setLabelProvider(new ILabelProvider() {

        public void addListener(ILabelProviderListener listener) {
        }

        public void dispose() {
        }

        public boolean isLabelProperty(Object element, String property) {
            return false;
        }

        public void removeListener(ILabelProviderListener listener) {
        }

        public Image getImage(Object element) {
            return null;
        }

        public String getText(Object element) {
            return element.toString();
        }
    });

    wcListViewer.setSorter(new ViewerSorter());
    wcListViewer.setInput(urls);
    return composite;
}

From source file:com.amazonaws.eclipse.explorer.simpledb.SimpleDBNavigatorActionProvider.java

License:Apache License

@Override
public void fillContextMenu(final IMenuManager menu) {
    IStructuredSelection selection = (IStructuredSelection) getContext().getSelection();

    if (selection.getFirstElement() == SimpleDBRootElement.ROOT_ELEMENT) {
        menu.add(new CreateDomainAction());
    } else if (selection.getFirstElement() instanceof DomainNode) {

        List<String> domainNames = new ArrayList<String>();
        Iterator iterator = selection.iterator();
        while (iterator.hasNext()) {
            Object next = iterator.next();
            if (next instanceof DomainNode) {
                DomainNode domainNode = (DomainNode) next;
                domainNames.add(domainNode.getName());
            }/*from  w w w .ja va2  s  . co m*/
        }

        menu.add(new CreateDomainAction());
        menu.add(new DeleteDomainAction(domainNames));
        menu.add(new Separator());

        menu.add(new OpenSQLScrapbookAction());
        DomainNode domainNode = (DomainNode) selection.getFirstElement();
        menu.add(new OpenDataTableEditorAction(domainNode.getName()));
    }
}