Search in sources :

Example 16 with Window

use of com.haulmont.cuba.gui.components.Window in project cuba by cuba-platform.

the class DesktopTree method handleClickAction.

protected void handleClickAction() {
    Action action = getItemClickAction();
    if (action == null) {
        action = getEnterPressAction();
        if (action == null) {
            action = getAction("edit");
            if (action == null) {
                action = getAction("view");
            }
        }
    }
    if (action != null && action.isEnabled()) {
        Window window = ComponentsHelper.getWindowImplementation(DesktopTree.this);
        if (window instanceof Window.Wrapper) {
            window = ((Window.Wrapper) window).getWrappedWindow();
        }
        if (!(window instanceof Window.Lookup)) {
            action.actionPerform(DesktopTree.this);
        } else {
            Window.Lookup lookup = (Window.Lookup) window;
            com.haulmont.cuba.gui.components.Component lookupComponent = lookup.getLookupComponent();
            if (lookupComponent != this)
                action.actionPerform(DesktopTree.this);
            else if (action.getId().equals(WindowDelegate.LOOKUP_ITEM_CLICK_ACTION_ID)) {
                action.actionPerform(DesktopTree.this);
            }
        }
    }
}
Also used : Window(com.haulmont.cuba.gui.components.Window) Action(com.haulmont.cuba.gui.components.Action) com.haulmont.cuba.gui.components(com.haulmont.cuba.gui.components)

Example 17 with Window

use of com.haulmont.cuba.gui.components.Window in project cuba by cuba-platform.

the class DesktopWindow method close.

@Override
public boolean close(final String actionId) {
    if (!forceClose) {
        if (!delegate.preClose(actionId))
            return false;
    }
    ClientConfig clientConfig = configuration.getConfig(ClientConfig.class);
    if (!forceClose && isModified()) {
        final Committable committable = (getWrapper() instanceof Committable) ? (Committable) getWrapper() : (this instanceof Committable) ? (Committable) this : null;
        if ((committable != null) && clientConfig.getUseSaveConfirmation()) {
            windowManager.showOptionDialog(messages.getMainMessage("closeUnsaved.caption"), messages.getMainMessage("saveUnsaved"), MessageType.WARNING, new Action[] { new DialogAction(Type.OK, Status.PRIMARY).withCaption(messages.getMainMessage("closeUnsaved.save")).withHandler(event -> {
                committable.commitAndClose();
            }), new BaseAction("discard").withIcon("icons/cancel.png").withCaption(messages.getMainMessage("closeUnsaved.discard")).withHandler(event -> {
                committable.close(actionId, true);
            }), new DialogAction(Type.CANCEL).withIcon(null).withHandler(event -> {
                doAfterClose = null;
            }) });
        } else {
            windowManager.showOptionDialog(messages.getMainMessage("closeUnsaved.caption"), messages.getMainMessage("closeUnsaved"), MessageType.WARNING, new Action[] { new DialogAction(Type.YES).withHandler(event -> {
                getWrapper().close(actionId, true);
            }), new DialogAction(Type.NO, Status.PRIMARY).withHandler(event -> {
                doAfterClose = null;
            }) });
        }
        return false;
    }
    if (!clientConfig.getManualScreenSettingsSaving()) {
        if (delegate.getWrapper() != null) {
            delegate.getWrapper().saveSettings();
        } else {
            saveSettings();
        }
    }
    delegate.disposeComponents();
    windowManager.close(this);
    boolean res = onClose(actionId);
    if (res && doAfterClose != null) {
        doAfterClose.run();
    }
    stopTimers();
    userActionsLog.trace("Window {} was closed", getId());
    return res;
}
Also used : StringUtils(org.apache.commons.lang.StringUtils) BoxLayoutAdapter(com.haulmont.cuba.desktop.sys.layout.BoxLayoutAdapter) Datasource(com.haulmont.cuba.gui.data.Datasource) LoggerFactory(org.slf4j.LoggerFactory) Settings(com.haulmont.cuba.gui.settings.Settings) AppBeans(com.haulmont.cuba.core.global.AppBeans) Icons(com.haulmont.cuba.gui.icons.Icons) BooleanUtils(org.apache.commons.lang.BooleanUtils) Pair(com.haulmont.bali.datastruct.Pair) com.haulmont.cuba.gui(com.haulmont.cuba.gui) Window(com.haulmont.cuba.gui.components.Window) Configuration(com.haulmont.cuba.core.global.Configuration) DesktopWindowManager(com.haulmont.cuba.desktop.sys.DesktopWindowManager) EventRouter(com.haulmont.bali.events.EventRouter) BaseAction(com.haulmont.cuba.gui.components.actions.BaseAction) Preconditions.checkNotNullArgument(com.haulmont.bali.util.Preconditions.checkNotNullArgument) AncestorEvent(javax.swing.event.AncestorEvent) com.haulmont.cuba.gui.components(com.haulmont.cuba.gui.components) TopLevelFrame(com.haulmont.cuba.desktop.TopLevelFrame) Frame(com.haulmont.cuba.gui.components.Frame) Status(com.haulmont.cuba.gui.components.Action.Status) DesktopConfig(com.haulmont.cuba.desktop.DesktopConfig) Messages(com.haulmont.cuba.core.global.Messages) ApplicationListener(org.springframework.context.ApplicationListener) DialogWindow(com.haulmont.cuba.desktop.sys.DialogWindow) List(java.util.List) ClientConfig(com.haulmont.cuba.client.ClientConfig) LayoutAdapter(com.haulmont.cuba.desktop.sys.layout.LayoutAdapter) JTabbedPaneExt(com.haulmont.cuba.desktop.sys.vcl.JTabbedPaneExt) Iterables(com.google.common.collect.Iterables) java.util(java.util) LookupSelectionChangeNotifier(com.haulmont.cuba.gui.components.LookupComponent.LookupSelectionChangeNotifier) Timer(com.haulmont.cuba.gui.components.Timer) ComponentSize(com.haulmont.cuba.desktop.gui.data.ComponentSize) CollectionUtils(org.apache.commons.collections4.CollectionUtils) AncestorListener(javax.swing.event.AncestorListener) DesktopContainerHelper(com.haulmont.cuba.desktop.gui.data.DesktopContainerHelper) CC(net.miginfocom.layout.CC) Component(com.haulmont.cuba.gui.components.Component) DsContext(com.haulmont.cuba.gui.data.DsContext) Nullable(javax.annotation.Nullable) App(com.haulmont.cuba.desktop.App) UserActionsLogger(com.haulmont.cuba.gui.logging.UserActionsLogger) Logger(org.slf4j.Logger) MigLayout(net.miginfocom.swing.MigLayout) Type(com.haulmont.cuba.gui.components.DialogAction.Type) JTextComponent(javax.swing.text.JTextComponent) Preconditions(com.haulmont.bali.util.Preconditions) java.awt(java.awt) UiEventsMulticaster(com.haulmont.cuba.gui.events.sys.UiEventsMulticaster) AbstractAction(com.haulmont.cuba.gui.components.AbstractAction) Element(org.dom4j.Element) MigLayoutHelper(com.haulmont.cuba.desktop.sys.layout.MigLayoutHelper) Action(com.haulmont.cuba.gui.components.Action) Entity(com.haulmont.cuba.core.entity.Entity) javax.swing(javax.swing) BaseAction(com.haulmont.cuba.gui.components.actions.BaseAction) ClientConfig(com.haulmont.cuba.client.ClientConfig)

