Search in sources :

Example 1 with WindowImplementation

use of com.haulmont.cuba.gui.components.sys.WindowImplementation in project cuba by cuba-platform.

the class WebScreens method createWindow.

protected Window createWindow(@SuppressWarnings("unused") WindowInfo windowInfo, Class<? extends Screen> screenClass, ScreenOpenDetails openDetails) {
    Window window;
    OpenMode openMode = openDetails.getOpenMode();
    switch(openMode) {
        case ROOT:
            // todo we should update UI theme and its properties only when RootWindow is attached to UI
            ui.beforeTopLevelWindowInit();
            window = uiComponents.create(RootWindow.NAME);
            break;
        case THIS_TAB:
        case NEW_TAB:
            window = uiComponents.create(TabWindow.NAME);
            break;
        case DIALOG:
            DialogWindow dialogWindow = uiComponents.create(DialogWindow.NAME);
            if (openDetails.isForceDialog()) {
                ThemeConstants theme = ui.getApp().getThemeConstants();
                dialogWindow.setDialogWidth(theme.get("cuba.web.WebWindowManager.forciblyDialog.width"));
                dialogWindow.setDialogHeight(theme.get("cuba.web.WebWindowManager.forciblyDialog.height"));
                dialogWindow.setResizable(true);
            } else {
                DialogMode dialogMode = screenClass.getAnnotation(DialogMode.class);
                if (dialogMode != null) {
                    dialogWindow.setModal(dialogMode.modal());
                    dialogWindow.setCloseable(dialogMode.closeable());
                    dialogWindow.setResizable(dialogMode.resizable());
                    dialogWindow.setCloseOnClickOutside(dialogMode.closeOnClickOutside());
                    if (StringUtils.isNotEmpty(dialogMode.width())) {
                        dialogWindow.setDialogWidth(dialogMode.width());
                    }
                    if (StringUtils.isNotEmpty(dialogMode.height())) {
                        dialogWindow.setDialogHeight(dialogMode.height());
                    }
                    dialogWindow.setWindowMode(dialogMode.windowMode());
                }
            }
            window = dialogWindow;
            break;
        default:
            throw new UnsupportedOperationException("Unsupported launch mode " + openMode);
    }
    WindowContextImpl windowContext = new WindowContextImpl(window, openDetails.getOpenMode());
    ((WindowImplementation) window).setContext(windowContext);
    return window;
}
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) ThemeConstants(com.haulmont.cuba.gui.theme.ThemeConstants) WindowImplementation(com.haulmont.cuba.gui.components.sys.WindowImplementation) GuiDialogWindow(com.haulmont.cuba.web.gui.components.WebDialogWindow.GuiDialogWindow)

Example 2 with WindowImplementation

use of com.haulmont.cuba.gui.components.sys.WindowImplementation in project cuba by cuba-platform.

the class WebScreens method createScreen.

