Search in sources :

Example 6 with LayoutLoader

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

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

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

the class PopupButtonLoader method createContent.

protected void createContent() {
    if (element != null && element.element("popup") != null) {
        LayoutLoader loader = new LayoutLoader(context, factory, layoutLoaderConfig);
        loader.setLocale(getLocale());
        loader.setMessagesPack(getMessagesPack());
        List<Element> elements = Dom4j.elements(element.element("popup"));
        if (elements.size() != 0) {
            Element innerElement = elements.get(0);
            if (innerElement != null) {
                popupComponentLoader = loader.createComponent(innerElement);
                resultComponent.setPopupContent(popupComponentLoader.getResultComponent());
                resultComponent.setAutoClose(false);
            }
        }
    }
}
Also used : LayoutLoader(com.haulmont.cuba.gui.xml.layout.LayoutLoader) Element(org.dom4j.Element)

Example 9 with LayoutLoader

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

LayoutLoader (com.haulmont.cuba.gui.xml.layout.LayoutLoader)9 Element (org.dom4j.Element)8 ComponentLoader (com.haulmont.cuba.gui.xml.layout.ComponentLoader)7 GuiDevelopmentException (com.haulmont.cuba.gui.GuiDevelopmentException)3 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 MessageTools (com.haulmont.cuba.core.global.MessageTools)1 MetadataTools (com.haulmont.cuba.core.global.MetadataTools)1 ComponentsHelper (com.haulmont.cuba.gui.ComponentsHelper)1 com.haulmont.cuba.gui.components (com.haulmont.cuba.gui.components)1 Component (com.haulmont.cuba.gui.components.Component)1 CustomFieldGenerator (com.haulmont.cuba.gui.components.FieldGroup.CustomFieldGenerator)1