use of com.haulmont.cuba.gui.Dialogs in project cuba by cuba-platform.
the class WebUserIndicator method substitutedUserChanged.
protected void substitutedUserChanged(ValueChangeEvent<User> event) {
UserSessionSource uss = beanLocator.get(UserSessionSource.NAME);
User newUser = event.getValue();
UserSession userSession = uss.getUserSession();
if (userSession == null) {
throw new RuntimeException("No user session found");
}
User oldUser = userSession.getSubstitutedUser() == null ? userSession.getUser() : userSession.getSubstitutedUser();
if (!oldUser.equals(newUser)) {
String newUserName = StringUtils.isBlank(newUser.getName()) ? newUser.getLogin() : newUser.getName();
Messages messages = beanLocator.get(Messages.NAME);
Dialogs dialogs = getScreenContext(this).getDialogs();
dialogs.createOptionDialog().withCaption(messages.getMainMessage("substUserSelectDialog.title")).withMessage(messages.formatMainMessage("substUserSelectDialog.msg", newUserName)).withType(Dialogs.MessageType.WARNING).withActions(new ChangeSubstUserAction(userComboBox.getValue()) {
@Override
public void doRevert() {
super.doRevert();
revertToCurrentUser();
}
}, new DoNotChangeSubstUserAction() {
@Override
public void actionPerform(com.haulmont.cuba.gui.components.Component component) {
super.actionPerform(component);
revertToCurrentUser();
}
}).show();
}
}
use of com.haulmont.cuba.gui.Dialogs in project cuba by cuba-platform.
the class ScreenValidation method showSaveConfirmationDialog.
/**
* Shows standard save confirmation dialog with Save, Discard and Cancel actions.
*
* @param origin screen controller
* @param closeAction close action
* @return result
*/
public SaveChangesDialogResult showSaveConfirmationDialog(FrameOwner origin, @SuppressWarnings("unused") CloseAction closeAction) {
SaveChangesDialogResult result = new SaveChangesDialogResult();
Dialogs dialogs = getScreenContext(origin).getDialogs();
dialogs.createOptionDialog().withCaption(messages.getMainMessage("closeUnsaved.caption")).withMessage(messages.getMainMessage("saveUnsaved")).withActions(new DialogAction(DialogAction.Type.OK, Action.Status.PRIMARY).withCaption(messages.getMainMessage("closeUnsaved.save")).withHandler(e -> {
result.commit();
}), new BaseAction("discard").withIcon(icons.get(CubaIcon.DIALOG_CANCEL)).withCaption(messages.getMainMessage("closeUnsaved.discard")).withHandler(e -> {
result.discard();
}), new DialogAction(DialogAction.Type.CANCEL).withIcon(null).withHandler(e -> {
Frame frame = UiControllerUtils.getFrame(origin);
ComponentsHelper.focusChildComponent(frame);
result.cancel();
})).show();
return result;
}
use of com.haulmont.cuba.gui.Dialogs 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.Dialogs in project cuba by cuba-platform.
the class ExceptionDialog method logoutPrompt.
protected void logoutPrompt() {
Dialogs dialogs = ((AppUI) getUI()).getDialogs();
dialogs.createOptionDialog(MessageType.WARNING).withCaption(messages.getMainMessage("exceptionDialog.logoutCaption")).withMessage(messages.getMainMessage("exceptionDialog.logoutMessage")).withActions(new BaseAction("close").withCaption(messages.getMainMessage("closeApplication")).withIcon("icons/ok.png").withHandler(event -> forceLogout()), new DialogAction(Type.CANCEL, Status.PRIMARY)).show();
}
Aggregations