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

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

Introduction

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

Prototype

public List toList();

Source Link

Document

Returns the elements in this selection as a List.

Usage

From source file:org.apache.karaf.eik.ui.KarafConfigurationTab.java

License:Apache License

private void handleBootFeatureMove(final int direction) {
    if (direction != -1 || direction != 1) {
        throw new IllegalArgumentException("direction must be -1 or 1. Value: " + direction);
    }//w  w w  .ja  v  a 2  s  .c  om

    final IStructuredSelection selection = (IStructuredSelection) bootFeaturesViewer.getSelection();

    @SuppressWarnings("unchecked")
    final List<String> selectionList = selection.toList();
    final String[] movedBootFeatures = new String[bootFeaturesList.size()];

    for (final String config : selectionList) {
        final int i = bootFeaturesList.indexOf(config);
        movedBootFeatures[i + direction] = config;
    }

    bootFeaturesList.removeAll(selectionList);

    for (int j = 0; j < movedBootFeatures.length; j++) {
        final String config = movedBootFeatures[j];
        if (config != null) {
            bootFeaturesList.add(j, config);
        }
    }

    bootFeaturesViewer.refresh();
    handleBootFeatureSelectionChange();
}

From source file:org.bonitasoft.studio.businessobject.ui.dialog.IndexFieldsSelectionDialog.java

License:Open Source License

