Example usage for org.eclipse.jface.viewers StructuredSelection toList

List of usage examples for org.eclipse.jface.viewers StructuredSelection toList

Introduction

In this page you can find the example usage for org.eclipse.jface.viewers StructuredSelection toList.

Prototype

@Override
    public List toList() 

Source Link

Usage

From source file:org.eclipse.sirius.diagram.ui.tools.internal.actions.style.ResetStylePropertiesToDefaultValuesAction.java

License:Open Source License

private Map<View, DDiagramElement> getSelectedCustomizedViews() {
    Map<View, DDiagramElement> customizedViews = new LinkedHashMap<View, DDiagramElement>();
    if (selection instanceof StructuredSelection) {
        StructuredSelection structuredSelection = (StructuredSelection) selection;
        for (Object obj : structuredSelection.toList()) {
            if (obj instanceof IGraphicalEditPart) {
                IGraphicalEditPart graphicalEditPart = (IGraphicalEditPart) obj;
                View view = graphicalEditPart.getNotationView();
                EObject element = view.getElement();
                if (element instanceof DDiagramElement) {
                    DDiagramElement dDiagramElement = (DDiagramElement) element;
                    if (new DDiagramElementQuery(dDiagramElement).isCustomized()
                            || new ViewQuery(view).isCustomized()) {
                        customizedViews.put(view, dDiagramElement);
                    }/*from   w w w  .  jav a 2s  .c o m*/
                } else if (element == null && new ViewQuery(view).isCustomized()) {
                    customizedViews.put(view, null);
                }
            }
        }
    }
    return customizedViews;
}

From source file:org.eclipse.team.svn.ui.composite.ResourceSelectionComposite.java

License:Open Source License

public List getCurrentSelection() {
    StructuredSelection selection = (StructuredSelection) this.tableViewer.getSelection();
    return selection.toList();
}

From source file:org.eclipse.ui.dialogs.FilteredItemsSelectionDialog.java

License:Open Source License

/**
 * Handle selection in the items list by updating labels of selected and
 * unselected items and refresh the details field using the selection.
 * /*from w w w  .  j  av a 2 s. c om*/
 * @param selection
 *            the new selection
 */
protected void handleSelected(StructuredSelection selection) {
    IStatus status = new Status(IStatus.OK, PlatformUI.PLUGIN_ID, IStatus.OK, EMPTY_STRING, null);

    Object[] lastSelection = currentSelection;

    currentSelection = selection.toArray();

    if (selection.size() == 0) {
        status = new Status(IStatus.ERROR, PlatformUI.PLUGIN_ID, IStatus.ERROR, EMPTY_STRING, null);

        if (lastSelection != null && getListSelectionLabelDecorator() != null) {
            list.update(lastSelection, null);
        }

        currentSelection = null;

    } else {
        status = new Status(IStatus.ERROR, PlatformUI.PLUGIN_ID, IStatus.ERROR, EMPTY_STRING, null);

        List items = selection.toList();

        Object item = null;
        IStatus tempStatus = null;

        for (Iterator it = items.iterator(); it.hasNext();) {
            Object o = it.next();

            if (o instanceof ItemsListSeparator) {
                continue;
            }

            item = o;
            tempStatus = validateItem(item);

            if (tempStatus.isOK()) {
                status = new Status(IStatus.OK, PlatformUI.PLUGIN_ID, IStatus.OK, EMPTY_STRING, null);
            } else {
                status = tempStatus;
                // if any selected element is not valid status is set to
                // ERROR
                break;
            }
        }

        if (lastSelection != null && getListSelectionLabelDecorator() != null) {
            list.update(lastSelection, null);
        }

        if (getListSelectionLabelDecorator() != null) {
            list.update(currentSelection, null);
        }
    }

    refreshDetails();
    updateStatus(status);
}

From source file:org.eclipse.ui.dialogs.FilteredItemsSelectionDialog.java

License:Open Source License

/**
 * Returns the current selection./*from   w w  w  .j a  va 2 s  . c om*/
 * 
 * @return the current selection
 */
protected StructuredSelection getSelectedItems() {

    StructuredSelection selection = (StructuredSelection) list.getSelection();

    List selectedItems = selection.toList();
    Object itemToRemove = null;

    for (Iterator it = selection.iterator(); it.hasNext();) {
        Object item = it.next();
        if (item instanceof ItemsListSeparator) {
            itemToRemove = item;
            break;
        }
    }

    if (itemToRemove == null)
        return new StructuredSelection(selectedItems);
    // Create a new selection without the collision
    List newItems = new ArrayList(selectedItems);
    newItems.remove(itemToRemove);
    return new StructuredSelection(newItems);

}

