Search in sources :

Example 1 with ButtonFieldActionDescriptor

use of de.metas.ui.web.window.descriptor.ButtonFieldActionDescriptor in project metasfresh-webui-api by metasfresh.

the class WindowRestController method getDocumentFieldZoomInto.

private JSONZoomInto getDocumentFieldZoomInto(final DocumentPath documentPath, final String fieldName) {
    userSession.assertLoggedIn();
    final DocumentZoomIntoInfo zoomIntoInfo = documentCollection.forDocumentReadonly(documentPath, document -> {
        final IDocumentFieldView field = document.getFieldView(fieldName);
        // Generic ZoomInto button
        if (field.getDescriptor().getWidgetType() == DocumentFieldWidgetType.ZoomIntoButton) {
            final ButtonFieldActionDescriptor buttonActionDescriptor = field.getDescriptor().getButtonActionDescriptor();
            final String zoomIntoTableIdFieldName = buttonActionDescriptor.getZoomIntoTableIdFieldName();
            final Integer adTableId = document.getFieldView(zoomIntoTableIdFieldName).getValueAs(Integer.class);
            if (adTableId == null || adTableId <= 0) {
                throw new EntityNotFoundException("Cannot fetch ZoomInto infos from a null value. No AD_Table_ID.").setParameter("documentPath", documentPath).setParameter("fieldName", fieldName).setParameter("zoomIntoTableIdFieldName", zoomIntoTableIdFieldName);
            }
            final Integer recordId = field.getValueAs(Integer.class);
            if (recordId == null) {
                throw new EntityNotFoundException("Cannot fetch ZoomInto infos from a null value. No Record_ID.").setParameter("documentPath", documentPath).setParameter("fieldName", fieldName).setParameter("zoomIntoTableIdFieldName", zoomIntoTableIdFieldName);
            }
            final String tableName = Services.get(IADTableDAO.class).retrieveTableName(adTableId);
            return DocumentZoomIntoInfo.of(tableName, recordId);
        } else // Key Field
        if (field.isKey()) {
            // Allow zooming into key column. It shall open precisely this record in a new window.
            // (see https://github.com/metasfresh/metasfresh/issues/1687 to understand the use-case)
            final String tableName = document.getEntityDescriptor().getTableName();
            final int recordId = document.getDocumentIdAsInt();
            return DocumentZoomIntoInfo.of(tableName, recordId);
        } else // Regular lookup value
        {
            return field.getZoomIntoInfo();
        }
    });
    final JSONDocumentPath jsonZoomIntoDocumentPath;
    if (zoomIntoInfo == null) {
        throw new EntityNotFoundException("ZoomInto not supported").setParameter("documentPath", documentPath).setParameter("fieldName", fieldName);
    } else if (!zoomIntoInfo.isRecordIdPresent()) {
        final WindowId windowId = documentCollection.getWindowId(zoomIntoInfo);
        jsonZoomIntoDocumentPath = JSONDocumentPath.newWindowRecord(windowId);
    } else {
        final DocumentPath zoomIntoDocumentPath = documentCollection.getDocumentPath(zoomIntoInfo);
        jsonZoomIntoDocumentPath = JSONDocumentPath.ofWindowDocumentPath(zoomIntoDocumentPath);
    }
    return JSONZoomInto.builder().documentPath(jsonZoomIntoDocumentPath).source(JSONDocumentPath.ofWindowDocumentPath(documentPath, fieldName)).build();
}
Also used : ButtonFieldActionDescriptor(de.metas.ui.web.window.descriptor.ButtonFieldActionDescriptor) DocumentZoomIntoInfo(de.metas.ui.web.window.model.lookup.DocumentZoomIntoInfo) WindowId(de.metas.ui.web.window.datatypes.WindowId) IADTableDAO(org.adempiere.ad.table.api.IADTableDAO) DocumentPath(de.metas.ui.web.window.datatypes.DocumentPath) JSONDocumentPath(de.metas.ui.web.window.datatypes.json.JSONDocumentPath) EntityNotFoundException(de.metas.ui.web.exceptions.EntityNotFoundException) IDocumentFieldView(de.metas.ui.web.window.model.IDocumentFieldView) JSONDocumentPath(de.metas.ui.web.window.datatypes.json.JSONDocumentPath)

Example 2 with ButtonFieldActionDescriptor

use of de.metas.ui.web.window.descriptor.ButtonFieldActionDescriptor 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)

Aggregations

ButtonFieldActionDescriptor (de.metas.ui.web.window.descriptor.ButtonFieldActionDescriptor)2 IADTableDAO (org.adempiere.ad.table.api.IADTableDAO)2 EntityNotFoundException (de.metas.ui.web.exceptions.EntityNotFoundException)1 DocumentPath (de.metas.ui.web.window.datatypes.DocumentPath)1 WindowId (de.metas.ui.web.window.datatypes.WindowId)1 JSONDocumentPath (de.metas.ui.web.window.datatypes.json.JSONDocumentPath)1 ButtonFieldActionType (de.metas.ui.web.window.descriptor.ButtonFieldActionDescriptor.ButtonFieldActionType)1 DocumentFieldDescriptor (de.metas.ui.web.window.descriptor.DocumentFieldDescriptor)1 DocumentFieldWidgetType (de.metas.ui.web.window.descriptor.DocumentFieldWidgetType)1 LookupDescriptor (de.metas.ui.web.window.descriptor.LookupDescriptor)1 LookupDescriptorProvider (de.metas.ui.web.window.descriptor.LookupDescriptorProvider)1 SqlDocumentEntityDataBindingDescriptor (de.metas.ui.web.window.descriptor.sql.SqlDocumentEntityDataBindingDescriptor)1 SqlDocumentFieldDataBindingDescriptor (de.metas.ui.web.window.descriptor.sql.SqlDocumentFieldDataBindingDescriptor)1 SqlLookupDescriptor (de.metas.ui.web.window.descriptor.sql.SqlLookupDescriptor)1 IDocumentFieldView (de.metas.ui.web.window.model.IDocumentFieldView)1 DocumentZoomIntoInfo (de.metas.ui.web.window.model.lookup.DocumentZoomIntoInfo)1 IExpression (org.adempiere.ad.expression.api.IExpression)1 ILogicExpression (org.adempiere.ad.expression.api.ILogicExpression)1