Search in sources :

Example 16 with Ribbon

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

the class CopyOfTechnologyHooks method disableRibbonItem.

private void disableRibbonItem(final ViewDefinitionState view, final Entity order) {
    WindowComponent window = (WindowComponent) view.getComponentByReference(QcadooViewConstants.L_WINDOW);
    Ribbon ribbon = window.getRibbon();
    RibbonGroup technology = ribbon.getGroupByName(L_TECHNOLOGY);
    RibbonGroup status = ribbon.getGroupByName(L_STATUS);
    RibbonActionItem clearAndLoadPatternTechnology = technology.getItemByName(L_CLEAR_AND_LOAD_PATTERN_TECHNOLOGY);
    RibbonActionItem checkTechnology = status.getItemByName(L_CHECK_TECHNOLOGY);
    String state = order.getStringField(OrderFields.STATE);
    if (!OrderState.PENDING.getStringValue().equals(state)) {
        clearAndLoadPatternTechnology.setEnabled(false);
        clearAndLoadPatternTechnology.requestUpdate(true);
        checkTechnology.setEnabled(false);
        checkTechnology.requestUpdate(true);
    }
}
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 17 with Ribbon

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

the class OrderPackDetailsHooks method onBeforeRender.

public final void onBeforeRender(final ViewDefinitionState view) {
    LookupComponent orderLookup = (LookupComponent) view.getComponentByReference(OrderPackFields.ORDER);
    Entity order = orderLookup.getEntity();
    FieldComponent orderQuantity = (FieldComponent) view.getComponentByReference("orderQuantity");
    FieldComponent sumQuantityOrderPacksField = (FieldComponent) view.getComponentByReference("sumQuantityOrderPacks");
    FieldComponent orderQuantityUnit = (FieldComponent) view.getComponentByReference("orderQuantityUnit");
    FieldComponent sumQuantityOrderPacksUnit = (FieldComponent) view.getComponentByReference("sumQuantityOrderPacksUnit");
    FieldComponent quantityUnit = (FieldComponent) view.getComponentByReference("quantityUnit");
    if (order != null) {
        String orderState = order.getStringField(OrderFields.STATE);
        FormComponent form = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
        if (OrderState.COMPLETED.getStringValue().equals(orderState) || OrderState.DECLINED.getStringValue().equals(orderState) || OrderState.ABANDONED.getStringValue().equals(orderState) || OrderState.PENDING.getStringValue().equals(orderState)) {
            form.setFormEnabled(false);
            WindowComponent window = (WindowComponent) view.getComponentByReference(QcadooViewConstants.L_WINDOW);
            Ribbon ribbon = window.getRibbon();
            RibbonActionItem actionsSave = ribbon.getGroupByName(ACTIONS).getItemByName("save");
            RibbonActionItem actionsSaveNew = ribbon.getGroupByName(ACTIONS).getItemByName("saveNew");
            RibbonActionItem actionsSaveBack = ribbon.getGroupByName(ACTIONS).getItemByName("saveBack");
            actionsSave.setEnabled(false);
            actionsSave.requestUpdate(true);
            actionsSaveNew.setEnabled(false);
            actionsSaveNew.requestUpdate(true);
            actionsSaveBack.setEnabled(false);
            actionsSaveBack.requestUpdate(true);
        }
        orderQuantity.setFieldValue(numberService.format(order.getField(OrderFields.PLANNED_QUANTITY)));
        FieldComponent quantityField = (FieldComponent) view.getComponentByReference(OrderPackFields.QUANTITY);
        BigDecimal sumQuantityOrderPacks = orderPackService.getSumQuantityOrderPacksForOrderWithoutPack(order, form.getEntityId());
        Either<Exception, Optional<BigDecimal>> eitherNumber = BigDecimalUtils.tryParseAndIgnoreSeparator((String) quantityField.getFieldValue(), LocaleContextHolder.getLocale());
        if (eitherNumber.isRight() && eitherNumber.getRight().isPresent()) {
            sumQuantityOrderPacks = sumQuantityOrderPacks.add(eitherNumber.getRight().get(), numberService.getMathContext());
        }
        sumQuantityOrderPacksField.setFieldValue(numberService.format(sumQuantityOrderPacks));
        String unit = order.getBelongsToField(OrderFields.PRODUCT).getStringField(ProductFields.UNIT);
        orderQuantityUnit.setFieldValue(unit);
        sumQuantityOrderPacksUnit.setFieldValue(unit);
        quantityUnit.setFieldValue(unit);
    } else {
        orderQuantity.setFieldValue(null);
        sumQuantityOrderPacksField.setFieldValue(null);
        orderQuantityUnit.setFieldValue(null);
        sumQuantityOrderPacksUnit.setFieldValue(null);
        quantityUnit.setFieldValue(null);
    }
}
Also used : Entity(com.qcadoo.model.api.Entity) FormComponent(com.qcadoo.view.api.components.FormComponent) Optional(com.google.common.base.Optional) LookupComponent(com.qcadoo.view.api.components.LookupComponent) WindowComponent(com.qcadoo.view.api.components.WindowComponent) Ribbon(com.qcadoo.view.api.ribbon.Ribbon) FieldComponent(com.qcadoo.view.api.components.FieldComponent) RibbonActionItem(com.qcadoo.view.api.ribbon.RibbonActionItem) BigDecimal(java.math.BigDecimal)