From source file:org.eclipse.wst.xsd.ui.internal.common.properties.sections.SpecificConstraintsWidget.java

License:Open Source License

protected void setButtonStates(int kind) {
    boolean add, addUsing, delete, edit;

    boolean listHasItems = false;
    StructuredSelection selection = (StructuredSelection) constraintsTableViewer.getSelection();
    if (selection != null) {
        if (selection.toList().size() > 0) {
            listHasItems = true;/*w ww .  ja  va2s .c o  m*/
        }
    }

    if (kind == ENUMERATION) {
        add = true;
        addUsing = true;
        edit = false;
    } else if (kind == PATTERN) {
        add = false;
        addUsing = true;
        edit = listHasItems;
    } else {
        add = true;
        addUsing = true;
        edit = true;
    }
    delete = listHasItems;

    if (!addButton.isDisposed()) {
        addButton.setEnabled(add);
    }
    if (!addUsingDialogButton.isDisposed()) {
        addUsingDialogButton.setEnabled(addUsing);
    }
    if (!deleteButton.isDisposed()) {
        deleteButton.setEnabled(delete);
    }
    if (!editButton.isDisposed()) {
        editButton.setEnabled(edit);
    }
}

From source file:org.fornax.cartridges.sculptor.framework.richclient.table.ColumnChooserDlg.java

License:Apache License

