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);
}
}
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);
}
}
}
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);
}
}
}
}
Aggregations