/** * Remove a specific container filter and re-filter the view (if necessary). * * This can be used to implement * {@link Filterable#removeContainerFilter(Container.Filter)} . */ protected void removeFilter(Filter filter) { for (Iterator<Filter> iterator = getFilters().iterator(); iterator .hasNext();) { Filter f = iterator.next(); if (f.equals(filter)) { iterator.remove(); filterAll(); return; } } }
/** * Remove all container filters for all properties and re-filter the view. * * This can be used to implement * {@link Filterable#removeAllContainerFilters()}. */ protected void removeAllFilters() { if (getFilters().isEmpty()) { return; } getFilters().clear(); filterAll(); }
/** * Adds a container filter and re-filter the view. * * The filter must implement Filter and its sub-filters (if any) must also * be in-memory filterable. * * This can be used to implement * {@link Filterable#addContainerFilter(Container.Filter)} and optionally * also * {@link SimpleFilterable#addContainerFilter(Object, String, boolean, boolean)} * (with {@link SimpleStringFilter}). * * Note that in some cases, incompatible filters cannot be detected when * added and an {@link UnsupportedFilterException} may occur when performing * filtering. * * @throws UnsupportedFilterException * if the filter is detected as not supported by the container */ protected void addFilter(Filter filter) throws UnsupportedFilterException { getFilters().add(filter); filterAll(); }
/** * Remove all container filters for a given property identifier and * re-filter the view. This also removes filters applying to multiple * properties including the one identified by propertyId. * * This can be used to implement * {@link Filterable#removeContainerFilters(Object)}. * * @param propertyId * @return Collection<Filter> removed filters */ protected Collection<Filter> removeFilters(Object propertyId) { if (getFilters().isEmpty() || propertyId == null) { return Collections.emptyList(); } List<Filter> removedFilters = new LinkedList<Filter>(); for (Iterator<Filter> iterator = getFilters().iterator(); iterator .hasNext();) { Filter f = iterator.next(); if (f.appliesToProperty(propertyId)) { removedFilters.add(f); iterator.remove(); } } if (!removedFilters.isEmpty()) { filterAll(); return removedFilters; } return Collections.emptyList(); }
/** * Sort base implementation to be used to implement {@link Sortable}. * * Subclasses should call this from a public * {@link #sort(Object[], boolean[])} method when implementing Sortable. * * @see Container.Sortable#sort(java.lang.Object[], boolean[]) */ protected void sortContainer(Object[] propertyId, boolean[] ascending) { if (!(this instanceof Sortable)) { throw new UnsupportedOperationException( "Cannot sort a Container that does not implement Sortable"); } // Set up the item sorter for the sort operation getItemSorter().setSortProperties((Sortable) this, propertyId, ascending); // Perform the actual sort doSort(); // Post sort updates if (isFiltered()) { filterAll(); } else { fireItemSetChange(); } }
/** * Add an item at the end of the container, and perform filtering if * necessary. An event is fired if the filtered view changes. * * @param newItemId * @param item * new item to add * @param filter * true to perform filtering and send event after adding the * item, false to skip these operations for batch inserts - if * false, caller needs to make sure these operations are * performed at the end of the batch * @return item added or null if no item was added */ protected ITEMCLASS internalAddItemAtEnd(ITEMIDTYPE newItemId, ITEMCLASS item, boolean filter) { ITEMCLASS newItem = internalAddAt(getAllItemIds().size(), newItemId, item); if (newItem != null && filter) { // TODO filter only this item, use fireItemAdded() filterAll(); if (!isFiltered()) { // TODO hack: does not detect change in filterAll() in this case fireItemAdded(indexOfId(newItemId), newItemId, item); } } return newItem; }
filterAll(); if (!isFiltered()) {