private void doCreateViewerComposite(Composite composite) {
    composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    GridLayout compositeLayout = new GridLayout();
    compositeLayout.numColumns = 3;//from   w  w w. java 2s.c  o m
    composite.setLayout(compositeLayout);

    Label displayColumnsLabel = new Label(composite, SWT.NONE);
    displayColumnsLabel.setText(Messages.ColumnChooserDlg_displayColumns);
    new Label(composite, SWT.NONE);

    Label availableColumnsLabel = new Label(composite, SWT.NONE);
    availableColumnsLabel.setText(Messages.ColumnChooserDlg_availableColumns);

    displayListViewer = new ListViewer(composite, SWT.V_SCROLL | SWT.MULTI | SWT.BORDER | SWT.H_SCROLL);
    displayListViewer.setContentProvider(new ArrayContentProvider());
    displayListViewer.setInput(tableViewer.getDefaultColumns().toArray());
    displayListViewer.setLabelProvider(new ColumnLabelProvider());
    displayList = displayListViewer.getList();
    displayList.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

    Composite buttonComposite = new Composite(composite, SWT.NONE);
    buttonComposite.setLayout(new GridLayout());

    addButton = new Button(buttonComposite, SWT.NONE);
    addButton.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false));
    addButton.setText(Messages.ColumnChooserDlg_add);
    addButton.setEnabled(false);

    removeButton = new Button(buttonComposite, SWT.NONE);
    GridData removeButtonGd = new GridData(SWT.LEFT, SWT.TOP, false, false);
    removeButton.setLayoutData(removeButtonGd);
    removeButton.setText(Messages.ColumnChooserDlg_remove);
    removeButton.setEnabled(false);

    upButton = new Button(buttonComposite, SWT.NONE);
    GridData upButtonGd = new GridData(SWT.FILL, SWT.CENTER, false, false);
    upButtonGd.verticalIndent = 20;
    upButton.setLayoutData(upButtonGd);
    upButton.setText(Messages.ColumnChooserDlg_up);
    upButton.setEnabled(false);

    downButton = new Button(buttonComposite, SWT.NONE);
    downButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
    downButton.setText(Messages.ColumnChooserDlg_down);
    downButton.setEnabled(false);

    availableListViewer = new ListViewer(composite, SWT.V_SCROLL | SWT.MULTI | SWT.BORDER | SWT.H_SCROLL);
    availableListViewer.setContentProvider(new ArrayContentProvider());
    java.util.List<AbstractViewerColumn> availableColumns = new ArrayList<AbstractViewerColumn>();
    availableColumns.addAll(tableViewer.getAllColumns());
    Collections.sort(availableColumns, new Comparator<AbstractViewerColumn>() {
        public int compare(AbstractViewerColumn col1, AbstractViewerColumn col2) {
            return col1.getText().compareTo(col2.getText());
        }
    });
    availableListViewer.setInput(availableColumns.toArray());
    availableListViewer.setLabelProvider(new ColumnLabelProvider());
    availableList = availableListViewer.getList();
    availableList.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

    displayListViewer.addSelectionChangedListener(new UpdateButtons());
    availableListViewer.addSelectionChangedListener(new UpdateButtons());

    ViewerFilter filter = new ViewerFilter() {
        @Override
        public boolean select(Viewer viewer, Object parentElement, Object element) {
            Object input = displayListViewer.getInput();
            if (input instanceof Object[]) {
                return !Arrays.asList((Object[]) input).contains(element);
            }

            return true;
        }
    };
    availableListViewer.setFilters(new ViewerFilter[] { filter });

    addButton.addSelectionListener(new SelectionAdapter() {
        @SuppressWarnings("unchecked")
        @Override
        public void widgetSelected(SelectionEvent event) {
            StructuredSelection selection = (StructuredSelection) availableListViewer.getSelection();
            Object[] items = (Object[]) displayListViewer.getInput();
            java.util.List<Object> listItems = new ArrayList<Object>();
            listItems.addAll(Arrays.asList(items));
            listItems.addAll(selection.toList());
            displayListViewer.setInput(listItems.toArray());
            displayListViewer.refresh();
            availableListViewer.refresh();
            updateButtons();
        }
    });

    removeButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent event) {
            StructuredSelection selection = (StructuredSelection) displayListViewer.getSelection();
            Object[] items = (Object[]) displayListViewer.getInput();
            java.util.List<Object> listItems = new ArrayList<Object>();
            listItems.addAll(Arrays.asList(items));
            listItems.removeAll(selection.toList());
            displayListViewer.setInput(listItems.toArray());
            displayListViewer.refresh();
            availableListViewer.refresh();
            updateButtons();
        }
    });

    upButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent event) {
            StructuredSelection selection = (StructuredSelection) displayListViewer.getSelection();
            Object[] items = (Object[]) displayListViewer.getInput();
            java.util.List<Object> listItems = new ArrayList<Object>();
            listItems.addAll(Arrays.asList(items));
            for (Object each : selection.toList()) {
                int index = listItems.indexOf(each);
                listItems.remove(each);
                listItems.add(index - 1, each);
            }
            displayListViewer.setInput(listItems.toArray());
            displayListViewer.refresh();
            displayListViewer.setSelection(selection);
            displayListViewer.reveal(selection.getFirstElement());
            updateButtons();
        }
    });

    downButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent event) {
            StructuredSelection selection = (StructuredSelection) displayListViewer.getSelection();
            Object[] items = (Object[]) displayListViewer.getInput();
            java.util.List<Object> listItems = new ArrayList<Object>();
            listItems.addAll(Arrays.asList(items));
            for (int i = selection.size() - 1; i > -1; i--) {
                Object each = selection.toArray()[i];
                int index = listItems.indexOf(each);
                listItems.remove(each);
                listItems.add(index + 1, each);
            }
            displayListViewer.setInput(listItems.toArray());
            displayListViewer.refresh();
            displayListViewer.setSelection(selection);
            displayListViewer.reveal(selection.getFirstElement());
            updateButtons();
        }
    });

    availableListViewer.refresh();
}

From source file:org.fornax.cartridges.sculptor.framework.richclient.table.ColumnChooserDlg.java

License:Apache License

private void updateUpButton() {
    if (displayListViewer.getSelection().isEmpty()) {
        upButton.setEnabled(false);//w w  w.j  a  v  a2  s  . c om
    } else {
        StructuredSelection selection = (StructuredSelection) displayListViewer.getSelection();
        Object[] items = (Object[]) displayListViewer.getInput();
        Object firstItem = items[0];
        upButton.setEnabled(!selection.toList().contains(firstItem));
    }
}

From source file:org.fornax.cartridges.sculptor.framework.richclient.table.ColumnChooserDlg.java

License:Apache License

private void updateDownButton() {
    if (displayListViewer.getSelection().isEmpty()) {
        downButton.setEnabled(false);//w w w .  ja  v a  2s. c o m
    } else {
        StructuredSelection selection = (StructuredSelection) displayListViewer.getSelection();
        Object[] items = (Object[]) displayListViewer.getInput();
        Object lastItem = items[items.length - 1];
        downButton.setEnabled(!selection.toList().contains(lastItem));
    }
}