Example 18 with Window

use of com.haulmont.cuba.gui.components.Window in project cuba by cuba-platform.

the class WebWindowManager method checkModificationsAndCloseAll.

/**
 * Check modifications and close all screens in all main windows.
 *
 * @param runIfOk     a closure to run after all screens are closed
 * @param runIfCancel a closure to run if there were modifications and a user canceled the operation
 */
public void checkModificationsAndCloseAll(final Runnable runIfOk, @Nullable final Runnable runIfCancel) {
    boolean modified = false;
    for (Window window : getOpenWindows()) {
        if (!disableSavingScreenHistory) {
            screenHistorySupport.saveScreenHistory(window, windowOpenMode.get(window).getOpenMode());
        }
        if (window instanceof WrappedWindow && ((WrappedWindow) window).getWrapper() != null) {
            ((WrappedWindow) window).getWrapper().saveSettings();
        } else {
            window.saveSettings();
        }
        if (window.getDsContext() != null && window.getDsContext().isModified()) {
            modified = true;
        }
    }
    disableSavingScreenHistory = true;
    if (modified) {
        showOptionDialog(messages.getMainMessage("closeUnsaved.caption"), messages.getMainMessage("discardChangesOnClose"), MessageType.WARNING, new Action[] { new BaseAction("closeApplication").withCaption(messages.getMainMessage("closeApplication")).withIcon(icons.get(CubaIcon.DIALOG_OK)).withHandler(event -> {
            closeAllWindows();
            runIfOk.run();
        }), new DialogAction(Type.CANCEL, Status.PRIMARY).withHandler(event -> {
            if (runIfCancel != null) {
                runIfCancel.run();
            }
        }) });
    } else {
        closeAllWindows();
        runIfOk.run();
    }
}
Also used : Window(com.haulmont.cuba.gui.components.Window) WebWindow(com.haulmont.cuba.web.gui.WebWindow) StringUtils(org.apache.commons.lang.StringUtils) ScreenHistorySupport(com.haulmont.cuba.gui.ScreenHistorySupport) Datasource(com.haulmont.cuba.gui.data.Datasource) WindowMode(com.vaadin.shared.ui.window.WindowMode) MessageType(com.haulmont.cuba.gui.components.Frame.MessageType) LoggerFactory(org.slf4j.LoggerFactory) CubaIcon(com.haulmont.cuba.gui.icons.CubaIcon) WebAppWorkArea(com.haulmont.cuba.web.gui.components.mainwindow.WebAppWorkArea) BeforeCloseWithShortcutEvent(com.haulmont.cuba.gui.components.Window.BeforeCloseWithShortcutEvent) Icons(com.haulmont.cuba.gui.icons.Icons) BooleanUtils(org.apache.commons.lang.BooleanUtils) Pair(com.haulmont.bali.datastruct.Pair) IconResolver(com.haulmont.cuba.web.gui.icons.IconResolver) AUTO_SIZE_PX(com.haulmont.cuba.gui.components.Component.AUTO_SIZE_PX) Window(com.haulmont.cuba.gui.components.Window) LayoutAnalyzer(com.haulmont.cuba.gui.app.core.dev.LayoutAnalyzer) UserIndicator(com.haulmont.cuba.gui.components.mainwindow.UserIndicator) Page(com.vaadin.server.Page) BaseAction(com.haulmont.cuba.gui.components.actions.BaseAction) ShortcutAction(com.vaadin.event.ShortcutAction) SilentException(com.haulmont.cuba.core.global.SilentException) com.haulmont.cuba.gui.components(com.haulmont.cuba.gui.components) BelongToFrame(com.haulmont.cuba.gui.components.Component.BelongToFrame) WindowInfo(com.haulmont.cuba.gui.config.WindowInfo) ClientType(com.haulmont.cuba.core.global.ClientType) Status(com.haulmont.cuba.gui.components.Action.Status) FoldersPane(com.haulmont.cuba.gui.components.mainwindow.FoldersPane) WindowBreadCrumbs(com.haulmont.cuba.web.sys.WindowBreadCrumbs) WebWrapperUtils(com.haulmont.cuba.web.gui.components.WebWrapperUtils) UuidSource(com.haulmont.cuba.core.global.UuidSource) ExceptionDialog(com.haulmont.cuba.web.exception.ExceptionDialog) ThemeConstants(com.haulmont.cuba.gui.theme.ThemeConstants) WebButton(com.haulmont.cuba.web.gui.components.WebButton) WebComponentsHelper.convertNotificationType(com.haulmont.cuba.web.gui.components.WebComponentsHelper.convertNotificationType) ClientConfig(com.haulmont.cuba.client.ClientConfig) ComponentsHelper(com.haulmont.cuba.gui.ComponentsHelper) WebAbstractComponent(com.haulmont.cuba.web.gui.components.WebAbstractComponent) java.util(java.util) WindowManager(com.haulmont.cuba.gui.WindowManager) ContentMode(com.vaadin.shared.ui.label.ContentMode) ParamsMap(com.haulmont.bali.util.ParamsMap) CssLayout(com.vaadin.ui.CssLayout) LayoutTip(com.haulmont.cuba.gui.app.core.dev.LayoutTip) Scope(org.springframework.context.annotation.Scope) Inject(javax.inject.Inject) Lists(com.google.common.collect.Lists) DevelopmentException(com.haulmont.cuba.core.global.DevelopmentException) Label(com.vaadin.ui.Label) LayoutLoaderConfig(com.haulmont.cuba.gui.xml.layout.LayoutLoaderConfig) com.haulmont.cuba.web.toolkit.ui(com.haulmont.cuba.web.toolkit.ui) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) Collections.singletonMap(java.util.Collections.singletonMap) Nullable(javax.annotation.Nullable) TopLevelWindowAttachListener(com.haulmont.cuba.gui.components.mainwindow.TopLevelWindowAttachListener) Logger(org.slf4j.Logger) AppWorkArea(com.haulmont.cuba.gui.components.mainwindow.AppWorkArea) UserSettingService(com.haulmont.cuba.security.app.UserSettingService) Type(com.haulmont.cuba.gui.components.DialogAction.Type) ExceptionUtils(org.apache.commons.lang.exception.ExceptionUtils) NotificationType(com.haulmont.cuba.gui.components.Frame.NotificationType) BorderStyle(com.vaadin.shared.ui.BorderStyle) Preconditions(com.haulmont.bali.util.Preconditions) BeforeCloseWithCloseButtonEvent(com.haulmont.cuba.gui.components.Window.BeforeCloseWithCloseButtonEvent) Button(com.vaadin.ui.Button) WebComponentsHelper(com.haulmont.cuba.web.gui.components.WebComponentsHelper) Mode(com.haulmont.cuba.gui.components.mainwindow.AppWorkArea.Mode) WindowConfig(com.haulmont.cuba.gui.config.WindowConfig) WebWindow(com.haulmont.cuba.web.gui.WebWindow) DialogParams(com.haulmont.cuba.gui.DialogParams) ShortcutListener(com.vaadin.event.ShortcutListener) Container(com.haulmont.cuba.gui.components.Component.Container) Unit(com.vaadin.server.Sizeable.Unit) Entity(com.haulmont.cuba.core.entity.Entity) com.vaadin.ui(com.vaadin.ui) Component(com.vaadin.ui.Component) BaseAction(com.haulmont.cuba.gui.components.actions.BaseAction)

