Search in sources :

Example 1 with FragmentLoaderInjectTask

use of com.haulmont.cuba.gui.sys.FragmentHelper.FragmentLoaderInjectTask in project cuba by cuba-platform.

the class RuntimePropertiesFrameLoader method loadComponent.

@Override
public void loadComponent() {
    if (getContext().getFrame() != null) {
        resultComponent.setFrame(getContext().getFrame());
    }
    String src = element.attributeValue("src");
    if (src == null) {
        src = DEFAULT_DESCRIPTOR;
    }
    String runtimeDs = element.attributeValue("runtimeDs");
    if (StringUtils.isEmpty(runtimeDs)) {
        throw new GuiDevelopmentException("runtimePropsDatasource is not set for runtimeProperties component", getContext().getFullFrameId());
    }
    getContext().getParams().put("runtimeDs", runtimeDs);
    String categoriesDs = element.attributeValue("categoriesDs");
    if (StringUtils.isEmpty(categoriesDs)) {
        throw new GuiDevelopmentException("categoriesDs is not set for runtimeProperties component", getContext().getFullFrameId());
    }
    getContext().getParams().put("categoriesDs", categoriesDs);
    String rows = element.attributeValue("rows");
    getContext().getParams().put("rows", rows);
    String cols = element.attributeValue("cols");
    getContext().getParams().put("cols", cols);
    String fieldWidth = element.attributeValue("fieldWidth");
    getContext().getParams().put("fieldWidth", fieldWidth);
    String fieldCaptionWidth = element.attributeValue("fieldCaptionWidth");
    getContext().getParams().put("fieldCaptionWidth", fieldCaptionWidth);
    String screenPath = Objects.equals(src, DEFAULT_DESCRIPTOR) ? "runtimeProperties" : src;
    if (element.attributeValue("id") != null) {
        screenPath = element.attributeValue("id");
    }
    if (getContext().getFrame() != null) {
        String parentId = getContext().getFullFrameId();
        if (StringUtils.isNotEmpty(parentId)) {
            screenPath = parentId + "." + screenPath;
        }
    }
    StopWatch loadStopWatch = createStopWatch(ScreenLifeCycle.LOAD, screenPath);
    if (fragmentLoader != null) {
        fragmentLoader.loadComponent();
    }
    // load properties after inner context, they must override values defined inside of fragment
    assignXmlDescriptor(resultComponent, element);
    loadVisible(resultComponent, element);
    loadEnable(resultComponent, element);
    loadStyleName(resultComponent, element);
    loadResponsive(resultComponent, element);
    loadCss(resultComponent, element);
    loadAlign(resultComponent, element);
    loadHeight(resultComponent, element);
    loadWidth(resultComponent, element);
    loadIcon(resultComponent, element);
    loadCaption(resultComponent, element);
    loadDescription(resultComponent, element);
    loadStopWatch.stop();
    // propagate init phases
    ComponentLoaderContext parentContext = (ComponentLoaderContext) getContext();
    if (innerContext != null) {
        parentContext.getInjectTasks().addAll(innerContext.getInjectTasks());
        parentContext.getInitTasks().addAll(innerContext.getInitTasks());
        parentContext.getPostInitTasks().addAll(innerContext.getPostInitTasks());
    }
    ScreenOptions options = parentContext.getOptions();
    parentContext.addInjectTask(new FragmentLoaderInjectTask((Fragment) resultComponent, options, beanLocator));
    parentContext.addInitTask(new FragmentLoaderInitTask((Fragment) resultComponent, options, (ComponentLoaderContext) context, beanLocator));
}
Also used : FragmentLoaderInjectTask(com.haulmont.cuba.gui.sys.FragmentHelper.FragmentLoaderInjectTask) GuiDevelopmentException(com.haulmont.cuba.gui.GuiDevelopmentException) FragmentLoaderInitTask(com.haulmont.cuba.gui.sys.FragmentHelper.FragmentLoaderInitTask) ScreenOptions(com.haulmont.cuba.gui.screen.ScreenOptions) Fragment(com.haulmont.cuba.gui.components.Fragment) ScreenFragment(com.haulmont.cuba.gui.screen.ScreenFragment) UIPerformanceLogger.createStopWatch(com.haulmont.cuba.gui.logging.UIPerformanceLogger.createStopWatch) StopWatch(org.perf4j.StopWatch)

