use of io.jmix.ui.model.InstanceContainer in project jmix by jmix-framework.
the class AppSettingsEntityScreen method showEntityPropertiesGridLayout.
@SuppressWarnings("rawtypes")
protected void showEntityPropertiesGridLayout() {
propertiesGridLayout.removeAll();
if (currentMetaClass != null) {
InstanceContainer container = initInstanceContainerWithDbEntity();
GridLayout gridLayout = AppSettingsGridLayoutBuilder.of(getApplicationContext(), container).withOwnerComponent(propertiesGridLayout).build();
propertiesGridLayout.add(gridLayout);
actionsBox.setVisible(true);
}
}
use of io.jmix.ui.model.InstanceContainer in project jmix by jmix-framework.
the class AppSettingsEntityScreen method initInstanceContainerWithDbEntity.
@SuppressWarnings("rawtypes")
protected InstanceContainer initInstanceContainerWithDbEntity() {
InstanceContainer container = dataComponents.createInstanceContainer(currentMetaClass.getJavaClass());
entityToEdit = dataManager.load(currentMetaClass.getJavaClass()).query(String.format(SELECT_APP_SETTINGS_ENTITY_QUERY, currentMetaClass.getName())).fetchPlan(fetchPlans.builder(currentMetaClass.getJavaClass()).addFetchPlan(FetchPlan.LOCAL).build()).hint(PersistenceHints.SOFT_DELETION, false).optional().orElse(null);
if (entityToEdit == null) {
entityToEdit = dataContext.create(currentMetaClass.getJavaClass());
} else {
entityToEdit = dataContext.merge(entityToEdit);
}
container.setItem(entityToEdit);
return container;
}
use of io.jmix.ui.model.InstanceContainer in project jmix by jmix-framework.
the class AbstractChartLoader method loadDataContainer.
protected void loadDataContainer(Chart chart, Element element) {
String dataContainerId = element.attributeValue("dataContainer");
if (StringUtils.isNotEmpty(dataContainerId)) {
FrameOwner frameOwner = getComponentContext().getFrame().getFrameOwner();
ScreenData screenData = UiControllerUtils.getScreenData(frameOwner);
CollectionContainer dataContainer;
InstanceContainer container = screenData.getContainer(dataContainerId);
if (container instanceof CollectionContainer) {
dataContainer = (CollectionContainer) container;
} else {
throw new GuiDevelopmentException("Not a CollectionContainer: " + dataContainerId, context);
}
chart.setDataProvider(new ContainerDataProvider(dataContainer));
}
}
use of io.jmix.ui.model.InstanceContainer in project jmix by jmix-framework.
the class LookupBuilderProcessor method getFetchPlanForCollectionContainer.
/**
* See {@link #getFetchPlanForField(HasValue)} javadoc.
*
* @return a fetch plan or null if the fetch plan cannot be evaluated
*/
@Nullable
protected <E> FetchPlan getFetchPlanForCollectionContainer(CollectionContainer<E> collectionDc, boolean initializeMasterReference, @Nullable MetaProperty inverseMetaProperty) {
FetchPlan fetchPlan = null;
if (collectionDc instanceof Nested) {
InstanceContainer masterDc = ((Nested) collectionDc).getMaster();
FetchPlan masterFetchPlan = masterDc.getFetchPlan();
if (masterFetchPlan != null) {
String property = ((Nested) collectionDc).getProperty();
FetchPlanProperty viewProperty = masterFetchPlan.getProperty(property);
if (viewProperty != null) {
fetchPlan = viewProperty.getFetchPlan();
if (fetchPlan != null && initializeMasterReference && inverseMetaProperty != null) {
fetchPlan = fetchPlans.builder(fetchPlan).add(inverseMetaProperty.getName()).build();
}
}
}
} else {
fetchPlan = collectionDc.getFetchPlan();
}
return fetchPlan;
}
use of io.jmix.ui.model.InstanceContainer in project jmix by jmix-framework.
the class AbstractDataGrid method createInstanceContainer.
protected InstanceContainer<E> createInstanceContainer(E item) {
if (itemDatasources == null) {
itemDatasources = new WeakHashMap<>();
}
Object container = itemDatasources.get(item);
if (container instanceof InstanceContainer) {
// noinspection unchecked
return (InstanceContainer<E>) container;
}
EntityDataGridItems<E> items = getEntityDataGridItemsNN();
DataComponents factory = this.applicationContext.getBean(DataComponents.class);
FetchPlanRepository viewRepository = this.applicationContext.getBean(FetchPlanRepository.class);
MetaClass metaClass = items.getEntityMetaClass();
InstanceContainer<E> instanceContainer;
if (metaClass instanceof KeyValueMetaClass) {
// noinspection unchecked
instanceContainer = (InstanceContainer<E>) factory.createKeyValueContainer(metaClass);
} else {
instanceContainer = factory.createInstanceContainer(metaClass.getJavaClass());
}
instanceContainer.setFetchPlan(viewRepository.getFetchPlan(metaClass, FetchPlan.LOCAL));
instanceContainer.setItem(item);
itemDatasources.put(item, instanceContainer);
return instanceContainer;
}
Aggregations