com.vaadin.data.provider.DataProviderWrapper Maven / Gradle / Ivy
/*
* Copyright (C) 2000-2024 Vaadin Ltd
*
* This program is available under Vaadin Commercial License and Service Terms.
*
* See for the full
* license.
*/
package com.vaadin.data.provider;
import java.util.Objects;
import java.util.stream.Stream;
import com.vaadin.shared.Registration;
/**
* Wrapper class for modifying, chaining and replacing filters and sorting in a
* query. Used to create a suitable {@link Query} for the underlying data
* provider with correct filters and sorting.
*
* @author Vaadin Ltd.
* @since 8.0
*
* @param
* data provider data type
* @param
* wrapper query filter type
* @param
* underlying data provider filter type
*/
public abstract class DataProviderWrapper
implements DataProvider {
/**
* The actual data provider behind this wrapper.
*/
protected DataProvider dataProvider;
/**
* Constructs a filtering wrapper for a data provider.
*
* @param dataProvider
* the wrapped data provider, not null
*/
protected DataProviderWrapper(DataProvider dataProvider) {
this.dataProvider = Objects.requireNonNull(dataProvider,
"The wrapped data provider cannot be null.");
}
@Override
public boolean isInMemory() {
return dataProvider.isInMemory();
}
@Override
public void refreshAll() {
dataProvider.refreshAll();
}
@Override
public void refreshItem(T item) {
dataProvider.refreshItem(item);
}
@Override
public Object getId(T item) {
return dataProvider.getId(item);
}
@Override
public Registration addDataProviderListener(
DataProviderListener listener) {
return dataProvider.addDataProviderListener(listener);
}
@Override
public int size(Query t) {
return dataProvider.size(new Query<>(t.getOffset(), t.getLimit(),
t.getSortOrders(), t.getInMemorySorting(), getFilter(t)));
}
@Override
public Stream fetch(Query t) {
return dataProvider.fetch(new Query<>(t.getOffset(), t.getLimit(),
t.getSortOrders(), t.getInMemorySorting(), getFilter(t)));
}
/**
* Gets the filter that should be used in the modified Query.
*
* @param query
* the current query
* @return filter for the modified Query
*/
protected abstract M getFilter(Query query);
}