Search in sources :

Example 1 with IExpression

use of org.adempiere.ad.expression.api.IExpression in project metasfresh-webui-api by metasfresh.

the class GridTabVOBasedDocumentEntityDescriptorFactory method createAndAddDocumentField.

private final void createAndAddDocumentField(final DocumentEntityDescriptor.Builder entityDescriptor, final GridFieldVO gridFieldVO, final boolean keyColumn) {
    // From entry data-binding:
    final SqlDocumentEntityDataBindingDescriptor.Builder entityBindings = entityDescriptor.getDataBindingBuilder(SqlDocumentEntityDataBindingDescriptor.Builder.class);
    // From GridFieldVO:
    final String fieldName = gridFieldVO.getColumnName();
    final String sqlColumnName = fieldName;
    // 
    final boolean isParentLinkColumn = sqlColumnName.equals(entityBindings.getSqlParentLinkColumnName());
    // 
    // 
    DocumentFieldWidgetType widgetType;
    final Class<?> valueClass;
    final Optional<IExpression<?>> defaultValueExpression;
    final boolean alwaysUpdateable;
    final LookupDescriptorProvider lookupDescriptorProvider;
    final LookupDescriptor lookupDescriptor;
    ILogicExpression readonlyLogic;
    if (isParentLinkColumn) {
        widgetType = DocumentFieldWidgetType.Integer;
        valueClass = widgetType.getValueClass();
        alwaysUpdateable = false;
        lookupDescriptorProvider = LookupDescriptorProvider.NULL;
        lookupDescriptor = null;
        defaultValueExpression = Optional.empty();
        readonlyLogic = ConstantLogicExpression.TRUE;
    } else {
        final int displayType = gridFieldVO.getDisplayType();
        widgetType = DescriptorsFactoryHelper.extractWidgetType(sqlColumnName, displayType);
        alwaysUpdateable = extractAlwaysUpdateable(gridFieldVO);
        final String ctxTableName = Services.get(IADTableDAO.class).retrieveTableName(gridFieldVO.getAD_Table_ID());
        lookupDescriptorProvider = SqlLookupDescriptor.builder().setCtxTableName(ctxTableName).setCtxColumnName(sqlColumnName).setWidgetType(widgetType).setDisplayType(displayType).setAD_Reference_Value_ID(gridFieldVO.getAD_Reference_Value_ID()).setAD_Val_Rule_ID(gridFieldVO.getAD_Val_Rule_ID()).buildProvider();
        lookupDescriptor = lookupDescriptorProvider.provideForScope(LookupDescriptorProvider.LookupScope.DocumentField);
        valueClass = DescriptorsFactoryHelper.getValueClass(widgetType, lookupDescriptor);
        defaultValueExpression = defaultValueExpressionsFactory.extractDefaultValueExpression(gridFieldVO.getDefaultValue(), fieldName, widgetType, valueClass, gridFieldVO.isMandatory(), gridFieldVO.isUseDocSequence());
        if (keyColumn) {
            readonlyLogic = ConstantLogicExpression.TRUE;
        } else if (gridFieldVO.isReadOnly()) {
            readonlyLogic = ConstantLogicExpression.TRUE;
        } else // and we want to allow the user setting it.
        if (!gridFieldVO.isUpdateable() && !gridFieldVO.isParentLink()) {
            readonlyLogic = ConstantLogicExpression.FALSE;
        } else {
            readonlyLogic = gridFieldVO.getReadOnlyLogic();
        }
    }
    // 
    // Button action
    final ButtonFieldActionDescriptor buttonAction;
    if (!isParentLinkColumn && widgetType.isButton()) {
        buttonAction = extractButtonFieldActionDescriptor(entityDescriptor.getTableNameOrNull(), fieldName, gridFieldVO.AD_Process_ID);
        if (buttonAction != null) {
            final ButtonFieldActionType actionType = buttonAction.getActionType();
            if (actionType == ButtonFieldActionType.processCall) {
                widgetType = DocumentFieldWidgetType.ProcessButton;
            } else if (actionType == ButtonFieldActionType.genericZoomInto) {
                widgetType = DocumentFieldWidgetType.ZoomIntoButton;
                // allow pressing the button
                readonlyLogic = ConstantLogicExpression.FALSE;
            }
        }
    } else {
        buttonAction = null;
    }
    // 
    // ORDER BY SortNo
    int orderBySortNo = gridFieldVO.getSortNo();
    if (orderBySortNo == 0 && keyColumn) {
        orderBySortNo = Integer.MAX_VALUE;
    }
    final String sqlColumnSql = gridFieldVO.getColumnSQL(false);
    final SqlDocumentFieldDataBindingDescriptor fieldBinding = SqlDocumentFieldDataBindingDescriptor.builder().setFieldName(sqlColumnName).setTableName(entityBindings.getTableName()).setTableAlias(entityBindings.getTableAlias()).setColumnName(sqlColumnName).setColumnSql(sqlColumnSql).setVirtualColumn(gridFieldVO.isVirtualColumn()).setMandatory(gridFieldVO.isMandatoryDB()).setWidgetType(widgetType).setValueClass(valueClass).setSqlValueClass(entityBindings.getPOInfo().getColumnClass(sqlColumnName)).setLookupDescriptor(lookupDescriptor).setKeyColumn(keyColumn).setEncrypted(gridFieldVO.isEncryptedColumn()).setDefaultOrderBy(orderBySortNo).build();
    final DocumentFieldDescriptor.Builder fieldBuilder = DocumentFieldDescriptor.builder(sqlColumnName).setCaption(gridFieldVO.getHeaderTrls(), gridFieldVO.getHeader()).setDescription(gridFieldVO.getDescriptionTrls(), gridFieldVO.getDescription()).setKey(keyColumn).setParentLink(isParentLinkColumn).setWidgetType(widgetType).setButtonActionDescriptor(buttonAction).setLookupDescriptorProvider(lookupDescriptorProvider).setValueClass(fieldBinding.getValueClass()).setVirtualField(fieldBinding.isVirtualColumn()).setCalculated(gridFieldVO.isCalculated()).setDefaultValueExpression(defaultValueExpression).addCharacteristicIfTrue(keyColumn, Characteristic.SideListField).addCharacteristicIfTrue(keyColumn, Characteristic.GridViewField).setReadonlyLogic(readonlyLogic).setAlwaysUpdateable(alwaysUpdateable).setMandatoryLogic(extractMandatoryLogic(gridFieldVO)).setDisplayLogic(gridFieldVO.getDisplayLogic()).setDefaultFilterInfo(createDefaultFilterDescriptor(gridFieldVO.getDefaultFilterDescriptor(), sqlColumnName, widgetType)).setDataBinding(fieldBinding);
    // 
    // Add Field builder to document entity
    entityDescriptor.addField(fieldBuilder);
    // 
    // Add Field's data binding to entity data binding
    entityBindings.addField(fieldBinding);
    // 
    // Collect special field
    collectSpecialField(fieldBuilder);
}
Also used : SqlDocumentEntityDataBindingDescriptor(de.metas.ui.web.window.descriptor.sql.SqlDocumentEntityDataBindingDescriptor) IExpression(org.adempiere.ad.expression.api.IExpression) LookupDescriptorProvider(de.metas.ui.web.window.descriptor.LookupDescriptorProvider) ButtonFieldActionDescriptor(de.metas.ui.web.window.descriptor.ButtonFieldActionDescriptor) SqlDocumentFieldDataBindingDescriptor(de.metas.ui.web.window.descriptor.sql.SqlDocumentFieldDataBindingDescriptor) DocumentFieldDescriptor(de.metas.ui.web.window.descriptor.DocumentFieldDescriptor) ILogicExpression(org.adempiere.ad.expression.api.ILogicExpression) ButtonFieldActionType(de.metas.ui.web.window.descriptor.ButtonFieldActionDescriptor.ButtonFieldActionType) DocumentFieldWidgetType(de.metas.ui.web.window.descriptor.DocumentFieldWidgetType) IADTableDAO(org.adempiere.ad.table.api.IADTableDAO) SqlLookupDescriptor(de.metas.ui.web.window.descriptor.sql.SqlLookupDescriptor) LookupDescriptor(de.metas.ui.web.window.descriptor.LookupDescriptor)

