PDA

View Full Version : Truly Dynamic EditorGrid



mark.clement
15 Jul 2009, 5:37 AM
Hi All

Im in need of a bit of help here on this one. Im trying to create a dynamic editor grid depending on a value selected from a combobox. If an item is selected from the combobox it must fetch a dynamic list of columns and values from the database (Which it does). I have managed to change the column model and reconfigure and refresh the editor grid to display the columns fetched from the database, which works, but populating the grid values im not to sure how.

My question is how do I populate the editor grid with the values returned? Can i still use a list Has anyone done something like this before? or know of any good examples or articles. I have been stuck for days.

Here is a code snippet i have so far :


public class DomainValueMapPage extends LayoutContainer {

private final DomainValueMapServiceAsync dvmService = GWT.create(DomainValueMapService.class);

private ListStore<BeanModel> dvmStore;
private BeanModelReader dvmReader;
private ListLoader dvmLoader;
private RpcProxy dvmProxy;

private List<ColumnConfig> columnConfig;
private ColumnModel columnModel;
private EditorGrid<BeanModel> dvmGrid;

private Long selectedDvmValueMapNo;

public DomainValueMapPage() {
setLayout(new FitLayout());
}

protected void onRender(Element parent, int index) {
super.onRender(parent, index);
loadDomainValueMaps();
createDomainValueMapPage();
}

private void createDomainValueMapPage() {

ComboBox<BeanModel> dvmComboBox = new ComboBox<BeanModel>();
dvmComboBox.setAutoWidth(true);
dvmComboBox.setWidth(500);
dvmComboBox.setStore(dvmStore);
dvmComboBox.setDisplayField("domainValueMapName");
dvmComboBox.setFieldLabel("Domain Value Map");
dvmComboBox.setLoadingText("Loading");
dvmComboBox.setEmptyText("Select A Domain Value Map...");
dvmComboBox.setEditable(false);

dvmComboBox.addSelectionChangedListener(new SelectionChangedListener<BeanModel>() {
@Override
public void selectionChanged(SelectionChangedEvent<BeanModel> se) {
if(se.getSelectedItem() != null && se.getSelectedItem().get("domainValueMapNo") != null) {
selectedDvmValueMapNo = se.getSelectedItem().get("domainValueMapNo");
loadDomainValueMapValues(selectedDvmValueMapNo);
}
}
});


ToolBar toolbar = new ToolBar();
toolbar.add(new LabelToolItem("Domain Value Map : "));
toolbar.add(dvmComboBox);

columnConfig = new ArrayList<ColumnConfig>();
columnConfig.add(new ColumnConfig("domainValueMapValue", "#", 30));

columnModel = new ColumnModel(columnConfig);

dvmGrid = new EditorGrid<BeanModel>(dvmStore, columnModel);
dvmGrid.setBorders(true);

ContentPanel mainContentPanel = new ContentPanel();
mainContentPanel.setTopComponent(toolbar);
mainContentPanel.setLayout(new FitLayout());
mainContentPanel.setIcon(Bank_switch_admin.IMAGES.table());
mainContentPanel.setHeading("Domain Value Map");
mainContentPanel.setFrame(true);
mainContentPanel.setBodyBorder(true);
mainContentPanel.add(dvmGrid);

add(mainContentPanel);
}

private void loadDomainValueMaps() {
dvmProxy = new RpcProxy() {
protected void load(Object loadConfig, AsyncCallback callback) {
dvmService.getDomainValueMaps(callback);
}
};

dvmReader = new BeanModelReader();
dvmLoader = new BaseListLoader(dvmProxy, dvmReader);
dvmStore = new ListStore<BeanModel>(dvmLoader);
dvmLoader.load();
}

private void loadDomainValueMapValues(Long domainValueMapNo) {
dvmService.getDomainValueMap(domainValueMapNo, new AsyncCallback<DomainValueMap>() {
public void onFailure(Throwable caught) {
//Do some exception handling
}

public void onSuccess(DomainValueMap result) {
columnConfig = new ArrayList<ColumnConfig>();

for(DomainValueMapColumn dvmCol : result.getDomainValueMapColumnList()) {
columnConfig.add(new ColumnConfig("", dvmCol.getDomainValueMapColumnName(), 100));
}

columnModel = new ColumnModel(columnConfig);


// Populate store with values from result.getDomainValueMapValueList

dvmGrid.reconfigure(dvmStore, columnModel);
dvmGrid.getView().refresh(true);
}
});
}
}Any help would be greatly appreciated. Apologies if this comes across stupid but im new to gxt.

Thanks
Mark

mark.clement
16 Jul 2009, 1:11 AM
Anybody got any thoughts or ideas on how to approach this problem. Thanks B)