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.siteview.mde.internal.ui.search.PluginSearchPage.java

License:Open Source License

private HashSet getSelectedResources() {
    HashSet result = new HashSet();
    int scope = container.getSelectedScope();
    if (scope == ISearchPageContainer.WORKSPACE_SCOPE)
        return null;
    if (scope == ISearchPageContainer.SELECTION_SCOPE
            || scope == ISearchPageContainer.SELECTED_PROJECTS_SCOPE) {
        if (container.getSelection() instanceof IStructuredSelection) {
            IStructuredSelection selection = (IStructuredSelection) container.getSelection();
            Iterator iter = selection.iterator();
            while (iter.hasNext()) {
                Object item = iter.next();
                if (item instanceof IResource)
                    result.add(((IResource) item).getProject());
            }/*from  w  w w . j a  va2 s  .  co  m*/
        } else if (container.getActiveEditorInput() != null) {
            result.add(container.getActiveEditorInput().getAdapter(IFile.class));
        }
    } else if (scope == ISearchPageContainer.WORKING_SET_SCOPE) {
        IWorkingSet[] workingSets = container.getSelectedWorkingSets();
        if (workingSets != null) {
            for (int i = 0; i < workingSets.length; i++) {
                IAdaptable[] elements = workingSets[i].getElements();
                for (int j = 0; j < elements.length; j++) {
                    IResource resource = (IResource) elements[j].getAdapter(IResource.class);
                    if (resource != null)
                        result.add(resource.getProject());
                }
            }
        }
    }
    return result;
}

From source file:com.siteview.mde.internal.ui.shared.target.TargetLocationsGroup.java

License:Open Source License

private void handleRemove() {
    IStructuredSelection selection = (IStructuredSelection) fTreeViewer.getSelection();
    IBundleContainer[] containers = fTarget.getBundleContainers();
    if (!selection.isEmpty() && containers != null && containers.length > 0) {
        List toRemove = new ArrayList();
        boolean removedSite = false;
        boolean removedContainer = false;
        for (Iterator iterator = selection.iterator(); iterator.hasNext();) {
            Object currentSelection = iterator.next();
            if (currentSelection instanceof IBundleContainer) {
                if (currentSelection instanceof IUBundleContainer) {
                    removedSite = true;//from w  w w.  ja  v a 2s .  c  om
                }
                removedContainer = true;
                toRemove.add(currentSelection);
            }
            if (currentSelection instanceof IUWrapper) {
                toRemove.add(currentSelection);
            }
        }

        if (removedContainer) {
            Set newContainers = new HashSet();
            newContainers.addAll(Arrays.asList(fTarget.getBundleContainers()));
            newContainers.removeAll(toRemove);
            if (newContainers.size() > 0) {
                fTarget.setBundleContainers(
                        (IBundleContainer[]) newContainers.toArray(new IBundleContainer[newContainers.size()]));
            } else {
                fTarget.setBundleContainers(null);
            }

            // If we remove a site container, the content change update must force a re-resolve bug 275458 / bug 275401
            contentsChanged(removedSite);
            fTreeViewer.refresh(false);
            updateButtons();
        } else {
            for (Iterator iterator = toRemove.iterator(); iterator.hasNext();) {
                Object current = iterator.next();
                if (current instanceof IUWrapper) {
                    ((IUWrapper) current).getParent().removeInstallableUnit(((IUWrapper) current).getIU());
                }
            }
            contentsChanged(removedSite);
            fTreeViewer.refresh(true);
            updateButtons();
        }
    }
}

From source file:com.siteview.mde.internal.ui.shared.target.TargetLocationsGroup.java

License:Open Source License

private void handleUpdate() {
    // go over the selection and make a map from container to set of ius to update.
    // if the set is empty then the whole container is to be updated.
    IStructuredSelection selection = (IStructuredSelection) fTreeViewer.getSelection();
    Map toUpdate = new HashMap();
    for (Iterator iterator = selection.iterator(); iterator.hasNext();) {
        Object currentSelection = iterator.next();
        if (currentSelection instanceof IBundleContainer)
            toUpdate.put(currentSelection, new HashSet(0));
        else if (currentSelection instanceof IUWrapper) {
            IUWrapper wrapper = (IUWrapper) currentSelection;
            Set iuSet = (Set) toUpdate.get(wrapper.getParent());
            if (iuSet == null) {
                iuSet = new HashSet();
                iuSet.add(wrapper.getIU().getId());
                toUpdate.put(wrapper.getParent(), iuSet);
            } else if (!iuSet.isEmpty())
                iuSet.add(wrapper.getIU().getId());
        }//from w  ww  .  j  a  v  a2  s. com
    }
    if (toUpdate.isEmpty())
        return;

    JobChangeAdapter listener = new JobChangeAdapter() {
        public void done(final IJobChangeEvent event) {
            Display.getDefault().asyncExec(new Runnable() {
                public void run() {
                    // XXX what if everything is disposed by the time we get back?
                    UpdateTargetJob job = (UpdateTargetJob) event.getJob();
                    contentsChanged(job.isUpdated());
                    fTreeViewer.refresh(true);
                    try {
                        ITargetHandle currentTarget = TargetPlatformService.getDefault()
                                .getWorkspaceTargetHandle();
                        if (job.isUpdated() && fTarget.getHandle().equals(currentTarget))
                            LoadTargetDefinitionJob.load(fTarget);
                    } catch (CoreException e) {
                        // do nothing if we could not see the current target.
                    }
                    updateButtons();
                }
            });
        }
    };
    UpdateTargetJob.update(toUpdate, listener);
}

From source file:com.siteview.mde.internal.ui.shared.target.TargetLocationsGroup.java

License:Open Source License

