Search in sources :

Example 1 with ComponentLoaderContext

use of com.haulmont.cuba.gui.xml.layout.loaders.ComponentLoaderContext 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 2 with ComponentLoaderContext

use of com.haulmont.cuba.gui.xml.layout.loaders.ComponentLoaderContext in project cuba by cuba-platform.

the class WindowManager method openFrame.

public Frame openFrame(Frame parentFrame, Component parent, @Nullable String id, WindowInfo windowInfo, Map<String, Object> params) {
    if (params == null) {
        params = Collections.emptyMap();
    }
    // Parameters can be useful later
    params = createParametersMap(windowInfo, params);
    String src = windowInfo.getTemplate();
    ComponentLoaderContext context = new ComponentLoaderContext(params);
    context.setDsContext(parentFrame.getDsContext());
    context.setFullFrameId(windowInfo.getId());
    context.setCurrentFrameId(windowInfo.getId());
    LayoutLoader loader = new LayoutLoader(context, AppConfig.getFactory(), LayoutLoaderConfig.getFrameLoaders());
    loader.setLocale(getLocale());
    loader.setMessagesPack(parentFrame.getMessagesPack());
    StopWatch loadDescriptorWatch = new Slf4JStopWatch(windowInfo.getId() + "#" + LifeCycle.LOAD, LoggerFactory.getLogger(UIPerformanceLogger.class));
    Frame component;
    String frameId = id != null ? id : windowInfo.getId();
    Pair<ComponentLoader, Element> loaderElementPair = loader.createFrameComponent(src, frameId, context.getParams());
    component = (Frame) loaderElementPair.getFirst().getResultComponent();
    if (parent != null) {
        showFrame(parent, component);
    } else {
        component.setFrame(parentFrame);
    }
    loaderElementPair.getFirst().loadComponent();
    if (component.getMessagesPack() == null) {
        component.setMessagesPack(parentFrame.getMessagesPack());
    }
    context.executeInjectTasks();
    context.setFrame(component);
    context.executePostWrapTasks();
    // init of frame
    context.executeInitTasks();
    context.executePostInitTasks();
    loadDescriptorWatch.stop();
    initDebugIds(component);
    userActionsLog.trace("Frame {} was opened", windowInfo.getId());
    return component;
}
Also used : LayoutLoader(com.haulmont.cuba.gui.xml.layout.LayoutLoader) Slf4JStopWatch(org.perf4j.slf4j.Slf4JStopWatch) UIPerformanceLogger(com.haulmont.cuba.gui.logging.UIPerformanceLogger) Element(org.dom4j.Element) ComponentLoaderContext(com.haulmont.cuba.gui.xml.layout.loaders.ComponentLoaderContext) Slf4JStopWatch(org.perf4j.slf4j.Slf4JStopWatch) StopWatch(org.perf4j.StopWatch) ComponentLoader(com.haulmont.cuba.gui.xml.layout.ComponentLoader)

Example 3 with ComponentLoaderContext

use of com.haulmont.cuba.gui.xml.layout.loaders.ComponentLoaderContext in project cuba by cuba-platform.

the class WindowManager method createWindow.

protected Window createWindow(WindowInfo windowInfo, OpenType openType, Map<String, Object> params, LayoutLoaderConfig layoutConfig, boolean topLevel) {
    if (!topLevel) {
        checkPermission(windowInfo);
    }
    StopWatch loadDescriptorWatch = new Slf4JStopWatch(windowInfo.getId() + "#" + LifeCycle.LOAD, LoggerFactory.getLogger(UIPerformanceLogger.class));
    Element element = screenXmlLoader.load(windowInfo.getTemplate(), windowInfo.getId(), params);
    // try to load main screen class to resolve dynamic compilation dependencies issues
    preloadMainScreenClass(element);
    ComponentLoaderContext componentLoaderContext = new ComponentLoaderContext(params);
    componentLoaderContext.setFullFrameId(windowInfo.getId());
    componentLoaderContext.setCurrentFrameId(windowInfo.getId());
    ComponentLoader windowLoader = createLayout(windowInfo, element, componentLoaderContext, layoutConfig);
    Window clientSpecificWindow = (Window) windowLoader.getResultComponent();
    Window windowWrapper = wrapByCustomClass(clientSpecificWindow, element);
    screenViewsLoader.deployViews(element);
    DsContext dsContext = loadDsContext(element);
    initDatasources(clientSpecificWindow, dsContext, params);
    componentLoaderContext.setDsContext(dsContext);
    WindowContext windowContext = new WindowContextImpl(clientSpecificWindow, openType, params);
    clientSpecificWindow.setContext(windowContext);
    dsContext.setFrameContext(windowContext);
    // noinspection unchecked
    windowLoader.loadComponent();
    clientSpecificWindow.setWindowManager(this);
    loadDescriptorWatch.stop();
    initWrapperFrame(windowWrapper, componentLoaderContext, element, params);
    componentLoaderContext.setFrame(windowWrapper);
    componentLoaderContext.executePostInitTasks();
    if (configuration.getConfig(GlobalConfig.class).getTestMode()) {
        initDebugIds(clientSpecificWindow);
    }
    StopWatch uiPermissionsWatch = new Slf4JStopWatch(windowInfo.getId() + "#" + LifeCycle.UI_PERMISSIONS, LoggerFactory.getLogger(UIPerformanceLogger.class));
    // apply ui permissions
    WindowCreationHelper.applyUiPermissions(clientSpecificWindow);
    uiPermissionsWatch.stop();
    return windowWrapper;
}
Also used : Slf4JStopWatch(org.perf4j.slf4j.Slf4JStopWatch) UIPerformanceLogger(com.haulmont.cuba.gui.logging.UIPerformanceLogger) DsContext(com.haulmont.cuba.gui.data.DsContext) Element(org.dom4j.Element) ComponentLoaderContext(com.haulmont.cuba.gui.xml.layout.loaders.ComponentLoaderContext) Slf4JStopWatch(org.perf4j.slf4j.Slf4JStopWatch) StopWatch(org.perf4j.StopWatch) ComponentLoader(com.haulmont.cuba.gui.xml.layout.ComponentLoader)

