/** * Tries to validate and commit data. If data committed successfully then closes the screen with * {@link #WINDOW_COMMIT_AND_CLOSE} action. May show validation errors or open an additional dialog before closing * the screen. * * @return result of close request */ public OperationResult closeWithCommit() { return commitChanges() .compose(() -> close(WINDOW_COMMIT_AND_CLOSE_ACTION)); }
OperationResult result = OperationResult.success(); while (result.getStatus() == OperationResult.Status.SUCCESS && iterator.hasNext()) { if (result.getStatus() != OperationResult.Status.SUCCESS) { return result.compose(() -> showFromNavigation(screen)); .show(); return OperationResult.fail(); if (result.getStatus() != OperationResult.Status.SUCCESS) { return result.compose(() -> showFromNavigation(screen)); return OperationResult.success();
/** * 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(); }
/** * Check modifications and close all screens in all main windows. * * @param runIfOk a closure to run after all screens are closed */ @Deprecated public void checkModificationsAndCloseAll(Runnable runIfOk) { checkModificationsAndCloseAll() .then(runIfOk); }
/** * Close the screen. * <br> If the screen has uncommitted changes in its {@link com.haulmont.cuba.gui.data.DsContext}, * the confirmation dialog will be shown. * <br> Don't override this method in subclasses, use hook {@link AbstractWindow#preClose(String)} * * @param actionId action ID that will be propagated to attached {@link CloseListener}s. * Use {@link #COMMIT_ACTION_ID} if some changes have just been committed, or * {@link #CLOSE_ACTION_ID} otherwise. These constants are recognized by various mechanisms of the * framework. */ @Deprecated default boolean close(String actionId) { OperationResult result = getFrameOwner().close(new StandardCloseAction(actionId)); return result.getStatus() == OperationResult.Status.SUCCESS; }
@Override public OperationResult compose(Supplier<OperationResult> nextStep) { if (status == Status.SUCCESS) { return nextStep.get(); } if (status == Status.FAIL) { return OperationResult.fail(); } UnknownOperationResult operationResult = new UnknownOperationResult(); then(() -> { OperationResult resultNested = nextStep.get(); operationResult.resolveWith(resultNested); }); otherwise(operationResult::fail); return operationResult; }
/** * 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(); } }
/** * 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(); }
/** * Try to perform logout. If there are unsaved changes in opened windows then logout will not be performed and * unsaved changes dialog will appear. * * @deprecated Use {@link #logout()} instead. * * @param runWhenLoggedOut runnable that will be invoked if user decides to logout */ @Deprecated public void logout(@Nullable Runnable runWhenLoggedOut) { logout().then(runWhenLoggedOut); }
/** * Close the screen. * <br> If the window has uncommitted changes in its {@link com.haulmont.cuba.gui.data.DsContext}, * and force=false, the confirmation dialog will be shown. * * @param actionId action ID that will be propagated to attached {@link CloseListener}s. * Use {@link #COMMIT_ACTION_ID} if some changes have just been committed, or * {@link #CLOSE_ACTION_ID} otherwise. These constants are recognized by various mechanisms of the * framework. * @param force if true, no confirmation dialog will be shown even if the screen has uncommitted changes */ @Deprecated default boolean close(String actionId, boolean force) { OperationResult result = getFrameOwner().close(new StandardCloseAction(actionId, !force)); return result.getStatus() == OperationResult.Status.SUCCESS; }
/** * Tries to validate and commit data. If data committed successfully then closes the screen with * {@link #WINDOW_COMMIT_AND_CLOSE} action. May show validation errors or open an additional dialog before closing * the screen. * * @return result of close request */ public OperationResult closeWithCommit() { if (validateAll()) { boolean committed = commitInternal(true); if (committed) { return close(WINDOW_COMMIT_AND_CLOSE_ACTION); } } return OperationResult.fail(); }
/** * Check modifications and close all screens in all main windows. * * @param runIfOk a closure to run after all screens are closed * @param runIfCancel a closure to run if there were modifications and a user canceled the operation */ @Deprecated public void checkModificationsAndCloseAll(Runnable runIfOk, Runnable runIfCancel) { checkModificationsAndCloseAll() .then(runIfOk) .otherwise(runIfCancel); }
protected void commit(@SuppressWarnings("unused") Action.ActionPerformedEvent event) { commitChanges() .then(() -> commitActionPerformed = true); }
protected boolean closeWindowStack(Screens.WindowStack windowStack) { boolean closed = true; for (Screen screen : windowStack.getBreadcrumbs()) { if (isNotCloseable(screen.getWindow()) || isWindowClosePrevented(screen.getWindow(), CloseOriginType.CLOSE_BUTTON)) { closed = false; windowStack.select(); break; } OperationResult closeResult = screen.close(FrameOwner.WINDOW_CLOSE_ACTION); if (closeResult.getStatus() != OperationResult.Status.SUCCESS) { closed = false; windowStack.select(); break; } } return closed; }
@Override public void actionPerform(com.haulmont.cuba.gui.components.Component component) { AppUI ui = AppUI.getCurrent(); WebScreens screens = (WebScreens) ui.getScreens(); screens.checkModificationsAndCloseAll() .then(() -> { App app = ui.getApp(); try { app.getConnection().substituteUser(user); doAfterChangeUser(); } catch (javax.persistence.NoResultException e) { Messages messages = AppBeans.get(Messages.NAME); app.getWindowManager().showNotification( messages.formatMainMessage("substitutionNotPerformed", user.getName()), Frame.NotificationType.WARNING ); doRevert(); } }) .otherwise(this::doRevert); }
protected void select(Collection<T> items) { boolean valid = true; if (selectValidator != null) { valid = selectValidator.test(new ValidationContext<>(this, items)); } if (valid) { OperationResult result = close(LOOKUP_SELECT_CLOSE_ACTION); if (selectHandler != null) { result.then(() -> selectHandler.accept(items)); } } }
protected boolean closeWindowStack(WindowStack windowStack) { boolean closed = true; Collection<Screen> tabScreens = windowStack.getBreadcrumbs(); for (Screen screen : tabScreens) { if (isNotCloseable(screen.getWindow())) { continue; } if (isWindowClosePrevented(screen.getWindow(), CloseOriginType.CLOSE_BUTTON)) { closed = false; // focus tab windowStack.select(); break; } OperationResult closeResult = screen.close(FrameOwner.WINDOW_CLOSE_ACTION); if (closeResult.getStatus() != OperationResult.Status.SUCCESS) { closed = false; // focus tab windowStack.select(); break; } } return closed; }