Search in sources :

Example 11 with LookupComponent

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

the class ModelCardProductDetailsListeners method fillDefaultTechnology.

public void fillDefaultTechnology(final ViewDefinitionState view, final ComponentState state, final String[] args) {
    LookupComponent productLookup = (LookupComponent) view.getComponentByReference(ModelCardProductFields.PRODUCT);
    Entity product = productLookup.getEntity();
    LookupComponent technologyLookup = (LookupComponent) view.getComponentByReference(ModelCardProductFields.TECHNOLOGY);
    if (product != null) {
        Entity defaultTechnology = technologyServiceO.getDefaultTechnology(product);
        if (defaultTechnology != null) {
            technologyLookup.setFieldValue(defaultTechnology.getId());
        } else {
            Entity productFamily = product.getBelongsToField(ProductFields.PARENT);
            if (productFamily != null) {
                defaultTechnology = technologyServiceO.getDefaultTechnology(productFamily);
                if (defaultTechnology != null) {
                    technologyLookup.setFieldValue(defaultTechnology.getId());
                } else {
                    technologyLookup.setFieldValue(null);
                }
            } else {
                technologyLookup.setFieldValue(null);
            }
        }
    } else {
        technologyLookup.setFieldValue(null);
    }
    technologyLookup.requestComponentUpdateState();
}
Also used : Entity(com.qcadoo.model.api.Entity) LookupComponent(com.qcadoo.view.api.components.LookupComponent)

Example 12 with LookupComponent

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

the class ProductsIntermediateInDetailsHooks method onProductionFlowComponentChange.

public void onProductionFlowComponentChange(final ViewDefinitionState view, final ComponentState componentState, final String[] args) {
    LookupComponent productsFlowLocationLookup = (LookupComponent) view.getComponentByReference(TechnologyFieldsPFTD.PRODUCTS_FLOW_LOCATION);
    productsFlowLocationLookup.setFieldValue(null);
}
Also used : LookupComponent(com.qcadoo.view.api.components.LookupComponent)

Example 13 with LookupComponent

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

the class UseReplacementHooks method fillFields.

private void fillFields(ViewDefinitionState view) {
    if (view.isViewAfterRedirect()) {
        JSONObject context = view.getJsonContext();
        LookupComponent basicProductComponent = (LookupComponent) view.getComponentByReference(BASIC_PRODUCT);
        LookupComponent productComponent = (LookupComponent) view.getComponentByReference(PRODUCT);
        if (context.has(L_WINDOW_MAIN_TAB_FORM_BASIC_PRODUCT)) {
            try {
                basicProductComponent.setFieldValue(context.getLong(L_WINDOW_MAIN_TAB_FORM_BASIC_PRODUCT));
                FilterValueHolder filterValueHolder = productComponent.getFilterValue();
                filterValueHolder.put("BASIC_PRODUCT_ID", context.getLong(L_WINDOW_MAIN_TAB_FORM_BASIC_PRODUCT));
                productComponent.setFilterValue(filterValueHolder);
            } catch (JSONException ex) {
                throw new RuntimeException(ex);
            }
        }
    }
}
Also used : FilterValueHolder(com.qcadoo.view.api.components.lookup.FilterValueHolder) JSONObject(org.json.JSONObject) LookupComponent(com.qcadoo.view.api.components.LookupComponent) JSONException(org.json.JSONException)

Example 14 with LookupComponent

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

the class UsedBatchDetailsHooks method onBeforeRender.

public void onBeforeRender(final ViewDefinitionState view) {
    FormComponent form = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
    Entity usedBatch = form.getEntity();
    Entity trackingOperationProductInComponent = usedBatch.getBelongsToField(UsedBatchFields.TRACKING_OPERATION_PRODUCT_IN_COMPONENT);
    if (view.isViewAfterRedirect() && Objects.nonNull(trackingOperationProductInComponent)) {
        Entity product = trackingOperationProductInComponent.getBelongsToField(TrackingOperationProductInComponentFields.PRODUCT);
        FieldComponent unitField = (FieldComponent) view.getComponentByReference(L_UNIT);
        unitField.setFieldValue(product.getStringField(ProductFields.UNIT));
        unitField.requestComponentUpdateState();
        LookupComponent batchLookup = (LookupComponent) view.getComponentByReference(UsedBatchFields.BATCH);
        FilterValueHolder batchFilterValueHolder = batchLookup.getFilterValue();
        batchFilterValueHolder.put(L_PRODUCT_ID, product.getId());
        batchLookup.setFilterValue(batchFilterValueHolder);
    }
}
Also used : FilterValueHolder(com.qcadoo.view.api.components.lookup.FilterValueHolder) FormComponent(com.qcadoo.view.api.components.FormComponent) Entity(com.qcadoo.model.api.Entity) LookupComponent(com.qcadoo.view.api.components.LookupComponent) FieldComponent(com.qcadoo.view.api.components.FieldComponent)

