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.buildml.eclipse.utils.GraphitiUtils.java

License:Open Source License

/**
 * Return a list of the objects currently selected on the Graphiti Diagram. The returned
 * list will only contain business objects (e.g. UIFileGroup, etc). This method is
 * useful for converting the Graphiti EditPart objects into objects that we actually
 * care about.// w  w  w . jav a2 s .c  o m
 * 
 * @return A list of business objects currently selected, or null if there's an
 * error fetching the selection.
 */
public static List<Object> getSelection() {

    IStructuredSelection selectedParts = EclipsePartUtils.getSelection();
    if (selectedParts == null) {
        return null;
    }

    /* traverse the list of selected "edit parts" and convert to business objects */
    List<Object> result = new ArrayList<Object>();
    Iterator<Object> iter = selectedParts.iterator();
    while (iter.hasNext()) {
        Object element = iter.next();
        PictogramElement pe = null;

        /* handle shapes (actions, file groups, etc) */
        if (element instanceof GraphitiShapeEditPart) {
            GraphitiShapeEditPart shapeEditPart = (GraphitiShapeEditPart) element;
            pe = shapeEditPart.getPictogramElement();
        }

        /* handle connection arrows */
        else if (element instanceof GraphitiConnectionEditPart) {
            GraphitiConnectionEditPart connectionEditPart = (GraphitiConnectionEditPart) element;
            pe = connectionEditPart.getPictogramElement();
        }

        /* convert Pictogram Element into business object, and add to result list */
        if (pe != null) {
            Object bo = getBusinessObject(pe);
            if (bo != null) {
                result.add(bo);
            }
        }

    }
    return result;
}

From source file:com.byterefinery.rmbench.actions.ForeignKeyAction.java

License:Open Source License

protected boolean calculateEnabled() {

    selectedColumnGroup = null;/* w w w . j ava2  s .  c o m*/
    groupTable = null;

    ISelection sel = (ISelection) getSelection();
    if (!(sel instanceof IStructuredSelection))
        return false;

    IStructuredSelection selection = (IStructuredSelection) sel;
    List<Column> columnGroup = new ArrayList<Column>(selection.size());

    for (Iterator<?> it = selection.iterator(); it.hasNext();) {
        Object selected = it.next();
        if (!(selected instanceof ColumnEditPart)) {
            return false;
        } else {
            Column column = ((ColumnEditPart) selected).getColumn();
            if (groupTable == null)
                groupTable = column.getTable();
            else if (groupTable != column.getTable()) {
                return false;
            }
            columnGroup.add(column);
        }
    }
    selectedColumnGroup = (Column[]) columnGroup.toArray(new Column[columnGroup.size()]);
    return true;
}

From source file:com.centurylink.mdw.plugin.designer.properties.editor.ListComposer.java

License:Apache License

private void rem() {
    IStructuredSelection selection = (IStructuredSelection) destViewer.getSelection();
    if (!selection.isEmpty()) {
        Iterator<?> it = selection.iterator();
        while (it.hasNext()) {
            Object item = it.next();
            destMutableCP.remFromDest(item);
        }/*from ww w . j  a v  a2 s .  c o  m*/
        destViewer.refresh();
        srcViewer.refresh();
    }
}

From source file:com.centurylink.mdw.plugin.designer.properties.editor.ListComposer.java

License:Apache License

private void add() {
    IStructuredSelection selection = (IStructuredSelection) srcViewer.getSelection();
    if (!selection.isEmpty()) {
        Iterator<?> it = selection.iterator();
        while (it.hasNext()) {
            Object item = it.next();
            destMutableCP.addToDest(item);
        }//w  w w .j  a  va  2 s.  c  o m
        destViewer.refresh();
        srcViewer.refresh();
    }
}

From source file:com.cloudbees.eclipse.dtp.internal.actions.DeleteDatabaseAction.java

License:Open Source License

