use of com.haulmont.cuba.gui.components.data.meta.EntityValueSource in project cuba by cuba-platform.
the class WebAbstractTextArea method convertToModel.
@Override
protected V convertToModel(String componentRawValue) throws ConversionException {
String value = emptyToNull(componentRawValue);
if (isTrimming()) {
value = StringUtils.trimToNull(value);
}
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(value, locale);
} catch (ValueConversionException e) {
throw new ConversionException(e.getLocalizedMessage(), e);
} catch (ParseException e) {
throw new ConversionException(getConversionErrorMessageInternal(), e);
}
}
return super.convertToModel(value);
}
use of com.haulmont.cuba.gui.components.data.meta.EntityValueSource in project cuba by cuba-platform.
the class WebAbstractTextArea method convertToPresentation.
@Override
protected String convertToPresentation(V modelValue) throws ConversionException {
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));
}
return nullToEmpty(super.convertToPresentation(modelValue));
}
use of com.haulmont.cuba.gui.components.data.meta.EntityValueSource in project cuba by cuba-platform.
the class WebCheckBoxGroup method valueBindingConnected.
@Override
protected void valueBindingConnected(ValueSource<Collection<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 EditorBuilderProcessor method initEntity.
protected <E extends Entity> E initEntity(EditorBuilder<E> builder, CollectionContainer<E> container) {
E entity;
boolean oneToOneComposition = false;
EntityValueSource entityValueSource = null;
HasValue<E> field = builder.getField();
if (field instanceof HasValueSource) {
ValueSource valueSource = ((HasValueSource) field).getValueSource();
if (valueSource instanceof EntityValueSource) {
entityValueSource = (EntityValueSource) valueSource;
oneToOneComposition = isCompositionProperty(entityValueSource);
}
}
if (builder.getMode() == EditMode.CREATE || (oneToOneComposition && field.getValue() == null)) {
if (builder.getNewEntity() == null) {
entity = metadata.create(builder.getEntityClass());
} else {
entity = builder.getNewEntity();
}
if (container instanceof Nested) {
initializeNestedEntity(entity, (Nested) container);
}
if (oneToOneComposition) {
Entity ownerEntity = entityValueSource.getItem();
MetaProperty inverseProp = entityValueSource.getMetaPropertyPath().getMetaProperty().getInverse();
if (inverseProp != null) {
entity.setValue(inverseProp.getName(), ownerEntity);
}
}
if (builder.getInitializer() != null) {
builder.getInitializer().accept(entity);
}
} else {
entity = builder.getEditedEntity();
}
return entity;
}
use of com.haulmont.cuba.gui.components.data.meta.EntityValueSource in project cuba by cuba-platform.
the class FormLoader method loadComponent.
protected ComponentPosition loadComponent(Element element, @Nullable String columnWidth, @Nullable Float flex) {
Component component;
if ("field".equals(element.getName())) {
component = loadField(element);
} else {
LayoutLoader loader = getLayoutLoader();
ComponentLoader childComponentLoader = loader.createComponent(element);
childComponentLoader.loadComponent();
component = childComponentLoader.getResultComponent();
}
// Set default width
String componentWidth = element.attributeValue("width");
if (Strings.isNullOrEmpty(componentWidth)) {
if (columnWidth != null) {
component.setWidth(columnWidth);
} else if (flex != null) {
component.setWidthFull();
}
}
// Set default caption
if (component instanceof HasValueSource && ((HasValueSource) component).getValueSource() instanceof EntityValueSource && component instanceof Component.HasCaption && ((Component.HasCaption) component).getCaption() == null) {
EntityValueSource valueSource = ((EntityValueSource) ((HasValueSource) component).getValueSource());
MetaPropertyPath metaPropertyPath = valueSource.getMetaPropertyPath();
String propertyName = metaPropertyPath != null ? metaPropertyPath.getMetaProperty().getName() : null;
if (metaPropertyPath != null) {
if (isDynamicAttribute(metaPropertyPath.getMetaProperty())) {
CategoryAttribute categoryAttribute = getCategoryAttribute(metaPropertyPath.getMetaProperty());
((Component.HasCaption) component).setCaption(categoryAttribute != null ? categoryAttribute.getLocaleName() : propertyName);
((Component.HasCaption) component).setDescription(categoryAttribute != null ? categoryAttribute.getLocaleDescription() : null);
} else {
MetaClass propertyMetaClass = getMetadataTools().getPropertyEnclosingMetaClass(metaPropertyPath);
String propertyCaption = getMessageTools().getPropertyCaption(propertyMetaClass, propertyName);
((Component.HasCaption) component).setCaption(propertyCaption);
}
}
}
int colspan = loadSpan(element, "colspan");
int rowspan = loadSpan(element, "rowspan");
return new ComponentPosition(component, colspan, rowspan);
}
Aggregations