Skip to content

Commit

Permalink
Reproduce allowSingleDeselect Issue ArcBees#285 with custom filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
Manuel Schrag committed Nov 23, 2015
1 parent bd4fe36 commit 19087ad
Showing 1 changed file with 34 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -41,6 +47,7 @@
import static com.google.gwt.query.client.GQuery.$;

public class ViewView implements IsWidget {

@UiField
static AppResources res;

Expand All @@ -53,6 +60,27 @@ public String getLiteral() {
}
}

private static class ChoicesCustomFilter implements ResultsFilter {

private final Logger log = Logger.getLogger("ViewView");

private ChosenValueListBox<Choices> valueListBox;

@Override
public void filter(String searchText, ChosenImpl chosen, boolean isShowing) {
List<Choices> 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<Choices> valueListBox) {
this.valueListBox = valueListBox;
}
}

private static class ChoiceRenderer extends AbstractRenderer<Choices> {
@Override
public String render(Choices choices) {
Expand Down Expand Up @@ -136,7 +164,12 @@ interface Binder extends UiBinder<Widget, ViewView> {

public ViewView() {
teamChosen = new ChosenListBox(true);
chosenValueListBox = new ChosenValueListBox<Choices>(new ChoiceRenderer());
ChosenOptions options = new ChosenOptions();
ChoicesCustomFilter customFilter = new ChoicesCustomFilter();
options.setAllowSingleDeselect(true);
options.setResultFilter(customFilter);
chosenValueListBox = new ChosenValueListBox<Choices>(new ChoiceRenderer(), options);
customFilter.setValueListBox(chosenValueListBox);
multipleChosenValueListBox = new MultipleChosenValueListBox<Choices>(new ChoiceRenderer());

widget = binder.createAndBindUi(this);
Expand Down Expand Up @@ -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));

Expand Down

0 comments on commit 19087ad

Please sign in to comment.