Skip to content

Instantly share code, notes, and snippets.

@olafleur
Created September 28, 2015 13:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save olafleur/572e13aa2506194242d6 to your computer and use it in GitHub Desktop.
Save olafleur/572e13aa2506194242d6 to your computer and use it in GitHub Desktop.
public class HomeView extends ViewImpl implements HomePresenter.MyView {
interface Binder extends UiBinder<Widget, HomeView> {
}
//First we declare our choices in an enum
private enum Choices {
VADER("Darth Vader"),
LUKE("Luke Skywalker"),
LEIA("Princess Leia"),
BOBA_FETT("Boba Fett");
public String getLiteral() {
return name;
}
private final String name;
Choices(String s) {
name = s;
}
}
//We decide how we want to show the different choices
private static class ChoiceRenderer extends AbstractRenderer<Choices> {
@Override
public String render(Choices choices) {
return choices != null ? choices.getLiteral() : "";
}
}
//Don’t forget that the component has to be provided
@UiField(provided = true)
MultipleChosenValueListBox<Choices> multipleValues;
@Inject
HomeView(Binder uiBinder) {
//There are multiple options that you can set on GWTChosen.
//These and the construction have to be called before the call to createAndBindUi
ChosenOptions chosenOptions = new ChosenOptions();
chosenOptions.setPlaceholderText("Choose your favorite character");
multipleValues = new MultipleChosenValueListBox<>(new ChoiceRenderer(), chosenOptions);
initWidget(uiBinder.createAndBindUi(this));
//Acceptable and selected values are set after createAndBindUi
multipleValues.setAcceptableValues(Lists.newArrayList(Choices.values()));
multipleValues.setValue(Lists.newArrayList(Choices.VADER, Choices.LEIA));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment