SWT / JFace数据绑定更改背景

时间:2014-09-23 21:14:42

标签: eclipse data-binding swt jface nebula

在使用DataBinding进行验证时,我必须实现更改后台行为,我该怎么做? 我有两个DateChooserCombo(星云),我希望防止重叠,并将颜色更改为红色,例如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);

1 个答案:

答案 0 :(得分: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");
    }
}