Example 4 with ComponentLoaderContext

use of com.haulmont.cuba.gui.xml.layout.loaders.ComponentLoaderContext in project cuba by cuba-platform.

the class WebFragments method init.

@Override
public void init(ScreenFragment controller) {
    checkNotNullArgument(controller);
    FragmentContextImpl fragmentContext = (FragmentContextImpl) controller.getFragment().getContext();
    if (fragmentContext.isInitialized()) {
        throw new IllegalStateException("Fragment is already initialized " + controller.getId());
    }
    ComponentLoaderContext loaderContext = fragmentContext.getLoaderContext();
    loaderContext.executeInitTasks();
    loaderContext.executePostInitTasks();
    fragmentContext.setInitialized(true);
}
Also used : FragmentContextImpl(com.haulmont.cuba.gui.sys.FragmentContextImpl) ComponentLoaderContext(com.haulmont.cuba.gui.xml.layout.loaders.ComponentLoaderContext)

Example 5 with ComponentLoaderContext

use of com.haulmont.cuba.gui.xml.layout.loaders.ComponentLoaderContext in project cuba by cuba-platform.

the class WebFragments method createFragment.

protected <T extends ScreenFragment> T createFragment(FrameOwner parent, WindowInfo windowInfo, ScreenOptions options) {
    if (windowInfo.getType() != WindowInfo.Type.FRAGMENT && !AbstractWindow.class.isAssignableFrom(windowInfo.getControllerClass())) {
        throw new IllegalArgumentException(String.format("Unable to create fragment %s it is a screen: %s", windowInfo.getId(), windowInfo.getControllerClass()));
    }
    StopWatch createStopWatch = createStopWatch(ScreenLifeCycle.CREATE, windowInfo.getId());
    Fragment fragment = uiComponents.create(Fragment.NAME);
    ScreenFragment controller = fragmentHelper.createController(windowInfo, fragment);
    // setup screen and controller
    setHostController(controller, parent);
    setWindowId(controller, windowInfo.getId());
    setFrame(controller, fragment);
    setScreenContext(controller, new ScreenContextImpl(windowInfo, options, getScreenContext(parent)));
    setScreenData(controller, new ScreenDataImpl());
    FragmentImplementation fragmentImpl = (FragmentImplementation) fragment;
    fragmentImpl.setFrameOwner(controller);
    fragmentImpl.setId(controller.getId());
    createStopWatch.stop();
    StopWatch loadStopWatch = createStopWatch(ScreenLifeCycle.LOAD, windowInfo.getId());
    Frame parentFrame = getFrame(parent);
    // fake parent loader context
    ComponentLoaderContext loaderContext = new ComponentLoaderContext(options);
    FragmentContextImpl frameContext = new FragmentContextImpl(fragment, loaderContext);
    frameContext.setManualInitRequired(true);
    ((FrameImplementation) fragment).setContext(frameContext);
    loaderContext.setCurrentFrameId(windowInfo.getId());
    loaderContext.setFullFrameId(windowInfo.getId());
    loaderContext.setFrame(fragment);
    loaderContext.setParent(null);
    loaderContext.setScreenData(UiControllerUtils.getScreenData(parent));
    if (parent instanceof LegacyFrame) {
        loaderContext.setDsContext(((LegacyFrame) parent).getDsContext());
    }
    // load XML if needed
    if (windowInfo.getTemplate() != null) {
        ComponentLoaderContext innerContext = new ComponentLoaderContext(options);
        innerContext.setMessagesPack(fragmentHelper.getMessagePack(windowInfo.getTemplate()));
        innerContext.setCurrentFrameId(windowInfo.getId());
        innerContext.setFullFrameId(windowInfo.getId());
        innerContext.setFrame(fragment);
        innerContext.setParent(loaderContext);
        LayoutLoader layoutLoader = beanLocator.getPrototype(LayoutLoader.NAME, innerContext);
        Element rootElement = screenXmlLoader.load(windowInfo.getTemplate(), windowInfo.getId(), innerContext.getParams());
        String messagesPack = rootElement.attributeValue("messagesPack");
        if (messagesPack != null) {
            innerContext.setMessagesPack(messagesPack);
        }
        ComponentLoader<Fragment> fragmentLoader = layoutLoader.createFragmentContent(fragment, rootElement);
        fragmentLoader.loadComponent();
        loaderContext.getInjectTasks().addAll(innerContext.getInjectTasks());
        loaderContext.getInitTasks().addAll(innerContext.getInitTasks());
        loaderContext.getPostInitTasks().addAll(innerContext.getPostInitTasks());
    }
    loaderContext.addInjectTask(new FragmentLoaderInjectTask(fragment, options, beanLocator));
    loaderContext.addInitTask(new FragmentLoaderInitTask(fragment, options, loaderContext, beanLocator));
    loadStopWatch.stop();
    loaderContext.executeInjectTasks();
    fragmentImpl.setFrame(parentFrame);
    // noinspection unchecked
    return (T) controller;
}
Also used : LayoutLoader(com.haulmont.cuba.gui.xml.layout.LayoutLoader) LegacyFrame(com.haulmont.cuba.gui.screen.compatibility.LegacyFrame) Frame(com.haulmont.cuba.gui.components.Frame) FragmentImplementation(com.haulmont.cuba.gui.components.sys.FragmentImplementation) Element(org.dom4j.Element) FragmentLoaderInjectTask(com.haulmont.cuba.gui.sys.FragmentHelper.FragmentLoaderInjectTask) LegacyFrame(com.haulmont.cuba.gui.screen.compatibility.LegacyFrame) FragmentContextImpl(com.haulmont.cuba.gui.sys.FragmentContextImpl) FrameImplementation(com.haulmont.cuba.gui.components.sys.FrameImplementation) Fragment(com.haulmont.cuba.gui.components.Fragment) 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) ScreenContextImpl(com.haulmont.cuba.gui.sys.ScreenContextImpl) FragmentLoaderInitTask(com.haulmont.cuba.gui.sys.FragmentHelper.FragmentLoaderInitTask)

