Search in sources :

Example 16 with DocumentFieldWidgetType

use of de.metas.ui.web.window.descriptor.DocumentFieldWidgetType 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();
}
Also used : Operator(de.metas.ui.web.document.filter.DocumentFilterParam.Operator) DocumentFieldWidgetType(de.metas.ui.web.window.descriptor.DocumentFieldWidgetType) ITranslatableString(de.metas.i18n.ITranslatableString) Join(org.compiere.apps.search.IUserQueryRestriction.Join) IUserQueryField(org.compiere.apps.search.IUserQueryField) ITranslatableString(de.metas.i18n.ITranslatableString) IUserQueryRestriction(org.compiere.apps.search.IUserQueryRestriction) LookupDescriptor(de.metas.ui.web.window.descriptor.LookupDescriptor)

Example 17 with DocumentFieldWidgetType

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

the class SqlDefaultDocumentFilterConverter method buildSqlWhereClause_StandardWidget.

private final String buildSqlWhereClause_StandardWidget(final SqlParamsCollector sqlParams, final DocumentFilterParam filterParam, final SqlOptions sqlOpts) {
    final SqlEntityFieldBinding paramBinding = getParameterBinding(filterParam.getFieldName());
    final DocumentFieldWidgetType widgetType = paramBinding.getWidgetType();
    // 
    // Regular filter
    final IQueryFilterModifier fieldModifier = extractFieldModifier(widgetType);
    final IQueryFilterModifier valueModifier = extractValueModifier(widgetType);
    final String columnSql = extractColumnSql(paramBinding, fieldModifier, sqlOpts);
    final Operator operator = filterParam.getOperator();
    switch(operator) {
        case EQUAL:
            {
                final Object sqlValue = convertToSqlValue(filterParam.getValue(), paramBinding, valueModifier);
                final boolean negate = false;
                return buildSqlWhereClause_Equals(columnSql, sqlValue, negate, sqlParams);
            }
        case NOT_EQUAL:
            {
                final Object sqlValue = convertToSqlValue(filterParam.getValue(), paramBinding, valueModifier);
                final boolean negate = true;
                return buildSqlWhereClause_Equals(columnSql, sqlValue, negate, sqlParams);
            }
        case IN_ARRAY:
            {
                final List<Object> sqlValuesList = filterParam.getValueAsList(itemObj -> convertToSqlValue(itemObj, paramBinding, valueModifier));
                return buildSqlWhereClause_InArray(columnSql, sqlValuesList, sqlParams);
            }
        case GREATER:
            {
                final Object sqlValue = convertToSqlValue(filterParam.getValue(), paramBinding, valueModifier);
                return buildSqlWhereClause_Compare(columnSql, ">", sqlValue, sqlParams);
            }
        case GREATER_OR_EQUAL:
            {
                final Object sqlValue = convertToSqlValue(filterParam.getValue(), paramBinding, valueModifier);
                return buildSqlWhereClause_Compare(columnSql, ">=", sqlValue, sqlParams);
            }
        case LESS:
            {
                final Object sqlValue = convertToSqlValue(filterParam.getValue(), paramBinding, valueModifier);
                return buildSqlWhereClause_Compare(columnSql, "<", sqlValue, sqlParams);
            }
        case LESS_OR_EQUAL:
            {
                final Object sqlValue = convertToSqlValue(filterParam.getValue(), paramBinding, valueModifier);
                return buildSqlWhereClause_Compare(columnSql, "<=", sqlValue, sqlParams);
            }
        case LIKE:
            {
                final Object sqlValue = convertToSqlValue(filterParam.getValue(), paramBinding, valueModifier);
                final boolean negate = false;
                final boolean ignoreCase = false;
                return buildSqlWhereClause_Like(columnSql, negate, ignoreCase, sqlValue, sqlParams);
            }
        case NOT_LIKE:
            {
                final Object sqlValue = convertToSqlValue(filterParam.getValue(), paramBinding, valueModifier);
                final boolean negate = true;
                final boolean ignoreCase = false;
                return buildSqlWhereClause_Like(columnSql, negate, ignoreCase, sqlValue, sqlParams);
            }
        case LIKE_I:
            {
                final Object sqlValue = convertToSqlValue(filterParam.getValue(), paramBinding, valueModifier);
                final boolean negate = false;
                final boolean ignoreCase = true;
                return buildSqlWhereClause_Like(columnSql, negate, ignoreCase, sqlValue, sqlParams);
            }
        case NOT_LIKE_I:
            {
                final Object sqlValue = convertToSqlValue(filterParam.getValue(), paramBinding, valueModifier);
                final boolean negate = true;
                final boolean ignoreCase = true;
                return buildSqlWhereClause_Like(columnSql, negate, ignoreCase, sqlValue, sqlParams);
            }
        case BETWEEN:
            {
                final Object sqlValue = convertToSqlValue(filterParam.getValue(), paramBinding, valueModifier);
                final Object sqlValueTo = convertToSqlValue(filterParam.getValueTo(), paramBinding, valueModifier);
                return buildSqlWhereClause_Between(columnSql, sqlValue, sqlValueTo, sqlParams);
            }
        default:
            {
                throw new IllegalArgumentException("Operator not supported: " + operator);
            }
    }
}
Also used : Operator(de.metas.ui.web.document.filter.DocumentFilterParam.Operator) LookupValue(de.metas.ui.web.window.datatypes.LookupValue) DateTruncQueryFilterModifier(org.adempiere.ad.dao.impl.DateTruncQueryFilterModifier) NonNull(lombok.NonNull) DocumentFilterParamDescriptor(de.metas.ui.web.document.filter.DocumentFilterParamDescriptor) SqlDocumentsRepository(de.metas.ui.web.window.model.sql.SqlDocumentsRepository) DocumentFilterParam(de.metas.ui.web.document.filter.DocumentFilterParam) IQueryFilterModifier(org.adempiere.ad.dao.IQueryFilterModifier) MoreObjects(com.google.common.base.MoreObjects) SqlOptions(de.metas.ui.web.window.model.sql.SqlOptions) ArrayList(java.util.ArrayList) List(java.util.List) DB(org.compiere.util.DB) Operator(de.metas.ui.web.document.filter.DocumentFilterParam.Operator) LabelsLookup(de.metas.ui.web.window.model.lookup.LabelsLookup) AdempiereException(org.adempiere.exceptions.AdempiereException) SqlEntityFieldBinding(de.metas.ui.web.window.descriptor.sql.SqlEntityFieldBinding) Check(de.metas.printing.esb.base.util.Check) DocumentFieldWidgetType(de.metas.ui.web.window.descriptor.DocumentFieldWidgetType) SqlEntityBinding(de.metas.ui.web.window.descriptor.sql.SqlEntityBinding) DBConstants(org.adempiere.db.DBConstants) DocumentFilter(de.metas.ui.web.document.filter.DocumentFilter) LookupValuesList(de.metas.ui.web.window.datatypes.LookupValuesList) NullQueryFilterModifier(org.adempiere.ad.dao.impl.NullQueryFilterModifier) IQueryFilterModifier(org.adempiere.ad.dao.IQueryFilterModifier) DocumentFieldWidgetType(de.metas.ui.web.window.descriptor.DocumentFieldWidgetType) ArrayList(java.util.ArrayList) List(java.util.List) LookupValuesList(de.metas.ui.web.window.datatypes.LookupValuesList) SqlEntityFieldBinding(de.metas.ui.web.window.descriptor.sql.SqlEntityFieldBinding)

