Search in sources :

Example 6 with Dialogs

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();
    }
}
Also used : DoNotChangeSubstUserAction(com.haulmont.cuba.web.actions.DoNotChangeSubstUserAction) ChangeSubstUserAction(com.haulmont.cuba.web.actions.ChangeSubstUserAction) UserSessionSource(com.haulmont.cuba.core.global.UserSessionSource) User(com.haulmont.cuba.security.entity.User) Messages(com.haulmont.cuba.core.global.Messages) Dialogs(com.haulmont.cuba.gui.Dialogs) UserSession(com.haulmont.cuba.security.global.UserSession) DoNotChangeSubstUserAction(com.haulmont.cuba.web.actions.DoNotChangeSubstUserAction) WebAbstractComponent(com.haulmont.cuba.web.gui.components.WebAbstractComponent)

Example 7 with Dialogs

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

Example 8 with Dialogs

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();
    }
}
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 9 with Dialogs

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();
}
Also used : Dialogs(com.haulmont.cuba.gui.Dialogs) DialogAction(com.haulmont.cuba.gui.components.DialogAction) BaseAction(com.haulmont.cuba.gui.components.actions.BaseAction) AppUI(com.haulmont.cuba.web.AppUI)

Aggregations

Dialogs (com.haulmont.cuba.gui.Dialogs)9 DialogAction (com.haulmont.cuba.gui.components.DialogAction)3 BaseAction (com.haulmont.cuba.gui.components.actions.BaseAction)3 Messages (com.haulmont.cuba.core.global.Messages)2 Entity (com.haulmont.cuba.core.entity.Entity)1 UserSessionSource (com.haulmont.cuba.core.global.UserSessionSource)1 Screens (com.haulmont.cuba.gui.Screens)1 RootWindow (com.haulmont.cuba.gui.components.RootWindow)1 ListAction (com.haulmont.cuba.gui.components.actions.ListAction)1 IllegalConcurrentAccessException (com.haulmont.cuba.gui.executors.IllegalConcurrentAccessException)1 Icons (com.haulmont.cuba.gui.icons.Icons)1 StudioAction (com.haulmont.cuba.gui.meta.StudioAction)1 Screen (com.haulmont.cuba.gui.screen.Screen)1 UnknownOperationResult (com.haulmont.cuba.gui.util.UnknownOperationResult)1 User (com.haulmont.cuba.security.entity.User)1 LoginException (com.haulmont.cuba.security.global.LoginException)1 NoUserSessionException (com.haulmont.cuba.security.global.NoUserSessionException)1 UserSession (com.haulmont.cuba.security.global.UserSession)1 AppUI (com.haulmont.cuba.web.AppUI)1 ChangeSubstUserAction (com.haulmont.cuba.web.actions.ChangeSubstUserAction)1