/** * @see java.lang.Object#equals(java.lang.Object) */ public boolean equals(Object rhs) { if (rhs instanceof SortParam) { SortParam param = (SortParam)rhs; return getProperty().equals(param.getProperty()) && isAscending() == param.isAscending(); } return false; }
public Iterator iterator(int first, int count) { List list = getList(); final SortParam sortParam = getSort(); if (sortParam != null) { if (list != listModel.getObject() || // Synthesized list. Always sort. lastSortParam == null || // Haven't sorted yet. !lastSortParam.getProperty().equals(sortParam.getProperty()) || // Sort params changed. lastSortParam.isAscending() != sortParam.isAscending()) { lastSortParam = new SortParam(sortParam.getProperty(), sortParam.isAscending()); ElementMetaData property = metaData.findElement(sortParam.getProperty()); Collections.sort(list, new PropertyComparator(property, sortParam.isAscending())); } } return list.subList(first, first + count).iterator(); }
@Override public String toString() { return "[SingleSortState sort=" + ((param == null) ? "null" : param.toString()) + ']'; }
@Override public void setPropertySortOrder(final T property, final SortOrder order) { Args.notNull(property, "property"); Args.notNull(order, "order"); if (order == SortOrder.NONE) { if ((param != null) && property.equals(param.getProperty())) { param = null; } } else { param = new SortParam<>(property, order == SortOrder.ASCENDING); } }
private static boolean isGroupedBy(SortParam groupParam, String property) { return property != null && groupParam != null && groupParam.getProperty() != null && property.equals(groupParam.getProperty()); }
@Override public Object getObject() { if (stateLocator instanceof IGroupStateLocator) { SortParam groupParam = ((IGroupStateLocator) stateLocator).getGroupParam(); if (!isGroupedBy(groupParam, property)) { return "group-by group-by-none"; } if (groupParam.isAscending()) { return "group-by group-by-asc"; } return "group-by group-by-desc"; } return ""; } }
public SortablePropertyComparator(S property, boolean ascending) { this(new SortParam<S>(property, ascending)); }
@Override protected void onSortChanged() { super.onSortChanged(); getTable().setCurrentPage(0); // reset group if (stateLocator instanceof IGroupStateLocator) { IGroupStateLocator locator = (IGroupStateLocator) stateLocator; if (isGroupedBy(locator.getGroupParam(), groupBy)) { boolean ascending = locator.getGroupParam().isAscending(); locator.setGroupParam(new SortParam(groupBy, !ascending)); locator.getSortState().setPropertySortOrder("", SortOrder.NONE); } } } };
/** * @see java.lang.Object#toString() */ public String toString() { return new StringBuffer().append("[SortParam property=").append(getProperty()).append( " ascending=").append(asc).append("]").toString(); } }
@SuppressWarnings({ "unchecked", "rawtypes" }) protected int compare(final IModel<Comparable> model1, final IModel<Comparable> model2) { int result; if (model1.getObject() == null && model2.getObject() == null) { result = 0; } else if (model1.getObject() == null) { result = 1; } else if (model2.getObject() == null) { result = -1; } else { result = model1.getObject().compareTo(model2.getObject()); } result = provider.getSort().isAscending() ? result : -result; return result; }
/** * @see org.apache.wicket.extensions.markup.html.repeater.data.sort.ISortState#setPropertySortOrder(java.lang.String, * int) */ public void setPropertySortOrder(String property, int dir) { if (property == null) { throw new IllegalArgumentException("argument [property] cannot be null"); } param = new SortParam(property, dir == ISortState.ASCENDING); }
private void switchGroupState(IGroupStateLocator groupStateLocator, String groupProperty) { SortParam groupParam = groupStateLocator.getGroupParam(); if (groupParam == null || !groupProperty.equals(groupParam.getProperty())) { groupParam = new SortParam(groupProperty, true); } else { groupParam = null; } groupStateLocator.setGroupParam(groupParam); // reset sort state ISortState sortState = groupStateLocator.getSortState(); if (!SortOrder.NONE.equals(sortState.getPropertySortOrder(groupProperty))) { if (sortState instanceof SingleSortState) { ((SingleSortState) sortState).setSort(null); } } }
protected Comparator<T> getComparator(final SortParam<String> sortParam, final SortParam<String> secondSortParam) { final String sortProperty = sortParam != null ? sortParam.getProperty() : null; final boolean ascending = sortParam != null ? sortParam.isAscending() : true; final String secondSortProperty = secondSortParam != null ? secondSortParam.getProperty() : null; final boolean secondAscending = secondSortParam != null ? secondSortParam.isAscending() : true; return new MyBeanComparator<T>(sortProperty, ascending, secondSortProperty, secondAscending); }
@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 void sortList(final List<VacationDO> 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<VacationDO> comp = getComparator(sp, secondSortParam); Collections.sort(list, comp); } this.sortParam = sp; }
/** * Returns a comparator given the sort property. * * @param sort */ protected Comparator<T> getComparator(SortParam<?> sort) { if (sort == null) { return null; } Property<T> property = getProperty(sort); if (property != null) { Comparator<T> comparator = property.getComparator(); if (comparator != null) { if (!sort.isAscending()) return new ReverseComparator<T>(comparator); else return comparator; } } LOGGER.log(Level.WARNING, "Could not find any comparator " + "for sort property " + sort); return null; }
@Override protected Map<String, String> load() { return groupRestClient.search(SyncopeConstants.ROOT_REALM, null, 1, MAX_GROUP_LIST_CARDINALITY, new SortParam<>("name", true), null).stream().collect(Collectors.toMap(GroupTO::getKey, GroupTO::getName)); } };
/** * @see java.lang.Object#toString() */ public String toString() { return "[SingleSortState sort=" + ((param == null) ? "null" : param.toString()) + "]"; }
protected Comparator<FFPAccountingDO> getComparator(final SortParam<String> sortParam, final SortParam<String> secondSortParam) { final String sortProperty = sortParam != null ? sortParam.getProperty() : null; final boolean ascending = sortParam != null ? sortParam.isAscending() : true; final String secondSortProperty = secondSortParam != null ? secondSortParam.getProperty() : null; final boolean secondAscending = secondSortParam != null ? secondSortParam.isAscending() : true; return new MyBeanComparator<FFPAccountingDO>(sortProperty, ascending, secondSortProperty, secondAscending); }
@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); } };