Search in sources :

Example 71 with FormComponent

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

use of com.qcadoo.view.api.components.FormComponent 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)

Example 73 with FormComponent

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

the class OperationDetailsHooks method disableWorkstationsTabFieldsIfOperationIsNotSaved.

private void disableWorkstationsTabFieldsIfOperationIsNotSaved(ViewDefinitionState view) {
    FormComponent operationForm = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
    GridComponent workstations = (GridComponent) view.getComponentByReference(OperationFields.WORKSTATIONS);
    if (operationForm.getEntityId() == null) {
        changedEnabledFields(view, L_WORKSTATIONS_TAB_FIELDS, false);
        changeEnabledLookups(view, L_WORKSTATIONS_TAB_LOOKUPS, Lists.newArrayList(""));
        workstations.setEnabled(false);
    } else {
        changedEnabledFields(view, L_WORKSTATIONS_TAB_FIELDS, true);
        changeEnabledLookups(view, L_WORKSTATIONS_TAB_LOOKUPS, L_WORKSTATIONS_TAB_LOOKUPS);
        workstations.setEnabled(true);
        setWorkstationsTabFields(view);
    }
}
Also used : FormComponent(com.qcadoo.view.api.components.FormComponent) GridComponent(com.qcadoo.view.api.components.GridComponent)

Example 74 with FormComponent

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

the class OperationSkillDetailsHooks method onBeforeRender.

public void onBeforeRender(final ViewDefinitionState view) {
    FormComponent operationSkillForm = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
    LookupComponent skillLookup = (LookupComponent) view.getComponentByReference(OperationSkillFields.SKILL);
    Entity operationSkill = operationSkillForm.getEntity();
    Entity operation = operationSkill.getBelongsToField(OperationSkillFields.OPERATION);
    filterSkillLookup(skillLookup, operation);
    fillMaxSkill(view, skillLookup);
}
Also used : FormComponent(com.qcadoo.view.api.components.FormComponent) Entity(com.qcadoo.model.api.Entity) LookupComponent(com.qcadoo.view.api.components.LookupComponent)

Example 75 with FormComponent

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

the class TechnologyDetailsHooks method disableFieldTechnologyFormAndEnabledMaster.

public void disableFieldTechnologyFormAndEnabledMaster(final ViewDefinitionState view) {
    FormComponent technologyForm = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
    FieldComponent masterField = (FieldComponent) view.getComponentByReference(TechnologyFields.MASTER);
    LookupComponent technologyGroupLookup = (LookupComponent) view.getComponentByReference(TechnologyFields.TECHNOLOGY_GROUP);
    boolean disabled = false;
    boolean masterDisabled = false;
    boolean technologyGroupEnabled = false;
    Long technologyId = technologyForm.getEntityId();
    if (Objects.nonNull(technologyId)) {
        Entity technology = getTechnologyDD().get(technologyId);
        if (Objects.isNull(technology)) {
            return;
        }
        String state = technology.getStringField(TechnologyFields.STATE);
        boolean isTemplateAccepted = technology.getBooleanField(TechnologyFields.IS_TEMPLATE_ACCEPTED);
        if (isTemplateAccepted || !TechnologyState.DRAFT.getStringValue().equals(state)) {
            disabled = true;
        }
        if (TechnologyState.ACCEPTED.getStringValue().equals(state)) {
            masterDisabled = true;
        }
        if (TechnologyState.ACCEPTED.getStringValue().equals(state) || TechnologyState.CHECKED.getStringValue().equals(state) || TechnologyState.DRAFT.getStringValue().equals(state)) {
            technologyGroupEnabled = true;
        }
    }
    technologyForm.setFormEnabled(!disabled);
    masterField.setEnabled(masterDisabled);
    masterField.requestComponentUpdateState();
    technologyGroupLookup.setEnabled(technologyGroupEnabled);
    technologyGroupLookup.requestComponentUpdateState();
}
Also used : 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)

Aggregations

FormComponent (com.qcadoo.view.api.components.FormComponent)644 Entity (com.qcadoo.model.api.Entity)501 FieldComponent (com.qcadoo.view.api.components.FieldComponent)183 LookupComponent (com.qcadoo.view.api.components.LookupComponent)104 GridComponent (com.qcadoo.view.api.components.GridComponent)83 BigDecimal (java.math.BigDecimal)55 WindowComponent (com.qcadoo.view.api.components.WindowComponent)52 FilterValueHolder (com.qcadoo.view.api.components.lookup.FilterValueHolder)45 RibbonActionItem (com.qcadoo.view.api.ribbon.RibbonActionItem)42 CheckBoxComponent (com.qcadoo.view.api.components.CheckBoxComponent)39 RibbonGroup (com.qcadoo.view.api.ribbon.RibbonGroup)36 Date (java.util.Date)33 DataDefinition (com.qcadoo.model.api.DataDefinition)29 AwesomeDynamicListComponent (com.qcadoo.view.api.components.AwesomeDynamicListComponent)28 JSONObject (org.json.JSONObject)28 ComponentState (com.qcadoo.view.api.ComponentState)27 Transactional (org.springframework.transaction.annotation.Transactional)20 ViewDefinitionState (com.qcadoo.view.api.ViewDefinitionState)17 Optional (com.google.common.base.Optional)16 Ribbon (com.qcadoo.view.api.ribbon.Ribbon)16