Example usage for org.apache.wicket.extensions.markup.html.repeater.util SortParam getProperty

List of usage examples for org.apache.wicket.extensions.markup.html.repeater.util SortParam getProperty

Introduction

In this page you can find the example usage for org.apache.wicket.extensions.markup.html.repeater.util SortParam getProperty.

Prototype

public T getProperty() 

Source Link

Usage

From source file:ca.travelagency.components.dataprovider.DataProvider.java

License:Apache License

private OrderBy getOrderBy() {
    SortParam<String> sortParam = getSort();
    return sortParam == null ? null : OrderBy.make(sortParam.getProperty(), sortParam.isAscending());
}

From source file:com.doculibre.constellio.wicket.components.sort.SortableListDataProvider.java

License:Open Source License

/**
 * @see org.apache.wicket.markup.repeater.data.IDataProvider#iterator(int,
 *      int)/*from  w  ww .  j  a va 2  s.c  om*/
 */
public Iterator<? extends Object> iterator(int first, int count) {
    SortParam sortParam = getSort();
    String sortProperty = sortParam != null ? sortParam.getProperty() : null;
    Boolean sortAscending = sortParam != null ? sortParam.isAscending() : null;
    List<? extends Object> list = getSortedList(sortProperty, sortAscending);

    int toIndex = first + count;
    if (toIndex > list.size()) {
        toIndex = list.size();
    }
    return list.subList(first, toIndex).listIterator();
}

From source file:com.doculibre.constellio.wicket.components.sort.SortableListDataProvider.java

License:Open Source License

/**
 * @see org.apache.wicket.markup.repeater.data.IDataProvider#size()
 *//* w w  w .j  a v  a  2 s  . c  o  m*/
public int size() {
    SortParam sortParam = getSort();
    String sortProperty = sortParam != null ? sortParam.getProperty() : null;
    Boolean sortAscending = sortParam != null ? sortParam.isAscending() : null;
    List<? extends Object> list = getSortedList(sortProperty, sortAscending);
    return list.size();
}

From source file:com.evolveum.midpoint.web.component.data.BaseSortableDataProvider.java

License:Apache License

protected ObjectPaging createPaging(long first, long count) {
    SortParam sortParam = getSort();
    OrderDirection order;//from   www  . j a v a2  s  .co  m
    if (sortParam.isAscending()) {
        order = OrderDirection.ASCENDING;
    } else {
        order = OrderDirection.DESCENDING;
    }

    return ObjectPaging.createPaging(WebMiscUtil.safeLongToInteger(first), WebMiscUtil.safeLongToInteger(count),
            (String) sortParam.getProperty(), SchemaConstantsGenerated.NS_COMMON, order);
}

From source file:com.evolveum.midpoint.web.component.util.AssignmentListDataProvider.java

License:Apache License

@SuppressWarnings("unchecked")
protected <V extends Comparable<V>> void sort(List<ContainerValueWrapper<AssignmentType>> list) {
    Collections.sort(list, new Comparator<ContainerValueWrapper<AssignmentType>>() {
        @Override//w ww .j  av  a 2 s  . co  m
        public int compare(ContainerValueWrapper<AssignmentType> o1, ContainerValueWrapper<AssignmentType> o2) {
            SortParam<String> sortParam = getSort();
            String propertyName = sortParam.getProperty();
            V prop1, prop2;
            try {
                prop1 = (V) PropertyUtils.getProperty(o1.getContainerValue().asContainerable(), propertyName);
                prop2 = (V) PropertyUtils.getProperty(o2.getContainerValue().asContainerable(), propertyName);
            } catch (RuntimeException | IllegalAccessException | InvocationTargetException
                    | NoSuchMethodException e) {
                throw new SystemException("Couldn't sort the object list: " + e.getMessage(), e);
            }
            int comparison = ObjectUtils.compare(prop1, prop2, true);
            return sortParam.isAscending() ? comparison : -comparison;
        }
    });
}

From source file:com.evolveum.midpoint.web.component.util.MultivalueContainerListDataProvider.java

License:Apache License

@SuppressWarnings("unchecked")
protected <V extends Comparable<V>> void sort(List<ContainerValueWrapper<C>> list) {
    Collections.sort(list, new Comparator<ContainerValueWrapper<C>>() {
        @Override/*from w w  w .j a  v  a  2  s . c  om*/
        public int compare(ContainerValueWrapper<C> o1, ContainerValueWrapper<C> o2) {
            SortParam<String> sortParam = getSort();
            String propertyName = sortParam.getProperty();
            V prop1, prop2;
            try {
                prop1 = (V) PropertyUtils.getProperty(o1.getContainerValue().asContainerable(), propertyName);
                prop2 = (V) PropertyUtils.getProperty(o2.getContainerValue().asContainerable(), propertyName);
            } catch (RuntimeException | IllegalAccessException | InvocationTargetException
                    | NoSuchMethodException e) {
                throw new SystemException("Couldn't sort the object list: " + e.getMessage(), e);
            }
            int comparison = ObjectUtils.compare(prop1, prop2, true);
            return sortParam.isAscending() ? comparison : -comparison;
        }
    });
}

