From: Artur Signell Date: Mon, 14 Dec 2009 12:27:07 +0000 (+0000) Subject: Added generics to BeanItem for #3717 X-Git-Tag: 6.7.0.beta1~2166 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=b8358a67c01f9f7b46fd85ada9700334d12cfd82;p=vaadin-framework.git Added generics to BeanItem for #3717 svn changeset:10280/svn branch:6.2 --- diff --git a/src/com/vaadin/data/util/BeanItem.java b/src/com/vaadin/data/util/BeanItem.java index 5e12bc3c1d..816a1c1c96 100644 --- a/src/com/vaadin/data/util/BeanItem.java +++ b/src/com/vaadin/data/util/BeanItem.java @@ -23,12 +23,12 @@ import com.vaadin.data.Property; * @since 3.0 */ @SuppressWarnings("serial") -public class BeanItem extends PropertysetItem { +public class BeanItem extends PropertysetItem { /** * The bean which this Item is based on. */ - private final Object bean; + private final BT bean; /** *

@@ -47,7 +47,7 @@ public class BeanItem extends PropertysetItem { * the Java Bean to copy properties from. * */ - public BeanItem(Object bean) { + public BeanItem(BT bean) { this(bean, getPropertyDescriptors(bean.getClass())); } @@ -63,7 +63,7 @@ public class BeanItem extends PropertysetItem { * @param propertyDescriptors * pre-computed property descriptors */ - BeanItem(Object bean, + BeanItem(BT bean, LinkedHashMap propertyDescriptors) { this.bean = bean; @@ -98,7 +98,7 @@ public class BeanItem extends PropertysetItem { * @param propertyIds * id of the property. */ - public BeanItem(Object bean, Collection propertyIds) { + public BeanItem(BT bean, Collection propertyIds) { this.bean = bean; @@ -140,7 +140,7 @@ public class BeanItem extends PropertysetItem { * @param propertyIds * ids of the properties. */ - public BeanItem(Object bean, String[] propertyIds) { + public BeanItem(BT bean, String[] propertyIds) { this(bean, Arrays.asList(propertyIds)); } @@ -187,7 +187,7 @@ public class BeanItem extends PropertysetItem { * * @return the bean object. */ - public Object getBean() { + public BT getBean() { return bean; } diff --git a/src/com/vaadin/data/util/BeanItemContainer.java b/src/com/vaadin/data/util/BeanItemContainer.java index 2575615232..10d3525581 100644 --- a/src/com/vaadin/data/util/BeanItemContainer.java +++ b/src/com/vaadin/data/util/BeanItemContainer.java @@ -41,7 +41,7 @@ public class BeanItemContainer implements Indexed, Sortable, Filterable, // filtered and unfiltered item IDs private ArrayList list = new ArrayList(); private ArrayList allItems = new ArrayList(); - private final Map beanToItem = new HashMap(); + private final Map> beanToItem = new HashMap>(); // internal data model to obtain property IDs etc. private final Class type; @@ -120,7 +120,7 @@ public class BeanItemContainer implements Indexed, Sortable, Filterable, * * @see com.vaadin.data.Container.Indexed#addItemAt(int, Object) */ - public BeanItem addItemAt(int index, Object newItemId) + public BeanItem addItemAt(int index, Object newItemId) throws UnsupportedOperationException { if (index < 0 || index > size()) { return null; @@ -146,7 +146,7 @@ public class BeanItemContainer implements Indexed, Sortable, Filterable, * Id of the new item to be added. * @return Returns new item or null if the operation fails. */ - private BeanItem addItemAtInternalIndex(int index, Object newItemId) { + private BeanItem addItemAtInternalIndex(int index, Object newItemId) { // Make sure that the Item has not been created yet if (allItems.contains(newItemId)) { return null; @@ -155,7 +155,7 @@ public class BeanItemContainer implements Indexed, Sortable, Filterable, BT pojo = (BT) newItemId; // "list" will be updated in filterAll() allItems.add(index, pojo); - BeanItem beanItem = new BeanItem(pojo, model); + BeanItem beanItem = new BeanItem(pojo, model); beanToItem.put(pojo, beanItem); // add listeners to be able to update filtering on property changes for (Filter filter : filters) { @@ -196,7 +196,7 @@ public class BeanItemContainer implements Indexed, Sortable, Filterable, * * @see com.vaadin.data.Container.Ordered#addItemAfter(Object, Object) */ - public BeanItem addItemAfter(Object previousItemId, Object newItemId) + public BeanItem addItemAfter(Object previousItemId, Object newItemId) throws UnsupportedOperationException { // only add if the previous item is visible if (containsId(previousItemId)) { @@ -273,7 +273,7 @@ public class BeanItemContainer implements Indexed, Sortable, Filterable, * * @see com.vaadin.data.Container#addItem(Object) */ - public BeanItem addBean(BT bean) { + public BeanItem addBean(BT bean) { return addItem(bean); } @@ -284,7 +284,8 @@ public class BeanItemContainer implements Indexed, Sortable, Filterable, * * @see com.vaadin.data.Container#addItem(Object) */ - public BeanItem addItem(Object itemId) throws UnsupportedOperationException { + public BeanItem addItem(Object itemId) + throws UnsupportedOperationException { if (size() > 0) { // add immediately after last visible item int lastIndex = allItems.indexOf(lastItemId()); @@ -307,7 +308,7 @@ public class BeanItemContainer implements Indexed, Sortable, Filterable, return model.keySet(); } - public BeanItem getItem(Object itemId) { + public BeanItem getItem(Object itemId) { return beanToItem.get(itemId); } @@ -323,7 +324,7 @@ public class BeanItemContainer implements Indexed, Sortable, Filterable, allItems.clear(); list.clear(); // detach listeners from all BeanItems - for (BeanItem item : beanToItem.values()) { + for (BeanItem item : beanToItem.values()) { removeAllValueChangeListeners(item); } beanToItem.clear(); @@ -350,7 +351,7 @@ public class BeanItemContainer implements Indexed, Sortable, Filterable, return true; } - private void addValueChangeListener(BeanItem beanItem, Object propertyId) { + private void addValueChangeListener(BeanItem beanItem, Object propertyId) { Property property = beanItem.getItemProperty(propertyId); if (property instanceof ValueChangeNotifier) { // avoid multiple notifications for the same property if @@ -361,14 +362,14 @@ public class BeanItemContainer implements Indexed, Sortable, Filterable, } } - private void removeValueChangeListener(BeanItem item, Object propertyId) { + private void removeValueChangeListener(BeanItem item, Object propertyId) { Property property = item.getItemProperty(propertyId); if (property instanceof ValueChangeNotifier) { ((ValueChangeNotifier) property).removeListener(this); } } - private void removeAllValueChangeListeners(BeanItem item) { + private void removeAllValueChangeListeners(BeanItem item) { for (Object propertyId : item.getItemPropertyIds()) { removeValueChangeListener(item, propertyId); } @@ -448,7 +449,7 @@ public class BeanItemContainer implements Indexed, Sortable, Filterable, list = (ArrayList) allItems.clone(); } // listen to change events to be able to update filtering - for (BeanItem item : beanToItem.values()) { + for (BeanItem item : beanToItem.values()) { addValueChangeListener(item, propertyId); } Filter f = new Filter(propertyId, filterString, ignoreCase, @@ -493,7 +494,7 @@ public class BeanItemContainer implements Indexed, Sortable, Filterable, if (!filters.isEmpty()) { filters = new HashSet(); // stop listening to change events for any property - for (BeanItem item : beanToItem.values()) { + for (BeanItem item : beanToItem.values()) { removeAllValueChangeListeners(item); } filterAll(); @@ -510,7 +511,7 @@ public class BeanItemContainer implements Indexed, Sortable, Filterable, } } // stop listening to change events for the property - for (BeanItem item : beanToItem.values()) { + for (BeanItem item : beanToItem.values()) { removeValueChangeListener(item, propertyId); } filterAll();