use of io.jmix.ui.component.data.meta.EntityValueSource in project jmix by jmix-framework.
the class CurrencyFieldImpl 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 = ((io.jmix.core.entity.annotation.CurrencyLabelPosition) annotationProperties.get("labelPosition")).name();
setCurrencyLabelPosition(CurrencyLabelPosition.valueOf(labelPosition));
}
}
use of io.jmix.ui.component.data.meta.EntityValueSource in project jmix by jmix-framework.
the class CurrencyFieldImpl 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 applicationContext.getBean(Messages.class).getMessage("databinding.conversion.error");
}
use of io.jmix.ui.component.data.meta.EntityValueSource in project jmix by jmix-framework.
the class CurrencyFieldImpl method convertToPresentation.
@Override
protected String convertToPresentation(@Nullable V modelValue) throws ConversionException {
Datatype<V> datatype = getDatatypeInternal();
// Vaadin TextField does not permit `null` value
if (datatype != null) {
return nullToEmpty(datatype.format(modelValue, locale));
}
if (valueBinding != null && valueBinding.getSource() instanceof EntityValueSource) {
EntityValueSource entityValueSource = (EntityValueSource) valueBinding.getSource();
Datatype<V> propertyDataType = entityValueSource.getMetaPropertyPath().getRange().asDatatype();
return nullToEmpty(propertyDataType.format(modelValue, locale));
}
return nullToEmpty(super.convertToPresentation(modelValue));
}
use of io.jmix.ui.component.data.meta.EntityValueSource in project jmix by jmix-framework.
the class DateFieldImpl method constructModelValue.
@SuppressWarnings("unchecked")
@Nullable
protected V constructModelValue() {
LocalDate dateValue = dateField.getValue();
if (dateValue == null) {
return null;
}
LocalTime timeValue = timeField.getValue() != null ? timeField.getValue() : LocalTime.MIDNIGHT;
LocalDateTime localDateTime = LocalDateTime.of(dateValue, timeValue);
ValueSource<V> valueSource = getValueSource();
if (valueSource instanceof EntityValueSource) {
MetaProperty metaProperty = ((EntityValueSource) valueSource).getMetaPropertyPath().getMetaProperty();
return (V) convertFromLocalDateTime(localDateTime, zoneId, metaProperty.getRange().asDatatype().getJavaClass());
}
return (V) convertFromLocalDateTime(localDateTime, zoneId, datatype == null ? Date.class : datatype.getJavaClass());
}
use of io.jmix.ui.component.data.meta.EntityValueSource in project jmix by jmix-framework.
the class DatePickerImpl method valueBindingConnected.
@Override
protected void valueBindingConnected(ValueSource<V> valueSource) {
super.valueBindingConnected(valueSource);
if (valueSource instanceof EntityValueSource) {
EntityValueSource entityValueSource = (EntityValueSource) valueSource;
DataAwareComponentsTools dataAwareComponentsTools = applicationContext.getBean(DataAwareComponentsTools.class);
dataAwareComponentsTools.setupDateRange(this, entityValueSource);
}
}
Aggregations