Example usage for org.eclipse.jface.databinding.viewers ViewerProperties checkedElements

List of usage examples for org.eclipse.jface.databinding.viewers ViewerProperties checkedElements

Introduction

In this page you can find the example usage for org.eclipse.jface.databinding.viewers ViewerProperties checkedElements.

Prototype

public static IViewerSetProperty checkedElements(Object elementType) 

Source Link

Document

Returns a set property for observing the checked elements of a CheckboxTableViewer , CheckboxTreeViewer or ICheckable .

Usage

From source file:gov.redhawk.ui.views.internal.monitor.ports.PortMonitorViewConfigDialog.java

License:Open Source License

private void createColumnGroup(final Composite parent) {
    final Group group = new Group(parent, SWT.None);
    group.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    group.setText("Column Configuration");
    group.setLayout(new GridLayout(1, false));
    CheckboxTableViewer viewer = CheckboxTableViewer.newCheckList(group,
            SWT.BORDER | SWT.FULL_SELECTION | SWT.V_SCROLL);
    final Table table = viewer.getTable();
    final GridData gd_table = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1);
    gd_table.minimumHeight = 200;/*from  w ww.j av a2s  .  co m*/
    table.setLayoutData(gd_table);
    viewer.getTable().setHeaderVisible(false);
    viewer.setSorter(new ViewerSorter() {
        @Override
        public int compare(final Viewer viewer, final Object e1, final Object e2) {
            final Column c1 = (Column) e1;
            final Column c2 = (Column) e2;
            return c1.getName().compareToIgnoreCase(c2.getName());
        }
    });
    ViewerSupport.bind(viewer, BeansObservables.observeList(state, "input"), PojoProperties.value("name"));
    context.bindSet(ViewerProperties.checkedElements(Column.class).observe(viewer),
            BeansObservables.observeSet(state, "checked"));
}

From source file:org.jboss.tools.openshift.express.internal.ui.wizard.application.ApplicationConfigurationWizardPage.java

License:Open Source License