Example 2 with FragmentLoaderInjectTask

use of com.haulmont.cuba.gui.sys.FragmentHelper.FragmentLoaderInjectTask in project cuba by cuba-platform.

the class FragmentComponentLoader method loadComponent.

@Override
public void loadComponent() {
    loadAliases();
    if (getComponentContext().getFrame() != null) {
        resultComponent.setFrame(getComponentContext().getFrame());
    }
    String src = element.attributeValue("src");
    String screenId = element.attributeValue("screen");
    String screenPath = StringUtils.isEmpty(screenId) ? src : screenId;
    if (element.attributeValue("id") != null) {
        screenPath = element.attributeValue("id");
    }
    if (getComponentContext().getFrame() != null) {
        String parentId = getComponentContext().getFullFrameId();
        if (StringUtils.isNotEmpty(parentId)) {
            screenPath = parentId + "." + screenPath;
        }
    }
    StopWatch loadStopWatch = createStopWatch(ScreenLifeCycle.LOAD, screenPath);
    if (fragmentLoader != null) {
        fragmentLoader.loadComponent();
    }
    // load properties after inner context, they must override values defined inside of fragment
    assignXmlDescriptor(resultComponent, element);
    loadVisible(resultComponent, element);
    loadEnable(resultComponent, element);
    loadStyleName(resultComponent, element);
    loadResponsive(resultComponent, element);
    loadCss(resultComponent, element);
    loadAlign(resultComponent, element);
    loadHeight(resultComponent, element);
    loadWidth(resultComponent, element);
    loadIcon(resultComponent, element);
    loadCaption(resultComponent, element);
    loadDescription(resultComponent, element);
    loadStopWatch.stop();
    // propagate init phases
    ComponentLoaderContext parentContext = (ComponentLoaderContext) getContext();
    if (innerContext != null) {
        parentContext.getInjectTasks().addAll(innerContext.getInjectTasks());
        parentContext.getInitTasks().addAll(innerContext.getInitTasks());
        parentContext.getPostInitTasks().addAll(innerContext.getPostInitTasks());
    }
    ScreenOptions options = parentContext.getOptions();
    parentContext.addInjectTask(new FragmentLoaderInjectTask(resultComponent, options, beanLocator));
    parentContext.addInitTask(new FragmentLoaderInitTask(resultComponent, options, innerContext, beanLocator));
}
Also used : FragmentLoaderInjectTask(com.haulmont.cuba.gui.sys.FragmentHelper.FragmentLoaderInjectTask) FragmentLoaderInitTask(com.haulmont.cuba.gui.sys.FragmentHelper.FragmentLoaderInitTask) ScreenOptions(com.haulmont.cuba.gui.screen.ScreenOptions) UIPerformanceLogger.createStopWatch(com.haulmont.cuba.gui.logging.UIPerformanceLogger.createStopWatch) StopWatch(org.perf4j.StopWatch)

Example 3 with FragmentLoaderInjectTask

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

UIPerformanceLogger.createStopWatch (com.haulmont.cuba.gui.logging.UIPerformanceLogger.createStopWatch)3 FragmentLoaderInitTask (com.haulmont.cuba.gui.sys.FragmentHelper.FragmentLoaderInitTask)3 FragmentLoaderInjectTask (com.haulmont.cuba.gui.sys.FragmentHelper.FragmentLoaderInjectTask)3 StopWatch (org.perf4j.StopWatch)3 Fragment (com.haulmont.cuba.gui.components.Fragment)2 ScreenOptions (com.haulmont.cuba.gui.screen.ScreenOptions)2 GuiDevelopmentException (com.haulmont.cuba.gui.GuiDevelopmentException)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 ScreenDataImpl (com.haulmont.cuba.gui.model.impl.ScreenDataImpl)1 ScreenFragment (com.haulmont.cuba.gui.screen.ScreenFragment)1 LegacyFrame (com.haulmont.cuba.gui.screen.compatibility.LegacyFrame)1 FragmentContextImpl (com.haulmont.cuba.gui.sys.FragmentContextImpl)1 ScreenContextImpl (com.haulmont.cuba.gui.sys.ScreenContextImpl)1 LayoutLoader (com.haulmont.cuba.gui.xml.layout.LayoutLoader)1 ComponentLoaderContext (com.haulmont.cuba.gui.xml.layout.loaders.ComponentLoaderContext)1 Element (org.dom4j.Element)1