* @since 3.0
*/
@SuppressWarnings("serial")
-public class BeanItem extends PropertysetItem {
+public class BeanItem<BT> extends PropertysetItem {
/**
* The bean which this Item is based on.
*/
- private final Object bean;
+ private final BT bean;
/**
* <p>
* the Java Bean to copy properties from.
*
*/
- public BeanItem(Object bean) {
+ public BeanItem(BT bean) {
this(bean, getPropertyDescriptors(bean.getClass()));
}
* @param propertyDescriptors
* pre-computed property descriptors
*/
- BeanItem(Object bean,
+ BeanItem(BT bean,
LinkedHashMap<String, PropertyDescriptor> propertyDescriptors) {
this.bean = bean;
* @param propertyIds
* id of the property.
*/
- public BeanItem(Object bean, Collection<?> propertyIds) {
+ public BeanItem(BT bean, Collection<?> propertyIds) {
this.bean = bean;
* @param propertyIds
* ids of the properties.
*/
- public BeanItem(Object bean, String[] propertyIds) {
+ public BeanItem(BT bean, String[] propertyIds) {
this(bean, Arrays.asList(propertyIds));
}
*
* @return the bean object.
*/
- public Object getBean() {
+ public BT getBean() {
return bean;
}
// filtered and unfiltered item IDs
private ArrayList<BT> list = new ArrayList<BT>();
private ArrayList<BT> allItems = new ArrayList<BT>();
- private final Map<BT, BeanItem> beanToItem = new HashMap<BT, BeanItem>();
+ private final Map<BT, BeanItem<BT>> beanToItem = new HashMap<BT, BeanItem<BT>>();
// internal data model to obtain property IDs etc.
private final Class<? extends BT> type;
*
* @see com.vaadin.data.Container.Indexed#addItemAt(int, Object)
*/
- public BeanItem addItemAt(int index, Object newItemId)
+ public BeanItem<BT> addItemAt(int index, Object newItemId)
throws UnsupportedOperationException {
if (index < 0 || index > size()) {
return null;
* 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<BT> addItemAtInternalIndex(int index, Object newItemId) {
// Make sure that the Item has not been created yet
if (allItems.contains(newItemId)) {
return null;
BT pojo = (BT) newItemId;
// "list" will be updated in filterAll()
allItems.add(index, pojo);
- BeanItem beanItem = new BeanItem(pojo, model);
+ BeanItem<BT> beanItem = new BeanItem<BT>(pojo, model);
beanToItem.put(pojo, beanItem);
// add listeners to be able to update filtering on property changes
for (Filter filter : filters) {
*
* @see com.vaadin.data.Container.Ordered#addItemAfter(Object, Object)
*/
- public BeanItem addItemAfter(Object previousItemId, Object newItemId)
+ public BeanItem<BT> addItemAfter(Object previousItemId, Object newItemId)
throws UnsupportedOperationException {
// only add if the previous item is visible
if (containsId(previousItemId)) {
*
* @see com.vaadin.data.Container#addItem(Object)
*/
- public BeanItem addBean(BT bean) {
+ public BeanItem<BT> addBean(BT bean) {
return addItem(bean);
}
*
* @see com.vaadin.data.Container#addItem(Object)
*/
- public BeanItem addItem(Object itemId) throws UnsupportedOperationException {
+ public BeanItem<BT> addItem(Object itemId)
+ throws UnsupportedOperationException {
if (size() > 0) {
// add immediately after last visible item
int lastIndex = allItems.indexOf(lastItemId());
return model.keySet();
}
- public BeanItem getItem(Object itemId) {
+ public BeanItem<BT> getItem(Object itemId) {
return beanToItem.get(itemId);
}
allItems.clear();
list.clear();
// detach listeners from all BeanItems
- for (BeanItem item : beanToItem.values()) {
+ for (BeanItem<BT> item : beanToItem.values()) {
removeAllValueChangeListeners(item);
}
beanToItem.clear();
return true;
}
- private void addValueChangeListener(BeanItem beanItem, Object propertyId) {
+ private void addValueChangeListener(BeanItem<BT> beanItem, Object propertyId) {
Property property = beanItem.getItemProperty(propertyId);
if (property instanceof ValueChangeNotifier) {
// avoid multiple notifications for the same property if
}
}
- private void removeValueChangeListener(BeanItem item, Object propertyId) {
+ private void removeValueChangeListener(BeanItem<BT> 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<BT> item) {
for (Object propertyId : item.getItemPropertyIds()) {
removeValueChangeListener(item, propertyId);
}
list = (ArrayList<BT>) allItems.clone();
}
// listen to change events to be able to update filtering
- for (BeanItem item : beanToItem.values()) {
+ for (BeanItem<BT> item : beanToItem.values()) {
addValueChangeListener(item, propertyId);
}
Filter f = new Filter(propertyId, filterString, ignoreCase,
if (!filters.isEmpty()) {
filters = new HashSet<Filter>();
// stop listening to change events for any property
- for (BeanItem item : beanToItem.values()) {
+ for (BeanItem<BT> item : beanToItem.values()) {
removeAllValueChangeListeners(item);
}
filterAll();
}
}
// stop listening to change events for the property
- for (BeanItem item : beanToItem.values()) {
+ for (BeanItem<BT> item : beanToItem.values()) {
removeValueChangeListener(item, propertyId);
}
filterAll();