Changeset 4666
- Timestamp:
- 03/10/14 15:52:30 (10 years ago)
- Location:
- vlo/branches/vlo-3.0/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/wicket
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
vlo/branches/vlo-3.0/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/wicket/panels/AllFacetValuesPanel.html
r4665 r4666 27 27 <form wicket:id="options"> 28 28 <p>Sort by <select wicket:id="sort"><option>name</option><option>count</option></select></p> 29 <div>Search: <input type="text" /></div>29 <div>Search: <input wicket:id="filter" type="text" /></div> 30 30 </form> 31 31 <div wicket:id="facetValuesContainer" class="sortedFacet"> -
vlo/branches/vlo-3.0/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/wicket/panels/AllFacetValuesPanel.java
r4665 r4666 25 25 import org.apache.wicket.ajax.AjaxRequestTarget; 26 26 import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior; 27 import org.apache.wicket.ajax.form.OnChangeAjaxBehavior; 27 28 import org.apache.wicket.ajax.markup.html.AjaxFallbackLink; 28 29 import org.apache.wicket.extensions.markup.html.repeater.util.SortParam; … … 31 32 import org.apache.wicket.markup.html.form.DropDownChoice; 32 33 import org.apache.wicket.markup.html.form.Form; 34 import org.apache.wicket.markup.html.form.TextField; 33 35 import org.apache.wicket.markup.html.link.Link; 34 36 import org.apache.wicket.markup.html.panel.GenericPanel; … … 37 39 import org.apache.wicket.model.CompoundPropertyModel; 38 40 import org.apache.wicket.model.IModel; 41 import org.apache.wicket.model.Model; 39 42 import org.apache.wicket.model.PropertyModel; 40 43 … … 49 52 private final FacetFieldValuesProvider valuesProvider; 50 53 private final WebMarkupContainer valuesContainer; 54 private IModel<String> filterModel = new Model<String>(); 51 55 52 56 public AllFacetValuesPanel(String id, IModel<FacetField> model) { 53 57 super(id, model); 54 valuesProvider = new FacetFieldValuesProvider(model); 58 // create a provider that shows all values and is sorted by name by default 59 valuesProvider = new FacetFieldValuesProvider(model, Integer.MAX_VALUE, FieldValueOrderSelector.NAME_SORT) { 55 60 61 @Override 62 protected IModel<String> getFilterModel() { 63 // filters the values 64 return filterModel; 65 } 66 67 }; 68 69 // create a container for the values to allow for AJAX updates 56 70 valuesContainer = new WebMarkupContainer("facetValuesContainer"); 57 71 valuesContainer.setOutputMarkupId(true); 58 72 add(valuesContainer); 59 73 74 // create the view of the actual values 60 75 final DataView<FacetField.Count> valuesView = createValuesView("facetValue"); 61 76 valuesContainer.add(valuesView); 62 77 78 // create the form for selection sort option and entering filter string 63 79 final Form optionsForm = createOptionsForm("options"); 64 80 optionsForm.setOutputMarkupId(true); … … 101 117 final DropDownChoice<SortParam<FieldValuesOrder>> sortSelect 102 118 = new FieldValueOrderSelector("sort", new PropertyModel<SortParam<FieldValuesOrder>>(valuesProvider, "sort")); 103 sortSelect.add(new AjaxFormComponentUpdatingBehavior("onchange") {119 sortSelect.add(new OnChangeAjaxBehavior() { 104 120 105 121 @Override … … 110 126 }); 111 127 options.add(sortSelect); 128 129 final TextField filterField = new TextField("filter", filterModel); 130 filterField.add(new AjaxFormComponentUpdatingBehavior("keyup") { 131 132 @Override 133 protected void onUpdate(AjaxRequestTarget target) { 134 target.add(valuesContainer); 135 } 136 }); 137 options.add(filterField); 112 138 return options; 113 139 } -
vlo/branches/vlo-3.0/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/wicket/provider/FacetFieldValuesProvider.java
r4664 r4666 17 17 package eu.clarin.cmdi.vlo.wicket.provider; 18 18 19 import com.google.common.base.Predicate; 20 import com.google.common.collect.ImmutableList; 21 import com.google.common.collect.Iterables; 19 22 import com.google.common.collect.Ordering; 20 23 import eu.clarin.cmdi.vlo.pojo.FieldValuesOrder; … … 67 70 } 68 71 72 /** 73 * override to achieve filtering 74 * 75 * @return model of string items should begin with 76 */ 77 protected IModel<String> getFilterModel() { 78 return null; 79 } 80 69 81 @Override 70 82 public Iterator<? extends FacetField.Count> iterator(long first, long count) { 71 // TODO: From old VLO: 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. 83 // get all the values 73 84 final List<FacetField.Count> values = model.getObject().getValues(); 74 return getOrdering().sortedCopy(values).listIterator((int) first); 85 // filter results 86 final Iterable<Count> filtered = filter(values); 87 // sort what remains 88 final ImmutableList sorted = getOrdering().immutableSortedCopy(filtered); 89 // return iterator starting at specified offset 90 return sorted.listIterator((int) first); 75 91 } 76 92 77 93 @Override 78 94 public long size() { 79 // Actual value count might be higher than what we want to show 80 return Math.min(maxNumberOfItems, model.getObject().getValueCount()); 95 if (hasFilter()) { 96 final List<FacetField.Count> values = model.getObject().getValues(); 97 return Iterables.size(filter(values)); 98 } else { 99 // Use value count from Solr, faster. 100 // 101 // Actual value count might be higher than what we want to show 102 // so get minimum. 103 return Math.min(maxNumberOfItems, model.getObject().getValueCount()); 104 } 81 105 } 82 106 … … 89 113 public void detach() { 90 114 model.detach(); 115 } 116 117 private Iterable<FacetField.Count> filter(List<FacetField.Count> list) { 118 if (hasFilter()) { 119 final String filterValue = getFilterModel().getObject().toLowerCase(); 120 return Iterables.filter(list, new Predicate<FacetField.Count>() { 121 @Override 122 public boolean apply(Count input) { 123 return input.getName().toLowerCase().startsWith(filterValue); 124 } 125 }); 126 } else { 127 return list; 128 } 129 } 130 131 private boolean hasFilter() { 132 return !(getFilterModel() == null || getFilterModel().getObject() == null || getFilterModel().getObject().isEmpty()); 91 133 } 92 134 … … 112 154 @Override 113 155 public int compare(Count arg0, Count arg1) { 156 // TODO: From old VLO: 157 // 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. 114 158 return Long.compare(arg0.getCount(), arg1.getCount()); 115 159 } … … 120 164 @Override 121 165 public int compare(Count arg0, Count arg1) { 166 // TODO: From old VLO: 167 // 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. 122 168 return arg0.getName().compareTo(arg1.getName()); 123 169 }
Note: See TracChangeset
for help on using the changeset viewer.