Example 15 with LookupComponent

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

the class TrackingOperationProductOutComponentDetailsHooks method fillStorageLocation.

private void fillStorageLocation(final ViewDefinitionState view) {
    FormComponent trackingOperationProductOutComponentForm = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
    Entity trackingOperationProductOutComponent = trackingOperationProductOutComponentForm.getEntity();
    if (view.isViewAfterRedirect()) {
        LookupComponent storageLocationLookup = (LookupComponent) view.getComponentByReference(L_STORAGE_LOCATION);
        Entity productionTracking = trackingOperationProductOutComponent.getBelongsToField(TrackingOperationProductOutComponentFields.PRODUCTION_TRACKING);
        Entity order = productionTracking.getBelongsToField(ProductionTrackingFields.ORDER);
        Entity product = trackingOperationProductOutComponent.getBelongsToField(TrackingOperationProductOutComponentFields.PRODUCT);
        FilterValueHolder storageLocationFilterValueHolder = storageLocationLookup.getFilterValue();
        Entity bpcq = basicProductionCountingService.getProductionCountingQuantityDD().find().add(SearchRestrictions.eq(ProductionCountingQuantityFields.ORDER + L_ID, order.getId())).add(SearchRestrictions.eq(ProductionCountingQuantityFields.ROLE, ProductionCountingQuantityRole.PRODUCED.getStringValue())).add(SearchRestrictions.eq(ProductionCountingQuantityFields.PRODUCT + L_ID, product.getId())).setMaxResults(1).uniqueResult();
        if (ProductionCountingQuantityTypeOfMaterial.FINAL_PRODUCT.getStringValue().equals(bpcq.getStringField(ProductionCountingQuantityFields.TYPE_OF_MATERIAL))) {
            if (Objects.nonNull(bpcq.getBelongsToField(ProductionCountingQuantityFields.PRODUCTS_INPUT_LOCATION))) {
                storageLocationFilterValueHolder.put(L_LOCATION_ID, bpcq.getBelongsToField(ProductionCountingQuantityFields.PRODUCTS_INPUT_LOCATION).getId());
                storageLocationFilterValueHolder.put(L_PRODUCT_ID, order.getBelongsToField(OrderFields.PRODUCT).getId());
                Optional<Entity> option = findStorageLocationForProduct(order.getBelongsToField(OrderFields.PRODUCT), bpcq.getBelongsToField(ProductionCountingQuantityFields.PRODUCTS_INPUT_LOCATION));
                if (option.isPresent()) {
                    if (Objects.isNull(storageLocationLookup.getEntity())) {
                        storageLocationLookup.setFieldValue(option.get().getId());
                        storageLocationLookup.requestComponentUpdateState();
                    }
                    storageLocationLookup.setEnabled(false);
                }
            } else if (storageLocationFilterValueHolder.has(L_LOCATION_ID)) {
                storageLocationFilterValueHolder.remove(L_LOCATION_ID);
            }
        } else {
            if (Objects.nonNull(bpcq.getBelongsToField(ProductionCountingQuantityFields.PRODUCTS_FLOW_LOCATION))) {
                storageLocationFilterValueHolder.put(L_LOCATION_ID, bpcq.getBelongsToField(ProductionCountingQuantityFields.PRODUCTS_FLOW_LOCATION).getId());
                storageLocationFilterValueHolder.put(L_PRODUCT_ID, bpcq.getBelongsToField(ProductionCountingQuantityFields.PRODUCT).getId());
                Optional<Entity> option = findStorageLocationForProduct(bpcq.getBelongsToField(ProductionCountingQuantityFields.PRODUCT), bpcq.getBelongsToField(ProductionCountingQuantityFields.PRODUCTS_FLOW_LOCATION));
                if (option.isPresent()) {
                    if (Objects.isNull(storageLocationLookup.getEntity())) {
                        storageLocationLookup.setFieldValue(option.get().getId());
                        storageLocationLookup.requestComponentUpdateState();
                    }
                    storageLocationLookup.setEnabled(false);
                }
            } else if (storageLocationFilterValueHolder.has(L_LOCATION_ID)) {
                storageLocationFilterValueHolder.remove(L_LOCATION_ID);
            }
        }
        storageLocationLookup.setFilterValue(storageLocationFilterValueHolder);
    }
}
Also used : FilterValueHolder(com.qcadoo.view.api.components.lookup.FilterValueHolder) FormComponent(com.qcadoo.view.api.components.FormComponent) Entity(com.qcadoo.model.api.Entity) 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