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.schmeedy.relaxng.eclipse.ui.internal.preferences.RngSchemaBindingView.java

License:Open Source License

@SuppressWarnings("unchecked")
private Set<RngSchemaBinding> extractSelectedBindings(ISelection selection, boolean constrainToUserBindings) {
    if (!(selection instanceof IStructuredSelection)) {
        return Collections.emptySet();
    }//from   w  ww  .j a  v a  2s.  c om
    IStructuredSelection structuredSelection = (IStructuredSelection) selection;
    Iterator<Object> i = structuredSelection.iterator();
    Set<RngSchemaBinding> selectedBindings = new HashSet<RngSchemaBinding>();
    while (i.hasNext()) {
        Object o = i.next();
        if (o instanceof RngSchemaBinding) {
            RngSchemaBinding binding = (RngSchemaBinding) o;
            if (!constrainToUserBindings || userBindings.contains(binding.getNamespace())) {
                selectedBindings.add(binding);
            } else {
                return Collections.emptySet();
            }
        } else {
            return Collections.emptySet();
        }
    }
    return selectedBindings;
}

From source file:com.servoy.eclipse.docgenerator.ui.handler.AutopilotDocumentationGenerationHandler.java

License:Open Source License

public Object execute(ExecutionEvent event) throws ExecutionException {
    IStructuredSelection selection = (IStructuredSelection) HandlerUtil.getActiveMenuSelection(event);
    if (selection != null) {
        IPackageFragment pkg = null;/*from  ww  w  .j ava  2 s  .  c o m*/
        Iterator<?> entries = selection.iterator();
        while (entries.hasNext()) {
            Object entry = entries.next();
            if (entry instanceof IPackageFragment) {
                if (pkg == null) {
                    pkg = (IPackageFragment) entry;
                }
            } else if (entry instanceof IJavaProject) {
                if (pkg == null) {
                    IJavaProject javaPrj = (IJavaProject) entry;
                    try {
                        // pick the package with the shortest name
                        for (IPackageFragment frag : javaPrj.getPackageFragments()) {
                            if (pkg == null) {
                                pkg = frag;
                            } else if (pkg.getElementName().length() > pkg.getElementName().length()) {
                                pkg = frag;
                            }
                        }
                    } catch (JavaModelException e) {
                        LogUtil.logger().log(Level.SEVERE,
                                "Exception while searching for root package in project '"
                                        + javaPrj.getElementName() + "'.",
                                e);
                        e.printStackTrace();
                    }
                }
            }
        }

        if (pkg != null && pkg.getResource() != null && pkg.getResource().getLocation() != null) {
            final IPackageFragment pkgFinal = pkg;
            IJavaProject prj = pkg.getJavaProject();

            // Build a map with the selected package and its project.
            final Map<String, List<String>> prjPkg = new HashMap<String, List<String>>();
            List<String> pkgNames = new ArrayList<String>();
            pkgNames.add(pkg.getElementName());
            prjPkg.put(prj.getElementName(), pkgNames);

            final WorkspaceJob docgenJob = new WorkspaceJob("Generating documentation") {
                @Override
                public IStatus runInWorkspace(final IProgressMonitor monitor) throws CoreException {
                    // Post a documentation generation request.
                    // Post a documentation generation request.
                    DocumentationGenerationRequest req = new DocumentationGenerationRequestFromUI(pkgFinal,
                            true, monitor) {
                        @Override
                        protected boolean isRunningModal() {
                            Boolean b = (Boolean) getProperty(IProgressConstants.PROPERTY_IN_DIALOG);
                            return b != null ? b.booleanValue() : false;
                        }

                        @Override
                        protected void postponeAction(Action act) {
                            setProperty(IProgressConstants.KEEP_PROPERTY, Boolean.TRUE);
                            setProperty(IProgressConstants.ACTION_PROPERTY, act);
                        }
                    };
                    Dictionary<String, String> props = new Hashtable<String, String>();
                    monitor.beginTask("Generating documentation", 100);

                    final BundleContext context = Activator.getDefault().getBundle().getBundleContext();
                    context.registerService(DocumentationGenerationRequest.class.getName(), req, props);

                    return Status.OK_STATUS;
                }
            };
            docgenJob.setUser(true);
            docgenJob.schedule();

        }
    }
    return null;
}

