Search in sources :

Example 1 with EmptyDataUnit

use of io.jmix.ui.component.data.meta.EmptyDataUnit 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)

Example 2 with EmptyDataUnit

use of io.jmix.ui.component.data.meta.EmptyDataUnit in project jmix by jmix-framework.

the class AbstractDataGrid method setupPaginationDataSourceProvider.

public void setupPaginationDataSourceProvider() {
    if (pagination == null) {
        return;
    }
    DataUnit items = getItems();
    PaginationDataBinder provider;
    if (items instanceof ContainerDataUnit) {
        provider = applicationContext.getBean(PaginationDataUnitBinder.class, items);
    } else if (items instanceof EmptyDataUnit && items instanceof EntityDataUnit) {
        provider = new PaginationEmptyBinder(((EntityDataUnit) items).getEntityMetaClass());
    } else {
        throw new IllegalStateException("Unsupported data unit type: " + items);
    }
    pagination.setDataBinder(provider);
}
Also used : PaginationDataUnitBinder(io.jmix.ui.component.pagination.data.PaginationDataUnitBinder) PaginationEmptyBinder(io.jmix.ui.component.pagination.data.PaginationEmptyBinder) EmptyDataUnit(io.jmix.ui.component.data.meta.EmptyDataUnit) DataUnit(io.jmix.ui.component.data.DataUnit) EntityDataUnit(io.jmix.ui.component.data.meta.EntityDataUnit) ContainerDataUnit(io.jmix.ui.component.data.meta.ContainerDataUnit) EmptyDataUnit(io.jmix.ui.component.data.meta.EmptyDataUnit) PaginationDataBinder(io.jmix.ui.component.pagination.data.PaginationDataBinder) ContainerDataUnit(io.jmix.ui.component.data.meta.ContainerDataUnit) EntityDataUnit(io.jmix.ui.component.data.meta.EntityDataUnit)

Example 3 with EmptyDataUnit

use of io.jmix.ui.component.data.meta.EmptyDataUnit in project jmix by jmix-framework.

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(io.jmix.ui.component.data.meta.EmptyDataUnit) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource)

Example 4 with EmptyDataUnit

use of io.jmix.ui.component.data.meta.EmptyDataUnit in project jmix by jmix-framework.

the class AbstractTable method setupPaginationDataSourceProvider.

public void setupPaginationDataSourceProvider() {
    if (pagination == null) {
        return;
    }
    DataUnit items = getItems();
    PaginationDataBinder provider;
    if (items instanceof ContainerDataUnit) {
        provider = applicationContext.getBean(PaginationDataUnitBinder.class, items);
    } else if (items instanceof EmptyDataUnit && items instanceof EntityDataUnit) {
        provider = new PaginationEmptyBinder(((EntityDataUnit) items).getEntityMetaClass());
    } else {
        throw new IllegalStateException("Unsupported data unit type: " + items);
    }
    pagination.setDataBinder(provider);
}
Also used : PaginationDataUnitBinder(io.jmix.ui.component.pagination.data.PaginationDataUnitBinder) PaginationEmptyBinder(io.jmix.ui.component.pagination.data.PaginationEmptyBinder) EmptyDataUnit(io.jmix.ui.component.data.meta.EmptyDataUnit) DataUnit(io.jmix.ui.component.data.DataUnit) EntityDataUnit(io.jmix.ui.component.data.meta.EntityDataUnit) ContainerDataUnit(io.jmix.ui.component.data.meta.ContainerDataUnit) EmptyDataUnit(io.jmix.ui.component.data.meta.EmptyDataUnit) PaginationDataBinder(io.jmix.ui.component.pagination.data.PaginationDataBinder) ContainerDataUnit(io.jmix.ui.component.data.meta.ContainerDataUnit) EntityDataUnit(io.jmix.ui.component.data.meta.EntityDataUnit)

Aggregations

EmptyDataUnit (io.jmix.ui.component.data.meta.EmptyDataUnit)4 ContainerDataUnit (io.jmix.ui.component.data.meta.ContainerDataUnit)3 DataUnit (io.jmix.ui.component.data.DataUnit)2 EntityDataUnit (io.jmix.ui.component.data.meta.EntityDataUnit)2 PaginationDataBinder (io.jmix.ui.component.pagination.data.PaginationDataBinder)2 PaginationDataUnitBinder (io.jmix.ui.component.pagination.data.PaginationDataUnitBinder)2 PaginationEmptyBinder (io.jmix.ui.component.pagination.data.PaginationEmptyBinder)2 CollectionDatasource (com.haulmont.cuba.gui.data.CollectionDatasource)1 CollectionContainer (io.jmix.ui.model.CollectionContainer)1 DataContext (io.jmix.ui.model.DataContext)1 DataLoader (io.jmix.ui.model.DataLoader)1 HasLoader (io.jmix.ui.model.HasLoader)1