Search in sources :

Example 1 with UnknownOperationResult

use of io.jmix.ui.util.UnknownOperationResult in project jmix by jmix-framework.

the class ScreensImpl 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.getMessage("closeUnsaved.caption")).withMessage(messages.getMessage("discardChangesOnClose")).withActions(new BaseAction("closeApplication").withCaption(messages.getMessage("closeApplication")).withIcon(icons.get(JmixIcon.DIALOG_OK)).withHandler(event -> {
            ui.getApp().closeWindowsInternal(true);
            result.success();
        }), new DialogAction(DialogAction.Type.CANCEL, Action.Status.PRIMARY).withHandler(event -> result.fail())).show();
        return result;
    } else {
        ui.getApp().closeWindowsInternal(true);
        return OperationResult.success();
    }
}
Also used : DialogAction(io.jmix.ui.action.DialogAction) UnknownOperationResult(io.jmix.ui.util.UnknownOperationResult) BaseAction(io.jmix.ui.action.BaseAction)

Example 2 with UnknownOperationResult

use of io.jmix.ui.util.UnknownOperationResult in project jmix by jmix-framework.

the class BulkEditorWindow method preventUnsavedChanges.

protected void preventUnsavedChanges(BeforeCloseEvent event) {
    CloseAction action = event.getCloseAction();
    if (action instanceof ChangeTrackerCloseAction && ((ChangeTrackerCloseAction) action).isCheckForUnsavedChanges() && hasChanges()) {
        UnknownOperationResult result = new UnknownOperationResult();
        screenValidation.showUnsavedChangesDialog(this, action).onDiscard(() -> result.resume(closeWithDiscard())).onCancel(result::fail);
        event.preventWindowClose(result);
    }
}
Also used : UnknownOperationResult(io.jmix.ui.util.UnknownOperationResult)

Example 3 with UnknownOperationResult

use of io.jmix.ui.util.UnknownOperationResult in project jmix by jmix-framework.

the class StandardEditor method preventUnsavedChanges.

protected void preventUnsavedChanges(BeforeCloseEvent event) {
    CloseAction action = event.getCloseAction();
    if (action instanceof ChangeTrackerCloseAction && ((ChangeTrackerCloseAction) action).isCheckForUnsavedChanges() && hasUnsavedChanges()) {
        ScreenValidation screenValidation = getApplicationContext().getBean(ScreenValidation.class);
        UnknownOperationResult result = new UnknownOperationResult();
        if (getApplicationContext().getBean(UiScreenProperties.class).isUseSaveConfirmation()) {
            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 : UiScreenProperties(io.jmix.ui.UiScreenProperties) UnknownOperationResult(io.jmix.ui.util.UnknownOperationResult)

Example 4 with UnknownOperationResult

use of io.jmix.ui.util.UnknownOperationResult in project jmix by jmix-framework.

the class AbstractWindow method beforeClose.

@Order(JmixOrder.HIGHEST_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()) {
            ScreenValidation screenValidation = getApplicationContext().getBean(ScreenValidation.class);
            UnknownOperationResult result = new UnknownOperationResult();
            if (this instanceof Committable && getApplicationContext().getBean(UiScreenProperties.class).isUseSaveConfirmation()) {
                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 : UnknownOperationResult(io.jmix.ui.util.UnknownOperationResult) Order(org.springframework.core.annotation.Order) JmixOrder(io.jmix.core.JmixOrder)

Example 5 with UnknownOperationResult

use of io.jmix.ui.util.UnknownOperationResult in project jmix by jmix-framework.

the class AppSettingsEntityScreen method handleEntityLookupChangeWithUnsavedChanges.

protected void handleEntityLookupChangeWithUnsavedChanges() {
    UnknownOperationResult result = new UnknownOperationResult();
    screenValidation.showUnsavedChangesDialog(this, new StandardCloseAction(Window.CLOSE_ACTION_ID)).onDiscard(() -> result.resume(updateEntityLookupValue(false))).onCancel(() -> result.resume(updateEntityLookupValue(true)));
}
Also used : UnknownOperationResult(io.jmix.ui.util.UnknownOperationResult)

Aggregations

UnknownOperationResult (io.jmix.ui.util.UnknownOperationResult)7 BaseAction (io.jmix.ui.action.BaseAction)2 DialogAction (io.jmix.ui.action.DialogAction)2 JmixOrder (io.jmix.core.JmixOrder)1 Messages (io.jmix.core.Messages)1 UiScreenProperties (io.jmix.ui.UiScreenProperties)1 RootWindow (io.jmix.ui.component.RootWindow)1 IllegalConcurrentAccessException (io.jmix.ui.executor.IllegalConcurrentAccessException)1 Icons (io.jmix.ui.icon.Icons)1 Order (org.springframework.core.annotation.Order)1