Search in sources :

Example 1 with UnknownOperationResult

use of com.haulmont.cuba.gui.util.UnknownOperationResult in project cuba by cuba-platform.

the class AbstractWindow method beforeClose.

@Order(Events.HIGHEST_PLATFORM_PRECEDENCE + 10)
@Subscribe
protected void beforeClose(Screen.BeforeCloseEvent event) {
    CloseAction closeAction = event.getCloseAction();
    boolean checkSavedChanges = !(closeAction instanceof ChangeTrackerCloseAction) || ((ChangeTrackerCloseAction) closeAction).isCheckForUnsavedChanges();
    if (checkSavedChanges) {
        String actionId = closeAction instanceof StandardCloseAction ? ((StandardCloseAction) closeAction).getActionId() : UNKNOWN_CLOSE_ACTION_ID;
        boolean close = preClose(actionId);
        if (!close) {
            event.preventWindowClose();
        }
    }
    if (!event.isClosePrevented()) {
        if (closeAction instanceof ChangeTrackerCloseAction && ((ChangeTrackerCloseAction) closeAction).isCheckForUnsavedChanges() && hasUnsavedChanges()) {
            Configuration configuration = getBeanLocator().get(Configuration.NAME);
            ClientConfig clientConfig = configuration.getConfig(ClientConfig.class);
            ScreenValidation screenValidation = getBeanLocator().get(ScreenValidation.NAME);
            UnknownOperationResult result = new UnknownOperationResult();
            if (this instanceof Committable && clientConfig.getUseSaveConfirmation()) {
                Committable committable = (Committable) this;
                screenValidation.showSaveConfirmationDialog(this, closeAction).onCommit(committable::commitAndClose).onDiscard(() -> result.resolveWith(closeWithDiscard())).onCancel(result::fail);
            } else {
                screenValidation.showUnsavedChangesDialog(this, closeAction).onDiscard(() -> result.resolveWith(closeWithDiscard())).onCancel(result::fail);
            }
            event.preventWindowClose(result);
        }
    }
}
Also used : Configuration(com.haulmont.cuba.core.global.Configuration) UnknownOperationResult(com.haulmont.cuba.gui.util.UnknownOperationResult) ClientConfig(com.haulmont.cuba.client.ClientConfig) Order(org.springframework.core.annotation.Order)

Example 2 with UnknownOperationResult

use of com.haulmont.cuba.gui.util.UnknownOperationResult in project cuba by cuba-platform.

the class StandardEditor method preventUnsavedChanges.

protected void preventUnsavedChanges(BeforeCloseEvent event) {
    CloseAction action = event.getCloseAction();
    if (action instanceof ChangeTrackerCloseAction && ((ChangeTrackerCloseAction) action).isCheckForUnsavedChanges() && hasUnsavedChanges()) {
        Configuration configuration = getBeanLocator().get(Configuration.NAME);
        ClientConfig clientConfig = configuration.getConfig(ClientConfig.class);
        ScreenValidation screenValidation = getBeanLocator().get(ScreenValidation.NAME);
        UnknownOperationResult result = new UnknownOperationResult();
        if (clientConfig.getUseSaveConfirmation()) {
            screenValidation.showSaveConfirmationDialog(this, action).onCommit(() -> result.resume(closeWithCommit())).onDiscard(() -> result.resume(closeWithDiscard())).onCancel(result::fail);
        } else {
            screenValidation.showUnsavedChangesDialog(this, action).onDiscard(() -> result.resume(closeWithDiscard())).onCancel(result::fail);
        }
        event.preventWindowClose(result);
    }
}
Also used : UnknownOperationResult(com.haulmont.cuba.gui.util.UnknownOperationResult) ClientConfig(com.haulmont.cuba.client.ClientConfig)

Example 3 with UnknownOperationResult

use of com.haulmont.cuba.gui.util.UnknownOperationResult in project cuba by cuba-platform.

the class App method logout.

/**
 * Try to perform logout. If there are unsaved changes in opened windows then logout will not be performed and
 * unsaved changes dialog will appear.
 *
 * @return operation result object
 */
public OperationResult logout() {
    AppUI ui = AppUI.getCurrent();
    try {
        RootWindow topLevelWindow = ui != null ? ui.getTopLevelWindow() : null;
        if (topLevelWindow != null) {
            Screens screens = ui.getScreens();
            if (!screens.hasUnsavedChanges()) {
                performStandardLogout(ui);
                return OperationResult.success();
            }
            UnknownOperationResult result = new UnknownOperationResult();
            Messages messages = beanLocator.get(Messages.NAME);
            Icons icons = beanLocator.get(Icons.NAME);
            Dialogs dialogs = ui.getDialogs();
            dialogs.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 -> {
                performStandardLogout(ui);
                result.success();
            }), new DialogAction(DialogAction.Type.CANCEL, Action.Status.PRIMARY).withHandler(event -> {
                result.fail();
            })).show();
            return OperationResult.fail();
        } else {
            forceLogout();
            return OperationResult.success();
        }
    } catch (Exception e) {
        log.error("Error on logout", e);
        String url = ControllerUtils.getLocationWithoutParams() + "?restartApp";
        if (ui != null) {
            ui.getPage().open(url, "_self");
        }
        return new UnknownOperationResult();
    }
}
Also used : Dialogs(com.haulmont.cuba.gui.Dialogs) DialogAction(com.haulmont.cuba.gui.components.DialogAction) UnknownOperationResult(com.haulmont.cuba.gui.util.UnknownOperationResult) Icons(com.haulmont.cuba.gui.icons.Icons) BaseAction(com.haulmont.cuba.gui.components.actions.BaseAction) RootWindow(com.haulmont.cuba.gui.components.RootWindow) Screens(com.haulmont.cuba.gui.Screens) LoginException(com.haulmont.cuba.security.global.LoginException) IllegalConcurrentAccessException(com.haulmont.cuba.gui.executors.IllegalConcurrentAccessException) NoUserSessionException(com.haulmont.cuba.security.global.NoUserSessionException)

Example 4 with UnknownOperationResult

use of com.haulmont.cuba.gui.util.UnknownOperationResult in project cuba by cuba-platform.

the class WebScreens method checkModificationsAndCloseAll.

/**
 * 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();
    }
}
Also used : UnknownOperationResult(com.haulmont.cuba.gui.util.UnknownOperationResult) BaseAction(com.haulmont.cuba.gui.components.actions.BaseAction)

Aggregations

UnknownOperationResult (com.haulmont.cuba.gui.util.UnknownOperationResult)4 ClientConfig (com.haulmont.cuba.client.ClientConfig)2 BaseAction (com.haulmont.cuba.gui.components.actions.BaseAction)2 Configuration (com.haulmont.cuba.core.global.Configuration)1 Dialogs (com.haulmont.cuba.gui.Dialogs)1 Screens (com.haulmont.cuba.gui.Screens)1 DialogAction (com.haulmont.cuba.gui.components.DialogAction)1 RootWindow (com.haulmont.cuba.gui.components.RootWindow)1 IllegalConcurrentAccessException (com.haulmont.cuba.gui.executors.IllegalConcurrentAccessException)1 Icons (com.haulmont.cuba.gui.icons.Icons)1 LoginException (com.haulmont.cuba.security.global.LoginException)1 NoUserSessionException (com.haulmont.cuba.security.global.NoUserSessionException)1 Order (org.springframework.core.annotation.Order)1