private void createApplicationConfigurationGroup(Composite parent, DataBindingContext dbc) {
    this.newAppConfigurationGroup = new Group(parent, SWT.NONE);
    newAppConfigurationGroup.setText("New application");
    GridLayoutFactory.fillDefaults().numColumns(3).margins(6, 6).applyTo(newAppConfigurationGroup);
    GridDataFactory.fillDefaults().grab(true, true).align(SWT.FILL, SWT.FILL).applyTo(newAppConfigurationGroup);

    final Label newAppNameLabel = new Label(newAppConfigurationGroup, SWT.NONE);
    newAppNameLabel.setText("Name:");
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).applyTo(newAppNameLabel);

    // application name
    this.newAppNameText = new Text(newAppConfigurationGroup, SWT.BORDER);
    GridDataFactory.fillDefaults().grab(true, false).span(2, 1).align(SWT.FILL, SWT.FILL)
            .applyTo(newAppNameText);/*from w w  w  .  j av a2  s . c om*/
    UIUtils.selectAllOnFocus(newAppNameText);
    final IObservableValue applicationNameTextObservable = WidgetProperties.text(SWT.Modify)
            .observe(newAppNameText);
    final IObservableValue applicationNameModelObservable = BeanProperties
            .value(ApplicationConfigurationWizardPageModel.PROPERTY_APPLICATION_NAME).observe(pageModel);
    ValueBindingBuilder.bind(applicationNameTextObservable).to(applicationNameModelObservable).in(dbc);

    final ISWTObservableValue useExistingAppBtnSelection = WidgetProperties.selection()
            .observe(useExistingAppBtn);
    final NewApplicationNameValidator newApplicationNameValidator = new NewApplicationNameValidator(
            useExistingAppBtnSelection, applicationNameTextObservable);
    dbc.addValidationStatusProvider(newApplicationNameValidator);
    ControlDecorationSupport.create(newApplicationNameValidator, SWT.LEFT | SWT.TOP, null,
            new RequiredControlDecorationUpdater());

    // application type
    final Label newAppTypeLabel = new Label(newAppConfigurationGroup, SWT.NONE);
    newAppTypeLabel.setText("Type:");
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).span(1, 1).applyTo(newAppTypeLabel);
    this.newAppCartridgeCombo = new Combo(newAppConfigurationGroup, SWT.BORDER | SWT.READ_ONLY);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).span(2, 1).grab(true, false)
            .applyTo(newAppCartridgeCombo);

    dbc.bindList(WidgetProperties.items().observe(newAppCartridgeCombo),
            BeanProperties.list(ApplicationConfigurationWizardPageModel.PROPERTY_CARTRIDGES).observe(pageModel),
            new UpdateListStrategy(UpdateListStrategy.POLICY_NEVER),
            new UpdateListStrategy().setConverter(new CartridgeToStringConverter()));

    final ISWTObservableValue selectedCartridgeIndexObservable = WidgetProperties.singleSelectionIndex()
            .observe(newAppCartridgeCombo);
    final IObservableValue selectedCartridgeModelObservable = BeanProperties
            .value(ApplicationConfigurationWizardPageModel.PROPERTY_SELECTED_CARTRIDGE).observe(pageModel);
    ValueBindingBuilder.bind(selectedCartridgeIndexObservable).converting(new CartridgesIndexToCartridge())
            .to(selectedCartridgeModelObservable).converting(new CartridgeToCartridgesIndex()).in(dbc);

    // gear profile
    final Label gearProfileLabel = new Label(newAppConfigurationGroup, SWT.NONE);
    gearProfileLabel.setText("Gear profile:");
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).span(1, 1).applyTo(gearProfileLabel);
    this.gearProfilesCombo = new Combo(newAppConfigurationGroup, SWT.BORDER | SWT.READ_ONLY);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).span(1, 1).grab(true, false)
            .applyTo(gearProfilesCombo);
    dbc.bindList(WidgetProperties.items().observe(gearProfilesCombo),
            BeanProperties.list(ApplicationConfigurationWizardPageModel.PROPERTY_GEAR_PROFILES)
                    .observe(pageModel),
            new UpdateListStrategy(UpdateListStrategy.POLICY_NEVER), new UpdateListStrategy() {

                /**
                * Needed to avoid buggy list update strategy in
                * ListBinding. The bug appears if the model list changes
                * its ordering and the strategy then tries to apply the
                * move in the target (widget). It does not apply the
                * conversion and ends up in a class cast exception when
                * updating the target (widget) items list.
                * 
                * @see https://issues.jboss.org/browse/JBIDE-11954
                */
                protected boolean useMoveAndReplace() {
                    return false;
                }

            }.setConverter(new GearProfileToStringConverter()));

    final ISWTObservableValue selectedGearProfileComboObservable = WidgetProperties.selection()
            .observe(gearProfilesCombo);
    final IObservableValue selectedGearProfileModelObservable = BeanProperties
            .value(ApplicationConfigurationWizardPageModel.PROPERTY_SELECTED_GEAR_PROFILE).observe(pageModel);
    ValueBindingBuilder.bind(selectedGearProfileComboObservable).converting(new StringToGearProfileConverter())
            .to(selectedGearProfileModelObservable).converting(new GearProfileToStringConverter()).in(dbc);

    // scaling
    this.enableScalingButton = new Button(newAppConfigurationGroup, SWT.CHECK);
    enableScalingButton.setText("Enable scaling");
    IObservableValue enableScalingModelObservable = BeanProperties
            .value(ApplicationConfigurationWizardPageModel.PROPERTY_APPLICATION_SCALE).observe(pageModel);
    final IObservableValue enableScalingButtonSelection = WidgetProperties.selection()
            .observe(enableScalingButton);
    ValueBindingBuilder.bind(enableScalingButtonSelection).converting(new BooleanToApplicationScaleConverter())
            .to(enableScalingModelObservable).converting(new ApplicationScaleToBooleanConverter()).in(dbc);

    final NewApplicationTypeValidator newApplicationTypeValidator = new NewApplicationTypeValidator(
            useExistingAppBtnSelection, selectedCartridgeIndexObservable);
    dbc.addValidationStatusProvider(newApplicationTypeValidator);
    ControlDecorationSupport.create(newApplicationTypeValidator, SWT.LEFT | SWT.TOP, null,
            new RequiredControlDecorationUpdater());

    // embeddable cartridges
    this.newAppEmbeddableCartridgesGroup = new Group(newAppConfigurationGroup, SWT.NONE);
    newAppEmbeddableCartridgesGroup.setText("Embeddable Cartridges");
    GridDataFactory.fillDefaults().grab(true, true).align(SWT.FILL, SWT.FILL).span(3, 1)
            .applyTo(newAppEmbeddableCartridgesGroup);
    GridLayoutFactory.fillDefaults().numColumns(2).margins(6, 6).applyTo(newAppEmbeddableCartridgesGroup);

    Composite tableContainer = new Composite(newAppEmbeddableCartridgesGroup, SWT.NONE);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, true).span(1, 2).hint(400, 250)
            .applyTo(tableContainer);
    this.viewer = createTable(tableContainer);
    dbc.bindSet(ViewerProperties.checkedElements(IEmbeddableCartridge.class).observe(viewer),
            BeanProperties.set(ApplicationConfigurationWizardPageModel.PROPERTY_SELECTED_EMBEDDABLE_CARTRIDGES)
                    .observe(pageModel));
    // strategy has to be attached after the binding, so that the binding
    // can still add the checked cartridge and the strategy can correct
    viewer.addCheckStateListener(new EmbedCartridgeStrategyAdapter(pageModel, this));

    this.checkAllButton = new Button(newAppEmbeddableCartridgesGroup, SWT.PUSH);
    checkAllButton.setText("&Select All");
    GridDataFactory.fillDefaults().hint(110, SWT.DEFAULT).grab(false, false).align(SWT.FILL, SWT.TOP)
            .applyTo(checkAllButton);
    checkAllButton.addSelectionListener(onCheckAll());

    this.uncheckAllButton = new Button(newAppEmbeddableCartridgesGroup, SWT.PUSH);
    uncheckAllButton.setText("&Deselect All");
    GridDataFactory.fillDefaults().hint(110, SWT.DEFAULT).grab(false, true).align(SWT.FILL, SWT.TOP)
            .applyTo(uncheckAllButton);
    uncheckAllButton.addSelectionListener(onUncheckAll());

    // bottom filler
    Composite spacer = new Composite(newAppConfigurationGroup, SWT.NONE);
    GridDataFactory.fillDefaults().span(2, 1).align(SWT.FILL, SWT.FILL).grab(true, true).applyTo(spacer);
}

