Search in sources :

Example 91 with WindowComponent

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

the class OrderTechnologicalProcessesSingleOrderListHooks method updateRibbonState.

private void updateRibbonState(final ViewDefinitionState view) {
    WindowComponent window = (WindowComponent) view.getComponentByReference(QcadooViewConstants.L_WINDOW);
    RibbonGroup orderTechnologicalProcessesGroup = window.getRibbon().getGroupByName(L_ORDER_TECHNOLOGICAL_PROCESSES);
    RibbonActionItem generateOrderTechnologicalProcessesActionItem = orderTechnologicalProcessesGroup.getItemByName(L_GENERATE_ORDER_TECHNOLOGICAL_PROCESSES);
    RibbonActionItem divideOrderTechnologicalProcessActionItem = orderTechnologicalProcessesGroup.getItemByName(L_DIVIDE_ORDER_TECHNOLOGICAL_PROCESS);
    FormComponent orderForm = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
    GridComponent orderTechnologicalProcessesGrid = (GridComponent) view.getComponentByReference(QcadooViewConstants.L_GRID);
    Set<Long> orderTechnologicalProcessesIds = orderTechnologicalProcessesGrid.getSelectedEntitiesIds();
    boolean isOrderTechnologicalProcessSelected = orderTechnologicalProcessesIds.size() == 1;
    boolean isOrderStateValid = false;
    Entity order = orderForm.getEntity();
    Long orderId = order.getId();
    if (Objects.nonNull(orderId)) {
        order = order.getDataDefinition().get(orderId);
        isOrderStateValid = !orderTechnologicalProcessService.checkOrderState(order);
    }
    generateOrderTechnologicalProcessesActionItem.setEnabled(isOrderStateValid);
    generateOrderTechnologicalProcessesActionItem.requestUpdate(true);
    divideOrderTechnologicalProcessActionItem.setEnabled(isOrderTechnologicalProcessSelected && isOrderStateValid);
    divideOrderTechnologicalProcessActionItem.requestUpdate(true);
}
Also used : FormComponent(com.qcadoo.view.api.components.FormComponent) Entity(com.qcadoo.model.api.Entity) RibbonGroup(com.qcadoo.view.api.ribbon.RibbonGroup) WindowComponent(com.qcadoo.view.api.components.WindowComponent) GridComponent(com.qcadoo.view.api.components.GridComponent) RibbonActionItem(com.qcadoo.view.api.ribbon.RibbonActionItem)

Example 92 with WindowComponent

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

the class ProductsToIssueDetailsHooks method onBeforeRender.

