Search in sources :

Example 1 with FragmentImplementation

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

the class RuntimePropertiesFrameLoader method createComponent.

@Override
public void createComponent() {
    String src = element.attributeValue("src");
    String screenId = element.attributeValue("id");
    if (src == null) {
        src = DEFAULT_DESCRIPTOR;
    }
    String fragmentId = screenId != null ? screenId : src;
    FragmentHelper fragmentHelper = getFragmentHelper();
    WindowInfo windowInfo = fragmentHelper.createFakeWindowInfo(src, fragmentId);
    Fragment fragment = factory.create(Fragment.NAME);
    ScreenFragment controller = fragmentHelper.createController(windowInfo, fragment);
    // setup screen and controller
    ComponentLoaderContext parentContext = (ComponentLoaderContext) getContext();
    FrameOwner hostController = parentContext.getFrame().getFrameOwner();
    // setup screen and controller
    setHostController(controller, hostController);
    setWindowId(controller, windowInfo.getId());
    setFrame(controller, fragment);
    setScreenContext(controller, new ScreenContextImpl(windowInfo, parentContext.getOptions(), getScreenContext(hostController)));
    setScreenData(controller, new ScreenDataImpl());
    FragmentImplementation fragmentImpl = (FragmentImplementation) fragment;
    fragmentImpl.setFrameOwner(controller);
    fragmentImpl.setId(fragmentId);
    FragmentContextImpl frameContext = new FragmentContextImpl(fragment, innerContext);
    ((FrameImplementation) fragment).setContext(frameContext);
    if (windowInfo.getTemplate() != null) {
        String frameId = fragmentId;
        if (parentContext.getFullFrameId() != null) {
            frameId = parentContext.getFullFrameId() + "." + frameId;
        }
        innerContext = new ComponentLoaderContext(getContext().getOptions());
        innerContext.setMessagesPack(fragmentHelper.getMessagePack(windowInfo.getTemplate()));
        innerContext.setCurrentFrameId(fragmentId);
        innerContext.setFullFrameId(frameId);
        innerContext.setFrame(fragment);
        innerContext.setParent(parentContext);
        LayoutLoader layoutLoader = getLayoutLoader(innerContext);
        ScreenXmlLoader screenXmlLoader = beanLocator.get(ScreenXmlLoader.NAME);
        Element rootElement = screenXmlLoader.load(windowInfo.getTemplate(), windowInfo.getId(), getContext().getParams());
        String messagesPack = rootElement.attributeValue("messagesPack");
        if (messagesPack != null) {
            innerContext.setMessagesPack(messagesPack);
        }
        this.fragmentLoader = layoutLoader.createFragmentContent(fragment, rootElement);
    }
    this.resultComponent = fragment;
}
Also used : LayoutLoader(com.haulmont.cuba.gui.xml.layout.LayoutLoader) FragmentImplementation(com.haulmont.cuba.gui.components.sys.FragmentImplementation) Element(org.dom4j.Element) FragmentContextImpl(com.haulmont.cuba.gui.sys.FragmentContextImpl) FrameImplementation(com.haulmont.cuba.gui.components.sys.FrameImplementation) Fragment(com.haulmont.cuba.gui.components.Fragment) ScreenFragment(com.haulmont.cuba.gui.screen.ScreenFragment) WindowInfo(com.haulmont.cuba.gui.config.WindowInfo) ScreenFragment(com.haulmont.cuba.gui.screen.ScreenFragment) FrameOwner(com.haulmont.cuba.gui.screen.FrameOwner) ScreenDataImpl(com.haulmont.cuba.gui.model.impl.ScreenDataImpl) FragmentHelper(com.haulmont.cuba.gui.sys.FragmentHelper) ScreenContextImpl(com.haulmont.cuba.gui.sys.ScreenContextImpl) ScreenXmlLoader(com.haulmont.cuba.gui.xml.layout.ScreenXmlLoader)

Example 2 with FragmentImplementation

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

the class FragmentComponentLoader method createComponent.

