use of com.haulmont.cuba.gui.components.data.meta.EntityValueSource in project cuba by cuba-platform.
the class WebCurrencyField method valueBindingConnected.
@Override
protected void valueBindingConnected(ValueSource<V> valueSource) {
super.valueBindingConnected(valueSource);
if (valueSource instanceof EntityValueSource) {
MetaPropertyPath metaPropertyPath = ((EntityValueSource) valueSource).getMetaPropertyPath();
if (metaPropertyPath.getRange().isDatatype()) {
Datatype datatype = metaPropertyPath.getRange().asDatatype();
if (!Number.class.isAssignableFrom(datatype.getJavaClass())) {
throw new IllegalArgumentException("CurrencyField doesn't support Datatype with class: " + datatype.getJavaClass());
}
} else {
throw new IllegalArgumentException("CurrencyField doesn't support properties with association");
}
MetaProperty metaProperty = metaPropertyPath.getMetaProperty();
Object annotation = metaProperty.getAnnotations().get(CurrencyValue.class.getName());
if (annotation == null) {
return;
}
// noinspection unchecked
Map<String, Object> annotationProperties = (Map<String, Object>) annotation;
String currencyName = (String) annotationProperties.get("currency");
component.setCurrency(currencyName);
String labelPosition = ((com.haulmont.cuba.core.entity.annotation.CurrencyLabelPosition) annotationProperties.get("labelPosition")).name();
setCurrencyLabelPosition(CurrencyLabelPosition.valueOf(labelPosition));
}
}
use of com.haulmont.cuba.gui.components.data.meta.EntityValueSource in project cuba by cuba-platform.
the class WebCurrencyField method convertToModel.
@Override
protected V convertToModel(String componentRawValue) throws ConversionException {
String value = StringUtils.trimToNull(emptyToNull(componentRawValue));
Datatype<V> datatype = getDatatypeInternal();
if (datatype != null) {
try {
return datatype.parse(value, locale);
} catch (ValueConversionException e) {
throw new ConversionException(e.getLocalizedMessage(), e);
} catch (ParseException e) {
throw new ConversionException(getConversionErrorMessageInternal(), e);
}
}
if (valueBinding != null && valueBinding.getSource() instanceof EntityValueSource) {
EntityValueSource entityValueSource = (EntityValueSource) valueBinding.getSource();
Datatype<V> propertyDataType = entityValueSource.getMetaPropertyPath().getRange().asDatatype();
try {
return propertyDataType.parse(componentRawValue, locale);
} catch (ValueConversionException e) {
throw new ConversionException(e.getLocalizedMessage(), e);
} catch (ParseException e) {
throw new ConversionException(getConversionErrorMessageInternal(), e);
}
}
return super.convertToModel(componentRawValue);
}
use of com.haulmont.cuba.gui.components.data.meta.EntityValueSource in project cuba by cuba-platform.
the class WebDatePicker method convertToModel.
@SuppressWarnings("unchecked")
@Override
protected V convertToModel(LocalDate componentRawValue) throws ConversionException {
if (componentRawValue == null) {
return null;
}
LocalDateTime localDateTime = LocalDateTime.of(componentRawValue, LocalTime.MIDNIGHT);
ValueSource<V> valueSource = getValueSource();
if (valueSource instanceof EntityValueSource) {
MetaProperty metaProperty = ((EntityValueSource) valueSource).getMetaPropertyPath().getMetaProperty();
return (V) convertFromLocalDateTime(localDateTime, metaProperty.getRange().asDatatype().getJavaClass());
}
return (V) convertFromLocalDateTime(localDateTime, datatype == null ? Date.class : datatype.getJavaClass());
}
use of com.haulmont.cuba.gui.components.data.meta.EntityValueSource in project cuba by cuba-platform.
the class WebDatePicker method valueBindingConnected.
@Override
protected void valueBindingConnected(ValueSource<V> valueSource) {
super.valueBindingConnected(valueSource);
if (valueSource instanceof EntityValueSource) {
EntityValueSource entityValueSource = (EntityValueSource) valueSource;
DataAwareComponentsTools dataAwareComponentsTools = beanLocator.get(DataAwareComponentsTools.class);
dataAwareComponentsTools.setupDateRange(this, entityValueSource);
}
}
use of com.haulmont.cuba.gui.components.data.meta.EntityValueSource in project cuba by cuba-platform.
the class WebAbstractTextArea method getConversionErrorMessageInternal.
protected String getConversionErrorMessageInternal() {
String customErrorMessage = getConversionErrorMessage();
if (StringUtils.isNotEmpty(customErrorMessage)) {
return customErrorMessage;
}
Datatype<V> datatype = this.datatype;
if (datatype == null && valueBinding != null && valueBinding.getSource() instanceof EntityValueSource) {
EntityValueSource entityValueSource = (EntityValueSource) valueBinding.getSource();
datatype = entityValueSource.getMetaPropertyPath().getRange().asDatatype();
}
if (datatype != null) {
String msg = getDatatypeConversionErrorMsg(datatype);
if (StringUtils.isNotEmpty(msg)) {
return msg;
}
}
return beanLocator.get(Messages.class).getMainMessage("databinding.conversion.error");
}
Aggregations