Created
April 16, 2014 21:33
-
-
Save branflake2267/10935370 to your computer and use it in GitHub Desktop.
ComboboxWithLoaderTest.java
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
import java.util.ArrayList; | |
import java.util.List; | |
import com.google.gwt.core.client.Callback; | |
import com.google.gwt.user.client.ui.RootPanel; | |
import com.google.gwt.user.client.ui.Widget; | |
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.loader.DataProxy; | |
import com.sencha.gxt.data.shared.loader.ListLoadConfig; | |
import com.sencha.gxt.data.shared.loader.ListLoadResult; | |
import com.sencha.gxt.data.shared.loader.ListLoadResultBean; | |
import com.sencha.gxt.data.shared.loader.ListLoader; | |
import com.sencha.gxt.data.shared.loader.LoadResultListStoreBinding; | |
import com.sencha.gxt.widget.core.client.form.ComboBox; | |
public class ComboboxWithLoaderTest { | |
private ComboBox<Company> combo; | |
public ComboboxWithLoaderTest() { | |
RootPanel.get().add(createComboboxWithLoaderTest()); | |
} | |
public Widget createComboboxWithLoaderTest() { | |
ListStore<Company> store = new ListStore<ComboboxWithLoaderTest.Company>(new ModelKeyProvider<Company>() { | |
@Override | |
public String getKey(Company item) { | |
return item.getId(); | |
} | |
}); | |
DataProxy<ListLoadConfig, ListLoadResult<Company>> proxy = new DataProxy<ListLoadConfig, ListLoadResult<Company>>() { | |
@Override | |
public void load(ListLoadConfig loadConfig, Callback<ListLoadResult<Company>, Throwable> callback) { | |
final List<Company> companies = new ArrayList<Company>(); | |
for (int i = 0; i < 5; i++) { | |
Company company = getCompany(i); | |
companies.add(company); | |
} | |
ListLoadResult<Company> result = new ListLoadResultBean<Company>(companies); | |
callback.onSuccess(result); | |
} | |
}; | |
final ListLoader<ListLoadConfig, ListLoadResult<Company>> loader = new ListLoader<ListLoadConfig, ListLoadResult<Company>>( | |
proxy); | |
loader.addLoadHandler(new LoadResultListStoreBinding<ListLoadConfig, Company, ListLoadResult<Company>>(store)); | |
LabelProvider<Company> labelProvider = new LabelProvider<Company>() { | |
@Override | |
public String getLabel(Company item) { | |
return item.getName(); | |
} | |
}; | |
combo = new ComboBox<Company>(store, labelProvider); | |
// set the loader | |
combo.setLoader(loader); | |
// copied config | |
combo.setName("callClassificationName"); | |
combo.setAllowBlank(false); | |
combo.setEditable(true); | |
combo.setAllowTextSelection(true); | |
combo.setReadOnly(false); | |
combo.setAllowBlank(false); | |
combo.setForceSelection(false); | |
combo.setTypeAhead(false); | |
// optional | |
combo.setLoadingText("Loading..."); | |
return combo; | |
} | |
private Company getCompany(int row) { | |
String key = "key" + row; | |
String name = ""; | |
if (row < 2) { | |
name = "apple" + row; | |
} else if (row > 2 && row < 5) { | |
name = "oranges" + row; | |
} else if (row > 5) { | |
name = "candy" + row; | |
} else { | |
name = "fruit" + row; | |
} | |
Company company = new Company(key, name); | |
return company; | |
} | |
public class Company { | |
private String id; | |
private String name; | |
public Company(String id, String name) { | |
this.id = id; | |
this.name = name; | |
} | |
public String getId() { | |
return id; | |
} | |
public String getName() { | |
return name; | |
} | |
@Override | |
public String toString() { | |
String s = ""; | |
s += "id=" + id + ","; | |
s += "name=" + name; | |
return s; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment