Example usage for org.eclipse.jface.viewers TableViewer setContentProvider

List of usage examples for org.eclipse.jface.viewers TableViewer setContentProvider

Introduction

In this page you can find the example usage for org.eclipse.jface.viewers TableViewer setContentProvider.

Prototype

@Override
public void setContentProvider(IContentProvider provider) 

Source Link

Document

Sets the content provider used by this AbstractTableViewer.

Usage

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

License:Open Source License

@Override
public void createControl(Composite parent) {
    context = new EMFDataBindingContext();
    final Composite mainComposite = new Composite(parent, SWT.NONE);
    mainComposite.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());
    mainComposite.setLayout(GridLayoutFactory.fillDefaults().numColumns(2).margins(15, 15).create());

    final TableViewer inputsViewer = new TableViewer(mainComposite,
            SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI);
    inputsViewer.getTable().setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());
    inputsViewer.getTable().setHeaderVisible(true);
    inputsViewer.getTable().setLinesVisible(true);
    inputsViewer.addSelectionChangedListener(this);
    inputsViewer.setContentProvider(new ArrayContentProvider());
    TableLayout layout = new TableLayout();
    layout.addColumnData(new ColumnWeightData(25));
    layout.addColumnData(new ColumnWeightData(20));
    layout.addColumnData(new ColumnWeightData(30));
    layout.addColumnData(new ColumnWeightData(25));
    inputsViewer.getTable().setLayout(layout);

    inputsViewer.getColumnViewerEditor()
            .addEditorActivationListener(new ColumnViewerEditorActivationListener() {

                @Override//from   ww  w. j  a va  2s. c o m
                public void beforeEditorDeactivated(ColumnViewerEditorDeactivationEvent event) {
                }

                @Override
                public void beforeEditorActivated(ColumnViewerEditorActivationEvent event) {
                }

                @Override
                public void afterEditorDeactivated(ColumnViewerEditorDeactivationEvent event) {
                    inputsViewer.refresh();
                }

                @Override
                public void afterEditorActivated(ColumnViewerEditorActivationEvent event) {
                }
            });

    TableViewerColumn inputNameColumn = new TableViewerColumn(inputsViewer, SWT.FILL);
    inputNameColumn.getColumn().setText(Messages.name);

    inputNameColumn.setEditingSupport(new InputNameEditingSupport(inputsViewer, definition, context));
    inputNameColumn.setLabelProvider(new ColumnLabelProvider() {
        @Override
        public String getText(Object element) {
            return ((Input) element).getName();
        }
    });

    TableViewerColumn mandatoryColumn = new TableViewerColumn(inputsViewer, SWT.FILL);
    mandatoryColumn.getColumn().setText(Messages.mandatory);
    mandatoryColumn.setEditingSupport(new InputMandatoryEditingSupport(inputsViewer, context));
    mandatoryColumn.setLabelProvider(new ColumnLabelProvider() {
        @Override
        public String getText(Object element) {
            if (((Input) element).isMandatory()) {
                return Messages.mandatory;
            } else {
                return Messages.optional;
            }
        }
    });

    TableViewerColumn inputTypeColumn = new TableViewerColumn(inputsViewer, SWT.FILL);
    inputTypeColumn.getColumn().setText(Messages.type);
    inputTypeColumn.setEditingSupport(new InputTypeEditingSupport(inputsViewer, context));
    inputTypeColumn.setLabelProvider(new ColumnLabelProvider() {
        @Override
        public String getText(Object element) {
            return ((Input) element).getType();
        }
    });

    TableViewerColumn defautltValueColumn = new TableViewerColumn(inputsViewer, SWT.FILL);
    defautltValueColumn.getColumn().setText(Messages.defaultValue);
    defautltValueColumn.setEditingSupport(new DefaultValueEditingSupport(inputsViewer, context));
    defautltValueColumn.setLabelProvider(new ColumnLabelProvider() {
        @Override
        public String getText(Object element) {
            return ((Input) element).getDefaultValue();
        }
    });

    context.bindValue(ViewersObservables.observeInput(inputsViewer), EMFObservables.observeValue(definition,
            ConnectorDefinitionPackage.Literals.CONNECTOR_DEFINITION__INPUT));

    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.setText(Messages.add);
    addButton.setLayoutData(GridDataFactory.fillDefaults().grab(true, false)
            .hint(DEFAULT_BUTTON_WIDTH_HINT, SWT.DEFAULT).create());
    addButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            Input input = ConnectorDefinitionFactory.eINSTANCE.createInput();
            input.setName(generateInputName());
            input.setType(String.class.getName());
            definition.getInput().add(input);
            inputsViewer.refresh();
            inputsViewer.editElement(input, 0);
        }
    });

    upButton = new Button(buttonComposite, SWT.FLAT);
    upButton.setText(Messages.up);
    upButton.setLayoutData(GridDataFactory.fillDefaults().grab(true, false)
            .hint(DEFAULT_BUTTON_WIDTH_HINT, SWT.DEFAULT).create());
    upButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            Input selectedInput = (Input) ((IStructuredSelection) inputsViewer.getSelection())
                    .getFirstElement();
            int index = definition.getInput().indexOf(selectedInput);
            if (index > 0) {
                definition.getInput().move(index - 1, selectedInput);
            }
            inputsViewer.refresh();
        }
    });

    downButton = new Button(buttonComposite, SWT.FLAT);
    downButton.setText(Messages.down);
    downButton.setLayoutData(GridDataFactory.fillDefaults().grab(true, false)
            .hint(DEFAULT_BUTTON_WIDTH_HINT, SWT.DEFAULT).create());
    downButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            Input selectedInput = (Input) ((IStructuredSelection) inputsViewer.getSelection())
                    .getFirstElement();
            int index = definition.getInput().indexOf(selectedInput);
            if (index < definition.getInput().size() - 1) {
                definition.getInput().move(index + 1, selectedInput);
            }
        }
    });

    removeButton = new Button(buttonComposite, SWT.FLAT);
    removeButton.setText(Messages.remove);
    removeButton.setLayoutData(GridDataFactory.fillDefaults().grab(true, false)
            .hint(DEFAULT_BUTTON_WIDTH_HINT, SWT.DEFAULT).create());
    removeButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            definition.getInput().removeAll(((IStructuredSelection) inputsViewer.getSelection()).toList());
            inputsViewer.refresh();
        }
    });

    updateButtons(new StructuredSelection());
    pageSupport = WizardPageSupport.create(this, context);
    setControl(mainComposite);
}

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