private void updateButtons() {
    IStructuredSelection selection = (IStructuredSelection) fTreeViewer.getSelection();
    fEditButton.setEnabled(!selection.isEmpty() && (selection.getFirstElement() instanceof IBundleContainer
            || selection.getFirstElement() instanceof IUWrapper));
    // If any container is selected, allow the remove (the remove ignores non-container entries)
    boolean removeAllowed = false;
    boolean updateAllowed = false;
    Iterator iter = selection.iterator();
    while (iter.hasNext()) {
        if (removeAllowed && updateAllowed) {
            break;
        }/*from   w  ww  .ja va2 s  . c o m*/
        Object current = iter.next();
        if (current instanceof IUBundleContainer) {
            updateAllowed = true;
        }
        if (current instanceof IBundleContainer) {
            removeAllowed = true;
        }
        if (current instanceof IUWrapper) {
            removeAllowed = true;
            updateAllowed = true;
        }
    }
    fRemoveButton.setEnabled(removeAllowed);
    fUpdateButton.setEnabled(updateAllowed);
}

From source file:com.siteview.mde.internal.ui.views.plugins.CopyToClipboardAction.java

License:Open Source License

private boolean canCopy(IStructuredSelection selection) {
    if (selection.isEmpty())
        return false;
    for (Iterator iter = selection.iterator(); iter.hasNext();) {
        Object obj = iter.next();
        if (!(obj instanceof FileAdapter))
            return false;
    }//  ww w .  ja  va 2s.c  o  m
    return true;
}

From source file:com.siteview.mde.internal.ui.views.plugins.ImportActionGroup.java

License:Open Source License

private void handleImport(int importType, IStructuredSelection selection) {
    ArrayList externalModels = new ArrayList();
    for (Iterator iter = selection.iterator(); iter.hasNext();) {
        IMonitorModelBase model = getModel(iter.next());
        if (model != null && model.getUnderlyingResource() == null)
            externalModels.add(model);//from   ww  w  .  j a va2  s  .c o  m
    }
    Display display = Display.getCurrent();
    if (display == null)
        display = Display.getDefault();
    IMonitorModelBase[] models = (IMonitorModelBase[]) externalModels
            .toArray(new IMonitorModelBase[externalModels.size()]);
    if (importType == PluginImportOperation.IMPORT_FROM_REPOSITORY) {
        Map importMap = getImportDescriptions(display.getActiveShell(), models);
        if (importMap != null) {
            RepositoryImportWizard wizard = new RepositoryImportWizard(importMap);
            WizardDialog dialog = new WizardDialog(display.getActiveShell(), wizard);
            dialog.open();
        }
    } else {
        PluginImportWizard.doImportOperation(display.getActiveShell(), importType, models, false);
    }
}

From source file:com.siteview.mde.internal.ui.views.plugins.ImportActionGroup.java

License:Open Source License

public static boolean canImport(IStructuredSelection selection) {
    for (Iterator iter = selection.iterator(); iter.hasNext();) {
        IMonitorModelBase model = getModel(iter.next());
        if (model != null && model.getUnderlyingResource() == null)
            return true;
    }//from w w  w.  j  a  va  2s.  c  o m
    return false;
}

From source file:com.siteview.mde.internal.ui.views.plugins.JavaSearchActionGroup.java

License:Open Source License

private boolean canDoJavaSearchOperation(IStructuredSelection selection, boolean add) {
    int nhits = 0;
    IMonitorModelBase model = null;/*w  w  w . ja va 2 s.  c om*/
    SearchablePluginsManager manager = MDECore.getDefault().getSearchablePluginsManager();
    for (Iterator iter = selection.iterator(); iter.hasNext();) {
        model = getModel(iter.next());
        if (model == null)
            return false;

        if (model.getUnderlyingResource() == null) {
            if (add == !manager.isInJavaSearch(model.getMonitorBase().getId()))
                nhits++;
        }
    }
    return nhits > 0;
}

From source file:com.siteview.mde.internal.ui.views.plugins.JavaSearchActionGroup.java

License:Open Source License

private void handleJavaSearch(final boolean add) {
    IStructuredSelection selection = (IStructuredSelection) getContext().getSelection();
    if (selection.size() == 0)
        return;/*from w  ww  .  j av a 2  s  .  c  om*/

    ArrayList result = new ArrayList();
    SearchablePluginsManager manager = MDECore.getDefault().getSearchablePluginsManager();
    for (Iterator iter = selection.iterator(); iter.hasNext();) {
        IMonitorModelBase model = getModel(iter.next());
        if (model != null && model.getUnderlyingResource() == null
                && manager.isInJavaSearch(model.getMonitorBase().getId()) != add) {
            result.add(model);
        }
    }
    if (result.size() == 0)
        return;
    final IMonitorModelBase[] array = (IMonitorModelBase[]) result
            .toArray(new IMonitorModelBase[result.size()]);

    IRunnableWithProgress op = new JavaSearchOperation(array, add);
    try {
        PlatformUI.getWorkbench().getProgressService().busyCursorWhile(op);
    } catch (InterruptedException e) {
    } catch (InvocationTargetException e) {
        MDEPlugin.logException(e);
    }
}

From source file:com.siteview.mde.internal.ui.views.plugins.PluginsDragAdapter.java

License:Open Source License

private FileAdapter[] getSelectedFiles() {
    IStructuredSelection selection = (IStructuredSelection) selectionProvider.getSelection();
    ArrayList files = new ArrayList();
    for (Iterator iter = selection.iterator(); iter.hasNext();) {
        Object obj = iter.next();
        if (obj instanceof FileAdapter)
            files.add(obj);/*w  ww . j  a  va2  s. c  o m*/
        else
            return new FileAdapter[0];
    }
    return (FileAdapter[]) files.toArray(new FileAdapter[files.size()]);
}