Example 18 with Ribbon

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

the class OrderDetailsRibbonHelper method getRibbonItem.

public RibbonActionItem getRibbonItem(final ViewDefinitionState view, final String ribbonGroupName, final String ribbonItemName) {
    WindowComponent window = (WindowComponent) view.getComponentByReference(QcadooViewConstants.L_WINDOW);
    Ribbon ribbon = window.getRibbon();
    RibbonGroup ribbonGroup = ribbon.getGroupByName(ribbonGroupName);
    if (Objects.isNull(ribbonGroup)) {
        return null;
    }
    return ribbonGroup.getItemByName(ribbonItemName);
}
Also used : RibbonGroup(com.qcadoo.view.api.ribbon.RibbonGroup) WindowComponent(com.qcadoo.view.api.components.WindowComponent) Ribbon(com.qcadoo.view.api.ribbon.Ribbon)

Example 19 with Ribbon

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

the class AssignmentToShiftDetailsListeners method changeCopyStaffAssignmentToShiftButtonState.

private void changeCopyStaffAssignmentToShiftButtonState(ViewDefinitionState view, Entity assignmentToShift) {
    WindowComponent window = (WindowComponent) view.getComponentByReference(QcadooViewConstants.L_WINDOW);
    Ribbon ribbon = window.getRibbon();
    RibbonGroup copyRibbonGroup = ribbon.getGroupByName(L_COPY);
    RibbonActionItem copyStaffAssignmentToShiftRibbonActionItem = copyRibbonGroup.getItemByName(L_COPY_STAFF_ASSIGNMENT_TO_SHIFT);
    GridComponent staffAssignmentToShiftsGrid = (GridComponent) view.getComponentByReference(AssignmentToShiftFields.STAFF_ASSIGNMENT_TO_SHIFTS);
    String state = assignmentToShift.getStringField(AssignmentToShiftFields.STATE);
    AssignmentToShiftState assignmentToShiftState = AssignmentToShiftState.parseString(state);
    Long assignmentToShiftId = assignmentToShift.getId();
    boolean isSaved = (assignmentToShiftId != null);
    if (isSaved) {
        assignmentToShift = getAssignmentToShiftFromDB(assignmentToShiftId);
    }
    boolean isExternalSynchronized = assignmentToShift.getBooleanField(AssignmentToShiftFields.EXTERNAL_SYNCHRONIZED);
    boolean areSelected = !staffAssignmentToShiftsGrid.getSelectedEntities().isEmpty();
    boolean isEnabled = isSaved ? isExternalSynchronized && assignmentToShiftState.isEditingAllowed() && areSelected : false;
    copyStaffAssignmentToShiftRibbonActionItem.setEnabled(isEnabled);
    copyStaffAssignmentToShiftRibbonActionItem.requestUpdate(true);
}
Also used : RibbonGroup(com.qcadoo.view.api.ribbon.RibbonGroup) WindowComponent(com.qcadoo.view.api.components.WindowComponent) Ribbon(com.qcadoo.view.api.ribbon.Ribbon) GridComponent(com.qcadoo.view.api.components.GridComponent) RibbonActionItem(com.qcadoo.view.api.ribbon.RibbonActionItem) AssignmentToShiftState(com.qcadoo.mes.assignmentToShift.states.constants.AssignmentToShiftState)