@Override
public void run(IAction action) {
    if (action instanceof ObjectPluginAction) {
        ObjectPluginAction pluginAction = (ObjectPluginAction) action;
        ISelection selection = pluginAction.getSelection();

        if (selection instanceof IStructuredSelection) {
            final IStructuredSelection structSelection = (IStructuredSelection) selection;
            @SuppressWarnings("unchecked")
            final Iterator<DatabaseInfo> iterator = structSelection.iterator();

            String name = "-";

            if (structSelection.size() == 1) {
                DatabaseInfo d = (DatabaseInfo) structSelection.getFirstElement();
                name = d.getName();//from   w  w  w . j  av a  2 s  .com
            }

            try {
                final String target = structSelection.size() > 1 ? "the selected databases" : "'" + name + "'";
                String question = MessageFormat.format("Are you sure you want to delete {0}?", target);

                boolean confirmed = MessageDialog.openQuestion(Display.getCurrent().getActiveShell(), "Delete",
                        question);
                if (confirmed) {

                    org.eclipse.core.runtime.jobs.Job job = new org.eclipse.core.runtime.jobs.Job(
                            "Deleting " + target) {
                        @Override
                        protected IStatus run(final IProgressMonitor monitor) {

                            monitor.beginTask("Deleting " + target + "...", structSelection.size() * 10);
                            try {

                                while (iterator.hasNext()) {
                                    DatabaseInfo databaseInfo = iterator.next();
                                    monitor.subTask("Deleting '" + databaseInfo.getName() + "'...");
                                    BeesSDK.deleteDatabase(databaseInfo.getName());
                                    monitor.worked(5);
                                    deleteDatabaseConnectionProfile(databaseInfo);
                                    monitor.worked(5);
                                }

                                CloudBeesDataToolsPlugin.getPoller().fetchAndUpdateDatabases(monitor);
                                CloudBeesUIPlugin.getDefault().fireDatabaseInfoChanged();

                            } catch (Exception e) {
                                CloudBeesDataToolsPlugin.logErrorAndShowDialog(e);
                            } finally {
                                monitor.done();
                            }

                            return Status.OK_STATUS;
                        }

                    };

                    job.setUser(true);
                    job.schedule();

                }
            } catch (Exception e) {
                CloudBeesDataToolsPlugin.logError(e);
            }
        }
    }
}

From source file:com.cloudbees.eclipse.run.ui.popup.actions.DeleteAction.java

License:Open Source License

@Override
public void run(IAction action) {
    if (action instanceof ObjectPluginAction) {
        ObjectPluginAction pluginAction = (ObjectPluginAction) action;
        ISelection selection = pluginAction.getSelection();

        if (selection instanceof IStructuredSelection) {
            final IStructuredSelection structSelection = (IStructuredSelection) selection;
            @SuppressWarnings("unchecked")
            final Iterator<ApplicationInfo> iterator = structSelection.iterator();

            String name = "-";

            if (structSelection.size() == 1) {
                ApplicationInfo d = (ApplicationInfo) structSelection.getFirstElement();
                name = d.getId();/* ww  w .j ava2 s  . c om*/
            }

            try {
                final String target = structSelection.size() > 1 ? "the selected apps" : "'" + name + "'";
                String question = MessageFormat.format("Are you sure you want to delete {0}?", target);

                boolean confirmed = MessageDialog.openQuestion(Display.getCurrent().getActiveShell(), "Delete",
                        question);
                if (confirmed) {

                    org.eclipse.core.runtime.jobs.Job job = new org.eclipse.core.runtime.jobs.Job(
                            "Deleting " + target) {
                        @Override
                        protected IStatus run(final IProgressMonitor monitor) {

                            monitor.beginTask("Deleting " + target + "...", structSelection.size() * 10);
                            try {

                                while (iterator.hasNext()) {
                                    ApplicationInfo applicationInfo = iterator.next();
                                    monitor.subTask("Deleting '" + applicationInfo.getId() + "'...");
                                    BeesSDK.delete(applicationInfo.getId());
                                    monitor.worked(10);
                                }

                                CBRunCoreActivator.getPoller().fetchAndUpdateApps();
                                CloudBeesUIPlugin.getDefault().fireApplicationInfoChanged();

                            } catch (Exception e) {
                                CBRunUiActivator.logErrorAndShowDialog(e);
                            } finally {
                                monitor.done();
                            }

                            return Status.OK_STATUS;
                        }
                    };

                    job.setUser(true);
                    job.schedule();

                }
            } catch (Exception e) {
                CBRunUiActivator.logError(e);
            }
        }
    }
}

