Example usage for com.vaadin.ui AbstractField addListener

List of usage examples for com.vaadin.ui AbstractField addListener

Introduction

In this page you can find the example usage for com.vaadin.ui AbstractField addListener.

Prototype

@Override
    public Registration addListener(Component.Listener listener) 

Source Link

Usage

From source file:nz.co.senanque.vaadinsupport.application.MaduraSessionManager.java

License:Apache License

public void bind(final MaduraForm form, final AbstractField field, MaduraPropertyWrapper property) {
    field.setPropertyDataSource(property);
    Hints hints = getHints();//  w ww  . j  a  va 2  s  . c o  m

    hints.setCommonProperties(field, property, m_messageSource);
    setPermissions(property, field);
    registerWidget(field);
    field.addListener(new MaduraPropertyWrapper.ValueChangeListener() {

        private static final long serialVersionUID = -3295559168401789196L;

        public void valueChange(ValueChangeEvent event) {
            com.vaadin.data.Property p = field.getPropertyDataSource();
            if (p instanceof MaduraPropertyWrapper) {
                MaduraPropertyWrapper property = (MaduraPropertyWrapper) p;
                if (property.getErrorText() != null) {
                    field.setComponentError(new UserError(property.getErrorText()));
                } else {
                    field.setComponentError(null);
                }
            }
            List<String> errors = new ArrayList<String>();
            if (form != null) {
                for (Object propertyId : form.getItemPropertyIds()) {
                    Field f = form.getField(propertyId);
                    if (f instanceof AbstractField) {
                        AbstractField fieldy = (AbstractField) f;
                        if (fieldy.getComponentError() != null) {
                            errors.add(fieldy.getComponentError().toString());
                        }
                    }
                }
                form.setErrors(errors);
            }
            updateOtherFields(field);
        }
    });
}

From source file:nz.co.senanque.vaadinsupport.application.MaduraSessionManager.java

License:Apache License

public void register(final AbstractField field) {
    if (field instanceof Button) {
        throw new RuntimeException("Attempted to register a button without a Button Painter");
    }// w ww .  j  av a  2  s.  c om
    registerWidget(field);
    field.addListener(new MaduraPropertyWrapper.ValueChangeListener() {

        private static final long serialVersionUID = 5542293169155226281L;

        public void valueChange(ValueChangeEvent event) {
            com.vaadin.data.Property p = field.getPropertyDataSource();
            if (p instanceof MaduraPropertyWrapper) {
                MaduraPropertyWrapper property = (MaduraPropertyWrapper) p;
                if (property.getErrorText() != null) {
                    field.setComponentError(new UserError(property.getErrorText()));
                } else {
                    field.setComponentError(null);
                }
            }
            //                List<String> errors = new ArrayList<String>();
            //                if (form != null)
            //                {
            //                    for (Object propertyId : form.getItemPropertyIds())
            //                    {
            //                        Field f = form.getField(propertyId);
            //                        if (f instanceof AbstractField)
            //                        {
            //                            AbstractField fieldy = (AbstractField) f;
            //                            if (fieldy.getComponentError() != null)
            //                            {
            //                                errors.add(fieldy.getComponentError()
            //                                        .toString());
            //                            }
            //                        }
            //                    }
            //                    form.setErrors(errors);
            //                }
            updateOtherFields(field);
        }
    });
}