Search in sources :

Example 1 with EmptyDataUnit

use of com.haulmont.cuba.gui.components.data.meta.EmptyDataUnit 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 2 with EmptyDataUnit

use of com.haulmont.cuba.gui.components.data.meta.EmptyDataUnit in project cuba by cuba-platform.

the class RefreshAction method actionPerform.

/**
 * This method is invoked by action owner component. Don't override it, there are special methods to
 * customize behaviour below.
 *
 * @param component component invoking action
 */
@Override
public void actionPerform(Component component) {
    if (beforeRefreshHandler != null) {
        beforeRefreshHandler.run();
    }
    CollectionDatasource datasource = owner.getDatasource();
    if (datasource == null) {
        // In case of using the 'metaClass' attribute, no datasource is created, but EmptyDataUnit.
        if (owner.getItems() instanceof EmptyDataUnit) {
            return;
        }
        throw new IllegalStateException("RefreshAction target is not bound to CollectionDatasource");
    }
    Map<String, Object> refreshParams = getRefreshParams();
    Map<String, Object> supplierParams = null;
    if (refreshParamsSupplier != null) {
        supplierParams = refreshParamsSupplier.get();
    }
    Map<String, Object> params = null;
    if (supplierParams != null || refreshParams != null) {
        params = new HashMap<>();
        params.putAll(refreshParams != null ? refreshParams : Collections.emptyMap());
        params.putAll(supplierParams != null ? supplierParams : Collections.emptyMap());
    }
    if (params != null) {
        datasource.refresh(params);
    } else {
        datasource.refresh();
    }
    if (afterRefreshHandler != null) {
        afterRefreshHandler.run();
    }
}
Also used : EmptyDataUnit(com.haulmont.cuba.gui.components.data.meta.EmptyDataUnit) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource)

Aggregations

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