Class GeneratedPropertyContainer
- java.lang.Object
-
- com.vaadin.data.util.AbstractContainer
-
- com.vaadin.data.util.GeneratedPropertyContainer
-
- All Implemented Interfaces:
Container,Container.Filterable,Container.Indexed,Container.ItemSetChangeNotifier,Container.Ordered,Container.PropertySetChangeNotifier,Container.Sortable,Serializable
public class GeneratedPropertyContainer extends AbstractContainer implements Container.Indexed, Container.Sortable, Container.Filterable, Container.PropertySetChangeNotifier, Container.ItemSetChangeNotifier
Container wrapper that adds support for generated properties. This container only supports adding new generated properties. Adding new normal properties should be done for the wrapped container.Removing properties from this container does not remove anything from the wrapped container but instead only hides them from the results. These properties can be returned to this container by calling
addContainerProperty(Object, Class, Object)with same property id which was removed.If wrapped container is Filterable and/or Sortable it should only be handled through this container as generated properties need to be handled in a specific way when sorting/filtering.
Items returned by this container do not support adding or removing properties. Generated properties are always read-only. Trying to make them editable throws an exception.
- Since:
- 7.4
- Author:
- Vaadin Ltd
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected classGeneratedPropertyContainer.GeneratedItemAddEventprotected classGeneratedPropertyContainer.GeneratedItemAddOrRemoveEventBase implementation for item add or remove events.protected classGeneratedPropertyContainer.GeneratedItemRemoveEventprotected static classGeneratedPropertyContainer.GeneratedProperty<T>Property implementation for generated propertiesclassGeneratedPropertyContainer.GeneratedPropertyItemItem implementation for generated properties, used to wrap the Item that belongs to the wrapped container.-
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 Constructor Description GeneratedPropertyContainer(Container.Indexed container)Constructor for GeneratedPropertyContainer.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddContainerFilter(Container.Filter filter)Adds a filter for the container.booleanaddContainerProperty(Object propertyId, Class<?> type, Object defaultValue)Adds a previously removed property back to GeneratedPropertyContainer.voidaddGeneratedProperty(Object propertyId, PropertyValueGenerator<?> generator)Add a new PropertyValueGenerator with given property id.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)voidaddListener(Container.PropertySetChangeListener listener)voidaddPropertySetChangeListener(Container.PropertySetChangeListener listener)Implementation of the corresponding method inContainer.PropertySetChangeNotifier, override with the corresponding public method and implement the interface to use this.booleancontainsId(Object itemId)Tests if the Container contains the specified Item.ObjectfirstItemId()Gets the ID of the first Item in the Container.Collection<Container.Filter>getContainerFilters()Returns the filters which have been applied to the containerProperty<?>getContainerProperty(Object itemId, Object propertyId)Gets the Property identified by the given itemId and propertyId from the Container.Collection<?>getContainerPropertyIds()Returns a list of propety ids available in this container.ObjectgetIdByIndex(int index)Get the item id for the item at the position given byindex.ItemgetItem(Object itemId)Gets theItemwith the given Item ID from the Container.Collection<?>getItemIds()Gets the ID's of all visible (after filtering and sorting) Items stored in the Container.List<?>getItemIds(int startIndex, int numberOfItems)GetnumberOfItemsconsecutive item ids from the container, starting with the item id atstartIndex.Collection<?>getSortableContainerPropertyIds()Gets the container property IDs which can be used to sort the items.Class<?>getType(Object propertyId)Gets the data type of all Properties identified by the given Property ID.Container.IndexedgetWrappedContainer()Returns the original underlying container.intindexOfId(Object itemId)Gets the index of the Item corresponding to the itemId.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.ObjectlastItemId()Gets the ID of the last Item in the Container..ObjectnextItemId(Object itemId)Gets the ID of the Item following the Item that corresponds toitemId.ObjectprevItemId(Object itemId)Gets the ID of the Item preceding the Item that corresponds toitemId.voidremoveAllContainerFilters()Remove all active filters from the container.booleanremoveAllItems()Removes all Items from the Container.voidremoveContainerFilter(Container.Filter filter)Removes a filter from the container.booleanremoveContainerProperty(Object propertyId)Marks the given property as hidden.voidremoveGeneratedProperty(Object propertyId)Removes any possible PropertyValueGenerator with given property id.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)voidremoveListener(Container.PropertySetChangeListener listener)voidremovePropertySetChangeListener(Container.PropertySetChangeListener listener)Implementation of the corresponding method inContainer.PropertySetChangeNotifier, override with the corresponding public method and implement the interface to use this.intsize()Gets the number of visible Items in the Container.voidsort(Object[] propertyId, boolean[] ascending)Sorts the container items.-
Methods inherited from class com.vaadin.data.util.AbstractContainer
fireContainerPropertySetChange, fireContainerPropertySetChange, fireItemSetChange, fireItemSetChange, getItemSetChangeListeners, getListeners, getPropertySetChangeListeners, setItemSetChangeListeners, setPropertySetChangeListeners
-
-
-
-
Constructor Detail
-
GeneratedPropertyContainer
public GeneratedPropertyContainer(Container.Indexed container)
Constructor for GeneratedPropertyContainer.- Parameters:
container- underlying indexed container
-
-
Method Detail
-
addGeneratedProperty
public void addGeneratedProperty(Object propertyId, PropertyValueGenerator<?> generator)
Add a new PropertyValueGenerator with given property id. This will override any existing properties with the same property id. Fires a PropertySetChangeEvent.- Parameters:
propertyId- property idgenerator- a property value generator
-
removeGeneratedProperty
public void removeGeneratedProperty(Object propertyId)
Removes any possible PropertyValueGenerator with given property id. Fires a PropertySetChangeEvent.- Parameters:
propertyId- property id
-
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)
-
addListener
public void addListener(Container.ItemSetChangeListener listener)
- Specified by:
addListenerin interfaceContainer.ItemSetChangeNotifier- Overrides:
addListenerin classAbstractContainer
-
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
public void removeListener(Container.ItemSetChangeListener listener)
- Specified by:
removeListenerin interfaceContainer.ItemSetChangeNotifier- Overrides:
removeListenerin classAbstractContainer
-
addPropertySetChangeListener
public void addPropertySetChangeListener(Container.PropertySetChangeListener listener)
Description copied from class:AbstractContainerImplementation of the corresponding method inContainer.PropertySetChangeNotifier, override with the corresponding public method and implement the interface to use this.- Specified by:
addPropertySetChangeListenerin interfaceContainer.PropertySetChangeNotifier- Overrides:
addPropertySetChangeListenerin classAbstractContainer- Parameters:
listener- The new Listener to be registered- See Also:
Container.PropertySetChangeNotifier.addListener(Container.PropertySetChangeListener)
-
addListener
public void addListener(Container.PropertySetChangeListener listener)
- Specified by:
addListenerin interfaceContainer.PropertySetChangeNotifier- Overrides:
addListenerin classAbstractContainer
-
removePropertySetChangeListener
public void removePropertySetChangeListener(Container.PropertySetChangeListener listener)
Description copied from class:AbstractContainerImplementation of the corresponding method inContainer.PropertySetChangeNotifier, override with the corresponding public method and implement the interface to use this.- Specified by:
removePropertySetChangeListenerin interfaceContainer.PropertySetChangeNotifier- Overrides:
removePropertySetChangeListenerin classAbstractContainer- Parameters:
listener- Listener to be removed- See Also:
Container.PropertySetChangeNotifier.removeListener(Container. PropertySetChangeListener)
-
removeListener
public void removeListener(Container.PropertySetChangeListener listener)
- Specified by:
removeListenerin interfaceContainer.PropertySetChangeNotifier- Overrides:
removeListenerin classAbstractContainer
-
addContainerFilter
public void addContainerFilter(Container.Filter filter) throws UnsupportedFilterException
Description copied from interface:Container.FilterableAdds a filter for the container.If a container has multiple filters, only items accepted by all filters are visible.
- Specified by:
addContainerFilterin interfaceContainer.Filterable- Throws:
UnsupportedFilterException- if the filter is not supported by the container
-
removeContainerFilter
public void removeContainerFilter(Container.Filter filter)
Description copied from interface:Container.FilterableRemoves a filter from the container.This requires that the equals() method considers the filters as equivalent (same instance or properly implemented equals() method).
- Specified by:
removeContainerFilterin interfaceContainer.Filterable
-
removeAllContainerFilters
public void removeAllContainerFilters()
Description copied from interface:Container.FilterableRemove all active filters from the container.- Specified by:
removeAllContainerFiltersin interfaceContainer.Filterable
-
getContainerFilters
public Collection<Container.Filter> getContainerFilters()
Description copied from interface:Container.FilterableReturns the filters which have been applied to the container- Specified by:
getContainerFiltersin interfaceContainer.Filterable- Returns:
- A collection of filters which have been applied to the container. An empty collection if no filters have been applied.
-
sort
public void sort(Object[] propertyId, boolean[] ascending)
Description copied from interface:Container.SortableSorts the container items.Sorting a container can irreversibly change the order of its items or only change the order temporarily, depending on the container.
- Specified by:
sortin interfaceContainer.Sortable- Parameters:
propertyId- Array of container property IDs, whose values are used to sort the items in container as primary, secondary, ... sorting criterion. All of the item IDs must be in the collection returned byContainer.Sortable.getSortableContainerPropertyIds()ascending- Array of sorting order flags corresponding to each property ID used in sorting. If this array is shorter than propertyId array, ascending order is assumed for items where the order is not specified. Usetrueto sort in ascending order,falseto use descending order.
-
getSortableContainerPropertyIds
public Collection<?> getSortableContainerPropertyIds()
Description copied from interface:Container.SortableGets the container property IDs which can be used to sort the items.- Specified by:
getSortableContainerPropertyIdsin interfaceContainer.Sortable- Returns:
- the IDs of the properties that can be used for sorting the container
-
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
-
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
-
getItem
public Item 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.
-
getContainerProperty
public Property<?> getContainerProperty(Object itemId, Object propertyId)
Description copied from interface:ContainerGets the Property identified by the given itemId and propertyId from the Container. If the Container does not contain the item or it is filtered out, or the Container does not have the Property,nullis returned.- Specified by:
getContainerPropertyin interfaceContainer- Parameters:
itemId- ID of the visible Item which contains the PropertypropertyId- ID of the Property to retrieve- Returns:
- Property with the given ID or
null
-
getContainerPropertyIds
public Collection<?> getContainerPropertyIds()
Returns a list of propety ids available in this container. This collection will contain properties for generated properties. Removed properties will not show unless there is a generated property overriding those.- Specified by:
getContainerPropertyIdsin interfaceContainer- Returns:
- unmodifiable collection of Property IDs
-
addContainerProperty
public boolean addContainerProperty(Object propertyId, Class<?> type, Object defaultValue) throws UnsupportedOperationException
Adds a previously removed property back to GeneratedPropertyContainer. Adding a property that is not previously removed causes an UnsupportedOperationException.- 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
Marks the given property as hidden. This property from wrapped container will be removed fromgetContainerPropertyIds()and is no longer be available in Items retrieved from this container.- 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
-
getType
public Class<?> getType(Object propertyId)
Description copied from interface:ContainerGets the data type of all Properties identified by the given Property ID.
-
nextItemId
public Object 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 Object 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 Object 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 Object 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
-
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
-
getItemIds
public Collection<?> 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
-
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
-
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
-
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
-
getIdByIndex
public Object 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<?> getItemIds(int startIndex, int numberOfItems)
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 includenumberOfItems- 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
-
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
-
getWrappedContainer
public Container.Indexed getWrappedContainer()
Returns the original underlying container.- Returns:
- the original underlying container
-
-