Search in sources :

Example 1 with DsContextLoader

use of com.haulmont.cuba.gui.xml.data.DsContextLoader in project cuba by cuba-platform.

the class WindowManager method loadDsContext.

protected DsContext loadDsContext(Element element) {
    DataSupplier dataSupplier;
    String dataSupplierClass = element.attributeValue("dataSupplier");
    if (StringUtils.isEmpty(dataSupplierClass)) {
        dataSupplier = defaultDataSupplier;
    } else {
        Class<Object> aClass = ReflectionHelper.getClass(dataSupplierClass);
        try {
            dataSupplier = (DataSupplier) aClass.newInstance();
        } catch (InstantiationException | IllegalAccessException e) {
            throw new RuntimeException("Unable to create data supplier for screen", e);
        }
    }
    // noinspection UnnecessaryLocalVariable
    DsContext dsContext = new DsContextLoader(dataSupplier).loadDatasources(element.element("dsContext"), null);
    return dsContext;
}
Also used : DsContextLoader(com.haulmont.cuba.gui.xml.data.DsContextLoader) DsContext(com.haulmont.cuba.gui.data.DsContext) GenericDataSupplier(com.haulmont.cuba.gui.data.impl.GenericDataSupplier) DataSupplier(com.haulmont.cuba.gui.data.DataSupplier)

Example 2 with DsContextLoader

use of com.haulmont.cuba.gui.xml.data.DsContextLoader in project cuba by cuba-platform.

the class FrameLoader method loadComponent.

@Override
public void loadComponent() {
    screenViewsLoader.deployViews(element);
    Element dsContextElement = element.element("dsContext");
    DsContextLoader contextLoader = new DsContextLoader(context.getDsContext().getDataSupplier());
    DsContext dsContext = contextLoader.loadDatasources(dsContextElement, context.getDsContext());
    assignXmlDescriptor(resultComponent, element);
    loadVisible(resultComponent, layoutElement);
    loadActions(resultComponent, element);
    loadSpacing(resultComponent, layoutElement);
    loadMargin(resultComponent, layoutElement);
    loadWidth(resultComponent, layoutElement);
    loadHeight(resultComponent, layoutElement);
    loadStyleName(resultComponent, layoutElement);
    loadResponsive(resultComponent, layoutElement);
    ComponentLoaderContext parentContext = (ComponentLoaderContext) getContext();
    setContext(innerContext);
    FrameContext frameContext = new FrameContextImpl(resultComponent, context.getParams());
    resultComponent.setContext(frameContext);
    if (dsContext != null) {
        resultComponent.setDsContext(dsContext);
        for (Datasource ds : dsContext.getAll()) {
            if (ds instanceof DatasourceImplementation) {
                ((DatasourceImplementation) ds).initialized();
            }
        }
        dsContext.setFrameContext(frameContext);
    }
    innerContext.setDsContext(dsContext);
    loadSubComponentsAndExpand(resultComponent, layoutElement);
    initWrapperFrame(resultComponent, element, parentContext.getParams(), parentContext);
    parentContext.getInjectTasks().addAll(innerContext.getInjectTasks());
    parentContext.getInitTasks().addAll(innerContext.getInitTasks());
    parentContext.getPostInitTasks().addAll(innerContext.getPostInitTasks());
    parentContext.getPostWrapTasks().addAll(innerContext.getPostWrapTasks());
    setContext(parentContext);
}
Also used : Datasource(com.haulmont.cuba.gui.data.Datasource) DsContextLoader(com.haulmont.cuba.gui.xml.data.DsContextLoader) DsContext(com.haulmont.cuba.gui.data.DsContext) Element(org.dom4j.Element) DatasourceImplementation(com.haulmont.cuba.gui.data.impl.DatasourceImplementation)

Example 3 with DsContextLoader

use of com.haulmont.cuba.gui.xml.data.DsContextLoader in project cuba by cuba-platform.

the class FragmentLoader method loadDsContext.

