Example usage for org.eclipse.jface.databinding.swt WidgetProperties selection

List of usage examples for org.eclipse.jface.databinding.swt WidgetProperties selection

Introduction

In this page you can find the example usage for org.eclipse.jface.databinding.swt WidgetProperties selection.

Prototype

public static IWidgetValueProperty selection() 

Source Link

Document

Returns a value property for observing the selection state of a Button , CCombo , Combo , DateTime , List , MenuItem (since 1.5), Scale , Slider (since 1.5) or Spinner .

Usage

From source file:com.maccasoft.composer.CommandControl.java

License:Open Source License

public void bind(DataBindingContext ctx, Command cmd) {
    List<Binding> bindings = new ArrayList<Binding>();

    bindings.add(ctx.bindValue(WidgetProperties.selection().observe(disable),
            BeanProperties.value(cmd.getClass(), Command.PROP_DISABLED).observe(cmd)));

    bindings.add(ctx.bindValue(WidgetProperties.selection().observe(repeat),
            BeanProperties.value(cmd.getClass(), Command.PROP_REPEAT).observe(cmd)));
    bindings.add(ctx.bindValue(WidgetProperties.singleSelectionIndex().observe(action),
            BeanProperties.value(cmd.getClass(), Command.PROP_ACTION).observe(cmd)));
    bindings.add(ctx.bindValue(WidgetProperties.singleSelectionIndex().observe(property),
            BeanProperties.value(cmd.getClass(), Command.PROP_PROPERTY).observe(cmd)));

    bindings.add(ctx.bindValue(WidgetProperties.selection().observe(steps),
            BeanProperties.value(cmd.getClass(), Command.PROP_VALUE).observe(cmd)));

    bindings.add(ctx.bindValue(WidgetProperties.text(SWT.Modify).observe(frequency),
            BeanProperties.value(cmd.getClass(), Command.PROP_FREQUENCY).observe(cmd),
            new UpdateValueStrategy().setConverter(new StringToDoubleConverter()),
            new UpdateValueStrategy().setConverter(new NumberToStringConverter())));
    bindings.add(ctx.bindValue(WidgetProperties.text(SWT.Modify).observe(frequencyNote),
            BeanProperties.value(cmd.getClass(), Command.PROP_FREQUENCY_NOTE).observe(cmd)));

    bindings.add(ctx.bindValue(WidgetProperties.text(SWT.Modify).observe(duration),
            BeanProperties.value(cmd.getClass(), Command.PROP_ENVELOPE_LENGTH).observe(cmd),
            new UpdateValueStrategy().setConverter(new StringToDoubleConverter()),
            new UpdateValueStrategy().setConverter(new NumberToStringConverter())));
    bindings.add(ctx.bindValue(WidgetProperties.text(SWT.Modify).observe(reset),
            BeanProperties.value(cmd.getClass(), Command.PROP_ENVELOPE_RESET).observe(cmd),
            new UpdateValueStrategy().setConverter(new StringToDoubleConverter()),
            new UpdateValueStrategy().setConverter(new NumberToStringConverter())));

    bindings.add(ctx.bindValue(WidgetProperties.text(SWT.Modify).observe(volume),
            BeanProperties.value(cmd.getClass(), Command.PROP_VOLUME).observe(cmd),
            new UpdateValueStrategy().setConverter(new StringToDoubleConverter()),
            new UpdateValueStrategy().setConverter(new NumberToStringConverter())));

    bindings.add(ctx.bindValue(WidgetProperties.text(SWT.Modify).observe(variable),
            BeanProperties.value(cmd.getClass(), Command.PROP_MODULATION).observe(cmd),
            new UpdateValueStrategy().setConverter(new StringToDoubleConverter()),
            new UpdateValueStrategy().setConverter(new NumberToStringConverter())));
    bindings.add(ctx.bindValue(WidgetProperties.text(SWT.Modify).observe(fixed),
            BeanProperties.value(cmd.getClass(), Command.PROP_DUTY_CYCLE).observe(cmd),
            new UpdateValueStrategy().setConverter(new StringToDoubleConverter()),
            new UpdateValueStrategy().setConverter(new NumberToStringConverter())));

    bindings.add(ctx.bindValue(WidgetProperties.text(SWT.Modify).observe(frequencyRegister),
            BeanProperties.value(cmd.getClass(), Command.PROP_FREQUENCY_REGISTER).observe(cmd),
            new UpdateValueStrategy().setConverter(new HexStringToLongConverter()),
            new UpdateValueStrategy().setConverter(new NumberToHexStringConverter())));
    bindings.add(ctx.bindValue(WidgetProperties.text(SWT.Modify).observe(envelopeRegister),
            BeanProperties.value(cmd.getClass(), Command.PROP_ENVELOPE_REGISTER).observe(cmd),
            new UpdateValueStrategy().setConverter(new HexStringToLongConverter()),
            new UpdateValueStrategy().setConverter(new NumberToHexStringConverter())));
    bindings.add(ctx.bindValue(WidgetProperties.text(SWT.Modify).observe(volumeRegister),
            BeanProperties.value(cmd.getClass(), Command.PROP_VOLUME_REGISTER).observe(cmd),
            new UpdateValueStrategy().setConverter(new HexStringToLongConverter()),
            new UpdateValueStrategy().setConverter(new NumberToHexStringConverter())));
    bindings.add(ctx.bindValue(WidgetProperties.text(SWT.Modify).observe(modulationRegister),
            BeanProperties.value(cmd.getClass(), Command.PROP_MODULATION_REGISTER).observe(cmd),
            new UpdateValueStrategy().setConverter(new HexStringToLongConverter()),
            new UpdateValueStrategy().setConverter(new NumberToHexStringConverter())));

    for (Iterator<Binding> it = bindings.iterator(); it.hasNext();) {
        it.next().updateModelToTarget();
    }/*ww w .j  ava  2s  .co  m*/

    updateVisibleStack();
    updateVisibleProperty();
    updateEnablement();
}

