Search in sources :

Example 26 with InstanceContainer

use of io.jmix.ui.model.InstanceContainer in project jmix by jmix-framework.

the class AbstractTable method getInstanceContainer.

@SuppressWarnings("unchecked")
@Override
public InstanceContainer<E> getInstanceContainer(E item) {
    if (fieldDatasources == null) {
        fieldDatasources = new WeakHashMap<>();
    }
    Object fieldDatasource = fieldDatasources.get(item);
    if (fieldDatasource instanceof InstanceContainer) {
        return (InstanceContainer<E>) fieldDatasource;
    }
    EntityTableItems containerTableItems = (EntityTableItems) getItems();
    if (containerTableItems == null) {
        throw new IllegalStateException("Table is not bound to items");
    }
    InstanceContainer<E> instanceContainer;
    MetaClass metaClass = containerTableItems.getEntityMetaClass();
    if (metaClass instanceof KeyValueMetaClass) {
        instanceContainer = (InstanceContainer<E>) dataComponents.createKeyValueContainer(metaClass);
    } else {
        instanceContainer = dataComponents.createInstanceContainer(metaClass.getJavaClass());
    }
    FetchPlan view = viewRepository.getFetchPlan(metaClass, FetchPlan.LOCAL);
    instanceContainer.setFetchPlan(view);
    instanceContainer.setItem(item);
    fieldDatasources.put(item, instanceContainer);
    return instanceContainer;
}
Also used : KeyValueMetaClass(io.jmix.core.impl.keyvalue.KeyValueMetaClass) MetaClass(io.jmix.core.metamodel.model.MetaClass) KeyValueMetaClass(io.jmix.core.impl.keyvalue.KeyValueMetaClass) EntityTableItems(io.jmix.ui.component.data.meta.EntityTableItems) InstanceContainer(io.jmix.ui.model.InstanceContainer) FetchPlan(io.jmix.core.FetchPlan)

Example 27 with InstanceContainer

use of io.jmix.ui.model.InstanceContainer in project jmix by jmix-framework.

the class TestCommentaryPanelLoader method loadDataContainer.

private void loadDataContainer(TestCommentaryPanel resultComponent, Element element) {
    String containerId = this.element.attributeValue("dataContainer");
    if (Strings.isNullOrEmpty(containerId)) {
        throw new GuiDevelopmentException("CommentaryPanel element doesn't have 'dataContainer' attribute", context, "CommentaryPanel ID", element.attributeValue("id"));
    }
    FrameOwner frameOwner = getComponentContext().getFrame().getFrameOwner();
    ScreenData screenData = UiControllerUtils.getScreenData(frameOwner);
    InstanceContainer container = screenData.getContainer(containerId);
    if (container instanceof CollectionContainer) {
        resultComponent.setDataContainer((CollectionContainer) container);
    } else {
        throw new GuiDevelopmentException("Not a CollectionContainer: " + containerId, context);
    }
}
Also used : FrameOwner(io.jmix.ui.screen.FrameOwner) GuiDevelopmentException(io.jmix.ui.GuiDevelopmentException) InstanceContainer(io.jmix.ui.model.InstanceContainer) CollectionContainer(io.jmix.ui.model.CollectionContainer) ScreenData(io.jmix.ui.model.ScreenData)

Example 28 with InstanceContainer

use of io.jmix.ui.model.InstanceContainer in project jmix by jmix-framework.

the class FormLoader method createField.

