public class EntityList<T extends Entity> extends Entity implements Iterable<T>
Encapsulates a list of entities. This list is observable, as it will fire EntityList.EntityListEvent
events when items are added
and removed from this list.
Modifier and Type | Class and Description |
---|---|
static class |
EntityList.EntityAddedEvent
Event fired after an item is added to the list.
|
static class |
EntityList.EntityEvent |
static class |
EntityList.EntityListEvent |
static class |
EntityList.EntityListInvalidatedEvent
An event that is fired when the statue of the list has changed in ways
that cannot be synchronized using Add/Remove events.
|
static class |
EntityList.EntityRemovedEvent
Event fired after an item is removed from the list.
|
static class |
EntityList.TransactionEvent
An event to encapsulate transactions on a list.
|
static class |
EntityList.VetoableEntityAddedEvent
Event fired before an item is added to the list.
|
static class |
EntityList.VetoableEntityEvent
A type of entity event which is fired before the add/remove occurs, and allows
the listener to veto/cancel the add/remove.
|
static class |
EntityList.VetoableEntityRemovedEvent
Event fired before an item is removed from the list.
|
static class |
EntityList.VetoException
Exception thrown if a veto listener vetos and add/remove.
|
Constructor and Description |
---|
EntityList() |
EntityList(EntityType rowType,
int maxLen) |
EntityList(EntityType rowType,
int maxLen,
List<T> internalList) |
EntityList(int maxLen) |
Modifier and Type | Method and Description |
---|---|
void |
add(T link)
Adds an item to the list.
|
void |
addActionListener(ActionListener<EntityList.EntityListEvent> l)
Add listener to be notified of events on this list.
|
protected T |
beforeAdd(T link) |
protected T |
beforeRemove(T link) |
void |
clear()
Removes all items from the list.
|
void |
commitTransaction()
Commits a transaction, and notifies listeners that the transaction is complete.
|
protected List<T> |
createInternalList()
Can be overridden by subclasses to create an alternate collection type
for the entity list.
|
protected void |
fireEntityAdded(Entity e,
int index)
Fires
EntityList.EntityAddedEvent event to listeners. |
protected void |
fireEntityRemoved(Entity e,
int index)
Fires
EntityList.EntityRemovedEvent to listeners. |
protected void |
fireTransactionEvent(EntityList.TransactionEvent evt) |
T |
get(int index)
Gets item at index.
|
EntityType |
getRowType() |
int |
indexOf(T item)
Gets the current index of in the list of the given item.
|
void |
invalidate()
Triggers an
EntityList.EntityListInvalidatedEvent to listeners to instruct
them that the list has changed in ways that cannot be reconstructed by
the typical Add/Remove events, and that views should resynchronize their
state with the list. |
Iterator<T> |
iterator() |
boolean |
remove(T link)
Removes an item from the list.
|
void |
removeActionListener(ActionListener<EntityList.EntityListEvent> l)
Removes listener.
|
void |
setRowType(EntityType rowType) |
int |
size()
Returns the number of items in the list.
|
void |
startTransaction()
Starts a transaction to keep track of adds and removes so that listeners
can be notified in bulk.
|
add, addPropertyChangeListener, addPropertyChangeListener, addVetoablePropertyChangeListener, addVetoablePropertyChangeListener, clearChanged, createImageToFile, createImageToFile, createImageToFile, createImageToFile, createImageToFile, createImageToFile, createImageToFile, createImageToFile, createImageToStorage, createImageToStorage, createImageToStorage, createImageToStorage, createImageToStorage, createImageToStorage, createImageToStorage, createImageToStorage, entityTypeBuilder, findProperty, firePropertyChangeEvent, fireVetoablePropertyChangeEvent, get, get, get, getAggregate, getBoolean, getBoolean, getDate, getDate, getDouble, getDouble, getEntity, getEntity, getEntityList, getEntityList, getEntityListNonNull, getEntityNonNull, getEntityType, getInt, getInt, getLong, getLong, getText, getText, hasPropertyChangeListeners, hasVetoablePropertyChangeListeners, isEmpty, isEmpty, isEntity, isEntity, isFalsey, isFalsey, removePropertyChangeListener, removePropertyChangeListener, removeVetoablePropertyChangeListener, removeVetoablePropertyChangeListener, set, set, set, set, setBoolean, setBoolean, setBoolean, setChanged, setDate, setDate, setDate, setDouble, setDouble, setDouble, setEntity, setEntity, setEntity, setEntityType, setFloat, setFloat, setFloat, setInt, setInt, setInt, setLong, setLong, setLong, setText, setText, setText, toMap
addObserver, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers, setChanged
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
forEach, spliterator
public EntityList(int maxLen)
public EntityList(EntityType rowType, int maxLen)
public EntityList(EntityType rowType, int maxLen, List<T> internalList)
public EntityList()
public EntityType getRowType()
public void setRowType(EntityType rowType)
rowType
- the rowType to setpublic void startTransaction()
Starts a transaction to keep track of adds and removes so that listeners can be notified in bulk.
public void commitTransaction()
Commits a transaction, and notifies listeners that the transaction is complete.
protected void fireTransactionEvent(EntityList.TransactionEvent evt)
protected List<T> createInternalList()
Can be overridden by subclasses to create an alternate collection type for the entity list. Default implementation uses an ArrayList.
public void invalidate()
Triggers an EntityList.EntityListInvalidatedEvent
to listeners to instruct
them that the list has changed in ways that cannot be reconstructed by
the typical Add/Remove events, and that views should resynchronize their
state with the list.
This method should not be called inside a transaction.
IllegalStateException
- if called inside a transaction.public void add(T link)
Adds an item to the list. This will trigger a EntityList.VetoableEntityAddedEvent
before the add, and a
EntityList.EntityAddedEvent
after the add.
link
- public boolean remove(T link)
Removes an item from the list. This will trigger a EntityList.VetoableEntityRemovedEvent
before the removal,
and a EntityList.EntityRemovedEvent
after the removal.
link
- The item to addpublic void clear()
Removes all items from the list. This will fire EntityList.VetoableEntityRemovedEvent
and EntityList.EntityRemovedEvent
events
before/after each item is removed.
public int size()
Returns the number of items in the list.
public T get(int index)
Gets item at index.
index
- The index of the item to get.public int indexOf(T item)
Gets the current index of in the list of the given item.
protected void fireEntityAdded(Entity e, int index)
Fires EntityList.EntityAddedEvent
event to listeners.
e
- index
- protected void fireEntityRemoved(Entity e, int index)
Fires EntityList.EntityRemovedEvent
to listeners.
e
- index
- public void addActionListener(ActionListener<EntityList.EntityListEvent> l)
Add listener to be notified of events on this list. Listeners will be notified of the following event types:
EntityList.EntityAddedEvent
- After an item is added.
EntityList.EntityRemovedEvent
- After an item is removed.
EntityList.VetoableEntityAddedEvent
- Before an item is added.
EntityList.VetoableEntityRemovedEvent
- Before an item is removed.
EntityList.TransactionEvent
- On startTransaction()
and commitTransaction()
.
l
- removeActionListener(com.codename1.ui.events.ActionListener)
public void removeActionListener(ActionListener<EntityList.EntityListEvent> l)
Removes listener.
l
- addActionListener(com.codename1.ui.events.ActionListener)
Copyright © 2021. All Rights Reserved.