From source file:org.jboss.tools.openshift.express.internal.ui.wizard.embed.EmbedCartridgeWizardPage.java

License:Open Source License

@Override
protected void doCreateControls(Composite parent, DataBindingContext dbc) {
    GridLayoutFactory.fillDefaults().margins(10, 10).applyTo(parent);

    Group embedGroup = new Group(parent, SWT.NONE);
    embedGroup.setText("Embeddable Cartridges");
    GridDataFactory.fillDefaults().hint(200, 300).align(SWT.FILL, SWT.FILL).grab(true, true)
            .applyTo(embedGroup);/*from   ww w . j  a va2  s.com*/
    GridLayoutFactory.fillDefaults().numColumns(3).margins(6, 6).applyTo(embedGroup);

    Composite tableContainer = new Composite(embedGroup, SWT.NONE);
    this.viewer = createTable(tableContainer);
    GridDataFactory.fillDefaults().span(3, 1).align(SWT.FILL, SWT.FILL).grab(true, true)
            .applyTo(tableContainer);
    dbc.bindSet(ViewerProperties.checkedElements(IEmbeddableCartridge.class).observe(viewer), BeanProperties
            .set(EmbedCartridgeWizardPageModel.PROPERTY_SELECTED_EMBEDDABLE_CARTRIDGES).observe(pageModel));
    ;
    // strategy has to be attached after the binding, so that the binding
    // can still add the checked cartridge and the strategy can correct
    viewer.addCheckStateListener(new EmbedCartridgeStrategyAdapter(pageModel, this));

    // hiding buttons for now: https://issues.jboss.org/browse/JBIDE-10399
    // Button checkAllButton = new Button(embedGroup, SWT.PUSH);
    // checkAllButton.setText("Embed A&ll");
    // GridDataFactory.fillDefaults()
    // .hint(110, SWT.DEFAULT).align(SWT.FILL,
    // SWT.CENTER).applyTo(checkAllButton);
    // checkAllButton.addSelectionListener(onCheckAll());

    // Button uncheckAllButton = new Button(embedGroup, SWT.PUSH);
    // uncheckAllButton.setText("Embed N&one");
    // GridDataFactory.fillDefaults()
    // .hint(110, SWT.DEFAULT).align(SWT.FILL,
    // SWT.CENTER).applyTo(uncheckAllButton);
    // uncheckAllButton.addSelectionListener(onUncheckAll());
}

From source file:org.jboss.tools.openshift.express.internal.ui.wizard.embed.EmbeddedCartridgesWizardPage.java

License:Open Source License

