Search in sources :

Example 81 with RibbonGroup

use of com.qcadoo.view.api.ribbon.RibbonGroup in project mes by qcadoo.

the class OrderTechnologicalProcessDetailsHooks method updateRibbonState.

private void updateRibbonState(final ViewDefinitionState view, final Entity orderTechnologicalProcess) {
    WindowComponent window = (WindowComponent) view.getComponentByReference(QcadooViewConstants.L_WINDOW);
    RibbonGroup actionsGroup = window.getRibbon().getGroupByName(L_ACTIONS);
    RibbonActionItem deleteActionItem = actionsGroup.getItemByName(L_DELETE);
    Entity order = orderTechnologicalProcess.getBelongsToField(OrderTechnologicalProcessFields.ORDER);
    boolean isOrderStateValid = !checkOrderState(order);
    deleteActionItem.setEnabled(isOrderStateValid);
    deleteActionItem.requestUpdate(true);
}
Also used : Entity(com.qcadoo.model.api.Entity) RibbonGroup(com.qcadoo.view.api.ribbon.RibbonGroup) WindowComponent(com.qcadoo.view.api.components.WindowComponent) RibbonActionItem(com.qcadoo.view.api.ribbon.RibbonActionItem)

Example 82 with RibbonGroup

use of com.qcadoo.view.api.ribbon.RibbonGroup 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 83 with RibbonGroup

use of com.qcadoo.view.api.ribbon.RibbonGroup 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 84 with RibbonGroup

use of com.qcadoo.view.api.ribbon.RibbonGroup 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 85 with RibbonGroup

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

Aggregations

RibbonGroup (com.qcadoo.view.api.ribbon.RibbonGroup)92 RibbonActionItem (com.qcadoo.view.api.ribbon.RibbonActionItem)86 WindowComponent (com.qcadoo.view.api.components.WindowComponent)75 Ribbon (com.qcadoo.view.api.ribbon.Ribbon)37 FormComponent (com.qcadoo.view.api.components.FormComponent)36 Entity (com.qcadoo.model.api.Entity)34 GridComponent (com.qcadoo.view.api.components.GridComponent)23 FieldComponent (com.qcadoo.view.api.components.FieldComponent)9 ViewDefinitionState (com.qcadoo.view.api.ViewDefinitionState)3 LookupComponent (com.qcadoo.view.api.components.LookupComponent)3 JSONObject (org.json.JSONObject)3 AssignmentToShiftState (com.qcadoo.mes.assignmentToShift.states.constants.AssignmentToShiftState)2 DataDefinition (com.qcadoo.model.api.DataDefinition)2 CheckBoxComponent (com.qcadoo.view.api.components.CheckBoxComponent)2 QcadooViewConstants (com.qcadoo.view.constants.QcadooViewConstants)2 Optional (com.google.common.base.Optional)1 HashMultimap (com.google.common.collect.HashMultimap)1 Lists (com.google.common.collect.Lists)1 Maps (com.google.common.collect.Maps)1 Multimap (com.google.common.collect.Multimap)1