Example 2 with IExpression

use of org.adempiere.ad.expression.api.IExpression in project metasfresh-webui-api by metasfresh.

the class ADProcessDescriptorsFactory method createProcessParaDescriptor.

private DocumentFieldDescriptor.Builder createProcessParaDescriptor(final WebuiProcessClassInfo webuiProcesClassInfo, final I_AD_Process_Para adProcessParam) {
    final IModelTranslationMap adProcessParaTrlsMap = InterfaceWrapperHelper.getModelTranslationMap(adProcessParam);
    final String parameterName = adProcessParam.getColumnName();
    // 
    // Ask the provider if it has some custom lookup descriptor
    LookupDescriptorProvider lookupDescriptorProvider = webuiProcesClassInfo.getLookupDescriptorProviderOrNull(parameterName);
    // Fallback: create an SQL lookup descriptor based on adProcessParam
    if (lookupDescriptorProvider == null) {
        lookupDescriptorProvider = SqlLookupDescriptor.builder().setCtxTableName(null).setCtxColumnName(parameterName).setDisplayType(adProcessParam.getAD_Reference_ID()).setAD_Reference_Value_ID(adProcessParam.getAD_Reference_Value_ID()).setAD_Val_Rule_ID(adProcessParam.getAD_Val_Rule_ID()).setReadOnlyAccess().buildProvider();
    }
    // 
    final LookupDescriptor lookupDescriptor = lookupDescriptorProvider.provideForScope(LookupDescriptorProvider.LookupScope.DocumentField);
    final DocumentFieldWidgetType widgetType = extractWidgetType(parameterName, adProcessParam.getAD_Reference_ID(), lookupDescriptor, adProcessParam.isRange());
    final Class<?> valueClass = DescriptorsFactoryHelper.getValueClass(widgetType, lookupDescriptor);
    // process parameters shall always allow displaying the password
    final boolean allowShowPassword = widgetType == DocumentFieldWidgetType.Password ? true : false;
    final ILogicExpression readonlyLogic = expressionFactory.compileOrDefault(adProcessParam.getReadOnlyLogic(), ConstantLogicExpression.FALSE, ILogicExpression.class);
    final ILogicExpression displayLogic = expressionFactory.compileOrDefault(adProcessParam.getDisplayLogic(), ConstantLogicExpression.TRUE, ILogicExpression.class);
    final ILogicExpression mandatoryLogic = ConstantLogicExpression.of(adProcessParam.isMandatory());
    final Optional<IExpression<?>> defaultValueExpr = defaultValueExpressions.extractDefaultValueExpression(adProcessParam.getDefaultValue(), parameterName, widgetType, valueClass, mandatoryLogic.isConstantTrue(), // don't allow using auto sequence
    false);
    final DocumentFieldDescriptor.Builder paramDescriptor = DocumentFieldDescriptor.builder(parameterName).setCaption(adProcessParaTrlsMap.getColumnTrl(I_AD_Process_Para.COLUMNNAME_Name, adProcessParam.getName())).setDescription(adProcessParaTrlsMap.getColumnTrl(I_AD_Process_Para.COLUMNNAME_Description, adProcessParam.getDescription())).setValueClass(valueClass).setWidgetType(widgetType).setAllowShowPassword(allowShowPassword).setLookupDescriptorProvider(lookupDescriptorProvider).setDefaultValueExpression(defaultValueExpr).setReadonlyLogic(readonlyLogic).setDisplayLogic(displayLogic).setMandatoryLogic(mandatoryLogic).addCharacteristic(Characteristic.PublicField);
    // Add a callout to forward process parameter value (UI) to current process instance
    if (webuiProcesClassInfo.isForwardValueToJavaProcessInstance(parameterName)) {
        paramDescriptor.addCallout(ProcessParametersCallout::forwardValueToCurrentProcessInstance);
    }
    return paramDescriptor;
}
Also used : IModelTranslationMap(de.metas.i18n.IModelTranslationMap) IExpression(org.adempiere.ad.expression.api.IExpression) LookupDescriptorProvider(de.metas.ui.web.window.descriptor.LookupDescriptorProvider) DocumentFieldDescriptor(de.metas.ui.web.window.descriptor.DocumentFieldDescriptor) ILogicExpression(org.adempiere.ad.expression.api.ILogicExpression) DocumentFieldWidgetType(de.metas.ui.web.window.descriptor.DocumentFieldWidgetType) SqlLookupDescriptor(de.metas.ui.web.window.descriptor.sql.SqlLookupDescriptor) LookupDescriptor(de.metas.ui.web.window.descriptor.LookupDescriptor)

