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:eu.geclipse.ui.dialogs.GridFileDialog.java

License:Open Source License

private IFileStore[] getSelection() {

    IFileStore[] result = null;/*  w w w  .  java2 s  .  co m*/

    if ((this.treeViewer != null) && !this.treeViewer.getTree().isDisposed()) {

        List<IFileStore> list = new ArrayList<IFileStore>();
        IStructuredSelection selection = (IStructuredSelection) this.treeViewer.getSelection();
        Iterator<?> iterator = selection.iterator();

        while (iterator.hasNext()) {

            Object o = iterator.next();

            if (o instanceof IGridConnectionElement) {
                try {
                    o = ((IGridConnectionElement) o).getConnectionFileStore();
                } catch (CoreException cExc) {
                    // Silently ignored
                }
            } else if (o instanceof IGridElement) {
                o = ((IGridElement) o).getFileStore();
            }

            if (o instanceof IFileStore) {
                list.add((IFileStore) o);
            }

        }

        if (!list.isEmpty()) {
            result = list.toArray(new IFileStore[list.size()]);
        }

    }

    return result;

}

From source file:eu.geclipse.ui.internal.actions.ManagePermissionsAction.java

License:Open Source License

@Override
protected boolean updateSelection(final IStructuredSelection selection) {

    Class<?> type = null;/*from  w ww  .j  a  v a2 s . c om*/
    IProtectable protectable;

    this.selectedElements.clear();
    boolean enabled = super.updateSelection(selection);

    Iterator<?> it = selection.iterator();
    while (enabled && it.hasNext()) {

        Object next = it.next();
        protectable = null;

        // Connection elements do not implement IProtectable directly but adapt to it
        if (next instanceof IProtectable) {
            protectable = (IProtectable) next;
        } else if (next instanceof IAdaptable) {
            IAdaptable adaptable = (IAdaptable) next;
            protectable = (IProtectable) adaptable.getAdapter(IProtectable.class);
        }

        // Enable only if the selected elements implement the interface
        if (protectable != null) {
            this.selectedElements.add(protectable);
        } else {
            enabled = false;
        }

        // Enable only if all the selected elements are of the same type
        if (type == null) {
            type = next.getClass();
        } else if (type != next.getClass()) {
            enabled = false;
        }
    }

    // TODO allow editing multiple objects at the same time (if canSaveWholeACL() == true)
    if (this.selectedElements.size() > 1) {
        enabled = false;
    }

    return enabled && !this.selectedElements.isEmpty();
}

From source file:eu.geclipse.ui.internal.actions.RefreshAction.java

License:Open Source License

private boolean filterSelection(final IStructuredSelection selection, final List<IResource> resources,
        final List<IGridElement> elements) {

    Iterator<?> iter = selection.iterator();

    while (iter.hasNext()) {
        Object o = iter.next();/* w w  w  .j  a  v  a2 s.  c om*/
        IResource resource = getResource(o);
        if (resource != null) {
            resources.add(resource);
        } else if (o instanceof IGridElement) {
            elements.add((IGridElement) o);
        }
    }

    return (resources.size() + elements.size()) == selection.size();

}

From source file:eu.geclipse.ui.internal.actions.SimpleTestAction.java

License:Open Source License

@Override
protected boolean updateSelection(final IStructuredSelection selection) {
    this.resources = new ArrayList<IGridResource>();
    boolean enabled = super.updateSelection(selection);
    Iterator<?> iter = selection.iterator();
    while (iter.hasNext() && enabled) {
        Object element = iter.next();
        boolean isResource = isResourcePhysical(element);
        enabled &= isResource;/*from w w  w . j a v a 2 s.co m*/
        if (isResource) {
            this.resources.add((IGridResource) element);
        }
    }
    return enabled && !this.resources.isEmpty();
}

From source file:eu.geclipse.ui.internal.actions.SubmitJobAction.java

License:Open Source License

