Search in sources :

Example 41 with RibbonGroup

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

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

the class MultiAssignmentToShiftDetailsHooks method enableAddButton.

private void enableAddButton(ViewDefinitionState view) {
    FormComponent form = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
    Entity multiAssignment = form.getPersistedEntityWithIncludedFormValues();
    GridComponent workersComponent = (GridComponent) view.getComponentByReference("workers");
    WindowComponent window = (WindowComponent) view.getComponentByReference(QcadooViewConstants.L_WINDOW);
    RibbonGroup add = (RibbonGroup) window.getRibbon().getGroupByName("add");
    RibbonActionItem addMany = (RibbonActionItem) add.getItemByName("addManyWorkers");
    if (workersComponent.getEntities().isEmpty() || !multiAssignment.isValid()) {
        addMany.setEnabled(false);
        addMany.requestUpdate(true);
    } else {
        addMany.setEnabled(true);
        addMany.requestUpdate(true);
    }
}
Also used : Entity(com.qcadoo.model.api.Entity) RibbonGroup(com.qcadoo.view.api.ribbon.RibbonGroup) RibbonActionItem(com.qcadoo.view.api.ribbon.RibbonActionItem)

Example 43 with RibbonGroup

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

Example 44 with RibbonGroup

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

the class AddressDetailsHooks method updateRibbonState.

private void updateRibbonState(final ViewDefinitionState view) {
    FormComponent addressForm = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
    WindowComponent window = (WindowComponent) view.getComponentByReference(QcadooViewConstants.L_WINDOW);
    RibbonGroup ribbonGroup = window.getRibbon().getGroupByName(L_ACTIONS);
    boolean isEnabled = shouldBeEnabled(addressForm);
    ribbonGroup.getItems().stream().forEach(ribbonActionItem -> {
        ribbonActionItem.setEnabled(isEnabled);
        ribbonActionItem.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)

Example 45 with RibbonGroup

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

the class PalletNumberHelperDetailsHooks method disableButtonsWhenNotSaved.

private void disableButtonsWhenNotSaved(final ViewDefinitionState view) {
    FormComponent palletNumberHelperForm = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
    WindowComponent window = (WindowComponent) view.getComponentByReference(QcadooViewConstants.L_WINDOW);
    Ribbon ribbon = window.getRibbon();
    RibbonGroup actionsRibbonGroup = ribbon.getGroupByName(L_ACTIONS);
    RibbonGroup printRibbonGroup = ribbon.getGroupByName(L_PRINT);
    RibbonActionItem saveRibbonActionItem = actionsRibbonGroup.getItemByName(L_SAVE);
    RibbonActionItem printPalletNumberReportHelperRibbonActionItem = printRibbonGroup.getItemByName(L_PRINT_PALLET_NUMBER_HELPER_REPORT);
    Long palletNumberHelperId = palletNumberHelperForm.getEntityId();
    boolean isEnabled = (palletNumberHelperId != null);
    if (saveRibbonActionItem != null) {
        saveRibbonActionItem.setEnabled(!isEnabled);
        saveRibbonActionItem.requestUpdate(true);
    }
    if (printPalletNumberReportHelperRibbonActionItem != null) {
        printPalletNumberReportHelperRibbonActionItem.setEnabled(isEnabled);
        printPalletNumberReportHelperRibbonActionItem.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

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