use of com.haulmont.cuba.gui.components.data.meta.EntityValueSource in project cuba by cuba-platform.
the class WebTextField method convertToPresentation.
@SuppressWarnings("unchecked")
@Override
protected String convertToPresentation(V modelValue) throws ConversionException {
if (formatter != null) {
return nullToEmpty(formatter.apply(modelValue));
}
if (datatype != null) {
return nullToEmpty(datatype.format(modelValue, locale));
}
if (valueBinding != null && valueBinding.getSource() instanceof EntityValueSource) {
EntityValueSource entityValueSource = (EntityValueSource) valueBinding.getSource();
Range range = entityValueSource.getMetaPropertyPath().getRange();
if (range.isDatatype()) {
Datatype<V> propertyDataType = range.asDatatype();
return nullToEmpty(propertyDataType.format(modelValue, locale));
} else {
setEditable(false);
if (modelValue == null)
return "";
if (range.isClass()) {
MetadataTools metadataTools = beanLocator.get(MetadataTools.class);
if (range.getCardinality().isMany()) {
return ((Collection<Entity>) modelValue).stream().map(metadataTools::getInstanceName).collect(Collectors.joining(", "));
} else {
return metadataTools.getInstanceName((Entity) modelValue);
}
} else if (range.isEnum()) {
Messages messages = beanLocator.get(Messages.class);
return messages.getMessage((Enum) modelValue);
}
}
}
return nullToEmpty(super.convertToPresentation(modelValue));
}
use of com.haulmont.cuba.gui.components.data.meta.EntityValueSource in project cuba by cuba-platform.
the class WebTextField method valueBindingConnected.
@Override
protected void valueBindingConnected(ValueSource<V> valueSource) {
super.valueBindingConnected(valueSource);
if (valueSource instanceof EntityValueSource) {
DataAwareComponentsTools dataAwareComponentsTools = beanLocator.get(DataAwareComponentsTools.class);
EntityValueSource entityValueSource = (EntityValueSource) valueSource;
dataAwareComponentsTools.setupCaseConversion(this, entityValueSource);
dataAwareComponentsTools.setupMaxLength(this, entityValueSource);
}
}
use of com.haulmont.cuba.gui.components.data.meta.EntityValueSource in project cuba by cuba-platform.
the class WebTextField 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 WebLookupField method valueBindingConnected.
@Override
protected void valueBindingConnected(ValueSource<V> valueSource) {
super.valueBindingConnected(valueSource);
if (valueSource instanceof EntityValueSource) {
DataAwareComponentsTools dataAwareComponentsTools = beanLocator.get(DataAwareComponentsTools.class);
dataAwareComponentsTools.setupOptions(this, (EntityValueSource) valueSource);
}
}
use of com.haulmont.cuba.gui.components.data.meta.EntityValueSource in project cuba by cuba-platform.
the class WebOptionsList method valueBindingConnected.
@SuppressWarnings("unchecked")
@Override
protected void valueBindingConnected(ValueSource<V> valueSource) {
super.valueBindingConnected(valueSource);
if (valueSource instanceof EntityValueSource) {
DataAwareComponentsTools dataAwareComponentsTools = beanLocator.get(DataAwareComponentsTools.class);
dataAwareComponentsTools.setupOptions(this, (EntityValueSource) valueSource);
}
}
Aggregations