Example usage for com.vaadin.v7.ui Field isReadOnly

List of usage examples for com.vaadin.v7.ui Field isReadOnly

Introduction

In this page you can find the example usage for com.vaadin.v7.ui Field isReadOnly.

Prototype

public boolean isReadOnly();

Source Link

Document

Tests if the Property is in read-only mode.

Usage

From source file:org.vaadin.viritin.v7.MBeanFieldGroup.java

License:Apache License

/**
 * Configures fields for some better defaults, like property fields
 * annotated with NotNull to be "required" (kind of a special validator in
 * Vaadin)//from  ww  w. j  a  v a  2 s . c  om
 */
public void configureMaddonDefaults() {
    for (Object property : getBoundPropertyIds()) {
        final Field<?> field = getField(property);

        try {

            // Make @NotNull annotated fields "required"
            try {
                java.lang.reflect.Field declaredField = findDeclaredField(property, nonHiddenBeanType);
                final NotNull notNullAnnotation = declaredField.getAnnotation(NotNull.class);
                if (notNullAnnotation != null && !field.isReadOnly()) {
                    field.setRequired(true);
                    Locale locale = getLocale();
                    if (locale == null) {
                        locale = Locale.getDefault();
                    }
                    String msg = getJavaxBeanValidatorFactory().getMessageInterpolator()
                            .interpolate(notNullAnnotation.message(), new MessageInterpolator.Context() {
                                @Override
                                public ConstraintDescriptor<?> getConstraintDescriptor() {
                                    return null;
                                }

                                @Override
                                public Object getValidatedValue() {
                                    return null;
                                }

                                @Override
                                public <T> T unwrap(Class<T> type) {
                                    return null;
                                }
                            }, locale);
                    getField(property).setRequiredError(msg);
                }
            } catch (NoSuchFieldException ex) {
                Logger.getLogger(MBeanFieldGroup.class.getName()).log(Level.FINE, null, ex);
            } catch (SecurityException ex) {
                Logger.getLogger(MBeanFieldGroup.class.getName()).log(Level.SEVERE, null, ex);
            }
        } catch (Throwable e) {
            if (e instanceof java.lang.ClassNotFoundException) {
                Logger.getLogger(MBeanFieldGroup.class.getName()).log(Level.FINE,
                        "Validation API not available.");
            }
        }
    }
}