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