Example usage for com.vaadin.ui AbstractField setLocale

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

Introduction

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

Prototype

public void setLocale(Locale locale) 

Source Link

Document

Sets the locale of this component.

Usage

From source file:info.magnolia.ui.form.field.factory.AbstractFieldFactory.java

License:Open Source License

@Override
public Field<T> createField() {
    if (locale == null) {
        if (uiContext instanceof SubAppContext) {
            final Locale authoringLocale = ((SubAppContext) uiContext).getAuthoringLocale();
            setLocale(authoringLocale == null ? i18NAuthoringSupport.getDefaultLocale(item) : authoringLocale);
        }//from  ww w . java  2s . c  om
    }

    if (field == null) {
        // Create the Vaadin field
        this.field = createFieldComponent();

        if (field instanceof AbstractField) {
            final AbstractField field = (AbstractField) this.field;
            if (definition.getConverterClass() != null) {
                Converter<?, ?> converter = initializeConverter(definition.getConverterClass());
                field.setConverter(converter);
            }
            field.setLocale(locale);
        }

        Property<?> property = initializeProperty();
        // Set the created property with the default value as field Property datasource.
        setPropertyDataSourceAndDefaultValue(property);

        if (StringUtils.isNotBlank(definition.getStyleName())) {
            this.field.addStyleName(definition.getStyleName());
        }

        field.setWidth(100, Unit.PERCENTAGE);

        setFieldCaption();
        setConstraints();

    }
    return this.field;
}

From source file:nz.co.senanque.vaadinsupport.HintsImpl.java

License:Apache License

public void setCommonProperties(final AbstractField ret, final MaduraPropertyWrapper property,
        final MessageSource messageSource) {
    ret.setWidth(getWidth());/* w w  w . j  a  v a2  s .c om*/
    ret.setReadThrough(true);
    ret.setPropertyDataSource(property);
    ret.setCaption(property.getLabel());
    ret.setRequired(property.isRequired());
    if (property.isRequired()) {
        ret.setInvalidCommitted(true);
    }
    if (property.isReadOnly()) {
        ret.setReadOnly(true);
    }
    ret.setEnabled(property.isEnabled());
    ret.setVisible(property.isVisible());
    ret.setImmediate(m_forceImmediate);
    ret.setLocale(LocaleContextHolder.getLocale());
    MessageSourceAccessor messageSourceAccessor = new MessageSourceAccessor(messageSource);
    ret.setDescription(
            messageSourceAccessor.getMessage(property.getDescription(), null, property.getDescription()));
    if (property.isNumeric()) {
        ret.addStyleName("v-textfield-align-right");
    }
    ret.setErrorHandler(new ComponentErrorHandler() {

        private static final long serialVersionUID = -1393935533100204195L;

        public boolean handleComponentError(ComponentErrorEvent event) {
            Throwable t = event.getThrowable();
            while (t != null) {
                if (t instanceof ValidationException) {
                    ret.setComponentError(new UserError(((ValidationException) t).getMessage()));
                    return true;
                }
                t = t.getCause();
            }
            return false;
        }
    });

}

From source file:nz.co.senanque.vaadinsupport.TouchkitHintsImpl.java

License:Apache License

public void setCommonProperties(final AbstractField ret, final MaduraPropertyWrapper property,
        final MessageSource messageSource) {
    ret.setWidth(getWidth());/*www  . j  a va  2 s .  c o m*/
    ret.setReadThrough(true);
    ret.setPropertyDataSource(property);
    ret.setCaption(property.getLabel());
    ret.setRequired(property.isRequired());
    if (property.isRequired()) {
        ret.setInvalidCommitted(true);
    }
    ret.setReadOnly(property.isReadOnly());
    ret.setEnabled(property.isEnabled());
    ret.setVisible(property.isVisible());
    ret.setImmediate(m_forceImmediate);
    ret.setLocale(LocaleContextHolder.getLocale());
    MessageSourceAccessor messageSourceAccessor = new MessageSourceAccessor(messageSource);
    ret.setDescription(
            messageSourceAccessor.getMessage(property.getDescription(), null, property.getDescription()));
    if (property.isNumeric()) {
        ret.addStyleName("v-textfield-align-right");
    }
    ret.setErrorHandler(new ComponentErrorHandler() {

        private static final long serialVersionUID = -1393935533100204195L;

        public boolean handleComponentError(ComponentErrorEvent event) {
            Throwable t = event.getThrowable();
            while (t != null) {
                if (t instanceof ValidationException) {
                    ret.setComponentError(new UserError(((ValidationException) t).getMessage()));
                    return true;
                }
                t = t.getCause();
            }
            return false;
        }
    });

}