Search in sources :

Example 41 with Window

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

the class WebWindowManager method showWindow.

@Override
protected void showWindow(final Window window, final String caption, final String description, OpenType type, final boolean multipleOpen) {
    OpenType targetOpenType = type.copy();
    // for backward compatibility only
    copyDialogParamsToOpenType(targetOpenType);
    overrideOpenTypeParams(targetOpenType, window.getDialogOptions());
    boolean forciblyDialog = false;
    if (targetOpenType.getOpenMode() != OpenMode.DIALOG && hasModalWindow()) {
        targetOpenType.setOpenMode(OpenMode.DIALOG);
        forciblyDialog = true;
    }
    if (targetOpenType.getOpenMode() == OpenMode.THIS_TAB && tabs.size() == 0) {
        targetOpenType.setOpenMode(OpenMode.NEW_TAB);
    }
    final WindowOpenInfo openInfo = new WindowOpenInfo(window, targetOpenType.getOpenMode());
    Component component;
    window.setCaption(caption);
    window.setDescription(description);
    switch(targetOpenType.getOpenMode()) {
        case NEW_TAB:
        case NEW_WINDOW:
            final WebAppWorkArea workArea = getConfiguredWorkArea(createWorkAreaContext(window));
            workArea.switchTo(AppWorkArea.State.WINDOW_CONTAINER);
            if (workArea.getMode() == Mode.SINGLE) {
                VerticalLayout mainLayout = workArea.getSingleWindowContainer();
                if (mainLayout.iterator().hasNext()) {
                    ComponentContainer oldLayout = (ComponentContainer) mainLayout.iterator().next();
                    WindowBreadCrumbs oldBreadCrumbs = tabs.get(oldLayout);
                    if (oldBreadCrumbs != null) {
                        Window oldWindow = oldBreadCrumbs.getCurrentWindow();
                        oldWindow.closeAndRun(MAIN_MENU_ACTION_ID, () -> showWindow(window, caption, description, OpenType.NEW_TAB, false));
                        return;
                    }
                }
            } else {
                final Integer hashCode = getWindowHashCode(window);
                ComponentContainer tab = null;
                if (hashCode != null && !multipleOpen) {
                    tab = findTab(hashCode);
                }
                ComponentContainer oldLayout = tab;
                final WindowBreadCrumbs oldBreadCrumbs = tabs.get(oldLayout);
                if (oldBreadCrumbs != null && windowOpenMode.containsKey(oldBreadCrumbs.getCurrentWindow().getFrame()) && !multipleOpen) {
                    Window oldWindow = oldBreadCrumbs.getCurrentWindow();
                    selectWindowTab(((Window.Wrapper) oldBreadCrumbs.getCurrentWindow()).getWrappedWindow());
                    int tabPosition = -1;
                    final TabSheetBehaviour tabSheet = workArea.getTabbedWindowContainer().getTabSheetBehaviour();
                    String tabId = tabSheet.getTab(tab);
                    if (tabId != null) {
                        tabPosition = tabSheet.getTabPosition(tabId);
                    }
                    final int finalTabPosition = tabPosition;
                    oldWindow.closeAndRun(MAIN_MENU_ACTION_ID, () -> {
                        showWindow(window, caption, description, OpenType.NEW_TAB, false);
                        Window wrappedWindow = window;
                        if (window instanceof Window.Wrapper) {
                            wrappedWindow = ((Window.Wrapper) window).getWrappedWindow();
                        }
                        if (finalTabPosition >= 0 && finalTabPosition < tabSheet.getComponentCount() - 1) {
                            moveWindowTab(workArea, wrappedWindow, finalTabPosition);
                        }
                    });
                    return;
                }
            }
            component = showWindowNewTab(window, multipleOpen);
            break;
        case THIS_TAB:
            getConfiguredWorkArea(createWorkAreaContext(window)).switchTo(AppWorkArea.State.WINDOW_CONTAINER);
            component = showWindowThisTab(window, caption, description);
            break;
        case DIALOG:
            component = showWindowDialog(window, targetOpenType, forciblyDialog);
            break;
        default:
            throw new UnsupportedOperationException();
    }
    openInfo.setData(component);
    if (window instanceof Window.Wrapper) {
        Window wrappedWindow = ((Window.Wrapper) window).getWrappedWindow();
        windowOpenMode.put(wrappedWindow, openInfo);
    } else {
        windowOpenMode.put(window, openInfo);
    }
    afterShowWindow(window);
}
Also used : Window(com.haulmont.cuba.gui.components.Window) WebWindow(com.haulmont.cuba.web.gui.WebWindow) WebAppWorkArea(com.haulmont.cuba.web.gui.components.mainwindow.WebAppWorkArea) WindowBreadCrumbs(com.haulmont.cuba.web.sys.WindowBreadCrumbs) WebAbstractComponent(com.haulmont.cuba.web.gui.components.WebAbstractComponent) Component(com.vaadin.ui.Component)