public void onBeforeRender(final ViewDefinitionState view) {
    FormComponent productToIssueForm = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
    FieldComponent locationFromLabel = (FieldComponent) view.getComponentByReference("locationFromLabel");
    FieldComponent helperField = (FieldComponent) view.getComponentByReference("generated");
    Entity helper = productToIssueForm.getEntity();
    Entity locationFrom = helper.getBelongsToField("locationFrom");
    if (Objects.nonNull(locationFrom)) {
        locationFromLabel.setFieldValue(translationService.translate("productFlowThruDivision.productsToIssueHelperDetails.window.mainTab.form.locationFromLabel.label", LocaleContextHolder.getLocale(), locationFrom.getStringField(LocationFields.NUMBER)));
        locationFromLabel.setRequired(true);
    }
    if (view.isViewAfterRedirect() && helper.getHasManyField("issues").isEmpty()) {
        String idsStr = helper.getStringField("productsToIssueIds");
        String[] split = idsStr.split(",");
        List<Long> ids = Lists.newArrayList(split).stream().map(Long::valueOf).collect(Collectors.toList());
        Multimap<Entity, Entity> locationFromProductMultimap = HashMultimap.create();
        Multimap<Entity, Entity> locationToProductMultimap = HashMultimap.create();
        List<Entity> createdIssues = Lists.newArrayList();
        for (Long id : ids) {
            Entity productToIssue = getProductToIssueDD().get(id);
            Entity product = productToIssue.getBelongsToField(ProductsToIssueFields.PRODUCT);
            locationFromProductMultimap.put(productToIssue.getBelongsToField(ProductsToIssueFields.WAREHOUSE_ISSUE).getBelongsToField(WarehouseIssueFields.PLACE_OF_ISSUE), product);
            locationToProductMultimap.put(productToIssue.getBelongsToField(ProductsToIssueFields.LOCATION), product);
            createdIssues.add(createIssue(getIssueDD(), productToIssue));
        }
        Map<Long, Map<Long, BigDecimal>> stockForWarehousesFrom = getStockForWarehouses(locationFromProductMultimap);
        Map<Long, Map<Long, BigDecimal>> stockForWarehousesTo = getStockForWarehouses(locationToProductMultimap);
        fillLocationQuantity(createdIssues, stockForWarehousesFrom, stockForWarehousesTo);
        helper.setField("issues", sortIssuesBasedOnFilter(view, createdIssues));
        productToIssueForm.setEntity(helper);
    } else {
        List<Entity> issues = helper.getHasManyField("issues");
        if (!issues.isEmpty() && issues.stream().allMatch(issue -> Objects.nonNull(issue.getId()))) {
            WindowComponent window = (WindowComponent) view.getComponentByReference(QcadooViewConstants.L_WINDOW);
            Ribbon ribbon = window.getRibbon();
            RibbonGroup group = ribbon.getGroupByName("actions");
            RibbonActionItem createDocumentsItem = group.getItemByName("createDocuments");
            RibbonActionItem createDocumentsAndGoBackItem = group.getItemByName("createDocumentsAndGoBack");
            createDocumentsItem.setEnabled(!Boolean.valueOf((String) helperField.getFieldValue()));
            createDocumentsItem.requestUpdate(true);
            createDocumentsAndGoBackItem.setEnabled(!Boolean.valueOf((String) helperField.getFieldValue()));
            createDocumentsAndGoBackItem.requestUpdate(true);
        }
        fillQuantitiesInAdditionalUnit(view);
    }
    fillUnits(view);
}
Also used : LocaleContextHolder(org.springframework.context.i18n.LocaleContextHolder) Arrays(java.util.Arrays) ProductsToIssueFields(com.qcadoo.mes.productFlowThruDivision.warehouseIssue.constans.ProductsToIssueFields) ResourceStockDtoFields(com.qcadoo.mes.materialFlowResources.constants.ResourceStockDtoFields) Autowired(org.springframework.beans.factory.annotation.Autowired) BigDecimalUtils(com.qcadoo.model.api.BigDecimalUtils) BigDecimal(java.math.BigDecimal) JSONException(org.json.JSONException) JSONObject(org.json.JSONObject) HashMultimap(com.google.common.collect.HashMultimap) Optional(com.google.common.base.Optional) Map(java.util.Map) RibbonActionItem(com.qcadoo.view.api.ribbon.RibbonActionItem) RibbonGroup(com.qcadoo.view.api.ribbon.RibbonGroup) WarehouseIssueParameterService(com.qcadoo.mes.productFlowThruDivision.warehouseIssue.WarehouseIssueParameterService) Collectors(java.util.stream.Collectors) DataDefinition(com.qcadoo.model.api.DataDefinition) Objects(java.util.Objects) List(java.util.List) Entity(com.qcadoo.model.api.Entity) StringUtils.isNotBlank(org.apache.commons.lang3.StringUtils.isNotBlank) FieldComponent(com.qcadoo.view.api.components.FieldComponent) CalculationQuantityService(com.qcadoo.mes.basic.CalculationQuantityService) WindowComponent(com.qcadoo.view.api.components.WindowComponent) DataDefinitionService(com.qcadoo.model.api.DataDefinitionService) IssueFields(com.qcadoo.mes.productFlowThruDivision.warehouseIssue.constans.IssueFields) QcadooViewConstants(com.qcadoo.view.constants.QcadooViewConstants) OrderFields(com.qcadoo.mes.orders.constants.OrderFields) Ribbon(com.qcadoo.view.api.ribbon.Ribbon) Multimap(com.google.common.collect.Multimap) OrdersConstants(com.qcadoo.mes.orders.constants.OrdersConstants) ArrayList(java.util.ArrayList) ViewDefinitionState(com.qcadoo.view.api.ViewDefinitionState) Lists(com.google.common.collect.Lists) Service(org.springframework.stereotype.Service) FormComponent(com.qcadoo.view.api.components.FormComponent) WarehouseIssueFields(com.qcadoo.mes.productFlowThruDivision.warehouseIssue.constans.WarehouseIssueFields) LocationFields(com.qcadoo.mes.materialFlow.constants.LocationFields) LinkedHashSet(java.util.LinkedHashSet) AwesomeDynamicListComponent(com.qcadoo.view.api.components.AwesomeDynamicListComponent) MaterialFlowResourcesService(com.qcadoo.mes.materialFlowResources.MaterialFlowResourcesService) TranslationService(com.qcadoo.localization.api.TranslationService) Maps(com.google.common.collect.Maps) Either(com.qcadoo.commons.functional.Either) NumberService(com.qcadoo.model.api.NumberService) ProductFields(com.qcadoo.mes.basic.constants.ProductFields) ProductFlowThruDivisionConstants(com.qcadoo.mes.productFlowThruDivision.constants.ProductFlowThruDivisionConstants) Comparator(java.util.Comparator) StringUtils(org.springframework.util.StringUtils) FormComponent(com.qcadoo.view.api.components.FormComponent) Entity(com.qcadoo.model.api.Entity) RibbonGroup(com.qcadoo.view.api.ribbon.RibbonGroup) WindowComponent(com.qcadoo.view.api.components.WindowComponent) FieldComponent(com.qcadoo.view.api.components.FieldComponent) Ribbon(com.qcadoo.view.api.ribbon.Ribbon) Map(java.util.Map) RibbonActionItem(com.qcadoo.view.api.ribbon.RibbonActionItem)

