use of io.jmix.ui.component.data.meta.EntityValueSource in project jmix by jmix-framework.
the class AbstractSelectList method valueBindingConnected.
@Override
protected void valueBindingConnected(ValueSource<V> valueSource) {
super.valueBindingConnected(valueSource);
if (valueSource instanceof EntityValueSource) {
DataAwareComponentsTools dataAwareComponentsTools = applicationContext.getBean(DataAwareComponentsTools.class);
dataAwareComponentsTools.setupOptions(this, (EntityValueSource) valueSource);
}
}
use of io.jmix.ui.component.data.meta.EntityValueSource in project jmix by jmix-framework.
the class GuiActionSupport method createActionsByMetaAnnotations.
public boolean createActionsByMetaAnnotations(PickerField pickerField) {
ValueSource valueSource = pickerField.getValueSource();
if (!(valueSource instanceof EntityValueSource)) {
return false;
}
EntityValueSource entityValueSource = (EntityValueSource) pickerField.getValueSource();
MetaPropertyPath mpp = entityValueSource.getMetaPropertyPath();
if (mpp == null) {
return false;
}
String[] actionIds = (String[]) metadataTools.getMetaAnnotationAttributes(mpp.getMetaProperty().getAnnotations(), Lookup.class).get("actions");
if (actionIds != null && actionIds.length > 0) {
for (String actionId : actionIds) {
createActionById(pickerField, actionId);
}
return true;
}
return false;
}
use of io.jmix.ui.component.data.meta.EntityValueSource in project jmix by jmix-framework.
the class MaskedFieldImpl method convertToPresentation.
@Override
protected String convertToPresentation(@Nullable 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();
Range range = entityValueSource.getMetaPropertyPath().getRange();
if (range.isDatatype()) {
Datatype<V> propertyDataType = range.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 MaskedFieldImpl method convertToModel.
@Nullable
@Override
protected V convertToModel(@Nullable String componentRawValue) throws ConversionException {
String value = emptyToNull(componentRawValue);
if (datatype != null) {
try {
return datatype.parse(value, locale);
} catch (ValueConversionException e) {
throw new ConversionException(e.getLocalizedMessage(), e);
} catch (ParseException e) {
throw new ConversionException(getConversionErrorMessage(), 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(getConversionErrorMessage(), e);
}
}
return super.convertToModel(value);
}
use of io.jmix.ui.component.data.meta.EntityValueSource in project jmix by jmix-framework.
the class TextFieldImpl method convertToPresentation.
@SuppressWarnings("unchecked")
@Override
protected String convertToPresentation(@Nullable 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 = applicationContext.getBean(MetadataTools.class);
if (range.getCardinality().isMany()) {
return ((Collection<Object>) modelValue).stream().map(metadataTools::getInstanceName).collect(Collectors.joining(", "));
} else {
return metadataTools.getInstanceName(modelValue);
}
} else if (range.isEnum()) {
Messages messages = applicationContext.getBean(Messages.class);
return messages.getMessage((Enum) modelValue);
}
}
}
return nullToEmpty(super.convertToPresentation(modelValue));
}
Aggregations