T
- The type of the items to be selected.public class DefaultSelectionModel<T> extends Object implements ISelectionModel<T>, IEnumerable<T>
ISelectionModel
that is based on an observable collection to hold the selected
elements.
This selection model has a domain that's controlled with a predicate
which encompasses the
items that can be selected. If that domain changes it is important to delegate item removal events from the domain model
to this selection model to ensure that items that have been removed are deselected as well. A convenience event handler
exists for that purpose.
EMPTY
Constructor and Description |
---|
DefaultSelectionModel()
Creates a default selection model implementation that uses a
ObservableCollection to hold the selection. |
Modifier and Type | Method and Description |
---|---|
void |
addItemSelectionChangedListener(IEventHandler<ItemSelectionChangedEventArgs<T>> itemSelectionChangedEvent)
Adds the given listener for the
ItemSelectionChanged event that occurs when an item changed its selection state
from selected to unselected or vice versa. |
void |
clear()
Clears the selection.
|
IEnumerator<T> |
enumerator()
Returns an
IEnumerator over a set of elements of type T. |
Predicate<T> |
getIsInDomain()
Gets the predicate which determines whether the queried item should be considered for this selection model.
|
IObservableCollection<T> |
getSelection()
Provides an observable collection view over the selected items.
|
boolean |
isSelected(T item)
Determines whether an item is selected by checking for the containment in the
Selection . |
void |
itemRemovedFromDomainHandler(Object source,
ItemEventArgs<T> evt)
Event handler for domain item removal events that removes the item from this model.
|
protected void |
onItemSelectionChanged(T o,
boolean selected)
Called when an item gets selected or deselected.
|
void |
removeDomainItem(T item)
Removes the given
item from the selection in response to the item being removed from the domain. |
void |
removeItemSelectionChangedListener(IEventHandler<ItemSelectionChangedEventArgs<T>> itemSelectionChangedEvent)
Removes the given listener for the
ItemSelectionChanged event that occurs when an item changed its selection
state from selected to unselected or vice versa. |
void |
setIsInDomain(Predicate<T> value)
Sets the predicate which determines whether the queried item should be considered for this selection model.
|
void |
setSelected(T item,
boolean selected)
Sets the selection state of the item.
|
int |
size()
Returns the number of selected items.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
concat, concat, create, create, iterator, parallelStream, stream
forEach, spliterator
public DefaultSelectionModel()
ObservableCollection
to hold the selection.public final void addItemSelectionChangedListener(IEventHandler<ItemSelectionChangedEventArgs<T>> itemSelectionChangedEvent)
ISelectionModel
ItemSelectionChanged
event that occurs when an item changed its selection state
from selected to unselected or vice versa.addItemSelectionChangedListener
in interface ISelectionModel<T>
itemSelectionChangedEvent
- The listener to add.ISelectionModel.setSelected(java.lang.Object, boolean)
,
ISelectionModel.removeItemSelectionChangedListener(IEventHandler)
public void clear()
ISelectionModel
This is a convenience method that will set the selection state of all elements to unselected.
clear
in interface ISelectionModel<T>
ISelectionModel.addItemSelectionChangedListener(IEventHandler)
public final IEnumerator<T> enumerator()
IEnumerable
IEnumerator
over a set of elements of type T.enumerator
in interface IEnumerable<T>
IEnumerator
.public final Predicate<T> getIsInDomain()
setIsInDomain(Predicate)
public final IObservableCollection<T> getSelection()
public boolean isSelected(T item)
Selection
.isSelected
in interface ISelectionModel<T>
item
- The item to checkpublic final void itemRemovedFromDomainHandler(Object source, ItemEventArgs<T> evt)
This method is intended to be used to delegate item removal events from the respective domain collection:
This method calls removeDomainItem(Object)
with Item
.
source
- The instance that raised the event.evt
- The event arguments.protected void onItemSelectionChanged(T o, boolean selected)
Triggers the ItemSelectionChanged
event.
o
- The item.selected
- Whether or not the item is selected after the change.public void removeDomainItem(T item)
item
from the selection in response to the item being removed from the domain.item
- The item to remove from the considered items.public final void removeItemSelectionChangedListener(IEventHandler<ItemSelectionChangedEventArgs<T>> itemSelectionChangedEvent)
ISelectionModel
ItemSelectionChanged
event that occurs when an item changed its selection
state from selected to unselected or vice versa.removeItemSelectionChangedListener
in interface ISelectionModel<T>
itemSelectionChangedEvent
- The listener to remove.ISelectionModel.setSelected(java.lang.Object, boolean)
,
ISelectionModel.addItemSelectionChangedListener(IEventHandler)
public final void setIsInDomain(Predicate<T> value)
value
- The IsInDomain to set.getIsInDomain()
public void setSelected(T item, boolean selected)
setSelected
in interface ISelectionModel<T>
item
- The item to set the selection state for.selected
- Whether to select the object.public int size()
ISelectionModel
size
in interface ISelectionModel<T>