Search in sources :

Example 21 with InstanceContainer

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);
    }
}
Also used : InstanceContainer(io.jmix.ui.model.InstanceContainer)

Example 22 with InstanceContainer

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;
}
Also used : InstanceContainer(io.jmix.ui.model.InstanceContainer)

Example 23 with InstanceContainer

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));
    }
}
Also used : FrameOwner(io.jmix.ui.screen.FrameOwner) GuiDevelopmentException(io.jmix.ui.GuiDevelopmentException) CollectionContainer(io.jmix.ui.model.CollectionContainer) InstanceContainer(io.jmix.ui.model.InstanceContainer) ContainerDataProvider(io.jmix.ui.data.impl.ContainerDataProvider) ScreenData(io.jmix.ui.model.ScreenData)

Example 24 with InstanceContainer

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;
}
Also used : Nested(io.jmix.ui.model.Nested) InstanceContainer(io.jmix.ui.model.InstanceContainer) Nullable(javax.annotation.Nullable)

Example 25 with InstanceContainer

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;
}
Also used : MetaClass(io.jmix.core.metamodel.model.MetaClass) KeyValueMetaClass(io.jmix.core.impl.keyvalue.KeyValueMetaClass) KeyValueMetaClass(io.jmix.core.impl.keyvalue.KeyValueMetaClass) InstanceContainer(io.jmix.ui.model.InstanceContainer) DataComponents(io.jmix.ui.model.DataComponents)

Aggregations

InstanceContainer (io.jmix.ui.model.InstanceContainer)30 ScreenData (io.jmix.ui.model.ScreenData)12 GuiDevelopmentException (io.jmix.ui.GuiDevelopmentException)11 CollectionContainer (io.jmix.ui.model.CollectionContainer)11 FrameOwner (io.jmix.ui.screen.FrameOwner)11 MetaClass (io.jmix.core.metamodel.model.MetaClass)6 MetaProperty (io.jmix.core.metamodel.model.MetaProperty)6 Nullable (javax.annotation.Nullable)5 CollectionDatasource (com.haulmont.cuba.gui.data.CollectionDatasource)3 Datasource (com.haulmont.cuba.gui.data.Datasource)3 ContainerOptions (io.jmix.ui.component.data.options.ContainerOptions)3 ContainerValueSource (io.jmix.ui.component.data.value.ContainerValueSource)3 ContainerDataProvider (io.jmix.ui.data.impl.ContainerDataProvider)3 Nested (io.jmix.ui.model.Nested)3 Map (java.util.Map)3 WeakHashMap (java.util.WeakHashMap)3 KeyValueMetaClass (io.jmix.core.impl.keyvalue.KeyValueMetaClass)2 MetaPropertyPath (io.jmix.core.metamodel.model.MetaPropertyPath)2 ValueSource (io.jmix.ui.component.data.ValueSource)2 DataContext (io.jmix.ui.model.DataContext)2