Search in sources :

Example 6 with WebAppWorkArea

use of com.haulmont.cuba.web.gui.components.mainwindow.WebAppWorkArea 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)

Example 7 with WebAppWorkArea

use of com.haulmont.cuba.web.gui.components.mainwindow.WebAppWorkArea in project cuba by cuba-platform.

the class WebWindowManager method showWindowThisTab.

protected Component showWindowThisTab(final Window window, final String caption, final String description) {
    getDialogParams().reset();
    WebAppWorkArea workArea = getConfiguredWorkArea(createWorkAreaContext(window));
    Layout layout;
    if (workArea.getMode() == Mode.TABBED) {
        TabSheetBehaviour tabSheet = workArea.getTabbedWindowContainer().getTabSheetBehaviour();
        layout = (Layout) tabSheet.getSelectedTab();
    } else {
        layout = (Layout) workArea.getSingleWindowContainer().getComponent(0);
    }
    final WindowBreadCrumbs breadCrumbs = tabs.get(layout);
    if (breadCrumbs == null) {
        throw new IllegalStateException("BreadCrumbs not found");
    }
    final Window currentWindow = breadCrumbs.getCurrentWindow();
    Set<Map.Entry<Window, Integer>> set = windows.entrySet();
    boolean pushed = false;
    for (Map.Entry<Window, Integer> entry : set) {
        if (entry.getKey().equals(currentWindow)) {
            windows.remove(currentWindow);
            getStack(breadCrumbs).push(new Pair<>(entry.getKey(), entry.getValue()));
            pushed = true;
            break;
        }
    }
    if (!pushed) {
        getStack(breadCrumbs).push(new Pair<>(currentWindow, null));
    }
    removeFromWindowMap(currentWindow);
    layout.removeComponent(WebComponentsHelper.getComposition(currentWindow));
    final Component component = WebComponentsHelper.getComposition(window);
    component.setSizeFull();
    layout.addComponent(component);
    breadCrumbs.addWindow(window);
    if (workArea.getMode() == Mode.TABBED) {
        TabSheetBehaviour tabSheet = workArea.getTabbedWindowContainer().getTabSheetBehaviour();
        String tabId = tabSheet.getTab(layout);
        String formattedCaption = formatTabCaption(caption, description);
        tabSheet.setTabCaption(tabId, formattedCaption);
        String formattedDescription = formatTabDescription(caption, description);
        if (!Objects.equals(formattedCaption, formattedDescription)) {
            tabSheet.setTabDescription(tabId, formattedDescription);
        } else {
            tabSheet.setTabDescription(tabId, null);
        }
        tabSheet.setTabIcon(tabId, iconResolver.getIconResource(window.getIcon()));
        ContentSwitchMode contentSwitchMode = ContentSwitchMode.valueOf(window.getContentSwitchMode().name());
        tabSheet.setContentSwitchMode(tabId, contentSwitchMode);
    } else {
        layout.markAsDirtyRecursive();
    }
    return layout;
}
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) 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) ParamsMap(com.haulmont.bali.util.ParamsMap) Collections.singletonMap(java.util.Collections.singletonMap)

Aggregations

WebAppWorkArea (com.haulmont.cuba.web.gui.components.mainwindow.WebAppWorkArea)7 WindowBreadCrumbs (com.haulmont.cuba.web.sys.WindowBreadCrumbs)6 Window (com.haulmont.cuba.gui.components.Window)5 WebWindow (com.haulmont.cuba.web.gui.WebWindow)5 WebAbstractComponent (com.haulmont.cuba.web.gui.components.WebAbstractComponent)5 Component (com.vaadin.ui.Component)5 CssLayout (com.vaadin.ui.CssLayout)4 Pair (com.haulmont.bali.datastruct.Pair)1 ParamsMap (com.haulmont.bali.util.ParamsMap)1 ShortcutListener (com.vaadin.event.ShortcutListener)1 Collections.singletonMap (java.util.Collections.singletonMap)1