From 6176acd274830fb343bd11739e6036b4f04e2dc0 Mon Sep 17 00:00:00 2001 From: Henri Sara Date: Tue, 8 Mar 2011 08:31:35 +0000 Subject: [PATCH] #6527 Container refactoring: default implementations (throw new UnsupportedOperationException()) for adding/removing items or container properties in AbstractInMemoryContainer, subclasses need to override to support these operations svn changeset:17656/svn branch:6.6 --- .../data/util/AbstractBeanContainer.java | 48 ++----------- .../data/util/AbstractInMemoryContainer.java | 72 +++++++++++++++++++ src/com/vaadin/data/util/BeanContainer.java | 16 ----- .../vaadin/data/util/BeanItemContainer.java | 29 +++----- 4 files changed, 86 insertions(+), 79 deletions(-) diff --git a/src/com/vaadin/data/util/AbstractBeanContainer.java b/src/com/vaadin/data/util/AbstractBeanContainer.java index 197e844dde..31ad37a57f 100644 --- a/src/com/vaadin/data/util/AbstractBeanContainer.java +++ b/src/com/vaadin/data/util/AbstractBeanContainer.java @@ -26,8 +26,8 @@ import com.vaadin.data.Property.ValueChangeNotifier; * *

* 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. + * the used JavaBean class and explicitly adding or removing properties is not + * supported. Only beans of the same type can be added to the container. *

* *

@@ -216,29 +216,12 @@ public abstract class AbstractBeanContainer extends return model.keySet(); } - /** - * Unsupported operation. Properties are determined by the introspecting the - * bean class. - */ - public boolean addContainerProperty(Object propertyId, Class type, - Object defaultValue) throws UnsupportedOperationException { - throw new UnsupportedOperationException(); - } - - /** - * Unsupported operation. Properties are determined by the introspecting the - * bean class. - */ - public boolean removeContainerProperty(Object propertyId) - throws UnsupportedOperationException { - throw new UnsupportedOperationException(); - } - /* * (non-Javadoc) * * @see com.vaadin.data.Container#removeAllItems() */ + @Override public boolean removeAllItems() { int origSize = size(); @@ -303,6 +286,7 @@ public abstract class AbstractBeanContainer extends * * @see com.vaadin.data.Container#removeItem(java.lang.Object) */ + @Override public boolean removeItem(Object itemId) { int origSize = size(); Item item = getItem(itemId); @@ -425,22 +409,6 @@ public abstract class AbstractBeanContainer extends } } - /** - * Unsupported operation. Use other methods to add items. - */ - public Object addItemAfter(Object previousItemId) - throws UnsupportedOperationException { - throw new UnsupportedOperationException(); - } - - /** - * Unsupported operation. Beans should be added through - * {@code addItemAt(int, ...)}. - */ - public Object addItemAt(int index) throws UnsupportedOperationException { - throw new UnsupportedOperationException(); - } - /* * (non-Javadoc) * @@ -471,14 +439,6 @@ public abstract class AbstractBeanContainer extends super.setItemSorter(itemSorter); } - /** - * Unsupported operation. See subclasses of {@link AbstractBeanContainer} - * for the correct way to add items. - */ - public Object addItem() throws UnsupportedOperationException { - throw new UnsupportedOperationException(); - } - @Override protected void registerNewItem(int position, IDTYPE itemId, BeanItem item) { diff --git a/src/com/vaadin/data/util/AbstractInMemoryContainer.java b/src/com/vaadin/data/util/AbstractInMemoryContainer.java index ae768cd497..58e2b5131a 100644 --- a/src/com/vaadin/data/util/AbstractInMemoryContainer.java +++ b/src/com/vaadin/data/util/AbstractInMemoryContainer.java @@ -19,6 +19,20 @@ import com.vaadin.data.Item; * this class, inherit {@link AbstractContainer}, or implement the * {@link Container} interface 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 + * {@link #internalAddItemAfter(Object, Object, Item)}, + * {@link #internalAddItemAt(int, Object, Item)}, + * {@link #internalAddItemAtEnd(Object, Item, boolean)}, + * {@link #internalRemoveItem(Object)} and {@link #internalRemoveAllItems()} + * methods. + * + * By default, adding and removing container properties is not supported, and + * subclasses need to implement {@link #getContainerPropertyIds()}. Optionally, + * subclasses can override {@link #addContainerProperty(Object, Class, Object)} + * and {@link #removeContainerProperty(Object)} to implement them. + * * Features: *