Search in sources :

Example 1 with ComponentLoaderContext

use of io.jmix.ui.xml.layout.loader.ComponentLoaderContext in project jmix by jmix-framework.

the class FragmentsImpl method createFragment.

protected <T extends ScreenFragment> T createFragment(FrameOwner parent, WindowInfo windowInfo, ScreenOptions options) {
    if (windowInfo.getType() != WindowInfo.Type.FRAGMENT) {
        throw new IllegalArgumentException(String.format("Unable to create fragment %s it is a screen: %s", windowInfo.getId(), windowInfo.getControllerClass()));
    }
    Timer.Sample createSample = Timer.start(meterRegistry);
    Fragment fragment = createFragmentInternal();
    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, applicationContext.getBean(ScreenData.class));
    FragmentImplementation fragmentImpl = (FragmentImplementation) fragment;
    fragmentImpl.setFrameOwner(controller);
    fragmentImpl.setId(controller.getId());
    createSample.stop(createScreenTimer(meterRegistry, ScreenLifeCycle.CREATE, windowInfo.getId()));
    Timer.Sample loadSample = Timer.start(meterRegistry);
    Frame parentFrame = getFrame(parent);
    // fake parent loader context
    ComponentLoaderContext loaderContext = createComponentLoaderContext(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));
    // load XML if needed
    if (windowInfo.getTemplate() != null) {
        ComponentLoaderContext innerContext = createComponentLoaderContext(options);
        innerContext.setCurrentFrameId(windowInfo.getId());
        innerContext.setFullFrameId(windowInfo.getId());
        innerContext.setFrame(fragment);
        innerContext.setParent(loaderContext);
        LayoutLoader layoutLoader = applicationContext.getBean(LayoutLoader.class, innerContext);
        Element rootElement = screenXmlLoader.load(windowInfo.getTemplate(), windowInfo.getId(), emptyMap());
        innerContext.setMessageGroup(fragmentHelper.findMessageGroup(rootElement, windowInfo.getTemplate()));
        loadAdditionalData(rootElement, innerContext);
        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, applicationContext));
    loaderContext.addInitTask(new FragmentLoaderInitTask(fragment, options, loaderContext, applicationContext));
    loadSample.stop(createScreenTimer(meterRegistry, ScreenLifeCycle.LOAD, windowInfo.getId()));
    loaderContext.executeInjectTasks();
    fragmentImpl.setFrame(parentFrame);
    // noinspection unchecked
    return (T) controller;
}
Also used : LayoutLoader(io.jmix.ui.xml.layout.loader.LayoutLoader) Frame(io.jmix.ui.component.Frame) FragmentImplementation(io.jmix.ui.component.impl.FragmentImplementation) Element(org.dom4j.Element) FragmentLoaderInjectTask(io.jmix.ui.sys.FragmentHelper.FragmentLoaderInjectTask) FrameImplementation(io.jmix.ui.component.impl.FrameImplementation) Fragment(io.jmix.ui.component.Fragment) ComponentLoaderContext(io.jmix.ui.xml.layout.loader.ComponentLoaderContext) Timer(io.micrometer.core.instrument.Timer) UiMonitoring.createScreenTimer(io.jmix.ui.monitoring.UiMonitoring.createScreenTimer) FragmentLoaderInitTask(io.jmix.ui.sys.FragmentHelper.FragmentLoaderInitTask) ScreenData(io.jmix.ui.model.ScreenData)

Example 2 with ComponentLoaderContext

use of io.jmix.ui.xml.layout.loader.ComponentLoaderContext in project jmix by jmix-framework.

the class CubaScreens method initDsContext.

protected void initDsContext(Screen screen, Element screenDescriptor, ComponentLoaderContext context) {
    DsContext dsContext = loadDsContext(screenDescriptor);
    initDatasources(screen.getWindow(), dsContext, context.getParams());
    ((com.haulmont.cuba.gui.xml.layout.loaders.ComponentLoaderContext) context).setDsContext(dsContext);
}
Also used : DsContext(com.haulmont.cuba.gui.data.DsContext) ComponentLoaderContext(io.jmix.ui.xml.layout.loader.ComponentLoaderContext)

Example 3 with ComponentLoaderContext

use of io.jmix.ui.xml.layout.loader.ComponentLoaderContext in project jmix by jmix-framework.

the class FragmentsImpl 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 : ComponentLoaderContext(io.jmix.ui.xml.layout.loader.ComponentLoaderContext)

