public class BeanItemContainer<BT> implements Indexed, Sortable, Filterable,
ItemSetChangeNotifier, ValueChangeListener {
// filtered and unfiltered item IDs
- private ArrayList<BT> list = new ArrayList<BT>();
+ private ArrayList<BT> filteredItems = new ArrayList<BT>();
private ArrayList<BT> allItems = new ArrayList<BT>();
private final Map<BT, BeanItem<BT>> beanToItem = new HashMap<BT, BeanItem<BT>>();
}
public BT getIdByIndex(int index) {
- return list.get(index);
+ return filteredItems.get(index);
}
public int indexOfId(Object itemId) {
- return list.indexOf(itemId);
+ return filteredItems.indexOf(itemId);
}
/**
public boolean containsId(Object itemId) {
// only look at visible items after filtering
- return list.contains(itemId);
+ return filteredItems.contains(itemId);
}
public Property getContainerProperty(Object itemId, Object propertyId) {
}
public Collection<BT> getItemIds() {
- return (Collection<BT>) list.clone();
+ return (Collection<BT>) filteredItems.clone();
}
public Class<?> getType(Object propertyId) {
public boolean removeAllItems() throws UnsupportedOperationException {
allItems.clear();
- list.clear();
+ filteredItems.clear();
// detach listeners from all BeanItems
for (BeanItem<BT> item : beanToItem.values()) {
removeAllValueChangeListeners(item);
removeAllValueChangeListeners(getItem(itemId));
// remove item
beanToItem.remove(itemId);
- list.remove(itemId);
+ filteredItems.remove(itemId);
fireItemSetChange();
return true;
}
}
public int size() {
- return list.size();
+ return filteredItems.size();
}
public Collection<Object> getSortableContainerPropertyIds() {
public void addContainerFilter(Object propertyId, String filterString,
boolean ignoreCase, boolean onlyMatchPrefix) {
if (filters.isEmpty()) {
- list = (ArrayList<BT>) allItems.clone();
+ filteredItems = (ArrayList<BT>) allItems.clone();
}
// listen to change events to be able to update filtering
for (BeanItem<BT> item : beanToItem.values()) {
*/
protected void filterAll() {
// avoid notification if the filtering had no effect
- List<BT> originalItems = list;
+ List<BT> originalItems = filteredItems;
// it is somewhat inefficient to do a (shallow) clone() every time
- list = (ArrayList<BT>) allItems.clone();
+ filteredItems = (ArrayList<BT>) allItems.clone();
for (Filter f : filters) {
filter(f);
}
// check if exactly the same items are there after filtering to avoid
// unnecessary notifications
// this may be slow in some cases as it uses BT.equals()
- if (!originalItems.equals(list)) {
+ if (!originalItems.equals(filteredItems)) {
fireItemSetChange();
}
}
protected void filter(Filter f) {
- Iterator<BT> iterator = list.iterator();
+ Iterator<BT> iterator = filteredItems.iterator();
while (iterator.hasNext()) {
BT bean = iterator.next();
if (!f.passesFilter(getItem(bean))) {