License:Open Source License

@Override
public void createControl(Composite parent) {
    context = new EMFDataBindingContext();
    final Composite mainComposite = new Composite(parent, SWT.NONE);
    mainComposite.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());
    mainComposite.setLayout(GridLayoutFactory.fillDefaults().numColumns(2).margins(15, 15).create());

    final TableViewer outputsViewer = new TableViewer(mainComposite,
            SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI);
    outputsViewer.getTable().setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());
    outputsViewer.getTable().setHeaderVisible(true);
    outputsViewer.getTable().setLinesVisible(true);
    outputsViewer.addSelectionChangedListener(this);
    outputsViewer.setContentProvider(new ArrayContentProvider());
    TableLayout layout = new TableLayout();
    layout.addColumnData(new ColumnWeightData(30));
    layout.addColumnData(new ColumnWeightData(70));
    outputsViewer.getTable().setLayout(layout);

    outputsViewer.getColumnViewerEditor()
            .addEditorActivationListener(new ColumnViewerEditorActivationListener() {

                @Override/*from  w w w.j  a v  a 2 s. co m*/
                public void beforeEditorDeactivated(ColumnViewerEditorDeactivationEvent event) {
                }

                @Override
                public void beforeEditorActivated(ColumnViewerEditorActivationEvent event) {
                }

                @Override
                public void afterEditorDeactivated(ColumnViewerEditorDeactivationEvent event) {
                    outputsViewer.refresh();
                }

                @Override
                public void afterEditorActivated(ColumnViewerEditorActivationEvent event) {
                }
            });

    TableViewerColumn outputNameColumn = new TableViewerColumn(outputsViewer, SWT.FILL);
    outputNameColumn.getColumn().setText(Messages.name);

    outputNameColumn.setEditingSupport(new OutputNameEditingSupport(outputsViewer, definition, context));
    outputNameColumn.setLabelProvider(new ColumnLabelProvider() {
        @Override
        public String getText(Object element) {
            return ((Output) element).getName();
        }
    });

    TableViewerColumn outputTypeColumn = new TableViewerColumn(outputsViewer, SWT.FILL);
    outputTypeColumn.getColumn().setText(Messages.type);
    outputTypeColumn.setEditingSupport(new OutputTypeEditingSupport(outputsViewer, context));
    outputTypeColumn.setLabelProvider(new ColumnLabelProvider() {
        @Override
        public String getText(Object element) {
            return ((Output) element).getType();
        }
    });

    context.bindValue(ViewersObservables.observeInput(outputsViewer), EMFObservables.observeValue(definition,
            ConnectorDefinitionPackage.Literals.CONNECTOR_DEFINITION__OUTPUT));

    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.setText(Messages.add);
    addButton.setLayoutData(GridDataFactory.fillDefaults().grab(true, false)
            .hint(DEFAULT_BUTTON_WIDTH_HINT, SWT.DEFAULT).create());
    addButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            Output input = ConnectorDefinitionFactory.eINSTANCE.createOutput();
            input.setName(generateOutputName());
            input.setType(String.class.getName());
            definition.getOutput().add(input);
            outputsViewer.refresh();
            outputsViewer.editElement(input, 0);
        }
    });

    upButton = new Button(buttonComposite, SWT.FLAT);
    upButton.setText(Messages.up);
    upButton.setLayoutData(GridDataFactory.fillDefaults().grab(true, false)
            .hint(DEFAULT_BUTTON_WIDTH_HINT, SWT.DEFAULT).create());
    upButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            Output selectedInput = (Output) ((IStructuredSelection) outputsViewer.getSelection())
                    .getFirstElement();
            int index = definition.getOutput().indexOf(selectedInput);
            if (index > 0) {
                definition.getOutput().move(index - 1, selectedInput);
            }
            outputsViewer.refresh();
        }
    });

    downButton = new Button(buttonComposite, SWT.FLAT);
    downButton.setText(Messages.down);
    downButton.setLayoutData(GridDataFactory.fillDefaults().grab(true, false)
            .hint(DEFAULT_BUTTON_WIDTH_HINT, SWT.DEFAULT).create());
    downButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            Output selectedInput = (Output) ((IStructuredSelection) outputsViewer.getSelection())
                    .getFirstElement();
            int index = definition.getOutput().indexOf(selectedInput);
            if (index < definition.getOutput().size() - 1) {
                definition.getOutput().move(index + 1, selectedInput);
            }
        }
    });

    removeButton = new Button(buttonComposite, SWT.FLAT);
    removeButton.setText(Messages.remove);
    removeButton.setLayoutData(GridDataFactory.fillDefaults().grab(true, false)
            .hint(DEFAULT_BUTTON_WIDTH_HINT, SWT.DEFAULT).create());
    removeButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            definition.getOutput().removeAll(((IStructuredSelection) outputsViewer.getSelection()).toList());
            outputsViewer.refresh();
        }
    });

    updateButtons(new StructuredSelection());
    pageSupport = WizardPageSupport.create(this, context);
    setControl(mainComposite);
}

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 ww .ja va2 s .com
            .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.ContractPropertySectionTest.java

License:Open Source License

@Test
public void should_bindRemoveButtonEnablement_convert_boolean_value() throws Exception {
    section.init(new WritableValue(aContract().build(), Contract.class));
    final Button removeButton = new Button(parent, SWT.PUSH);
    final TableViewer inputsTableViewer = new TableViewer(parent);
    inputsTableViewer.setLabelProvider(new LabelProvider());
    inputsTableViewer.setContentProvider(ArrayContentProvider.getInstance());
    inputsTableViewer.setInput(Arrays.asList("item"));
    section.bindRemoveButtonEnablement(removeButton, inputsTableViewer);
    assertThat(removeButton.isEnabled()).isFalse();
    assertThat(inputsTableViewer.getSelection().isEmpty()).isTrue();
    inputsTableViewer.setSelection(new StructuredSelection("item"));
    assertThat(removeButton.isEnabled()).isTrue();
    assertThat(inputsTableViewer.getSelection().isEmpty()).isFalse();
}

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

License:Open Source License

@Test
public void should_bindAddChildButtonEnablement_convert_boolean_value() throws Exception {
    section.init(new WritableValue(aContract().build(), Contract.class));
    final Button button = new Button(parent, SWT.PUSH);
    final TableViewer inputsTableViewer = new TableViewer(parent);
    inputsTableViewer.setLabelProvider(new LabelProvider());
    inputsTableViewer.setContentProvider(ArrayContentProvider.getInstance());

    final ContractInput textParentInput = ProcessFactory.eINSTANCE.createContractInput();
    textParentInput.setType(ContractInputType.TEXT);
    final ContractInput complexParentInput = ProcessFactory.eINSTANCE.createContractInput();
    complexParentInput.setType(ContractInputType.COMPLEX);

    inputsTableViewer.setInput(Arrays.asList(textParentInput, complexParentInput));
    section.bindAddChildButtonEnablement(button, inputsTableViewer);
    assertThat(button.isEnabled()).isFalse();
    assertThat(inputsTableViewer.getSelection().isEmpty()).isTrue();
    inputsTableViewer.setSelection(new StructuredSelection(textParentInput));
    assertThat(button.isEnabled()).isFalse();
    assertThat(inputsTableViewer.getSelection().isEmpty()).isFalse();

    inputsTableViewer.setSelection(new StructuredSelection(complexParentInput));
    assertThat(button.isEnabled()).isTrue();
}

