Search in sources :

Example 36 with LookupComponent

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

the class OrderedProductDetailsHooksSN method disabledFieldWhenOfferIsSelected.

public void disabledFieldWhenOfferIsSelected(final ViewDefinitionState view) {
    LookupComponent offerLookup = (LookupComponent) view.getComponentByReference(OrderedProductFieldsSN.OFFER);
    Entity offer = offerLookup.getEntity();
    FieldComponent pricePerUnitField = (FieldComponent) view.getComponentByReference(OrderedProductFields.PRICE_PER_UNIT);
    FieldComponent totalPriceField = (FieldComponent) view.getComponentByReference(OrderedProductFields.TOTAL_PRICE);
    if (offer == null) {
        pricePerUnitField.setEnabled(true);
        totalPriceField.setEnabled(true);
    } else {
        pricePerUnitField.setEnabled(false);
        totalPriceField.setEnabled(false);
    }
}
Also used : Entity(com.qcadoo.model.api.Entity) LookupComponent(com.qcadoo.view.api.components.LookupComponent) FieldComponent(com.qcadoo.view.api.components.FieldComponent)

Example 37 with LookupComponent

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

the class ProductionTrackingDetailsHooksTSFPC method disabledSubcontractorFieldForState.

public void disabledSubcontractorFieldForState(final ViewDefinitionState view) {
    FormComponent productionTrackingForm = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
    LookupComponent subcontractorLookup = (LookupComponent) view.getComponentByReference(ProductionTrackingFieldsTSFPC.SUBCONTRACTOR);
    if (productionTrackingForm.getEntityId() == null) {
        return;
    }
    Entity productionTracking = getProductionTrackingFromDB(productionTrackingForm.getEntityId());
    String state = productionTracking.getStringField(ProductionTrackingFields.STATE);
    boolean isDraft = ProductionTrackingStateStringValues.DRAFT.equals(state);
    boolean isExternalSynchronized = productionTracking.getBooleanField(ProductionTrackingFields.IS_EXTERNAL_SYNCHRONIZED);
    subcontractorLookup.setEnabled(isDraft && isExternalSynchronized);
}
Also used : FormComponent(com.qcadoo.view.api.components.FormComponent) Entity(com.qcadoo.model.api.Entity) LookupComponent(com.qcadoo.view.api.components.LookupComponent)

Example 38 with LookupComponent

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

the class TechnologyService method generateTechnologyNumber.

public void generateTechnologyNumber(final ViewDefinitionState view, final ComponentState state, final String[] args) {
    if (!(state instanceof FieldComponent)) {
        throw new IllegalStateException("Component is not FieldComponentState");
    }
    FieldComponent numberField = (FieldComponent) view.getComponentByReference(TechnologyFields.NUMBER);
    LookupComponent productLookup = (LookupComponent) state;
    Entity product = productLookup.getEntity();
    if (Objects.isNull(product) || StringUtils.isNotEmpty(Objects.toString(numberField.getFieldValue(), ""))) {
        return;
    }
    numberField.setFieldValue(technologyNameAndNumberGenerator.generateNumber(product));
    numberField.requestComponentUpdateState();
}
Also used : Entity(com.qcadoo.model.api.Entity) LookupComponent(com.qcadoo.view.api.components.LookupComponent) FieldComponent(com.qcadoo.view.api.components.FieldComponent)

Example 39 with LookupComponent

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

the class ModifyTechnologyDetailsHooks method onBeforeRender.

