//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// This file is a part of the 'esoco-common' project.
// Copyright 2017 Elmar Sonnenschein, esoco GmbH, Flensburg, Germany
//
// 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 de.esoco.lib.model;

import de.esoco.lib.property.HasAttributeFilter;
import de.esoco.lib.property.HasAttributeSorting;

import java.util.LinkedHashMap;
import java.util.Map;
import java.util.function.Function;
import java.util.function.Predicate;


/********************************************************************
 * A base class for {@link DataProvider} implementations that handles the
 * management of filter and sort constraints.
 *
 * @author eso
 */
public abstract class AbstractDataProvider<T> implements DataProvider<T>,
														 HasAttributeFilter<T>,
														 HasAttributeSorting<T>
{
	//~ Instance fields --------------------------------------------------------

	private Map<Function<? super T, ?>, Predicate<?>> aAttributeFilters =
		new LinkedHashMap<>();

	private Map<Function<? super T, ? extends Comparable<?>>, SortDirection> aAttributeOrders =
		new LinkedHashMap<>();

	//~ Methods ----------------------------------------------------------------

	/***************************************
	 * {@inheritDoc}
	 */
	@Override
	public <V> void applyFilter(
		Function<? super T, V> rAttribute,
		Predicate<? super V>   pCriteria)
	{
		if (pCriteria == null)
		{
			aAttributeFilters.remove(rAttribute);
		}
		else
		{
			aAttributeFilters.put(rAttribute, pCriteria);
		}

		applyConstraints();
	}

	/***************************************
	 * {@inheritDoc}
	 */
	@Override
	public <V extends Comparable<V>> void applySorting(
		Function<? super T, V> rAttribute,
		SortDirection		   eDirection)
	{
		if (eDirection == null)
		{
			aAttributeOrders.remove(rAttribute);
		}
		else
		{
			aAttributeOrders.put(rAttribute, eDirection);
		}

		applyConstraints();
	}

	/***************************************
	 * {@inheritDoc}
	 */
	@Override
	@SuppressWarnings("unchecked")
	public <V> Predicate<? super V> getFilter(Function<? super T, V> rAttribute)
	{
		return (Predicate<? super V>) aAttributeFilters.get(rAttribute);
	}

	/***************************************
	 * {@inheritDoc}
	 */
	@Override
	public SortDirection getSortDirection(Function<? super T, ?> rAttribute)
	{
		return aAttributeOrders.get(rAttribute);
	}

	/***************************************
	 * Must be implemented by subclasses to apply (or reset) the filter and
	 * order constraints that have been set on this instance.
	 */
	protected abstract void applyConstraints();

	/***************************************
	 * Returns the attribute filters.
	 *
	 * @return A mapping from attributes to filter predicates
	 */
	protected final Map<Function<? super T, ?>, Predicate<?>> getAttributeFilters()
	{
		return aAttributeFilters;
	}

	/***************************************
	 * Returns the attribute order criteria.
	 *
	 * @return A mapping from attributes to order directions
	 */
	protected final Map<Function<? super T, ? extends Comparable<?>>,
						SortDirection> getAttributeOrders()
	{
		return aAttributeOrders;
	}
}

@@ -1712,21 +1712,23 @@
 ttribute
-Order
+Sorting
 s =%0A%09%09ne
@@ -2419,21 +2419,23 @@
 ttribute
-Order
+Sorting
 s.remove
@@ -2476,21 +2476,23 @@
 ttribute
-Order
+Sorting
 s.put(rA
@@ -2981,29 +2981,378 @@
 bute
-Orders.get(rAttribute
+Sortings.get(rAttribute);%0A%09%7D%0A%0A%09/***************************************%0A%09 * Removes all attribute filters.%0A%09 */%0A%09public void removeAllFilters()%0A%09%7B%0A%09%09aAttributeFilters.clear();%0A%09%09applyConstraints();%0A%09%7D%0A%0A%09/***************************************%0A%09 * Removes all attribute sortings.%0A%09 */%0A%09public void removeAllSortings()%0A%09%7B%0A%09%09aAttributeSortings.clear();%0A%09%09applyConstraints(
 );%0A%09
@@ -4122,21 +4122,23 @@
 ttribute
-Order
+Sorting
 s;%0A%09%7D%0A%7D%0A

Implement UiEntityTableList