Created
September 28, 2015 13:33
-
-
Save olafleur/572e13aa2506194242d6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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