Changeset 4664
- Timestamp:
- 03/10/14 13:41:24 (11 years ago)
- Location:
- vlo/branches/vlo-3.0/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo
- Files:
-
- 1 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
vlo/branches/vlo-3.0/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/wicket/provider/FacetFieldValuesProvider.java
r4606 r4664 17 17 package eu.clarin.cmdi.vlo.wicket.provider; 18 18 19 import com.google.common.collect.Ordering; 20 import eu.clarin.cmdi.vlo.pojo.FieldValuesOrder; 19 21 import java.util.Iterator; 20 22 import java.util.List; 21 23 import org.apache.solr.client.solrj.response.FacetField; 22 import org.apache.wicket.markup.repeater.data.IDataProvider; 24 import org.apache.solr.client.solrj.response.FacetField.Count; 25 import org.apache.wicket.extensions.markup.html.repeater.util.SortParam; 26 import org.apache.wicket.extensions.markup.html.repeater.util.SortableDataProvider; 23 27 import org.apache.wicket.model.IModel; 24 28 import org.apache.wicket.model.Model; … … 26 30 /** 27 31 * Provides facet values and counts (both through the {@link Count} object of 28 * SOLR) present on a {@link FacetField} 32 * SOLR) present on a {@link FacetField}, sortable by either count or name 29 33 * 34 * @see FieldValuesOrder 30 35 * @author twagoo 31 36 */ 32 public class FacetFieldValuesProvider implements IDataProvider<FacetField.Count> {37 public class FacetFieldValuesProvider extends SortableDataProvider<FacetField.Count, FieldValuesOrder> { 33 38 34 39 private final IModel<FacetField> model; … … 45 50 } 46 51 52 public FacetFieldValuesProvider(IModel<FacetField> model, int max) { 53 this(model, max, new SortParam<FieldValuesOrder>(FieldValuesOrder.COUNT, false)); 54 } 55 47 56 /** 48 57 * Creates a provider with a set maximum number of values … … 50 59 * @param model FacetField model to get values and counts for 51 60 * @param max maximum number of values to show 61 * @param sort initial sort property and order 52 62 */ 53 public FacetFieldValuesProvider(IModel<FacetField> model, int max ) {63 public FacetFieldValuesProvider(IModel<FacetField> model, int max, SortParam<FieldValuesOrder> sort) { 54 64 this.model = model; 55 65 this.maxNumberOfItems = max; 66 setSort(sort); 56 67 } 57 68 … … 61 72 // IGNORABLE_VALUES (like "unknown") are move to the back of the list and should only be shown when you click "more...", unless the list is too small then whe can just show them. 62 73 final List<FacetField.Count> values = model.getObject().getValues(); 63 return values.listIterator((int) first);74 return getOrdering().sortedCopy(values).listIterator((int) first); 64 75 } 65 76 … … 80 91 } 81 92 93 private Ordering getOrdering() { 94 final Ordering ordering; 95 if (getSort().getProperty() == FieldValuesOrder.COUNT) { 96 ordering = COUNT_ORDERING; 97 } else if (getSort().getProperty() == FieldValuesOrder.NAME) { 98 ordering = NAME_ORDERING; 99 } else { 100 ordering = Ordering.natural(); 101 } 102 103 if (getSort().isAscending()) { 104 return ordering; 105 } else { 106 return ordering.reverse(); 107 } 108 } 109 110 private static Ordering<FacetField.Count> COUNT_ORDERING = new Ordering<FacetField.Count>() { 111 112 @Override 113 public int compare(Count arg0, Count arg1) { 114 return Long.compare(arg0.getCount(), arg1.getCount()); 115 } 116 }; 117 118 private static Ordering<FacetField.Count> NAME_ORDERING = new Ordering<FacetField.Count>() { 119 120 @Override 121 public int compare(Count arg0, Count arg1) { 122 return arg0.getName().compareTo(arg1.getName()); 123 } 124 }; 125 82 126 }
Note: See TracChangeset
for help on using the changeset viewer.