Search in sources :

Example 6 with WebWindow

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

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

use of com.haulmont.cuba.web.gui.WebWindow 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

WebWindow (com.haulmont.cuba.web.gui.WebWindow)8 Window (com.haulmont.cuba.gui.components.Window)5 com.haulmont.cuba.gui.components (com.haulmont.cuba.gui.components)2 WebAbstractComponent (com.haulmont.cuba.web.gui.components.WebAbstractComponent)2 WindowBreadCrumbs (com.haulmont.cuba.web.sys.WindowBreadCrumbs)2 Component (com.vaadin.ui.Component)2 Pair (com.haulmont.bali.datastruct.Pair)1 BelongToFrame (com.haulmont.cuba.gui.components.Component.BelongToFrame)1 BeforeCloseWithCloseButtonEvent (com.haulmont.cuba.gui.components.Window.BeforeCloseWithCloseButtonEvent)1 BeforeCloseWithShortcutEvent (com.haulmont.cuba.gui.components.Window.BeforeCloseWithShortcutEvent)1 WebAppWorkArea (com.haulmont.cuba.web.gui.components.mainwindow.WebAppWorkArea)1 com.haulmont.cuba.web.toolkit.ui (com.haulmont.cuba.web.toolkit.ui)1 com.vaadin.ui (com.vaadin.ui)1 CssLayout (com.vaadin.ui.CssLayout)1