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();
}
}
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);
}
}
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);
}
}
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);
}
}
}
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)));
}
Aggregations