From source file:com.nextep.designer.dbgm.mysql.ui.impl.MySQLColumnFormEditor.java

License:Open Source License

@Override
protected void doBindModel(DataBindingContext context) {
    IObservableValue selectionValue = ViewersObservables.observeSingleSelection(getSelectionProvider());

    // Binding charset
    IObservableValue widgetValue = WidgetProperties.text().observe(charsetCombo);
    IObservableValue modelValue = PojoObservables.observeDetailValue(selectionValue, "characterSet", //$NON-NLS-1$
            String.class);
    UpdateValueStrategy modelUpdateStrategy = new UpdateValueStrategy();
    modelUpdateStrategy.setConverter(MySQLConverterFactory.createNameToCodeCharsetConverter(collationCombo));
    UpdateValueStrategy targetUpdateStrategy = new UpdateValueStrategy();
    targetUpdateStrategy.setConverter(MySQLConverterFactory.createCodeToNameCharsetConverter());
    context.bindValue(widgetValue, modelValue, modelUpdateStrategy, targetUpdateStrategy);

    // Binding autoinc
    widgetValue = WidgetProperties.selection().observe(autoIncButton);
    modelValue = PojoObservables.observeDetailValue(selectionValue, "autoIncremented", Boolean.class); //.value(IBasicColumn.class, "name").observe( //$NON-NLS-1$
    context.bindValue(widgetValue, modelValue, null, null);

    // Binding unsigned
    widgetValue = WidgetProperties.selection().observe(unsignedButton);
    modelValue = PojoObservables.observeDetailValue(selectionValue, "datatype.unsigned", //$NON-NLS-1$
            Boolean.class);
    context.bindValue(widgetValue, modelValue, null, null);

    // Binding collation
    widgetValue = WidgetProperties.text().observe(collationCombo);
    modelValue = PojoObservables.observeDetailValue(selectionValue, "collation", String.class); //$NON-NLS-1$
    context.bindValue(widgetValue, modelValue, null, null);
}

From source file:com.nextep.designer.dbgm.oracle.ui.impl.OracleMaterializedViewFormEditor.java

License:Open Source License

