Search in sources :

Example 1 with DataComponents

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

the class SelectValueDialog method createEntityComboBox.

protected Field createEntityComboBox(MetaClass metaClass) {
    EntityComboBox<Object> entityComboBox = uiComponents.create(EntityComboBox.NAME);
    Options<Object> options;
    DataComponents dataComponents = getApplicationContext().getBean(DataComponents.class);
    CollectionContainer<Object> container = dataComponents.createCollectionContainer(metaClass.getJavaClass());
    CollectionLoader<Object> loader = dataComponents.createCollectionLoader();
    loader.setQuery("select e from " + metaClass.getName() + " e");
    loader.setFetchPlan(FetchPlan.INSTANCE_NAME);
    loader.setContainer(container);
    loader.load();
    options = new ContainerOptions<>(container);
    entityComboBox.setOptions(options);
    entityComboBox.setOptionCaptionProvider(((Function) context.getOptionCaptionProvider()));
    entityComboBox.addValueChangeListener(event -> {
        V selectedEntity = (V) event.getValue();
        if (selectedEntity != null && !valueExists(selectedEntity)) {
            addValueToLayout(selectedEntity);
        }
        entityComboBox.setValue(null);
    });
    return entityComboBox;
}
Also used : Function(java.util.function.Function) DataComponents(io.jmix.ui.model.DataComponents)

Example 2 with DataComponents

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

the class BulkEditorFieldFactory method createEntityField.

protected Field createEntityField(Datasource datasource, MetaProperty property) {
    Lookup lookup = property.getAnnotatedElement().getAnnotation(Lookup.class);
    if (lookup != null && lookup.type() == LookupType.DROPDOWN) {
        DataComponents dataComponents = AppBeans.get(DataComponents.class);
        Metadata metadata = AppBeans.get(Metadata.class);
        MetaClass metaClass = metadata.getClassNN(property.getJavaType());
        CollectionContainer<Entity> container = dataComponents.createCollectionContainer(metaClass.getJavaClass());
        CollectionLoader<Entity> loader = dataComponents.createCollectionLoader();
        loader.setQuery("select e from " + metaClass.getName() + " e");
        loader.setFetchPlan(FetchPlan.INSTANCE_NAME);
        loader.setContainer(container);
        loader.load();
        LookupPickerField<Entity> lookupPickerField = componentsFactory.create(LookupPickerField.NAME);
        lookupPickerField.setDatasource(datasource, property.getName());
        lookupPickerField.setOptions(new ContainerOptions(container));
        GuiActionSupport guiActionSupport = AppBeans.get(GuiActionSupport.NAME);
        guiActionSupport.createActionsByMetaAnnotations(lookupPickerField);
        return lookupPickerField;
    }
    PickerField<Entity> pickerField = componentsFactory.create(PickerField.NAME);
    pickerField.setDatasource(datasource, property.getName());
    GuiActionSupport guiActionSupport = AppBeans.get(GuiActionSupport.NAME);
    guiActionSupport.createActionById(pickerField, PickerField.ActionType.LOOKUP.getId());
    if (lookup == null || !guiActionSupport.createActionsByMetaAnnotations(pickerField)) {
        guiActionSupport.createActionById(pickerField, PickerField.ActionType.CLEAR.getId());
    }
    return pickerField;
}
Also used : Entity(io.jmix.core.Entity) ContainerOptions(io.jmix.ui.component.data.options.ContainerOptions) MetaClass(io.jmix.core.metamodel.model.MetaClass) Metadata(com.haulmont.cuba.core.global.Metadata) Lookup(com.haulmont.cuba.core.entity.annotation.Lookup) GuiActionSupport(com.haulmont.cuba.gui.components.actions.GuiActionSupport) DataComponents(io.jmix.ui.model.DataComponents)

Example 3 with DataComponents

use of io.jmix.ui.model.DataComponents 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

DataComponents (io.jmix.ui.model.DataComponents)3 MetaClass (io.jmix.core.metamodel.model.MetaClass)2 Lookup (com.haulmont.cuba.core.entity.annotation.Lookup)1 Metadata (com.haulmont.cuba.core.global.Metadata)1 GuiActionSupport (com.haulmont.cuba.gui.components.actions.GuiActionSupport)1 Entity (io.jmix.core.Entity)1 KeyValueMetaClass (io.jmix.core.impl.keyvalue.KeyValueMetaClass)1 ContainerOptions (io.jmix.ui.component.data.options.ContainerOptions)1 InstanceContainer (io.jmix.ui.model.InstanceContainer)1 Function (java.util.function.Function)1