Package com.vaadin.data.provider
Class HierarchicalDataCommunicator<T>
- java.lang.Object
-
- com.vaadin.server.AbstractClientConnector
-
- com.vaadin.server.AbstractExtension
-
- com.vaadin.data.provider.DataCommunicator<T>
-
- com.vaadin.data.provider.HierarchicalDataCommunicator<T>
-
- Type Parameters:
T- the bean type
- All Implemented Interfaces:
MethodEventSource,ClientConnector,Extension,Connector,Serializable
public class HierarchicalDataCommunicator<T> extends DataCommunicator<T>
Data communicator that handles requesting hierarchical data fromHierarchicalDataProviderand sending it to client side.- Since:
- 8.1
- Author:
- Vaadin Ltd
- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.vaadin.data.provider.DataCommunicator
DataCommunicator.ActiveDataHandler, DataCommunicator.SimpleDataRequestRpc
-
Nested classes/interfaces inherited from interface com.vaadin.server.ClientConnector
ClientConnector.AttachEvent, ClientConnector.AttachListener, ClientConnector.ConnectorErrorEvent, ClientConnector.DetachEvent, ClientConnector.DetachListener
-
-
Field Summary
-
Fields inherited from class com.vaadin.data.provider.DataCommunicator
reset
-
-
Constructor Summary
Constructors Constructor Description HierarchicalDataCommunicator()Construct a new hierarchical data communicator backed by aTreeDataProvider.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidcollapse(T item)Collapses the given item and removes its sub-hierarchy.voidcollapse(T item, boolean syncAndRefresh)Collapses the given item and removes its sub-hierarchy.voidcollapse(T item, Integer index)Collapses the given item and removes its sub-hierarchy.protected <F> HierarchyMapper<T,F>createHierarchyMapper(HierarchicalDataProvider<T,F> dataProvider)Create newHierarchyMapperfor the given data provider.voiddoCollapse(T item, Optional<Integer> index)Deprecated.Usecollapse(Object, Integer)instead.voiddoExpand(T item, Optional<Integer> index)Deprecated.useexpand(Object, Integer)insteadvoidexpand(T item)Expands the given item.voidexpand(T item, boolean syncAndRefresh)Expands the given item.voidexpand(T item, Integer index)Expands the given item at the given index.List<T>fetchItemsWithRange(int offset, int limit)Fetches a list of items from the DataProvider.HierarchicalDataProvider<T,?>getDataProvider()Gets the current data provider from this DataCommunicator.intgetDataProviderSize()Getter method for finding the size of DataProvider.protected HierarchyMapper<T,?>getHierarchyMapper()Returns theHierarchyMapperused by this data communicator.ItemCollapseAllowedProvider<T>getItemCollapseAllowedProvider()Gets the item collapse allowed provider.IntegergetParentIndex(T item)Returns parent index for the row or a negative value.protected HierarchicalDataCommunicatorStategetState()Returns the shared state for this connector.protected HierarchicalDataCommunicatorStategetState(boolean markAsDirty)Returns the shared state for this connector.booleanhasChildren(T item)Returns whether given item has children.booleanisExpanded(T item)Returns whether given item is expanded.protected voidonDropRows(elemental.json.JsonArray keys)Triggered when rows have been dropped from the client side cache.protected voidsendDataToClient(boolean initial)Send the needed data and updates to the client side.voidsetBackEndSorting(List<QuerySortOrder> sortOrder)Sets theQuerySortOrders to use with backend sorting.voidsetBackEndSorting(List<QuerySortOrder> sortOrder, boolean immediateReset)Sets theQuerySortOrders 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> voidsetFilter(F filter)Sets the filter for this DataCommunicator.voidsetInMemorySorting(Comparator<T> comparator)Sets theComparatorto use with in-memory sorting.voidsetInMemorySorting(Comparator<T> comparator, boolean immediateReset)Sets theComparatorto use with in-memory sorting.voidsetItemCollapseAllowedProvider(ItemCollapseAllowedProvider<T> provider)Sets the item collapse allowed provider for this HierarchicalDataCommunicator.-
Methods inherited from class com.vaadin.data.provider.DataCommunicator
addDataGenerator, attach, beforeClientResponse, createKeyMapper, createRpc, detach, dropAllData, getActiveDataHandler, getBackEndSorting, getClientRpc, getDataObject, getFilter, getInMemorySorting, getKeyMapper, getMaximumAllowedRows, getMinPushSize, getPushRows, getUpdatedData, onRequestRows, pushData, refresh, removeDataGenerator, reset, setDataProvider, setMaximumAllowedRows, setMinPushSize, setPushRows
-
Methods inherited from class com.vaadin.server.AbstractExtension
extend, getParent, getSupportedParentType, remove, setParent
-
Methods inherited from class com.vaadin.server.AbstractClientConnector
addAttachListener, addDetachListener, addExtension, addListener, addListener, addListener, addListener, addListener, addListener, addMethodInvocationToQueue, createState, encodeState, equals, fireEvent, getAllChildrenIterable, getConnectorId, getErrorHandler, getExtensions, getListeners, getResource, getRpcManager, getRpcProxy, getSession, getStateType, getUI, handleConnectorRequest, hashCode, hasListeners, isAttached, isConnectorEnabled, isThis, markAsDirty, markAsDirtyRecursive, registerRpc, registerRpc, removeAttachListener, removeDetachListener, removeExtension, removeListener, removeListener, removeListener, removeListener, removeListener, requestRepaint, requestRepaintAll, retrievePendingRpcCalls, setErrorHandler, setResource, updateDiffstate
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.vaadin.server.ClientConnector
addAttachListener, addDetachListener, encodeState, getErrorHandler, getExtensions, getRpcManager, getStateType, getUI, handleConnectorRequest, isAttached, isConnectorEnabled, markAsDirty, markAsDirtyRecursive, removeAttachListener, removeDetachListener, removeExtension, requestRepaint, requestRepaintAll, retrievePendingRpcCalls, setErrorHandler
-
Methods inherited from interface com.vaadin.shared.Connector
getConnectorId
-
-
-
-
Constructor Detail
-
HierarchicalDataCommunicator
public HierarchicalDataCommunicator()
Construct a new hierarchical data communicator backed by aTreeDataProvider.
-
-
Method Detail
-
getState
protected HierarchicalDataCommunicatorState getState()
Description copied from class:AbstractClientConnectorReturns the shared state for this connector. The shared state object is shared between the server connector and the client connector. Changes are only communicated from the server to the client and not in the other direction.As a side effect, marks the connector dirty so any changes done to the state will be sent to the client. Use
getState(false)to avoid marking the connector as dirty.- Overrides:
getStatein classDataCommunicator<T>- Returns:
- The shared state for this connector. Never null.
-
getState
protected HierarchicalDataCommunicatorState getState(boolean markAsDirty)
Description copied from class:AbstractClientConnectorReturns the shared state for this connector.- Overrides:
getStatein classDataCommunicator<T>- Parameters:
markAsDirty- true if the connector should automatically be marked dirty, false otherwise- Returns:
- The shared state for this connector. Never null.
- See Also:
AbstractClientConnector.getState()
-
fetchItemsWithRange
public List<T> fetchItemsWithRange(int offset, int limit)
Description copied from class:DataCommunicatorFetches a list of items from the DataProvider.- Overrides:
fetchItemsWithRangein classDataCommunicator<T>- Parameters:
offset- the starting index of the rangelimit- the max number of results- Returns:
- the list of items in given range
-
getDataProvider
public HierarchicalDataProvider<T,?> getDataProvider()
Description copied from class:DataCommunicatorGets the current data provider from this DataCommunicator.- Overrides:
getDataProviderin 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 type- Parameters:
dataProvider- the data provider to set, notnullinitialFilter- the initial filter value to use, ornullto not use any initial filter value- Returns:
- a consumer that accepts a new filter value to use
-
createHierarchyMapper
protected <F> HierarchyMapper<T,F> createHierarchyMapper(HierarchicalDataProvider<T,F> dataProvider)
Create newHierarchyMapperfor the given data provider. May be overridden in subclasses.- Type Parameters:
F- Query type- Parameters:
dataProvider- the data provider- Returns:
- new
HierarchyMapper
-
setDataProvider
public <F> SerializableConsumer<F> setDataProvider(DataProvider<T,F> dataProvider, F initialFilter)
Set the current hierarchical data provider for this communicator.- Overrides:
setDataProviderin classDataCommunicator<T>- Type Parameters:
F- the filter type- Parameters:
dataProvider- the data provider to set, must extendHierarchicalDataProvider, notnullinitialFilter- the initial filter value to use, ornullto not use any initial filter value- Returns:
- a consumer that accepts a new filter value to use
-
sendDataToClient
protected void sendDataToClient(boolean initial)
Description copied from class:DataCommunicatorSend the needed data and updates to the client side.- Overrides:
sendDataToClientin classDataCommunicator<T>- Parameters:
initial-trueif initial data load,falseif not
-
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.- Parameters:
item- the item to collapse
-
collapse
public void collapse(T item, boolean syncAndRefresh)
Collapses the given item and removes its sub-hierarchy. Calling this method will have no effect if the row is already collapsed.syncAndRefreshindicates whether the changes should be synchronised to the client and the data provider be notified.- Parameters:
item- the item to collapsesyncAndRefresh-trueif the changes should be synchronised to the client and the data provider should be notified of the changes,falseotherwise.
-
collapse
public void collapse(T item, Integer index)
Collapses the given item and removes its sub-hierarchy. Calling this method will have no effect if the row is already collapsed.- Parameters:
item- the item to collapseindex- the index of the item
-
doCollapse
@Deprecated public void doCollapse(T item, Optional<Integer> index)
Deprecated.Usecollapse(Object, Integer)instead.Collapses given item and removes its sub-hierarchy. Calling this method will have no effect if the row is already collapsed. The index is provided by the client-side or calculated from a full data request.- Parameters:
item- the item to collapseindex- the index of the item
-
onDropRows
protected void onDropRows(elemental.json.JsonArray keys)
Description copied from class:DataCommunicatorTriggered when rows have been dropped from the client side cache.- Overrides:
onDropRowsin classDataCommunicator<T>- Parameters:
keys- the keys of the rows that have been dropped
-
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.- Parameters:
item- the item to expand
-
expand
public void expand(T item, boolean syncAndRefresh)
Expands the given item. Calling this method will have no effect if the item is already expanded or if it has no children.syncAndRefreshindicates whether the changes should be synchronised to the client and the data provider be notified.- Parameters:
item- the item to expandsyncAndRefresh-trueif the changes should be synchronised to the client and the data provider should be notified of the changes,falseotherwise.
-
expand
public void expand(T item, Integer index)
Expands the given item at the given index. Calling this method will have no effect if the item is already expanded.- Parameters:
item- the item to expandindex- the index of the item
-
doExpand
@Deprecated public void doExpand(T item, Optional<Integer> index)
Deprecated.useexpand(Object, Integer)insteadExpands the given item at given index. Calling this method will have no effect if the row is already expanded. The index is provided by the client-side or calculated from a full data request.- Parameters:
item- the item to expandindex- the index of the item- See Also:
expand(Object)
-
hasChildren
public boolean hasChildren(T item)
Returns whether given item has children.- Parameters:
item- the item to test- Returns:
trueif item has children;falseif not
-
isExpanded
public boolean isExpanded(T item)
Returns whether given item is expanded.- Parameters:
item- the item to test- Returns:
trueif item is expanded;falseif not
-
setItemCollapseAllowedProvider
public void setItemCollapseAllowedProvider(ItemCollapseAllowedProvider<T> provider)
Sets the item collapse allowed provider for this HierarchicalDataCommunicator. The provider should returntruefor any item that the user can collapse.Note: This callback will be accessed often when sending data to the client. The callback should not do any costly operations.
- Parameters:
provider- the item collapse allowed provider, notnull
-
getParentIndex
public Integer getParentIndex(T item)
Returns parent index for the row or a negative value.- Parameters:
item- the item to find the parent of- Returns:
- the parent index or a negative value for top-level items
-
getItemCollapseAllowedProvider
public ItemCollapseAllowedProvider<T> getItemCollapseAllowedProvider()
Gets the item collapse allowed provider.- Returns:
- the item collapse allowed provider
-
getDataProviderSize
public int getDataProviderSize()
Description copied from class:DataCommunicatorGetter method for finding the size of DataProvider. Can be overridden by a subclass that uses a specific type of DataProvider and/or query.- Overrides:
getDataProviderSizein classDataCommunicator<T>- Returns:
- the size of data provider with current filter
-
setBackEndSorting
public void setBackEndSorting(List<QuerySortOrder> sortOrder, boolean immediateReset)
Description copied from class:DataCommunicatorSets theQuerySortOrders to use with backend sorting.- Overrides:
setBackEndSortingin classDataCommunicator<T>- Parameters:
sortOrder- list of sort order information to pass to a queryimmediateReset-trueif an internal reset should be performed immediately after updating the comparator (unless full reset is already pending),falseif you are going to trigger reset separately later
-
setBackEndSorting
public void setBackEndSorting(List<QuerySortOrder> sortOrder)
Description copied from class:DataCommunicatorSets theQuerySortOrders to use with backend sorting.- Overrides:
setBackEndSortingin classDataCommunicator<T>- Parameters:
sortOrder- list of sort order information to pass to a query
-
setInMemorySorting
public void setInMemorySorting(Comparator<T> comparator, boolean immediateReset)
Description copied from class:DataCommunicatorSets theComparatorto use with in-memory sorting.- Overrides:
setInMemorySortingin classDataCommunicator<T>- Parameters:
comparator- comparator used to sort dataimmediateReset-trueif an internal reset should be performed immediately after updating the comparator (unless full reset is already pending),falseif you are going to trigger reset separately later
-
setInMemorySorting
public void setInMemorySorting(Comparator<T> comparator)
Description copied from class:DataCommunicatorSets theComparatorto use with in-memory sorting.- Overrides:
setInMemorySortingin classDataCommunicator<T>- Parameters:
comparator- comparator used to sort data
-
setFilter
protected <F> void setFilter(F filter)
Description copied from class:DataCommunicatorSets the filter for this DataCommunicator. This method is used by user through the consumer method fromDataCommunicator.setDataProvider(com.vaadin.data.provider.DataProvider<T, F>, F)and should not be called elsewhere.- Overrides:
setFilterin classDataCommunicator<T>- Type Parameters:
F- the filter type- Parameters:
filter- the filter
-
getHierarchyMapper
protected HierarchyMapper<T,?> getHierarchyMapper()
Returns theHierarchyMapperused by this data communicator.- Returns:
- the hierarchy mapper used by this data communicator
-
-