protected <T extends Screen> T createScreen(WindowInfo windowInfo, LaunchMode launchMode, ScreenOptions options) {
    if (windowInfo.getType() != WindowInfo.Type.SCREEN) {
        throw new DevelopmentException(String.format("Unable to create screen %s with type %s. If the screen is defined as @UiController make sure it is not present in legacy screens.xml", windowInfo.getId(), windowInfo.getType()));
    }
    @SuppressWarnings("unchecked") Class<T> resolvedScreenClass = (Class<T>) windowInfo.getControllerClass();
    // load XML document here in order to get metadata before Window creation, e.g. forceDialog from <dialogMode>
    Element element = loadScreenXml(windowInfo, options);
    ScreenOpenDetails openDetails = prepareScreenOpenDetails(resolvedScreenClass, element, launchMode);
    checkPermissions(openDetails.getOpenMode(), windowInfo);
    StopWatch createStopWatch = createStopWatch(ScreenLifeCycle.CREATE, windowInfo.getId());
    Window window = createWindow(windowInfo, resolvedScreenClass, openDetails);
    T controller = createController(windowInfo, window, resolvedScreenClass);
    // setup screen and controller
    setWindowId(controller, windowInfo.getId());
    setFrame(controller, window);
    setScreenContext(controller, new ScreenContextImpl(windowInfo, options, this, ui.getDialogs(), ui.getNotifications(), ui.getFragments(), ui.getUrlRouting(), ui.getWebBrowserTools()));
    setScreenData(controller, new ScreenDataImpl());
    WindowImplementation windowImpl = (WindowImplementation) window;
    windowImpl.setFrameOwner(controller);
    windowImpl.setId(controller.getId());
    createStopWatch.stop();
    // load UI from XML
    StopWatch loadStopWatch = createStopWatch(ScreenLifeCycle.LOAD, windowInfo.getId());
    ComponentLoaderContext componentLoaderContext = new ComponentLoaderContext(options);
    componentLoaderContext.setFullFrameId(windowInfo.getId());
    componentLoaderContext.setCurrentFrameId(windowInfo.getId());
    componentLoaderContext.setMessagesPack(getPackage(resolvedScreenClass));
    componentLoaderContext.setFrame(window);
    if (element != null) {
        loadWindowFromXml(element, windowInfo, window, controller, componentLoaderContext);
    }
    loadStopWatch.stop();
    // inject top level screen dependencies
    StopWatch injectStopWatch = createStopWatch(ScreenLifeCycle.INJECTION, windowInfo.getId());
    for (ControllerDependencyInjector dependencyInjector : dependencyInjectors) {
        dependencyInjector.inject(new ControllerDependencyInjector.InjectionContext(controller, options));
    }
    injectStopWatch.stop();
    // perform injection in nested fragments
    componentLoaderContext.executeInjectTasks();
    // run init
    StopWatch initStopWatch = createStopWatch(ScreenLifeCycle.INIT, windowInfo.getId());
    fireEvent(controller, InitEvent.class, new InitEvent(controller, options));
    initStopWatch.stop();
    componentLoaderContext.executeInitTasks();
    componentLoaderContext.executePostInitTasks();
    fireEvent(controller, AfterInitEvent.class, new AfterInitEvent(controller, options));
    return controller;
}
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) Element(org.dom4j.Element) WindowImplementation(com.haulmont.cuba.gui.components.sys.WindowImplementation) ComponentLoaderContext(com.haulmont.cuba.gui.xml.layout.loaders.ComponentLoaderContext) UIPerformanceLogger.createStopWatch(com.haulmont.cuba.gui.logging.UIPerformanceLogger.createStopWatch) StopWatch(org.perf4j.StopWatch) ScreenDataImpl(com.haulmont.cuba.gui.model.impl.ScreenDataImpl)

Example 3 with WindowImplementation

use of com.haulmont.cuba.gui.components.sys.WindowImplementation in project cuba by cuba-platform.

the class WebScreens method remove.

@Override
public void remove(Screen screen) {
    checkNotNullArgument(screen);
    checkOpened(screen);
    WindowImplementation windowImpl = (WindowImplementation) screen.getWindow();
    if (windowImpl instanceof Disposable) {
        ((Disposable) windowImpl).dispose();
    }
    LaunchMode launchMode = windowImpl.getContext().getLaunchMode();
    if (launchMode instanceof OpenMode) {
        OpenMode openMode = (OpenMode) launchMode;
        switch(openMode) {
            case DIALOG:
                removeDialogWindow(screen);
                break;
            case NEW_TAB:
            case NEW_WINDOW:
                removeNewTabWindow(screen);
                break;
            case ROOT:
                removeRootWindow(screen);
                break;
            case THIS_TAB:
                removeThisTabWindow(screen);
                break;
            default:
                throw new UnsupportedOperationException("Unsupported OpenMode");
        }
    }
    fireEvent(screen, AfterDetachEvent.class, new AfterDetachEvent(screen));
    events.publish(new ScreenClosedEvent(screen));
    afterScreenRemove(screen);
}
Also used : Disposable(com.haulmont.cuba.gui.components.Component.Disposable) WindowImplementation(com.haulmont.cuba.gui.components.sys.WindowImplementation) ScreenClosedEvent(com.haulmont.cuba.gui.screen.event.ScreenClosedEvent)

Aggregations

WindowImplementation (com.haulmont.cuba.gui.components.sys.WindowImplementation)3 WebWindow (com.haulmont.cuba.web.gui.WebWindow)2 GuiDialogWindow (com.haulmont.cuba.web.gui.components.WebDialogWindow.GuiDialogWindow)2 WebTabWindow (com.haulmont.cuba.web.gui.components.WebTabWindow)2 Disposable (com.haulmont.cuba.gui.components.Component.Disposable)1 UIPerformanceLogger.createStopWatch (com.haulmont.cuba.gui.logging.UIPerformanceLogger.createStopWatch)1 ScreenDataImpl (com.haulmont.cuba.gui.model.impl.ScreenDataImpl)1 ScreenClosedEvent (com.haulmont.cuba.gui.screen.event.ScreenClosedEvent)1 ThemeConstants (com.haulmont.cuba.gui.theme.ThemeConstants)1 ComponentLoaderContext (com.haulmont.cuba.gui.xml.layout.loaders.ComponentLoaderContext)1 Element (org.dom4j.Element)1 StopWatch (org.perf4j.StopWatch)1