Search in sources :

Example 1 with DataLoader

use of com.haulmont.cuba.gui.model.DataLoader in project cuba by cuba-platform.

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(com.haulmont.cuba.gui.model.DataLoader)

Example 2 with DataLoader

use of com.haulmont.cuba.gui.model.DataLoader in project cuba by cuba-platform.

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) entity);
            }
        }
        loader.load();
    } else {
        log.warn("RefreshAction '{}' target container has no loader, refresh is impossible", getId());
    }
}
Also used : DataLoader(com.haulmont.cuba.gui.model.DataLoader) DataContext(com.haulmont.cuba.gui.model.DataContext) EmptyDataUnit(com.haulmont.cuba.gui.components.data.meta.EmptyDataUnit) CollectionContainer(com.haulmont.cuba.gui.model.CollectionContainer) HasLoader(com.haulmont.cuba.gui.model.HasLoader) ContainerDataUnit(com.haulmont.cuba.gui.components.data.meta.ContainerDataUnit)

Example 3 with DataLoader

use of com.haulmont.cuba.gui.model.DataLoader in project cuba by cuba-platform.

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(com.haulmont.cuba.gui.model.DataLoader)

Aggregations

DataLoader (com.haulmont.cuba.gui.model.DataLoader)3 ContainerDataUnit (com.haulmont.cuba.gui.components.data.meta.ContainerDataUnit)1 EmptyDataUnit (com.haulmont.cuba.gui.components.data.meta.EmptyDataUnit)1 CollectionContainer (com.haulmont.cuba.gui.model.CollectionContainer)1 DataContext (com.haulmont.cuba.gui.model.DataContext)1 HasLoader (com.haulmont.cuba.gui.model.HasLoader)1