/** * At default a new SortableDOProvider is returned. Overload this method e. g. for avoiding * LazyInitializationExceptions due to sorting. * * @param sortProperty * @param ascending */ protected ISortableDataProvider<O, String> createSortableDataProvider(final SortParam<String> sortParam, final SortParam<String> secondSortParam) { if (listPageSortableDataProvider == null) { listPageSortableDataProvider = new MyListPageSortableDataProvider<O>(sortParam, secondSortParam, this); } return listPageSortableDataProvider; }
/** * @see org.apache.wicket.markup.repeater.data.IDataProvider#size() */ @Override public long size() { if (idList == null) { reloadList(); } return this.idList != null ? this.idList.size() : 0; }
public MyListPageSortableDataProvider(final SortParam<String> sortParam, final SortParam<String> secondSortParam, final AbstractListPage<?, ?, T> listPage) { this.listPage = listPage; // set default sort if (sortParam != null) { setSort(sortParam); } else { setSort("NOSORT", SortOrder.ASCENDING); } }
this.completeList = null; // Force to load all elements from data-base (avoid lazy initialization exceptions). final SortParam<String> sp = getSort(); if (ObjectUtils.equals(sortParam, sp) == false) { reloadList(); if (baseDao instanceof BaseDao) { final List<T> list = (List<T>) ((BaseDao<?>) baseDao).getListByIds(idList.subList(fromIndex, toIndex)); sortList(list); return list.iterator(); } else { reloadList(); result = completeList; if (toIndex > idList.size()) {
private void sortList(final List<T> list) { final SortParam<String> sp = getSort(); if (sp != null && "NOSORT".equals(sp.getProperty()) == false) { if (this.sortParam != null && StringUtils.equals(this.sortParam.getProperty(), sp.getProperty()) == false) { this.secondSortParam = this.sortParam; } final Comparator<T> comp = getComparator(sp, secondSortParam); Collections.sort(list, comp); } this.sortParam = sp; }
private void reloadList() { final List<T> list = listPage.getList(); setCompleteList(list); }
public MyListPageSortableDataProvider<T> setCompleteList(final List<T> completeList) { this.completeList = completeList; this.idList = new LinkedList<Serializable>(); if (this.completeList != null) { sortList(this.completeList); for (final T entry : completeList) { this.idList.add(entry.getId()); } } return this; }
@Override protected Comparator<VisitorbookDO> getComparator(final SortParam<String> sortParam, final SortParam<String> secondSortParam) { final String sortProperty = sortParam != null ? sortParam.getProperty() : null; if ("arrive".equals(sortProperty) || "depart".equals(sortProperty)) { VisitorbookTimeComparator comparator = new VisitorbookTimeComparator(); comparator.property = sortProperty; comparator.dsc = sortParam != null ? (sortParam.isAscending() == false) : false; return comparator; } return super.getComparator(sortParam, secondSortParam); } };
public List<O> getList() { if (this.refreshResultList == false && this.resultList != null) { return this.resultList; } this.refreshResultList = false; try { this.resultList = buildList(); listPageSortableDataProvider.setCompleteList(this.resultList); if (this.resultList == null) { // An error occured: form.addError("search.error"); } return this.resultList; } catch (final Exception ex) { if (ex instanceof UserException) { final UserException userException = (UserException) ex; error(getLocalizedMessage(userException.getI18nKey(), userException.getParams())); } else { log.error(ex.getMessage(), ex); } } return this.resultList = new ArrayList<O>(); }