@Override
public void createComponent() {
    String src = element.attributeValue("src");
    String screenId = element.attributeValue("screen");
    if (src == null && screenId == null) {
        throw new GuiDevelopmentException("Either 'src' or 'screen' must be specified for 'frame'", context, "fragment", element.attributeValue("id"));
    }
    String fragmentId;
    if (element.attributeValue("id") != null) {
        fragmentId = element.attributeValue("id");
    } else if (screenId != null) {
        fragmentId = screenId;
    } else {
        fragmentId = src;
    }
    FragmentHelper fragmentHelper = getFragmentHelper();
    WindowInfo windowInfo;
    if (src == null) {
        // load screen class only once
        windowInfo = getWindowConfig().getWindowInfo(screenId).resolve();
    } else {
        windowInfo = fragmentHelper.createFakeWindowInfo(src, fragmentId);
    }
    StopWatch createStopWatch = createStopWatch(ScreenLifeCycle.CREATE, windowInfo.getId());
    Fragment fragment = factory.create(Fragment.NAME);
    ScreenFragment controller = fragmentHelper.createController(windowInfo, fragment);
    // setup screen and controller
    ComponentLoaderContext parentContext = (ComponentLoaderContext) getContext();
    FrameOwner hostController = parentContext.getFrame().getFrameOwner();
    setHostController(controller, hostController);
    setWindowId(controller, windowInfo.getId());
    setFrame(controller, fragment);
    setScreenContext(controller, new ScreenContextImpl(windowInfo, parentContext.getOptions(), getScreenContext(hostController)));
    setScreenData(controller, new ScreenDataImpl());
    FragmentImplementation fragmentImpl = (FragmentImplementation) fragment;
    fragmentImpl.setFrameOwner(controller);
    fragmentImpl.setId(fragmentId);
    FragmentContextImpl frameContext = new FragmentContextImpl(fragment, innerContext);
    ((FrameImplementation) fragment).setContext(frameContext);
    if (windowInfo.getTemplate() != null) {
        String frameId = fragmentId;
        if (parentContext.getFullFrameId() != null) {
            frameId = parentContext.getFullFrameId() + "." + frameId;
        }
        innerContext = new ComponentLoaderContext(getComponentContext().getOptions());
        innerContext.setMessagesPack(fragmentHelper.getMessagePack(windowInfo.getTemplate()));
        innerContext.setCurrentFrameId(fragmentId);
        innerContext.setFullFrameId(frameId);
        innerContext.setFrame(fragment);
        innerContext.setParent(parentContext);
        innerContext.setProperties(loadProperties(element));
        LayoutLoader layoutLoader = getLayoutLoader(innerContext);
        ScreenXmlLoader screenXmlLoader = beanLocator.get(ScreenXmlLoader.NAME);
        Element rootElement = screenXmlLoader.load(windowInfo.getTemplate(), windowInfo.getId(), getComponentContext().getParams());
        String messagesPack = rootElement.attributeValue("messagesPack");
        if (messagesPack != null) {
            innerContext.setMessagesPack(messagesPack);
        }
        this.fragmentLoader = layoutLoader.createFragmentContent(fragment, rootElement);
    }
    createStopWatch.stop();
    this.resultComponent = fragment;
}
Also used : LayoutLoader(com.haulmont.cuba.gui.xml.layout.LayoutLoader) FragmentImplementation(com.haulmont.cuba.gui.components.sys.FragmentImplementation) Element(org.dom4j.Element) FragmentContextImpl(com.haulmont.cuba.gui.sys.FragmentContextImpl) FrameImplementation(com.haulmont.cuba.gui.components.sys.FrameImplementation) Fragment(com.haulmont.cuba.gui.components.Fragment) ScreenFragment(com.haulmont.cuba.gui.screen.ScreenFragment) WindowInfo(com.haulmont.cuba.gui.config.WindowInfo) UIPerformanceLogger.createStopWatch(com.haulmont.cuba.gui.logging.UIPerformanceLogger.createStopWatch) StopWatch(org.perf4j.StopWatch) ScreenFragment(com.haulmont.cuba.gui.screen.ScreenFragment) FrameOwner(com.haulmont.cuba.gui.screen.FrameOwner) ScreenDataImpl(com.haulmont.cuba.gui.model.impl.ScreenDataImpl) FragmentHelper(com.haulmont.cuba.gui.sys.FragmentHelper) GuiDevelopmentException(com.haulmont.cuba.gui.GuiDevelopmentException) ScreenContextImpl(com.haulmont.cuba.gui.sys.ScreenContextImpl) ScreenXmlLoader(com.haulmont.cuba.gui.xml.layout.ScreenXmlLoader)

Example 3 with FragmentImplementation

use of com.haulmont.cuba.gui.components.sys.FragmentImplementation 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

Fragment (com.haulmont.cuba.gui.components.Fragment)3 FragmentImplementation (com.haulmont.cuba.gui.components.sys.FragmentImplementation)3 FrameImplementation (com.haulmont.cuba.gui.components.sys.FrameImplementation)3 ScreenDataImpl (com.haulmont.cuba.gui.model.impl.ScreenDataImpl)3 FragmentContextImpl (com.haulmont.cuba.gui.sys.FragmentContextImpl)3 ScreenContextImpl (com.haulmont.cuba.gui.sys.ScreenContextImpl)3 LayoutLoader (com.haulmont.cuba.gui.xml.layout.LayoutLoader)3 Element (org.dom4j.Element)3 WindowInfo (com.haulmont.cuba.gui.config.WindowInfo)2 UIPerformanceLogger.createStopWatch (com.haulmont.cuba.gui.logging.UIPerformanceLogger.createStopWatch)2 FrameOwner (com.haulmont.cuba.gui.screen.FrameOwner)2 ScreenFragment (com.haulmont.cuba.gui.screen.ScreenFragment)2 FragmentHelper (com.haulmont.cuba.gui.sys.FragmentHelper)2 ScreenXmlLoader (com.haulmont.cuba.gui.xml.layout.ScreenXmlLoader)2 StopWatch (org.perf4j.StopWatch)2 GuiDevelopmentException (com.haulmont.cuba.gui.GuiDevelopmentException)1 Frame (com.haulmont.cuba.gui.components.Frame)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