Example 42 with Window

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

the class WebWindowManager method setWindowCaption.

@Override
public void setWindowCaption(Window window, String caption, String description) {
    Window webWindow = window;
    if (window instanceof Window.Wrapper) {
        webWindow = ((Window.Wrapper) window).getWrappedWindow();
    }
    window.setCaption(caption);
    window.setDebugId(description);
    WindowOpenInfo openInfo = windowOpenMode.get(webWindow);
    String formattedCaption;
    if (openInfo != null && (openInfo.getOpenMode() == OpenMode.NEW_TAB || openInfo.getOpenMode() == OpenMode.NEW_WINDOW || openInfo.getOpenMode() == OpenMode.THIS_TAB)) {
        formattedCaption = formatTabCaption(caption, description);
    } else {
        formattedCaption = formatTabDescription(caption, description);
    }
    if (openInfo != null) {
        if (openInfo.getOpenMode() == OpenMode.DIALOG) {
            com.vaadin.ui.Window dialog = (com.vaadin.ui.Window) openInfo.getData();
            dialog.setCaption(formattedCaption);
        } else {
            if (getConfiguredWorkArea(createWorkAreaContext(window)).getMode() == Mode.SINGLE) {
                return;
            }
            Component tabContent = (Component) openInfo.getData();
            if (tabContent == null) {
                return;
            }
            TabSheetBehaviour tabSheet = getConfiguredWorkArea(createWorkAreaContext(window)).getTabbedWindowContainer().getTabSheetBehaviour();
            String tabId = tabSheet.getTab(tabContent);
            if (tabId == null) {
                return;
            }
            tabSheet.setTabCaption(tabId, formattedCaption);
            String formattedDescription = formatTabDescription(caption, description);
            if (!Objects.equals(formattedDescription, formattedCaption)) {
                tabSheet.setTabDescription(tabId, formattedDescription);
            } else {
                tabSheet.setTabDescription(tabId, null);
            }
        }
    }
}
Also used : Window(com.haulmont.cuba.gui.components.Window) WebWindow(com.haulmont.cuba.web.gui.WebWindow) com.haulmont.cuba.web.toolkit.ui(com.haulmont.cuba.web.toolkit.ui) com.vaadin.ui(com.vaadin.ui) WebAbstractComponent(com.haulmont.cuba.web.gui.components.WebAbstractComponent) Component(com.vaadin.ui.Component)

Example 43 with Window

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

the class WebWindowManager method openDefaultScreen.

@Override
public void openDefaultScreen() {
    String defaultScreenId = webConfig.getDefaultScreenId();
    if (webConfig.getUserCanChooseDefaultScreen()) {
        String userDefaultScreen = userSettingService.loadSetting(ClientType.WEB, "userDefaultScreen");
        defaultScreenId = StringUtils.isEmpty(userDefaultScreen) ? defaultScreenId : userDefaultScreen;
    }
    if (StringUtils.isEmpty(defaultScreenId)) {
        return;
    }
    if (!windowConfig.hasWindow(defaultScreenId)) {
        log.info("Can't find default screen: {}", defaultScreenId);
        return;
    }
    Window window = openWindow(windowConfig.getWindowInfo(defaultScreenId), OpenType.NEW_TAB);
    // in case of window is created by Runnable instance
    if (window == null) {
        return;
    }
    if (!webConfig.getDefaultScreenCanBeClosed()) {
        WebAppWorkArea workArea = getConfiguredWorkArea(createWorkAreaContext(window));
        if (workArea.getMode() == Mode.TABBED) {
            TabSheetBehaviour tabSheetBehaviour = workArea.getTabbedWindowContainer().getTabSheetBehaviour();
            HasComponents tabLayout = WebComponentsHelper.getComposition(window).getParent();
            String tabId = tabSheetBehaviour.getTab(tabLayout);
            tabSheetBehaviour.setTabClosable(tabId, false);
        }
    }
}
Also used : Window(com.haulmont.cuba.gui.components.Window) WebWindow(com.haulmont.cuba.web.gui.WebWindow) WebAppWorkArea(com.haulmont.cuba.web.gui.components.mainwindow.WebAppWorkArea)

