Search in sources :

Example 11 with ComponentState

use of com.qcadoo.view.api.ComponentState in project mes by qcadoo.

the class ProductionTrackingDetailsListeners method disableFields.

public void disableFields(final ViewDefinitionState viewDefinitionState, final ComponentState componentState, final String[] args) {
    productionTrackingService.changeProducedQuantityFieldState(viewDefinitionState);
    Object recordingTypeValue = viewDefinitionState.getComponentByReference(OrderFieldsPC.TYPE_OF_PRODUCTION_RECORDING).getFieldValue();
    boolean recordingTypeEqualsCumulated = TypeOfProductionRecording.CUMULATED.getStringValue().equals(recordingTypeValue);
    boolean recordingTypeEqualsForEach = TypeOfProductionRecording.FOR_EACH.getStringValue().equals(recordingTypeValue);
    if (recordingTypeEqualsCumulated || recordingTypeEqualsForEach) {
        for (String componentName : Arrays.asList(OrderFieldsPC.REGISTER_QUANTITY_IN_PRODUCT, OrderFieldsPC.REGISTER_QUANTITY_OUT_PRODUCT, OrderFieldsPC.REGISTER_PRODUCTION_TIME, OrderFieldsPC.REGISTER_PIECEWORK)) {
            ComponentState component = viewDefinitionState.getComponentByReference(componentName);
            component.setEnabled(true);
        }
    }
}
Also used : ComponentState(com.qcadoo.view.api.ComponentState)

Example 12 with ComponentState

use of com.qcadoo.view.api.ComponentState in project mes by qcadoo.

the class AnomalyExplanationDetailsHooks method onBeforeRender.

public void onBeforeRender(final ViewDefinitionState view) {
    FormComponent form = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
    Entity entity = form.getEntity();
    if (view.isViewAfterRedirect()) {
        initializeFormValues(view, entity);
    }
    boolean useWaste = ((CheckBoxComponent) view.getComponentByReference("useWaste")).isChecked();
    LookupComponent productLookup = ((LookupComponent) view.getComponentByReference("product"));
    productLookup.setEnabled(!useWaste);
    view.getComponentByReference("location").setEnabled(!useWaste);
    ComponentState givenUnitComponent = view.getComponentByReference("givenUnit");
    String givenUnit = (String) givenUnitComponent.getFieldValue();
    Entity selectedProduct = productLookup.getEntity();
    boolean shouldAdditionalUnitBeEnabled = true;
    if (selectedProduct != null) {
        String selectedProductAdditionalUnit = selectedProduct.getStringField(ProductFields.ADDITIONAL_UNIT);
        if (isNotBlank(selectedProductAdditionalUnit) && isNotBlank(givenUnit) && selectedProductAdditionalUnit.equals(givenUnit)) {
            shouldAdditionalUnitBeEnabled = false;
        }
    }
    givenUnitComponent.setEnabled(shouldAdditionalUnitBeEnabled);
}
Also used : FormComponent(com.qcadoo.view.api.components.FormComponent) Entity(com.qcadoo.model.api.Entity) LookupComponent(com.qcadoo.view.api.components.LookupComponent) CheckBoxComponent(com.qcadoo.view.api.components.CheckBoxComponent) ComponentState(com.qcadoo.view.api.ComponentState)

Example 13 with ComponentState

use of com.qcadoo.view.api.ComponentState in project mes by qcadoo.

the class AnomalyExplanationDetailsHooks method initializeFormValues.

private void initializeFormValues(ViewDefinitionState view, Entity entity) {
    LookupComponent productLookup = ((LookupComponent) view.getComponentByReference("product"));
    if (entity.getId() == null) {
        Entity anomaly = entity.getBelongsToField(AnomalyExplanationFields.ANOMALY);
        Entity anomalyProduct = anomaly.getBelongsToField(AnomalyFields.PRODUCT);
        productLookup.setFieldValue(anomalyProduct.getId());
        String selectedProductUnit = anomalyProduct.getStringField(ProductFields.UNIT);
        String additionalSelectedProductUnit = anomalyProduct.getStringField(ProductFields.ADDITIONAL_UNIT);
        ComponentState givenUnitComponent = view.getComponentByReference("givenUnit");
        if (isNotBlank(additionalSelectedProductUnit)) {
            givenUnitComponent.setFieldValue(additionalSelectedProductUnit);
        } else {
            givenUnitComponent.setFieldValue(selectedProductUnit);
        }
        BigDecimal anomalyUsedQuantity = anomaly.getDecimalField(AnomalyFields.USED_QUANTITY);
        view.getComponentByReference("usedQuantity").setFieldValue(numberService.formatWithMinimumFractionDigits(anomalyUsedQuantity, 0));
        String additionalAnomalyProductUnit = anomalyProduct.getStringField(ProductFields.ADDITIONAL_UNIT);
        ComponentState givenQuantityComponent = view.getComponentByReference("givenQuantity");
        if (isNotBlank(additionalAnomalyProductUnit)) {
            productUnitsConversionService.forProduct(anomalyProduct).fromPrimaryUnit().to(additionalAnomalyProductUnit).convertValue(anomalyUsedQuantity).ifPresent(convertedValue -> {
                givenQuantityComponent.setFieldValue(numberService.formatWithMinimumFractionDigits(convertedValue, 0));
            });
        } else {
            givenQuantityComponent.setFieldValue(numberService.formatWithMinimumFractionDigits(anomalyUsedQuantity, 0));
        }
        Entity anomalyLocation = anomaly.getBelongsToField(AnomalyFields.LOCATION);
        view.getComponentByReference("location").setFieldValue(ofNullable(anomalyLocation).map(Entity::getId).orElse(null));
    }
    Entity selectedProduct = productLookup.getEntity();
    ComponentState productUnit = view.getComponentByReference("productUnit");
    ComponentState usedQuantity = view.getComponentByReference("usedQuantity");
    if (selectedProduct != null) {
        productUnit.setFieldValue(selectedProduct.getStringField(ProductFields.UNIT));
        usedQuantity.setEnabled(true);
    } else {
        if (((CheckBoxComponent) view.getComponentByReference("useWaste")).isChecked()) {
            productUnit.setFieldValue(entity.getStringField(AnomalyExplanationFields.GIVEN_UNIT));
        } else {
            productUnit.setFieldValue(null);
        }
        usedQuantity.setEnabled(false);
    }
}
Also used : Entity(com.qcadoo.model.api.Entity) LookupComponent(com.qcadoo.view.api.components.LookupComponent) BigDecimal(java.math.BigDecimal) ComponentState(com.qcadoo.view.api.ComponentState) CheckBoxComponent(com.qcadoo.view.api.components.CheckBoxComponent)

