From f6e41dc7c8666146595bc6aa66102f7cfc9c37cb Mon Sep 17 00:00:00 2001 From: Henri Sara Date: Mon, 29 Nov 2010 14:34:38 +0000 Subject: #5713 BeanContainer that does not require item id to be the bean svn changeset:16216/svn branch:6.5 --- src/com/vaadin/data/util/BeanContainer.java | 95 +++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 src/com/vaadin/data/util/BeanContainer.java (limited to 'src') diff --git a/src/com/vaadin/data/util/BeanContainer.java b/src/com/vaadin/data/util/BeanContainer.java new file mode 100644 index 0000000000..9c264b9dce --- /dev/null +++ b/src/com/vaadin/data/util/BeanContainer.java @@ -0,0 +1,95 @@ +package com.vaadin.data.util; + +import com.vaadin.data.Item; + +/** + * An in-memory container for JavaBeans. + * + *

+ * The properties of the container are determined automatically by introspecting + * the used JavaBean class. Only beans of the same type can be added to the + * container. + *

+ * + *

+ * In BeanContainer (unlike {@link BeanItemContainer}), the item IDs do not have + * to be the beans themselves. + *

+ * + *

+ * It is not possible to add additional properties to the container and nested + * bean properties are not supported. + *

+ * + * @param + * The type of the item identifier + * @param + * The type of the Bean + * + * @see AbstractBeanContainer + * @see BeanItemContainer + * + * @since 6.5 + */ +public class BeanContainer extends + AbstractBeanContainer { + + public BeanContainer(Class type) { + super(type); + } + + public Item addItemAt(int index, Object newItemId) + throws UnsupportedOperationException { + throw new UnsupportedOperationException(); + } + + public Item addItemAfter(Object previousItemId, Object newItemId) + throws UnsupportedOperationException { + throw new UnsupportedOperationException(); + } + + public Item addItem(Object itemId) throws UnsupportedOperationException { + throw new UnsupportedOperationException(); + } + + /** + * Adds the bean to the Container. + * + * @see com.vaadin.data.Container#addItem(Object) + */ + @Override + public BeanItem addItem(IDTYPE itemId, BT bean) { + return super.addItem(itemId, bean); + } + + /** + * Adds the bean after the given bean. + * + * @see com.vaadin.data.Container.Ordered#addItemAfter(Object, Object) + */ + @Override + public BeanItem addItemAfter(IDTYPE previousItemId, IDTYPE newItemId, + BT bean) { + return super.addItemAfter(previousItemId, newItemId, bean); + } + + /** + * Adds a new bean at the given index. + * + * The bean is used both as the item contents and as the item identifier. + * + * @param index + * Index at which the bean should be added. + * @param newItemId + * The item id for the bean to add to the container. + * @param bean + * The bean to add to the container. + * + * @return Returns the new BeanItem or null if the operation fails. + */ + @Override + public BeanItem addItemAt(int index, IDTYPE newItemId, BT bean) { + return super.addItemAt(index, newItemId, bean); + } + +} -- cgit v1.2.3