【问题标题】:SWT/JFace databinding change backgroundSWT/JFace 数据绑定变更背景
【发布时间】:2014-09-23 21:14:42
【问题描述】:

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

【问题讨论】:

    标签: eclipse data-binding swt jface nebula


    【解决方案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");
        }
    }
    

    【讨论】:

    • 如果您创建一个新的Color 对象,您必须安排在完成后将其丢弃。
    • 是的,你是对的,这只是说明如何更改 bg 颜色的解决方案,但是是的,每个 swt 资源都需要处置或需要使用像 ColorRegistry o 这样的资源注册表。
    猜你喜欢
    • 1970-01-01
    • 2011-09-13
    • 2011-02-24
    • 1970-01-01
    • 2015-10-12
    • 2011-05-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多