use of io.jmix.ui.component.data.options.ContainerOptions 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.component.data.options.ContainerOptions 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