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;
}
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);
}
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());
}
}
}
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;
}
Aggregations