@Override
protected void doBindModel(DataBindingContext context) {
    final IMaterializedView view = getModel();

    // Binding refresh time
    IObservableValue widgetValue = WidgetProperties.selection().observe(timeCombo);
    IObservableValue modelValue = PojoProperties.value(IMaterializedView.class, "refreshTime").observe(view); //$NON-NLS-1$
    // Converters setup
    UpdateValueStrategy targetModelStrategy = new UpdateValueStrategy();
    targetModelStrategy.setConverter(OracleConverterFactory.createGenericEnumModelConverter(RefreshTime.class));
    UpdateValueStrategy modelTargetStrategy = new UpdateValueStrategy();
    modelTargetStrategy//  ww  w.  j  a v a 2  s . c om
            .setConverter(OracleConverterFactory.createGenericEnumTargetConverter(RefreshTime.class));
    // Binding
    context.bindValue(widgetValue, modelValue, targetModelStrategy, modelTargetStrategy);

    // Binding refresh method
    widgetValue = WidgetProperties.selection().observe(methodCombo);
    modelValue = PojoProperties.value(IMaterializedView.class, "refreshMethod").observe(view); //$NON-NLS-1$
    // Converters setup
    targetModelStrategy = new UpdateValueStrategy();
    targetModelStrategy
            .setConverter(OracleConverterFactory.createGenericEnumModelConverter(RefreshMethod.class));
    modelTargetStrategy = new UpdateValueStrategy();
    modelTargetStrategy
            .setConverter(OracleConverterFactory.createGenericEnumTargetConverter(RefreshMethod.class));
    // Binding
    context.bindValue(widgetValue, modelValue, targetModelStrategy, modelTargetStrategy);

    // Binding view type
    widgetValue = WidgetProperties.selection().observe(typeCombo);
    modelValue = PojoProperties.value(IMaterializedView.class, "viewType").observe(view); //$NON-NLS-1$
    // Converters setup
    targetModelStrategy = new UpdateValueStrategy();
    targetModelStrategy
            .setConverter(OracleConverterFactory.createGenericEnumModelConverter(MaterializedViewType.class));
    modelTargetStrategy = new UpdateValueStrategy();
    modelTargetStrategy
            .setConverter(OracleConverterFactory.createGenericEnumTargetConverter(MaterializedViewType.class));
    // Binding
    context.bindValue(widgetValue, modelValue, targetModelStrategy, modelTargetStrategy);

    // Binding start expression
    widgetValue = WidgetProperties.text(SWT.FocusOut).observe(startText);
    modelValue = PojoProperties.value(IMaterializedView.class, "startExpr").observe(view); //$NON-NLS-1$
    context.bindValue(widgetValue, modelValue);

    // Binding next expression
    widgetValue = WidgetProperties.text(SWT.FocusOut).observe(nextText);
    modelValue = PojoProperties.value(IMaterializedView.class, "nextExpr").observe(view); //$NON-NLS-1$
    context.bindValue(widgetValue, modelValue);

    // Binding build type
    widgetValue = WidgetProperties.selection().observe(buildCombo);
    modelValue = PojoProperties.value(IMaterializedView.class, "buildType").observe(view); //$NON-NLS-1$
    // Converters setup
    targetModelStrategy = new UpdateValueStrategy();
    targetModelStrategy.setConverter(OracleConverterFactory.createGenericEnumModelConverter(BuildType.class));
    modelTargetStrategy = new UpdateValueStrategy();
    modelTargetStrategy.setConverter(OracleConverterFactory.createGenericEnumTargetConverter(BuildType.class));
    // Binding
    context.bindValue(widgetValue, modelValue, targetModelStrategy, modelTargetStrategy);

    // Binding start expression
    widgetValue = WidgetProperties.selection().observe(queryRewriteButton);
    modelValue = PojoProperties.value(IMaterializedView.class, "queryRewriteEnabled").observe(view); //$NON-NLS-1$
    context.bindValue(widgetValue, modelValue);
}

From source file:com.nextep.designer.dbgm.oracle.ui.impl.OracleTablePhysicalPropertiesFormEditor.java

License:Open Source License