From source file:org.jboss.tools.windup.ui.internal.editor.launch.InputPackagesSection.java

License:Open Source License

private void createButtonBar(Composite parent) {
    Composite container = toolkit.createComposite(parent);
    GridLayoutFactory.fillDefaults().applyTo(container);
    GridDataFactory.fillDefaults().grab(false, true).applyTo(container);

    Button addButton = toolkit.createButton(container, Messages.windupAdd, SWT.PUSH);
    GridDataFactory.fillDefaults().grab(true, false).applyTo(addButton);
    addButton.addSelectionListener(new SelectionAdapter() {
        @Override/* w  ww.  j  av a  2 s  .c  o m*/
        public void widgetSelected(SelectionEvent e) {
            FilteredListDialog dialog = new FilteredListDialog(parent.getShell(), new WorkbenchLabelProvider());
            dialog.setMultipleSelection(true);
            dialog.setMessage(Messages.windupPackagesSelect);
            dialog.setElements(computePackages(configuration));
            dialog.setTitle(Messages.windupPackages);
            dialog.setHelpAvailable(false);
            dialog.create();
            if (dialog.open() == Window.OK) {
                Object[] selected = (Object[]) dialog.getResult();
                if (selected.length > 0) {
                    List<IPackageFragment> packages = Lists.newArrayList();
                    Arrays.stream(selected).forEach(p -> packages.add((IPackageFragment) p));
                    modelService.addPackages(configuration, packages);
                    reloadTable();
                }
            }
        }
    });

    Button removeButton = toolkit.createButton(container, Messages.windupRemove, SWT.PUSH);
    GridDataFactory.fillDefaults().grab(true, false).applyTo(removeButton);
    removeButton.addSelectionListener(new SelectionAdapter() {
        @SuppressWarnings("unchecked")
        @Override
        public void widgetSelected(SelectionEvent e) {
            ISelection selection = table.getSelection();
            if (!selection.isEmpty()) {
                StructuredSelection ss = (StructuredSelection) selection;
                modelService.removePackages(configuration, (List<IPackageFragment>) ss.toList());
                reloadTable();
            }
        }
    });
}

From source file:org.jboss.tools.windup.ui.internal.editor.launch.InputProjectsSection.java

License:Open Source License

private void createButtonBar(Composite parent) {
    Composite container = toolkit.createComposite(parent);
    GridLayoutFactory.fillDefaults().applyTo(container);
    GridDataFactory.fillDefaults().grab(false, true).applyTo(container);

    Button addButton = toolkit.createButton(container, Messages.windupAdd, SWT.PUSH);
    GridDataFactory.fillDefaults().grab(true, false).applyTo(addButton);
    addButton.addSelectionListener(new SelectionAdapter() {
        @Override//from w  ww.  ja  v a2s .c  o  m
        public void widgetSelected(SelectionEvent e) {
            List<IProject> projects = Lists
                    .newArrayList(ResourcesPlugin.getWorkspace().getRoot().getProjects());
            projects.removeAll(Lists.newArrayList(getCurrentProjects(configuration)));
            ListSelectionDialog dialog = new ListSelectionDialog(parent.getShell(), projects,
                    new ArrayContentProvider(), new JavaUILabelProvider(), Messages.windupProjects);
            dialog.setTitle(Messages.windupProjects);
            dialog.setHelpAvailable(false);
            if (dialog.open() == Window.OK) {
                Object[] selected = (Object[]) dialog.getResult();
                if (selected.length > 0) {
                    List<IProject> newProjects = Lists.newArrayList();
                    Arrays.stream(selected).forEach(p -> newProjects.add((IProject) p));
                    modelService.createInput(configuration, newProjects);
                    reloadTable();
                }
            }
        }
    });

    Button removeButton = toolkit.createButton(container, Messages.windupRemove, SWT.PUSH);
    GridDataFactory.fillDefaults().grab(true, false).applyTo(removeButton);
    removeButton.addSelectionListener(new SelectionAdapter() {
        @SuppressWarnings("unchecked")
        @Override
        public void widgetSelected(SelectionEvent e) {
            ISelection selection = table.getSelection();
            if (!selection.isEmpty()) {
                StructuredSelection ss = (StructuredSelection) selection;
                List<IProject> projects = (List<IProject>) ss.toList();
                modelService.deleteInput(configuration, projects);
                broker.post(INPUT_CHANGED, true);
                reloadTable();
            }
        }
    });
}