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.liferay.ide.kaleo.ui.navigator.WorkflowDefinitionsActionProvider.java

License:Open Source License

public void fillContextMenu(IMenuManager menu) {
    // This is a temp workaround to clean up the default group that are provided by CNF
    menu.removeAll();/*from   w w w  . j  av  a  2 s .c o m*/

    ICommonViewerSite site = actionSite.getViewSite();
    IStructuredSelection selection = null;

    if (site instanceof ICommonViewerWorkbenchSite) {
        ICommonViewerWorkbenchSite wsSite = (ICommonViewerWorkbenchSite) site;
        selection = (IStructuredSelection) wsSite.getSelectionProvider().getSelection();
    }

    WorkflowDefinitionEntry definition = null;
    WorkflowDefinitionsFolder definitionsFolder = null;

    if (selection != null && !selection.isEmpty()) {
        Iterator<?> iterator = selection.iterator();
        Object obj = iterator.next();

        if (obj instanceof WorkflowDefinitionEntry) {
            definition = (WorkflowDefinitionEntry) obj;
        }

        if (obj instanceof WorkflowDefinitionsFolder) {
            definitionsFolder = (WorkflowDefinitionsFolder) obj;
        }

        if (iterator.hasNext()) {
            definition = null;
            definitionsFolder = null;
        }
    }

    menu.add(invisibleSeparator(TOP_SECTION_START_SEPARATOR));
    addTopSection(menu, definition, definitionsFolder);
    menu.add(invisibleSeparator(TOP_SECTION_END_SEPARATOR));
    menu.add(new Separator());

    menu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
    menu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS + "-end"));
}

From source file:com.liferay.ide.portlet.ui.editor.PortalDeployExcludesSection.java

License:Open Source License

@SuppressWarnings("rawtypes")
private void handleRemove() {
    IStructuredSelection ssel = (IStructuredSelection) fViewer.getSelection();
    PluginPackageModel model = (PluginPackageModel) getPage().getModel();
    int i = 0;/*from ww w  . ja  va 2 s  .co m*/
    String[] removedFiles = new String[ssel.size()];
    for (Iterator iter = ssel.iterator(); iter.hasNext(); i++) {
        removedFiles[i] = ((File) iter.next()).getName();
    }

    model.removePortalDeployExcludeJar(removedFiles);
    updateButtons();
}

From source file:com.liferay.ide.portlet.ui.editor.PortalJarsSection.java

License:Open Source License

@SuppressWarnings("rawtypes")
private void handleRemove() {
    IStructuredSelection ssel = (IStructuredSelection) fViewer.getSelection();
    PluginPackageModel model = (PluginPackageModel) getPage().getModel();
    int i = 0;//from w w  w .j  a va  2  s  .  c om
    String[] removedFiles = new String[ssel.size()];
    for (Iterator iter = ssel.iterator(); iter.hasNext(); i++) {
        removedFiles[i] = ((File) iter.next()).getName();
    }

    model.removePortalDependencyJars(removedFiles);
    updateButtons();
}

From source file:com.liferay.ide.portlet.ui.editor.PortalTldsSection.java

License:Open Source License

@SuppressWarnings("rawtypes")
private void handleRemove() {
    IStructuredSelection ssel = (IStructuredSelection) fViewer.getSelection();
    PluginPackageModel model = (PluginPackageModel) getPage().getModel();
    int i = 0;//from  w  w w .jav a  2s .com
    String[] removedFiles = new String[ssel.size()];
    for (Iterator iter = ssel.iterator(); iter.hasNext(); i++) {
        removedFiles[i] = ((File) iter.next()).getName();
    }

    model.removePortalDependencyTlds(removedFiles);
    updateButtons();
}

From source file:com.liferay.ide.portlet.ui.editor.RequiredDeploymentContextsSection.java

License:Open Source License

