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.iw.plugins.spindle.wizards.extra.ConvertComponentIntoPageAction.java

License:Mozilla Public License

/**
 * @see org.eclipse.ui.IActionDelegate#run(IAction)
 *//*from  w ww .j a  v  a  2  s .c  om*/
public void run(IAction action) {

    final Shell shell = TapestryPlugin.getDefault().getActiveWorkbenchShell();

    if (selection != null) {

        final IStructuredSelection useSelection = selection;

        IWorkspaceRunnable runnable = new IWorkspaceRunnable() {

            public void run(IProgressMonitor monitor) throws CoreException {

                try {

                    for (Iterator iter = useSelection.iterator(); iter.hasNext();) {

                        IFile file = (IFile) iter.next();

                        if (!checkPageExists(file)) {

                            convertJWCToPage(file);
                        }

                    }
                } catch (ClassCastException e) {
                    // do nothing
                } catch (CoreException e) {

                    ErrorDialog.openError(shell, "Spindle Error", "Convert failed", e.getStatus());

                    throw (e);
                }
            }
        };

        try {
            TapestryPlugin.getDefault().getWorkspace().run(runnable, null);
        } catch (CoreException e) {
        }
    }
}

From source file:com.iw.plugins.spindle.wizards.extra.ConvertComponentIntoPageAction.java

License:Mozilla Public License

/**
 * Method checkMultiSelection./*from  w  ww . j a va  2  s.  co m*/
 * @param selection
 * @return boolean
 */
private boolean checkSelection(IStructuredSelection selection) {
    boolean result = false;

    if (selection != null && !selection.isEmpty() && selection.size() == 1) {

        try {

            for (Iterator iter = selection.iterator(); iter.hasNext();) {

                IFile candidateFile = (IFile) iter.next();

                if (!candidateFile.isReadOnly() && !checkPageExists(candidateFile)) {

                    try {

                        ITapestryProject project = TapestryPlugin.getDefault()
                                .getTapestryProjectFor(candidateFile);

                        TapestryProjectModelManager mgr = project.getModelManager();

                        TapestryLibraryModel projectModel = (TapestryLibraryModel) project.getProjectModel();

                        TapestryComponentModel cmodel = null;

                        if (mgr != null && projectModel != null) {

                            IPackageFragment modelFragment = project.getLookup()
                                    .findPackageFragment(candidateFile);

                            if (modelFragment != null) {

                                fragment = modelFragment;

                                cmodel = (TapestryComponentModel) mgr.getReadOnlyModel(candidateFile);

                                if (cmodel.isLoaded()) {

                                    result = true;

                                }
                            }

                        }

                    } catch (CoreException e) {

                    }
                }

            }
        } catch (ClassCastException e) {

        }
    }
    return result;
}

From source file:com.ixenit.membersort.handlers.SortHandler.java

License:Apache License

private void _sortSelection(IStructuredSelection selection)
        throws JavaModelException, MalformedTreeException, BadLocationException {

    // Iterate through the selected elements
    for (Iterator<?> iterator = selection.iterator(); iterator.hasNext();) {
        Object fragment = iterator.next();

        // If the current element is a java package the retrieve
        // its compilation units and process them
        if (fragment instanceof IPackageFragment) {
            IPackageFragment pkg = (IPackageFragment) fragment;

            ICompilationUnit[] compilationUnits = pkg.getCompilationUnits();

            for (ICompilationUnit iCompilationUnit : compilationUnits) {
                _processUnit(iCompilationUnit);
            }//from w w w . j av a 2s .co m
        } else if (fragment instanceof ICompilationUnit) {
            _processUnit((ICompilationUnit) fragment);
        }
    }
}

From source file:com.jalios.jcmstools.transversal.EJPTUtil.java

License:LGPL

public static IProject getSelectedProject(ExecutionEvent event) {
    IProject syncProject = null;/*from w  w  w .j av  a 2s  . c  o m*/

    // case 1 : user is working on an active editor on a file and sync
    // action is
    // called
    IEditorPart activeEditor = HandlerUtil.getActiveEditor(event);
    if (activeEditor instanceof IFileEditorInput) {
        IFileEditorInput input = (IFileEditorInput) activeEditor.getEditorInput();
        syncProject = input.getFile().getProject();

        if (isJCMSPluginProject(syncProject)) {
            return syncProject;
        }
    }

    // case 2 : user is selecting a tree selection in the packaging/project
    // explorer
    try {
        ISelection selection = HandlerUtil.getCurrentSelectionChecked(event);
        if (selection instanceof IStructuredSelection) {
            IStructuredSelection structuredSelection = (IStructuredSelection) selection;
            Object element = structuredSelection.iterator().next();
            if (element instanceof IProject) {
                if (isJCMSPluginProject((IProject) element)) {
                    return (IProject) element;
                }
            }
            if (element instanceof IResource) {
                IResource resource = (IResource) element;
                if (isJCMSPluginProject(resource.getProject())) {
                    return resource.getProject();
                }
            }
        }
    } catch (ExecutionException e) {
        e.printStackTrace();
    }

    return syncProject;
}

From source file:com.kdmanalytics.toif.ui.common.ResourceChangeMonitor.java

License:Open Source License

@Override
public void selectionChanged(IWorkbenchPart part, ISelection selection) {
    if (selection instanceof IStructuredSelection) {
        IStructuredSelection sel = (IStructuredSelection) selection;
        for (Iterator<?> it = sel.iterator(); it.hasNext();) {
            Object o = it.next();
            if (o instanceof IResource) {
                setSelectedCitedResources((IResource) o);
            }/*from  w  ww  . j  av  a  2 s.  co  m*/
        }
    }
}