Example 93 with WindowComponent

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

the class WarehouseIssueDetailHooks method updateRibbonState.

private void updateRibbonState(final ViewDefinitionState view) {
    WindowComponent window = (WindowComponent) view.getComponentByReference(QcadooViewConstants.L_WINDOW);
    Ribbon ribbon = window.getRibbon();
    RibbonGroup group = ribbon.getGroupByName("issue");
    RibbonActionItem productsToIssue = group.getItemByName("productsToIssue");
    RibbonGroup groupCopyProductsToIssue = ribbon.getGroupByName("copyissue");
    RibbonActionItem copyProductsToIssue = groupCopyProductsToIssue.getItemByName("copyProductsToIssue");
    if (!warehouseIssueParameterService.issueForOrder()) {
        productsToIssue.setEnabled(false);
        productsToIssue.setMessage("productFlowThruDivision.issue.activeWhenIssueForOrder");
        productsToIssue.requestUpdate(true);
        window.requestRibbonRender();
    }
    String state = (String) view.getComponentByReference(WarehouseIssueFields.STATE).getFieldValue();
    if (state.equals(WarehouseIssueStringValues.DISCARD) || state.equals(WarehouseIssueStringValues.COMPLETED)) {
        copyProductsToIssue.setEnabled(false);
        copyProductsToIssue.requestUpdate(true);
        window.requestRibbonRender();
    }
}
Also used : RibbonGroup(com.qcadoo.view.api.ribbon.RibbonGroup) WindowComponent(com.qcadoo.view.api.components.WindowComponent) Ribbon(com.qcadoo.view.api.ribbon.Ribbon) RibbonActionItem(com.qcadoo.view.api.ribbon.RibbonActionItem)

Example 94 with WindowComponent

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

the class ProductsToIssueListListeners method changeRibbonState.

private void changeRibbonState(final ViewDefinitionState view) {
    WindowComponent window = (WindowComponent) view.getComponentByReference(QcadooViewConstants.L_WINDOW);
    RibbonGroup group = window.getRibbon().getGroupByName("warehouseIssues");
    RibbonActionItem copyProducts = group.getItemByName("copyProducts");
    RibbonActionItem correctReservations = group.getItemByName("correctReservations");
    GridComponent grid = (GridComponent) view.getComponentByReference(QcadooViewConstants.L_GRID);
    DataDefinition productsToIssueDD = dataDefinitionService.get(ProductFlowThruDivisionConstants.PLUGIN_IDENTIFIER, ProductFlowThruDivisionConstants.MODEL_PRODUCTS_TO_ISSUE);
    Set<Long> selectedEntitiesIds = grid.getSelectedEntitiesIds();
    boolean enabled = !selectedEntitiesIds.isEmpty();
    boolean correctionEnabled = !selectedEntitiesIds.isEmpty();
    if (enabled) {
        Entity warehouse = null;
        Entity location = null;
        for (Long id : selectedEntitiesIds) {
            Entity productToIssue = productsToIssueDD.get(id);
            if (productToIssue != null) {
                Entity warehouseIssue = productToIssue.getBelongsToField(ProductsToIssueFields.WAREHOUSE_ISSUE);
                String state = warehouseIssue.getStringField(WarehouseIssueFields.STATE);
                Entity productLocation = productToIssue.getBelongsToField(ProductsToIssueFields.LOCATION);
                if (location == null) {
                    location = productLocation;
                } else {
                    if (productLocation != null && !location.getId().equals(productLocation.getId())) {
                        correctionEnabled = false;
                    }
                }
                if (WarehouseIssueState.DISCARD.getStringValue().equals(state) || WarehouseIssueState.COMPLETED.getStringValue().equals(state)) {
                    enabled = false;
                } else {
                    Entity issueWarehouse = warehouseIssue.getBelongsToField(WarehouseIssueFields.PLACE_OF_ISSUE);
                    if (warehouse == null) {
                        warehouse = issueWarehouse;
                    } else {
                        if (!warehouse.getId().equals(issueWarehouse.getId())) {
                            enabled = false;
                            correctionEnabled = false;
                        }
                    }
                }
            } else {
                enabled = false;
            }
        }
    }
    correctReservations.setEnabled(correctionEnabled);
    correctReservations.requestUpdate(true);
    copyProducts.setEnabled(enabled);
    copyProducts.requestUpdate(true);
}
Also used : Entity(com.qcadoo.model.api.Entity) RibbonGroup(com.qcadoo.view.api.ribbon.RibbonGroup) WindowComponent(com.qcadoo.view.api.components.WindowComponent) GridComponent(com.qcadoo.view.api.components.GridComponent) DataDefinition(com.qcadoo.model.api.DataDefinition) RibbonActionItem(com.qcadoo.view.api.ribbon.RibbonActionItem)