Example 20 with Ribbon

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

the class AssignmentToShiftDetailsHooks method disableButtonsWhenNotExternalSynchronized.

private void disableButtonsWhenNotExternalSynchronized(final ViewDefinitionState view, Entity assignmentToShift) {
    WindowComponent window = (WindowComponent) view.getComponentByReference(QcadooViewConstants.L_WINDOW);
    Ribbon ribbon = window.getRibbon();
    RibbonGroup actionsRibbonGroup = ribbon.getGroupByName(L_ACTIONS);
    RibbonGroup statusRibbonGroup = ribbon.getGroupByName(L_STATUS);
    RibbonGroup copyRibbonGroup = ribbon.getGroupByName(L_COPY);
    RibbonGroup addRibbonGroup = ribbon.getGroupByName(L_ADD);
    RibbonActionItem saveRibbonActionItem = actionsRibbonGroup.getItemByName(L_SAVE);
    RibbonActionItem saveBackRibbonActionItem = actionsRibbonGroup.getItemByName(L_SAVE_BACK);
    RibbonActionItem saveNewRibbonActionItem = actionsRibbonGroup.getItemByName(L_SAVE_NEW);
    RibbonActionItem deleteRibbonActionItem = actionsRibbonGroup.getItemByName(L_DELETE);
    RibbonActionItem acceptAssignmentToShiftRibbonActionItem = statusRibbonGroup.getItemByName(L_ACCEPT_ASSIGNMENT_TO_SHIFT);
    RibbonActionItem correctAssignmentToShiftRibbonActionItem = statusRibbonGroup.getItemByName(L_CORRECT_ASSIGNMENT_TO_SHIFT);
    RibbonActionItem acceptCorrectedAssignmentToShiftRibbonActionItem = statusRibbonGroup.getItemByName(L_ACCEPT_CORRECTED_ASSIGNMENT_TO_SHIFT);
    RibbonActionItem copyStaffAssignmentToShiftRibbonActionItem = copyRibbonGroup.getItemByName(L_COPY_STAFF_ASSIGNMENT_TO_SHIFT);
    RibbonActionItem addManyWorkersRibbonActionItem = addRibbonGroup.getItemByName(L_ADD_MANY_WORKERS);
    GridComponent staffAssignmentToShiftsGrid = (GridComponent) view.getComponentByReference(AssignmentToShiftFields.STAFF_ASSIGNMENT_TO_SHIFTS);
    String state = assignmentToShift.getStringField(AssignmentToShiftFields.STATE);
    AssignmentToShiftState assignmentToShiftState = AssignmentToShiftState.parseString(state);
    Long assignmentToShiftId = assignmentToShift.getId();
    boolean isSaved = (assignmentToShiftId != null);
    if (isSaved) {
        assignmentToShift = getAssignmentToShift(assignmentToShiftId);
    }
    boolean isExternalSynchronized = assignmentToShift.getBooleanField(AssignmentToShiftFields.EXTERNAL_SYNCHRONIZED);
    boolean areSelected = !staffAssignmentToShiftsGrid.getSelectedEntities().isEmpty();
    boolean isEnabled = isSaved ? isExternalSynchronized && assignmentToShiftState.isEditingAllowed() : true;
    String message = null;
    if (!isEnabled) {
        if (isExternalSynchronized) {
            message = L_ASSIGNMENT_TO_SHIFT_STATE_DOES_NOT_ALLOW_EDITING;
        } else {
            message = L_ASSIGNMENT_TO_SHIFT_INFO_IS_WAITING_FOR_SYNC;
        }
    }
    List<RibbonActionItem> ribbonActionItems = Lists.newArrayList(saveRibbonActionItem, saveBackRibbonActionItem, saveNewRibbonActionItem, deleteRibbonActionItem, acceptAssignmentToShiftRibbonActionItem, correctAssignmentToShiftRibbonActionItem, acceptCorrectedAssignmentToShiftRibbonActionItem, copyStaffAssignmentToShiftRibbonActionItem, addManyWorkersRibbonActionItem);
    for (RibbonActionItem ribbonActionItem : ribbonActionItems) {
        if (ribbonActionItem != null) {
            String ribbonActionItemName = ribbonActionItem.getName();
            if (AssignmentToShiftStateStringValues.DRAFT.equals(state) && (L_CORRECT_ASSIGNMENT_TO_SHIFT.equals(ribbonActionItemName) || L_ACCEPT_CORRECTED_ASSIGNMENT_TO_SHIFT.equals(ribbonActionItemName))) {
                ribbonActionItem.setEnabled(false);
                ribbonActionItem.setMessage(message);
            } else if ((AssignmentToShiftStateStringValues.ACCEPTED.equals(state) || AssignmentToShiftStateStringValues.CORRECTED.equals(state)) && L_CORRECT_ASSIGNMENT_TO_SHIFT.equals(ribbonActionItemName)) {
                ribbonActionItem.setEnabled(true);
            } else if (AssignmentToShiftStateStringValues.DURING_CORRECTION.equals(state) && (L_DELETE.equals(ribbonActionItemName) || L_ACCEPT_ASSIGNMENT_TO_SHIFT.equals(ribbonActionItemName) || L_CORRECT_ASSIGNMENT_TO_SHIFT.equals(ribbonActionItemName))) {
                ribbonActionItem.setEnabled(false);
                ribbonActionItem.setMessage(message);
            } else if (L_COPY_STAFF_ASSIGNMENT_TO_SHIFT.equals(ribbonActionItemName) && !areSelected) {
                ribbonActionItem.setEnabled(false);
            } else if (L_ADD_MANY_WORKERS.equals(ribbonActionItemName) && !isSaved) {
                ribbonActionItem.setEnabled(false);
            } else {
                ribbonActionItem.setEnabled(isEnabled);
                ribbonActionItem.setMessage(message);
            }
            ribbonActionItem.requestUpdate(true);
        }
    }
}
Also used : RibbonGroup(com.qcadoo.view.api.ribbon.RibbonGroup) WindowComponent(com.qcadoo.view.api.components.WindowComponent) Ribbon(com.qcadoo.view.api.ribbon.Ribbon) GridComponent(com.qcadoo.view.api.components.GridComponent) RibbonActionItem(com.qcadoo.view.api.ribbon.RibbonActionItem) StaffAssignmentToShiftState(com.qcadoo.mes.assignmentToShift.constants.StaffAssignmentToShiftState) AssignmentToShiftState(com.qcadoo.mes.assignmentToShift.states.constants.AssignmentToShiftState)

