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 typeAll Implemented Interfaces:
MethodEventSource
,ClientConnector
,Extension
,Connector
,Serializable
public class HierarchicalDataCommunicator<T> extends DataCommunicator<T>
Data communicator that handles requesting hierarchical data from
HierarchicalDataProvider
and sending it to client side.Since:
8.1
Author:
Vaadin Ltd
See Also:
-
-
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 a
TreeDataProvider
.
-
Method Summary
All Methods Modifier and Type Method Description void
collapse(T item)
Collapses the given item and removes its sub-hierarchy.
void
collapse(T item, boolean syncAndRefresh)
Collapses the given item and removes its sub-hierarchy.
void
collapse(T item, Integer index)
Collapses the given item and removes its sub-hierarchy.
protected <F> HierarchyMapper<T,F>
createHierarchyMapper(HierarchicalDataProvider<T,F> dataProvider)
Create new
HierarchyMapper
for the given data provider.void
doCollapse(T item, Optional<Integer> index)
Deprecated.
Usecollapse(Object, Integer)
instead.void
doExpand(T item, Optional<Integer> index)
Deprecated.
useexpand(Object, Integer)
insteadvoid
expand(T item)
Expands the given item.
void
expand(T item, boolean syncAndRefresh)
Expands the given item.
void
expand(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.
int
getDataProviderSize()
Getter method for finding the size of DataProvider.
protected HierarchyMapper<T,?>
getHierarchyMapper()
Returns the
HierarchyMapper
used by this data communicator.ItemCollapseAllowedProvider<T>
getItemCollapseAllowedProvider()
Gets the item collapse allowed provider.
Integer
getParentIndex(T item)
Returns parent index for the row or a negative value.
protected HierarchicalDataCommunicatorState
getState()
Returns the shared state for this connector.
protected HierarchicalDataCommunicatorState
getState(boolean markAsDirty)
Returns the shared state for this connector.
boolean
hasChildren(T item)
Returns whether given item has children.
boolean
isExpanded(T item)
Returns whether given item is expanded.
protected void
onDropRows(elemental.json.JsonArray keys)
Triggered when rows have been dropped from the client side cache.
protected void
sendDataToClient(boolean initial)
Send the needed data and updates to the client side.
void
setBackEndSorting(List<QuerySortOrder> sortOrder)
Sets the
QuerySortOrder
s to use with backend sorting.void
setBackEndSorting(List<QuerySortOrder> sortOrder, boolean immediateReset)
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)
Sets the filter for this DataCommunicator.
void
setInMemorySorting(Comparator<T> comparator)
Sets the
Comparator
to use with in-memory sorting.void
setInMemorySorting(Comparator<T> comparator, boolean immediateReset)
Sets the
Comparator
to use with in-memory sorting.void
setItemCollapseAllowedProvider(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 a
TreeDataProvider
.
-
-
Method Detail
-
getState
protected HierarchicalDataCommunicatorState getState()
Description copied from class:
AbstractClientConnector
Returns 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:
getState
in classDataCommunicator<T>
Returns:
The shared state for this connector. Never null.
-
getState
protected HierarchicalDataCommunicatorState getState(boolean markAsDirty)
Description copied from class:
AbstractClientConnector
Returns the shared state for this connector.
Overrides:
getState
in classDataCommunicator<T>
Parameters:
markAsDirty
- true if the connector should automatically be marked dirty, false otherwiseReturns:
The shared state for this connector. Never null.
See Also:
-
fetchItemsWithRange
public List<T> fetchItemsWithRange(int offset, int limit)
Description copied from class:
DataCommunicator
Fetches a list of items from the DataProvider.
Overrides:
fetchItemsWithRange
in classDataCommunicator<T>
Parameters:
offset
- the starting index of the rangelimit
- the max number of resultsReturns:
the list of items in given range
-
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
-
sendDataToClient
protected void sendDataToClient(boolean initial)
Description copied from class:
DataCommunicator
Send the needed data and updates to the client side.
Overrides:
sendDataToClient
in classDataCommunicator<T>
Parameters:
initial
-true
if initial data load,false
if 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.
syncAndRefresh
indicates whether the changes should be synchronised to the client and the data provider be notified.Parameters:
item
- the item to collapsesyncAndRefresh
-true
if the changes should be synchronised to the client and the data provider should be notified of the changes,false
otherwise.
-
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:
DataCommunicator
Triggered when rows have been dropped from the client side cache.
Overrides:
onDropRows
in 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.
syncAndRefresh
indicates whether the changes should be synchronised to the client and the data provider be notified.Parameters:
item
- the item to expandsyncAndRefresh
-true
if the changes should be synchronised to the client and the data provider should be notified of the changes,false
otherwise.
-
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 itemSee Also:
-
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
-
setItemCollapseAllowedProvider
public void setItemCollapseAllowedProvider(ItemCollapseAllowedProvider<T> provider)
Sets the item collapse allowed provider for this HierarchicalDataCommunicator. The provider should return
true
for 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 ofReturns:
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:
DataCommunicator
Getter method for finding the size of DataProvider. 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, boolean immediateReset)
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 queryimmediateReset
-true
if an internal reset should be performed immediately after updating the comparator (unless full reset is already pending),false
if you are going to trigger reset separately later
-
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(Comparator<T> comparator, boolean immediateReset)
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 dataimmediateReset
-true
if an internal reset should be performed immediately after updating the comparator (unless full reset is already pending),false
if you are going to trigger reset separately later
-
setInMemorySorting
public void setInMemorySorting(Comparator<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)
Description copied from class:
DataCommunicator
Sets the filter for this DataCommunicator. This method is used by user through the consumer method from
DataCommunicator.setDataProvider(com.vaadin.data.provider.DataProvider<T, F>, F)
and should not be called elsewhere.Overrides:
setFilter
in classDataCommunicator<T>
Type Parameters:
F
- the filter typeParameters:
filter
- the filter
-
getHierarchyMapper
protected HierarchyMapper<T,?> getHierarchyMapper()
Returns the
HierarchyMapper
used by this data communicator.Returns:
the hierarchy mapper used by this data communicator
-
-