Search in sources :

Example 1 with WindowBreadCrumbs

use of com.haulmont.cuba.web.sys.WindowBreadCrumbs in project cuba by cuba-platform.

the class WebWindowManager method createNewTabLayout.

protected Layout createNewTabLayout(final Window window, final boolean multipleOpen, WindowBreadCrumbs breadCrumbs, Component... additionalComponents) {
    Layout layout = new CssLayout();
    layout.setPrimaryStyleName("c-app-window-wrap");
    layout.setSizeFull();
    layout.addComponent(breadCrumbs);
    if (additionalComponents != null) {
        for (final Component c : additionalComponents) {
            layout.addComponent(c);
        }
    }
    final Component component = WebComponentsHelper.getComposition(window);
    component.setSizeFull();
    layout.addComponent(component);
    WebAppWorkArea workArea = getConfiguredWorkArea(createWorkAreaContext(window));
    if (workArea.getMode() == Mode.TABBED) {
        layout.addStyleName("c-app-tabbed-window");
        TabSheetBehaviour tabSheet = workArea.getTabbedWindowContainer().getTabSheetBehaviour();
        String tabId;
        Integer hashCode = getWindowHashCode(window);
        ComponentContainer tab = null;
        if (hashCode != null) {
            tab = findTab(hashCode);
        }
        if (tab != null && !multipleOpen) {
            tabSheet.replaceComponent(tab, layout);
            tabSheet.removeComponent(tab);
            tabs.put(layout, breadCrumbs);
            tabId = tabSheet.getTab(layout);
        } else {
            tabs.put(layout, breadCrumbs);
            tabId = "tab_" + uuidSource.createUuid();
            tabSheet.addTab(layout, tabId);
            if (ui.isTestMode()) {
                String id = "tab_" + window.getId();
                tabSheet.setTabTestId(tabId, ui.getTestIdManager().getTestId(id));
                tabSheet.setTabCubaId(tabId, id);
            }
        }
        String windowContentSwitchMode = window.getContentSwitchMode().name();
        ContentSwitchMode contentSwitchMode = ContentSwitchMode.valueOf(windowContentSwitchMode);
        tabSheet.setContentSwitchMode(tabId, contentSwitchMode);
        String formattedCaption = formatTabCaption(window.getCaption(), window.getDescription());
        tabSheet.setTabCaption(tabId, formattedCaption);
        String formattedDescription = formatTabDescription(window.getCaption(), window.getDescription());
        if (!Objects.equals(formattedCaption, formattedDescription)) {
            tabSheet.setTabDescription(tabId, formattedDescription);
        } else {
            tabSheet.setTabDescription(tabId, null);
        }
        tabSheet.setTabIcon(tabId, iconResolver.getIconResource(window.getIcon()));
        tabSheet.setTabClosable(tabId, true);
        tabSheet.setTabCloseHandler(layout, (targetTabSheet, tabContent) -> {
            // noinspection SuspiciousMethodCalls
            WindowBreadCrumbs breadCrumbs1 = tabs.get(tabContent);
            if (!canWindowBeClosed(breadCrumbs1.getCurrentWindow())) {
                return;
            }
            Runnable closeTask = new TabCloseTask(breadCrumbs1);
            closeTask.run();
            // it is needed to force redraw tabsheet if it has a lot of tabs and part of them are hidden
            targetTabSheet.markAsDirty();
        });
        tabSheet.setSelectedTab(layout);
    } else {
        tabs.put(layout, breadCrumbs);
        layout.addStyleName("c-app-single-window");
        VerticalLayout mainLayout = workArea.getSingleWindowContainer();
        mainLayout.removeAllComponents();
        mainLayout.addComponent(layout);
    }
    return layout;
}
Also used : WebAppWorkArea(com.haulmont.cuba.web.gui.components.mainwindow.WebAppWorkArea) CssLayout(com.vaadin.ui.CssLayout) 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)

Example 2 with WindowBreadCrumbs

use of com.haulmont.cuba.web.sys.WindowBreadCrumbs in project cuba by cuba-platform.

the class WebWindowManager method createWindowBreadCrumbs.

protected WindowBreadCrumbs createWindowBreadCrumbs(Window window) {
    WebAppWorkArea appWorkArea = getConfiguredWorkArea(createWorkAreaContext(window));
    WindowBreadCrumbs windowBreadCrumbs = new WindowBreadCrumbs(appWorkArea);
    boolean showBreadCrumbs = webConfig.getShowBreadCrumbs() || Mode.SINGLE == appWorkArea.getMode();
    windowBreadCrumbs.setVisible(showBreadCrumbs);
    stacks.put(windowBreadCrumbs, new Stack<>());
    return windowBreadCrumbs;
}
Also used : WebAppWorkArea(com.haulmont.cuba.web.gui.components.mainwindow.WebAppWorkArea) WindowBreadCrumbs(com.haulmont.cuba.web.sys.WindowBreadCrumbs)

