com.vaadin.flow.data.provider.hierarchy.
Class HierarchicalDataCommunicator<T>
- java.lang.Object
-
- com.vaadin.flow.data.provider.DataCommunicator<T>
-
- com.vaadin.flow.data.provider.hierarchy.HierarchicalDataCommunicator<T>
-
Type Parameters:
T
- the bean typeAll Implemented Interfaces:
public class HierarchicalDataCommunicator<T> extends DataCommunicator<T>
Data communicator that handles requesting hierarchical data from
HierarchicalDataProvider
and sending it to client side.Since:
1.2
Author:
Vaadin Ltd
See Also:
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.vaadin.flow.data.provider.DataCommunicator
DataCommunicator.EmptyDataProvider<T1>, DataCommunicator.Filter<F>
-
-
Field Summary
-
Fields inherited from class com.vaadin.flow.data.provider.DataCommunicator
DEFAULT_PAGE_INCREASE_COUNT
-
-
Constructor Summary
Constructors Constructor Description HierarchicalDataCommunicator(CompositeDataGenerator<T> dataGenerator, HierarchicalArrayUpdater arrayUpdater, SerializableConsumer<elemental.json.JsonArray> dataUpdater, StateNode stateNode, SerializableSupplier<ValueProvider<T,String>> uniqueKeyProviderSupplier)
Construct a new hierarchical data communicator backed by a
TreeDataProvider
.
-
Method Summary
All Methods Modifier and Type Method Description Collection<T>
collapse(Collection<T> items)
Collapses the given items and removes its sub-hierarchy.
void
collapse(T item)
Collapses the given item and removes its sub-hierarchy.
protected void
collapse(T item, boolean syncClient)
Collapses the given item and removes its sub-hierarchy.
void
confirmUpdate(int id, String parentKey)
protected <F> HierarchyMapper<T,F>
createHierarchyMapper(HierarchicalDataProvider<T,F> dataProvider)
Create new
HierarchyMapper
for the given data provider.Collection<T>
expand(Collection<T> items)
Expands the given items.
void
expand(T item)
Expands the given item.
protected void
expand(T item, boolean syncClient)
Expands the given item.
Stream<T>
fetchFromProvider(int offset, int limit)
Fetches a list of items from the DataProvider.
HierarchicalDataProvider<T,?>
getDataProvider()
Gets the current data provider from this DataCommunicator.
int
getDataProviderSize()
Getter method for determining the item count of the data.
int
getDepth(T item)
Returns depth of item in the tree starting from zero representing a root.
protected HierarchyMapper<T,?>
getHierarchyMapper()
Returns the
HierarchyMapper
used by this data communicator.Integer
getIndex(T item)
Returns index for the row or
null
.Integer
getParentIndex(T item)
Returns parent index for the row or
null
.T
getParentItem(T item)
Returns parent item for the row or
null
.protected void
handleDataRefreshEvent(DataChangeEvent.DataRefreshEvent<T> event)
boolean
hasChildren(T item)
Returns whether given item has children.
boolean
hasExpandedItems()
Returns true if there is any expanded items.
boolean
isExpanded(T item)
Returns whether given item is expanded.
void
reset()
Resets all the data.
void
setBackEndSorting(List<QuerySortOrder> sortOrder)
Sets the
QuerySortOrder
s to use with backend sorting.<F> SerializableConsumer<F>
setDataProvider(DataProvider<T,F> dataProvider, F initialFilter)
Set the current hierarchical data provider for this communicator.
<F> SerializableConsumer<F>
setDataProvider(HierarchicalDataProvider<T,F> dataProvider, F initialFilter)
Set the current hierarchical data provider for this communicator.
protected <F> void
setFilter(F filter)
void
setInMemorySorting(SerializableComparator<T> comparator)
Sets the
Comparator
to use with in-memory sorting.void
setParentRequestedRange(int start, int length, T parentItem)
-
Methods inherited from class com.vaadin.flow.data.provider.DataCommunicator
buildQuery, confirmUpdate, enablePushUpdates, getBackEndSorting, getFilter, getInMemorySorting, getItem, getItemCount, getItemCountEstimate, getItemCountEstimateIncrease, getKeyMapper, getPageSize, isDefinedSize, isFetchEnabled, isItemActive, isPagingEnabled, refresh, setCountCallback, setDataProvider, setDefinedSize, setFetchEnabled, setItemCountEstimate, setItemCountEstimateIncrease, setKeyMapper, setPageSize, setPagingEnabled, setRequestedRange
-
-
-
-
Constructor Detail
-
HierarchicalDataCommunicator
public HierarchicalDataCommunicator(CompositeDataGenerator<T> dataGenerator, HierarchicalArrayUpdater arrayUpdater, SerializableConsumer<elemental.json.JsonArray> dataUpdater, StateNode stateNode, SerializableSupplier<ValueProvider<T,String>> uniqueKeyProviderSupplier)
Construct a new hierarchical data communicator backed by a
TreeDataProvider
.Parameters:
dataGenerator
- the data generator functionarrayUpdater
- array updater strategydataUpdater
- data updater strategystateNode
- the state node used to communicate foruniqueKeyProviderSupplier
- Unique key provider for a row. If null, then using Grid's default key generator.
-
-
Method Detail
-
reset
public void reset()
Resets all the data.
It effectively resends all available data.
Overrides:
reset
in classDataCommunicator<T>
-
handleDataRefreshEvent
protected void handleDataRefreshEvent(DataChangeEvent.DataRefreshEvent<T> event)
Overrides:
handleDataRefreshEvent
in classDataCommunicator<T>
-
fetchFromProvider
public Stream<T> fetchFromProvider(int offset, int limit)
Description copied from class:
DataCommunicator
Fetches a list of items from the DataProvider.
NOTE: the
limit
parameter shows how many items the client wants to fetch, but the actual number of results may be greater, and vary from0 to pages * pageSize
.Overrides:
fetchFromProvider
in classDataCommunicator<T>
Parameters:
offset
- the starting index of the rangelimit
- the desired number of resultsReturns:
the list of items in given range
-
setParentRequestedRange
public void setParentRequestedRange(int start, int length, T parentItem)
-
getDataProvider
public HierarchicalDataProvider<T,?> getDataProvider()
Description copied from class:
DataCommunicator
Gets the current data provider from this DataCommunicator.
Overrides:
getDataProvider
in classDataCommunicator<T>
Returns:
the data provider
-
setDataProvider
public <F> SerializableConsumer<F> setDataProvider(HierarchicalDataProvider<T,F> dataProvider, F initialFilter)
Set the current hierarchical data provider for this communicator.
Type Parameters:
F
- the filter typeParameters:
dataProvider
- the data provider to set, notnull
initialFilter
- the initial filter value to use, ornull
to not use any initial filter valueReturns:
a consumer that accepts a new filter value to use
-
createHierarchyMapper
protected <F> HierarchyMapper<T,F> createHierarchyMapper(HierarchicalDataProvider<T,F> dataProvider)
Create new
HierarchyMapper
for the given data provider. May be overridden in subclasses.Type Parameters:
F
- Query typeParameters:
dataProvider
- the data providerReturns:
new
HierarchyMapper
-
setDataProvider
public <F> SerializableConsumer<F> setDataProvider(DataProvider<T,F> dataProvider, F initialFilter)
Set the current hierarchical data provider for this communicator.
Overrides:
setDataProvider
in classDataCommunicator<T>
Type Parameters:
F
- the filter typeParameters:
dataProvider
- the data provider to set, must extendHierarchicalDataProvider
, notnull
initialFilter
- the initial filter value to use, ornull
to not use any initial filter valueReturns:
a consumer that accepts a new filter value to use
-
confirmUpdate
public void confirmUpdate(int id, String parentKey)
-
collapse
public void collapse(T item)
Collapses the given item and removes its sub-hierarchy. Calling this method will have no effect if the row is already collapsed.
Changes are synchronized to the client.
Parameters:
item
- the item to collapse
-
collapse
protected void collapse(T item, boolean syncClient)
Collapses the given item and removes its sub-hierarchy. Calling this method will have no effect if the row is already collapsed.
syncClient
indicates whether the changes should be synchronized to the client.Parameters:
item
- the item to collapsesyncClient
-true
if the changes should be synchronized to the client,false
otherwise.
-
collapse
public Collection<T> collapse(Collection<T> items)
Collapses the given items and removes its sub-hierarchy. Calling this method will have no effect if the row is already collapsed.
Changes are synchronized to the client.
Parameters:
items
- the items to collapseReturns:
the collapsed items
-
expand
public void expand(T item)
Expands the given item. Calling this method will have no effect if the item is already expanded or if it has no children.
Changes are synchronized to the client.
Parameters:
item
- the item to expand
-
expand
public Collection<T> expand(Collection<T> items)
Expands the given items. Calling this method will have no effect if the item is already expanded or if it has no children.
Changes are synchronized to the client.
Parameters:
items
- the items to expandReturns:
the expanded items
-
expand
protected void expand(T item, boolean syncClient)
Expands the given item. Calling this method will have no effect if the item is already expanded or if it has no children.
syncClient
indicates whether the changes should be synchronized to the client.Parameters:
item
- the item to expandsyncClient
-true
if the changes should be synchronized to the client,false
otherwise.
-
hasChildren
public boolean hasChildren(T item)
Returns whether given item has children.
Parameters:
item
- the item to testReturns:
true
if item has children;false
if not
-
isExpanded
public boolean isExpanded(T item)
Returns whether given item is expanded.
Parameters:
item
- the item to testReturns:
true
if item is expanded;false
if not
-
getParentIndex
public Integer getParentIndex(T item)
Returns parent index for the row or
null
.Parameters:
item
- the item to find the parent ofReturns:
the parent index or
null
for top-level items
-
getIndex
public Integer getIndex(T item)
Returns index for the row or
null
.Parameters:
item
- the target itemReturns:
the index or
null
for top-level and non-existing items
-
getParentItem
public T getParentItem(T item)
Returns parent item for the row or
null
.Parameters:
item
- the item to find the parent ofReturns:
the parent item or
null
for top-level items
-
getDepth
public int getDepth(T item)
Returns depth of item in the tree starting from zero representing a root.
Parameters:
item
- Target itemReturns:
depth of item in the tree or -1 if item is null
-
getDataProviderSize
public int getDataProviderSize()
Description copied from class:
DataCommunicator
Getter method for determining the item count of the data.
This method should be used only with defined size, i.e. when
DataCommunicator.isDefinedSize()
returnstrue
.Can be overridden by a subclass that uses a specific type of DataProvider and/or query.
Overrides:
getDataProviderSize
in classDataCommunicator<T>
Returns:
the size of data provider with current filter
-
setBackEndSorting
public void setBackEndSorting(List<QuerySortOrder> sortOrder)
Description copied from class:
DataCommunicator
Sets the
QuerySortOrder
s to use with backend sorting.Overrides:
setBackEndSorting
in classDataCommunicator<T>
Parameters:
sortOrder
- list of sort order information to pass to a query
-
setInMemorySorting
public void setInMemorySorting(SerializableComparator<T> comparator)
Description copied from class:
DataCommunicator
Sets the
Comparator
to use with in-memory sorting.Overrides:
setInMemorySorting
in classDataCommunicator<T>
Parameters:
comparator
- comparator used to sort data
-
setFilter
protected <F> void setFilter(F filter)
-
hasExpandedItems
public boolean hasExpandedItems()
Returns true if there is any expanded items.
Returns:
true
if there is any expanded items.
-
getHierarchyMapper
protected HierarchyMapper<T,?> getHierarchyMapper()
Returns the
HierarchyMapper
used by this data communicator.Returns:
the hierarchy mapper used by this data communicator
-
-