M
- the model typepublic abstract class Store<M> extends Object implements StoreHandlers.HasStoreHandlers<M>
Modifier and Type | Class and Description |
---|---|
static interface |
Store.Change<M,V>
Represents a change that can occur to a given model.
|
static class |
Store.PropertyChange<M,V>
ValueProvider-based change impl - takes a ValueProvider and the new value
to be changed.
|
class |
Store.Record
Records wrap model instances and provide specialized editing features,
including modification tracking and editing capabilities.
|
static interface |
Store.StoreFilter<M>
Defines the interface for store filters.
|
static class |
Store.StoreSortInfo<M>
Sort information for a Store to use.
|
Constructor and Description |
---|
Store(ModelKeyProvider<? super M> keyProvider)
Creates a store with the given key provider.
|
Modifier and Type | Method and Description |
---|---|
void |
addFilter(Store.StoreFilter<M> filter)
Adds the filter to the end of the store's set of filters.
|
void |
addSortInfo(int index,
Store.StoreSortInfo<M> info)
Adds the sort info at the specified index.
|
void |
addSortInfo(Store.StoreSortInfo<M> info)
Adds the specified sort info to the store.
|
HandlerRegistration |
addStoreAddHandler(StoreAddEvent.StoreAddHandler<M> handler)
Adds a
StoreAddEvent handler. |
HandlerRegistration |
addStoreClearHandler(StoreClearEvent.StoreClearHandler<M> handler)
Adds a
StoreClearEvent handler. |
HandlerRegistration |
addStoreDataChangeHandler(StoreDataChangeEvent.StoreDataChangeHandler<M> handler)
Adds a
StoreDataChangeEvent handler. |
HandlerRegistration |
addStoreFilterHandler(StoreFilterEvent.StoreFilterHandler<M> handler)
Adds a
StoreFilterEvent handler. |
HandlerRegistration |
addStoreHandlers(StoreHandlers<M> handlers)
Adds a common store event handler.
|
HandlerRegistration |
addStoreRecordChangeHandler(StoreRecordChangeEvent.StoreRecordChangeHandler<M> handler)
Adds a
StoreRecordChangeEvent handler. |
HandlerRegistration |
addStoreRemoveHandler(StoreRemoveEvent.StoreRemoveHandler<M> handler)
Adds a
StoreRemoveEvent handler. |
HandlerRegistration |
addStoreSortHandler(StoreSortEvent.StoreSortHandler<M> handler)
Adds a
StoreSortEvent handler. |
HandlerRegistration |
addStoreUpdateHandler(StoreUpdateEvent.StoreUpdateHandler<M> handler)
Adds a
StoreUpdateEvent handler. |
protected abstract void |
applyFilters()
Sets the filters to run again, whether they need it or not.
|
abstract void |
applySort(boolean suppressEvent)
Tells the store to re-apply sort settings and to fire an event when
complete.
|
protected Comparator<M> |
buildFullComparator()
Creates a new master
Comparator that runs all the
Store.StoreSortInfo comparators in sequence, returning the value of the
first comparator that returns a non-zero value, or zero if no comparator
returns a non-zero value. |
protected void |
clear()
Removes all items from the store.
|
void |
clearSortInfo()
Removes all of the sort info from the store, so subsequent calls to
applySort will not change the order.
|
void |
commitChanges()
Commits the outstanding changes.
|
protected HandlerManager |
ensureHandlers()
Ensures the store's handler manager exists, creating it if necessary (lazy
construction).
|
M |
findModel(M model)
Finds the matching model using the store's key provider.
|
abstract M |
findModelWithKey(String key)
Finds the model with the given key, using
ModelKeyProvider as
necessary. |
void |
fireEvent(<any> event) |
abstract List<M> |
getAll()
Returns a list of all items contained in the store.
|
LinkedHashSet<Store.StoreFilter<M>> |
getFilters()
Returns the stores filters.
|
ModelKeyProvider<? super M> |
getKeyProvider()
Returns the stores model key provider.
|
Collection<Store.Record> |
getModifiedRecords()
Returns a list of records that have been changed and not committed.
|
Store.Record |
getRecord(M data)
Gets the current Record instance for the given item.
|
List<Store.StoreSortInfo<M>> |
getSortInfo()
Gets the list of sort info objects.
|
boolean |
hasMatchingKey(M model1,
M model2)
Returns true if the two models have the same key.
|
boolean |
hasRecord(M data)
Returns true if a record exists for the given model.
|
boolean |
isAutoCommit()
Returns true if auto commit is enabled.
|
boolean |
isEnableFilters()
Returns true if filtering is enabled, whether or not filters are present.
|
boolean |
isFiltered()
Returns true if filtering is enabled AND the store has filters.
|
protected boolean |
isSorted()
Returns true if the store is sorted (
Store.StoreSortInfo has been added
and not cleared). |
void |
rejectChanges()
Cancel outstanding changes on all changed records.
|
protected boolean |
remove(M model)
Cleans up any reference the Store might've had to the model.
|
void |
removeFilter(Store.StoreFilter<M> filter)
Removes the filter from the store's set of filters.
|
void |
removeFilters()
Removes all filters.
|
void |
setAutoCommit(boolean isAutoCommit)
Enables or disables auto commit.
|
void |
setEnableFilters(boolean enableFilters)
Enables or disables the filters.
|
abstract void |
update(M item)
Replaces the item that matches the key of the given item, and fires a
StoreUpdateEvent to indicate that
this change has occurred. |
<V> ValueProvider<? super M,V> |
wrapRecordValueProvider(ValueProvider<? super M,V> valueProvider)
Returns a ValueProvider that will read and write to the corresponding Record object if
necessary instead of the model itself.
|
public Store(ModelKeyProvider<? super M> keyProvider)
keyProvider
- the key provider, responsible for returning a unique key
for a given modelpublic void addFilter(Store.StoreFilter<M> filter)
filter
- the filter to addpublic void addSortInfo(int index, Store.StoreSortInfo<M> info)
index
- the sort indexinfo
- the sort infopublic void addSortInfo(Store.StoreSortInfo<M> info)
info
- the sort infopublic HandlerRegistration addStoreAddHandler(StoreAddEvent.StoreAddHandler<M> handler)
StoreAddEvent.HasStoreAddHandlers
StoreAddEvent
handler.addStoreAddHandler
in interface StoreAddEvent.HasStoreAddHandlers<M>
handler
- the handlerpublic HandlerRegistration addStoreClearHandler(StoreClearEvent.StoreClearHandler<M> handler)
StoreClearEvent.HasStoreClearHandler
StoreClearEvent
handler.addStoreClearHandler
in interface StoreClearEvent.HasStoreClearHandler<M>
handler
- the handlerpublic HandlerRegistration addStoreDataChangeHandler(StoreDataChangeEvent.StoreDataChangeHandler<M> handler)
StoreDataChangeEvent.HasStoreDataChangeHandlers
StoreDataChangeEvent
handler.addStoreDataChangeHandler
in interface StoreDataChangeEvent.HasStoreDataChangeHandlers<M>
handler
- the handlerpublic HandlerRegistration addStoreFilterHandler(StoreFilterEvent.StoreFilterHandler<M> handler)
StoreFilterEvent.HasStoreFilterHandlers
StoreFilterEvent
handler.addStoreFilterHandler
in interface StoreFilterEvent.HasStoreFilterHandlers<M>
handler
- the handlerpublic HandlerRegistration addStoreHandlers(StoreHandlers<M> handlers)
StoreHandlers.HasStoreHandlers
addStoreHandlers
in interface StoreHandlers.HasStoreHandlers<M>
handlers
- the handlerspublic HandlerRegistration addStoreRecordChangeHandler(StoreRecordChangeEvent.StoreRecordChangeHandler<M> handler)
StoreRecordChangeEvent.HasStoreRecordChangeHandlers
StoreRecordChangeEvent
handler.addStoreRecordChangeHandler
in interface StoreRecordChangeEvent.HasStoreRecordChangeHandlers<M>
handler
- the handlerpublic HandlerRegistration addStoreRemoveHandler(StoreRemoveEvent.StoreRemoveHandler<M> handler)
StoreRemoveEvent.HasStoreRemoveHandler
StoreRemoveEvent
handler.addStoreRemoveHandler
in interface StoreRemoveEvent.HasStoreRemoveHandler<M>
handler
- the handlerpublic HandlerRegistration addStoreSortHandler(StoreSortEvent.StoreSortHandler<M> handler)
StoreSortEvent.HasStoreSortHandler
StoreSortEvent
handler.addStoreSortHandler
in interface StoreSortEvent.HasStoreSortHandler<M>
handler
- the handlerpublic HandlerRegistration addStoreUpdateHandler(StoreUpdateEvent.StoreUpdateHandler<M> handler)
StoreUpdateEvent.HasStoreUpdateHandlers
StoreUpdateEvent
handler.addStoreUpdateHandler
in interface StoreUpdateEvent.HasStoreUpdateHandlers<M>
handler
- the handlerpublic abstract void applySort(boolean suppressEvent)
addSortInfo(StoreSortInfo)
,
addSortInfo(int, StoreSortInfo)
, and clearSortInfo()
.suppressEvent
- true to suppress event from firingpublic void clearSortInfo()
public void commitChanges()
public M findModel(M model)
model
- target modelpublic abstract M findModelWithKey(String key)
ModelKeyProvider
as
necessary.key
- the key of the model to findpublic void fireEvent(<any> event)
public abstract List<M> getAll()
public LinkedHashSet<Store.StoreFilter<M>> getFilters()
public ModelKeyProvider<? super M> getKeyProvider()
public Collection<Store.Record> getModifiedRecords()
public Store.Record getRecord(M data)
hasRecord(Object)
to check if you don't want to create a new one.data
- the data keypublic List<Store.StoreSortInfo<M>> getSortInfo()
applySort(boolean)
must be called. Note
that addSortInfo(StoreSortInfo)
and
addSortInfo(int, StoreSortInfo)
will add the new sort info the
this list, and then call applySort directly.public boolean hasMatchingKey(M model1, M model2)
model1
- the first modelmodel2
- the second modelpublic boolean hasRecord(M data)
data
- the modelpublic boolean isAutoCommit()
public boolean isEnableFilters()
public boolean isFiltered()
public void rejectChanges()
public void removeFilter(Store.StoreFilter<M> filter)
filter
- the filter to be removedpublic void removeFilters()
public void setAutoCommit(boolean isAutoCommit)
isAutoCommit
- true to enable auto commitStore.Record.addChange(ValueProvider, Object)
public void setEnableFilters(boolean enableFilters)
enableFilters
- true to enable filterspublic abstract void update(M item)
StoreUpdateEvent
to indicate that
this change has occurred. Any changes to the previous model via it's record instance will be lost and the record
will be removed.
This will not cause the sort or filter to be re-applied to the object.item
- the new item to take its place in the Store.protected abstract void applyFilters()
protected Comparator<M> buildFullComparator()
Comparator
that runs all the
Store.StoreSortInfo
comparators in sequence, returning the value of the
first comparator that returns a non-zero value, or zero if no comparator
returns a non-zero value.protected void clear()
protected HandlerManager ensureHandlers()
protected boolean isSorted()
Store.StoreSortInfo
has been added
and not cleared).protected boolean remove(M model)
Collection.remove(Object)
model
- the data model to removepublic <V> ValueProvider<? super M,V> wrapRecordValueProvider(ValueProvider<? super M,V> valueProvider)
V
- the value typevalueProvider
- an existing ValueProvider to wrapCopyright © 2018. All rights reserved.