Example 44 with Window

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

the class WebWindowManager method closeAllTabbedWindowsExcept.

public void closeAllTabbedWindowsExcept(@Nullable ComponentContainer keepOpened) {
    boolean modified = false;
    List<WebWindow> windowsToClose = new ArrayList<>();
    WindowBreadCrumbs keepOpenedCrumbs = tabs.get(keepOpened);
    Frame keepOpenedFrame = keepOpenedCrumbs != null ? keepOpenedCrumbs.getCurrentWindow().getFrame() : null;
    for (Window window : getOpenWindows()) {
        if (!canWindowBeClosed(window)) {
            continue;
        }
        OpenMode openMode = windowOpenMode.get(window).getOpenMode();
        WindowBreadCrumbs windowBreadCrumbs = tabs.get(windowOpenMode.get(window).getData());
        Window currentWindow = (windowBreadCrumbs != null && window != windowBreadCrumbs.getCurrentWindow()) ? windowBreadCrumbs.getCurrentWindow() : window;
        if (window.getFrame() == keepOpenedFrame || openMode == OpenMode.DIALOG || keepOpenedCrumbs == windowBreadCrumbs || isCloseWithCloseButtonPrevented(currentWindow))
            continue;
        if (window.getDsContext() != null && window.getDsContext().isModified()) {
            modified = true;
        }
        windowsToClose.add((WebWindow) window);
    }
    disableSavingScreenHistory = true;
    if (modified) {
        showOptionDialog(messages.getMainMessage("closeUnsaved.caption"), messages.getMainMessage("discardChangesInTabs"), MessageType.WARNING, new Action[] { new AbstractAction(messages.getMainMessage("closeTabs")) {

            {
                icon = icons.get(CubaIcon.DIALOG_OK);
            }

            @Override
            public void actionPerform(com.haulmont.cuba.gui.components.Component component) {
                closeTabsForce(windowsToClose);
            }
        }, new DialogAction(Type.CANCEL, Status.PRIMARY) });
    } else {
        closeTabsForce(windowsToClose);
    }
}
Also used : Window(com.haulmont.cuba.gui.components.Window) WebWindow(com.haulmont.cuba.web.gui.WebWindow) BelongToFrame(com.haulmont.cuba.gui.components.Component.BelongToFrame) com.haulmont.cuba.gui.components(com.haulmont.cuba.gui.components) WebWindow(com.haulmont.cuba.web.gui.WebWindow) WindowBreadCrumbs(com.haulmont.cuba.web.sys.WindowBreadCrumbs)

Example 45 with Window

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

the class WebWindowManager method closeWindow.