@Override
protected void doBindModel(DataBindingContext context) {
    // Not binding anything if the model is not ready
    if (getModel() == null) {
        return;//from   ww w.  j ava  2  s.  co  m
    }
    final IPhysicalProperties props = getModel().getPhysicalProperties();
    // Binding tablespace
    IObservableValue widgetValue = WidgetProperties.text(SWT.FocusOut).observe(tablespaceText);
    IObservableValue modelValue = PojoProperties.value(IPhysicalProperties.class, "tablespaceName") //$NON-NLS-1$
            .observe(props);
    context.bindValue(widgetValue, modelValue);

    // Binding organization
    if (props instanceof ITablePhysicalProperties || (props == null && getModel() instanceof IOracleTable)) {
        widgetValue = WidgetProperties.selection().observe(organizationCombo);
        modelValue = PojoProperties.value(IOracleTablePhysicalProperties.class, "physicalOrganisation") //$NON-NLS-1$
                .observe(props);
        UpdateValueStrategy modelStrategy = new UpdateValueStrategy()
                .setConverter(OracleConverterFactory.createPhysicalOrganizationModelConverter());
        UpdateValueStrategy targetStrategy = new UpdateValueStrategy()
                .setConverter(OracleConverterFactory.createPhysicalOrganizationTargetConverter());
        context.bindValue(widgetValue, modelValue, modelStrategy, targetStrategy);
    }
    // Binding logging
    widgetValue = WidgetProperties.selection().observe(loggingButton);
    modelValue = PojoProperties.value(IPhysicalProperties.class, "logging").observe(props); //$NON-NLS-1$
    context.bindValue(widgetValue, modelValue);
    // Binding compressed
    widgetValue = WidgetProperties.selection().observe(compressedButton);
    modelValue = PojoProperties.value(IPhysicalProperties.class, "compressed").observe(props); //$NON-NLS-1$
    context.bindValue(widgetValue, modelValue);
}

From source file:com.nextep.designer.dbgm.ui.editors.ColumnFormEditor.java

License:Open Source License