@SuppressWarnings("rawtypes")
private void handleRemove() {
    IStructuredSelection ssel = (IStructuredSelection) fViewer.getSelection();
    PluginPackageModel model = (PluginPackageModel) getPage().getModel();
    int i = 0;/*w w  w  . j  ava 2  s .c o m*/
    String[] removedServiceDeps = new String[ssel.size()];
    for (Iterator iter = ssel.iterator(); iter.hasNext(); i++) {
        removedServiceDeps[i] = iter.next().toString();
    }

    model.removeRequiredDeploymentContexts(removedServiceDeps);
    updateButtons();
}

From source file:com.liferay.ide.project.ui.migration.AutoCorrectAction.java

License:Open Source License

@Override
public void selectionChanged(IStructuredSelection selection) {
    if (selection.isEmpty()) {
        setEnabled(false);// w w w .jav  a2 s  .  co  m
    } else {
        boolean selectionCompatible = true;

        Iterator<?> items = selection.iterator();
        Object lastItem = null;

        while (items.hasNext()) {
            Object item = items.next();

            if (!(item instanceof Problem)) {
                selectionCompatible = false;
                break;
            }

            Problem problem = (Problem) item;

            if (problem.autoCorrectContext == null) {
                selectionCompatible = false;
                break;
            }
            if (lastItem != null) {
                String prCurrentKey = ((Problem) item).autoCorrectContext.substring(0,
                        problem.autoCorrectContext.indexOf(":"));
                ;
                String prLastKey = ((Problem) lastItem).autoCorrectContext.substring(0,
                        problem.autoCorrectContext.indexOf(":"));

                if (!(prCurrentKey.equals(prLastKey))) {
                    selectionCompatible = false;
                    break;
                }
            }

            lastItem = item;
        }

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

        List<String> autoCorrectContexts = new ArrayList<>();

        while (items2.hasNext()) {
            Object item = items2.next();

            if (item instanceof Problem && ((Problem) item).autoCorrectContext != null) {
                autoCorrectContexts.add(((Problem) item).autoCorrectContext);
            }
        }

        setEnabled(selectionCompatible);

        List<String> allAutoCorrectContexts = new ArrayList<>();

        if (_provider instanceof TableViewer) {
            TableViewer viewer = (TableViewer) _provider;
            Object obj = viewer.getInput();
            if (obj instanceof Object[]) {
                Object[] problems = (Object[]) obj;

                for (Object o : problems) {
                    if (o instanceof Problem && ((Problem) o).autoCorrectContext != null) {
                        allAutoCorrectContexts.add(((Problem) o).autoCorrectContext);
                    }
                }
            } else if (obj instanceof List<?>) {
                List<?> list = (List<?>) obj;

                for (Object p : list) {
                    if (p instanceof Problem) {
                        Problem problem = (Problem) p;

                        if (problem.autoCorrectContext != null) {
                            allAutoCorrectContexts.add(problem.autoCorrectContext);
                        }
                    }
                }
            }
        }

        setText("Correct automatically");
    }
}

From source file:com.liferay.ide.project.ui.migration.MigrationUtil.java

License:Open Source License

public static List<Problem> getProblemsFromSelection(ISelection selection) {
    final List<Problem> problems = new ArrayList<>();

    if (selection instanceof IStructuredSelection) {
        final IStructuredSelection ss = (IStructuredSelection) selection;

        Iterator<?> elements = ss.iterator();

        while (elements.hasNext()) {
            Object element = elements.next();

            if (element instanceof Problem) {
                problems.add((Problem) element);
            }/*from www  . j  a v  a 2 s. c  o m*/
        }
    }

    return problems;
}

From source file:com.liferay.ide.project.ui.migration.MigrationUtil.java

License:Open Source License

