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:descent.internal.ui.wizards.buildpaths.newsourcepage.GenerateBuildPathActionGroup.java

License:Open Source License

private boolean canOperateOnSelection() {
    ISelection sel = fSite.getSelectionProvider().getSelection();
    if (!(sel instanceof IStructuredSelection))
        return false;
    IStructuredSelection selection = (IStructuredSelection) sel;
    for (Iterator iter = selection.iterator(); iter.hasNext();) {
        Object element = iter.next();
        if (element instanceof IWorkingSet)
            return false;
    }// w  ww .j a  v a 2 s .c o m
    return true;
}

From source file:descent.internal.ui.wizards.buildpaths.newsourcepage.IncludeToBuildpathAction.java

License:Open Source License

private boolean canHandle(IStructuredSelection elements) {
    if (elements.size() == 0)
        return false;

    try {//from   ww w  .j  a va  2 s  . c  om
        fSelectedElements.clear();
        for (Iterator iter = elements.iterator(); iter.hasNext();) {
            Object element = iter.next();
            fSelectedElements.add(element);
            if (element instanceof IResource) {
                IResource resource = (IResource) element;
                IJavaProject project = JavaCore.create(resource.getProject());
                if (project == null || !project.exists())
                    return false;

                if (!ClasspathModifier.isExcluded(resource, project))
                    return false;
            } else {
                return false;
            }
        }
        return true;
    } catch (CoreException e) {
    }
    return false;
}

From source file:descent.internal.ui.wizards.buildpaths.newsourcepage.RemoveFromBuildpathAction.java

License:Open Source License

private boolean canHandle(IStructuredSelection elements) {
    if (elements.size() == 0)
        return false;

    try {//  w  w w .j  a va 2s . c  o  m
        fSelectedElements.clear();
        for (Iterator iter = elements.iterator(); iter.hasNext();) {
            Object element = iter.next();
            fSelectedElements.add(element);
            if (!(element instanceof IPackageFragmentRoot || element instanceof IJavaProject
                    || element instanceof ClassPathContainer))
                return false;

            if (element instanceof IJavaProject) {
                IJavaProject project = (IJavaProject) element;
                if (!ClasspathModifier.isSourceFolder(project))
                    return false;

            } else if (element instanceof IPackageFragmentRoot) {
                IClasspathEntry entry = ((IPackageFragmentRoot) element).getRawClasspathEntry();
                if (entry != null && entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
                    return false;
                }
            }
        }
        return true;
    } catch (JavaModelException e) {
    }
    return false;
}

From source file:descent.ui.actions.OpenAction.java

License:Open Source License

private boolean checkEnabled(IStructuredSelection selection) {
    if (selection.isEmpty())
        return false;
    for (Iterator iter = selection.iterator(); iter.hasNext();) {
        Object element = iter.next();
        if (element instanceof ISourceReference)
            continue;
        if (element instanceof IFile)
            continue;
        if (element instanceof IStorage)
            continue;
        return false;
    }/* w  w  w  . j a  v a2s.  co m*/
    return true;
}

From source file:dk.itu.sdg.language.xwpf.resource.xwpf.ui.launch.XwpfLaunchShortcut.java

License:Apache License

public void launch(org.eclipse.jface.viewers.ISelection selection, String mode) {
    if (selection instanceof org.eclipse.jface.viewers.IStructuredSelection) {
        org.eclipse.jface.viewers.IStructuredSelection structuredSelection = (org.eclipse.jface.viewers.IStructuredSelection) selection;
        java.util.Iterator<?> it = structuredSelection.iterator();
        while (it.hasNext()) {
            Object object = it.next();
            if (object instanceof org.eclipse.core.resources.IFile) {
                org.eclipse.core.resources.IFile file = (org.eclipse.core.resources.IFile) object;
                launch(file, mode);/* ww  w  .ja va  2s.c  o  m*/
            }
        }
    }
}

From source file:dk.itu.sdg.language.xwpf.resource.xwpf.ui.XwpfPropertySheetPage.java

License:Apache License

