use of de.metas.ui.web.window.descriptor.LookupDescriptor in project metasfresh-webui-api by metasfresh.
the class GridTabVOBasedDocumentEntityDescriptorFactory method createLabelsLookup.
private static final LabelsLookup createLabelsLookup(final I_AD_UI_Element labelsUIElement, final String tableName) {
final I_AD_Tab labelsTab = labelsUIElement.getLabels_Tab();
final String labelsTableName = labelsTab.getAD_Table().getTableName();
final String linkColumnName;
if (labelsTab.getParent_Column_ID() > 0) {
linkColumnName = labelsTab.getParent_Column().getColumnName();
} else {
linkColumnName = InterfaceWrapperHelper.getKeyColumnName(tableName);
}
final String labelsLinkColumnName;
if (labelsTab.getAD_Column_ID() > 0) {
labelsLinkColumnName = labelsTab.getAD_Column().getColumnName();
} else {
labelsLinkColumnName = linkColumnName;
}
final I_AD_Column labelsValueColumn = labelsUIElement.getLabels_Selector_Field().getAD_Column();
final String labelsValueColumnName = labelsValueColumn.getColumnName();
final LookupDescriptor labelsValuesLookupDescriptor = SqlLookupDescriptor.builder().setCtxTableName(labelsTableName).setCtxColumnName(labelsValueColumnName).setDisplayType(labelsValueColumn.getAD_Reference_ID()).setWidgetType(DescriptorsFactoryHelper.extractWidgetType(labelsValueColumnName, labelsValueColumn.getAD_Reference_ID())).setAD_Reference_Value_ID(labelsValueColumn.getAD_Reference_Value_ID()).setAD_Val_Rule_ID(labelsValueColumn.getAD_Val_Rule_ID()).buildForDefaultScope();
return LabelsLookup.builder().labelsTableName(labelsTableName).labelsValueColumnName(labelsValueColumnName).labelsValuesLookupDescriptor(labelsValuesLookupDescriptor).labelsLinkColumnName(labelsLinkColumnName).tableName(tableName).linkColumnName(linkColumnName).build();
}
use of de.metas.ui.web.window.descriptor.LookupDescriptor 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.LookupDescriptor in project metasfresh-webui-api by metasfresh.
the class WebuiProcessClassInfo method createParamLookupValuesProvider.
//
//
// ----
//
//
/**
* @return parameterName and provider
*/
private static Map.Entry<String, LookupDescriptorProvider> createParamLookupValuesProvider(final Method method) {
final ProcessParamLookupValuesProvider ann = method.getAnnotation(ProcessParamLookupValuesProvider.class);
if (!LookupValuesList.class.isAssignableFrom(method.getReturnType())) {
throw new AdempiereException("Method's return type shall be " + LookupValuesList.class + ": " + method);
}
final ImmutableList<Function<LookupDataSourceContext, Object>> parameterValueProviders = Stream.of(method.getParameterTypes()).map(parameterType -> {
final Function<LookupDataSourceContext, Object> parameterValueProvider;
if (LookupDataSourceContext.class.isAssignableFrom(parameterType)) {
parameterValueProvider = evalCtx -> evalCtx;
} else {
throw new AdempiereException("Parameter " + parameterType + " not supported for " + method);
}
return parameterValueProvider;
}).collect(ImmutableList.toImmutableList());
// FIXME: holding a hard reference to method may introduce ClassLoader memory leaks
final Method methodToInvoke = method;
final LookupDescriptor lookupDescriptor = ListLookupDescriptor.builder().setLookupTableName(ann.lookupTableName()).setDependsOnFieldNames(ann.dependsOn()).setLookupSourceType(ann.lookupSource()).setLookupValues(ann.numericKey(), evalCtx -> retriveLookupValues(methodToInvoke, parameterValueProviders, evalCtx)).build();
final LookupDescriptorProvider lookupDescriptorProvider = LookupDescriptorProvider.singleton(lookupDescriptor);
return GuavaCollectors.entry(ann.parameterName(), lookupDescriptorProvider);
}
use of de.metas.ui.web.window.descriptor.LookupDescriptor 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));
}
use of de.metas.ui.web.window.descriptor.LookupDescriptor in project metasfresh-webui-api by metasfresh.
the class UserQueryDocumentFilterDescriptorsProvider method createFilterDescriptor0.
private static final DocumentFilterDescriptor createFilterDescriptor0(@NonNull final IUserQuery userQuery) {
final DocumentFilterDescriptor.Builder filter = DocumentFilterDescriptor.builder().setFilterId("userquery-" + userQuery.getId()).setDisplayName(userQuery.getCaption()).setFrequentUsed(false);
if (WindowConstants.isProtocolDebugging()) {
filter.putDebugProperty("userQuery", userQuery.toString());
}
for (final IUserQueryRestriction queryRestriction : userQuery.getRestrictions()) {
final Join join = queryRestriction.getJoin();
final UserQueryField searchField = UserQueryField.cast(queryRestriction.getSearchField());
final String fieldName = searchField.getColumnName();
final Operator operator = MQueryDocumentFilterHelper.fromMQueryOperator(queryRestriction.getOperator());
final Object value = queryRestriction.getValue();
final Object valueTo = queryRestriction.getValueTo();
final boolean isParameter;
if (operator.isRangeOperator()) {
isParameter = value == null || valueTo == null;
} else {
isParameter = value == null;
}
if (isParameter) {
final ITranslatableString displayName = searchField.getDisplayName();
final DocumentFieldWidgetType widgetType = searchField.getWidgetType();
final LookupDescriptor lookupDescriptor = searchField.getLookupDescriptor();
filter.addParameter(DocumentFilterParamDescriptor.builder().setJoinAnd(join == Join.AND).setDisplayName(displayName).setFieldName(fieldName).setWidgetType(widgetType).setOperator(operator).setDefaultValue(value).setDefaultValueTo(valueTo).setMandatory(// mandatory if there is no default value
value == null).setLookupDescriptor(lookupDescriptor));
} else {
filter.addInternalParameter(DocumentFilterParam.builder().setJoinAnd(join == Join.AND).setFieldName(fieldName).setOperator(operator).setValue(value).setValueTo(valueTo).build());
}
}
return filter.build();
}
Aggregations