@SuppressWarnings("rawtypes")
public static List<Problem> getProblemsFromTreeNode(ISelection selection) {
    if (selection instanceof IStructuredSelection) {
        final IStructuredSelection ss = (IStructuredSelection) selection;

        Iterator iterator = ss.iterator();

        List<Problem> allProblems = new ArrayList<>();

        while (iterator.hasNext()) {
            Object element = iterator.next();

            if (element instanceof FileProblems) {
                FileProblems fp = (FileProblems) element;

                allProblems.addAll(fp.getProblems());
            } else if (element instanceof MigrationProblems) {
                MigrationProblems migrationProblems = (MigrationProblems) element;

                for (FileProblems fProblems : migrationProblems.getProblems()) {
                    allProblems.addAll(fProblems.getProblems());
                }// ww w. j  ava  2 s  .  c  om
            } else if (element instanceof MigrationProblemsContainer) {
                MigrationProblemsContainer migrationProblemsContainer = (MigrationProblemsContainer) element;

                for (MigrationProblems migrationProblems : migrationProblemsContainer.getProblemsArray()) {
                    for (FileProblems fProblems : migrationProblems.getProblems()) {
                        allProblems.addAll(fProblems.getProblems());
                    }
                }
            }
        }

        // remove duplicate problem
        HashSet<Problem> hashSet = new HashSet<Problem>(allProblems);
        allProblems.clear();
        allProblems.addAll(hashSet);

        return allProblems;
    }

    return null;
}

From source file:com.liferay.ide.project.ui.migration.MigrationUtil.java

License:Open Source License

@SuppressWarnings("rawtypes")
public static List<Problem> getCurrentProblemsFromTreeNode(ISelection selection) {
    if (selection instanceof IStructuredSelection) {
        final IStructuredSelection ss = (IStructuredSelection) selection;

        Iterator iterator = ss.iterator();

        List<Problem> notIgnoreProblems = new ArrayList<>();

        while (iterator.hasNext()) {
            Object element = iterator.next();

            if (element instanceof FileProblems) {
                FileProblems fp = (FileProblems) element;

                for (Problem problem : fp.getProblems()) {
                    if (problem.getStatus() != Problem.STATUS_IGNORE) {
                        notIgnoreProblems.add(problem);
                    }/*ww w .  ja v a2s.c  o m*/
                }
            } else if (element instanceof MigrationProblems) {
                MigrationProblems migrationProblems = (MigrationProblems) element;

                for (FileProblems fProblems : migrationProblems.getProblems()) {
                    for (Problem problem : fProblems.getProblems()) {
                        if (problem.getStatus() != Problem.STATUS_IGNORE) {
                            notIgnoreProblems.add(problem);
                        }
                    }
                }
            } else if (element instanceof MigrationProblemsContainer) {
                MigrationProblemsContainer migrationProblemsContainer = (MigrationProblemsContainer) element;

                for (MigrationProblems migrationProblems : migrationProblemsContainer.getProblemsArray()) {
                    for (FileProblems fProblems : migrationProblems.getProblems()) {
                        for (Problem problem : fProblems.getProblems()) {
                            if (problem.getStatus() != Problem.STATUS_IGNORE) {
                                notIgnoreProblems.add(problem);
                            }
                        }
                    }
                }
            }
        }

        // remove duplicate problem
        HashSet<Problem> hashSet = new HashSet<Problem>(notIgnoreProblems);
        notIgnoreProblems.clear();
        notIgnoreProblems.addAll(hashSet);

        return notIgnoreProblems;
    }

    return null;
}

From source file:com.liferay.ide.sdk.ui.InstalledSDKsCompostite.java

License:Open Source License

protected void enableButtons() {
    IStructuredSelection selection = (IStructuredSelection) this.tableViewer.getSelection();

    int selectionCount = selection.size();

    if (selectionCount > 0 && selectionCount <= this.tableViewer.getTable().getItemCount()) {
        Iterator<?> iterator = selection.iterator();

        while (iterator.hasNext()) {
            SDK install = (SDK) iterator.next();

            if (isContributed(install)) {
                fEditButton.setEnabled(false);
                fRemoveButton.setEnabled(false);

                return;
            }/*from   w  w  w  .j a  v  a2 s .  co m*/
        }

        fEditButton.setEnabled(true);
        fRemoveButton.setEnabled(true);
        fOpenInEclipse.setEnabled(true);
    } else {
        fEditButton.setEnabled(false);
        fRemoveButton.setEnabled(false);
        fOpenInEclipse.setEnabled(false);
    }
}