Example 3 with IExpression

use of org.adempiere.ad.expression.api.IExpression 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));
}
Also used : X_M_Attribute(org.compiere.model.X_M_Attribute) ArrayKey(org.compiere.util.Util.ArrayKey) CCache(org.compiere.util.CCache) IExpression(org.adempiere.ad.expression.api.IExpression) DocumentId(de.metas.ui.web.window.datatypes.DocumentId) TimeUtil(org.compiere.util.TimeUtil) LookupDescriptorProvider(de.metas.ui.web.window.descriptor.LookupDescriptorProvider) ILogicExpression(org.adempiere.ad.expression.api.ILogicExpression) Function(java.util.function.Function) DocumentLayoutElementDescriptor(de.metas.ui.web.window.descriptor.DocumentLayoutElementDescriptor) BigDecimal(java.math.BigDecimal) LookupDescriptor(de.metas.ui.web.window.descriptor.LookupDescriptor) InterfaceWrapperHelper(org.adempiere.model.InterfaceWrapperHelper) I_M_AttributeSet(org.compiere.model.I_M_AttributeSet) Characteristic(de.metas.ui.web.window.descriptor.DocumentFieldDescriptor.Characteristic) IDocumentFieldView(de.metas.ui.web.window.model.IDocumentFieldView) BiConsumer(java.util.function.BiConsumer) DocumentEntityDescriptor(de.metas.ui.web.window.descriptor.DocumentEntityDescriptor) I_M_AttributeInstance(org.compiere.model.I_M_AttributeInstance) I_M_Attribute(org.compiere.model.I_M_Attribute) DocumentsRepository(de.metas.ui.web.window.model.DocumentsRepository) ConstantLogicExpression(org.adempiere.ad.expression.api.ConstantLogicExpression) DocumentFieldDataBindingDescriptor(de.metas.ui.web.window.descriptor.DocumentFieldDataBindingDescriptor) MAttribute(org.compiere.model.MAttribute) ASIEditingInfo(org.adempiere.mm.attributes.util.ASIEditingInfo) DocumentFieldDescriptor(de.metas.ui.web.window.descriptor.DocumentFieldDescriptor) DocumentEntityDataBindingDescriptor(de.metas.ui.web.window.descriptor.DocumentEntityDataBindingDescriptor) DocumentLayoutElementFieldDescriptor(de.metas.ui.web.window.descriptor.DocumentLayoutElementFieldDescriptor) List(java.util.List) Component(org.springframework.stereotype.Component) StringLookupValue(de.metas.ui.web.window.datatypes.LookupValue.StringLookupValue) DocumentEntityDataBindingDescriptorBuilder(de.metas.ui.web.window.descriptor.DocumentEntityDataBindingDescriptor.DocumentEntityDataBindingDescriptorBuilder) AdempiereException(org.adempiere.exceptions.AdempiereException) Check(de.metas.printing.esb.base.util.Check) DocumentFieldWidgetType(de.metas.ui.web.window.descriptor.DocumentFieldWidgetType) Optional(java.util.Optional) DocumentType(de.metas.ui.web.window.datatypes.DocumentType) I_M_AttributeSetInstance(org.compiere.model.I_M_AttributeSetInstance) StringLookupValue(de.metas.ui.web.window.datatypes.LookupValue.StringLookupValue) IExpression(org.adempiere.ad.expression.api.IExpression) IDocumentFieldView(de.metas.ui.web.window.model.IDocumentFieldView) ILogicExpression(org.adempiere.ad.expression.api.ILogicExpression) DocumentFieldWidgetType(de.metas.ui.web.window.descriptor.DocumentFieldWidgetType) I_M_AttributeInstance(org.compiere.model.I_M_AttributeInstance) LookupDescriptor(de.metas.ui.web.window.descriptor.LookupDescriptor)

