0

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);

1 Answer 1

1

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");
    }
}
2
  • If you create a new Color object you must arrange to dispose of it when you are finished with it.
    – greg-449
    Sep 24, 2014 at 7:22
  • Yes you're right, this is just an illustration of the solution of how to change bg color, but yes every swt resource needs to be disposed or needs to use a resource registry like ColorRegistry o.
    – unique_ptr
    Sep 24, 2014 at 7:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.