From source file:com.servoy.eclipse.docgenerator.ui.handler.ExplicitDocumentationGenerationHandler.java

License:Open Source License

public Object execute(ExecutionEvent event) throws ExecutionException {
    IStructuredSelection selection = (IStructuredSelection) HandlerUtil.getActiveMenuSelection(event);
    if (selection != null) {
        IPackageFragment pkg = null;/*w  w  w  . ja va  2 s.co  m*/
        Iterator<?> entries = selection.iterator();
        while (entries.hasNext()) {
            Object entry = entries.next();
            if (entry instanceof IPackageFragment) {
                if (pkg == null) {
                    pkg = (IPackageFragment) entry;
                }
            }
        }

        if (pkg != null && pkg.getResource() != null && pkg.getResource().getLocation() != null) {
            final IPackageFragment pkgFinal = pkg;
            IJavaProject prj = pkg.getJavaProject();

            // Build a map with the selected package and its project.
            final Map<String, List<String>> prjPkg = new HashMap<String, List<String>>();
            List<String> pkgNames = new ArrayList<String>();
            pkgNames.add(pkg.getElementName());
            prjPkg.put(prj.getElementName(), pkgNames);

            final WorkspaceJob docgenJob = new WorkspaceJob("Generating documentation") {
                @Override
                public IStatus runInWorkspace(final IProgressMonitor monitor) throws CoreException {
                    monitor.beginTask("Generating documentation", 100);

                    // Post a documentation generation request.
                    DocumentationGenerationRequest req = new DocumentationGenerationRequestFromUI(pkgFinal,
                            false, monitor) {
                        @Override
                        protected boolean isRunningModal() {
                            Boolean b = (Boolean) getProperty(IProgressConstants.PROPERTY_IN_DIALOG);
                            return b != null ? b.booleanValue() : false;
                        }

                        @Override
                        protected void postponeAction(Action act) {
                            setProperty(IProgressConstants.KEEP_PROPERTY, Boolean.TRUE);
                            setProperty(IProgressConstants.ACTION_PROPERTY, act);
                        }
                    };
                    Dictionary<String, String> props = new Hashtable<String, String>();
                    final BundleContext context = Activator.getDefault().getBundle().getBundleContext();
                    context.registerService(DocumentationGenerationRequest.class.getName(), req, props);

                    return Status.OK_STATUS;
                }
            };
            docgenJob.setUser(true);
            docgenJob.schedule();
        }
    }
    return null;
}

From source file:com.siteview.mde.internal.ui.editor.category.CategorySection.java

License:Open Source License

private boolean handleRemove() {
    IStructuredSelection ssel = (IStructuredSelection) fCategoryViewer.getSelection();
    Iterator iterator = ssel.iterator();
    boolean success = true;
    Set removedCategories = new HashSet();
    while (iterator.hasNext()) {
        Object object = iterator.next();
        if (object == null)
            continue;
        if (object instanceof ISiteCategoryDefinition) {
            if (!handleRemoveCategoryDefinition((ISiteCategoryDefinition) object)) {
                success = false;//from w  w w  .  java  2s  .  c  om
            }
        } else {
            //check if some of features was not removed during category removal
            SiteFeatureAdapter fa = (SiteFeatureAdapter) object;
            if (removedCategories.contains(fa.category))
                continue;

            if (!handleRemoveSiteFeatureAdapter(fa)) {
                success = false;
            }
        }
    }
    return success;
}

From source file:com.siteview.mde.internal.ui.editor.feature.DataSection.java

License:Open Source License

private void handleDelete() {
    IStructuredSelection ssel = (IStructuredSelection) fDataViewer.getSelection();

    if (ssel.isEmpty())
        return;//from   www. j  ava 2  s.c om
    IFeatureModel model = (IFeatureModel) getPage().getModel();
    if (!model.isEditable()) {
        return;
    }
    IFeature feature = model.getFeature();

    try {
        IFeatureData[] removed = new IFeatureData[ssel.size()];
        int i = 0;
        for (Iterator iter = ssel.iterator(); iter.hasNext();) {
            IFeatureData iobj = (IFeatureData) iter.next();
            removed[i++] = iobj;
        }
        feature.removeData(removed);
    } catch (CoreException e) {
        MDEPlugin.logException(e);
    }
}

From source file:com.siteview.mde.internal.ui.editor.feature.IncludedFeaturesSection.java