protected void loadDsContext(@Nullable Element dsContextElement) {
    DsContext dsContext = null;
    if (resultComponent.getFrameOwner() instanceof LegacyFrame) {
        DsContextLoader dsContextLoader;
        DsContext parentDsContext = getComponentContext().getParent().getDsContext();
        if (parentDsContext != null) {
            dsContextLoader = new DsContextLoader(parentDsContext.getDataSupplier());
        } else {
            dsContextLoader = new DsContextLoader(new GenericDataSupplier());
        }
        dsContext = dsContextLoader.loadDatasources(dsContextElement, parentDsContext, getComponentContext().getAliasesMap());
        ((ComponentLoaderContext) context).setDsContext(dsContext);
    }
    if (dsContext != null) {
        FrameOwner frameOwner = getComponentContext().getFrame().getFrameOwner();
        if (frameOwner instanceof LegacyFrame) {
            LegacyFrame frame = (LegacyFrame) frameOwner;
            frame.setDsContext(dsContext);
            for (Datasource ds : dsContext.getAll()) {
                if (ds instanceof DatasourceImplementation) {
                    ((DatasourceImplementation) ds).initialized();
                }
            }
            dsContext.setFrameContext(resultComponent.getContext());
        }
    }
}
Also used : Datasource(com.haulmont.cuba.gui.data.Datasource) DsContextLoader(com.haulmont.cuba.gui.xml.data.DsContextLoader) DsContext(com.haulmont.cuba.gui.data.DsContext) FrameOwner(com.haulmont.cuba.gui.screen.FrameOwner) LegacyFrame(com.haulmont.cuba.gui.screen.compatibility.LegacyFrame) GenericDataSupplier(com.haulmont.cuba.gui.data.impl.GenericDataSupplier) DatasourceImplementation(com.haulmont.cuba.gui.data.impl.DatasourceImplementation)

Example 4 with DsContextLoader

use of com.haulmont.cuba.gui.xml.data.DsContextLoader in project cuba by cuba-platform.

the class WebScreens method loadDsContext.

protected DsContext loadDsContext(Element element) {
    DataSupplier dataSupplier;
    String dataSupplierClass = element.attributeValue("dataSupplier");
    if (StringUtils.isEmpty(dataSupplierClass)) {
        dataSupplier = defaultDataSupplier;
    } else {
        Class<Object> aClass = ReflectionHelper.getClass(dataSupplierClass);
        try {
            dataSupplier = (DataSupplier) aClass.newInstance();
        } catch (InstantiationException | IllegalAccessException e) {
            throw new RuntimeException("Unable to create data supplier for screen", e);
        }
    }
    // noinspection UnnecessaryLocalVariable
    DsContext dsContext = new DsContextLoader(dataSupplier).loadDatasources(element.element("dsContext"), null, null);
    return dsContext;
}
Also used : DsContextLoader(com.haulmont.cuba.gui.xml.data.DsContextLoader) DsContext(com.haulmont.cuba.gui.data.DsContext) GenericDataSupplier(com.haulmont.cuba.gui.data.impl.GenericDataSupplier) DataSupplier(com.haulmont.cuba.gui.data.DataSupplier)

Aggregations

DsContext (com.haulmont.cuba.gui.data.DsContext)4 DsContextLoader (com.haulmont.cuba.gui.xml.data.DsContextLoader)4 GenericDataSupplier (com.haulmont.cuba.gui.data.impl.GenericDataSupplier)3 DataSupplier (com.haulmont.cuba.gui.data.DataSupplier)2 Datasource (com.haulmont.cuba.gui.data.Datasource)2 DatasourceImplementation (com.haulmont.cuba.gui.data.impl.DatasourceImplementation)2 FrameOwner (com.haulmont.cuba.gui.screen.FrameOwner)1 LegacyFrame (com.haulmont.cuba.gui.screen.compatibility.LegacyFrame)1 Element (org.dom4j.Element)1