Search in sources :

Example 1 with TopLevelWindowAttachListener

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

the class WebWindowManager method createTopLevelWindow.

public void createTopLevelWindow(WindowInfo windowInfo) {
    ui.beforeTopLevelWindowInit();
    String template = windowInfo.getTemplate();
    Window.TopLevelWindow topLevelWindow;
    Map<String, Object> params = Collections.emptyMap();
    if (template != null) {
        // noinspection unchecked
        topLevelWindow = (Window.TopLevelWindow) createWindow(windowInfo, OpenType.NEW_TAB, params, LayoutLoaderConfig.getWindowLoaders(), true);
    } else {
        Class screenClass = windowInfo.getScreenClass();
        if (screenClass != null) {
            // noinspection unchecked
            topLevelWindow = (Window.TopLevelWindow) createWindowByScreenClass(windowInfo, params);
        } else {
            throw new DevelopmentException("Unable to load top level window");
        }
    }
    // detect work area
    Window windowImpl = ((Window.Wrapper) topLevelWindow).getWrappedWindow();
    if (topLevelWindow instanceof AbstractMainWindow) {
        AbstractMainWindow mainWindow = (AbstractMainWindow) topLevelWindow;
        // bind system UI components to AbstractMainWindow
        ComponentsHelper.walkComponents(windowImpl, component -> {
            if (component instanceof AppWorkArea) {
                mainWindow.setWorkArea((AppWorkArea) component);
            } else if (component instanceof UserIndicator) {
                mainWindow.setUserIndicator((UserIndicator) component);
            } else if (component instanceof FoldersPane) {
                mainWindow.setFoldersPane((FoldersPane) component);
            }
            return false;
        });
    }
    ui.setTopLevelWindow(topLevelWindow);
    // load menu
    ComponentsHelper.walkComponents(windowImpl, component -> {
        if (component instanceof TopLevelWindowAttachListener) {
            ((TopLevelWindowAttachListener) component).topLevelWindowAttached(topLevelWindow);
        }
        return false;
    });
    if (topLevelWindow instanceof Window.HasWorkArea) {
        AppWorkArea workArea = ((Window.HasWorkArea) topLevelWindow).getWorkArea();
        if (workArea != null) {
            workArea.addStateChangeListener(new AppWorkArea.StateChangeListener() {

                @Override
                public void stateChanged(AppWorkArea.State newState) {
                    if (newState == AppWorkArea.State.WINDOW_CONTAINER) {
                        initTabShortcuts();
                        // listener used only once
                        getConfiguredWorkArea(createWorkAreaContext(topLevelWindow)).removeStateChangeListener(this);
                    }
                }
            });
        }
    }
    afterShowWindow(topLevelWindow);
}
Also used : Window(com.haulmont.cuba.gui.components.Window) WebWindow(com.haulmont.cuba.web.gui.WebWindow) FoldersPane(com.haulmont.cuba.gui.components.mainwindow.FoldersPane) TopLevelWindowAttachListener(com.haulmont.cuba.gui.components.mainwindow.TopLevelWindowAttachListener) DevelopmentException(com.haulmont.cuba.core.global.DevelopmentException) WebAppWorkArea(com.haulmont.cuba.web.gui.components.mainwindow.WebAppWorkArea) AppWorkArea(com.haulmont.cuba.gui.components.mainwindow.AppWorkArea) UserIndicator(com.haulmont.cuba.gui.components.mainwindow.UserIndicator)

Aggregations

DevelopmentException (com.haulmont.cuba.core.global.DevelopmentException)1 Window (com.haulmont.cuba.gui.components.Window)1 AppWorkArea (com.haulmont.cuba.gui.components.mainwindow.AppWorkArea)1 FoldersPane (com.haulmont.cuba.gui.components.mainwindow.FoldersPane)1 TopLevelWindowAttachListener (com.haulmont.cuba.gui.components.mainwindow.TopLevelWindowAttachListener)1 UserIndicator (com.haulmont.cuba.gui.components.mainwindow.UserIndicator)1 WebWindow (com.haulmont.cuba.web.gui.WebWindow)1 WebAppWorkArea (com.haulmont.cuba.web.gui.components.mainwindow.WebAppWorkArea)1