在使用 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);