From source file:com.kdmanalytics.toif.ui.handlers.FilterToifHandler.java

License:Open Source License

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {

        public void run() {
            IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
            ISelectionService service = window.getSelectionService();
            ISelection selection = service.getSelection();

            if (selection instanceof IStructuredSelection) {
                IStructuredSelection sel = (IStructuredSelection) selection;
                List<IResource> resources = new LinkedList<IResource>();
                for (Iterator<?> it = sel.iterator(); it.hasNext();) {
                    Object o = it.next();
                    if (o instanceof IAdaptable) {
                        o = ((IAdaptable) o).getAdapter(IResource.class);
                    }/*from w w  w  . j  a  v a2  s . c o m*/
                    if (o instanceof IResource) {
                        resources.add((IResource) o);
                    }
                }

                IWorkbenchPage page = window.getActivePage();
                try {
                    FindingView view = (FindingView) page.showView("com.kdmanalytics.toif.views.FindingView");
                    view.setResourceFilter(resources);
                    view.refresh();
                } catch (PartInitException e) {
                    e.printStackTrace();
                }
            }
        }
    });

    return null;
}

From source file:com.kdmanalytics.toif.ui.views.FindingSelectionChangedListener.java

License:Open Source License

@Override
public void selectionChanged(SelectionChangedEvent event) {
    viewer = (TreeViewer) event.getSource();

    IStructuredSelection selection = (IStructuredSelection) event.getSelection();
    clear();/*from   w w  w  . j ava 2s  . c  om*/
    for (Iterator<?> it = selection.iterator(); it.hasNext();) {
        Object o = it.next();
        if (o instanceof IFindingEntry) {
            add((IFindingEntry) o);
        }
    }
}

From source file:com.kopson.cite.actions.CopyRowClipboard.java

License:Open Source License

@SuppressWarnings("unchecked")
@Override//from  w w w. ja  v a 2  s .  com
public Object execute(ExecutionEvent event) throws ExecutionException {

    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    IWorkbenchPage page = window.getActivePage();
    IViewPart view = page.findView(SmartLogConsole.ID);
    Clipboard clipboard = new Clipboard(Display.getDefault());
    ISelection selection = view.getSite().getSelectionProvider().getSelection();
    List<SmartLogEntry> logList = new ArrayList<SmartLogEntry>();
    if (selection != null && selection instanceof IStructuredSelection) {
        IStructuredSelection currentSelection = (IStructuredSelection) selection;
        for (Iterator<SmartLogEntry> iterator = currentSelection.iterator(); iterator.hasNext();) {
            SmartLogEntry logRow = iterator.next();
            logList.add(logRow);
        }
    }
    StringBuilder sb = new StringBuilder();
    for (SmartLogEntry logRow : logList) {
        sb.append(rowToString(logRow));
    }
    TextTransfer textTransfer = TextTransfer.getInstance();
    clipboard.setContents(new Object[] { sb.toString() }, new Transfer[] { textTransfer });

    return null;
}

From source file:com.legstar.eclipse.plugin.schemagen.wizards.JavaToXsdWizardPage.java

License:Open Source License

/**
 * The composite widget presenting the currently selected java classes.
 * /*from w  w w  . ja v a2s.c  o  m*/
 * @param container the parent container
 */
private void createJavaClassesTableViewer(final Composite container) {
    createTable(container);
    mJavaClassesTableViewer = new TableViewer(mTable);
    mJavaClassesTableViewer.setUseHashlookup(true);
    mJavaClassesTableViewer.setColumnProperties(mColumnNames);
    mJavaClassesTableViewer.setSorter(new JavaClassSorter(JavaClassSorter.JAVAPROJECT));
    mJavaClassesTableViewer.setLabelProvider(new JavaClassesTableLabelProvider());
    mJavaClassesTableViewer.setContentProvider(new JavaClassesTableContentProvider());
    mJavaClassesTableViewer.setInput(mModel);

    final Button removeButton = new Button(container, SWT.NONE);
    removeButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(final SelectionEvent e) {
            IStructuredSelection selection = (IStructuredSelection) mJavaClassesTableViewer.getSelection();
            for (Iterator<?> iterator = selection.iterator(); iterator.hasNext();) {
                JavaClass element = (JavaClass) iterator.next();
                removeJavaClass(element);
            }
            dialogChanged();

        }
    });
    removeButton.setText(Messages.remove_button_label);
    GridData gridData = new GridData(GridData.HORIZONTAL_ALIGN_END);
    gridData.horizontalSpan = LAYOUT_COLUMNS;
    removeButton.setLayoutData(gridData);

}

From source file:com.liferay.ide.kaleo.ui.action.AbstractWorkflowDefinitionAction.java

License:Open Source License

/**
 * Update the enabled state.//from   w w w.j a  va 2s  .  c  o  m
 *
 * @param sel
 *            a selection
 */
@SuppressWarnings("rawtypes")
public void selectionChanged(IStructuredSelection sel) {
    if (sel.isEmpty()) {
        setEnabled(false);
        return;
    }

    boolean enabled = false;
    Iterator iterator = sel.iterator();

    while (iterator.hasNext()) {
        Object obj = iterator.next();
        if (obj instanceof WorkflowDefinitionEntry) {
            WorkflowDefinitionEntry node = (WorkflowDefinitionEntry) obj;
            if (accept(node)) {
                enabled = true;
            }
        } else if (obj instanceof WorkflowDefinitionsFolder) {
            WorkflowDefinitionsFolder node = (WorkflowDefinitionsFolder) obj;
            if (accept(node)) {
                enabled = true;
            }
        } else {
            setEnabled(false);
            return;
        }
    }

    setEnabled(enabled);
}