Example 19 with Window

use of com.haulmont.cuba.gui.components.Window in project cuba by cuba-platform.

the class ChangePasswordAfterLoginListener method onApplicationEvent.

@Override
public void onApplicationEvent(AppLoggedInEvent event) {
    App app = event.getApp();
    Connection connection = app.getConnection();
    if (connection.isAuthenticated() && !isLoggedInWithExternalAuth(connection.getSessionNN())) {
        User user = connection.getSessionNN().getUser();
        // Change password on logon
        if (Boolean.TRUE.equals(user.getChangePasswordAtNextLogon())) {
            WebWindowManager wm = app.getWindowManager();
            for (Window window : wm.getOpenWindows()) {
                window.setEnabled(false);
            }
            WindowInfo changePasswordDialog = windowConfig.getWindowInfo("sec$User.changePassword");
            Window changePasswordWindow = wm.openWindow(changePasswordDialog, WindowManager.OpenType.DIALOG.closeable(false), ParamsMap.of("cancelEnabled", Boolean.FALSE));
            changePasswordWindow.addCloseListener(actionId -> {
                for (Window window : wm.getOpenWindows()) {
                    window.setEnabled(true);
                }
            });
        }
    }
}
Also used : App(com.haulmont.cuba.web.App) Window(com.haulmont.cuba.gui.components.Window) User(com.haulmont.cuba.security.entity.User) WebWindowManager(com.haulmont.cuba.web.WebWindowManager) Connection(com.haulmont.cuba.web.Connection) WindowInfo(com.haulmont.cuba.gui.config.WindowInfo)

