Search in sources :

Example 21 with LookupComponent

use of com.qcadoo.view.api.components.LookupComponent 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 22 with LookupComponent

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

the class ProdOutResourceAttrValDetailsHooks method setValueBold.

private void setValueBold(ViewDefinitionState view) {
    LookupComponent attributeValueLookup = (LookupComponent) view.getComponentByReference(ProdOutResourceAttrValFields.ATTRIBUTE_VALUE);
    attributeValueLookup.setRequired(true);
    attributeValueLookup.requestComponentUpdateState();
}
Also used : LookupComponent(com.qcadoo.view.api.components.LookupComponent)

Example 23 with LookupComponent

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

the class ProdOutResourceAttrValDetailsHooks method onBeforeRender.

public void onBeforeRender(final ViewDefinitionState view) {
    setValueBold(view);
    setFilters(view);
    LookupComponent attributeLookup = (LookupComponent) view.getComponentByReference(ProdOutResourceAttrValFields.ATTRIBUTE);
    LookupComponent attributeValueLookup = (LookupComponent) view.getComponentByReference(ProdOutResourceAttrValFields.ATTRIBUTE_VALUE);
    FieldComponent valueField = (FieldComponent) view.getComponentByReference(ProdOutResourceAttrValFields.VALUE);
    if (Objects.nonNull(attributeLookup.getEntity())) {
        Entity attribute = attributeLookup.getEntity();
        FieldComponent unitField = (FieldComponent) view.getComponentByReference(L_UNIT);
        unitField.setFieldValue(attribute.getStringField(AttributeFields.UNIT));
        unitField.requestComponentUpdateState();
        if (AttributeDataType.CONTINUOUS.getStringValue().equals(attribute.getStringField(AttributeFields.DATA_TYPE))) {
            valueField.setVisible(true);
            attributeValueLookup.setVisible(false);
        } else {
            valueField.setVisible(false);
            attributeValueLookup.setVisible(true);
        }
    } else {
        valueField.setVisible(false);
        attributeValueLookup.setVisible(false);
    }
}
Also used : Entity(com.qcadoo.model.api.Entity) LookupComponent(com.qcadoo.view.api.components.LookupComponent) FieldComponent(com.qcadoo.view.api.components.FieldComponent)

Example 24 with LookupComponent

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

the class WorkstationDetailsListenersPL method clearProductionLine.

public void clearProductionLine(final ViewDefinitionState view, final ComponentState state, final String[] args) {
    LookupComponent productionLineLookup = (LookupComponent) view.getComponentByReference("productionLinesLookup");
    productionLineLookup.setFieldValue(null);
    productionLineLookup.requestComponentUpdateState();
}
Also used : LookupComponent(com.qcadoo.view.api.components.LookupComponent)

Example 25 with LookupComponent

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

the class UserDetailsHooksPL method setFieldsEnabledForAdmin.

public void setFieldsEnabledForAdmin(final ViewDefinitionState view) {
    if (securityService.hasCurrentUserRole("ROLE_ADMIN")) {
        LookupComponent lookupComponent = (LookupComponent) view.getComponentByReference(UserFieldsPL.PRODUCTION_LINE);
        lookupComponent.setEnabled(true);
        lookupComponent.requestComponentUpdateState();
    }
}
Also used : LookupComponent(com.qcadoo.view.api.components.LookupComponent)

Aggregations

LookupComponent (com.qcadoo.view.api.components.LookupComponent)277 Entity (com.qcadoo.model.api.Entity)182 FieldComponent (com.qcadoo.view.api.components.FieldComponent)105 FormComponent (com.qcadoo.view.api.components.FormComponent)102 FilterValueHolder (com.qcadoo.view.api.components.lookup.FilterValueHolder)69 BigDecimal (java.math.BigDecimal)16 CheckBoxComponent (com.qcadoo.view.api.components.CheckBoxComponent)12 GridComponent (com.qcadoo.view.api.components.GridComponent)11 WindowComponent (com.qcadoo.view.api.components.WindowComponent)8 RibbonActionItem (com.qcadoo.view.api.ribbon.RibbonActionItem)7 Date (java.util.Date)6 JSONObject (org.json.JSONObject)6 ComponentState (com.qcadoo.view.api.ComponentState)5 AwesomeDynamicListComponent (com.qcadoo.view.api.components.AwesomeDynamicListComponent)5 JSONException (org.json.JSONException)5 DataDefinition (com.qcadoo.model.api.DataDefinition)3 RibbonGroup (com.qcadoo.view.api.ribbon.RibbonGroup)3 Optional (com.google.common.base.Optional)2 ProductFields (com.qcadoo.mes.basic.constants.ProductFields)2 DataDefinitionService (com.qcadoo.model.api.DataDefinitionService)2