Search in sources :

Example 6 with ComponentLoader

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

use of com.haulmont.cuba.gui.xml.layout.ComponentLoader 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 8 with ComponentLoader

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

the class AccordionLoader method createComponent.

@Override
public void createComponent() {
    resultComponent = (Accordion) factory.createComponent(Accordion.NAME);
    loadId(resultComponent, element);
    // noinspection unchecked
    List<Element> tabElements = element.elements("tab");
    for (Element tabElement : tabElements) {
        final String name = tabElement.attributeValue("id");
        boolean lazy = Boolean.parseBoolean(tabElement.attributeValue("lazy"));
        ComponentLoader tabComponentLoader = getLoader(tabElement, TabComponentLoader.class);
        Accordion.Tab tab;
        if (lazy) {
            tab = resultComponent.addLazyTab(name, tabElement, tabComponentLoader);
        } else {
            tabComponentLoader.createComponent();
            Component tabComponent = tabComponentLoader.getResultComponent();
            tab = resultComponent.addTab(name, tabComponent);
            pendingLoadComponents.add(tabComponentLoader);
        }
        pendingLoadTabs.put(tabElement, tab);
    }
}
Also used : Accordion(com.haulmont.cuba.gui.components.Accordion) Element(org.dom4j.Element) Component(com.haulmont.cuba.gui.components.Component) ComponentLoader(com.haulmont.cuba.gui.xml.layout.ComponentLoader)

Example 9 with ComponentLoader

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

the class FrameComponentLoader 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.getFullFrameId());
    }
    if (src == null) {
        WindowConfig windowConfig = AppBeans.get(WindowConfig.NAME);
        WindowInfo windowInfo = windowConfig.getWindowInfo(screenId);
        src = windowInfo.getTemplate();
        if (src == null) {
            throw new GuiDevelopmentException("Screen " + screenId + " doesn't have template path configured", context.getFullFrameId());
        }
    }
    if (element.attributeValue("id") != null) {
        frameId = element.attributeValue("id");
    }
    LayoutLoader layoutLoader = new LayoutLoader(context, factory, LayoutLoaderConfig.getFrameLoaders());
    layoutLoader.setLocale(getLocale());
    layoutLoader.setMessagesPack(getMessagesPack());
    String currentFrameId = context.getCurrentFrameId();
    context.setCurrentFrameId(frameId);
    try {
        Pair<ComponentLoader, Element> loaderElementPair = layoutLoader.createFrameComponent(src, frameId, context.getParams());
        frameLoader = loaderElementPair.getFirst();
        resultComponent = (Frame) frameLoader.getResultComponent();
    } finally {
        context.setCurrentFrameId(currentFrameId);
    }
}
Also used : WindowConfig(com.haulmont.cuba.gui.config.WindowConfig) LayoutLoader(com.haulmont.cuba.gui.xml.layout.LayoutLoader) Element(org.dom4j.Element) GuiDevelopmentException(com.haulmont.cuba.gui.GuiDevelopmentException) WindowInfo(com.haulmont.cuba.gui.config.WindowInfo) ComponentLoader(com.haulmont.cuba.gui.xml.layout.ComponentLoader)

Example 10 with ComponentLoader

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

the class RuntimePropertiesFrameLoader method createComponent.

@Override
public void createComponent() {
    String src = element.attributeValue("src");
    if (src == null) {
        src = DEFAULT_DESCRIPTOR;
    }
    String screenPath = src;
    if (element.attributeValue("id") != null) {
        screenPath = element.attributeValue("id");
    }
    frameId = screenPath;
    LayoutLoader layoutLoader = new LayoutLoader(context, factory, LayoutLoaderConfig.getFrameLoaders());
    layoutLoader.setLocale(getLocale());
    layoutLoader.setMessagesPack(getMessagesPack());
    String currentFrameId = context.getCurrentFrameId();
    context.setCurrentFrameId(frameId);
    try {
        Pair<ComponentLoader, Element> loaderElementPair = layoutLoader.createFrameComponent(src, frameId, context.getParams());
        frameLoader = loaderElementPair.getFirst();
        resultComponent = (Frame) frameLoader.getResultComponent();
    } finally {
        context.setCurrentFrameId(currentFrameId);
    }
}
Also used : LayoutLoader(com.haulmont.cuba.gui.xml.layout.LayoutLoader) Element(org.dom4j.Element) ComponentLoader(com.haulmont.cuba.gui.xml.layout.ComponentLoader)

Aggregations

ComponentLoader (com.haulmont.cuba.gui.xml.layout.ComponentLoader)11 Element (org.dom4j.Element)9 LayoutLoader (com.haulmont.cuba.gui.xml.layout.LayoutLoader)7 GuiDevelopmentException (com.haulmont.cuba.gui.GuiDevelopmentException)4 Component (com.haulmont.cuba.gui.components.Component)3 DsContext (com.haulmont.cuba.gui.data.DsContext)2 UIPerformanceLogger (com.haulmont.cuba.gui.logging.UIPerformanceLogger)2 ComponentLoaderContext (com.haulmont.cuba.gui.xml.layout.loaders.ComponentLoaderContext)2 StopWatch (org.perf4j.StopWatch)2 Slf4JStopWatch (org.perf4j.slf4j.Slf4JStopWatch)2 Strings (com.google.common.base.Strings)1 Iterables (com.google.common.collect.Iterables)1 Dom4j (com.haulmont.bali.util.Dom4j)1 Preconditions.checkNotNullArgument (com.haulmont.bali.util.Preconditions.checkNotNullArgument)1 MetaClass (com.haulmont.chile.core.model.MetaClass)1 MetaProperty (com.haulmont.chile.core.model.MetaProperty)1 MetaPropertyPath (com.haulmont.chile.core.model.MetaPropertyPath)1 DynamicAttributesUtils (com.haulmont.cuba.core.app.dynamicattributes.DynamicAttributesUtils)1 CategoryAttribute (com.haulmont.cuba.core.entity.CategoryAttribute)1 AppBeans (com.haulmont.cuba.core.global.AppBeans)1