AggregateValidationStatus的ChangeListener中的JFace/Eclipse数据绑定触发器多验证器 [英] JFace/Eclipse databinding trigger multivalidator in ChangeListener of AggregateValidationStatus

查看:98
本文介绍了AggregateValidationStatus的ChangeListener中的JFace/Eclipse数据绑定触发器多验证器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个AggregateValidationStatus和一个IChangeListener.每次选择/更改和调用组件时,都会调用该侦听器.我唯一的问题是必须在ChangeListener的开头触发我的MultiValidatorvalidate()方法.不幸的是,文档很少,我发现对我没有帮助.

I have an AggregateValidationStatus with an IChangeListener. The listener is called every time I select/change and component which is what I need. The only problem I have is that I have to trigger the validate() method of my MultiValidator in the beginning of the ChangeListener. Sadly there is very low documentation and what I found didn't help me.

我的ChangeListener

final AggregateValidationStatus aggregateValidationStatus = new AggregateValidationStatus(
        dataBindingContext.getBindings(), AggregateValidationStatus.MAX_SEVERITY);
aggregateValidationStatus.addChangeListener(new IChangeListener() {
    public void handleChange(ChangeEvent event) {
        //Here I have to trigger the MultiValidator to return either OK or ERROR
        boolean formIsValid = true;
        aggregateValidationStatus.getValue();
        for (Object o : dataBindingContext.getBindings()) {
            Binding binding = (Binding) o;
            IStatus status = (IStatus) binding.getValidationStatus().getValue();
            if (!status.isOK()) {
                formIsValid = false;
            }

            Control control = null;
            if (binding.getTarget() instanceof ISWTObservable) {
                ISWTObservable swtObservable = (ISWTObservable) binding.getTarget();
                control = (Control) swtObservable.getWidget();
            }
            if (binding.getTarget() instanceof CalendarComboObservableValue) {
                CalendarComboObservableValue observable = (CalendarComboObservableValue) binding.getTarget();
                control = (Control) observable.getControl();
            }

            if (binding.getTarget() instanceof IViewerObservable) {
                IViewerObservable observable = (IViewerObservable) binding.getTarget();
                control = observable.getViewer().getControl();
            }

            ControlDecoration decoration = decoratorMap.get(control);
            if (decoration != null) {
                if (status.isOK() || status.matches(Status.WARNING)) {
                    decoration.hide();
                } else {
                    decoration.setDescriptionText(status.getMessage());
                    decoration.show();
                }
            }
        }
        if (saveBtn != null)
            saveBtn.setEnabled(formIsValid);
    }
});

推荐答案

您的AggregateValidationStatus仅聚合datBindingContext的绑定:

final AggregateValidationStatus aggregateValidationStatus = new AggregateValidationStatus(
    dataBindingContext.getBindings(), AggregateValidationStatus.MAX_SEVERITY);

MultiValidator未附加到单个绑定,而是附加到整个上下文.因此,如果您希望AggregateValidationStatus也监视MultiValidator,则应使用其他构造函数:

The MultiValidator is not attached to a single binding but to the whole context. So if you want your AggregateValidationStatus to monitor MultiValidators as well, you should use a different constructor:

final AggregateValidationStatus aggregateValidationStatus = new AggregateValidationStatus(
    dataBindingContext, AggregateValidationStatus.MAX_SEVERITY);

这应该使handleChanged中的MultiValidator手动触发成为多余.

This should make the manual trigger of the MultiValidator in handleChanged superfluent.

这篇关于AggregateValidationStatus的ChangeListener中的JFace/Eclipse数据绑定触发器多验证器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