public void selectionChanged(org.eclipse.ui.IWorkbenchPart part,
        org.eclipse.jface.viewers.ISelection iSelection) {
    // This is a workaround for a bug in EMF (see
    // https://bugs.eclipse.org/bugs/show_bug.cgi?id=291301).Unfortunately Ed Merks
    // refuses to fix it, so we need to solve it here.
    if (iSelection instanceof dk.itu.sdg.language.xwpf.resource.xwpf.ui.XwpfEObjectSelection) {
        final dk.itu.sdg.language.xwpf.resource.xwpf.ui.XwpfEObjectSelection selection = (dk.itu.sdg.language.xwpf.resource.xwpf.ui.XwpfEObjectSelection) iSelection;
        final org.eclipse.emf.ecore.EObject selectedObject = selection.getSelectedObject();
        // check whether the selected object or one of its children contains a proxy which
        // is a GenXYZClass (e.g., GenFeature, GenClass, GenPackage)
        if (containsGenProxy(selectedObject)) {
            return;
        }/* www .ja v a2  s  .  co m*/
    }
    if (iSelection instanceof org.eclipse.jface.viewers.IStructuredSelection) {
        org.eclipse.jface.viewers.IStructuredSelection structuredSelection = (org.eclipse.jface.viewers.IStructuredSelection) iSelection;
        java.util.Iterator<?> it = structuredSelection.iterator();
        while (it.hasNext()) {
            final Object next = it.next();
            if (next instanceof org.eclipse.emf.ecore.EObject) {
                if (containsGenProxy((org.eclipse.emf.ecore.EObject) next)) {
                    return;
                }
            }
        }
    }
    // end of workaround
    super.selectionChanged(part, iSelection);
}

From source file:e4.handler.E4TemplatePreferencePage.java

License:Open Source License

/**
 * Updates the buttons./*from w  w  w  . j  a v  a2 s  . c  om*/
 */
protected void updateButtons() {
    IStructuredSelection selection = (IStructuredSelection) fTableViewer.getSelection();
    int selectionCount = selection.size();
    int itemCount = fTableViewer.getTable().getItemCount();
    boolean canRestore = fTemplateStore.getTemplateData(true).length != fTemplateStore
            .getTemplateData(false).length;
    boolean canRevert = false;
    for (Iterator it = selection.iterator(); it.hasNext();) {
        TemplatePersistenceData data = (TemplatePersistenceData) it.next();
        if (data.isModified()) {
            canRevert = true;
            break;
        }
    }

    fEditButton.setEnabled(selectionCount == 1);
    fExportButton.setEnabled(selectionCount > 0);
    fRemoveButton.setEnabled(selectionCount > 0 && selectionCount <= itemCount);
    fRestoreButton.setEnabled(canRestore);
    fRevertButton.setEnabled(canRevert);
}

From source file:e4.handler.E4TemplatePreferencePage.java

License:Open Source License

private void remove() {
    IStructuredSelection selection = (IStructuredSelection) fTableViewer.getSelection();

    Iterator elements = selection.iterator();
    while (elements.hasNext()) {
        TemplatePersistenceData data = (TemplatePersistenceData) elements.next();
        fTemplateStore.delete(data);/*from ww w. j  a v a 2  s. co m*/
    }

    fTableViewer.refresh();
}

From source file:e4.handler.E4TemplatePreferencePage.java

License:Open Source License

private void revert() {
    IStructuredSelection selection = (IStructuredSelection) fTableViewer.getSelection();

    Iterator elements = selection.iterator();
    while (elements.hasNext()) {
        TemplatePersistenceData data = (TemplatePersistenceData) elements.next();
        data.revert();// www .  j a  v  a2  s .  co m
        fTableViewer.setChecked(data, data.isEnabled());
    }

    selectionChanged1();
    fTableViewer.refresh();
}

From source file:edu.illinois.ncsa.datawolf.executor.java.wizard.ToolSelectWizardPage.java

License:Open Source License

private void validate() {
    IStructuredSelection ssel = (IStructuredSelection) lvTools.getSelection();
    setPageComplete(false);/*from   w w w.  jav  a2 s .c  om*/
    txtName.setText(""); //$NON-NLS-1$
    txtDescription.setText(""); //$NON-NLS-1$
    txtVersion.setText(""); //$NON-NLS-1$
    if (!ssel.isEmpty()) {
        for (Iterator<Class<? extends JavaTool>> iter = ssel.iterator(); iter.hasNext();) {
            Class<? extends JavaTool> item = iter.next();
            try {
                JavaTool tool = item.newInstance();
                if (tool.getName() != null) {
                    txtName.setText(tool.getName());
                } else {
                    txtName.setText("Unknown tool"); //$NON-NLS-1$
                }
                txtVersion.setText(Integer.toString(tool.getVersion()));
                if (tool.getDescription() != null) {
                    txtDescription.setText(tool.getDescription());
                } else {
                    txtDescription.setText(""); //$NON-NLS-1$
                }
                setPageComplete(true);
            } catch (Throwable thr) {
                logger.warn("Could not retrieve tool information.", thr);
                tools.remove(item);
                lvTools.remove(item);
            }
        }
    }
}