@Override
protected void doBindModel(DataBindingContext context) {
    IObservableValue selectionValue = ViewersObservables.observeSingleSelection(getSelectionProvider());

    IObservableValue widgetValue = WidgetProperties.text(SWT.FocusOut).observe(nameText);
    IObservableValue modelValue = PojoObservables.observeDetailValue(selectionValue, "name", //$NON-NLS-1$
            String.class);

    UpdateValueStrategy targetModelStrategy = new UpdateValueStrategy();
    // UpdateValueStrategy.POLICY_CONVERT);
    targetModelStrategy.setAfterConvertValidator(ValidatorFactory.createNameValidator(false));
    Binding boundValue = context.bindValue(widgetValue, modelValue, targetModelStrategy, null);
    fieldDecorators.add(ControlDecorationSupport.create(boundValue, SWT.TOP | SWT.LEFT));

    // Binding description
    widgetValue = WidgetProperties.text(SWT.FocusOut).observe(descText);
    modelValue = PojoObservables.observeDetailValue(selectionValue, "description", String.class); //$NON-NLS-1$
    boundValue = context.bindValue(widgetValue, modelValue);

    // Binding datatype
    widgetValue = WidgetProperties.selection().observe(datatypeCombo);
    modelValue = PojoObservables.observeDetailValue(selectionValue, "datatype.name", //$NON-NLS-1$
            String.class);
    boundValue = context.bindValue(widgetValue, modelValue);

    final IValidator integerValidator = ValidatorFactory.createIntegerValidator();
    // Binding length
    widgetValue = WidgetProperties.text(SWT.FocusOut).observe(lengthText);
    modelValue = PojoObservables.observeDetailValue(selectionValue, "datatype.length", //$NON-NLS-1$
            int.class);
    targetModelStrategy = new UpdateValueStrategy();
    targetModelStrategy.setAfterGetValidator(integerValidator);
    targetModelStrategy.setConverter(ConverterFactory.createToIntegerConverter(true, true));

    UpdateValueStrategy modelTargetStrategy = new UpdateValueStrategy();
    modelTargetStrategy.setAfterGetValidator(integerValidator);
    modelTargetStrategy.setConverter(ConverterFactory.createFromIntegerConverter(true, true));
    boundValue = context.bindValue(widgetValue, modelValue, targetModelStrategy, modelTargetStrategy);
    fieldDecorators.add(ControlDecorationSupport.create(boundValue, SWT.TOP | SWT.LEFT));

    // Binding length type
    widgetValue = WidgetProperties.selection().observe(lengthTypeCombo);
    modelValue = PojoObservables.observeDetailValue(selectionValue, "datatype.lengthType", //$NON-NLS-1$
            String.class);
    targetModelStrategy = new UpdateValueStrategy()
            .setConverter(ConverterFactory.createLengthTypeModelConverter());
    modelTargetStrategy = new UpdateValueStrategy()
            .setConverter(ConverterFactory.createLengthTypeTargetConverter());
    boundValue = context.bindValue(widgetValue, modelValue, targetModelStrategy, modelTargetStrategy);

    // Binding precision
    widgetValue = WidgetProperties.text(SWT.FocusOut).observe(precisionText);
    modelValue = PojoObservables.observeDetailValue(selectionValue, "datatype.precision", //$NON-NLS-1$
            int.class);
    targetModelStrategy = new UpdateValueStrategy();
    targetModelStrategy.setAfterGetValidator(integerValidator);
    targetModelStrategy.setConverter(ConverterFactory.createToIntegerConverter(true, true));

    modelTargetStrategy = new UpdateValueStrategy();
    modelTargetStrategy.setAfterGetValidator(integerValidator);
    modelTargetStrategy.setConverter(ConverterFactory.createFromIntegerConverter(true, true));
    boundValue = context.bindValue(widgetValue, modelValue, targetModelStrategy, modelTargetStrategy);
    fieldDecorators.add(ControlDecorationSupport.create(boundValue, SWT.TOP | SWT.LEFT));

    // Binding not null
    widgetValue = WidgetProperties.selection().observe(notNullButton);
    modelValue = PojoObservables.observeDetailValue(selectionValue, "notNull", boolean.class); //$NON-NLS-1$
    boundValue = context.bindValue(widgetValue, modelValue);

    // Binding virtual
    widgetValue = WidgetProperties.selection().observe(virtualButton);
    modelValue = PojoObservables.observeDetailValue(selectionValue, "virtual", boolean.class); //$NON-NLS-1$
    boundValue = context.bindValue(widgetValue, modelValue);

    // Binding default
    widgetValue = WidgetProperties.text(SWT.FocusOut).observe(defaultText);
    modelValue = PojoObservables.observeDetailValue(selectionValue, "defaultExpr", String.class); //$NON-NLS-1$
    boundValue = context.bindValue(widgetValue, modelValue);
}

From source file:com.nextep.designer.dbgm.ui.editors.PartitionableFormEditor.java

License:Open Source License

@SuppressWarnings("unchecked")
@Override// w  ww. j  a  v  a 2  s. c  om
protected void doBindModel(DataBindingContext context) {
    final IPartitionable partitionable = (IPartitionable) getModel().getPhysicalProperties();
    // Binding partitioning
    IObservableValue widgetValue = WidgetProperties.selection().observe(partitioningCombo);
    IObservableValue modelValue = PojoProperties.value(IPartitionable.class, "partitioningMethod") //$NON-NLS-1$
            .observe(partitionable);
    UpdateValueStrategy modelStrategy = new UpdateValueStrategy()
            .setConverter(ConverterFactory.createPartitioningMethodModelConverter());
    UpdateValueStrategy targetStrategy = new UpdateValueStrategy()
            .setConverter(ConverterFactory.createPartitioningMethodTargetConverter());
    context.bindValue(widgetValue, modelValue, modelStrategy, targetStrategy);

    // Injecting model in underlying column component
    if (getModel() instanceof IBasicTable && partitioningColumnsComponent instanceof IModelOriented<?>) {
        ((IModelOriented<IPhysicalProperties>) partitioningColumnsComponent)
                .setModel(getModel().getPhysicalProperties());
    }
}

From source file:com.nextep.designer.dbgm.ui.editors.TableFormEditor.java

License:Open Source License