Example 20 with Window

use of com.haulmont.cuba.gui.components.Window in project cuba by cuba-platform.

the class WindowBreadCrumbs method isCloseWithCloseButtonPrevented.

protected boolean isCloseWithCloseButtonPrevented(Window currentWindow) {
    WebWindow webWindow = (WebWindow) ComponentsHelper.getWindowImplementation(currentWindow);
    if (webWindow != null) {
        Window.BeforeCloseWithCloseButtonEvent event = new Window.BeforeCloseWithCloseButtonEvent(webWindow);
        webWindow.fireBeforeCloseWithCloseButton(event);
        return event.isClosePrevented();
    }
    return false;
}
Also used : Window(com.haulmont.cuba.gui.components.Window) WebWindow(com.haulmont.cuba.web.gui.WebWindow) WebWindow(com.haulmont.cuba.web.gui.WebWindow)

Aggregations

Window (com.haulmont.cuba.gui.components.Window)54 DesktopWindow (com.haulmont.cuba.desktop.gui.components.DesktopWindow)15 WebWindow (com.haulmont.cuba.web.gui.WebWindow)13 com.haulmont.cuba.gui.components (com.haulmont.cuba.gui.components)10 WebAppWorkArea (com.haulmont.cuba.web.gui.components.mainwindow.WebAppWorkArea)6 WindowBreadCrumbs (com.haulmont.cuba.web.sys.WindowBreadCrumbs)6 ParamsMap (com.haulmont.bali.util.ParamsMap)5 Component (com.haulmont.cuba.gui.components.Component)5 WebAbstractComponent (com.haulmont.cuba.web.gui.components.WebAbstractComponent)5 Component (com.vaadin.ui.Component)5 Entity (com.haulmont.cuba.core.entity.Entity)4 TopLevelFrame (com.haulmont.cuba.desktop.TopLevelFrame)4 WindowConfig (com.haulmont.cuba.gui.config.WindowConfig)4 CssLayout (com.vaadin.ui.CssLayout)4 Pair (com.haulmont.bali.datastruct.Pair)3 WindowManager (com.haulmont.cuba.gui.WindowManager)3 Action (com.haulmont.cuba.gui.components.Action)3 ButtonsPanel (com.haulmont.cuba.gui.components.ButtonsPanel)3 Frame (com.haulmont.cuba.gui.components.Frame)3 WindowInfo (com.haulmont.cuba.gui.config.WindowInfo)3