PDA

View Full Version : TreeComboBox example



banbaal
26 Dec 2010, 8:18 PM
Here is a tree combobox combining StoreFilterField and TreeGrid. it allows using grid features like grouping rowNumberer multiple column etc. contstructor takes columnModel code example below



UComboBox<CustomerTypeDTO> parentTypeComboBox;
List<ColumnConfig> configs = new ArrayList<ColumnConfig>(2);
ColumnConfig config = new ColumnConfig("customerTypeCode", "Code", 80);
configs.add(config);
config = new ColumnConfig("customerTypeName", "Name", 120);
configs.add(config);
parentTypeComboBox = new UComboBox<CustomerTypeDTO>(new ColumnModel(configs));
parentTypeComboBox.setDisplayField("customerTypeCode");
parentTypeComboBox.setForceSelection(true);

RpcProxy<ArrayList> proxy = new RpcProxy<ArrayList>() {
@Override
protected void load(Object loadConfig, AsyncCallback<ArrayList> asyncCallback) {
if (loadConfig == null) {
EntityManagerRPC.App.getInstance().executeQuery(new Query("CustomerType.findParents").setParameter("inactive", false), asyncCallback);
return;
}
EntityManagerRPC.App.getInstance().executeQuery(new Query("CustomerType.findByParent").setParameter("parentId", ((CustomerTypeDTO) loadConfig).getCustomerTypeId()).setParameter("inactive", false), asyncCallback);
}
};
TreeLoader<CustomerTypeDTO> loader = new BaseTreeLoader<CustomerTypeDTO>(proxy) {
@Override
public boolean hasChildren(CustomerTypeDTO parent) {
return true;
}
};
TreeStore<CustomerTypeDTO> store = new TreeStore<CustomerTypeDTO>(loader);
parentTypeComboBox.setTreeStore(store);

parentTypeComboBox.addSelectionChangedListener(new SelectionChangedListener<CustomerTypeDTO>() {
@Override
public void selectionChanged(SelectionChangedEvent<CustomerTypeDTO> se) {
if (se.getSelectedItem() != null)
parentNameTextField.setValue(se.getSelectedItem().getCustomerTypeName());
}
});

parentTypeComboBox.setSelectedItem(updatingDTO.getParentCustomerType());
dto.setParentCustomerType(parentTypeComboBox.getSelectedItem());23979

nasanjargal.b
1 Mar 2011, 7:51 PM
it's very nice. :D