@Override
protected void doBindModel(DataBindingContext context) {

    final IBasicTable table = getModel();
    // Name binding
    IObservableValue widgetValue = WidgetProperties.text(SWT.FocusOut).observe(nameText);
    IObservableValue modelValue = PojoProperties.value(IBasicTable.class, "name") //$NON-NLS-1$
            .observe(table);/*from   w ww.  java2 s  . c o m*/

    UpdateValueStrategy targetModelStrategy = new UpdateValueStrategy();
    targetModelStrategy.setAfterConvertValidator(ValidatorFactory.createNameValidator(false));
    Binding boundValue = context.bindValue(widgetValue, modelValue, targetModelStrategy, null);
    registerControlDecoration(ControlDecorationSupport.create(boundValue, SWT.TOP | SWT.LEFT));

    // Short name binding
    widgetValue = WidgetProperties.text(SWT.FocusOut).observe(shortNameText);
    modelValue = PojoProperties.value(IBasicTable.class, "shortName").observe(table); //$NON-NLS-1$

    targetModelStrategy = new UpdateValueStrategy();
    targetModelStrategy.setAfterConvertValidator(ValidatorFactory.createNameValidator(true));
    boundValue = context.bindValue(widgetValue, modelValue, targetModelStrategy, null);
    registerControlDecoration(ControlDecorationSupport.create(boundValue, SWT.TOP | SWT.LEFT));

    // Description binding
    widgetValue = WidgetProperties.text(SWT.FocusOut).observe(descText);
    modelValue = PojoProperties.value(IBasicTable.class, "description").observe(table); //$NON-NLS-1$

    targetModelStrategy = new UpdateValueStrategy();
    boundValue = context.bindValue(widgetValue, modelValue, targetModelStrategy, null);

    // Binding temporary
    widgetValue = WidgetProperties.selection().observe(temporaryCheck);
    modelValue = PojoProperties.value(IBasicTable.class, "temporary", boolean.class).observe( //$NON-NLS-1$
            table);
    boundValue = context.bindValue(widgetValue, modelValue);
}

From source file:com.nextep.designer.dbgm.ui.editors.UniqueKeyFormEditor.java

License:Open Source License

@Override
protected void doBindModel(DataBindingContext context) {
    IObservableValue selectionValue = ViewersObservables.observeSingleSelection(getSelectionProvider());

    // Binding name
    IObservableValue widgetValue = WidgetProperties.text(SWT.FocusOut).observe(nameText);
    IObservableValue modelValue = PojoObservables.observeDetailValue(selectionValue, "name", //$NON-NLS-1$
            String.class);

    UpdateValueStrategy targetModelStrategy = new UpdateValueStrategy();
    targetModelStrategy.setAfterConvertValidator(ValidatorFactory.createNameValidator(false));
    Binding boundValue = context.bindValue(widgetValue, modelValue, targetModelStrategy, null);
    ControlDecorationSupport.create(boundValue, SWT.TOP | SWT.LEFT);

    // Binding description
    widgetValue = WidgetProperties.text(SWT.FocusOut).observe(descText);
    modelValue = PojoObservables.observeDetailValue(selectionValue, "description", String.class); //$NON-NLS-1$
    boundValue = context.bindValue(widgetValue, modelValue, null, null);

    // Binding primary flag
    widgetValue = WidgetProperties.selection().observe(primaryButton);
    modelValue = PojoObservables.observeDetailValue(selectionValue, "constraintType", //$NON-NLS-1$
            ConstraintType.class);
    targetModelStrategy = new UpdateValueStrategy().setConverter(new IConverter() {

        @Override/*  w  w w.  ja  v  a 2s.c o  m*/
        public Object getToType() {
            return ConstraintType.class;
        }

        @Override
        public Object getFromType() {
            return boolean.class;
        }

        @Override
        public Object convert(Object fromObject) {
            return (Boolean) fromObject ? ConstraintType.PRIMARY : ConstraintType.UNIQUE;
        }
    });
    UpdateValueStrategy modelTargetStrategy = new UpdateValueStrategy().setConverter(new IConverter() {

        @Override
        public Object getToType() {
            return boolean.class;
        }

        @Override
        public Object getFromType() {
            return ConstraintType.class;
        }

        @Override
        public Object convert(Object fromObject) {
            return fromObject == ConstraintType.PRIMARY;
        }
    });
    boundValue = context.bindValue(widgetValue, modelValue, targetModelStrategy, modelTargetStrategy);
}

From source file:com.planetmayo.debrief.satc_rcp.ui.contributions.BaseContributionView.java

License:Open Source License

/**
 * binds model value to specified slider, label and checkBox with specified
 * converters returns writable value which is used to store direct ui value
 *///from   ww w  .  ja v  a2 s .  c o  m
protected WritableValue bindSliderLabelCheckbox(DataBindingContext context, final IObservableValue modelValue,
        Scale slider, Label label, Button checkBox, PrefixSuffixLabelConverter labelValueConverter,
        BooleanToNullConverter<?> checkBoxValueConverter, UnitConverter unitConverter) {
    final WritableValue uiProxy = new WritableValue(modelValue.getValue(), modelValue.getValueType());

    IObservableValue sliderValue = WidgetProperties.selection().observe(slider);
    IObservableValue labelValue = WidgetProperties.text().observe(label);

    if (unitConverter != null) {
        IConverter modelToUI = new CompoundConverter(unitConverter.getModelToUI(), new IntegerConverter());
        context.bindValue(sliderValue, uiProxy, UIUtils.converterStrategy(unitConverter.getUIToModel()),
                UIUtils.converterStrategy(modelToUI));
    } else {
        context.bindValue(sliderValue, uiProxy);
    }
    if (checkBox != null) {
        IObservableValue sliderEnabled = WidgetProperties.enabled().observe(slider);
        IObservableValue checkBoxValue = WidgetProperties.selection().observe(checkBox);
        context.bindValue(checkBoxValue, modelValue, UIUtils.converterStrategy(checkBoxValueConverter),
                UIUtils.converterStrategy(new NullToBooleanConverter()));
        context.bindValue(sliderEnabled, modelValue, null,
                UIUtils.converterStrategy(new NullToBooleanConverter()));
    }

    context.bindValue(labelValue, uiProxy, null, UIUtils.converterStrategy(labelValueConverter));
    context.bindValue(uiProxy, modelValue, new UpdateValueStrategy(UpdateValueStrategy.POLICY_NEVER), null);
    slider.addListener(SWT.MouseUp, new Listener() {
        @Override
        public void handleEvent(Event arg0) {
            modelValue.setValue(uiProxy.getValue());
        }
    });
    slider.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            if ((e.stateMask & SWT.BUTTON1) == 0) {
                modelValue.setValue(uiProxy.getValue());
            }
        }
    });
    return uiProxy;
}

From source file:com.planetmayo.debrief.satc_rcp.ui.contributions.BaseContributionView.java

License:Open Source License

/**
 * Utility base method which binds common header widgets: "active" checkbox,
 * hardconstrains label, estimate label, weight spinner. Must be called if
 * necessary from implementation of bindValues method in child class
 * //from  w  ww.  j  a va2  s.  c  o m
 * @param context
 * @param contribution
 * @param labelsConverter
 */
protected final void bindCommonHeaderWidgets(DataBindingContext context, IObservableValue hardContraint,
        IObservableValue estimateValue, IConverter estimateConverter, IConverter hardConstraintsConverter) {
    IObservableValue activeValue = BeansObservables.observeValue(contribution, BaseContribution.ACTIVE);
    IObservableValue activeButton = WidgetProperties.selection().observe(activeCheckBox);
    context.bindValue(activeButton, activeValue);

    if (hardContraint != null) {
        IObservableValue hardContraintLabel = WidgetProperties.text().observe(hardConstraintLabel);
        context.bindValue(hardContraintLabel, hardContraint, null,
                UIUtils.converterStrategy(hardConstraintsConverter));
    }

    if (estimateValue != null) {
        IObservableValue estimateLabel = WidgetProperties.text().observe(this.estimateLabel);
        context.bindValue(estimateLabel, estimateValue, null, UIUtils.converterStrategy(estimateConverter));
    }

    IObservableValue weightValue = BeansObservables.observeValue(contribution, BaseContribution.WEIGHT);
    IObservableValue weightWidget = WidgetProperties.selection().observe(weightSpinner);
    context.bindValue(weightWidget, weightValue);
}