All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.holonplatform.vaadin.data.ItemDataProvider Maven / Gradle / Ivy

There is a newer version: 5.4.0
Show newest version
/*
 * Copyright 2016-2017 Axioma srl.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package com.holonplatform.vaadin.data;

import java.util.function.Function;

import com.holonplatform.core.beans.BeanIntrospector;
import com.holonplatform.core.datastore.DataTarget;
import com.holonplatform.core.datastore.Datastore;
import com.holonplatform.core.property.PropertyBox;
import com.holonplatform.core.property.PropertySet;
import com.holonplatform.core.query.QueryConfigurationProvider;
import com.holonplatform.vaadin.internal.data.DatastoreBeanItemDataProvider;
import com.holonplatform.vaadin.internal.data.DatastoreItemDataProvider;
import com.holonplatform.vaadin.internal.data.DefaultItemDataProvider;
import com.holonplatform.vaadin.internal.data.ItemDataProviderWrapper;

/**
 * Iterface to load items data from a data source.
 * 
 * @param  Item data type
 * 
 * @since 5.0.0
 */
public interface ItemDataProvider extends ItemSetCounter, ItemSetLoader {

	/**
	 * Create an {@link ItemDataProvider} using given operations.
	 * @param  Item data type
	 * @param counter Items counter (not null)
	 * @param loader Items loader (not null)
	 * @return A new {@link ItemDataProvider} instance
	 */
	static  ItemDataProvider create(ItemSetCounter counter, ItemSetLoader loader) {
		return new DefaultItemDataProvider<>(counter, loader);
	}

	/**
	 * Construct a {@link ItemDataProvider} using a {@link Datastore}.
	 * @param datastore Datastore to use (not null)
	 * @param target Data target (not null)
	 * @param propertySet Property set to load
	 * @return the {@link ItemDataProvider} instance
	 */
	static ItemDataProvider create(Datastore datastore, DataTarget target, PropertySet propertySet) {
		return new DatastoreItemDataProvider(datastore, target, propertySet);
	}

	/**
	 * Construct a {@link ItemDataProvider} using a {@link Datastore}.
	 * @param datastore Datastore to use (not null)
	 * @param target Data target (not null)
	 * @param propertySet Property set to load
	 * @param queryConfigurationProviders Optional additional {@link QueryConfigurationProvider}s
	 * @return the {@link ItemDataProvider} instance
	 */
	static ItemDataProvider create(Datastore datastore, DataTarget target, PropertySet propertySet,
			QueryConfigurationProvider... queryConfigurationProviders) {
		DatastoreItemDataProvider provider = new DatastoreItemDataProvider(datastore, target, propertySet);
		if (queryConfigurationProviders != null) {
			for (QueryConfigurationProvider queryConfigurationProvider : queryConfigurationProviders) {
				provider.addQueryConfigurationProvider(queryConfigurationProvider);
			}
		}
		return provider;
	}

	/**
	 * Construct a {@link ItemDataProvider} using a {@link Datastore} and given beanClass as item type.
	 * 

* The query projection will be configured using the bean class property names and the query results will be * obtained as instances of given bean class. The default {@link BeanIntrospector} will be used to inspect bean * class properties. *

* @param Bean type * @param datastore Datastore to use (not null) * @param target Data target (not null) * @param beanClass Item bean type (not null) * @return the {@link ItemDataProvider} instance */ static ItemDataProvider create(Datastore datastore, DataTarget target, Class beanClass) { return new DatastoreBeanItemDataProvider<>(datastore, target, beanClass); } /** * Construct a {@link ItemDataProvider} using a {@link Datastore} and given beanClass as item type. *

* The query projection will be configured using the bean class property names and the query results will be * obtained as instances of given bean class. The default {@link BeanIntrospector} will be used to inspect bean * class properties. *

* @param Bean type * @param datastore Datastore to use (not null) * @param target Data target (not null) * @param beanClass Item bean type (not null) * @param queryConfigurationProviders Optional additional {@link QueryConfigurationProvider}s * @return the {@link ItemDataProvider} instance */ static ItemDataProvider create(Datastore datastore, DataTarget target, Class beanClass, QueryConfigurationProvider... queryConfigurationProviders) { DatastoreBeanItemDataProvider provider = new DatastoreBeanItemDataProvider<>(datastore, target, beanClass); if (queryConfigurationProviders != null) { for (QueryConfigurationProvider queryConfigurationProvider : queryConfigurationProviders) { provider.addQueryConfigurationProvider(queryConfigurationProvider); } } return provider; } /** * Create a new {@link ItemDataProvider} which wraps a concrete data provider and converts items into a different * type using a converter function. * @param Item type * @param Converted type * @param provider Concrete data privider (not null) * @param converter Converter function (not null) * @return the data provider wrapper * @return the {@link ItemDataProvider} instance */ static ItemDataProvider convert(ItemDataProvider provider, Function converter) { return new ItemDataProviderWrapper<>(provider, converter); } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy