Search in sources :

Example 6 with WindowBreadCrumbs

use of com.haulmont.cuba.web.sys.WindowBreadCrumbs 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 7 with WindowBreadCrumbs

use of com.haulmont.cuba.web.sys.WindowBreadCrumbs 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 8 with WindowBreadCrumbs

use of com.haulmont.cuba.web.sys.WindowBreadCrumbs 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

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