Search in sources :

Example 66 with FieldComponent

use of com.qcadoo.view.api.components.FieldComponent in project mes by qcadoo.

the class ChangeTechnologyParametersListeners method onChangePerformanceNorm.

public void onChangePerformanceNorm(final ViewDefinitionState view, final ComponentState state, final String[] args) {
    CheckBoxComponent changePerformanceNorm = (CheckBoxComponent) state;
    FieldComponent standardPerformance = (FieldComponent) view.getComponentByReference(L_STANDARD_PERFORMANCE);
    if (changePerformanceNorm.isChecked()) {
        standardPerformance.setEnabled(true);
    } else {
        standardPerformance.setEnabled(false);
        standardPerformance.setFieldValue(null);
    }
}
Also used : FieldComponent(com.qcadoo.view.api.components.FieldComponent) CheckBoxComponent(com.qcadoo.view.api.components.CheckBoxComponent)

Example 67 with FieldComponent

use of com.qcadoo.view.api.components.FieldComponent in project mes by qcadoo.

the class TOCDetailsListeners method addUpTheNumberOfWorkstations.

public void addUpTheNumberOfWorkstations(final ViewDefinitionState view, final ComponentState componentState, final String[] args) {
    FormComponent form = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
    int size = form.getPersistedEntityWithIncludedFormValues().getHasManyField(TechnologyOperationComponentFields.WORKSTATIONS).size();
    FieldComponent quantityOfWorkstations = (FieldComponent) view.getComponentByReference(TechnologyOperationComponentFields.QUANTITY_OF_WORKSTATIONS);
    quantityOfWorkstations.setFieldValue(size);
    quantityOfWorkstations.requestComponentUpdateState();
}
Also used : FormComponent(com.qcadoo.view.api.components.FormComponent) FieldComponent(com.qcadoo.view.api.components.FieldComponent)

Example 68 with FieldComponent

use of com.qcadoo.view.api.components.FieldComponent in project mes by qcadoo.

the class OPICDetailsListeners method calculateQuantity.

private void calculateQuantity(final ViewDefinitionState view, final Entity operationProductInComponent) {
    Entity technologyInputProductType = operationProductInComponent.getBelongsToField(OperationProductInComponentFields.TECHNOLOGY_INPUT_PRODUCT_TYPE);
    Entity product = operationProductInComponent.getBelongsToField(OperationProductInComponentFields.PRODUCT);
    String givenUnit = operationProductInComponent.getStringField(OperationProductInComponentFields.GIVEN_UNIT);
    FieldComponent unitField = (FieldComponent) view.getComponentByReference(OperationProductInComponentFields.UNIT);
    FieldComponent givenQuantityField = (FieldComponent) view.getComponentByReference(OperationProductInComponentFields.GIVEN_QUANTITY);
    if ((Objects.isNull(technologyInputProductType) && Objects.isNull(product)) || Objects.isNull(givenUnit) || givenUnit.isEmpty() || Objects.isNull(givenQuantityField.getFieldValue())) {
        return;
    }
    Either<Exception, Optional<BigDecimal>> maybeQuantity = BigDecimalUtils.tryParse((String) givenQuantityField.getFieldValue(), view.getLocale());
    if (maybeQuantity.isRight()) {
        if (maybeQuantity.getRight().isPresent()) {
            BigDecimal givenQuantity = maybeQuantity.getRight().get();
            if (Objects.nonNull(product)) {
                String baseUnit = product.getStringField(ProductFields.UNIT);
                if (baseUnit.equals(givenUnit)) {
                    operationProductInComponent.setField(OperationProductInComponentFields.QUANTITY, givenQuantity);
                } else {
                    PossibleUnitConversions unitConversions = unitConversionService.getPossibleConversions(givenUnit, searchCriteriaBuilder -> searchCriteriaBuilder.add(SearchRestrictions.belongsTo(UnitConversionItemFieldsB.PRODUCT, product)));
                    if (unitConversions.isDefinedFor(baseUnit)) {
                        BigDecimal convertedQuantity = unitConversions.convertTo(givenQuantity, baseUnit);
                        operationProductInComponent.setField(OperationProductInComponentFields.QUANTITY, convertedQuantity);
                    } else {
                        operationProductInComponent.addError(operationProductInComponent.getDataDefinition().getField(OperationProductInComponentFields.GIVEN_QUANTITY), "technologies.operationProductInComponent.validate.error.missingUnitConversion");
                        operationProductInComponent.setField(OperationProductInComponentFields.QUANTITY, null);
                    }
                }
            } else {
                operationProductInComponent.setField(OperationProductInComponentFields.QUANTITY, givenQuantity);
                operationProductInComponent.setField(OperationProductInComponentFields.UNIT, givenUnit);
                unitField.setFieldValue(givenUnit);
                unitField.requestComponentUpdateState();
            }
        } else {
            operationProductInComponent.setField(OperationProductInComponentFields.QUANTITY, null);
        }
    } else {
        operationProductInComponent.setField(OperationProductInComponentFields.QUANTITY, null);
    }
}
Also used : Entity(com.qcadoo.model.api.Entity) Optional(com.google.common.base.Optional) FieldComponent(com.qcadoo.view.api.components.FieldComponent) PossibleUnitConversions(com.qcadoo.model.api.units.PossibleUnitConversions) BigDecimal(java.math.BigDecimal)