From source file:com.codeaffine.home.control.admin.ui.util.viewer.property.PropertySheetViewer.java

License:Open Source License

/**
 * Reset the selected properties to their default values.
 *///  w  w  w.  jav  a2s . c  o  m
public void resetProperties() {
    // Determine the selection
    IStructuredSelection selection = (IStructuredSelection) getSelection();

    // Iterate over entries and reset them
    Iterator itr = selection.iterator();
    while (itr.hasNext()) {
        ((IPropertySheetEntry) itr.next()).resetPropertyValue();
    }
}

From source file:com.codesourcery.internal.installer.ui.pages.ComponentsPage.java

License:Open Source License

@SuppressWarnings("synthetic-access")
@Override//w ww . j  a  va2  s.c om
public Control createContents(Composite parent) {
    Composite area = new Composite(parent, SWT.NONE);
    GridLayout areaLayout = new GridLayout();
    areaLayout.verticalSpacing = 0;
    area.setLayout(areaLayout);
    area.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));

    // Create bold font
    FontData[] fd = getFont().getFontData();
    fd[0].setStyle(SWT.BOLD);
    titleFont = new Font(getShell().getDisplay(), fd[0]);

    // Create dimmed colors
    RGB dimRGB = blendRGB(getShell().getDisplay().getSystemColor(SWT.COLOR_LIST_FOREGROUND).getRGB(),
            getShell().getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND).getRGB(), 45);
    dimColor1 = new Color(getShell().getDisplay(), dimRGB);
    dimRGB = blendRGB(getShell().getDisplay().getSystemColor(SWT.COLOR_LIST_SELECTION).getRGB(),
            getShell().getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND).getRGB(), 75);
    dimColor2 = new Color(getShell().getDisplay(), dimRGB);

    // Message label
    messageLabel = new Label(area, SWT.WRAP);
    messageLabel.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false, 1, 1));

    // Scrolled composite container
    componentContainer = new ScrolledComposite(area, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
    componentContainer.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    componentContainer.setExpandHorizontal(true);
    componentContainer.setExpandVertical(true);

    // Create the components bar
    componentsBar = new ExpandBar(componentContainer, SWT.NONE);
    componentsBar.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    componentsBar.setSpacing(COMPONENTS_MARGIN);
    componentsBar.setBackground(getShell().getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND));
    componentsBar.setBackgroundMode(SWT.INHERIT_DEFAULT);
    componentContainer.setContent(componentsBar);

    // Create required components section
    requiredList = new ExpandItem(componentsBar, SWT.NONE);
    requiredList.setText(InstallMessages.ComponentsPage_Required);
    requiredList.setImage(Installer.getDefault().getImageRegistry().get(IInstallerImages.COMPONENT));
    // Create required components panel
    requiredComponentsPanel = new ComponentsPanel(componentsBar);
    requiredList.setControl(requiredComponentsPanel);

    // Create optional components section
    optionalList = new ExpandItem(componentsBar, SWT.NONE);
    optionalList.setText(InstallMessages.ComponentsPage_Optional);
    optionalList.setImage(Installer.getDefault().getImageRegistry().get(IInstallerImages.COMPONENT_OPTIONAL));
    // Create optional components panel
    optionalComponentsPanel = new ComponentsPanel(componentsBar);
    optionalList.setControl(optionalComponentsPanel);
    optionalComponentsPanel.addSelectionChangedListener(new ISelectionChangedListener() {
        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection selection = (IStructuredSelection) event.getSelection();
            IInstallComponent[] components = RepositoryManager.getDefault().getInstallComponents();
            for (IInstallComponent component : components) {
                if (component.isOptional()) {
                    component.setInstall(false);
                    Iterator<?> iter = selection.iterator();
                    while (iter.hasNext()) {
                        if (component.equals(iter.next())) {
                            component.setInstall(true);
                            break;
                        }
                    }
                }
            }

            // Update install space for new component selection
            updateInstallPlan();
            // Update button state
            updateButtons();
            // Validate selection
            validate();
        }
    });

    // Button area
    buttonArea = new Composite(area, SWT.NONE);
    buttonArea.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    buttonArea.setLayout(new GridLayout(2, false));
    // Select all optional button
    selectAllButton = new Button(buttonArea, SWT.PUSH);
    selectAllButton.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1));
    selectAllButton.setText(InstallMessages.ComponentsPage_SelectAllOptional);
    selectAllButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            selectAllOptional(true);
        }
    });
    // Deselect all optional button
    deselectAllButton = new Button(buttonArea, SWT.PUSH);
    deselectAllButton.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1));
    deselectAllButton.setText(InstallMessages.ComponentsPage_DeselectAllOptional);
    deselectAllButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            selectAllOptional(false);
        }
    });

    statusArea = new Composite(area, SWT.NONE);
    GridLayout gl = new GridLayout(1, false);
    gl.horizontalSpacing = 0;
    gl.verticalSpacing = 0;
    gl.marginHeight = 0;
    gl.marginWidth = 0;
    statusArea.setLayout(gl);
    statusArea.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));

    progressBar = new SpinnerProgress(statusArea, SWT.NONE);
    progressBar.setText(InstallMessages.ComponentsPage_ComputingSize);
    progressBar.setLayoutData(new GridData(SWT.END, SWT.CENTER, true, false, 1, 1));
    installSizeLabel = new Label(statusArea, SWT.NONE);
    installSizeLabel.setLayoutData(new GridData(SWT.END, SWT.CENTER, true, false, 1, 1));

    setProgressVisible(false);

    // Listen to component changes
    RepositoryManager.getDefault().addRepositoryListener(this);

    // Update page
    updatePage();

    return area;
}