@Override
protected Control createDialogArea(final Composite parent) {
    final Composite contents = (Composite) super.createDialogArea(parent);

    final Label messageLabel = createMessageArea(contents);
    messageLabel.setLayoutData(/* w ww  .j  a  v  a 2s  . c o  m*/
            GridDataFactory.fillDefaults().grab(false, false).span(3, 1).hint(300, SWT.DEFAULT).create());

    final GridLayout contentsGridLayout = (GridLayout) contents.getLayout();
    contentsGridLayout.numColumns = 3;

    final GridData contentsGridData = (GridData) contents.getLayoutData();
    contentsGridData.horizontalAlignment = SWT.FILL;
    contentsGridData.verticalAlignment = SWT.FILL;

    final Composite choiceComposite = new Composite(contents, SWT.NONE);
    {
        final GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
        data.horizontalAlignment = SWT.END;
        choiceComposite.setLayoutData(data);

        final GridLayout layout = new GridLayout();
        data.horizontalAlignment = SWT.FILL;
        layout.marginHeight = 0;
        layout.marginWidth = 0;
        layout.numColumns = 1;
        choiceComposite.setLayout(layout);
    }

    final Label choiceLabel = new Label(choiceComposite, SWT.NONE);
    choiceLabel.setText(Messages.availableAttributes);
    final GridData choiceLabelGridData = new GridData();
    choiceLabelGridData.verticalAlignment = SWT.FILL;
    choiceLabelGridData.horizontalAlignment = SWT.FILL;
    choiceLabel.setLayoutData(choiceLabelGridData);

    final Table choiceTable = choiceOfValues == null ? null
            : new Table(choiceComposite, SWT.MULTI | SWT.BORDER);
    if (choiceTable != null) {
        final GridData choiceTableGridData = new GridData();
        choiceTableGridData.widthHint = 200;
        choiceTableGridData.heightHint = 100;
        choiceTableGridData.verticalAlignment = SWT.FILL;
        choiceTableGridData.horizontalAlignment = SWT.FILL;
        choiceTableGridData.grabExcessHorizontalSpace = true;
        choiceTableGridData.grabExcessVerticalSpace = true;
        choiceTable.setLayoutData(choiceTableGridData);
    }

    final TableViewer choiceTableViewer = choiceOfValues == null ? null : new TableViewer(choiceTable);
    if (choiceTableViewer != null) {
        choiceTableViewer.setContentProvider(ArrayContentProvider.getInstance());
        choiceTableViewer.setLabelProvider(labelProvider);
        final PatternFilter filter = new PatternFilter() {

            @Override
            protected boolean isParentMatch(final Viewer viewer, final Object element) {
                return viewer instanceof AbstractTreeViewer && super.isParentMatch(viewer, element);
            }
        };
        choiceTableViewer.addFilter(filter);
        if (unique) {
            choiceTableViewer.addFilter(new ViewerFilter() {

                @Override
                public boolean select(final Viewer viewer, final Object parentElement, final Object element) {
                    return !values.contains(element);
                }
            });
        }
        choiceTableViewer.setInput(choiceOfValues);
    }

    final Composite controlButtons = new Composite(contents, SWT.NONE);
    final GridData controlButtonsGridData = new GridData();
    controlButtonsGridData.verticalAlignment = SWT.FILL;
    controlButtonsGridData.horizontalAlignment = SWT.FILL;
    controlButtons.setLayoutData(controlButtonsGridData);

    final GridLayout controlsButtonGridLayout = new GridLayout();
    controlButtons.setLayout(controlsButtonGridLayout);

    new Label(controlButtons, SWT.NONE);

    final Button addButton = new Button(controlButtons, SWT.PUSH);
    addButton.setText(Messages.add);
    final GridData addButtonGridData = new GridData();
    addButtonGridData.verticalAlignment = SWT.FILL;
    addButtonGridData.horizontalAlignment = SWT.FILL;
    addButton.setLayoutData(addButtonGridData);

    final Button removeButton = new Button(controlButtons, SWT.PUSH);
    removeButton.setText(Messages.Remove);
    final GridData removeButtonGridData = new GridData();
    removeButtonGridData.verticalAlignment = SWT.FILL;
    removeButtonGridData.horizontalAlignment = SWT.FILL;
    removeButton.setLayoutData(removeButtonGridData);

    final Label spaceLabel = new Label(controlButtons, SWT.NONE);
    final GridData spaceLabelGridData = new GridData();
    spaceLabelGridData.verticalSpan = 2;
    spaceLabel.setLayoutData(spaceLabelGridData);

    final Button upButton = new Button(controlButtons, SWT.PUSH);
    upButton.setText(Messages.up);
    final GridData upButtonGridData = new GridData();
    upButtonGridData.verticalAlignment = SWT.FILL;
    upButtonGridData.horizontalAlignment = SWT.FILL;
    upButton.setLayoutData(upButtonGridData);

    final Button downButton = new Button(controlButtons, SWT.PUSH);
    downButton.setText(Messages.down);
    final GridData downButtonGridData = new GridData();
    downButtonGridData.verticalAlignment = SWT.FILL;
    downButtonGridData.horizontalAlignment = SWT.FILL;
    downButton.setLayoutData(downButtonGridData);

    final Composite featureComposite = new Composite(contents, SWT.NONE);
    {
        final GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
        data.horizontalAlignment = SWT.END;
        featureComposite.setLayoutData(data);

        final GridLayout layout = new GridLayout();
        data.horizontalAlignment = SWT.FILL;
        layout.marginHeight = 0;
        layout.marginWidth = 0;
        layout.numColumns = 1;
        featureComposite.setLayout(layout);
    }

    final Label selectedFieldLabel = new Label(featureComposite, SWT.NONE);
    selectedFieldLabel.setText(Messages.indexedAttributes);
    final GridData featureLabelGridData = new GridData();
    featureLabelGridData.horizontalSpan = 2;
    featureLabelGridData.horizontalAlignment = SWT.FILL;
    featureLabelGridData.verticalAlignment = SWT.FILL;
    selectedFieldLabel.setLayoutData(featureLabelGridData);

    final Table selectedFieldTable = new Table(featureComposite, SWT.MULTI | SWT.BORDER);
    final GridData featureTableGridData = new GridData();
    featureTableGridData.widthHint = 200;
    featureTableGridData.heightHint = 100;
    featureTableGridData.verticalAlignment = SWT.FILL;
    featureTableGridData.horizontalAlignment = SWT.FILL;
    featureTableGridData.grabExcessHorizontalSpace = true;
    featureTableGridData.grabExcessVerticalSpace = true;
    selectedFieldTable.setLayoutData(featureTableGridData);

    final TableViewer selectedFieldTableViewer = new TableViewer(selectedFieldTable);
    selectedFieldTableViewer.setContentProvider(contentProvider);
    selectedFieldTableViewer.setLabelProvider(labelProvider);
    selectedFieldTableViewer.setInput(values);
    final List<Field> children = values;
    if (!values.isEmpty()) {
        selectedFieldTableViewer.setSelection(new StructuredSelection(children.get(0)));
    }

    if (choiceTableViewer != null) {
        choiceTableViewer.addDoubleClickListener(new IDoubleClickListener() {

            @Override
            public void doubleClick(final DoubleClickEvent event) {
                if (addButton.isEnabled()) {
                    addButton.notifyListeners(SWT.Selection, null);
                }
            }
        });

        selectedFieldTableViewer.addDoubleClickListener(new IDoubleClickListener() {

            @Override
            public void doubleClick(final DoubleClickEvent event) {
                if (removeButton.isEnabled()) {
                    removeButton.notifyListeners(SWT.Selection, null);
                }
            }
        });
    }

    upButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(final SelectionEvent event) {
            final IStructuredSelection selection = (IStructuredSelection) selectedFieldTableViewer
                    .getSelection();
            int minIndex = 0;
            for (final Iterator<?> i = selection.iterator(); i.hasNext();) {
                final Object value = i.next();
                final int index = children.indexOf(value);
                Collections.swap(children, Math.max(index - 1, minIndex++), index);
            }
            selectedFieldTableViewer.refresh();
        }
    });

    downButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(final SelectionEvent event) {
            final IStructuredSelection selection = (IStructuredSelection) selectedFieldTableViewer
                    .getSelection();
            int maxIndex = children.size() - 1;
            final List<?> objects = selection.toList();
            for (final ListIterator<?> i = objects.listIterator(objects.size()); i.hasPrevious();) {
                final Object value = i.previous();
                final int index = children.indexOf(value);
                Collections.swap(children, Math.min(index + 1, maxIndex--), index);
            }
            selectedFieldTableViewer.refresh();
        }
    });

    addButton.addSelectionListener(new SelectionAdapter() {

        // event is null when choiceTableViewer is double clicked
        @Override
        public void widgetSelected(final SelectionEvent event) {
            if (choiceTableViewer != null) {
                final IStructuredSelection selection = (IStructuredSelection) choiceTableViewer.getSelection();
                for (final Iterator<?> i = selection.iterator(); i.hasNext();) {
                    final Field value = (Field) i.next();
                    if (!unique || !children.contains(value)) {
                        children.add(value);
                    }
                }
                selectedFieldTableViewer.refresh();
                selectedFieldTableViewer.setSelection(selection);
                choiceTableViewer.refresh();
            }

        }
    });

    removeButton.addSelectionListener(new SelectionAdapter() {

        // event is null when featureTableViewer is double clicked
        @Override
        public void widgetSelected(final SelectionEvent event) {
            final IStructuredSelection selection = (IStructuredSelection) selectedFieldTableViewer
                    .getSelection();
            Object firstValue = null;
            for (final Iterator<?> i = selection.iterator(); i.hasNext();) {
                final Object value = i.next();
                if (firstValue == null) {
                    firstValue = value;
                }
                children.remove(value);
            }

            if (!children.isEmpty()) {
                selectedFieldTableViewer.setSelection(new StructuredSelection(children.get(0)));
            }
            selectedFieldTableViewer.refresh();
            if (choiceTableViewer != null) {
                choiceTableViewer.refresh();
                choiceTableViewer.setSelection(selection);
            }
        }
    });

    return contents;
}

