use of com.haulmont.cuba.gui.data.impl.DatasourceImplementation 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.data.impl.DatasourceImplementation in project cuba by cuba-platform.
the class AbstractEditor method setItem.
/**
* Called by the framework to set an edited entity after creation of all components and datasources, and after
* {@link #init(java.util.Map)}.
* <p>Don't override this method in subclasses, use hooks {@link #initNewItem(com.haulmont.cuba.core.entity.Entity)}
* and {@link #postInit()} instead.</p>
* @param item entity instance
*/
@SuppressWarnings("unchecked")
@Override
public void setItem(Entity item) {
if (PersistenceHelper.isNew(item)) {
DatasourceImplementation parentDs = (DatasourceImplementation) getParentDs();
if (parentDs == null || !parentDs.getItemsToCreate().contains(item)) {
initNewItem((T) item);
}
}
setItemInternal(item);
postInit();
}
use of com.haulmont.cuba.gui.data.impl.DatasourceImplementation in project cuba by cuba-platform.
the class LinkCellClickListener method handleEditorCommit.
protected void handleEditorCommit(Entity editorItem, Entity rowItem, String columnId) {
MetaPropertyPath mpp = rowItem.getMetaClass().getPropertyPath(columnId);
if (mpp == null) {
throw new IllegalStateException(String.format("Unable to find metaproperty %s for class %s", columnId, rowItem.getMetaClass()));
}
if (mpp.getRange().isClass()) {
boolean modifiedInTable = false;
boolean ownerDsModified = false;
DatasourceImplementation ds = ((DatasourceImplementation) table.getDatasource());
if (ds != null) {
modifiedInTable = ds.getItemsToUpdate().contains(rowItem);
ownerDsModified = ds.isModified();
}
rowItem.setValueEx(columnId, null);
rowItem.setValueEx(columnId, editorItem);
if (ds != null) {
// remove from items to update if it was not modified before setValue
if (!modifiedInTable) {
ds.getItemsToUpdate().remove(rowItem);
}
ds.setModified(ownerDsModified);
}
} else {
table.getItems().updateItem(editorItem);
}
}
use of com.haulmont.cuba.gui.data.impl.DatasourceImplementation 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.data.impl.DatasourceImplementation in project cuba by cuba-platform.
the class WebAbstractDataGrid method createItemDatasource.
protected Datasource createItemDatasource(E item) {
if (itemDatasources == null) {
itemDatasources = new WeakHashMap<>();
}
Object fieldDatasource = itemDatasources.get(item);
if (fieldDatasource instanceof Datasource) {
return (Datasource) fieldDatasource;
}
EntityDataGridItems<E> items = getEntityDataGridItemsNN();
Datasource datasource = DsBuilder.create().setAllowCommit(false).setMetaClass(items.getEntityMetaClass()).setRefreshMode(CollectionDatasource.RefreshMode.NEVER).setViewName(View.LOCAL).buildDatasource();
((DatasourceImplementation) datasource).valid();
// noinspection unchecked
datasource.setItem(item);
return datasource;
}
Aggregations