Search in sources :

Example 1 with FrameImplementation

use of io.jmix.ui.component.impl.FrameImplementation 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 FrameImplementation

use of io.jmix.ui.component.impl.FrameImplementation in project jmix by jmix-framework.

the class FragmentComponentLoader method createComponent.

@Override
public void createComponent() {
    WindowInfo windowInfo = createWindowInfo(element);
    String fragmentId;
    if (element.attributeValue("id") != null) {
        fragmentId = element.attributeValue("id");
    } else {
        fragmentId = windowInfo.getId();
    }
    Timer.Sample createSample = Timer.start(getMeterRegistry());
    Fragment fragment = createComponentInternal();
    FragmentHelper fragmentHelper = getFragmentHelper();
    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);
    setupScreenContext(controller, new ScreenContextImpl(windowInfo, parentContext.getOptions(), getScreenContext(hostController)));
    setScreenData(controller, applicationContext.getBean(ScreenData.class));
    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 = createInnerContext();
        innerContext.setCurrentFrameId(fragmentId);
        innerContext.setFullFrameId(frameId);
        innerContext.setFrame(fragment);
        innerContext.setParent(parentContext);
        innerContext.setProperties(loadProperties(element));
        LayoutLoader layoutLoader = getLayoutLoader(innerContext);
        ScreenXmlLoader screenXmlLoader = applicationContext.getBean(ScreenXmlLoader.class);
        Element rootElement = screenXmlLoader.load(windowInfo.getTemplate(), windowInfo.getId(), getComponentContext().getParams());
        innerContext.setMessageGroup(fragmentHelper.findMessageGroup(rootElement, windowInfo.getTemplate()));
        loadAdditionalData(rootElement);
        this.fragmentLoader = layoutLoader.createFragmentContent(fragment, rootElement);
    }
    createSample.stop(createScreenTimer(getMeterRegistry(), ScreenLifeCycle.CREATE, windowInfo.getId()));
    this.resultComponent = fragment;
}
Also used : FragmentImplementation(io.jmix.ui.component.impl.FragmentImplementation) Element(org.dom4j.Element) FrameImplementation(io.jmix.ui.component.impl.FrameImplementation) ScreenFragment(io.jmix.ui.screen.ScreenFragment) Fragment(io.jmix.ui.component.Fragment) WindowInfo(io.jmix.ui.WindowInfo) Timer(io.micrometer.core.instrument.Timer) UiMonitoring.createScreenTimer(io.jmix.ui.monitoring.UiMonitoring.createScreenTimer) ScreenFragment(io.jmix.ui.screen.ScreenFragment) FrameOwner(io.jmix.ui.screen.FrameOwner) ScreenData(io.jmix.ui.model.ScreenData)

Example 3 with FrameImplementation

use of io.jmix.ui.component.impl.FrameImplementation in project jmix by jmix-framework.

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();
    FrameHelper frameHelper = getFrameHelper();
    WindowInfo windowInfo = frameHelper.createFakeWindowInfo(src, fragmentId);
    UiComponents uiComponents = applicationContext.getBean(UiComponents.class);
    Fragment fragment = uiComponents.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, applicationContext.getBean(ScreenData.class));
    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.setMessageGroup(fragmentHelper.getMessageGroup(windowInfo.getTemplate()));
        innerContext.setCurrentFrameId(fragmentId);
        innerContext.setFullFrameId(frameId);
        innerContext.setFrame(fragment);
        innerContext.setParent(parentContext);
        LayoutLoader layoutLoader = getLayoutLoader(innerContext);
        ScreenXmlLoader screenXmlLoader = applicationContext.getBean(ScreenXmlLoader.class);
        Element rootElement = screenXmlLoader.load(windowInfo.getTemplate(), windowInfo.getId(), getContext().getParams());
        String messagesPack = rootElement.attributeValue("messagesPack");
        if (messagesPack != null) {
            innerContext.setMessageGroup(messagesPack);
        }
        this.fragmentLoader = layoutLoader.createFragmentContent(fragment, rootElement);
    }
    this.resultComponent = fragment;
}
Also used : LayoutLoader(io.jmix.ui.xml.layout.loader.LayoutLoader) FrameHelper(com.haulmont.cuba.gui.sys.FrameHelper) UiComponents(com.haulmont.cuba.gui.UiComponents) FragmentImplementation(io.jmix.ui.component.impl.FragmentImplementation) Element(org.dom4j.Element) FragmentContextImpl(io.jmix.ui.sys.FragmentContextImpl) FrameImplementation(io.jmix.ui.component.impl.FrameImplementation) ScreenFragment(io.jmix.ui.screen.ScreenFragment) Fragment(io.jmix.ui.component.Fragment) WindowInfo(io.jmix.ui.WindowInfo) ScreenFragment(io.jmix.ui.screen.ScreenFragment) FrameOwner(io.jmix.ui.screen.FrameOwner) FragmentHelper(io.jmix.ui.sys.FragmentHelper) ScreenContextImpl(io.jmix.ui.sys.ScreenContextImpl) ScreenXmlLoader(io.jmix.ui.sys.ScreenXmlLoader) ScreenData(io.jmix.ui.model.ScreenData)