Aggregations

ComponentLoaderContext (com.haulmont.cuba.gui.xml.layout.loaders.ComponentLoaderContext)5 Element (org.dom4j.Element)4 StopWatch (org.perf4j.StopWatch)4 UIPerformanceLogger (com.haulmont.cuba.gui.logging.UIPerformanceLogger)2 UIPerformanceLogger.createStopWatch (com.haulmont.cuba.gui.logging.UIPerformanceLogger.createStopWatch)2 ScreenDataImpl (com.haulmont.cuba.gui.model.impl.ScreenDataImpl)2 FragmentContextImpl (com.haulmont.cuba.gui.sys.FragmentContextImpl)2 ComponentLoader (com.haulmont.cuba.gui.xml.layout.ComponentLoader)2 LayoutLoader (com.haulmont.cuba.gui.xml.layout.LayoutLoader)2 Slf4JStopWatch (org.perf4j.slf4j.Slf4JStopWatch)2 Fragment (com.haulmont.cuba.gui.components.Fragment)1 Frame (com.haulmont.cuba.gui.components.Frame)1 FragmentImplementation (com.haulmont.cuba.gui.components.sys.FragmentImplementation)1 FrameImplementation (com.haulmont.cuba.gui.components.sys.FrameImplementation)1 WindowImplementation (com.haulmont.cuba.gui.components.sys.WindowImplementation)1 DsContext (com.haulmont.cuba.gui.data.DsContext)1 LegacyFrame (com.haulmont.cuba.gui.screen.compatibility.LegacyFrame)1 FragmentLoaderInitTask (com.haulmont.cuba.gui.sys.FragmentHelper.FragmentLoaderInitTask)1 FragmentLoaderInjectTask (com.haulmont.cuba.gui.sys.FragmentHelper.FragmentLoaderInjectTask)1 ScreenContextImpl (com.haulmont.cuba.gui.sys.ScreenContextImpl)1