Search in sources :

Example 1 with DataLoader

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

the class FilterDataContext method loadAll.

public void loadAll() {
    if (collectionLoaderRegistrations != null) {
        for (DataLoaderRegistration registration : collectionLoaderRegistrations) {
            DataLoader loader = registration.getLoader();
            Map<String, Object> parameterValues = getQueryParameterValues(loader, registration.getParameters());
            for (Map.Entry<String, Object> entry : parameterValues.entrySet()) {
                loader.setParameter(entry.getKey(), entry.getValue());
            }
            loader.load();
        }
    }
    if (containerRegistrations != null) {
        for (ContainerRegistration registration : containerRegistrations) {
            // noinspection unchecked
            registration.getContainer().addCollectionChangeListener(registration.getListener());
        }
    }
}
Also used : DataLoader(io.jmix.ui.model.DataLoader)

Example 2 with DataLoader

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

the class FilterDataContext method loadForParam.

public void loadForParam(Param param) {
    if (collectionLoaderRegistrations != null) {
        collectionLoaderRegistrations.stream().filter(registration -> param.equals(registration.getParam())).findAny().ifPresent(registration -> {
            DataLoader loader = registration.getLoader();
            Map<String, Object> parameterValues = getQueryParameterValues(loader, registration.getParameters());
            for (Map.Entry<String, Object> entry : parameterValues.entrySet()) {
                loader.setParameter(entry.getKey(), entry.getValue());
            }
            loader.load();
        });
    }
}
Also used : DataLoader(io.jmix.ui.model.DataLoader)

Example 3 with DataLoader

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

the class BulkEditors method refreshItems.

protected void refreshItems(@Nullable DataUnit dataSource) {
    if (dataSource instanceof ContainerDataUnit) {
        CollectionContainer<?> container = ((ContainerDataUnit<?>) dataSource).getContainer();
        DataLoader loader = null;
        if (container instanceof HasLoader) {
            loader = ((HasLoader) container).getLoader();
        }
        if (loader != null) {
            loader.load();
        } else {
            log.warn("Target container has no loader, refresh is impossible");
        }
    }
}
Also used : DataLoader(io.jmix.ui.model.DataLoader) HasLoader(io.jmix.ui.model.HasLoader) ContainerDataUnit(io.jmix.ui.component.data.meta.ContainerDataUnit)

Example 4 with DataLoader

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

the class DynamicAttributesPanel method setInstanceContainer.

/**
 * Defines InstanceContainer for DynamicAttributesPanel.
 *
 * @param container {@link InstanceContainer} object with editing entity
 */
@StudioProperty(name = "dataContainer", type = PropertyType.DATACONTAINER_REF, required = true)
public void setInstanceContainer(InstanceContainer<Object> container) {
    this.instanceContainer = container;
    propertiesForm.setValueSourceProvider(new ContainerValueSourceProvider<>(instanceContainer));
    initCategoryField(instanceContainer);
    initPropertiesForm();
    instanceContainer.addItemChangeListener(this::onInstanceContainerItemChangeEvent);
    if (instanceContainer instanceof HasLoader) {
        DataLoader loader = ((HasLoader) instanceContainer).getLoader();
        if (loader != null) {
            loader.setHint(DynAttrQueryHints.LOAD_DYN_ATTR, true);
        }
    }
}
Also used : DataLoader(io.jmix.ui.model.DataLoader) HasLoader(io.jmix.ui.model.HasLoader) StudioProperty(io.jmix.ui.meta.StudioProperty)

Example 5 with DataLoader

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

the class RefreshAction method execute.

/**
 * Executes the action.
 */
@Override
public void execute() {
    if (target == null) {
        throw new IllegalStateException("RefreshAction target is not set");
    }
    if (target.getItems() instanceof EmptyDataUnit) {
        return;
    }
    if (!(target.getItems() instanceof ContainerDataUnit)) {
        throw new IllegalStateException("RefreshAction target is null or does not implement SupportsContainerBinding");
    }
    CollectionContainer container = ((ContainerDataUnit) target.getItems()).getContainer();
    if (container == null) {
        throw new IllegalStateException("RefreshAction target is not bound to CollectionContainer");
    }
    DataLoader loader = null;
    if (container instanceof HasLoader) {
        loader = ((HasLoader) container).getLoader();
    }
    if (loader != null) {
        DataContext dataContext = loader.getDataContext();
        if (dataContext != null) {
            for (Object entity : container.getItems()) {
                dataContext.evict(entity);
            }
        }
        loader.load();
    } else {
        log.warn("RefreshAction '{}' target container has no loader, refresh is impossible", getId());
    }
}
Also used : DataLoader(io.jmix.ui.model.DataLoader) DataContext(io.jmix.ui.model.DataContext) EmptyDataUnit(io.jmix.ui.component.data.meta.EmptyDataUnit) CollectionContainer(io.jmix.ui.model.CollectionContainer) HasLoader(io.jmix.ui.model.HasLoader) ContainerDataUnit(io.jmix.ui.component.data.meta.ContainerDataUnit)

Aggregations

DataLoader (io.jmix.ui.model.DataLoader)12 HasLoader (io.jmix.ui.model.HasLoader)5 ScreenData (io.jmix.ui.model.ScreenData)4 FrameOwner (io.jmix.ui.screen.FrameOwner)3 Screen (io.jmix.ui.screen.Screen)3 ContainerDataUnit (io.jmix.ui.component.data.meta.ContainerDataUnit)2 Subscribe (io.jmix.ui.screen.Subscribe)2 MetaClass (io.jmix.core.metamodel.model.MetaClass)1 MetaProperty (io.jmix.core.metamodel.model.MetaProperty)1 DynamicAttributesState (io.jmix.dynattr.DynamicAttributesState)1 Filter (io.jmix.ui.component.Filter)1 JpqlFilter (io.jmix.ui.component.JpqlFilter)1 EmptyDataUnit (io.jmix.ui.component.data.meta.EmptyDataUnit)1 DesignTimeConfiguration (io.jmix.ui.component.filter.configuration.DesignTimeConfiguration)1 StudioProperty (io.jmix.ui.meta.StudioProperty)1 CollectionContainer (io.jmix.ui.model.CollectionContainer)1 CollectionLoader (io.jmix.ui.model.CollectionLoader)1 DataContext (io.jmix.ui.model.DataContext)1 ScreenContext (io.jmix.ui.screen.ScreenContext)1 Serializable (java.io.Serializable)1