Example 3 with WindowBreadCrumbs

use of com.haulmont.cuba.web.sys.WindowBreadCrumbs in project cuba by cuba-platform.

the class WebWindowManager method createCloseShortcut.

public ShortcutListener createCloseShortcut(Window.TopLevelWindow topLevelWindow) {
    String closeShortcut = clientConfig.getCloseShortcut();
    KeyCombination combination = KeyCombination.create(closeShortcut);
    return new ShortcutListener("onClose", combination.getKey().getCode(), KeyCombination.Modifier.codes(combination.getModifiers())) {

        @Override
        public void handleAction(Object sender, Object target) {
            WebAppWorkArea workArea = getConfiguredWorkArea(createWorkAreaContext(topLevelWindow));
            if (workArea.getState() != AppWorkArea.State.WINDOW_CONTAINER) {
                return;
            }
            if (workArea.getMode() == Mode.TABBED) {
                TabSheetBehaviour tabSheet = workArea.getTabbedWindowContainer().getTabSheetBehaviour();
                if (tabSheet != null) {
                    Layout layout = (Layout) tabSheet.getSelectedTab();
                    if (layout != null) {
                        tabSheet.focus();
                        WindowBreadCrumbs breadCrumbs = tabs.get(layout);
                        if (!canWindowBeClosed(breadCrumbs.getCurrentWindow())) {
                            return;
                        }
                        if (isCloseWithShortcutPrevented(breadCrumbs.getCurrentWindow())) {
                            return;
                        }
                        if (stacks.get(breadCrumbs).empty()) {
                            final Component previousTab = tabSheet.getPreviousTab(layout);
                            if (previousTab != null) {
                                breadCrumbs.getCurrentWindow().closeAndRun(Window.CLOSE_ACTION_ID, () -> tabSheet.setSelectedTab(previousTab));
                            } else {
                                breadCrumbs.getCurrentWindow().close(Window.CLOSE_ACTION_ID);
                            }
                        } else {
                            breadCrumbs.getCurrentWindow().close(Window.CLOSE_ACTION_ID);
                        }
                    }
                }
            } else {
                Iterator<WindowBreadCrumbs> it = tabs.values().iterator();
                if (it.hasNext()) {
                    Window currentWindow = it.next().getCurrentWindow();
                    if (!isCloseWithShortcutPrevented(currentWindow)) {
                        ui.focus();
                        currentWindow.close(Window.CLOSE_ACTION_ID);
                    }
                }
            }
        }
    };
}
Also used : WebAppWorkArea(com.haulmont.cuba.web.gui.components.mainwindow.WebAppWorkArea) Window(com.haulmont.cuba.gui.components.Window) WebWindow(com.haulmont.cuba.web.gui.WebWindow) ShortcutListener(com.vaadin.event.ShortcutListener) 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)

Example 4 with WindowBreadCrumbs

use of com.haulmont.cuba.web.sys.WindowBreadCrumbs in project cuba by cuba-platform.

the class WebWindowManager method showWindowNewTab.

protected Component showWindowNewTab(final Window window, final boolean multipleOpen) {
    getDialogParams().reset();
    final WindowBreadCrumbs breadCrumbs = createWindowBreadCrumbs(window);
    breadCrumbs.addListener(new WindowBreadCrumbs.Listener() {

        @Override
        public void windowClick(final Window window) {
            Runnable op = new Runnable() {

                @Override
                public void run() {
                    Window currentWindow = breadCrumbs.getCurrentWindow();
                    if (currentWindow != null && window != currentWindow) {
                        if (!isCloseWithCloseButtonPrevented(currentWindow)) {
                            currentWindow.closeAndRun(Window.CLOSE_ACTION_ID, this);
                        }
                    }
                }
            };
            op.run();
        }
    });
    breadCrumbs.addWindow(window);
    // noinspection UnnecessaryLocalVariable
    final Layout layout = createNewTabLayout(window, multipleOpen, breadCrumbs);
    return layout;
}
Also used : Window(com.haulmont.cuba.gui.components.Window) WebWindow(com.haulmont.cuba.web.gui.WebWindow) CssLayout(com.vaadin.ui.CssLayout) WindowBreadCrumbs(com.haulmont.cuba.web.sys.WindowBreadCrumbs)

Example 5 with WindowBreadCrumbs

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

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