From source file:org.bonitasoft.studio.businessobject.ui.wizard.BusinessDataModelWizardPage.java

License:Open Source License

protected void deleteBusinessObject(final TableViewer boTableViewer,
        final IViewerObservableValue observeSingleSelection, final IObservableList businessObjectsObserveList) {
    final IStructuredSelection selection = (IStructuredSelection) boTableViewer.getSelection();
    final BusinessObject bo = (BusinessObject) selection.getFirstElement();
    if (MessageDialog.openQuestion(Display.getDefault().getActiveShell(), Messages.deleteBOConfirmTitle,
            Messages.bind(Messages.deleteBOConfirmMessage, NamingUtils.getSimpleName(bo.getQualifiedName())))) {
        for (final Object selected : selection.toList()) {
            businessObjectsObserveList.remove(selected);
        }//from   w  w  w  .j  a  v a 2  s.  c om
        if (businessObjectsObserveList.isEmpty()) {
            observeSingleSelection.setValue(null);
        }
    }
}

From source file:org.bonitasoft.studio.businessobject.ui.wizard.control.AttributesTabItemControl.java

License:Open Source License

protected void deleteField(final TableViewer featuresTableViewer,
        final IObservableValue viewerObservableValue) {
    final IStructuredSelection selection = (IStructuredSelection) featuresTableViewer.getSelection();
    fieldsList.removeAll(selection.toList());
}

