use of de.metas.ui.web.window.descriptor.DocumentFieldWidgetType in project metasfresh-webui-api by metasfresh.
the class DocumentField method convertToValueClass.
private Object convertToValueClass(final Object value) {
final DocumentFieldWidgetType widgetType = getWidgetType();
final Class<?> targetType = descriptor.getValueClass();
return convertToValueClass(value, widgetType, targetType);
}
use of de.metas.ui.web.window.descriptor.DocumentFieldWidgetType in project metasfresh-webui-api by metasfresh.
the class DocumentField method getValueAs.
@Override
public <T> T getValueAs(final Class<T> returnType) {
Preconditions.checkNotNull(returnType, "returnType shall not be null");
// N/A
final DocumentFieldWidgetType widgetType = null;
final T value = convertToValueClass(_value, widgetType, returnType);
return value;
}
use of de.metas.ui.web.window.descriptor.DocumentFieldWidgetType in project metasfresh-webui-api by metasfresh.
the class GenericDocumentSummaryValueProvider method createFieldValueExtractorFromLookupDisplayColumn.
private static final FieldValueExtractor createFieldValueExtractorFromLookupDisplayColumn(final ILookupDisplayColumn lookupDisplayColumn, final DocumentEntityDescriptor.Builder entityDescriptor) {
final String fieldName = lookupDisplayColumn.getColumnName();
final DocumentFieldDescriptor.Builder field = entityDescriptor.getFieldBuilder(fieldName);
if (field == null) {
return null;
}
final DocumentFieldWidgetType widgetType = field.getWidgetType();
if (widgetType.isDateOrTime()) {
return new DateFieldValueExtractor(fieldName, widgetType);
} else if (widgetType.isNumeric()) {
return new NumericFieldValueExtractor(fieldName, widgetType, lookupDisplayColumn.getFormatPattern());
}
return new GenericFieldValueExtractor(fieldName);
}
use of de.metas.ui.web.window.descriptor.DocumentFieldWidgetType in project metasfresh-webui-api by metasfresh.
the class BoardDescriptorRepository method createBoardCardFieldDescriptor.
private final BoardCardFieldDescriptor createBoardCardFieldDescriptor(final I_WEBUI_Board_CardField cardFieldPO, final DocumentEntityDescriptor documentEntityDescriptor) {
// TODO: might be not so performant, we just need the ColumnName
final String fieldName = cardFieldPO.getAD_Column().getColumnName();
final DocumentFieldDescriptor documentField = documentEntityDescriptor.getField(fieldName);
final SqlDocumentFieldDataBindingDescriptor fieldBinding = documentField.getDataBindingNotNull(SqlDocumentFieldDataBindingDescriptor.class);
final DocumentFieldWidgetType widgetType = documentField.getWidgetType();
final boolean isDisplayColumnAvailable = fieldBinding.isUsingDisplayColumn();
final ImmutableSet<String> sqlSelectValues;
final BoardFieldLoader fieldLoader;
if (widgetType == DocumentFieldWidgetType.Amount && documentEntityDescriptor.hasField(WindowConstants.FIELDNAME_C_Currency_ID)) {
sqlSelectValues = ImmutableSet.of(fieldBinding.getSqlSelectValue(), WindowConstants.FIELDNAME_C_Currency_ID);
fieldLoader = (rs, adLanguage) -> {
final BigDecimal valueBD = rs.getBigDecimal(fieldBinding.getColumnName());
if (valueBD == null) {
return null;
}
final int currencyId = rs.getInt(WindowConstants.FIELDNAME_C_Currency_ID);
final String currencyCode = Services.get(ICurrencyDAO.class).getISO_Code(Env.getCtx(), currencyId);
if (currencyCode == null) {
return valueBD;
}
return Amount.of(valueBD, currencyCode);
};
} else {
sqlSelectValues = ImmutableSet.of(fieldBinding.getSqlSelectValue());
final DocumentFieldValueLoader documentFieldValueLoader = fieldBinding.getDocumentFieldValueLoader();
final LookupDescriptor lookupDescriptor = documentField.getLookupDescriptor(LookupScope.DocumentField);
fieldLoader = (rs, adLanguage) -> documentFieldValueLoader.retrieveFieldValue(rs, isDisplayColumnAvailable, adLanguage, lookupDescriptor);
}
return BoardCardFieldDescriptor.builder().caption(documentField.getCaption()).fieldName(fieldBinding.getColumnName()).widgetType(widgetType).sqlSelectValues(sqlSelectValues).usingDisplayColumn(isDisplayColumnAvailable).sqlSelectDisplayValue(fieldBinding.getSqlSelectDisplayValue()).sqlOrderBy(fieldBinding.getSqlOrderBy()).fieldLoader(fieldLoader).build();
}
use of de.metas.ui.web.window.descriptor.DocumentFieldWidgetType in project metasfresh-webui-api by metasfresh.
the class ASIDescriptorFactory method createDocumentFieldDescriptor.
private DocumentFieldDescriptor.Builder createDocumentFieldDescriptor(final I_M_Attribute attribute) {
final int attributeId = attribute.getM_Attribute_ID();
final String fieldName = attribute.getValue();
final String attributeValueType = attribute.getAttributeValueType();
final Class<?> valueClass;
final DocumentFieldWidgetType widgetType;
final Function<I_M_AttributeInstance, Object> readMethod;
final BiConsumer<I_M_AttributeInstance, IDocumentFieldView> writeMethod;
LookupDescriptor lookupDescriptor = null;
if (X_M_Attribute.ATTRIBUTEVALUETYPE_Date.equals(attributeValueType)) {
valueClass = java.util.Date.class;
widgetType = DocumentFieldWidgetType.Date;
readMethod = I_M_AttributeInstance::getValueDate;
writeMethod = (aiRecord, field) -> aiRecord.setValueDate(TimeUtil.asTimestamp(field.getValueAs(java.util.Date.class)));
} else if (X_M_Attribute.ATTRIBUTEVALUETYPE_List.equals(attributeValueType)) {
valueClass = StringLookupValue.class;
widgetType = DocumentFieldWidgetType.List;
readMethod = I_M_AttributeInstance::getValue;
writeMethod = ASIAttributeFieldBinding::writeValueFromLookup;
lookupDescriptor = getLookupDescriptor(attribute);
} else if (X_M_Attribute.ATTRIBUTEVALUETYPE_Number.equals(attributeValueType)) {
valueClass = BigDecimal.class;
widgetType = DocumentFieldWidgetType.Number;
readMethod = I_M_AttributeInstance::getValueNumber;
writeMethod = (aiRecord, field) -> aiRecord.setValueNumber(field.getValueAs(BigDecimal.class));
} else if (X_M_Attribute.ATTRIBUTEVALUETYPE_StringMax40.equals(attributeValueType)) {
valueClass = String.class;
widgetType = DocumentFieldWidgetType.Text;
readMethod = I_M_AttributeInstance::getValue;
writeMethod = (aiRecord, field) -> aiRecord.setValue(field.getValueAs(String.class));
} else {
throw new IllegalArgumentException("@NotSupported@ @AttributeValueType@=" + attributeValueType + ", @M_Attribute_ID@=" + attribute);
}
final ILogicExpression readonlyLogic = ConstantLogicExpression.FALSE;
final ILogicExpression displayLogic = ConstantLogicExpression.TRUE;
final ILogicExpression mandatoryLogic = ConstantLogicExpression.of(attribute.isMandatory());
final Optional<IExpression<?>> defaultValueExpr = Optional.empty();
return DocumentFieldDescriptor.builder(fieldName).setCaption(attribute.getName()).setDescription(attribute.getDescription()).setValueClass(valueClass).setWidgetType(widgetType).setLookupDescriptorProvider(lookupDescriptor).setDefaultValueExpression(defaultValueExpr).setReadonlyLogic(readonlyLogic).setDisplayLogic(displayLogic).setMandatoryLogic(mandatoryLogic).addCharacteristic(Characteristic.PublicField).setDataBinding(new ASIAttributeFieldBinding(attributeId, fieldName, attribute.isMandatory(), readMethod, writeMethod));
}
Aggregations