Search in sources :

Example 1 with PaginationDataBinder

use of io.jmix.ui.component.pagination.data.PaginationDataBinder 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 2 with PaginationDataBinder

use of io.jmix.ui.component.pagination.data.PaginationDataBinder in project jmix by jmix-framework.

the class AbstractPaginationLoader method loadDataSourceProvider.

protected void loadDataSourceProvider(Element element) {
    Element loaderProvider = element.element("loaderProvider");
    Element containerProvider = element.element("containerProvider");
    if (loaderProvider != null && containerProvider != null) {
        throw new GuiDevelopmentException("Pagination must have only one provider: 'loaderProvider' or 'containerProvider'", getContext());
    }
    if (loaderProvider != null) {
        loadString(loaderProvider, "loaderId", id -> {
            ScreenData screenData = UiControllerUtils.getScreenData(getComponentContext().getFrame().getFrameOwner());
            DataLoader loader = screenData.getLoader(id);
            if (loader instanceof BaseCollectionLoader) {
                PaginationDataBinder dataSourceProvider = applicationContext.getBean(PaginationLoaderBinder.class, loader);
                resultComponent.setDataBinder(dataSourceProvider);
            } else {
                throw new GuiDevelopmentException(String.format("PaginationDataSourceProvider does not support %s loader type", loader.getClass().getCanonicalName()), getContext());
            }
        });
        if (resultComponent.getDataBinder() == null) {
            throw new GuiDevelopmentException("Specify 'loaderId' attribute of `loaderProvider` element", getContext());
        }
    }
    if (containerProvider != null) {
        loadString(containerProvider, "dataContainer", containerId -> {
            ScreenData screenData = UiControllerUtils.getScreenData(getComponentContext().getFrame().getFrameOwner());
            InstanceContainer container = screenData.getContainer(containerId);
            if (container instanceof CollectionContainer) {
                PaginationDataBinder dataSourceProvider = applicationContext.getBean(PaginationContainerBinder.class, container);
                resultComponent.setDataBinder(dataSourceProvider);
            } else {
                throw new GuiDevelopmentException(String.format("PaginationDataSourceProvider does not support %s container type", container.getClass().getCanonicalName()), getContext());
            }
        });
        if (resultComponent.getDataBinder() == null) {
            throw new GuiDevelopmentException("Specify 'dataContainer' attribute of `containerProvider` element", getContext());
        }
    }
}
Also used : Element(org.dom4j.Element) PaginationDataBinder(io.jmix.ui.component.pagination.data.PaginationDataBinder) GuiDevelopmentException(io.jmix.ui.GuiDevelopmentException)

Example 3 with PaginationDataBinder

use of io.jmix.ui.component.pagination.data.PaginationDataBinder 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

PaginationDataBinder (io.jmix.ui.component.pagination.data.PaginationDataBinder)3 DataUnit (io.jmix.ui.component.data.DataUnit)2 ContainerDataUnit (io.jmix.ui.component.data.meta.ContainerDataUnit)2 EmptyDataUnit (io.jmix.ui.component.data.meta.EmptyDataUnit)2 EntityDataUnit (io.jmix.ui.component.data.meta.EntityDataUnit)2 PaginationDataUnitBinder (io.jmix.ui.component.pagination.data.PaginationDataUnitBinder)2 PaginationEmptyBinder (io.jmix.ui.component.pagination.data.PaginationEmptyBinder)2 GuiDevelopmentException (io.jmix.ui.GuiDevelopmentException)1 Element (org.dom4j.Element)1