/** * Validates screen and commits data context. * * @return operation result */ protected OperationResult commitChanges() { ValidationErrors validationErrors = validateScreen(); if (!validationErrors.isEmpty()) { ScreenValidation screenValidation = getBeanLocator().get(ScreenValidation.class); screenValidation.showValidationErrors(this, validationErrors); return OperationResult.fail(); } getScreenData().getDataContext().commit(); return OperationResult.success(); }
/** * Requests closing of the screen caused by the given action. * * @param action close action which is propagated to {@link BeforeCloseEvent} and {@link AfterCloseEvent} * @return result of operation */ public OperationResult close(CloseAction action) { BeforeCloseEvent beforeCloseEvent = new BeforeCloseEvent(this, action); fireEvent(BeforeCloseEvent.class, beforeCloseEvent); if (beforeCloseEvent.isClosePrevented()) { if (beforeCloseEvent.getCloseResult() != null) { return beforeCloseEvent.getCloseResult(); } return OperationResult.fail(); } // save settings right before removing if (isSaveSettingsOnClose(action)) { saveSettings(); } if (isSaveScreenHistoryOnClose(action)) { ScreenHistorySupport screenHistorySupport = beanLocator.get(ScreenHistorySupport.NAME); screenHistorySupport.saveScreenHistory(this); } screenContext.getScreens().remove(this); AfterCloseEvent afterCloseEvent = new AfterCloseEvent(this, action); fireEvent(AfterCloseEvent.class, afterCloseEvent); return OperationResult.success(); }
/** * Check modifications and close all screens in all main windows excluding root screens. * * @return operation result */ public OperationResult checkModificationsAndCloseAll() { if (hasUnsavedChanges()) { UnknownOperationResult result = new UnknownOperationResult(); ui.getDialogs().createOptionDialog() .withCaption(messages.getMainMessage("closeUnsaved.caption")) .withMessage(messages.getMainMessage("discardChangesOnClose")) .withActions( new BaseAction("closeApplication") .withCaption(messages.getMainMessage("closeApplication")) .withIcon(icons.get(CubaIcon.DIALOG_OK)) .withHandler(event -> { closeWindowsInternal(); result.success(); }), new DialogAction(DialogAction.Type.CANCEL, Action.Status.PRIMARY) .withHandler(event -> result.fail()) ) .show(); return result; } else { closeWindowsInternal(); return OperationResult.success(); } }