Example 4 with FrameImplementation

use of io.jmix.ui.component.impl.FrameImplementation in project jmix by jmix-framework.

the class ComponentsHelper method getWindowComponent.

@Nullable
public static Component getWindowComponent(Window window, String id) {
    String[] elements = ValuePathHelper.parse(id);
    FrameImplementation frameImpl = (FrameImplementation) window;
    if (elements.length == 1) {
        return frameImpl.getRegisteredComponent(id);
    } else {
        Component innerComponent = frameImpl.getRegisteredComponent(elements[0]);
        if (innerComponent instanceof HasComponents) {
            String subPath = ValuePathHelper.pathSuffix(elements);
            return ((HasComponents) innerComponent).getComponent(subPath);
        } else if (innerComponent instanceof HasNamedComponents) {
            String subPath = ValuePathHelper.pathSuffix(elements);
            return ((HasNamedComponents) innerComponent).getComponent(subPath);
        }
        return null;
    }
}
Also used : FrameImplementation(io.jmix.ui.component.impl.FrameImplementation) Nullable(javax.annotation.Nullable)

Example 5 with FrameImplementation

use of io.jmix.ui.component.impl.FrameImplementation in project jmix by jmix-framework.

the class ComponentsHelper method getFrameComponent.

@Nullable
public static Component getFrameComponent(Frame frame, String id) {
    FrameImplementation frameImpl = (FrameImplementation) frame;
    String[] elements = ValuePathHelper.parse(id);
    if (elements.length == 1) {
        Component component = frameImpl.getRegisteredComponent(id);
        if (component == null && frame.getFrame() != null && frame.getFrame() != frame) {
            component = frame.getFrame().getComponent(id);
        }
        return component;
    } else {
        Component innerComponent = frameImpl.getRegisteredComponent(elements[0]);
        if (innerComponent instanceof HasComponents) {
            String subPath = ValuePathHelper.pathSuffix(elements);
            return ((HasComponents) innerComponent).getComponent(subPath);
        } else if (innerComponent instanceof HasNamedComponents) {
            String subPath = ValuePathHelper.pathSuffix(elements);
            return ((HasNamedComponents) innerComponent).getComponent(subPath);
        }
        return null;
    }
}
Also used : FrameImplementation(io.jmix.ui.component.impl.FrameImplementation) Nullable(javax.annotation.Nullable)

Aggregations

FrameImplementation (io.jmix.ui.component.impl.FrameImplementation)6 Fragment (io.jmix.ui.component.Fragment)3 FragmentImplementation (io.jmix.ui.component.impl.FragmentImplementation)3 ScreenData (io.jmix.ui.model.ScreenData)3 Element (org.dom4j.Element)3 WindowInfo (io.jmix.ui.WindowInfo)2 UiMonitoring.createScreenTimer (io.jmix.ui.monitoring.UiMonitoring.createScreenTimer)2 FrameOwner (io.jmix.ui.screen.FrameOwner)2 ScreenFragment (io.jmix.ui.screen.ScreenFragment)2 LayoutLoader (io.jmix.ui.xml.layout.loader.LayoutLoader)2 Timer (io.micrometer.core.instrument.Timer)2 Nullable (javax.annotation.Nullable)2 UiComponents (com.haulmont.cuba.gui.UiComponents)1 FrameHelper (com.haulmont.cuba.gui.sys.FrameHelper)1 AppUI (io.jmix.ui.AppUI)1 Frame (io.jmix.ui.component.Frame)1 FragmentContextImpl (io.jmix.ui.sys.FragmentContextImpl)1 FragmentHelper (io.jmix.ui.sys.FragmentHelper)1 FragmentLoaderInitTask (io.jmix.ui.sys.FragmentHelper.FragmentLoaderInitTask)1 FragmentLoaderInjectTask (io.jmix.ui.sys.FragmentHelper.FragmentLoaderInjectTask)1