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:com.subgraph.vega.ui.http.builder.HeaderEditor.java

License:Open Source License

private SelectionListener createSelectionListenerButtonMoveDown() {
    return new SelectionAdapter() {
        @Override//  w w  w . j  av a2  s .c  om
        public void widgetSelected(SelectionEvent e) {
            IStructuredSelection selection = (IStructuredSelection) tableViewerHeaders.getSelection();
            int idx[] = new int[selection.size()];
            int offset = 1;
            for (Iterator<?> i = selection.iterator(); i.hasNext(); offset++) {
                idx[idx.length - offset] = messageBuilder.getHeaderIdxOf((IHttpHeaderBuilder) i.next());
            }

            if (idx[0] + 1 != messageBuilder.getHeaderCnt()) {
                for (int i = 0; i < idx.length; i++) {
                    messageBuilder.swapHeader(idx[i], idx[i] + 1);
                }
            }
            tableViewerHeaders.refresh();
        }
    };
}

From source file:com.subgraph.vega.ui.http.commands.DropTransaction.java

License:Open Source License

public Object execute(ExecutionEvent event) throws ExecutionException {
    ISelection selection = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage().getSelection();

    if (selection != null && selection instanceof IStructuredSelection) {
        IStructuredSelection strucSelection = (IStructuredSelection) selection;

        for (Iterator<?> iterator = strucSelection.iterator(); iterator.hasNext();) {
            IProxyTransaction transaction = (IProxyTransaction) iterator.next();
            transaction.doDrop();//from  w  ww  .ja va2  s  . c  om
        }
    }
    return null;
}

From source file:com.subgraph.vega.ui.http.commands.ForwardTransaction.java

License:Open Source License

public Object execute(ExecutionEvent event) throws ExecutionException {
    ISelection selection = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage().getSelection();

    if (selection != null && selection instanceof IStructuredSelection) {
        IStructuredSelection strucSelection = (IStructuredSelection) selection;

        for (Iterator<?> iterator = strucSelection.iterator(); iterator.hasNext();) {
            IProxyTransaction transaction = (IProxyTransaction) iterator.next();
            transaction.doForward();/* w w w. j  a v  a 2 s. c  om*/
        }
    }
    return null;
}

From source file:com.synflow.ngDesign.ui.internal.navigator.actions.SelectionUtil.java

License:Open Source License

/**
 * Returns <code>true</code> if the given selection contains a source folder.
 * //from  ww w  . ja v  a2  s .  com
 * @param selection
 *            a structured selection
 * @return a boolean indicating whether the selection contains a source folder
 */
public static boolean containsSourceFolder(IStructuredSelection selection) {
    for (Iterator<?> e = selection.iterator(); e.hasNext();) {
        Object next = e.next();
        if (next instanceof ITreeElement) {
            ITreeElement element = (ITreeElement) next;
            if (element.isSourceFolder()) {
                return true;
            }
        }
    }
    return false;
}

From source file:com.synflow.ngDesign.ui.internal.navigator.actions.SelectionUtil.java

License:Open Source License

/**
 * Removes resources that are adapted from packages/source folders.
 * /*from  w w  w . ja  v  a 2s  .c om*/
 * @param selectedResources
 *            list of selected resources
 * @param selection
 *            structured selection
 */
public static void discardTreeElements(List<IResource> selectedResources, IStructuredSelection selection) {
    for (Iterator<?> e = selection.iterator(); e.hasNext();) {
        Object next = e.next();
        if (next instanceof ITreeElement) {
            ITreeElement element = (ITreeElement) next;
            selectedResources.remove(element.getAdapter(IResource.class));
        }
    }
}

From source file:com.synflow.ngDesign.ui.internal.navigator.CxDropAdapterAssistant.java

License:Open Source License

/**
 * Returns the resource selection from the LocalSelectionTransfer.
 * /*from   ww w  .  ja va 2 s  .  c om*/
 * @return the resource selection from the LocalSelectionTransfer
 */
private IResource[] getSelectedResources(IStructuredSelection selection) {
    ArrayList<IResource> selectedResources = new ArrayList<IResource>();
    for (Iterator<?> it = selection.iterator(); it.hasNext();) {
        Object object = it.next();
        IResource resource = getResource(object);
        if (resource != null) {
            selectedResources.add(resource);
        }
    }
    return selectedResources.toArray(new IResource[selectedResources.size()]);
}

From source file:com.synflow.ngDesign.ui.internal.navigator.EditActionProvider.java

License:Open Source License

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

    boolean canCopy = true, canPaste = true, canDelete = true;
    Iterator<?> it = selection.iterator();
    while (it.hasNext()) {
        Object obj = it.next();/*from   www. j  a  v a  2  s.  c  o m*/
        if (obj instanceof ITreeElement) {
            // cannot copy a package or source folder
            canCopy = false;

            // cannot paste in or delete source folder
            ITreeElement element = (ITreeElement) obj;
            if (element.isSourceFolder()) {
                canPaste = canDelete = false;
            }
        }
    }

    if (canCopy) {
        copyAction.selectionChanged(selection);
        menu.appendToGroup(ICommonMenuConstants.GROUP_EDIT, copyAction);
    }

    if (canPaste) {
        pasteAction.selectionChanged(selection);
        menu.appendToGroup(ICommonMenuConstants.GROUP_EDIT, pasteAction);
    }

    if (canDelete) {
        deleteAction.selectionChanged(selection);
        menu.appendToGroup(ICommonMenuConstants.GROUP_EDIT, deleteAction);
    }
}

From source file:com.synflow.ngDesign.ui.internal.navigator.RefactorActionProvider.java

License:Open Source License

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

    boolean canRename = true;
    Iterator<?> it = selection.iterator();
    while (it.hasNext()) {
        Object obj = it.next();/*from  ww w.  ja  va2  s  . c o  m*/
        if (obj instanceof ITreeElement) {
            // cannot rename source folder
            ITreeElement element = (ITreeElement) obj;
            if (element.isSourceFolder()) {
                canRename = false;
            }
        }
    }

    if (canRename) {
        renameAction.selectionChanged(selection);
        menu.appendToGroup(ICommonMenuConstants.GROUP_REORGANIZE, renameAction);
    }
}

From source file:com.testingtech.ttworkbench.utp.tests.TransformEAToUML.java

License:Open Source License

public void selectionChanged(final IAction action, final ISelection selection) {

    fileToProcess = null;/*from  w  w  w.j a  v  a  2  s.  com*/
    boolean thereIsAFileToProcess = false;

    if (selection instanceof IStructuredSelection) {
        final IStructuredSelection ssel = (IStructuredSelection) selection;
        final Iterator iter = ssel.iterator();

        while (iter.hasNext()) {
            final Object o = iter.next();

            if (o instanceof IFile) {
                fileToProcess = (IFile) o;
                thereIsAFileToProcess = true;
            } else if (o instanceof IAdaptable) {
                final IAdaptable adaptable = (IAdaptable) o;
                fileToProcess = (IFile) adaptable.getAdapter(IFile.class);
                thereIsAFileToProcess = true;
            }
        }
    }

    action.setEnabled(thereIsAFileToProcess);

}

From source file:com.vectrace.MercurialEclipse.repository.RepositoriesView.java

License:Open Source License

@SuppressWarnings("rawtypes")
protected void refreshViewerNode() {
    IStructuredSelection selection = (IStructuredSelection) treeViewer.getSelection();
    Iterator iter = selection.iterator();
    while (iter.hasNext()) {
        Object object = iter.next();
        if (object instanceof IHgRepositoryLocation) {
            refreshAction.run();/*from   w w  w . ja  v a 2  s.  c  o  m*/
            break;
        }
        treeViewer.refresh(object);
    }
}