Example 18 with DocumentFieldWidgetType

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

the class HUEditorRowAttributesHelper method createLayoutElement.

private static final DocumentLayoutElementDescriptor createLayoutElement(final IAttributeValue attributeValue, final int warehouseId) {
    final I_M_Attribute attribute = attributeValue.getM_Attribute();
    final IModelTranslationMap attributeTrlMap = InterfaceWrapperHelper.getModelTranslationMap(attribute);
    final ITranslatableString caption = attributeTrlMap.getColumnTrl(I_M_Attribute.COLUMNNAME_Name, attribute.getName());
    final ITranslatableString description = attributeTrlMap.getColumnTrl(I_M_Attribute.COLUMNNAME_Description, attribute.getDescription());
    final String attributeName = HUEditorRowAttributesHelper.extractAttributeName(attributeValue);
    final DocumentFieldWidgetType widgetType = HUEditorRowAttributesHelper.extractWidgetType(attributeValue);
    return DocumentLayoutElementDescriptor.builder().setCaption(caption).setDescription(description).setWidgetType(widgetType).addField(DocumentLayoutElementFieldDescriptor.builder(attributeName).setPublicField(true).addDevices(createDevices(attribute.getValue(), warehouseId))).build();
}
Also used : IModelTranslationMap(de.metas.i18n.IModelTranslationMap) DocumentFieldWidgetType(de.metas.ui.web.window.descriptor.DocumentFieldWidgetType) ITranslatableString(de.metas.i18n.ITranslatableString) I_M_Attribute(org.compiere.model.I_M_Attribute) ITranslatableString(de.metas.i18n.ITranslatableString)

