T
- the bean typepublic class DataCommunicator<T> extends AbstractExtension
DataGenerator
s to write
JsonObject
s representing each data object to be sent to the
client-side.Modifier and Type | Class and Description |
---|---|
protected class |
DataCommunicator.ActiveDataHandler
A class for handling currently active data and dropping data that is no
longer needed.
|
protected class |
DataCommunicator.SimpleDataRequestRpc
Simple implementation of collection data provider communication.
|
ClientConnector.AttachEvent, ClientConnector.AttachListener, ClientConnector.ConnectorErrorEvent, ClientConnector.DetachEvent, ClientConnector.DetachListener
Modifier and Type | Field and Description |
---|---|
protected boolean |
reset
Boolean for pending hard reset.
|
Constructor and Description |
---|
DataCommunicator() |
Modifier and Type | Method and Description |
---|---|
void |
addDataGenerator(DataGenerator<T> generator)
Adds a data generator to this data communicator.
|
void |
attach()
Notifies the connector that it is connected to a VaadinSession (and
therefore also to a UI).
|
void |
beforeClientResponse(boolean initial)
Initially and in the case of a reset all data should be pushed to the
client.
|
protected DataKeyMapper<T> |
createKeyMapper(ValueProvider<T,Object> identifierGetter)
Creates a
DataKeyMapper to use with this DataCommunicator. |
protected DataRequestRpc |
createRpc()
Creates a
DataRequestRpc used with this DataCommunicator . |
void |
detach()
Notifies the connector that it is detached from its VaadinSession.
|
protected void |
dropAllData()
Drops all data associated with this data communicator.
|
List<T> |
fetchItemsWithRange(int offset,
int limit)
Fetches a list of items from the DataProvider.
|
protected DataCommunicator.ActiveDataHandler |
getActiveDataHandler()
Returns the active data handler.
|
List<QuerySortOrder> |
getBackEndSorting()
Returns the
QuerySortOrder to use with backend sorting. |
protected DataCommunicatorClientRpc |
getClientRpc()
Get the client rpc interface for this data communicator.
|
protected JsonObject |
getDataObject(T data)
Creates the JsonObject for given data object.
|
DataProvider<T,?> |
getDataProvider()
Gets the current data provider from this DataCommunicator.
|
int |
getDataProviderSize()
Getter method for finding the size of DataProvider.
|
protected Object |
getFilter()
Get the object used for filtering in this data communicator.
|
Comparator<T> |
getInMemorySorting()
Returns the
Comparator to use with in-memory sorting. |
DataKeyMapper<T> |
getKeyMapper()
Gets the
DataKeyMapper used by this DataCommunicator . |
int |
getMinPushSize()
Get minimum size of data which will be sent to the client when data
source is set.
|
protected Range |
getPushRows()
Get the current range of rows to push in the next response.
|
protected DataCommunicatorState |
getState()
Returns the shared state for this connector.
|
protected DataCommunicatorState |
getState(boolean markAsDirty)
Returns the shared state for this connector.
|
protected Set<T> |
getUpdatedData()
Returns the currently set updated data.
|
protected void |
onDropRows(JsonArray keys)
Triggered when rows have been dropped from the client side cache.
|
protected void |
onRequestRows(int firstRowIndex,
int numberOfRows,
int firstCachedRowIndex,
int cacheSize)
Request the given rows to be available on the client side.
|
protected void |
pushData(int firstIndex,
List<T> data)
Sends given collection of data objects to the client-side.
|
void |
refresh(T data)
Informs the DataProvider that a data object has been updated.
|
void |
removeDataGenerator(DataGenerator<T> generator)
Removes a data generator from this data communicator.
|
void |
reset()
Method for internal reset from a change in the component, requiring a
full data update.
|
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. |
protected void |
setDataProvider(DataProvider<T,?> dataProvider)
Sets a new
DataProvider and refreshes all the internal
structures. |
<F> SerializableConsumer<F> |
setDataProvider(DataProvider<T,F> dataProvider,
F initialFilter)
Sets the current data provider for this DataCommunicator.
|
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 |
setMinPushSize(int size)
Set minimum size of data which will be sent to the client when data
source is set.
|
protected void |
setPushRows(Range pushRows)
Set the range of rows to push for next response.
|
extend, getParent, getSupportedParentType, remove, setParent
addAttachListener, addDetachListener, addExtension, 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, requestRepaint, requestRepaintAll, retrievePendingRpcCalls, setErrorHandler, setResource, updateDiffstate
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
addAttachListener, addDetachListener, encodeState, getErrorHandler, getExtensions, getRpcManager, getStateType, getUI, handleConnectorRequest, isAttached, isConnectorEnabled, markAsDirty, markAsDirtyRecursive, removeAttachListener, removeDetachListener, removeExtension, requestRepaint, requestRepaintAll, retrievePendingRpcCalls, setErrorHandler
getConnectorId
public void attach()
ClientConnector
The caller of this method is Connector#setParent(ClientConnector)
if the parent is itself already attached to the session. If not, the
parent will call the ClientConnector.attach()
for all its children when it is
attached to the session. This method is always called before the
connector's data is sent to the client-side for the first time.
The attachment logic is implemented in AbstractClientConnector
.
attach
in interface ClientConnector
attach
in class AbstractClientConnector
public void detach()
AbstractClientConnector
The caller of this method is #setParent(ClientConnector)
if the
parent is in the session. When the parent is detached from the session it
is its responsibility to call ClientConnector.detach()
for each of its children.
The AbstractClientConnector.getSession()
and AbstractClientConnector.getUI()
methods might return
null
after this method is called.
detach
in interface ClientConnector
detach
in class AbstractClientConnector
protected void setPushRows(Range pushRows)
pushRows
- protected Range getPushRows()
protected Object getFilter()
protected DataCommunicatorClientRpc getClientRpc()
protected void onRequestRows(int firstRowIndex, int numberOfRows, int firstCachedRowIndex, int cacheSize)
firstRowIndex
- the index of the first requested rownumberOfRows
- the number of requested rowsfirstCachedRowIndex
- the index of the first cached rowcacheSize
- the number of cached rowsprotected void onDropRows(JsonArray keys)
keys
- the keys of the rows that have been droppedpublic void beforeClientResponse(boolean initial)
beforeClientResponse
in interface ClientConnector
beforeClientResponse
in class AbstractClientConnector
initial
- true
if the client-side connector will be created
and initialized after this method has been invoked.
false
if there is already an initialized
client-side connector.protected void sendDataToClient(boolean initial)
initial
- true
if initial data load, false
if notpublic List<T> fetchItemsWithRange(int offset, int limit)
offset
- the starting index of the rangelimit
- the max number of resultspublic void addDataGenerator(DataGenerator<T> generator)
generator
- the data generator to add, not nullpublic void removeDataGenerator(DataGenerator<T> generator)
generator
- the data generator to remove, not nullpublic DataKeyMapper<T> getKeyMapper()
DataKeyMapper
used by this DataCommunicator
. Key
mapper can be used to map keys sent to the client-side back to their
respective data objects.protected void pushData(int firstIndex, List<T> data)
firstIndex
- first index of pushed datadata
- data objects to send as an iterableprotected JsonObject getDataObject(T data)
data
- data object to be made into a json objectprotected DataCommunicator.ActiveDataHandler getActiveDataHandler()
protected void dropAllData()
public void reset()
public void refresh(T data)
data
- updated data object; not null
protected Set<T> getUpdatedData()
public void setInMemorySorting(Comparator<T> comparator)
Comparator
to use with in-memory sorting.comparator
- comparator used to sort datapublic Comparator<T> getInMemorySorting()
Comparator
to use with in-memory sorting.public void setBackEndSorting(List<QuerySortOrder> sortOrder)
QuerySortOrder
s to use with backend sorting.sortOrder
- list of sort order information to pass to a querypublic List<QuerySortOrder> getBackEndSorting()
QuerySortOrder
to use with backend sorting.protected DataKeyMapper<T> createKeyMapper(ValueProvider<T,Object> identifierGetter)
DataKeyMapper
to use with this DataCommunicator.
This method is called from the constructor.
identifierGetter
- has to return a unique key for every bean, and the returned
key has to follow general hashCode()
and
equals()
contract, see Object.hashCode()
for
details.protected DataRequestRpc createRpc()
DataRequestRpc
used with this DataCommunicator
.
This method is called from the constructor.
public DataProvider<T,?> getDataProvider()
public <F> SerializableConsumer<F> setDataProvider(DataProvider<T,F> dataProvider, F initialFilter)
The returned consumer can be used to set some other filter value that should be included in queries sent to the data provider. It is only valid until another data provider is set.
F
- the filter typedataProvider
- the data provider to set, not null
initialFilter
- the initial filter value to use, or null
to not
use any initial filter valueprotected <F> void setFilter(F filter)
setDataProvider(com.vaadin.data.provider.DataProvider<T, F>, F)
and should not
be called elsewhere.F
- the filter typefilter
- the filterpublic void setMinPushSize(int size)
Server doesn't send all data from data source to the client. It sends
some initial chunk of data (whose size is determined as minimum between
size
parameter of this method and data size). Client decides
whether it is able to show more data and request server to send more data
(next chunk).
When component is disabled then client cannot communicate to the server side (by design, because of security reasons). It means that client will get only initial chunk of data whose size is set here.
size
- the size of initial data to send to the clientpublic int getMinPushSize()
setMinPushSize(int)
public int getDataProviderSize()
protected DataCommunicatorState getState(boolean markAsDirty)
AbstractClientConnector
getState
in class AbstractClientConnector
markAsDirty
- true if the connector should automatically be marked dirty,
false otherwiseAbstractClientConnector.getState()
protected DataCommunicatorState getState()
AbstractClientConnector
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.
getState
in class AbstractClientConnector
protected void setDataProvider(DataProvider<T,?> dataProvider)
DataProvider
and refreshes all the internal
structures.dataProvider
- Copyright © 2018 Vaadin Ltd. All rights reserved.