@Override public void setSort(SortParam<Object> param) { super.setSort(param); Collections.sort(rules, super.getComparator(param)); }
public void validateSelectionIndex(int i) { if (selection.length <= i) { if (dataProvider.size() <= i) { throw new ArrayIndexOutOfBoundsException(i); } else { // expand selection array, the data provider likely resized and the two got // misaligned boolean[] newSelection = new boolean[(int) dataProvider.size()]; System.arraycopy(selection, 0, newSelection, 0, selection.length); this.selection = newSelection; } } }
/** * @return a regex matcher for each search keyword */ private Matcher[] getMatchers() { if (matchers != null) { return matchers; } if (keywords == null) { return new Matcher[0]; } // build the case insensitive regex patterns matchers = new Matcher[keywords.length]; String keyword; String regex; Pattern pattern; for (int i = 0; i < keywords.length; i++) { keyword = keywords[i]; regex = ".*" + escape(keyword) + ".*"; pattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE); matchers[i] = pattern.matcher(""); } return matchers; }
/** * Returns a filtered list of items. Subclasses can override if they have a more efficient way * of filtering than in memory keyword comparison */ protected List<T> getFilteredItems() { List<T> items = getItems(); // if needed, filter if (keywords != null && keywords.length > 0) { return filterByKeywords(items); } else { // make a deep copy anyways, the catalog does not do that for us return new ArrayList<T>(items); } }
public Iterator<T> iterator(int first, int count) { List<T> items = getFilteredItems(); // global sorting Comparator<T> comparator = getComparator(getSort()); if (comparator != null) { Collections.sort(items, comparator); } // in memory paging int last = first + count; if (last > items.size()) last = items.size(); return items.subList(first, last).iterator(); }
@Override protected Comparator<RepositoryInfo> getComparator(SortParam sort) { return super.getComparator(sort); }
@Override public void onClick(AjaxRequestTarget target) { SortParam currSort = dataProvider.getSort(); Property<T> property = (Property<T>) getModelObject(); if (currSort == null || !property.getName().equals(currSort.getProperty())) { dataProvider.setSort(new SortParam(property.getName(), true)); } else { dataProvider .setSort(new SortParam(property.getName(), !currSort.isAscending())); } setSelection(false); target.addComponent(listContainer); }
private List<T> filterByKeywords(List<T> items) { List<T> result = new ArrayList<T>(); final Matcher[] matchers = getMatchers(); List<Property<T>> properties = getProperties(); for (T item : items) { ITEM: // find any match of any pattern over any property for (Property<T> property : properties) { if (property.isSearchable()) { Object value = property.getPropertyValue(item); if (value != null) { // brute force check for keywords for (Matcher matcher : matchers) { matcher.reset(String.valueOf(value)); if (matcher.matches()) { result.add(item); break ITEM; } } } } } } return result; }
/** Sets back to the first page, clears the selection and */ public void reset() { dataView.setCurrentPage(0); clearSelection(); dataProvider.setSort(null); }
/** Returns only the properties that have been marked as visible */ List<Property<T>> getVisibleProperties() { List<Property<T>> results = new ArrayList<Property<T>>(); for (Property<T> p : getProperties()) { if (p.isVisible()) results.add(p); } return results; }
/** * Returns the size of the filtered item collection * * @see org.apache.wicket.markup.repeater.data.IDataProvider#size() */ @Override public long size() { return getFilteredItems().size(); }
/** * Returns the global size of the collection, without filtering it * * @return */ public int fullSize() { return getItems().size(); }
/** * Provides catalog access for the provider (cannot be stored as a field, this class is going to * be serialized) * * @return */ protected Catalog getCatalog() { return getApplication().getCatalog(); }
/** @see org.apache.wicket.markup.repeater.data.IDataProvider#iterator(int, int) */ @Override public Iterator<T> iterator(long first, long count) { List<T> items = getFilteredItems(); // global sorting Comparator<T> comparator = getComparator(getSort()); if (comparator != null) { Collections.sort(items, comparator); } if (items.size() <= count) { // the list has been paged for us. return items.iterator(); } // in memory paging long last = first + count; if (last > items.size()) last = items.size(); return items.subList((int) first, (int) last).iterator(); }
@Override protected Comparator<LayerInfo> getComparator(SortParam sort) { return super.getComparator(sort); } }
@Override public void onClick(AjaxRequestTarget target) { SortParam<?> currSort = dataProvider.getSort(); @SuppressWarnings("unchecked") Property<T> property = (Property<T>) getModelObject(); if (currSort == null || !property.getName().equals(currSort.getProperty())) { dataProvider.setSort(new SortParam<Object>(property.getName(), true)); } else { dataProvider.setSort( new SortParam<Object>(property.getName(), !currSort.isAscending())); } setSelection(false); target.add(listContainer); } };
/** * Returns a filtered list of items. Subclasses can override if they have a more efficient way * of filtering than in memory keyword comparison * * @return */ protected List<T> getFilteredItems() { List<T> items = getItems(); // if needed, filter if (keywords != null && keywords.length > 0) { return filterByKeywords(items); } else { // make a deep copy anyways, the catalog does not do that for us return new ArrayList<T>(items); } }
private List<T> filterByKeywords(List<T> items) { List<T> result = new ArrayList<T>(); final Matcher[] matchers = getMatchers(); List<Property<T>> properties = getProperties(); for (T item : items) { ITEM: // find any match of any pattern over any property for (Property<T> property : properties) { if(property.isSearchable()) { Object value = property.getPropertyValue(item); if (value != null) { // brute force check for keywords for (Matcher matcher : matchers) { matcher.reset(String.valueOf(value)); if (matcher.matches()) { result.add(item); break ITEM; } } } } } } return result; }
/** * Sets back to the first page, clears the selection and */ public void reset() { dataView.setCurrentPage(0); clearSelection(); dataProvider.setSort(null); }
/** * Returns only the properties that have been marked as visible * * @return */ List<Property<T>> getVisibleProperties() { List<Property<T>> results = new ArrayList<Property<T>>(); for (Property<T> p : getProperties()) { if (p.isVisible()) results.add(p); } return results; }