From source file:com.collabnet.subversion.merge.actions.OpenFileInSystemEditorAction.java

License:Open Source License

protected List getSelectedResources() {
    ArrayList openableFiles = new ArrayList();
    IStructuredSelection selection = (IStructuredSelection) selectionProvider.getSelection();
    Iterator iter = selection.iterator();
    while (iter.hasNext()) {
        Object element = iter.next();
        if (element instanceof AdaptableMergeResult) {
            MergeResult mergeResult = (MergeResult) element;
            if (mergeResult.getResource() instanceof IFile && !mergeResult.isDelete())
                openableFiles.add(mergeResult.getResource());
        }/* w  w w .  ja  va 2  s  . c  o  m*/
    }
    return openableFiles;
}

From source file:com.collabnet.subversion.merge.views.MergeResultsView.java

License:Open Source License

public void createPartControl(Composite parent) {
    GridLayout layout = new GridLayout();
    layout.numColumns = 1;/*from   w ww .j a  v  a  2  s.  com*/
    layout.verticalSpacing = 2;
    layout.marginWidth = 0;
    layout.marginHeight = 2;
    parent.setLayout(layout);

    treeViewer = new TreeViewer(parent);
    treeViewer.setLabelProvider(labelProvider);
    treeViewer.setContentProvider(new MergeResultsViewContentProvider());
    treeViewer.setUseHashlookup(true);
    GridData layoutData = new GridData();
    layoutData.grabExcessHorizontalSpace = true;
    layoutData.grabExcessVerticalSpace = true;
    layoutData.horizontalAlignment = GridData.FILL;
    layoutData.verticalAlignment = GridData.FILL;
    treeViewer.getControl().setLayoutData(layoutData);
    treeViewer.setInput(this);
    treeViewer.addOpenListener(new IOpenListener() {
        public void open(OpenEvent event) {
            treeConflict = null;
            IStructuredSelection selection = (IStructuredSelection) treeViewer.getSelection();
            Object selectedItem = selection.getFirstElement();
            MergeResult mergeResult = null;
            if (selectedItem instanceof AdaptableMergeResult)
                mergeResult = (MergeResult) selectedItem;
            if (selectedItem instanceof AdaptableMergeResultsFolder) {
                MergeResultsFolder mergeResultsFolder = (MergeResultsFolder) selectedItem;
                mergeResult = mergeResultsFolder.getMergeResult();
            }
            if (mergeResult != null) {
                if (mergeResult.getResource() instanceof IFile && mergeResult.isConflicted()
                        && !mergeResult.isResolved()) {
                    editConflicts(mergeResult);
                    return;
                }
                if (mergeResult.getResource() instanceof IFile && mergeResult.hasTreeConflict()
                        && !mergeResult.isTreeConflictResolved()) {
                    boolean addAddConflict = false;
                    if (mergeResult.getResource() != null && mergeResult.getResource().exists()) {
                        treeConflict = getTreeConflict(mergeResult.getResource());
                        if (treeConflict != null && treeConflict.getDescription() != null
                                && treeConflict.getDescription().contains("local add") //$NON-NLS-1$
                                && treeConflict.getDescription().contains("incoming add")) { //$NON-NLS-1$
                            addAddConflict = true;
                        }
                        if (!addAddConflict) {
                            openAction.run();
                        }
                    }
                    if (!addAddConflict) {
                        return;
                    }
                }
                if (!mergeResult.getAction().equals(MergeResult.ACTION_DELETE)) {
                    final ISVNLocalResource localResource = SVNWorkspaceRoot
                            .getSVNResourceFor(mergeResult.getResource());
                    if (!localResource.exists()) {
                        return;
                    }
                    BusyIndicator.showWhile(Display.getCurrent(), new Runnable() {
                        public void run() {
                            try {
                                if (treeConflict != null) {
                                    if (!localResource.isFolder()) {
                                        SVNConflictDescriptor descriptor = treeConflict.getConflictDescriptor();
                                        SVNConflictVersion rightVersion = descriptor.getSrcRightVersion();
                                        try {
                                            ISVNRemoteFile remoteFile = new RemoteFile(
                                                    localResource.getRepository(),
                                                    new SVNUrl(rightVersion.getReposURL() + "/"
                                                            + rightVersion.getPathInRepos()),
                                                    new SVNRevision.Number(rightVersion.getPegRevision()));
                                            SVNLocalCompareInput compareInput = new SVNLocalCompareInput(
                                                    localResource, remoteFile);
                                            CompareUI.openCompareEditorOnPage(compareInput,
                                                    getSite().getPage());
                                        } catch (Exception e) {
                                        }
                                    }
                                    return;
                                }
                                CompareUI.openCompareEditorOnPage(
                                        new SVNLocalCompareInput(localResource, SVNRevision.BASE),
                                        getSite().getPage());
                            } catch (SVNException e) {
                                if (!e.operationInterrupted()) {
                                    Activator.handleError(Messages.MergeResultsView_compareError, e);
                                    MessageDialog.openError(Display.getCurrent().getActiveShell(),
                                            Messages.MergeResultsView_compareWithLatest,
                                            e.getLocalizedMessage());
                                }
                            } catch (SVNClientException e) {
                                Activator.handleError(Messages.MergeResultsView_compareError, e);
                                MessageDialog.openError(Display.getCurrent().getActiveShell(),
                                        Messages.MergeResultsView_compareWithLatest, e.getLocalizedMessage());
                            }
                        }
                    });
                }
            }
        }
    });
    treeViewer.getTree().addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            boolean mergeOutputSelected = false;
            IStructuredSelection selection = (IStructuredSelection) treeViewer.getSelection();
            Iterator iter = selection.iterator();
            while (iter.hasNext()) {
                if (iter.next() instanceof MergeOutput) {
                    mergeOutputSelected = true;
                    break;
                }
            }
            removeAction.setEnabled(mergeOutputSelected);
        }
    });
    createMenus();
    createToolbar();
    getSite().setSelectionProvider(treeViewer);

    if (Activator.getDefault().getPreferenceStore().getBoolean(CONFLICTS_ONLY_PREFERENCE))
        setContentDescription(Messages.MergeResultsView_conflictsMode);
}