Example 69 with FieldComponent

use of com.qcadoo.view.api.components.FieldComponent in project mes by qcadoo.

the class OPICDetailsListeners method fillUnitForTechnologyType.

private void fillUnitForTechnologyType(ViewDefinitionState view) {
    LookupComponent technologyInputProductTypeLookup = (LookupComponent) view.getComponentByReference(OperationProductInComponentFields.TECHNOLOGY_INPUT_PRODUCT_TYPE);
    FieldComponent unitField = (FieldComponent) view.getComponentByReference(OperationProductInComponentFields.UNIT);
    FieldComponent givenUnitField = (FieldComponent) view.getComponentByReference(OperationProductInComponentFields.GIVEN_UNIT);
    Entity technologyInputProductType = technologyInputProductTypeLookup.getEntity();
    String givenUnit = (String) givenUnitField.getFieldValue();
    LookupComponent productLookup = (LookupComponent) view.getComponentByReference(OperationProductInComponentFields.PRODUCT);
    if (productLookup.isEmpty() && Objects.nonNull(technologyInputProductType) && StringUtils.isNoneEmpty(givenUnit)) {
        unitField.setFieldValue(givenUnit);
        unitField.requestComponentUpdateState();
    }
    unitService.fillProductUnitBeforeRenderIfEmpty(view, OperationProductInComponentFields.UNIT);
    unitService.fillProductUnitBeforeRenderIfEmpty(view, OperationProductInComponentFields.GIVEN_UNIT);
}
Also used : Entity(com.qcadoo.model.api.Entity) LookupComponent(com.qcadoo.view.api.components.LookupComponent) FieldComponent(com.qcadoo.view.api.components.FieldComponent)

Example 70 with FieldComponent

use of com.qcadoo.view.api.components.FieldComponent in project mes by qcadoo.

the class OperationDetailsListeners method addUpTheNumberOfWorkstations.

public void addUpTheNumberOfWorkstations(final ViewDefinitionState view, final ComponentState componentState, final String[] args) {
    FormComponent form = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
    int size = form.getPersistedEntityWithIncludedFormValues().getHasManyField(OperationFields.WORKSTATIONS).size();
    FieldComponent quantityOfWorkstations = (FieldComponent) view.getComponentByReference(OperationFields.QUANTITY_OF_WORKSTATIONS);
    quantityOfWorkstations.setFieldValue(size);
    quantityOfWorkstations.requestComponentUpdateState();
}
Also used : FormComponent(com.qcadoo.view.api.components.FormComponent) FieldComponent(com.qcadoo.view.api.components.FieldComponent)

Aggregations

FieldComponent (com.qcadoo.view.api.components.FieldComponent)443 Entity (com.qcadoo.model.api.Entity)201 FormComponent (com.qcadoo.view.api.components.FormComponent)183 LookupComponent (com.qcadoo.view.api.components.LookupComponent)107 BigDecimal (java.math.BigDecimal)47 CheckBoxComponent (com.qcadoo.view.api.components.CheckBoxComponent)31 GridComponent (com.qcadoo.view.api.components.GridComponent)31 Date (java.util.Date)30 Optional (com.google.common.base.Optional)18 AwesomeDynamicListComponent (com.qcadoo.view.api.components.AwesomeDynamicListComponent)14 ComponentState (com.qcadoo.view.api.ComponentState)13 FilterValueHolder (com.qcadoo.view.api.components.lookup.FilterValueHolder)13 WindowComponent (com.qcadoo.view.api.components.WindowComponent)12 RibbonActionItem (com.qcadoo.view.api.ribbon.RibbonActionItem)11 RibbonGroup (com.qcadoo.view.api.ribbon.RibbonGroup)9 PossibleUnitConversions (com.qcadoo.model.api.units.PossibleUnitConversions)7 SimpleDateFormat (java.text.SimpleDateFormat)7 ViewDefinitionState (com.qcadoo.view.api.ViewDefinitionState)6 QcadooViewConstants (com.qcadoo.view.constants.QcadooViewConstants)6 Collectors (java.util.stream.Collectors)6