From source file:org.bonitasoft.studio.contract.ui.wizard.SelectBusinessDataWizardPage.java

License:Open Source License

public void createTableViewer(final Composite parent) {
    final DataBindingContext dbc = new DataBindingContext();
    final TableViewer businessDataTableViewer = new TableViewer(parent,
            SWT.BORDER | SWT.SINGLE | SWT.NO_FOCUS | SWT.H_SCROLL | SWT.V_SCROLL);
    businessDataTableViewer.getTable().setLayout(GridLayoutFactory.fillDefaults().create());
    businessDataTableViewer.getTable()/*  w  w w. j  av a 2  s. c o  m*/
            .setLayoutData(GridDataFactory.fillDefaults().grab(true, true).hint(200, 100).create());
    final ObservableListContentProvider contentProvider = new ObservableListContentProvider();
    businessDataTableViewer.setContentProvider(contentProvider);
    final IObservableSet knownElements = contentProvider.getKnownElements();
    final IObservableMap[] labelMaps = EMFObservables.observeMaps(knownElements,
            new EStructuralFeature[] { ProcessPackage.Literals.ELEMENT__NAME,
                    ProcessPackage.Literals.DATA__MULTIPLE,
                    ProcessPackage.Literals.JAVA_OBJECT_DATA__CLASS_NAME });
    businessDataTableViewer
            .setLabelProvider(new BusinessObjectDataStyledLabelProvider(businessObjectStore, labelMaps));
    businessDataTableViewer
            .setInput(new WritableList(availableBusinessData, ProcessPackage.Literals.BUSINESS_OBJECT_DATA));
    final IViewerObservableValue observeSingleSelection = ViewersObservables
            .observeSingleSelection(businessDataTableViewer);
    dbc.bindValue(observeSingleSelection, selectedDataObservable);

    final MultiValidator multiValidator = new BusinessDataSelectedValidator(availableBusinessData,
            selectedDataObservable, businessObjectStore);
    dbc.addValidationStatusProvider(multiValidator);
    WizardPageSupport.create(this, dbc);
}

From source file:org.bonitasoft.studio.engine.ui.dialog.ProcessEnablementProblemsDialog.java

License:Open Source License

@Override
protected Control createCustomArea(Composite parent) {
    if (processResolutionProblems.isEmpty()) {
        return super.createCustomArea(parent);
    }// w  w  w .  ja v  a2 s .  c  o m
    TableViewer problemsViewer = new TableViewer(parent, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
    problemsViewer.getControl().setLayoutData(
            GridDataFactory.fillDefaults().grab(true, true).hint(300, 100).indent(0, 10).create());
    problemsViewer.setContentProvider(new ArrayContentProvider());
    problemsViewer.setLabelProvider(new LabelProvider() {

        /*
         * (non-Javadoc)
         * @see org.eclipse.jface.viewers.LabelProvider#getText(java.lang.Object)
         */
        @Override
        public String getText(Object element) {
            return ((Problem) element).getDescription();
        }

        /*
         * (non-Javadoc)
         * @see org.eclipse.jface.viewers.LabelProvider#getImage(java.lang.Object)
         */
        @Override
        public Image getImage(Object element) {
            return ((Problem) element).getLevel() == Level.ERROR
                    ? JFaceResources.getImage(Dialog.DLG_IMG_MESSAGE_ERROR)
                    : JFaceResources.getImage(Dialog.DLG_IMG_MESSAGE_WARNING);
        }
    });
    problemsViewer.setInput(processResolutionProblems);
    return problemsViewer.getControl();
}

From source file:org.bonitasoft.studio.validators.ui.wizard.ValidatorWizardPage.java

License:Open Source License

protected void createDependenciesViewer(Composite mainComposite) {
    Label dependencyLabel = new Label(mainComposite, SWT.NONE);
    dependencyLabel.setText(Messages.dependencies);
    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/*from  w  w w . j  a va2s  . c  o  m*/
        public Image getImage(Object element) {
            return Pics.getImage("jar.gif", ValidatorPlugin.getDefault());
        }
    });

    context.bindValue(ViewersObservables.observeInput(viewer), EMFObservables.observeValue(validator,
            ValidatorPackage.Literals.VALIDATOR_DESCRIPTOR__DEPENDENCIES));

    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 (!validator.getDependencies().contains(jar)) {
                        validator.getDependencies().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) {
                    validator.getDependencies().remove(selected);
                }
            }
            viewer.refresh();
        }
    });

}

