Search in sources :

Example 6 with ContainerOptions

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;
}
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 7 with ContainerOptions

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

ContainerOptions (io.jmix.ui.component.data.options.ContainerOptions)6 MetaClass (io.jmix.core.metamodel.model.MetaClass)4 GuiDevelopmentException (io.jmix.ui.GuiDevelopmentException)3 CollectionContainer (io.jmix.ui.model.CollectionContainer)3 InstanceContainer (io.jmix.ui.model.InstanceContainer)3 Lookup (com.haulmont.cuba.core.entity.annotation.Lookup)2 Metadata (com.haulmont.cuba.core.global.Metadata)2 Entity (io.jmix.core.Entity)2 ScreenData (io.jmix.ui.model.ScreenData)2 FrameOwner (io.jmix.ui.screen.FrameOwner)2 Strings (com.google.common.base.Strings)1 ImmutableList (com.google.common.collect.ImmutableList)1 Datatypes (com.haulmont.chile.core.datatypes.Datatypes)1 CubaProperties (com.haulmont.cuba.CubaProperties)1 PersistenceManagerClient (com.haulmont.cuba.client.sys.PersistenceManagerClient)1 LookupType (com.haulmont.cuba.core.entity.annotation.LookupType)1 AppBeans (com.haulmont.cuba.core.global.AppBeans)1 Messages (com.haulmont.cuba.core.global.Messages)1 UserSessionSource (com.haulmont.cuba.core.global.UserSessionSource)1 UiComponents (com.haulmont.cuba.gui.UiComponents)1