public final void onBeforeRender(final ViewDefinitionState view) {
    FormComponent form = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
    if (view.isViewAfterRedirect()) {
        Entity mt = form.getEntity().getDataDefinition().get(form.getEntityId());
        LookupComponent replaceProductLookup = (LookupComponent) view.getComponentByReference(ModifyTechnologyHelperFields.REPLACE_PRODUCT);
        replaceProductLookup.setFieldValue(mt.getBelongsToField(L_MAIN_PRODUCT).getId());
        replaceProductLookup.requestComponentUpdateState();
        String selectedEntities = mt.getStringField(ModifyTechnologyHelperFields.SELECTED_ENTITIES);
        List<Long> ids = Lists.newArrayList(selectedEntities.split(",")).stream().map(Long::valueOf).collect(Collectors.toList());
        boolean sizeProduct = mt.getBooleanField("sizeProduct");
        if (sizeProduct) {
            List<Entity> producstBySize = dataDefinitionService.get(TechnologiesConstants.PLUGIN_IDENTIFIER, TechnologiesConstants.MODEL_PRODUCT_BY_SIZE_GROUP).find().add(SearchRestrictions.in(L_ID, ids)).list().getEntities();
            Set<BigDecimal> quantities = producstBySize.stream().map(op -> op.getDecimalField(L_QUANTITY)).collect(Collectors.toSet());
            if (quantities.size() == 1) {
                FieldComponent qnt = (FieldComponent) view.getComponentByReference(ModifyTechnologyHelperFields.REPLACE_PRODUCT_QUANTITY);
                qnt.setFieldValue(quantities.stream().findFirst().get());
                qnt.requestComponentUpdateState();
            }
        } else {
            List<Entity> opicDtos = dataDefinitionService.get(TechnologiesConstants.PLUGIN_IDENTIFIER, TechnologiesConstants.MODEL_OPERATION_PRODUCT_IN_COMPONENT_DTO).find().add(SearchRestrictions.in(L_ID, ids)).list().getEntities();
            Set<BigDecimal> quantities = opicDtos.stream().map(op -> op.getDecimalField(L_QUANTITY)).collect(Collectors.toSet());
            if (quantities.size() == 1) {
                FieldComponent qnt = (FieldComponent) view.getComponentByReference(ModifyTechnologyHelperFields.REPLACE_PRODUCT_QUANTITY);
                qnt.setFieldValue(quantities.stream().findFirst().get());
                qnt.requestComponentUpdateState();
            }
        }
        FieldComponent replaceProductUnit = (FieldComponent) view.getComponentByReference(L_REPLACE_PRODUCT_UNIT);
        replaceProductUnit.setFieldValue(mt.getBelongsToField(L_MAIN_PRODUCT).getStringField(ProductFields.UNIT));
    }
    setForm(view);
}
Also used : DataDefinitionService(com.qcadoo.model.api.DataDefinitionService) SearchRestrictions(com.qcadoo.model.api.search.SearchRestrictions) CheckBoxComponent(com.qcadoo.view.api.components.CheckBoxComponent) QcadooViewConstants(com.qcadoo.view.constants.QcadooViewConstants) Set(java.util.Set) Autowired(org.springframework.beans.factory.annotation.Autowired) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) ModifyTechnologyHelperFields(com.qcadoo.mes.technologies.constants.ModifyTechnologyHelperFields) BigDecimal(java.math.BigDecimal) Entity(com.qcadoo.model.api.Entity) ViewDefinitionState(com.qcadoo.view.api.ViewDefinitionState) List(java.util.List) Lists(com.google.common.collect.Lists) FieldComponent(com.qcadoo.view.api.components.FieldComponent) Service(org.springframework.stereotype.Service) FormComponent(com.qcadoo.view.api.components.FormComponent) LookupComponent(com.qcadoo.view.api.components.LookupComponent) ProductFields(com.qcadoo.mes.basic.constants.ProductFields) TechnologiesConstants(com.qcadoo.mes.technologies.constants.TechnologiesConstants) AwesomeDynamicListComponent(com.qcadoo.view.api.components.AwesomeDynamicListComponent) 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) BigDecimal(java.math.BigDecimal)

Example 40 with LookupComponent

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

the class OPICDetailsHooks method setAttributeTabState.

private void setAttributeTabState(ViewDefinitionState view) {
    FormComponent operationProductInComponentForm = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
    LookupComponent attributeLookup = (LookupComponent) view.getComponentByReference(OperationProductInComponentFields.ATTRIBUTE);
    if (Objects.isNull(attributeLookup)) {
        return;
    }
    LookupComponent productLookup = (LookupComponent) view.getComponentByReference(OperationProductInComponentFields.PRODUCT);
    Entity operationProductInComponent = operationProductInComponentForm.getEntity();
    Entity operationComponent = operationProductInComponent.getBelongsToField(OperationProductInComponentFields.OPERATION_COMPONENT);
    Entity technology = null;
    if (Objects.isNull(operationComponent)) {
        technology = operationProductInComponent.getBelongsToField(OperationProductInComponentFields.TECHNOLOGY);
    } else {
        technology = operationComponent.getBelongsToField(TechnologyOperationComponentFields.TECHNOLOGY);
    }
    Entity technologyProduct = technology.getBelongsToField(TechnologyFields.PRODUCT);
    if (ProductFamilyElementType.PRODUCTS_FAMILY.getStringValue().equals(technologyProduct.getField(ProductFields.ENTITY_TYPE)) && Objects.nonNull(productLookup.getEntity()) && ProductFamilyElementType.PRODUCTS_FAMILY.getStringValue().equals(productLookup.getEntity().getField(ProductFields.ENTITY_TYPE))) {
        attributeLookup.setEnabled(true);
    } else {
        attributeLookup.setFieldValue(null);
        attributeLookup.setEnabled(false);
    }
}
Also used : 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