From source file:org.bundlemaker.core.ui.projecteditor.newwizard.ChooseContentProviderSelectionPage.java

License:Open Source License

@Override
public void createControl(Composite parent) {
    Composite comp = new Composite(parent, SWT.NONE);
    comp.setLayout(new GridLayout(1, false));
    comp.setFont(parent.getFont());/* w ww  . j a  v  a2s.  co m*/
    GridData gd = new GridData(GridData.FILL_BOTH);
    gd.grabExcessHorizontalSpace = true;
    comp.setLayoutData(gd);

    SashForm sashForm = new SashForm(comp, SWT.VERTICAL);
    gd = new GridData(GridData.FILL_BOTH);
    // limit the width of the sash form to avoid the wizard opening very wide.
    gd.widthHint = 300;
    sashForm.setLayoutData(gd);
    sashForm.setFont(comp.getFont());

    TableViewer wizardSelectionViewer = new TableViewer(sashForm, SWT.BORDER);
    wizardSelectionViewer.setContentProvider(new ArrayContentProvider());
    wizardSelectionViewer.setLabelProvider(new LabelProvider() {
        @Override
        public String getText(Object element) {
            if (element instanceof ChooseContentProviderWizardNode) {
                return ((ChooseContentProviderWizardNode) element).getLabel();
            }
            return super.getText(element);
        }

        @Override
        public Image getImage(Object element) {
            if (element instanceof ChooseContentProviderWizardNode) {
                return ((ChooseContentProviderWizardNode) element).getImage();
            }
            return super.getImage(element);
        }
    });
    wizardSelectionViewer.addDoubleClickListener(new IDoubleClickListener() {
        @Override
        public void doubleClick(DoubleClickEvent event) {
            IStructuredSelection selection = (IStructuredSelection) event.getSelection();
            if (!selection.isEmpty()) {
                setSelectedNode((IWizardNode) selection.getFirstElement());
                getContainer().showPage(getNextPage());
            }
        }
    });
    wizardSelectionViewer.addSelectionChangedListener(new ISelectionChangedListener() {
        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection selection = (IStructuredSelection) event.getSelection();
            if (!selection.isEmpty()) {
                _description.setText(
                        ((ChooseContentProviderWizardNode) selection.getFirstElement()).getDescription());
                setSelectedNode(((ChooseContentProviderWizardNode) selection.getFirstElement()));
            }
        }
    });
    wizardSelectionViewer.getTable().setLayoutData(new GridData(GridData.FILL_BOTH));
    wizardSelectionViewer.getTable().setFont(sashForm.getFont());

    _description = SWTFactory.createText(sashForm, SWT.READ_ONLY | SWT.BORDER | SWT.MULTI | SWT.WRAP, 1);

    sashForm.setWeights(new int[] { 70, 30 });
    initViewerContents(wizardSelectionViewer);
    setControl(comp);
}

From source file:org.caleydo.data.tcga.internal.TCGABrowserStartupAddon.java

License:Open Source License

private TableViewer createTableViewer(Composite parent) {
    final TableViewer t = new TableViewer(parent, SWT.BORDER | SWT.FULL_SELECTION);
    t.getTable().setHeaderVisible(true);
    t.getTable().setLinesVisible(true);//from w  w w.j ava2 s  .c o  m
    t.setLabelProvider(new LabelProvider());
    t.setContentProvider(ArrayContentProvider.getInstance());
    return t;
}