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