Example 4 with ComponentLoaderContext

use of io.jmix.ui.xml.layout.loader.ComponentLoaderContext in project jmix by jmix-framework.

the class ScreensImpl method createScreen.

protected <T extends Screen> T createScreen(WindowInfo windowInfo, OpenMode openMode, ScreenOptions options) {
    if (windowInfo.getType() != WindowInfo.Type.SCREEN) {
        throw new IllegalArgumentException(String.format("Unable to create screen %s with type %s", 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, openMode);
    checkPermissions(openDetails.getOpenMode(), windowInfo);
    Timer.Sample createSample = Timer.start(meterRegistry);
    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, applicationContext.getBean(ScreenData.class));
    WindowImplementation windowImpl = (WindowImplementation) window;
    windowImpl.setFrameOwner(controller);
    windowImpl.setId(controller.getId());
    createSample.stop(createScreenTimer(meterRegistry, ScreenLifeCycle.CREATE, windowInfo.getId()));
    // load UI from XML
    Timer.Sample loadSample = Timer.start(meterRegistry);
    ComponentLoaderContext componentLoaderContext = createComponentLoaderContext(options);
    componentLoaderContext.setFullFrameId(windowInfo.getId());
    componentLoaderContext.setCurrentFrameId(windowInfo.getId());
    componentLoaderContext.setMessageGroup(getPackage(resolvedScreenClass));
    componentLoaderContext.setFrame(window);
    if (element != null) {
        loadWindowFromXml(element, windowInfo, window, controller, componentLoaderContext);
    }
    loadSample.stop(createScreenTimer(meterRegistry, ScreenLifeCycle.LOAD, windowInfo.getId()));
    // inject top level screen dependencies
    Timer.Sample injectSample = Timer.start(meterRegistry);
    dependencyManager.inject(controller, options);
    injectSample.stop(createScreenTimer(meterRegistry, ScreenLifeCycle.INJECTION, windowInfo.getId()));
    // perform injection in nested fragments
    componentLoaderContext.executeInjectTasks();
    // run init
    Timer.Sample initSample = Timer.start(meterRegistry);
    fireScreenInitEvent(controller, InitEvent.class, new InitEvent(controller, options));
    initSample.stop(createScreenTimer(meterRegistry, ScreenLifeCycle.INIT, windowInfo.getId()));
    componentLoaderContext.executeInitTasks();
    componentLoaderContext.executePostInitTasks();
    fireScreenAfterInitEvent(controller, AfterInitEvent.class, new AfterInitEvent(controller, options));
    return controller;
}
Also used : GuiDialogWindow(io.jmix.ui.component.impl.DialogWindowImpl.GuiDialogWindow) Element(org.dom4j.Element) WindowImplementation(io.jmix.ui.component.impl.WindowImplementation) ComponentLoaderContext(io.jmix.ui.xml.layout.loader.ComponentLoaderContext) UiMonitoring.createScreenTimer(io.jmix.ui.monitoring.UiMonitoring.createScreenTimer) Timer(io.micrometer.core.instrument.Timer) ScreenData(io.jmix.ui.model.ScreenData)

Aggregations

ComponentLoaderContext (io.jmix.ui.xml.layout.loader.ComponentLoaderContext)4 ScreenData (io.jmix.ui.model.ScreenData)2 UiMonitoring.createScreenTimer (io.jmix.ui.monitoring.UiMonitoring.createScreenTimer)2 Timer (io.micrometer.core.instrument.Timer)2 Element (org.dom4j.Element)2 DsContext (com.haulmont.cuba.gui.data.DsContext)1 Fragment (io.jmix.ui.component.Fragment)1 Frame (io.jmix.ui.component.Frame)1 GuiDialogWindow (io.jmix.ui.component.impl.DialogWindowImpl.GuiDialogWindow)1 FragmentImplementation (io.jmix.ui.component.impl.FragmentImplementation)1 FrameImplementation (io.jmix.ui.component.impl.FrameImplementation)1 WindowImplementation (io.jmix.ui.component.impl.WindowImplementation)1 FragmentLoaderInitTask (io.jmix.ui.sys.FragmentHelper.FragmentLoaderInitTask)1 FragmentLoaderInjectTask (io.jmix.ui.sys.FragmentHelper.FragmentLoaderInjectTask)1 LayoutLoader (io.jmix.ui.xml.layout.loader.LayoutLoader)1