@SuppressWarnings("unchecked")
protected Field createField(Element element) {
    String property = element.attributeValue("property");
    if (Strings.isNullOrEmpty(property)) {
        throw new GuiDevelopmentException("Field element has no 'property' attribute", context);
    }
    InstanceContainer container = loadContainer(element, property).orElseThrow(() -> new GuiDevelopmentException(String.format("Can't infer component for field '%s'. " + "No data container associated with it", property), context));
    MetaClass metaClass = container.getEntityMetaClass();
    ComponentGenerationContext context = new ComponentGenerationContext(metaClass, property);
    context.setTargetClass(Form.class);
    context.setValueSource(new ContainerValueSource<>(container, property));
    context.setXmlDescriptor(element);
    loadOptionsContainer(element).ifPresent(optionsContainer -> context.setOptions(new ContainerOptions(optionsContainer)));
    Component component = getUiComponentsGenerator().generate(context);
    Preconditions.checkState(component instanceof Field, "Form field '%s' must implement io.jmix.ui.component.Field", property);
    return (Field) component;
}
Also used : ContainerOptions(io.jmix.ui.component.data.options.ContainerOptions) MetaClass(io.jmix.core.metamodel.model.MetaClass) GuiDevelopmentException(io.jmix.ui.GuiDevelopmentException) InstanceContainer(io.jmix.ui.model.InstanceContainer)

Example 29 with InstanceContainer

use of io.jmix.ui.model.InstanceContainer in project jmix by jmix-framework.

the class TreeLoader method loadDataContainer.

protected void loadDataContainer(Tree resultComponent, Element element) {
    String containerId = element.attributeValue("dataContainer");
    if (containerId != null) {
        FrameOwner frameOwner = getComponentContext().getFrame().getFrameOwner();
        ScreenData screenData = UiControllerUtils.getScreenData(frameOwner);
        InstanceContainer container = screenData.getContainer(containerId);
        CollectionContainer collectionContainer;
        if (container instanceof CollectionContainer) {
            collectionContainer = (CollectionContainer) container;
        } else {
            throw new GuiDevelopmentException("Not a CollectionContainer: " + containerId, context);
        }
        String hierarchyProperty = loadHierarchyProperty(element);
        if (Strings.isNullOrEmpty(hierarchyProperty)) {
            throw new GuiDevelopmentException("Tree doesn't have 'hierarchyProperty' attribute of the 'treechildren' element", context, "Tree ID", element.attributeValue("id"));
        }
        String showOrphansAttr = element.attributeValue("showOrphans");
        boolean showOrphans = showOrphansAttr == null || Boolean.parseBoolean(showOrphansAttr);
        resultComponent.setItems(new ContainerTreeItems(collectionContainer, hierarchyProperty, showOrphans));
    }
}
Also used : FrameOwner(io.jmix.ui.screen.FrameOwner) GuiDevelopmentException(io.jmix.ui.GuiDevelopmentException) InstanceContainer(io.jmix.ui.model.InstanceContainer) CollectionContainer(io.jmix.ui.model.CollectionContainer) ScreenData(io.jmix.ui.model.ScreenData) ContainerTreeItems(io.jmix.ui.component.data.tree.ContainerTreeItems)

Example 30 with InstanceContainer

use of io.jmix.ui.model.InstanceContainer in project jmix by jmix-framework.

the class TwinColumnLoader method loadOptionsContainer.

protected void loadOptionsContainer(TwinColumn component, Element element) {
    String containerId = element.attributeValue("optionsContainer");
    if (containerId != null) {
        FrameOwner frameOwner = getComponentContext().getFrame().getFrameOwner();
        ScreenData screenData = UiControllerUtils.getScreenData(frameOwner);
        InstanceContainer container = screenData.getContainer(containerId);
        if (!(container instanceof CollectionContainer)) {
            throw new GuiDevelopmentException("Not a CollectionContainer: " + containerId, context);
        }
        // noinspection unchecked
        component.setOptions(new ContainerOptions((CollectionContainer) container));
    }
}
Also used : ContainerOptions(io.jmix.ui.component.data.options.ContainerOptions) FrameOwner(io.jmix.ui.screen.FrameOwner) GuiDevelopmentException(io.jmix.ui.GuiDevelopmentException) InstanceContainer(io.jmix.ui.model.InstanceContainer) CollectionContainer(io.jmix.ui.model.CollectionContainer) ScreenData(io.jmix.ui.model.ScreenData)

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