Originally posted by jsantaelena
Att,
I was able to run your code to see the datasource in action.
Thank you very much,
Dmitriy
public class FoldersDataSource extends GwtRpcDataSource { private static final String NAME_FIELD = "name"; public FoldersDataSource() { setID("folders"); setTitle("Dossiers"); DataSourceTextField nameField = new DataSourceTextField(NAME_FIELD, "Nom", 128); // folder_id = primary key DataSourceIntegerField folderIdField = new DataSourceIntegerField(ID_FIELD, "Folder Id"); folderIdField.setPrimaryKey(true); folderIdField.setRequired(true); // parent_id = foreign key DataSourceIntegerField folderParentIdField = new DataSourceIntegerField(PARENT_ID_FIELD, "Parent Id"); folderParentIdField.setRequired(true); folderParentIdField.setForeignKey(ID_FIELD); folderParentIdField.setRootValue("0"); setFields(nameField, folderIdField, folderParentIdField); } @Override protected void executeFetch(final String requestId, final DSRequest request, final DSResponse response) { int parentId = 0; try { // get the id of node to open. Strangely, can't use getAttributeAsInt, fails for the root id parentId = Integer.parseInt(request.getCriteria().getAttribute(PARENT_ID_FIELD)); } catch(RuntimeException e) { GWT.log("Not a number", e); } FilesServiceAsync filesService = FilesServiceAsync.Util.getInstance(); filesService.getSubFolders(parentId, new AsyncCallback<Folder[]>() { public void onFailure(Throwable arg0) { response.setStatus(RPCResponse.STATUS_FAILURE); processResponse(requestId, response); } public void onSuccess(Folder[] folders) { Record[] records = new Record[folders.length]; for(int i = 0; i < records.length; i++) { TreeNode treeNode = new TreeNode(); Folder folder = folders[i]; treeNode.setAttribute(ID_FIELD, folder.getId()); treeNode.setAttribute(PARENT_ID_FIELD, folder.getParentId()); treeNode.setAttribute(NAME_FIELD, folder.getName()); records[i] = treeNode; } response.setData(records); processResponse(requestId, response); } }); }
static { list = new ArrayList<TestRecord>(); TestRecord record; for (int i = 1; i <= 40; i++) { record = new TestRecord(); record.setId(i); record.setName("Name " + i); record.setDate(new Date(200 + i, 1, 1) ); list.add(record); } }
ListGridField[] fields = new ListGridField[3]; fields[0] = new ListGridField("id", "ID"); fields[0].setType(ListGridFieldType.INTEGER); fields[1] = new ListGridField("name", "name"); fields[1].setType(ListGridFieldType.TEXT); fields[2] = new ListGridField("date", "Date of Birth"); fields[2].setType(ListGridFieldType.DATE); listGrid.setFields(fields);
Comment