Aggregations

DocumentFieldDescriptor (de.metas.ui.web.window.descriptor.DocumentFieldDescriptor)3 DocumentFieldWidgetType (de.metas.ui.web.window.descriptor.DocumentFieldWidgetType)3 LookupDescriptor (de.metas.ui.web.window.descriptor.LookupDescriptor)3 LookupDescriptorProvider (de.metas.ui.web.window.descriptor.LookupDescriptorProvider)3 IExpression (org.adempiere.ad.expression.api.IExpression)3 ILogicExpression (org.adempiere.ad.expression.api.ILogicExpression)3 SqlLookupDescriptor (de.metas.ui.web.window.descriptor.sql.SqlLookupDescriptor)2 IModelTranslationMap (de.metas.i18n.IModelTranslationMap)1 Check (de.metas.printing.esb.base.util.Check)1 DocumentId (de.metas.ui.web.window.datatypes.DocumentId)1 DocumentType (de.metas.ui.web.window.datatypes.DocumentType)1 StringLookupValue (de.metas.ui.web.window.datatypes.LookupValue.StringLookupValue)1 ButtonFieldActionDescriptor (de.metas.ui.web.window.descriptor.ButtonFieldActionDescriptor)1 ButtonFieldActionType (de.metas.ui.web.window.descriptor.ButtonFieldActionDescriptor.ButtonFieldActionType)1 DocumentEntityDataBindingDescriptor (de.metas.ui.web.window.descriptor.DocumentEntityDataBindingDescriptor)1 DocumentEntityDataBindingDescriptorBuilder (de.metas.ui.web.window.descriptor.DocumentEntityDataBindingDescriptor.DocumentEntityDataBindingDescriptorBuilder)1 DocumentEntityDescriptor (de.metas.ui.web.window.descriptor.DocumentEntityDescriptor)1 DocumentFieldDataBindingDescriptor (de.metas.ui.web.window.descriptor.DocumentFieldDataBindingDescriptor)1 Characteristic (de.metas.ui.web.window.descriptor.DocumentFieldDescriptor.Characteristic)1 DocumentLayoutElementDescriptor (de.metas.ui.web.window.descriptor.DocumentLayoutElementDescriptor)1