0

在使用 DataBinding 进行验证时,我必须实现更改背景行为,我该怎么做?我有两个 DateChooserCombo (nebula),我想防止重叠,并将颜色更改为红色,例如当 dateBegin > dateEnd 时,这就是我到目前为止所做的。谢谢

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

1 回答 1

1

我认为这样的事情会奏效。

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");
    }
}
于 2014-09-23T22:53:45.067 回答