Aggregations

Ribbon (com.qcadoo.view.api.ribbon.Ribbon)40 RibbonGroup (com.qcadoo.view.api.ribbon.RibbonGroup)37 RibbonActionItem (com.qcadoo.view.api.ribbon.RibbonActionItem)36 WindowComponent (com.qcadoo.view.api.components.WindowComponent)31 FormComponent (com.qcadoo.view.api.components.FormComponent)16 Entity (com.qcadoo.model.api.Entity)10 GridComponent (com.qcadoo.view.api.components.GridComponent)8 ViewDefinitionState (com.qcadoo.view.api.ViewDefinitionState)4 QcadooViewConstants (com.qcadoo.view.constants.QcadooViewConstants)3 Optional (com.google.common.base.Optional)2 Lists (com.google.common.collect.Lists)2 AssignmentToShiftState (com.qcadoo.mes.assignmentToShift.states.constants.AssignmentToShiftState)2 DataDefinition (com.qcadoo.model.api.DataDefinition)2 DataDefinitionService (com.qcadoo.model.api.DataDefinitionService)2 CheckBoxComponent (com.qcadoo.view.api.components.CheckBoxComponent)2 FieldComponent (com.qcadoo.view.api.components.FieldComponent)2 BigDecimal (java.math.BigDecimal)2 Arrays (java.util.Arrays)2 Service (org.springframework.stereotype.Service)2 HashMultimap (com.google.common.collect.HashMultimap)1