Example 14 with ComponentState

use of com.qcadoo.view.api.ComponentState in project mes by qcadoo.

the class TechSubcontractingService method inheritSubcontractingValue.

public void inheritSubcontractingValue(final ViewDefinitionState view, final ComponentState componentState, final String[] args) {
    ComponentState operationLookup = view.getComponentByReference(OPERATION_FIELD);
    if (operationLookup.getFieldValue() == null) {
        return;
    }
    Entity operation = dataDefinitionService.get(TechnologiesConstants.PLUGIN_IDENTIFIER, TechnologiesConstants.MODEL_OPERATION).get((Long) operationLookup.getFieldValue());
    checkArgument(operation != null, "source entity is null");
    FieldComponent isSucontractungComponent = (FieldComponent) view.getComponentByReference(IS_SUBCONTRACTING);
    isSucontractungComponent.setFieldValue(operation.getField(IS_SUBCONTRACTING));
}
Also used : Entity(com.qcadoo.model.api.Entity) FieldComponent(com.qcadoo.view.api.components.FieldComponent) ComponentState(com.qcadoo.view.api.ComponentState)

Example 15 with ComponentState

use of com.qcadoo.view.api.ComponentState in project mes by qcadoo.

the class ProductionCountingQuantityAdvancedDetailsHooks method hideTab.

private void hideTab(ViewDefinitionState view) {
    ComponentState attributesTab = view.getComponentByReference(ATTRIBUTES);
    ComponentState batchesTab = view.getComponentByReference(L_BATCHES_TAB);
    FieldComponent roleField = (FieldComponent) view.getComponentByReference(ProductionCountingQuantityFields.ROLE);
    FieldComponent materialField = (FieldComponent) view.getComponentByReference(ProductionCountingQuantityFields.TYPE_OF_MATERIAL);
    boolean isProduced = checkIfIsProduced((String) roleField.getFieldValue());
    boolean isUsedMaterial = checkIfIsUsed((String) roleField.getFieldValue()) && checkIfIsComponent((String) materialField.getFieldValue());
    attributesTab.setVisible(isProduced);
    batchesTab.setVisible(isUsedMaterial);
}
Also used : FieldComponent(com.qcadoo.view.api.components.FieldComponent) ComponentState(com.qcadoo.view.api.ComponentState)

Aggregations

ComponentState (com.qcadoo.view.api.ComponentState)68 Entity (com.qcadoo.model.api.Entity)33 FormComponent (com.qcadoo.view.api.components.FormComponent)31 GridComponent (com.qcadoo.view.api.components.GridComponent)23 ViewDefinitionState (com.qcadoo.view.api.ViewDefinitionState)21 Autowired (org.springframework.beans.factory.annotation.Autowired)17 FieldComponent (com.qcadoo.view.api.components.FieldComponent)16 Test (org.junit.Test)16 Service (org.springframework.stereotype.Service)16 QcadooViewConstants (com.qcadoo.view.constants.QcadooViewConstants)15 Collectors (java.util.stream.Collectors)14 List (java.util.List)13 DataDefinition (com.qcadoo.model.api.DataDefinition)12 Lists (com.google.common.collect.Lists)11 DataDefinitionService (com.qcadoo.model.api.DataDefinitionService)11 Map (java.util.Map)11 BigDecimal (java.math.BigDecimal)10 Maps (com.google.common.collect.Maps)8 LookupComponent (com.qcadoo.view.api.components.LookupComponent)8 Transactional (org.springframework.transaction.annotation.Transactional)8