diff --git a/sample/src/main/java/com/arcbees/chosen/sample/client/application/widgetsample/ViewView.java b/sample/src/main/java/com/arcbees/chosen/sample/client/application/widgetsample/ViewView.java index 3c28a8b..b08a1f4 100644 --- a/sample/src/main/java/com/arcbees/chosen/sample/client/application/widgetsample/ViewView.java +++ b/sample/src/main/java/com/arcbees/chosen/sample/client/application/widgetsample/ViewView.java @@ -16,6 +16,12 @@ package com.arcbees.chosen.sample.client.application.widgetsample; +import java.util.List; +import java.util.logging.Logger; + +import com.arcbees.chosen.client.ChosenImpl; +import com.arcbees.chosen.client.ChosenOptions; +import com.arcbees.chosen.client.ResultsFilter; import com.arcbees.chosen.client.event.ChosenChangeEvent; import com.arcbees.chosen.client.event.ChosenChangeEvent.ChosenChangeHandler; import com.arcbees.chosen.client.event.HidingDropDownEvent.HidingDropDownHandler; @@ -41,6 +47,7 @@ import static com.google.gwt.query.client.GQuery.$; public class ViewView implements IsWidget { + @UiField static AppResources res; @@ -53,6 +60,27 @@ public String getLiteral() { } } + private static class ChoicesCustomFilter implements ResultsFilter { + + private final Logger log = Logger.getLogger("ViewView"); + + private ChosenValueListBox valueListBox; + + @Override + public void filter(String searchText, ChosenImpl chosen, boolean isShowing) { + List list = Lists.newArrayList(Choices.values()); + list.add(0, null); + if (valueListBox != null) { + log.fine("Setting new values from custom filter with null element"); + valueListBox.setAcceptableValues(list); + } + } + + public void setValueListBox(ChosenValueListBox valueListBox) { + this.valueListBox = valueListBox; + } + } + private static class ChoiceRenderer extends AbstractRenderer { @Override public String render(Choices choices) { @@ -136,7 +164,12 @@ interface Binder extends UiBinder { public ViewView() { teamChosen = new ChosenListBox(true); - chosenValueListBox = new ChosenValueListBox(new ChoiceRenderer()); + ChosenOptions options = new ChosenOptions(); + ChoicesCustomFilter customFilter = new ChoicesCustomFilter(); + options.setAllowSingleDeselect(true); + options.setResultFilter(customFilter); + chosenValueListBox = new ChosenValueListBox(new ChoiceRenderer(), options); + customFilter.setValueListBox(chosenValueListBox); multipleChosenValueListBox = new MultipleChosenValueListBox(new ChoiceRenderer()); widget = binder.createAndBindUi(this); @@ -203,9 +236,6 @@ private void init() { teamChosen.setWidth("300px"); - chosenValueListBox.setAcceptableValues(Lists.newArrayList(Choices.values())); - chosenValueListBox.setValue(Choices.THIRD); - multipleChosenValueListBox.setAcceptableValues(Lists.newArrayList(Choices.values())); multipleChosenValueListBox.setValue(Lists.newArrayList(Choices.FIFTH, Choices.FIRST, Choices.FOURTH));