Example 19 with DocumentFieldWidgetType

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

the class HUEditorRowAttributes method toJSONDocumentField.

private final JSONDocumentField toJSONDocumentField(final IAttributeValue attributeValue) {
    final String fieldName = HUEditorRowAttributesHelper.extractAttributeName(attributeValue);
    final Object jsonValue = HUEditorRowAttributesHelper.extractJSONValue(attributesStorage, attributeValue);
    final DocumentFieldWidgetType widgetType = HUEditorRowAttributesHelper.extractWidgetType(attributeValue);
    return JSONDocumentField.ofNameAndValue(fieldName, jsonValue).setDisplayed(isDisplayed(fieldName)).setMandatory(false).setReadonly(isReadonly(fieldName)).setWidgetType(JSONLayoutWidgetType.fromNullable(widgetType));
}
Also used : DocumentFieldWidgetType(de.metas.ui.web.window.descriptor.DocumentFieldWidgetType)

Example 20 with DocumentFieldWidgetType

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

the class ViewExcelExporter method getValueAt.

@Override
public CellValue getValueAt(final int rowIndex, final int columnIndex) {
    final String fieldName = getFieldName(columnIndex);
    final IViewRow row = getRow(rowIndex);
    if (row == null) {
        return null;
    }
    final Object value = row.getFieldNameAndJsonValues().get(fieldName);
    if (value == null) {
        return null;
    }
    final DocumentFieldWidgetType widgetType = getWidgetType(columnIndex);
    if (widgetType.isDateOrTime()) {
        return CellValue.ofDate(JSONDate.fromJson(value.toString(), widgetType));
    } else if (value instanceof JSONLookupValue) {
        final String valueStr = ((JSONLookupValue) value).getCaption();
        return CellValues.toCellValue(valueStr, widgetType.getDisplayType());
    } else {
        return CellValues.toCellValue(value, widgetType.getDisplayType());
    }
}
Also used : JSONLookupValue(de.metas.ui.web.window.datatypes.json.JSONLookupValue) DocumentFieldWidgetType(de.metas.ui.web.window.descriptor.DocumentFieldWidgetType)

Aggregations

DocumentFieldWidgetType (de.metas.ui.web.window.descriptor.DocumentFieldWidgetType)20 DocumentFieldDescriptor (de.metas.ui.web.window.descriptor.DocumentFieldDescriptor)6 LookupDescriptor (de.metas.ui.web.window.descriptor.LookupDescriptor)6 ITranslatableString (de.metas.i18n.ITranslatableString)4 Operator (de.metas.ui.web.document.filter.DocumentFilterParam.Operator)3 LookupDescriptorProvider (de.metas.ui.web.window.descriptor.LookupDescriptorProvider)3 SqlDocumentFieldDataBindingDescriptor (de.metas.ui.web.window.descriptor.sql.SqlDocumentFieldDataBindingDescriptor)3 SqlLookupDescriptor (de.metas.ui.web.window.descriptor.sql.SqlLookupDescriptor)3 List (java.util.List)3 MoreObjects (com.google.common.base.MoreObjects)2 IModelTranslationMap (de.metas.i18n.IModelTranslationMap)2 Check (de.metas.printing.esb.base.util.Check)2 DocumentFilter (de.metas.ui.web.document.filter.DocumentFilter)2 DocumentFilterParamDescriptor (de.metas.ui.web.document.filter.DocumentFilterParamDescriptor)2 DocumentId (de.metas.ui.web.window.datatypes.DocumentId)2 DocumentEntityDescriptor (de.metas.ui.web.window.descriptor.DocumentEntityDescriptor)2 SqlDocumentEntityDataBindingDescriptor (de.metas.ui.web.window.descriptor.sql.SqlDocumentEntityDataBindingDescriptor)2 SqlEntityFieldBinding (de.metas.ui.web.window.descriptor.sql.SqlEntityFieldBinding)2 BigDecimal (java.math.BigDecimal)2 IExpression (org.adempiere.ad.expression.api.IExpression)2