Class AbstractInMemoryContainer<ITEMIDTYPE,PROPERTYIDCLASS,ITEMCLASS extends Item>
- java.lang.Object
-
- com.vaadin.data.util.AbstractContainer
-
- com.vaadin.data.util.AbstractInMemoryContainer<ITEMIDTYPE,PROPERTYIDCLASS,ITEMCLASS>
-
- Type Parameters:
ITEMIDTYPE- the class of item identifiers in the container, use Object if can be any classPROPERTYIDCLASS- the class of property identifiers for the items in the container, use Object if can be any classITEMCLASS- the (base) class of the Item instances in the container, useItemif unknown
- All Implemented Interfaces:
Container,Container.Indexed,Container.ItemSetChangeNotifier,Container.Ordered,Serializable
- Direct Known Subclasses:
AbstractBeanContainer,IndexedContainer
public abstract class AbstractInMemoryContainer<ITEMIDTYPE,PROPERTYIDCLASS,ITEMCLASS extends Item> extends AbstractContainer implements Container.ItemSetChangeNotifier, Container.Indexed
AbstractContainerclass that handles common functionality for in-memory containers. Concrete in-memory container classes can either inherit this class, inheritAbstractContainer, or implement theContainerinterface directly. Adding and removing items (if desired) must be implemented in subclasses by overriding the appropriate add*Item() and remove*Item() and removeAllItems() methods, calling the corresponding#internalAddItemAfter(Object, Object, Item),#internalAddItemAt(int, Object, Item),internalAddItemAtEnd(Object, Item, boolean),internalRemoveItem(Object)andinternalRemoveAllItems()methods. By default, adding and removing container properties is not supported, and subclasses need to implementContainer.getContainerPropertyIds(). Optionally, subclasses can overrideaddContainerProperty(Object, Class, Object)andremoveContainerProperty(Object)to implement them. Features:Container.OrderedContainer.IndexedContainer.FilterableandContainer.SimpleFilterable(internal implementation, does not implement the interface directly)Container.Sortable(internal implementation, does not implement the interface directly)
Container.Sortable, subclasses need to implementgetSortablePropertyIds()and call the superclass methodsortContainer(Object[], boolean[])in the methodsort(Object[], boolean[]). To implementContainer.Filterable, subclasses need to implement the methodsContainer.Filterable.addContainerFilter(Container.Filter)(callingaddFilter(Filter)),Container.Filterable.removeAllContainerFilters()(callingremoveAllFilters()) andContainer.Filterable.removeContainerFilter(Container.Filter)(callingremoveFilter(Container.Filter)). To implementContainer.SimpleFilterable, subclasses also need to implement the methodsContainer.SimpleFilterable.addContainerFilter(Object, String, boolean, boolean)andContainer.SimpleFilterable.removeContainerFilters(Object)callingaddFilter(Container.Filter)andremoveFilters(Object)respectively.- Since:
- 6.6
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classAbstractInMemoryContainer.BaseItemAddEventAnEventobject specifying information about the added items.protected static classAbstractInMemoryContainer.BaseItemRemoveEventAnEventobject specifying information about the removed items.-
Nested classes/interfaces inherited from class com.vaadin.data.util.AbstractContainer
AbstractContainer.BaseItemSetChangeEvent, AbstractContainer.BasePropertySetChangeEvent
-
Nested classes/interfaces inherited from interface com.vaadin.data.Container
Container.Editor, Container.Filter, Container.Filterable, Container.Hierarchical, Container.Indexed, Container.ItemSetChangeEvent, Container.ItemSetChangeListener, Container.ItemSetChangeNotifier, Container.Ordered, Container.PropertySetChangeEvent, Container.PropertySetChangeListener, Container.PropertySetChangeNotifier, Container.SimpleFilterable, Container.Sortable, Container.Viewer
-
Nested classes/interfaces inherited from interface com.vaadin.data.Container.Indexed
Container.Indexed.ItemAddEvent, Container.Indexed.ItemRemoveEvent
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractInMemoryContainer()Constructor for an abstract in-memory container.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description booleanaddContainerProperty(Object propertyId, Class<?> type, Object defaultValue)Adds a new Property to all Items in the Container.protected voidaddFilter(Container.Filter filter)Adds a container filter and re-filter the view.ObjectaddItem()Creates a new Item into the Container, and assign it an automatic ID.ItemaddItem(Object itemId)Creates a new Item with the given ID in the Container.ObjectaddItemAfter(Object previousItemId)Adds a new item after the given item.ItemaddItemAfter(Object previousItemId, Object newItemId)Adds a new item after the given item.ObjectaddItemAt(int index)Adds a new item at given index (in the filtered view).ItemaddItemAt(int index, Object newItemId)Adds a new item at given index (in the filtered view).voidaddItemSetChangeListener(Container.ItemSetChangeListener listener)Implementation of the corresponding method inContainer.ItemSetChangeNotifier, override with the corresponding public method and implement the interface to use this.voidaddListener(Container.ItemSetChangeListener listener)Deprecated.As of 7.0, replaced byaddItemSetChangeListener(Container.ItemSetChangeListener)booleancontainsId(Object itemId)Tests if the Container contains the specified Item.protected booleandoFilterContainer(boolean hasFilters)Filters the data in the container and updates internal data structures.protected voiddoSort()Perform the sorting of the data structures in the container.protected voidfilterAll()Filter the view to recreate the visible item list from the unfiltered items, and send a notification if the set of visible items changed in any way.protected voidfireItemAdded(int position, ITEMIDTYPE itemId, ITEMCLASS item)Notify item set change listeners that an item has been added to the container.protected voidfireItemRemoved(int position, Object itemId)Notify item set change listeners that an item has been removed from the container.protected voidfireItemsAdded(int firstPosition, ITEMIDTYPE firstItemId, int numberOfItems)Notify item set change listeners that items has been added to the container.protected voidfireItemsRemoved(int firstPosition, Object firstItemId, int numberOfItems)Notify item set change listeners that items has been removed from the container.ITEMIDTYPEfirstItemId()Gets the ID of the first Item in the Container.protected List<ITEMIDTYPE>getAllItemIds()Internal helper method to get the internal list of all item identifiers.protected Collection<Container.Filter>getContainerFilters()protected List<ITEMIDTYPE>getFilteredItemIds()Internal helper method to get the internal list of filtered item identifiers.protected Set<Container.Filter>getFilters()Returns the internal collection of filters.protected ITEMIDTYPEgetFirstVisibleItem()Returns the item id of the first visible item after filtering.ITEMIDTYPEgetIdByIndex(int index)Get the item id for the item at the position given byindex.ITEMCLASSgetItem(Object itemId)Gets theItemwith the given Item ID from the Container.List<?>getItemIds()Gets the ID's of all visible (after filtering and sorting) Items stored in the Container.List<ITEMIDTYPE>getItemIds(int startIndex, int numberOfIds)GetnumberOfItemsconsecutive item ids from the container, starting with the item id atstartIndex.protected ItemSortergetItemSorter()Returns the ItemSorter used for comparing items in a sort.protected Collection<?>getSortablePropertyIds()Returns the sortable property identifiers for the container.protected abstract ITEMCLASSgetUnfilteredItem(Object itemId)Get an item even if filtered out.protected List<ITEMIDTYPE>getVisibleItemIds()Returns the internal list of visible item identifiers after filtering.protected booleanhasContainerFilters()Returns true if any filters have been applied to the container.intindexOfId(Object itemId)Gets the index of the Item corresponding to the itemId.protected ITEMCLASSinternalAddItemAfter(ITEMIDTYPE previousItemId, ITEMIDTYPE newItemId, ITEMCLASS item, boolean filter)Add an item after a given (visible) item, and perform filtering.protected ITEMCLASSinternalAddItemAt(int index, ITEMIDTYPE newItemId, ITEMCLASS item, boolean filter)Add an item at a given (visible after filtering) item index, and perform filtering.protected ITEMCLASSinternalAddItemAtEnd(ITEMIDTYPE newItemId, ITEMCLASS item, boolean filter)Add an item at the end of the container, and perform filtering if necessary.protected voidinternalRemoveAllItems()Removes all items from the internal data structures of this class.protected booleaninternalRemoveItem(Object itemId)Removes a single item from the internal data structures of this class.protected booleanisFiltered()Returns true is the container has active filters.booleanisFirstId(Object itemId)Tests if the Item corresponding to the given Item ID is the first Item in the Container.booleanisLastId(Object itemId)Tests if the Item corresponding to the given Item ID is the last Item in the Container.protected booleanisPropertyFiltered(Object propertyId)Checks if there is a filter that applies to a given property.ITEMIDTYPElastItemId()Gets the ID of the last Item in the Container..ITEMIDTYPEnextItemId(Object itemId)Gets the ID of the Item following the Item that corresponds toitemId.protected booleanpassesFilters(Object itemId)Checks if the given itemId passes the filters set for the container.ITEMIDTYPEprevItemId(Object itemId)Gets the ID of the Item preceding the Item that corresponds toitemId.protected voidregisterNewItem(int position, ITEMIDTYPE itemId, ITEMCLASS item)Registers a new item as having been added to the container.protected voidremoveAllFilters()Remove all container filters for all properties and re-filter the view.booleanremoveAllItems()Removes all Items from the Container.booleanremoveContainerProperty(Object propertyId)Removes a Property specified by the given Property ID from the Container.protected voidremoveFilter(Container.Filter filter)Remove a specific container filter and re-filter the view (if necessary).protected Collection<Container.Filter>removeFilters(Object propertyId)Remove all container filters for a given property identifier and re-filter the view.booleanremoveItem(Object itemId)Removes the Item identified byItemIdfrom the Container.voidremoveItemSetChangeListener(Container.ItemSetChangeListener listener)Implementation of the corresponding method inContainer.ItemSetChangeNotifier, override with the corresponding public method and implement the interface to use this.voidremoveListener(Container.ItemSetChangeListener listener)Deprecated.As of 7.0, replaced byremoveItemSetChangeListener(Container.ItemSetChangeListener)protected voidsetAllItemIds(List<ITEMIDTYPE> allItemIds)Deprecated.protected voidsetFilteredItemIds(List<ITEMIDTYPE> filteredItemIds)Deprecated.protected voidsetFilters(Set<Container.Filter> filters)Set the internal collection of filters without performing filtering.protected voidsetItemSorter(ItemSorter itemSorter)Sets the ItemSorter used for comparing items in a sort.intsize()Gets the number of visible Items in the Container.protected voidsortContainer(Object[] propertyId, boolean[] ascending)Sort base implementation to be used to implementContainer.Sortable.-
Methods inherited from class com.vaadin.data.util.AbstractContainer
addListener, addPropertySetChangeListener, fireContainerPropertySetChange, fireContainerPropertySetChange, fireItemSetChange, fireItemSetChange, getItemSetChangeListeners, getListeners, getPropertySetChangeListeners, removeListener, removePropertySetChangeListener, setItemSetChangeListeners, setPropertySetChangeListeners
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.vaadin.data.Container
getContainerProperty, getContainerPropertyIds, getType
-
-
-
-
Method Detail
-
getItem
public ITEMCLASS getItem(Object itemId)
Description copied from interface:ContainerGets theItemwith the given Item ID from the Container. If the Container does not contain the requested Item,nullis returned.Containers should not return Items that are filtered out.
-
getUnfilteredItem
protected abstract ITEMCLASS getUnfilteredItem(Object itemId)
Get an item even if filtered out. For internal use only.- Parameters:
itemId-- Returns:
-
size
public int size()
Description copied from interface:ContainerGets the number of visible Items in the Container.Filtering can hide items so that they will not be visible through the container API.
-
containsId
public boolean containsId(Object itemId)
Description copied from interface:ContainerTests if the Container contains the specified Item.Filtering can hide items so that they will not be visible through the container API, and this method should respect visibility of items (i.e. only indicate visible items as being in the container) if feasible for the container.
- Specified by:
containsIdin interfaceContainer- Parameters:
itemId- ID the of Item to be tested- Returns:
- boolean indicating if the Container holds the specified Item
-
getItemIds
public List<?> getItemIds()
Description copied from interface:ContainerGets the ID's of all visible (after filtering and sorting) Items stored in the Container. The ID's cannot be modified through the returned collection.If the container is
Container.Ordered, the collection returned by this method should follow that order. If the container isContainer.Sortable, the items should be in the sorted order.Calling this method for large lazy containers can be an expensive operation and should be avoided when practical.
- Specified by:
getItemIdsin interfaceContainer- Returns:
- unmodifiable collection of Item IDs
-
nextItemId
public ITEMIDTYPE nextItemId(Object itemId)
Description copied from interface:Container.OrderedGets the ID of the Item following the Item that corresponds toitemId. If the given Item is the last or not found in the Container,nullis returned.- Specified by:
nextItemIdin interfaceContainer.Ordered- Parameters:
itemId- ID of a visible Item in the Container- Returns:
- ID of the next visible Item or
null
-
prevItemId
public ITEMIDTYPE prevItemId(Object itemId)
Description copied from interface:Container.OrderedGets the ID of the Item preceding the Item that corresponds toitemId. If the given Item is the first or not found in the Container,nullis returned.- Specified by:
prevItemIdin interfaceContainer.Ordered- Parameters:
itemId- ID of a visible Item in the Container- Returns:
- ID of the previous visible Item or
null
-
firstItemId
public ITEMIDTYPE firstItemId()
Description copied from interface:Container.OrderedGets the ID of the first Item in the Container.- Specified by:
firstItemIdin interfaceContainer.Ordered- Returns:
- ID of the first visible Item in the Container
-
lastItemId
public ITEMIDTYPE lastItemId()
Description copied from interface:Container.OrderedGets the ID of the last Item in the Container..- Specified by:
lastItemIdin interfaceContainer.Ordered- Returns:
- ID of the last visible Item in the Container
-
isFirstId
public boolean isFirstId(Object itemId)
Description copied from interface:Container.OrderedTests if the Item corresponding to the given Item ID is the first Item in the Container.- Specified by:
isFirstIdin interfaceContainer.Ordered- Parameters:
itemId- ID of an Item in the Container- Returns:
trueif the Item is first visible item in the Container,falseif not
-
isLastId
public boolean isLastId(Object itemId)
Description copied from interface:Container.OrderedTests if the Item corresponding to the given Item ID is the last Item in the Container.- Specified by:
isLastIdin interfaceContainer.Ordered- Returns:
trueif the Item is last visible item in the Container,falseif not
-
getIdByIndex
public ITEMIDTYPE getIdByIndex(int index)
Description copied from interface:Container.IndexedGet the item id for the item at the position given byindex.- Specified by:
getIdByIndexin interfaceContainer.Indexed- Parameters:
index- the index of the requested item id- Returns:
- the item id of the item at the given index
-
getItemIds
public List<ITEMIDTYPE> getItemIds(int startIndex, int numberOfIds)
Description copied from interface:Container.IndexedGetnumberOfItemsconsecutive item ids from the container, starting with the item id atstartIndex.Implementations should return at most
numberOfItemsitem ids, but can contain less if the container has less items than required to fulfill the request. The returned list must hence contain all of the item ids from the range:startIndextomax(startIndex + (numberOfItems-1), container.size()-1).For quick migration to new API see:
ContainerHelpers.getItemIdsUsingGetIdByIndex(int, int, Indexed)- Specified by:
getItemIdsin interfaceContainer.Indexed- Parameters:
startIndex- the index for the first item which id to includenumberOfIds- the number of consecutive item ids to get from the given start index, must be >= 0- Returns:
- List containing the requested item ids or empty list if
numberOfItems== 0; not null
-
indexOfId
public int indexOfId(Object itemId)
Description copied from interface:Container.IndexedGets the index of the Item corresponding to the itemId. The following istruefor the returned index: 0 <= index < size(), or index = -1 if there is no visible item with that id in the container.- Specified by:
indexOfIdin interfaceContainer.Indexed- Parameters:
itemId- ID of an Item in the Container- Returns:
- index of the Item, or -1 if (the filtered and sorted view of) the Container does not include the Item
-
addItemAt
public Object addItemAt(int index) throws UnsupportedOperationException
Description copied from interface:Container.IndexedAdds a new item at given index (in the filtered view).The indices of the item currently in the given position and all the following items are incremented.
This method should apply filters to the added item after inserting it, possibly hiding it immediately. If the container is being sorted, the item may be added at the correct sorted position instead of the given position. See
Container.Indexed,Container.Ordered,Container.FilterableandContainer.Sortablefor more information.- Specified by:
addItemAtin interfaceContainer.Indexed- Parameters:
index- Index (in the filtered and sorted view) to add the new item.- Returns:
- item id of the created item or null if the operation fails.
- Throws:
UnsupportedOperationException- if the operation is not supported by the container
-
addItemAt
public Item addItemAt(int index, Object newItemId) throws UnsupportedOperationException
Description copied from interface:Container.IndexedAdds a new item at given index (in the filtered view).The indexes of the item currently in the given position and all the following items are incremented.
This method should apply filters to the added item after inserting it, possibly hiding it immediately. If the container is being sorted, the item may be added at the correct sorted position instead of the given position. See
Container.Indexed,Container.FilterableandContainer.Sortablefor more information.- Specified by:
addItemAtin interfaceContainer.Indexed- Parameters:
index- Index (in the filtered and sorted view) at which to add the new item.newItemId- Id of the new item to be added.- Returns:
- new
Itemor null if the operation fails. - Throws:
UnsupportedOperationException- if the operation is not supported by the container
-
addItemAfter
public Object addItemAfter(Object previousItemId) throws UnsupportedOperationException
Description copied from interface:Container.OrderedAdds a new item after the given item.Adding an item after null item adds the item as first item of the ordered container.
- Specified by:
addItemAfterin interfaceContainer.Ordered- Parameters:
previousItemId- Id of the visible item in ordered container after which to insert the new item.- Returns:
- item id the the created new item or null if the operation fails.
- Throws:
UnsupportedOperationException- if the operation is not supported by the container- See Also:
Ordered: adding items in filtered or sorted containers
-
addItemAfter
public Item addItemAfter(Object previousItemId, Object newItemId) throws UnsupportedOperationException
Description copied from interface:Container.OrderedAdds a new item after the given item.Adding an item after null item adds the item as first item of the ordered container.
- Specified by:
addItemAfterin interfaceContainer.Ordered- Parameters:
previousItemId- Id of the visible item in ordered container after which to insert the new item.newItemId- Id of the new item to be added.- Returns:
- new item or null if the operation fails.
- Throws:
UnsupportedOperationException- if the operation is not supported by the container- See Also:
Ordered: adding items in filtered or sorted containers
-
addItem
public Item addItem(Object itemId) throws UnsupportedOperationException
Description copied from interface:ContainerCreates a new Item with the given ID in the Container.The new Item is returned, and it is ready to have its Properties modified. Returns
nullif the operation fails or the Container already contains a Item with the given ID.This functionality is optional.
- Specified by:
addItemin interfaceContainer- Parameters:
itemId- ID of the Item to be created- Returns:
- Created new Item, or
nullin case of a failure - Throws:
UnsupportedOperationException- if adding an item with an explicit item ID is not supported by the container
-
addItem
public Object addItem() throws UnsupportedOperationException
Description copied from interface:ContainerCreates a new Item into the Container, and assign it an automatic ID.The new ID is returned, or
nullif the operation fails. After a successful call you can use themethod to fetch the Item.getItemThis functionality is optional.
- Specified by:
addItemin interfaceContainer- Returns:
- ID of the newly created Item, or
nullin case of a failure - Throws:
UnsupportedOperationException- if adding an item without an explicit item ID is not supported by the container
-
removeItem
public boolean removeItem(Object itemId) throws UnsupportedOperationException
Description copied from interface:ContainerRemoves the Item identified byItemIdfrom the Container.Containers that support filtering should also allow removing an item that is currently filtered out.
This functionality is optional.
- Specified by:
removeItemin interfaceContainer- Parameters:
itemId- ID of the Item to remove- Returns:
trueif the operation succeeded,falseif not- Throws:
UnsupportedOperationException- if the container does not support removing individual items
-
removeAllItems
public boolean removeAllItems() throws UnsupportedOperationExceptionDescription copied from interface:ContainerRemoves all Items from the Container.Note that Property ID and type information is preserved. This functionality is optional.
- Specified by:
removeAllItemsin interfaceContainer- Returns:
trueif the operation succeeded,falseif not- Throws:
UnsupportedOperationException- if the container does not support removing all items
-
addContainerProperty
public boolean addContainerProperty(Object propertyId, Class<?> type, Object defaultValue) throws UnsupportedOperationException
Description copied from interface:ContainerAdds a new Property to all Items in the Container. The Property ID, data type and default value of the new Property are given as parameters.This functionality is optional.
- Specified by:
addContainerPropertyin interfaceContainer- Parameters:
propertyId- ID of the Propertytype- Data type of the new PropertydefaultValue- The value all created Properties are initialized to- Returns:
trueif the operation succeeded,falseif not- Throws:
UnsupportedOperationException- if the container does not support explicitly adding container properties
-
removeContainerProperty
public boolean removeContainerProperty(Object propertyId) throws UnsupportedOperationException
Description copied from interface:ContainerRemoves a Property specified by the given Property ID from the Container. Note that the Property will be removed from all Items in the Container.This functionality is optional.
- Specified by:
removeContainerPropertyin interfaceContainer- Parameters:
propertyId- ID of the Property to remove- Returns:
trueif the operation succeeded,falseif not- Throws:
UnsupportedOperationException- if the container does not support removing container properties
-
addListener
@Deprecated public void addListener(Container.ItemSetChangeListener listener)
Deprecated.As of 7.0, replaced byaddItemSetChangeListener(Container.ItemSetChangeListener)- Specified by:
addListenerin interfaceContainer.ItemSetChangeNotifier- Overrides:
addListenerin classAbstractContainer
-
addItemSetChangeListener
public void addItemSetChangeListener(Container.ItemSetChangeListener listener)
Description copied from class:AbstractContainerImplementation of the corresponding method inContainer.ItemSetChangeNotifier, override with the corresponding public method and implement the interface to use this.- Specified by:
addItemSetChangeListenerin interfaceContainer.ItemSetChangeNotifier- Overrides:
addItemSetChangeListenerin classAbstractContainer- Parameters:
listener- listener to be added- See Also:
Container.ItemSetChangeNotifier.addListener(Container.ItemSetChangeListener)
-
removeItemSetChangeListener
public void removeItemSetChangeListener(Container.ItemSetChangeListener listener)
Description copied from class:AbstractContainerImplementation of the corresponding method inContainer.ItemSetChangeNotifier, override with the corresponding public method and implement the interface to use this.- Specified by:
removeItemSetChangeListenerin interfaceContainer.ItemSetChangeNotifier- Overrides:
removeItemSetChangeListenerin classAbstractContainer- Parameters:
listener- listener to be removed- See Also:
Container.ItemSetChangeNotifier.removeListener(Container.ItemSetChangeListener)
-
removeListener
@Deprecated public void removeListener(Container.ItemSetChangeListener listener)
Deprecated.As of 7.0, replaced byremoveItemSetChangeListener(Container.ItemSetChangeListener)- Specified by:
removeListenerin interfaceContainer.ItemSetChangeNotifier- Overrides:
removeListenerin classAbstractContainer
-
filterAll
protected void filterAll()
Filter the view to recreate the visible item list from the unfiltered items, and send a notification if the set of visible items changed in any way.
-
doFilterContainer
protected boolean doFilterContainer(boolean hasFilters)
Filters the data in the container and updates internal data structures. This method should reset any internal data structures and then repopulate them sogetItemIds()and other methods only return the filtered items.- Parameters:
hasFilters- true if filters has been set for the container, false otherwise- Returns:
- true if the item set has changed as a result of the filtering
-
passesFilters
protected boolean passesFilters(Object itemId)
Checks if the given itemId passes the filters set for the container. The caller should make sure the itemId exists in the container. For non-existing itemIds the behavior is undefined.- Parameters:
itemId- An itemId that exists in the container.- Returns:
- true if the itemId passes all filters or no filters are set, false otherwise.
-
addFilter
protected void addFilter(Container.Filter filter) throws UnsupportedFilterException
Adds a container filter and re-filter the view. The filter must implement Filter and its sub-filters (if any) must also be in-memory filterable. This can be used to implementContainer.Filterable.addContainerFilter(Container.Filter)and optionally alsoContainer.SimpleFilterable.addContainerFilter(Object, String, boolean, boolean)(withSimpleStringFilter). Note that in some cases, incompatible filters cannot be detected when added and anUnsupportedFilterExceptionmay occur when performing filtering.- Throws:
UnsupportedFilterException- if the filter is detected as not supported by the container
-
hasContainerFilters
protected boolean hasContainerFilters()
Returns true if any filters have been applied to the container.- Returns:
- true if the container has filters applied, false otherwise
- Since:
- 7.1
-
getContainerFilters
protected Collection<Container.Filter> getContainerFilters()
-
removeFilter
protected void removeFilter(Container.Filter filter)
Remove a specific container filter and re-filter the view (if necessary). This can be used to implementContainer.Filterable.removeContainerFilter(Container.Filter).
-
removeAllFilters
protected void removeAllFilters()
Remove all container filters for all properties and re-filter the view. This can be used to implementContainer.Filterable.removeAllContainerFilters().
-
isPropertyFiltered
protected boolean isPropertyFiltered(Object propertyId)
Checks if there is a filter that applies to a given property.- Parameters:
propertyId-- Returns:
- true if there is an active filter for the property
-
removeFilters
protected Collection<Container.Filter> removeFilters(Object propertyId)
Remove all container filters for a given property identifier and re-filter the view. This also removes filters applying to multiple properties including the one identified by propertyId. This can be used to implementFilterable#removeContainerFilters(Object).- Parameters:
propertyId-- Returns:
- Collection
removed filters
-
getItemSorter
protected ItemSorter getItemSorter()
Returns the ItemSorter used for comparing items in a sort. SeesetItemSorter(ItemSorter)for more information.- Returns:
- The ItemSorter used for comparing two items in a sort.
-
setItemSorter
protected void setItemSorter(ItemSorter itemSorter)
Sets the ItemSorter used for comparing items in a sort. TheItemSorter.compare(Object, Object)method is called with item ids to perform the sorting. A default ItemSorter is used if this is not explicitly set.- Parameters:
itemSorter- The ItemSorter used for comparing two items in a sort (not null).
-
sortContainer
protected void sortContainer(Object[] propertyId, boolean[] ascending)
Sort base implementation to be used to implementContainer.Sortable. Subclasses should call this from a public#sort(Object[], boolean[])method when implementing Sortable.
-
doSort
protected void doSort()
Perform the sorting of the data structures in the container. This is invoked when theitemSorterhas been prepared for the sort operation. Typically this method callsCollections.sort(aCollection, getItemSorter())on all arrays (containing item ids) that need to be sorted.
-
getSortablePropertyIds
protected Collection<?> getSortablePropertyIds()
Returns the sortable property identifiers for the container. Can be used to implementContainer.Sortable.getSortableContainerPropertyIds().
-
internalRemoveAllItems
protected void internalRemoveAllItems()
Removes all items from the internal data structures of this class. This can be used to implementremoveAllItems()in subclasses. No notification is sent, the caller has to fire a suitable item set change notification.
-
internalRemoveItem
protected boolean internalRemoveItem(Object itemId)
Removes a single item from the internal data structures of this class. This can be used to implementremoveItem(Object)in subclasses. No notification is sent, the caller has to fire a suitable item set change notification.- Parameters:
itemId- the identifier of the item to remove- Returns:
- true if an item was successfully removed, false if failed to remove or no such item
-
internalAddItemAtEnd
protected ITEMCLASS internalAddItemAtEnd(ITEMIDTYPE newItemId, ITEMCLASS item, boolean filter)
Add an item at the end of the container, and perform filtering if necessary. An event is fired if the filtered view changes.- Parameters:
newItemId-item- new item to addfilter- true to perform filtering and send event after adding the item, false to skip these operations for batch inserts - if false, caller needs to make sure these operations are performed at the end of the batch- Returns:
- item added or null if no item was added
-
internalAddItemAfter
protected ITEMCLASS internalAddItemAfter(ITEMIDTYPE previousItemId, ITEMIDTYPE newItemId, ITEMCLASS item, boolean filter)
Add an item after a given (visible) item, and perform filtering. An event is fired if the filtered view changes. The new item is added at the beginning if previousItemId is null.- Parameters:
previousItemId- item id of a visible item after which to add the new item, or null to add at the beginningnewItemId-item- new item to addfilter- true to perform filtering and send event after adding the item, false to skip these operations for batch inserts - if false, caller needs to make sure these operations are performed at the end of the batch- Returns:
- item added or null if no item was added
-
internalAddItemAt
protected ITEMCLASS internalAddItemAt(int index, ITEMIDTYPE newItemId, ITEMCLASS item, boolean filter)
Add an item at a given (visible after filtering) item index, and perform filtering. An event is fired if the filtered view changes.- Parameters:
index- position where to add the item (visible/view index)newItemId-item- new item to addfilter- true to perform filtering and send event after adding the item, false to skip these operations for batch inserts - if false, caller needs to make sure these operations are performed at the end of the batch- Returns:
- item added or null if no item was added
-
registerNewItem
protected void registerNewItem(int position, ITEMIDTYPE itemId, ITEMCLASS item)Registers a new item as having been added to the container. This can involve storing the item or any relevant information about it in internal container-specific collections if necessary, as well as registering listeners etc. The full identifier list inAbstractInMemoryContainerhas already been updated to reflect the new item when this method is called.- Parameters:
position-itemId-item-
-
fireItemAdded
protected void fireItemAdded(int position, ITEMIDTYPE itemId, ITEMCLASS item)Notify item set change listeners that an item has been added to the container.- Parameters:
position- position of the added item in the viewitemId- id of the added itemitem- the added item- Since:
- 7.4
-
fireItemsAdded
protected void fireItemsAdded(int firstPosition, ITEMIDTYPE firstItemId, int numberOfItems)Notify item set change listeners that items has been added to the container.- Parameters:
firstPosition- position of the first visible added item in the viewfirstItemId- id of the first visible added itemnumberOfItems- the number of visible added items
-
fireItemRemoved
protected void fireItemRemoved(int position, Object itemId)Notify item set change listeners that an item has been removed from the container.- Parameters:
position- position of the removed item in the view prior to removal (if was visible)itemId- id of the removed item, of typeObjectto satisfyContainer.removeItem(Object)API- Since:
- 7.4
-
fireItemsRemoved
protected void fireItemsRemoved(int firstPosition, Object firstItemId, int numberOfItems)Notify item set change listeners that items has been removed from the container.- Parameters:
firstPosition- position of the first visible removed item in the view prior to removalfirstItemId- id of the first visible removed item, of typeObjectto satisfyContainer.removeItem(Object)APInumberOfItems- the number of removed visible items
-
getVisibleItemIds
protected List<ITEMIDTYPE> getVisibleItemIds()
Returns the internal list of visible item identifiers after filtering. For internal use only.
-
getFirstVisibleItem
protected ITEMIDTYPE getFirstVisibleItem()
Returns the item id of the first visible item after filtering. 'Null' is returned if there is no visible items.For internal use only.
- Returns:
- item id of the first visible item
- Since:
- 7.4
-
isFiltered
protected boolean isFiltered()
Returns true is the container has active filters.- Returns:
- true if the container is currently filtered
-
setFilteredItemIds
@Deprecated protected void setFilteredItemIds(List<ITEMIDTYPE> filteredItemIds)
Deprecated.Internal helper method to set the internal list of filtered item identifiers. Should not be used outside this class except for implementing clone(), may disappear from future versions.- Parameters:
filteredItemIds-
-
getFilteredItemIds
protected List<ITEMIDTYPE> getFilteredItemIds()
Internal helper method to get the internal list of filtered item identifiers. Should not be used outside this class except for implementing clone(), may disappear from future versions - usegetVisibleItemIds()in other contexts.- Returns:
- List
-
setAllItemIds
@Deprecated protected void setAllItemIds(List<ITEMIDTYPE> allItemIds)
Deprecated.Internal helper method to set the internal list of all item identifiers. Should not be used outside this class except for implementing clone(), may disappear from future versions.- Parameters:
allItemIds-
-
getAllItemIds
protected List<ITEMIDTYPE> getAllItemIds()
Internal helper method to get the internal list of all item identifiers. Avoid using this method outside this class, may disappear in future versions.- Returns:
- List
-
setFilters
protected void setFilters(Set<Container.Filter> filters)
Set the internal collection of filters without performing filtering. This method is mostly for internal use, useaddFilter(Container.Filter)andremove*Filter*(which also re-filter the container) instead when possible.- Parameters:
filters-
-
getFilters
protected Set<Container.Filter> getFilters()
Returns the internal collection of filters. The returned collection should not be modified by callers outside this class.- Returns:
- Set
-
-