package com.sencha.gxt.explorer.client.forms; import com.google.gwt.core.client.EntryPoint; import com.google.gwt.core.client.GWT; import com.google.gwt.event.logical.shared.ValueChangeEvent; import com.google.gwt.event.logical.shared.ValueChangeHandler; import com.google.gwt.user.client.ui.IsWidget; import com.google.gwt.user.client.ui.RootPanel; import com.google.gwt.user.client.ui.VerticalPanel; import com.google.gwt.user.client.ui.Widget; import com.sencha.gxt.cell.core.client.form.ComboBoxCell.TriggerAction; import com.sencha.gxt.data.shared.LabelProvider; import com.sencha.gxt.data.shared.ListStore; import com.sencha.gxt.data.shared.ModelKeyProvider; import com.sencha.gxt.data.shared.PropertyAccess; import com.sencha.gxt.examples.resources.client.TestData; import com.sencha.gxt.examples.resources.client.model.Country; import com.sencha.gxt.examples.resources.client.model.State; import com.sencha.gxt.explorer.client.model.Example.Detail; import com.sencha.gxt.widget.core.client.form.ComboBox; import com.sencha.gxt.widget.core.client.info.Info; public class ComboBoxExample implements IsWidget, EntryPoint { interface StateProperties extends PropertyAccess
{ ModelKeyProvider
abbr(); LabelProvider
name(); } interface CountryProperties extends PropertyAccess
{ ModelKeyProvider
abbr(); LabelProvider
name(); } public Widget asWidget() { VerticalPanel vp = new VerticalPanel(); vp.setSpacing(10); StateProperties props = GWT.create(StateProperties.class); ListStore
states = new ListStore
(props.abbr()); states.addAll(TestData.getStates()); ComboBox
combo = new ComboBox
(states, props.name()); combo.addValueChangeHandler(new ValueChangeHandler
() { @Override public void onValueChange(ValueChangeEvent
event) { Info.display("Selected", "You selected " + (event.getValue() == null ? "nothing" : event.getValue().getName()) + "!"); } }); combo.setEmptyText("Select a state..."); combo.setWidth(150); combo.setTypeAhead(true); combo.setTriggerAction(TriggerAction.ALL); vp.add(combo); states = new ListStore
(props.abbr()); states.addAll(TestData.getStates()); combo = new ComboBox
(states, props.name(), new LabelProvider
() { @Override public String getLabel(State item) { return "
" + item.getName() + "
"; } }); combo.addValueChangeHandler(new ValueChangeHandler
() { @Override public void onValueChange(ValueChangeEvent
event) { Info.display("Selected", "You selected " + (event.getValue() == null ? "nothing" : event.getValue().getName()) + "!"); } }); combo.setEmptyText("Select a state..."); combo.setWidth(150); combo.setTypeAhead(true); combo.setTriggerAction(TriggerAction.ALL); vp.add(combo); CountryProperties countryProps = GWT.create(CountryProperties.class); ListStore
countries = new ListStore
(countryProps.abbr()); countries.addAll(TestData.getCountries()); ComboBox
combo2 = new ComboBox
(countries, countryProps.name(), new LabelProvider
() { @Override public String getLabel(Country item) { return "
" + item.getName(); } }); combo2.addValueChangeHandler(new ValueChangeHandler
() { @Override public void onValueChange(ValueChangeEvent
event) { Info.display("Selected", "You selected " + (event.getValue() == null ? "nothing" : event.getValue().getName()) + "!"); } }); combo2.setWidth(150); combo2.setTypeAhead(true); combo2.setTriggerAction(TriggerAction.ALL); vp.add(combo2); return vp; } public void onModuleLoad() { RootPanel.get().add(asWidget()); } }