public class CollectionContainerImpl<E> extends InstanceContainerImpl<E> implements CollectionContainer<E>
CollectionContainer.CollectionChangeEvent<T>, CollectionContainer.UnmuteEventsMode
InstanceContainer.ItemChangeEvent<T>, InstanceContainer.ItemPropertyChangeEvent<T>
Modifier and Type | Field and Description |
---|---|
protected java.util.List<E> |
collection |
protected java.util.Map<IndexKey,java.lang.Integer> |
idMap |
protected io.jmix.core.MetadataTools |
metadataTools |
protected Sorter |
sorter |
entityMetaClass, events, fetchPlan, item, listener, listenersEnabled, loader, metadata
Constructor and Description |
---|
CollectionContainerImpl(io.jmix.core.metamodel.model.MetaClass metaClass) |
Modifier and Type | Method and Description |
---|---|
io.jmix.core.common.event.Subscription |
addCollectionChangeListener(java.util.function.Consumer<CollectionContainer.CollectionChangeEvent<E>> listener)
Adds listener to
CollectionContainer.CollectionChangeEvent . |
protected void |
addToCollection(E entity) |
protected void |
attachListener(java.util.Collection<E> entities) |
protected void |
buildIdMap() |
protected void |
clearItemIfNotExists() |
boolean |
containsItem(java.lang.Object entityOrId)
Returns true if the given entity exists in the container.
|
protected void |
detachListener(java.util.Collection<E> entities) |
protected void |
fireCollectionChanged(CollectionChangeType type,
java.util.Collection<? extends E> changes) |
E |
getItem(java.lang.Object entityId)
Returns entity by its id.
|
int |
getItemIndex(java.lang.Object entityOrId)
Returns the index in the items list of the given entity or -1 if there is no such entity.
|
E |
getItemOrNull(java.lang.Object entityId)
Returns entity by its id or null if the container doesn't have an entity with the given id.
|
java.util.List<E> |
getItems()
Returns immutable list of contained entities.
|
java.util.List<E> |
getMutableItems()
Returns mutable list of contained entities.
|
Sorter |
getSorter()
Returns sorter object currently set for the container.
|
void |
itemPropertyChanged(io.jmix.core.entity.EntityPropertyChangeEvent e) |
protected void |
replaceInCollection(int idx,
E entity) |
void |
replaceItem(E entity)
If the item with the same id exists in the container, it is replaced with the given instance.
|
void |
setItem(E item)
Sets the given entity instance to the container.
|
void |
setItems(java.util.Collection<E> entities)
Sets a collection of entities to the container.
|
void |
setSorter(Sorter sorter)
Sets sorter object.
|
java.lang.String |
toString() |
void |
unmute(CollectionContainer.UnmuteEventsMode mode)
Enables all event listeners.
|
addItemChangeListener, addItemPropertyChangeListener, attachListener, detachListener, fireItemChanged, getEntityMetaClass, getFetchPlan, getItem, getItemOrNull, getLoader, mute, setFetchPlan, setLoader, unmute
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
addItemChangeListener, addItemPropertyChangeListener, getEntityMetaClass, getFetchPlan, getItem, getItemOrNull, getView, mute, setFetchPlan, setView, unmute
@Autowired protected io.jmix.core.MetadataTools metadataTools
protected java.util.List<E> collection
protected java.util.Map<IndexKey,java.lang.Integer> idMap
protected Sorter sorter
public CollectionContainerImpl(io.jmix.core.metamodel.model.MetaClass metaClass)
public void setItem(@Nullable E item)
InstanceContainer
setItem
in interface InstanceContainer<E>
setItem
in class InstanceContainerImpl<E>
public java.util.List<E> getItems()
CollectionContainer
getItems
in interface CollectionContainer<E>
public java.util.List<E> getMutableItems()
CollectionContainer
CollectionContainer.CollectionChangeEvent
.getMutableItems
in interface CollectionContainer<E>
public void setItems(@Nullable java.util.Collection<E> entities)
CollectionContainer
setItems
in interface CollectionContainer<E>
public E getItem(java.lang.Object entityId)
CollectionContainer
getItem
in interface CollectionContainer<E>
@Nullable public E getItemOrNull(java.lang.Object entityId)
CollectionContainer
getItemOrNull
in interface CollectionContainer<E>
public int getItemIndex(java.lang.Object entityOrId)
CollectionContainer
getItemIndex
in interface CollectionContainer<E>
entityOrId
- entity instance or its idpublic boolean containsItem(java.lang.Object entityOrId)
CollectionContainer
containsItem
in interface CollectionContainer<E>
entityOrId
- entity instance or its idpublic void replaceItem(E entity)
CollectionContainer
Sends CollectionContainer.CollectionChangeEvent
of the SET_ITEM
or ADD_ITEMS
type.
replaceItem
in interface CollectionContainer<E>
protected void replaceInCollection(int idx, E entity)
protected void addToCollection(E entity)
public io.jmix.core.common.event.Subscription addCollectionChangeListener(java.util.function.Consumer<CollectionContainer.CollectionChangeEvent<E>> listener)
CollectionContainer
CollectionContainer.CollectionChangeEvent
.addCollectionChangeListener
in interface CollectionContainer<E>
@Nullable public Sorter getSorter()
CollectionContainer
getSorter
in interface CollectionContainer<E>
public void setSorter(Sorter sorter)
CollectionContainer
setSorter
in interface CollectionContainer<E>
public void unmute(CollectionContainer.UnmuteEventsMode mode)
CollectionContainer
mode
.unmute
in interface CollectionContainer<E>
mode
- modepublic void itemPropertyChanged(io.jmix.core.entity.EntityPropertyChangeEvent e)
itemPropertyChanged
in interface ItemPropertyChangeNotifier
itemPropertyChanged
in class InstanceContainerImpl<E>
protected void fireCollectionChanged(CollectionChangeType type, java.util.Collection<? extends E> changes)
protected void attachListener(java.util.Collection<E> entities)
protected void detachListener(java.util.Collection<E> entities)
protected void buildIdMap()
protected void clearItemIfNotExists()
public java.lang.String toString()
toString
in class InstanceContainerImpl<E>