use of com.haulmont.cuba.gui.components.data.meta.EntityValueSource in project cuba by cuba-platform.
the class WebDateField 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.setupDateFormat(this, entityValueSource);
dataAwareComponentsTools.setupZoneId(this, entityValueSource);
if (valueSourceStateChangeSubscription != null) {
valueSourceStateChangeSubscription.remove();
}
// setup dateRange after valueSource is activated and value is set because
// Vaadin dateField rejects value if it is not in range
valueSourceStateChangeSubscription = valueSource.addStateChangeListener(event -> {
if (event.getState() == BindingState.ACTIVE) {
dataAwareComponentsTools.setupDateRange(this, entityValueSource);
}
});
}
}
use of com.haulmont.cuba.gui.components.data.meta.EntityValueSource in project cuba by cuba-platform.
the class WebDateField method constructModelValue.
@SuppressWarnings("unchecked")
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 com.haulmont.cuba.gui.components.data.meta.EntityValueSource in project cuba by cuba-platform.
the class WebTimeField method constructModelValue.
@SuppressWarnings("unchecked")
protected V constructModelValue() {
LocalTime timeValue = component.getValue();
if (timeValue == null) {
return null;
}
ValueSource<V> valueSource = getValueSource();
if (valueSource instanceof EntityValueSource) {
MetaProperty metaProperty = ((EntityValueSource) valueSource).getMetaPropertyPath().getMetaProperty();
return (V) convertFromLocalTime(timeValue, metaProperty.getRange().asDatatype().getJavaClass());
}
return (V) convertFromLocalTime(timeValue, datatype == null ? Date.class : datatype.getJavaClass());
}
use of com.haulmont.cuba.gui.components.data.meta.EntityValueSource in project cuba by cuba-platform.
the class WebCurrencyField 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");
}
use of com.haulmont.cuba.gui.components.data.meta.EntityValueSource in project cuba by cuba-platform.
the class WebCurrencyField method convertToPresentation.
@Override
protected String convertToPresentation(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));
}
Aggregations