Example 95 with WindowComponent

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

the class ProductDetailsHooksPC method updateButtonsState.

public void updateButtonsState(final ViewDefinitionState view) {
    FormComponent productForm = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
    WindowComponent window = (WindowComponent) view.getComponentByReference(QcadooViewConstants.L_WINDOW);
    Ribbon ribbon = window.getRibbon();
    RibbonGroup showProductionTrackingsRibbonGroup = ribbon.getGroupByName(L_SHOW_PRODUCTION_TRACKINGS);
    RibbonActionItem showProductionTrackingsForProductRibbonActionItem = showProductionTrackingsRibbonGroup.getItemByName(L_SHOW_PRODUCTION_TRACKINGS_FOR_PRODUCT);
    RibbonActionItem showProductionTrackingsForProductGroupedRibbonActionItem = showProductionTrackingsRibbonGroup.getItemByName(L_SHOW_PRODUCTION_TRACKINGS_FOR_PRODUCT_GROUPED);
    Long productionTrackingId = productForm.getEntityId();
    boolean isSaved = (productionTrackingId != null);
    showProductionTrackingsForProductRibbonActionItem.setEnabled(isSaved);
    showProductionTrackingsForProductGroupedRibbonActionItem.setEnabled(isSaved);
    showProductionTrackingsForProductRibbonActionItem.requestUpdate(true);
    showProductionTrackingsForProductGroupedRibbonActionItem.requestUpdate(true);
}
Also used : FormComponent(com.qcadoo.view.api.components.FormComponent) RibbonGroup(com.qcadoo.view.api.ribbon.RibbonGroup) WindowComponent(com.qcadoo.view.api.components.WindowComponent) Ribbon(com.qcadoo.view.api.ribbon.Ribbon) RibbonActionItem(com.qcadoo.view.api.ribbon.RibbonActionItem)

Aggregations

WindowComponent (com.qcadoo.view.api.components.WindowComponent)105 RibbonActionItem (com.qcadoo.view.api.ribbon.RibbonActionItem)93 RibbonGroup (com.qcadoo.view.api.ribbon.RibbonGroup)75 FormComponent (com.qcadoo.view.api.components.FormComponent)51 Entity (com.qcadoo.model.api.Entity)46 Ribbon (com.qcadoo.view.api.ribbon.Ribbon)31 GridComponent (com.qcadoo.view.api.components.GridComponent)28 FieldComponent (com.qcadoo.view.api.components.FieldComponent)12 LookupComponent (com.qcadoo.view.api.components.LookupComponent)8 EntityTree (com.qcadoo.model.api.EntityTree)4 CheckBoxComponent (com.qcadoo.view.api.components.CheckBoxComponent)3 JSONObject (org.json.JSONObject)3 Optional (com.google.common.base.Optional)2 AssignmentToShiftState (com.qcadoo.mes.assignmentToShift.states.constants.AssignmentToShiftState)2 DataDefinition (com.qcadoo.model.api.DataDefinition)2 ViewDefinitionState (com.qcadoo.view.api.ViewDefinitionState)2 TreeComponent (com.qcadoo.view.api.components.TreeComponent)2 Date (java.util.Date)2 HashMultimap (com.google.common.collect.HashMultimap)1 Lists (com.google.common.collect.Lists)1