From source file:com.googlecode.wicketwebbeans.databinder.DataSorter.java

License:Apache License

public void buildOrdered(Criteria criteria) {
    String property;/*from ww w  .j  av a 2s . c  o  m*/
    SortParam sort = sortState.getSort();
    if (sort != null && sort.getProperty() != null) {
        property = sort.getProperty();
        asc = sort.isAscending();
    } else {
        property = defaultProperty;
    }
    if (property != null) {
        if (property.contains(".")) {
            String[] path = property.split("\\.");
            for (int ii = 0; ii < path.length - 1; ii++) {
                criteria.createAlias(path[ii], path[ii]);
            }
        }

        criteria.addOrder(asc ? Order.asc(property) : Order.desc(property));
    }
}

From source file:com.romeikat.datamessie.core.base.ui.dataprovider.AbstractTableDataProvider.java

License:Open Source License

private List<TableRow<X, Y, Z>> getTableRows() {
    final ISingleTable<X, Y, Z> table = tableModel.getObject();
    final SortParam<Y> sortParam = getSort();
    final List<X> rowHeaders;

    // Default sorting
    if (sortParam == null) {
        final Comparator<? super X> rowHeaderComparator = getRowHeaderComparator();
        rowHeaders = table.getRowHeadersSorted(rowHeaderComparator);
    }//from   w ww. ja  v a2 s.  c o  m
    // Sorting by sort state
    else {
        final Y sortProperty = sortParam.getProperty();
        final Comparator<? super X> rowHeaderComparator = getRowHeaderComparator();
        final Comparator<? super Z> columnValueComparator;
        if (sortParam.isAscending()) {
            columnValueComparator = new AscendingComparator<Z>();
        } else {
            columnValueComparator = new DescendingComparator<Z>();
        }
        // Row headers for cells with values
        final List<X> rowHeadersWithValues = table.getRowHeadersSorted(sortProperty, rowHeaderComparator,
                columnValueComparator);
        // Row headers for cells without values
        final List<X> rowHeadersWithoutValues = table.getRowHeadersSorted(rowHeaderComparator);
        rowHeadersWithoutValues.removeAll(rowHeadersWithValues);
        // All row headers
        rowHeaders = Lists
                .newArrayListWithExpectedSize(rowHeadersWithValues.size() + rowHeadersWithoutValues.size());
        rowHeaders.addAll(rowHeadersWithValues);
        rowHeaders.addAll(rowHeadersWithoutValues);
    }

    final List<TableRow<X, Y, Z>> tableRows = table.getTableRows(rowHeaders);
    return tableRows;
}

From source file:com.senacor.wbs.web.project.SortableListDataProvider.java

License:Apache License

public Iterator<E> iterator(final int first, final int count) {
    final SortParam sp = getSort();
    SortUtils.sort(data, sp.getProperty(), sp.isAscending(), getLocale());
    int toIndex = first + count;
    if (toIndex > data.size()) {
        toIndex = data.size();/* w  ww .  j  a va  2 s. co  m*/
    }
    return data.subList(first, toIndex).listIterator();
}

From source file:com.socialsite.dao.hibernate.AbstractDaoImpl.java

License:Open Source License

/**
 * a helper method to find the list of item matching the filter
 * /*from  w w  w  .  j a va 2s.c  o m*/
 * @param filter
 *            filter text
 * @param first
 *            first index of the resul
 * @param count
 *            count
 * @param sortParam
 *            sorting is done based on this property
 * @param clazz
 *            class of the item
 * @param field
 *            field that will be matched with the criteria
 * @return list of item matching the filter text
 */
@SuppressWarnings("unchecked")
protected List find(String filter, final int first, final int count, final SortParam sortParam,
        final Class clazz, final String field) {
    // avoids the NPE
    filter = filter == null ? "" : filter;

    // order
    final Order order = sortParam.isAscending() ? Order.asc(sortParam.getProperty())
            : Order.desc(sortParam.getProperty());
    final Criteria criteria = getSession().createCriteria(clazz);
    criteria.setFirstResult(first);
    criteria.setMaxResults(count);
    criteria.add(Restrictions.ilike(field, filter, MatchMode.ANYWHERE));
    criteria.addOrder(order);
    return criteria.list();
}