License:Open Source License

private void handleDelete() {
    IStructuredSelection ssel = (IStructuredSelection) fIncludesViewer.getSelection();

    if (ssel.isEmpty())
        return;/*from   w ww. java  2s.c  om*/
    IFeatureModel model = (IFeatureModel) getPage().getModel();
    if (!model.isEditable()) {
        return;
    }
    IFeature feature = model.getFeature();

    try {
        IFeatureChild[] removed = new IFeatureChild[ssel.size()];
        int i = 0;
        for (Iterator iter = ssel.iterator(); iter.hasNext();) {
            IFeatureChild iobj = (IFeatureChild) iter.next();
            removed[i++] = iobj;
        }
        feature.removeIncludedFeatures(removed);
    } catch (CoreException e) {
        MDEPlugin.logException(e);
    }
}

From source file:com.siteview.mde.internal.ui.editor.feature.PluginSection.java

License:Open Source License

private void handleDelete() {
    IStructuredSelection ssel = (IStructuredSelection) fPluginViewer.getSelection();

    if (ssel.isEmpty())
        return;//from w  ww  .  java2s  .  c o  m
    IFeatureModel model = (IFeatureModel) getPage().getModel();
    if (!model.isEditable()) {
        return;
    }
    IFeature feature = model.getFeature();

    try {
        IFeaturePlugin[] removed = new IFeaturePlugin[ssel.size()];
        int i = 0;
        for (Iterator iter = ssel.iterator(); iter.hasNext();) {
            IFeaturePlugin iobj = (IFeaturePlugin) iter.next();
            removed[i++] = iobj;
        }
        feature.removePlugins(removed);
    } catch (CoreException e) {
        MDEPlugin.logException(e);
    }
}

From source file:com.siteview.mde.internal.ui.editor.feature.RequiresSection.java

License:Open Source License

private void handleDelete() {
    IFeatureModel model = (IFeatureModel) getPage().getModel();
    if (!model.isEditable()) {
        return;/* ww  w. java 2  s  .  c  o  m*/
    }
    IFeature feature = model.getFeature();
    IStructuredSelection selection = (IStructuredSelection) fPluginViewer.getSelection();
    if (selection.isEmpty())
        return;

    try {
        IFeatureImport[] deleted = new IFeatureImport[selection.size()];
        int i = 0;
        for (Iterator iter = selection.iterator(); iter.hasNext();) {
            IFeatureImport iimport = (IFeatureImport) iter.next();
            deleted[i++] = iimport;
        }
        feature.removeImports(deleted);
    } catch (CoreException e) {
        MDEPlugin.logException(e);
    }
}

From source file:com.siteview.mde.internal.ui.editor.feature.URLSection.java

License:Open Source License

private void handleDelete() {
    IStructuredSelection ssel = (IStructuredSelection) fUrlViewer.getSelection();

    if (ssel.isEmpty())
        return;//  w  ww .j a v a  2 s . c om
    IFeatureModel model = (IFeatureModel) getPage().getModel();
    if (!model.isEditable()) {
        return;
    }
    IFeature feature = model.getFeature();

    IFeatureURL url = feature.getURL();
    if (url == null) {
        return;
    }
    for (Iterator iter = ssel.iterator(); iter.hasNext();) {
        IFeatureURLElement urlElement = (IFeatureURLElement) iter.next();
        // IFeature feature = urlElement.getFeature();
        try {
            url.removeDiscovery(urlElement);
        } catch (CoreException e) {
            MDEPlugin.logException(e);
        }
    }
}

From source file:com.siteview.mde.internal.ui.editor.monitor.DependencyManagementSection.java

License:Open Source License

private void handleRemove() {
    IStructuredSelection ssel = (IStructuredSelection) fAdditionalTable.getSelection();

    IBuild build = getBuildModel(false).getBuild();
    IBuildEntry entry = build.getEntry(IBuildEntry.SECONDARY_DEPENDENCIES);
    Iterator it = ssel.iterator();
    try {//from w w w .j a v  a2 s . co  m
        while (it.hasNext()) {
            String pluginName = (String) it.next();
            entry.removeToken(pluginName);
        }
        if (entry.getTokens().length == 0)
            build.remove(entry);
    } catch (CoreException e) {
        MDEPlugin.logException(e);
    }
    refresh();
    markDirty();
}