protected void closeWindow(Window window, WindowOpenInfo openInfo) {
    if (!disableSavingScreenHistory) {
        screenHistorySupport.saveScreenHistory(window, openInfo.getOpenMode());
    }
    WebWindow webWindow = (WebWindow) window;
    webWindow.stopTimers();
    switch(openInfo.getOpenMode()) {
        case DIALOG:
            {
                final CubaWindow cubaDialogWindow = (CubaWindow) openInfo.getData();
                cubaDialogWindow.forceClose();
                fireListeners(window, tabs.size() != 0);
                break;
            }
        case NEW_WINDOW:
        case NEW_TAB:
            {
                final Layout layout = (Layout) openInfo.getData();
                layout.removeComponent(WebComponentsHelper.getComposition(window));
                WebAppWorkArea workArea = getConfiguredWorkArea(createWorkAreaContext(window));
                if (workArea.getMode() == Mode.TABBED) {
                    TabSheetBehaviour tabSheet = workArea.getTabbedWindowContainer().getTabSheetBehaviour();
                    tabSheet.silentCloseTabAndSelectPrevious(layout);
                    tabSheet.removeComponent(layout);
                } else {
                    VerticalLayout singleLayout = workArea.getSingleWindowContainer();
                    singleLayout.removeComponent(layout);
                }
                WindowBreadCrumbs windowBreadCrumbs = tabs.get(layout);
                if (windowBreadCrumbs != null) {
                    windowBreadCrumbs.clearListeners();
                    windowBreadCrumbs.removeWindow();
                }
                tabs.remove(layout);
                stacks.remove(windowBreadCrumbs);
                fireListeners(window, !tabs.isEmpty());
                if (tabs.isEmpty() && app.getConnection().isConnected()) {
                    workArea.switchTo(AppWorkArea.State.INITIAL_LAYOUT);
                }
                break;
            }
        case THIS_TAB:
            {
                final Layout layout = (Layout) openInfo.getData();
                final WindowBreadCrumbs breadCrumbs = tabs.get(layout);
                if (breadCrumbs == null) {
                    throw new IllegalStateException("Unable to close screen: breadCrumbs not found");
                }
                breadCrumbs.removeWindow();
                Window currentWindow = breadCrumbs.getCurrentWindow();
                if (!getStack(breadCrumbs).empty()) {
                    Pair<Window, Integer> entry = getStack(breadCrumbs).pop();
                    putToWindowMap(entry.getFirst(), entry.getSecond());
                }
                Component component = WebComponentsHelper.getComposition(currentWindow);
                component.setSizeFull();
                WebAppWorkArea workArea = getConfiguredWorkArea(createWorkAreaContext(window));
                layout.removeComponent(WebComponentsHelper.getComposition(window));
                if (app.getConnection().isConnected()) {
                    layout.addComponent(component);
                    if (workArea.getMode() == Mode.TABBED) {
                        TabSheetBehaviour tabSheet = workArea.getTabbedWindowContainer().getTabSheetBehaviour();
                        String tabId = tabSheet.getTab(layout);
                        String formattedCaption = formatTabCaption(currentWindow.getCaption(), currentWindow.getDescription());
                        tabSheet.setTabCaption(tabId, formattedCaption);
                        String formattedDescription = formatTabDescription(currentWindow.getCaption(), currentWindow.getDescription());
                        if (!Objects.equals(formattedCaption, formattedDescription)) {
                            tabSheet.setTabDescription(tabId, formattedDescription);
                        } else {
                            tabSheet.setTabDescription(tabId, null);
                        }
                        tabSheet.setTabIcon(tabId, iconResolver.getIconResource(currentWindow.getIcon()));
                        ContentSwitchMode contentSwitchMode = ContentSwitchMode.valueOf(currentWindow.getContentSwitchMode().name());
                        tabSheet.setContentSwitchMode(tabId, contentSwitchMode);
                    }
                }
                fireListeners(window, !tabs.isEmpty());
                if (tabs.isEmpty() && app.getConnection().isConnected()) {
                    workArea.switchTo(AppWorkArea.State.INITIAL_LAYOUT);
                }
                break;
            }
        default:
            {
                throw new UnsupportedOperationException();
            }
    }
}
Also used : Window(com.haulmont.cuba.gui.components.Window) WebWindow(com.haulmont.cuba.web.gui.WebWindow) WebWindow(com.haulmont.cuba.web.gui.WebWindow) WebAppWorkArea(com.haulmont.cuba.web.gui.components.mainwindow.WebAppWorkArea) CssLayout(com.vaadin.ui.CssLayout) WindowBreadCrumbs(com.haulmont.cuba.web.sys.WindowBreadCrumbs) WebAbstractComponent(com.haulmont.cuba.web.gui.components.WebAbstractComponent) Component(com.vaadin.ui.Component) Pair(com.haulmont.bali.datastruct.Pair)

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