Search in sources :

Example 1 with ConversionType

use of com.haulmont.cuba.core.entity.annotation.ConversionType in project cuba by cuba-platform.

the class DataAwareComponentsTools method setupCaseConversion.

/**
 * Sets case conversion using {@link CaseConversion} annotation on entity property.
 *
 * @param component UI component
 * @param valueSource value source
 */
public void setupCaseConversion(TextInputField.CaseConversionSupported component, EntityValueSource valueSource) {
    MetaProperty metaProperty = valueSource.getMetaPropertyPath().getMetaProperty();
    Map<String, Object> annotations = metaProperty.getAnnotations();
    String caseConversionAnnotation = CaseConversion.class.getName();
    // noinspection unchecked
    Map<String, Object> caseConversion = (Map<String, Object>) annotations.get(caseConversionAnnotation);
    if (MapUtils.isNotEmpty(caseConversion)) {
        ConversionType conversionType = (ConversionType) caseConversion.get("type");
        TextInputField.CaseConversion conversion = TextInputField.CaseConversion.valueOf(conversionType.name());
        component.setCaseConversion(conversion);
    }
}
Also used : ConversionType(com.haulmont.cuba.core.entity.annotation.ConversionType) MetaProperty(com.haulmont.chile.core.model.MetaProperty) TextInputField(com.haulmont.cuba.gui.components.TextInputField) Map(java.util.Map)

Example 2 with ConversionType

use of com.haulmont.cuba.core.entity.annotation.ConversionType in project cuba by cuba-platform.

the class AbstractTextFieldLoader method loadCaseConversion.

protected void loadCaseConversion(TextInputField.CaseConversionSupported component, Element element) {
    String caseConversion = element.attributeValue("caseConversion");
    if (StringUtils.isNotEmpty(caseConversion)) {
        component.setCaseConversion(TextInputField.CaseConversion.valueOf(caseConversion));
        return;
    }
    if (resultComponent.getMetaPropertyPath() != null) {
        Map<String, Object> annotations = resultComponent.getMetaPropertyPath().getMetaProperty().getAnnotations();
        // noinspection unchecked
        Map<String, Object> conversion = (Map<String, Object>) annotations.get(CaseConversion.class.getName());
        if (MapUtils.isNotEmpty(conversion)) {
            ConversionType conversionType = (ConversionType) conversion.get("type");
            TextInputField.CaseConversion tfCaseConversion = TextInputField.CaseConversion.valueOf(conversionType.name());
            component.setCaseConversion(tfCaseConversion);
        }
    }
}
Also used : ConversionType(com.haulmont.cuba.core.entity.annotation.ConversionType) TextInputField(com.haulmont.cuba.gui.components.TextInputField) Map(java.util.Map)

Example 3 with ConversionType

use of com.haulmont.cuba.core.entity.annotation.ConversionType in project cuba by cuba-platform.

the class WebAbstractTextField method setDatasource.

@Override
public void setDatasource(Datasource datasource, String property) {
    super.setDatasource(datasource, property);
    if (metaProperty != null) {
        Map<String, Object> annotations = metaProperty.getAnnotations();
        if (this instanceof CaseConversionSupported && ((CaseConversionSupported) this).getCaseConversion() == CaseConversion.NONE) {
            String caseConversionAnnotation = com.haulmont.cuba.core.entity.annotation.CaseConversion.class.getName();
            // noinspection unchecked
            Map<String, Object> caseConversion = (Map<String, Object>) annotations.get(caseConversionAnnotation);
            if (MapUtils.isNotEmpty(caseConversion)) {
                ConversionType conversionType = (ConversionType) caseConversion.get("type");
                CaseConversion conversion = CaseConversion.valueOf(conversionType.name());
                ((CaseConversionSupported) this).setCaseConversion(conversion);
            }
        }
        if (this instanceof TextInputField.MaxLengthLimited) {
            MaxLengthLimited maxLengthLimited = (MaxLengthLimited) this;
            Integer maxLength = (Integer) annotations.get("length");
            if (maxLength != null) {
                maxLengthLimited.setMaxLength(maxLength);
            }
            Integer sizeMax = (Integer) annotations.get(Size.class.getName() + "_max");
            if (sizeMax != null) {
                maxLengthLimited.setMaxLength(sizeMax);
            }
            Integer lengthMax = (Integer) annotations.get(Length.class.getName() + "_max");
            if (lengthMax != null) {
                maxLengthLimited.setMaxLength(lengthMax);
            }
        }
    }
}
Also used : Size(javax.validation.constraints.Size) ConversionType(com.haulmont.cuba.core.entity.annotation.ConversionType) Length(org.hibernate.validator.constraints.Length) Map(java.util.Map)

Aggregations

ConversionType (com.haulmont.cuba.core.entity.annotation.ConversionType)3 Map (java.util.Map)3 TextInputField (com.haulmont.cuba.gui.components.TextInputField)2 MetaProperty (com.haulmont.chile.core.model.MetaProperty)1 Size (javax.validation.constraints.Size)1 Length (org.hibernate.validator.constraints.Length)1