@Override
protected void doCreateControls(Composite parent, DataBindingContext dbc) {
    GridLayoutFactory.fillDefaults().numColumns(2).margins(10, 10).applyTo(parent);

    Composite tableContainer = new Composite(parent, SWT.NONE);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, true).hint(500, 400)
            .applyTo(tableContainer);//from   www. j ava 2s .  com
    CheckboxTableViewer viewer = createCartridgesTableViewer(tableContainer);

    viewer.setInput(BeanProperties.list(EmbeddedCartridgesWizardPageModel.PROPERTY_EMBEDDABLE_CARTRIDGES)
            .observe(pageModel));
    // directly bind UI to model so that UI/model are synced (we'd have to update UI with strategy results otherwise)
    dbc.bindSet(ViewerProperties.checkedElements(ICartridge.class).observe(viewer), BeanProperties
            .set(EmbeddedCartridgesWizardPageModel.PROPERTY_CHECKED_CARTRIDGES).observe(pageModel));
    // strategy has to be attached after the binding, so that the binding
    // can still add the checked cartridge and the strategy can correct
    viewer.addCheckStateListener(onCartridgeChecked(pageModel, this));

    IObservableValue selectedCartridgeObservable = BeanProperties
            .value(EmbeddedCartridgesWizardPageModel.PROPERTY_SELECTED_CARTRIDGE).observe(pageModel);
    ValueBindingBuilder.bind(ViewerProperties.singlePostSelection().observe(viewer))
            .to(selectedCartridgeObservable).in(dbc);

    createButtons(parent, dbc);

    // selected cartridge details
    Group cartridgeDetailsGroup = new Group(parent, SWT.NONE);
    cartridgeDetailsGroup.setText(" Selected Cartridge: ");
    GridDataFactory.fillDefaults().span(2, 1).align(SWT.FILL, SWT.FILL).grab(true, false).hint(SWT.DEFAULT, 140)
            .applyTo(cartridgeDetailsGroup);
    new CartridgeDetailViews(selectedCartridgeObservable,
            BeanProperties.value(ApplicationConfigurationWizardPageModel.PROPERTY_CAN_ADDREMOVE_CARTRIDGES)
                    .observe(pageModel),
            cartridgeDetailsGroup, dbc).createControls();
}

From source file:org.jboss.tools.openshift.express.internal.ui.wizard.markers.ConfigureMarkersWizardPage.java

License:Open Source License

@Override
protected void doCreateControls(Composite parent, DataBindingContext dbc) {
    GridLayoutFactory.fillDefaults().margins(10, 10).applyTo(parent);

    // markers table
    Composite tableContainer = new Composite(parent, SWT.NONE);
    this.viewer = createTable(tableContainer);
    GridDataFactory.fillDefaults().span(3, 1).align(SWT.FILL, SWT.FILL).hint(SWT.DEFAULT, 250).grab(true, true)
            .applyTo(tableContainer);// w  w  w .  ja  v a 2  s  .c om
    dbc.bindSet(ViewerProperties.checkedElements(IOpenShiftMarker.class).observe(viewer),
            BeanProperties.set(ConfigureMarkersWizardPageModel.PROPERTY_CHECKED_MARKERS).observe(pageModel));
    ValueBindingBuilder
            .bind(ViewerProperties.singleSelection().observe(viewer)).to(BeanProperties
                    .value(ConfigureMarkersWizardPageModel.PROPERTY_SELECTED_MARKER).observe(pageModel))
            .in(dbc);

    // marker description
    Group descriptionGroup = new Group(parent, SWT.NONE);
    descriptionGroup.setText("Marker Description");
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, false).applyTo(descriptionGroup);
    GridLayoutFactory.fillDefaults().margins(6, 6).applyTo(descriptionGroup);
    StyledText descriptionText = new StyledText(descriptionGroup, SWT.WRAP | SWT.V_SCROLL | SWT.READ_ONLY);
    descriptionText.setAlwaysShowScrollBars(false);
    StyledTextUtils.setTransparent(descriptionText);
    GridDataFactory.fillDefaults().hint(SWT.DEFAULT, 80).align(SWT.FILL, SWT.FILL).grab(true, false)
            .applyTo(descriptionText);
    dbc.bindSet(ViewersObservables.observeCheckedElements(viewer, IOpenShiftMarker.class),
            BeanProperties.set(ConfigureMarkersWizardPageModel.PROPERTY_CHECKED_MARKERS).observe(pageModel));
    ValueBindingBuilder
            .bind(WidgetProperties.text().observe(descriptionText)).notUpdating(BeanProperties
                    .value(ConfigureMarkersWizardPageModel.PROPERTY_SELECTED_MARKER).observe(pageModel))
            .converting(new Converter(IOpenShiftMarker.class, String.class) {

                @Override
                public Object convert(Object fromObject) {
                    if (!(fromObject instanceof BaseOpenShiftMarker)) {
                        return null;
                    }
                    return ((IOpenShiftMarker) fromObject).getDescription();
                }

            }).in(dbc);
}