Search in sources :

Example 1 with WebAppWorkArea

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

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

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

the class WebScreens method removeThisTabWindow.

protected void removeThisTabWindow(Screen screen) {
    TabWindow window = (TabWindow) screen.getWindow();
    com.vaadin.ui.Component windowComposition = window.unwrapComposition(com.vaadin.ui.Component.class);
    TabWindowContainer windowContainer = (TabWindowContainer) windowComposition.getParent();
    windowContainer.removeComponent(windowComposition);
    WindowBreadCrumbs breadCrumbs = windowContainer.getBreadCrumbs();
    breadCrumbs.removeWindow();
    Window currentWindow = breadCrumbs.getCurrentWindow();
    com.vaadin.ui.Component currentWindowComposition = currentWindow.unwrapComposition(com.vaadin.ui.Component.class);
    windowContainer.addComponent(currentWindowComposition);
    WebAppWorkArea workArea = getConfiguredWorkArea();
    if (workArea.getMode() == Mode.TABBED) {
        TabSheetBehaviour tabSheet = workArea.getTabbedWindowContainer().getTabSheetBehaviour();
        String tabId = tabSheet.getTab(windowContainer);
        TabWindow tabWindow = (TabWindow) currentWindow;
        String formattedCaption = tabWindow.formatTabCaption();
        String formattedDescription = tabWindow.formatTabDescription();
        tabSheet.setTabCaption(tabId, formattedCaption);
        if (!Objects.equals(formattedCaption, formattedDescription)) {
            tabSheet.setTabDescription(tabId, formattedDescription);
        } else {
            tabSheet.setTabDescription(tabId, null);
        }
        tabSheet.setTabIcon(tabId, iconResolver.getIconResource(currentWindow.getIcon()));
        tabSheet.setTabClosable(tabId, currentWindow.isCloseable());
        ContentSwitchMode contentSwitchMode = ContentSwitchMode.valueOf(tabWindow.getContentSwitchMode().name());
        tabSheet.setContentSwitchMode(tabId, contentSwitchMode);
    }
}
Also used : GuiDialogWindow(com.haulmont.cuba.web.gui.components.WebDialogWindow.GuiDialogWindow) WebWindow(com.haulmont.cuba.web.gui.WebWindow) WebTabWindow(com.haulmont.cuba.web.gui.components.WebTabWindow) WebAppWorkArea(com.haulmont.cuba.web.gui.components.mainwindow.WebAppWorkArea) com.haulmont.cuba.gui(com.haulmont.cuba.gui) WebTabWindow(com.haulmont.cuba.web.gui.components.WebTabWindow)

Example 4 with WebAppWorkArea

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

the class WebScreens method checkOpened.

protected void checkOpened(Screen screen) {
    WebAppWorkArea workArea = getConfiguredWorkAreaOrNull();
    if (workArea == null) {
        return;
    }
    // In case of 'managedMainTabSheetMode = UNLOAD_TABS',
    // inactive screens are detached, so we need to skip this check
    HasTabSheetBehaviour behaviour = workArea.getTabbedWindowContainer();
    if (behaviour instanceof CubaManagedTabSheet && ((CubaManagedTabSheet) behaviour).getMode() == UNLOAD_TABS) {
        return;
    }
    com.vaadin.ui.Component uiComponent = screen.getWindow().unwrapComposition(com.vaadin.ui.Component.class);
    if (!uiComponent.isAttached()) {
        throw new IllegalStateException("Screen is not opened " + screen.getId());
    }
}
Also used : WebAppWorkArea(com.haulmont.cuba.web.gui.components.mainwindow.WebAppWorkArea) com.haulmont.cuba.gui(com.haulmont.cuba.gui)

Example 5 with WebAppWorkArea

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

the class WebScreens method createNewTabLayout.

protected void createNewTabLayout(Screen screen) {
    WindowBreadCrumbs breadCrumbs = createWindowBreadCrumbs(screen);
    breadCrumbs.setWindowNavigateHandler(this::handleWindowBreadCrumbsNavigate);
    breadCrumbs.addWindow(screen.getWindow());
    WebWindow webWindow = (WebWindow) screen.getWindow();
    webWindow.setResolvedState(createOrUpdateState(webWindow.getResolvedState(), getConfiguredWorkArea().generateUrlStateMark()));
    TabWindowContainer windowContainer = new TabWindowContainerImpl();
    windowContainer.setPrimaryStyleName("c-app-window-wrap");
    windowContainer.setSizeFull();
    windowContainer.setBreadCrumbs(breadCrumbs);
    windowContainer.addComponent(breadCrumbs);
    Window window = screen.getWindow();
    com.vaadin.ui.Component windowComposition = window.unwrapComposition(com.vaadin.ui.Component.class);
    windowContainer.addComponent(windowComposition);
    WebAppWorkArea workArea = getConfiguredWorkArea();
    if (workArea.getMode() == Mode.TABBED) {
        windowContainer.addStyleName("c-app-tabbed-window");
        TabSheetBehaviour tabSheet = workArea.getTabbedWindowContainer().getTabSheetBehaviour();
        String tabId = "tab_" + uuidSource.createUuid();
        tabSheet.addTab(windowContainer, tabId);
        if (ui.isTestMode()) {
            String id = "tab_" + window.getId();
            tabSheet.setTabTestId(tabId, ui.getTestIdManager().getTestId(id));
            tabSheet.setTabCubaId(tabId, id);
        }
        TabWindow tabWindow = (TabWindow) window;
        String windowContentSwitchMode = tabWindow.getContentSwitchMode().name();
        ContentSwitchMode contentSwitchMode = ContentSwitchMode.valueOf(windowContentSwitchMode);
        tabSheet.setContentSwitchMode(tabId, contentSwitchMode);
        String formattedCaption = tabWindow.formatTabCaption();
        String formattedDescription = tabWindow.formatTabDescription();
        tabSheet.setTabCaption(tabId, formattedCaption);
        if (!Objects.equals(formattedCaption, formattedDescription)) {
            tabSheet.setTabDescription(tabId, formattedDescription);
        } else {
            tabSheet.setTabDescription(tabId, null);
        }
        tabSheet.setTabIcon(tabId, iconResolver.getIconResource(window.getIcon()));
        tabSheet.setTabClosable(tabId, window.isCloseable());
        tabSheet.setTabCloseHandler(windowContainer, this::handleTabWindowClose);
        tabSheet.setSelectedTab(windowContainer);
    } else {
        windowContainer.addStyleName("c-app-single-window");
        CubaSingleModeContainer mainLayout = workArea.getSingleWindowContainer();
        if (mainLayout.getWindowContainer() != null) {
            // remove all windows from single stack
            TabWindowContainer oldWindowContainer = (TabWindowContainer) mainLayout.getWindowContainer();
            Deque<Window> windows = oldWindowContainer.getBreadCrumbs().getWindows();
            Iterator<Window> iterator = windows.descendingIterator();
            while (iterator.hasNext()) {
                Window oldWindow = iterator.next();
                remove(oldWindow.getFrameOwner());
            }
            // after last window closed we need to switch back to window container
            workArea.switchTo(AppWorkArea.State.WINDOW_CONTAINER);
        }
        mainLayout.setWindowContainer(windowContainer);
    }
}
Also used : GuiDialogWindow(com.haulmont.cuba.web.gui.components.WebDialogWindow.GuiDialogWindow) WebWindow(com.haulmont.cuba.web.gui.WebWindow) WebTabWindow(com.haulmont.cuba.web.gui.components.WebTabWindow) WebWindow(com.haulmont.cuba.web.gui.WebWindow) WebAppWorkArea(com.haulmont.cuba.web.gui.components.mainwindow.WebAppWorkArea) com.haulmont.cuba.gui(com.haulmont.cuba.gui) WebTabWindow(com.haulmont.cuba.web.gui.components.WebTabWindow)

Aggregations

WebAppWorkArea (com.haulmont.cuba.web.gui.components.mainwindow.WebAppWorkArea)24 WebWindow (com.haulmont.cuba.web.gui.WebWindow)10 Screen (com.haulmont.cuba.gui.screen.Screen)7 CssLayout (com.vaadin.ui.CssLayout)7 com.haulmont.cuba.gui (com.haulmont.cuba.gui)6 WindowBreadCrumbs (com.haulmont.cuba.web.sys.WindowBreadCrumbs)6 Window (com.haulmont.cuba.gui.components.Window)5 WebAbstractComponent (com.haulmont.cuba.web.gui.components.WebAbstractComponent)5 GuiDialogWindow (com.haulmont.cuba.web.gui.components.WebDialogWindow.GuiDialogWindow)5 WebTabWindow (com.haulmont.cuba.web.gui.components.WebTabWindow)5 Component (com.vaadin.ui.Component)5 HasWorkArea (com.haulmont.cuba.gui.components.Window.HasWorkArea)3 AppWorkArea (com.haulmont.cuba.gui.components.mainwindow.AppWorkArea)3 Layout (com.vaadin.ui.Layout)3 Nonnull (javax.annotation.Nonnull)2 Nullable (javax.annotation.Nullable)2 Pair (com.haulmont.bali.datastruct.Pair)1 ParamsMap (com.haulmont.bali.util.ParamsMap)1 Preconditions.checkNotNullArgument (com.haulmont.bali.util.Preconditions.checkNotNullArgument)1 ReflectionHelper (com.haulmont.bali.util.ReflectionHelper)1