com.vaadin.data.provider.
Class HierarchyMapper<T,F>
- java.lang.Object
-
- com.vaadin.data.provider.HierarchyMapper<T,F>
-
Type Parameters:
T
- the data typeF
- the filter typeAll Implemented Interfaces:
public class HierarchyMapper<T,F> extends Object implements DataGenerator<T>
Mapper for hierarchical data.
Keeps track of the expanded nodes, and size of of the subtrees for each expanded node.
This class is framework internal implementation details, and can be changed / moved at any point. This means that you should not directly use this for anything.
Since:
8.1
Author:
Vaadin Ltd
See Also:
-
-
Constructor Summary
Constructors Constructor and Description HierarchyMapper(HierarchicalDataProvider<T,F> provider)
Constructs a new HierarchyMapper.
-
Method Summary
All Methods Modifier and Type Method and Description Range
collapse(T item, Integer position)
Collapses the given item.
void
destroyAllData()
Informs the
DataGenerator
that all data has been dropped.Range
doCollapse(T item, Optional<Integer> position)
Deprecated.
Usecollapse(Object, Integer)
instead.Range
doExpand(T item, Optional<Integer> position)
Deprecated.
Useexpand(Object, Integer)
instead.Range
expand(T item, Integer position)
Expands the given item.
Stream<T>
fetchItems(Range range)
Gets a stream of items in the form of a flattened hierarchy from the back-end and filter the wanted results from the list.
Stream<T>
fetchItems(T parent, Range range)
Gets a stream of children for the given item in the form of a flattened hierarchy from the back-end and filter the wanted results from the list.
void
generateData(T item, JsonObject jsonObject)
Adds custom data for the given item to its serialized
JsonObject
representation.List<QuerySortOrder>
getBackEndSorting()
Gets the current back-end sorting.
HierarchicalDataProvider<T,F>
getDataProvider()
Gets the
HierarchicalDataProvider
for thisHierarchyMapper
.F
getFilter()
Gets the current filter.
Optional<Integer>
getIndexOf(T target)
Finds the current index of given object.
Comparator<T>
getInMemorySorting()
Gets the current in-memory sorting.
ItemCollapseAllowedProvider<T>
getItemCollapseAllowedProvider()
Gets the current item collapse allowed provider.
Integer
getParentIndex(T item)
Finds the index of the parent of the item in given target index.
protected T
getParentOfItem(T item)
Find parent for the given item among open folders.
int
getTreeSize()
Returns the size of the currently expanded hierarchy.
boolean
hasChildren(T item)
Returns whether given item has children.
boolean
isExpanded(T item)
Returns whether the given item is expanded.
protected void
registerChildren(T parent, List<T> childList)
Register parent and children items into inner structures.
protected void
removeChildren(Object id)
Removes all children of an item identified by a given id.
void
setBackEndSorting(List<QuerySortOrder> backEndSorting)
Sets the current back-end sorting.
void
setFilter(Object filter)
Sets the current filter.
void
setInMemorySorting(Comparator<T> inMemorySorting)
Sets the current in-memory sorting.
void
setItemCollapseAllowedProvider(ItemCollapseAllowedProvider<T> itemCollapseAllowedProvider)
Sets the current item collapse allowed provider.
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.vaadin.data.provider.DataGenerator
destroyData, refreshData
-
-
-
-
Constructor Detail
-
HierarchyMapper
public HierarchyMapper(HierarchicalDataProvider<T,F> provider)
Constructs a new HierarchyMapper.
Parameters:
provider
- the hierarchical data provider for this mapper
-
-
Method Detail
-
getTreeSize
public int getTreeSize()
Returns the size of the currently expanded hierarchy.
Returns:
the amount of available data
-
getParentIndex
public Integer getParentIndex(T item)
Finds the index of the parent of the item in given target index.
Parameters:
item
- the item to get the parent ofReturns:
the parent index or a negative value if the parent is not found
-
isExpanded
public boolean isExpanded(T item)
Returns whether the given item is expanded.
Parameters:
item
- the item to testReturns:
true
if item is expanded;false
if not
-
expand
public Range expand(T item, Integer position)
Expands the given item.
Parameters:
item
- the item to expandposition
- the index of the itemReturns:
range of rows added by expanding the item
-
doExpand
@Deprecated public Range doExpand(T item, Optional<Integer> position)
Deprecated. Use
expand(Object, Integer)
instead.Expands the given item.
Parameters:
item
- the item to expandposition
- the index of itemReturns:
range of rows added by expanding the item
-
collapse
public Range collapse(T item, Integer position)
Collapses the given item.
Parameters:
item
- the item to collapseposition
- the index of the itemReturns:
range of rows removed by collapsing the item
-
doCollapse
@Deprecated public Range doCollapse(T item, Optional<Integer> position)
Deprecated. Use
collapse(Object, Integer)
instead.Collapses the given item.
Parameters:
item
- the item to collapseposition
- the index of itemReturns:
range of rows removed by collapsing the item
-
generateData
public void generateData(T item, JsonObject jsonObject)
Description copied from interface:
DataGenerator
Adds custom data for the given item to its serialized
JsonObject
representation. This JSON object will be sent to client-side DataProvider.Specified by:
generateData
in interfaceDataGenerator<T>
Parameters:
item
- the data item being serializedjsonObject
- the JSON object being sent to the client
-
getItemCollapseAllowedProvider
public ItemCollapseAllowedProvider<T> getItemCollapseAllowedProvider()
Gets the current item collapse allowed provider.
Returns:
the item collapse allowed provider
-
setItemCollapseAllowedProvider
public void setItemCollapseAllowedProvider(ItemCollapseAllowedProvider<T> itemCollapseAllowedProvider)
Sets the current item collapse allowed provider.
Parameters:
itemCollapseAllowedProvider
- the item collapse allowed provider
-
getInMemorySorting
public Comparator<T> getInMemorySorting()
Gets the current in-memory sorting.
Returns:
the in-memory sorting
-
setInMemorySorting
public void setInMemorySorting(Comparator<T> inMemorySorting)
Sets the current in-memory sorting. This will cause the hierarchy to be constructed again.
Parameters:
inMemorySorting
- the in-memory sorting
-
getBackEndSorting
public List<QuerySortOrder> getBackEndSorting()
Gets the current back-end sorting.
Returns:
the back-end sorting
-
setBackEndSorting
public void setBackEndSorting(List<QuerySortOrder> backEndSorting)
Sets the current back-end sorting. This will cause the hierarchy to be constructed again.
Parameters:
backEndSorting
- the back-end sorting
-
getFilter
public F getFilter()
Gets the current filter.
Returns:
the filter
-
setFilter
public void setFilter(Object filter)
Sets the current filter. This will cause the hierarchy to be constructed again.
Parameters:
filter
- the filter
-
getDataProvider
public HierarchicalDataProvider<T,F> getDataProvider()
Gets the
HierarchicalDataProvider
for thisHierarchyMapper
.Returns:
the hierarchical data provider
-
hasChildren
public boolean hasChildren(T item)
Returns whether given item has children.
Parameters:
item
- the node to testReturns:
true
if node has children;false
if not
-
fetchItems
public Stream<T> fetchItems(Range range)
Gets a stream of items in the form of a flattened hierarchy from the back-end and filter the wanted results from the list.
Parameters:
range
- the requested item rangeReturns:
the stream of items
-
fetchItems
public Stream<T> fetchItems(T parent, Range range)
Gets a stream of children for the given item in the form of a flattened hierarchy from the back-end and filter the wanted results from the list.
Parameters:
parent
- the parent item for the fetchrange
- the requested item rangeReturns:
the stream of items
-
getParentOfItem
protected T getParentOfItem(T item)
Find parent for the given item among open folders.
Parameters:
item
- the itemReturns:
parent item or
null
for root items or if the parent is closed
-
removeChildren
protected void removeChildren(Object id)
Removes all children of an item identified by a given id. Items removed by this method as well as the original item are all marked to be collapsed. May be overridden in subclasses for removing obsolete data to avoid memory leaks.
Parameters:
id
- the item id
-
getIndexOf
public Optional<Integer> getIndexOf(T target)
Finds the current index of given object. This is based on a search in flattened version of the hierarchy.
Parameters:
target
- the target object to findReturns:
optional index of given object
-
registerChildren
protected void registerChildren(T parent, List<T> childList)
Register parent and children items into inner structures. May be overridden in subclasses.
Parameters:
parent
- the parent itemchildList
- list of parents children to be registered.
-
destroyAllData
public void destroyAllData()
Description copied from interface:
DataGenerator
Informs the
DataGenerator
that all data has been dropped. This method should clean up any unneeded information stored for items.Specified by:
destroyAllData
in interfaceDataGenerator<T>
-
-