From source file:org.bonitasoft.studio.businessobject.ui.wizard.control.IndexesTabItemControl.java

License:Open Source License

protected void deleteIndex(final IObservableList indexListObservable, final TableViewer indexesTableViewer) {
    final IStructuredSelection selection = (IStructuredSelection) indexesTableViewer.getSelection();
    indexListObservable.removeAll(selection.toList());
}

From source file:org.bonitasoft.studio.businessobject.ui.wizard.control.QueriesTabItemControl.java

License:Open Source License

protected void deleteQuery(IObservableList queryObserveDetailList, TableViewer queriesTableViewer) {
    IStructuredSelection selection = (IStructuredSelection) queriesTableViewer.getSelection();
    queryObserveDetailList.removeAll(selection.toList());
}

From source file:org.bonitasoft.studio.businessobject.ui.wizard.control.UniqueConstraintTabItemControl.java

License:Open Source License

protected void deleteUniqueConstraint(final IObservableList uniqueConstraintListObservable,
        final TableViewer constraintsTableViewer) {
    final IStructuredSelection selection = (IStructuredSelection) constraintsTableViewer.getSelection();
    uniqueConstraintListObservable.removeAll(selection.toList());
}

From source file:org.bonitasoft.studio.connector.model.definition.wizard.DefinitionInformationWizardPage.java

License:Open Source License

protected void createDependenciesViewer(Composite mainComposite) {
    Label dependencyLabel = new Label(mainComposite, SWT.NONE);
    dependencyLabel.setText(Messages.dependenciesLabel);
    dependencyLabel.setLayoutData(GridDataFactory.fillDefaults().align(SWT.END, SWT.TOP).create());

    final TableViewer viewer = new TableViewer(mainComposite, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION);
    viewer.getTable().setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());
    viewer.setContentProvider(new ArrayContentProvider());
    viewer.addSelectionChangedListener(this);
    viewer.setLabelProvider(new LabelProvider() {
        @Override/*w ww.  j  av  a 2 s  . c  om*/
        public Image getImage(Object element) {
            return Pics.getImage("jar.gif");
        }
    });

    context.bindValue(ViewersObservables.observeInput(viewer), EMFObservables.observeValue(definition,
            ConnectorDefinitionPackage.Literals.CONNECTOR_DEFINITION__JAR_DEPENDENCY));

    final Composite buttonComposite = new Composite(mainComposite, SWT.NONE);
    buttonComposite.setLayoutData(GridDataFactory.fillDefaults().grab(false, true).create());
    buttonComposite
            .setLayout(GridLayoutFactory.fillDefaults().numColumns(1).margins(0, 0).spacing(0, 3).create());

    final Button addButton = new Button(buttonComposite, SWT.FLAT);
    addButton.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());
    addButton.setText(Messages.Add);
    addButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            SelectJarsDialog dialog = new SelectJarsDialog(Display.getDefault().getActiveShell());
            if (dialog.open() == Dialog.OK) {
                for (IRepositoryFileStore jarFile : dialog.getSelectedJars()) {
                    String jar = jarFile.getName();
                    if (!definition.getJarDependency().contains(jar)) {
                        definition.getJarDependency().add(jar);
                    }
                }
            }
        }

    });

    removeJarButton = new Button(buttonComposite, SWT.FLAT);
    removeJarButton.setLayoutData(
            GridDataFactory.fillDefaults().hint(DEFAULT_BUTTON_WIDTH_HINT, SWT.DEFAULT).create());
    removeJarButton.setText(Messages.remove);
    removeJarButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            final IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
            for (Object selected : selection.toList()) {
                if (selected instanceof String) {
                    definition.getJarDependency().remove(selected);
                }
            }
            viewer.refresh();
        }
    });

    new Label(mainComposite, SWT.NONE); //FILLER
    final Label dependenciesHintLabel = new Label(mainComposite, SWT.NONE);
    dependenciesHintLabel.setLayoutData(GridDataFactory.fillDefaults().span(2, 1).create());
    dependenciesHintLabel.setText(Messages.dependenciesInfo);
}

From source file:org.bonitasoft.studio.connector.model.implementation.wizard.AbstractImplementationWizardPage.java

License:Open Source License

protected void createDependenciesViewer(Composite mainComposite) {
    Label dependencyLabel = new Label(mainComposite, SWT.NONE);
    dependencyLabel.setText(Messages.dependenciesLabel);
    dependencyLabel.setLayoutData(GridDataFactory.fillDefaults().align(SWT.END, SWT.TOP).create());

    final TableViewer viewer = new TableViewer(mainComposite, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION);
    viewer.getTable()/*  w  w w  . j av a2 s .c  o m*/
            .setLayoutData(GridDataFactory.fillDefaults().grab(true, true).hint(SWT.DEFAULT, 75).create());
    viewer.setContentProvider(new ArrayContentProvider());
    viewer.addSelectionChangedListener(this);
    viewer.setLabelProvider(new LabelProvider() {
        @Override
        public Image getImage(Object element) {
            return Pics.getImage("jar.gif");
        }
    });

    context.bindValue(ViewersObservables.observeInput(viewer),
            EMFObservables.observeValue(implementation.getJarDependencies(),
                    ConnectorImplementationPackage.Literals.JAR_DEPENDENCIES__JAR_DEPENDENCY));

    final Composite buttonComposite = new Composite(mainComposite, SWT.NONE);
    buttonComposite.setLayoutData(GridDataFactory.fillDefaults().grab(false, true).create());
    buttonComposite.setLayout(GridLayoutFactory.fillDefaults().numColumns(1).create());

    final Button addButton = new Button(buttonComposite, SWT.FLAT);
    addButton.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());
    addButton.setText(Messages.Add);
    addButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            SelectJarsDialog dialog = new SelectJarsDialog(Display.getDefault().getActiveShell());
            if (dialog.open() == Dialog.OK) {
                for (IRepositoryFileStore jarFile : dialog.getSelectedJars()) {
                    String jar = jarFile.getName();
                    if (!implementation.getJarDependencies().getJarDependency().contains(jar)) {
                        implementation.getJarDependencies().getJarDependency().add(jar);
                    }
                }
            }
        }

    });

    removeButton = new Button(buttonComposite, SWT.FLAT);
    removeButton.setLayoutData(
            GridDataFactory.fillDefaults().hint(DEFAULT_BUTTON_WIDTH_HINT, SWT.DEFAULT).create());
    removeButton.setText(Messages.remove);
    removeButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            final IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
            for (Object selected : selection.toList()) {
                if (selected instanceof String) {
                    implementation.getJarDependencies().getJarDependency().remove(selected);
                }
            }
            viewer.refresh();
        }
    });

}

From source file:org.bonitasoft.studio.contract.ui.property.constraint.ContractConstraintController.java

License:Open Source License

@Override
public void remove(final ColumnViewer viewer) {
    final IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
    final IObservableList constraintsObservable = (IObservableList) viewer.getInput();
    final List<?> selectedInput = selection.toList();
    if (openConfirmation(selectedInput)) {
        for (final Object constraint : selectedInput) {
            final ContractConstraint contractConstraint = (ContractConstraint) constraint;
            constraintsObservable.remove(contractConstraint);
        }//  w w  w.  ja  va 2  s.  c  o m
    }
}