unique_ptr
unique_ptr

Reputation: 586

SWT/JFace databinding change background

I have to implement a change background behavior when validating using DataBinding, how do I do this ? I have two DateChooserCombo (nebula ) and I want to prevent overlapping, and change color to red for example when dateBegin > dateEnd, this is what I've done so far. thanks

    IObservableValue textObservable = new DateChooserComboObservableValue(
            dateChooser, SWT.Modify);

    UpdateValueStrategy strategy = new UpdateValueStrategy();
    strategy.setBeforeSetValidator(new IValidator() {
        @Override
        public IStatus validate(Object value) {
                  //for testing purpose make it fail
            return ValidationStatus.error("this is not permitted");
        }
    });
    Realm realm = SWTObservables.getRealm(dateChooser.getDisplay());
    DataBindingContext context = new DataBindingContext(realm);
    org.eclipse.core.databinding.Binding binding = context.bindValue(
            textObservable, PojoProperties.value(Model.class, "dateEnd")
                    .observe(realm, model.dateEnd), strategy,
            strategy);
        //didn't show the control decoration as expected 
    ControlDecorationSupport.create(binding, SWT.TOP | SWT.LEFT);

Upvotes: 0

Views: 407

Answers (1)

unique_ptr
unique_ptr

Reputation: 586

I think something like this would work.

new IValidator() {
    @Override
    public IStatus validate(Object value) {
              // change background goes could here
              //myControl.setBackground (new Color (display, new RGB (230,230,230));
              //for testing purpose make it fail
        return ValidationStatus.error("this is not permitted");
    }
}

Upvotes: 1

Related Questions