T
- data typepublic abstract class AbstractDataView<T> extends Object implements DataView<T>
Modifier and Type | Field and Description |
---|---|
protected Component |
component |
protected SerializableSupplier<? extends DataProvider<T,?>> |
dataProviderSupplier |
protected static String |
NULL_IDENTIFIER_ERROR_MESSAGE |
protected static String |
NULL_ITEM_ERROR_MESSAGE |
Constructor and Description |
---|
AbstractDataView(SerializableSupplier<? extends DataProvider<T,?>> dataProviderSupplier,
Component component)
Creates a new instance of
AbstractDataView subclass and verifies
the passed data provider is compatible with this data view
implementation. |
Modifier and Type | Method and Description |
---|---|
Registration |
addItemCountChangeListener(ComponentEventListener<ItemCountChangeEvent<?>> listener)
Add an item count change listener that is fired when the item count
changes.
|
protected boolean |
equals(T item,
T compareTo) |
protected IdentifierProvider<T> |
getIdentifierProvider() |
Stream<T> |
getItems()
Get the full data available to the component.
|
protected abstract Class<?> |
getSupportedDataProviderType()
Returns supported
DataProvider type for this DataView . |
void |
refreshAll()
Notifies the component that all the items should be refreshed.
|
void |
refreshItem(T item)
Notifies the component that the item has been updated and thus should be
refreshed.
|
void |
setIdentifierProvider(IdentifierProvider<T> identifierProvider)
Sets an identifier provider, which returns an identifier for the given
item.
|
protected void |
verifyDataProviderType(Class<?> dataProviderType)
Verifies an obtained
DataProvider type is appropriate for current
Data View type. |
protected static final String NULL_ITEM_ERROR_MESSAGE
protected static final String NULL_IDENTIFIER_ERROR_MESSAGE
protected SerializableSupplier<? extends DataProvider<T,?>> dataProviderSupplier
protected Component component
public AbstractDataView(SerializableSupplier<? extends DataProvider<T,?>> dataProviderSupplier, Component component)
AbstractDataView
subclass and verifies
the passed data provider is compatible with this data view
implementation.dataProviderSupplier
- supplier from which the DataProvider can be gottencomponent
- the component that the dataView is bound topublic Registration addItemCountChangeListener(ComponentEventListener<ItemCountChangeEvent<?>> listener)
DataView
Item count change listener is bound to the component and will be retained
even if the data changes by setting of a new items or
DataProvider
to component.
NOTE: when the component supports lazy loading (implements
HasLazyDataView
) and a count callback has not been provided, an
estimate of the item count is used and increased until the actual count
has been reached. When the estimate is used, the event is fired with the
ItemCountChangeEvent.isItemCountEstimated()
returning
true
.
addItemCountChangeListener
in interface DataView<T>
listener
- item count change listener to registerprotected abstract Class<?> getSupportedDataProviderType()
DataProvider
type for this DataView
.protected final void verifyDataProviderType(Class<?> dataProviderType)
DataProvider
type is appropriate for current
Data View type.dataProviderType
- data provider type to be verifiedIllegalStateException
- if data provider type is incompatible with data view typepublic Stream<T> getItems()
DataView
public void refreshItem(T item)
DataView
For this to work properly, the item must either implement
Object.equals(Object)
and Object.hashCode()
to consider
both the old and the new item instances to be equal, or alternatively use
the DataView.setIdentifierProvider(IdentifierProvider)
to set an
appropriate item's identifier.
This method delegates the update to
DataProvider.refreshItem(Object)
.
refreshItem
in interface DataView<T>
item
- item containing updated stateDataView.setIdentifierProvider(IdentifierProvider)
public void refreshAll()
DataView
refreshAll
in interface DataView<T>
public void setIdentifierProvider(IdentifierProvider<T> identifierProvider)
DataView
dataView.setIdentifiedProvider(Item::getId);
.setIdentifierProvider
in interface DataView<T>
identifierProvider
- function that returns the non-null identifier for a given itemprotected IdentifierProvider<T> getIdentifierProvider()
Copyright © 2024. All rights reserved.