protected void onFirstShowPage() {
super.onFirstShowPage();
final PVerticalPanel panel = new PVerticalPanel();
panel.add(new PLabel("Choose a word:"));
final PSuggestBox suggestBox = new PSuggestBox();
suggestBox.setLimit(10);
final PMultiWordSuggestOracle suggestOracle = (PMultiWordSuggestOracle) suggestBox.getSuggestOracle();
suggestBox.addSelectionHandler(new PSelectionHandler<PSuggestion>() {
@Override
public void onSelection(final PSelectionEvent<PSuggestion> event) {
final String msg = "Selected item : " + event.getSelectedItem().getReplacementString();
UIContext.getRootEventBus().fireEvent(new DemoBusinessEvent(msg));
}
});
final Query query = new Query();
final FindPonysCommand command = new FindPonysCommand(query);
final Result<List<Pony>> ponys = command.execute();
final List<String> datas = new ArrayList<String>();
for (final Pony pony : ponys.getData()) {
datas.add(pony.getName());
}
suggestOracle.addAll(datas);
suggestOracle.setDefaultSuggestions(datas.subList(0, 5));
panel.add(suggestBox);
panel.add(new PHTML("<br><br>"));
panel.add(new PLabel("Manipulate the suggest box:"));
final PListBox operation = new PListBox(true);
operation.addItem("Select \"Friesian horse\"", 0);
operation.addItem("Get textbox value", 1);
operation.addItem("Enable/Disable textbox", 2);
operation.addItem("Clear", 3);