@Override
protected boolean updateSelection(final IStructuredSelection selection) {

    boolean enabled = !selection.isEmpty() && super.updateSelection(selection);

    if (enabled) {
        this.jobDescriptions.clear();
        IGridProject project = null;//from   w  w  w. j av a  2 s . com
        Iterator<?> iter = selection.iterator();
        while (iter.hasNext() && enabled) {
            Object element = iter.next();
            List<IGridJobDescription> descriptions = getJobDescriptions(element);
            if (descriptions != null && !descriptions.isEmpty()) {
                if (project == null) {
                    project = descriptions.get(0).getProject();
                }
                if (project != descriptions.get(0).getProject()) {
                    //job description from different projects cannot be submitted together
                    return false;
                }
                this.jobDescriptions.addAll(descriptions);
            } else {
                enabled = false;
            }
        }
    }

    return enabled && (this.jobDescriptions != null);

}

From source file:eu.geclipse.ui.internal.actions.UpdateJobStatusAction.java

License:Open Source License

@Override
protected boolean updateSelection(final IStructuredSelection selection) {
    this.selectedJobs.clear();
    for (Iterator<?> iterator = selection.iterator(); iterator.hasNext();) {
        Object element = iterator.next();
        if (element instanceof GridJob) {
            this.selectedJobs.add((GridJob) element);
        }//from   www. ja  v a2 s  .  c  o m
    }
    if (this.selectedJobs.size() > 0) {
        if (!this.isEnabled()) {
            this.setEnabled(true);
        }
    } else {
        this.setEnabled(false);
    }
    return super.updateSelection(selection) && (this.selectedJobs.size() > 0);
}

From source file:eu.geclipse.ui.internal.transfer.SelectionTransferDragAdapter.java

License:Open Source License

/**
 * Determines if the specified selection contains only dragable elements.
 * //from   w  ww  .j a  v a  2 s . c  o  m
 * @param selection The selection to be tested.
 * @return True if {@link GridModelViewPart#isDragSource(IGridElement)} returns
 * true for all elements contained in the specified selection.
 */
protected boolean isDragable(final ISelection selection) {
    boolean result = true;
    if (!selection.isEmpty() && (selection instanceof IStructuredSelection)) {
        IStructuredSelection sSelection = (IStructuredSelection) selection;
        Iterator<?> iter = sSelection.iterator();
        while (iter.hasNext() && result) {
            Object obj = iter.next();
            if (!(obj instanceof IGridElement) || !this.view.isDragSource((IGridElement) obj)) {
                result = false;
            }
        }
    }
    return result;
}

From source file:eu.geclipse.ui.internal.transfer.SelectionTransferDropAdapter.java

License:Open Source License

/**
 * Get the Grid elements that are contained in the specified
 * {@link DropTargetEvent}. This methods returns <code>null</code>
 * if not all dragged elements are {@link IGridElement}s.
 * //from   w  ww.j a v  a  2s .  c  o m
 * @param event The event from which to get the elements.
 * @return All Grid element that are contained in the specified
 * event.
 */
protected IGridElement[] getElements() {
    IGridElement[] result = null;
    ISelection selection = LocalSelectionTransfer.getInstance().getSelection();
    if (selection instanceof IStructuredSelection) {
        IStructuredSelection sSelection = (IStructuredSelection) selection;
        Iterator<?> iter = sSelection.iterator();
        List<IGridElement> elements = new ArrayList<IGridElement>();
        while (iter.hasNext()) {
            Object obj = iter.next();
            if (obj instanceof IGridElement) {
                elements.add((IGridElement) obj);
            }
        }
        if (elements.size() == sSelection.size()) {
            result = elements.toArray(new IGridElement[elements.size()]);
        }
    }
    return result;
}

From source file:eu.geclipse.ui.visualisation.AbstractVisualisationAction.java

License:Open Source License

@Override
protected boolean updateSelection(final IStructuredSelection selection) {
    this.vis = new ArrayList<IGridVisualisation>();
    boolean enabled = super.updateSelection(selection);
    Iterator<?> iter = selection.iterator();
    while (iter.hasNext() && enabled) {
        Object element = iter.next();
        boolean isVisualizableFile = isVisualizable(element);
        enabled &= isVisualizableFile;
        if (isVisualizableFile) {
            this.vis.add((IGridVisualisation) element);
        }/*from   w  ww  . ja v  a  2s.  co  m*/
    }
    return enabled && !this.vis.isEmpty();
}