Where are those gwt extensions? I could not check out any thing!
Originally posted by nlotz
public GwtRpcDataSource() { //setClientOnly(true); }
protected void executeFetch(final DSRequest request) { fetchEndpoint.callEndpoint(new AsyncCallback<Object>() { public void onFailure(Throwable caught) { fetchEndpoint.postFailure(caught); } public void onSuccess(Object object) { Collection<T> resultSet = fetchEndpoint.transformResult(object); JavaScriptObject obj=request.getAttributeAsJavaScriptObject("parentNode"); TreeNode parentNode=new TreeNode(obj); TreeNode[] nodes=new TreeNode[resultSet.size()]; int index=0; for (T result: resultSet) { DSRequest req = new DSRequest(); req.setAttribute(DO_NOT_HANDLE, true); final TreeNode node = new TreeNode(); populateRecord(node, result, request); nodes[index++]=node; } //http://forums.smartclient.com/showthread.php?t=173&highlight=client+tree // You have to pass somehow the Tree into DataSource. It is not good to make //DataSource depend on Tree. But this is the only way I can make it work. tree.addList(nodes, parentNode); // This approach does not work //parentNode.setChildren(nodes); fetchEndpoint.postSuccess(object); } }, request, parameters); }
protected abstract void populateRecord(ListGridRecord record, T object, DSRequest request);
protected void populateRecord(ListGridRecord record, Node node, DSRequest request) { record.setAttribute("name", node.getName()); JavaScriptObject obj=request.getAttributeAsJavaScriptObject("parentNode"); TreeNode parentNode=new TreeNode(obj); //need to set id based on request record.setAttribute("id", parentNode.getAttribute("id")+"."+node.getName()); record.setAttribute("folder", true); }
public class RouterTab extends HLayout { private static DataSource dataSource = null; private VLayout vLayout = null; public RouterTab() { setHeight100(); setWidth100(); setMargin(10); vLayout = new VLayout(); vLayout.setWidth100(); vLayout.setHeight100(); vLayout.setPadding(10); addMember(vLayout); createDataGrid(); } private void createDataGrid() throws IllegalStateException { dataSource = RouterDataSource.getInstance(); final ListGrid listGrid = new ListGrid(); listGrid.setWidth100(); listGrid.setHeight100(); listGrid.setAlternateRecordStyles(true); listGrid.setShowAllRecords(true); listGrid.setCanResizeFields(true); listGrid.setCanReorderFields(true); listGrid.setCanSort(true); ClientSession.getInstance().getLogger().info("setting datasource RouterDataSource...", null); listGrid.setDataSource(dataSource); listGrid.setAutoFetchData(true); listGrid.setShowFilterEditor(true); listGrid.setFilterOnKeypress(true); ClientSession.getInstance().getLogger().info("fetching data ...", null); listGrid.setAutoFitData(Autofit.BOTH); listGrid.addRecordDoubleClickHandler(new RecordDoubleClickHandler() { public void onRecordDoubleClick(RecordDoubleClickEvent event) { GWT.log("clicked on record", null); } }); GWT.log(RouterDataSource.getInstance().getTitle(), null); vLayout.addMember(listGrid); listGrid.fetchData(); } }
public class RouterDataSource extends GwtRpcDataSource<GWTMgtNetRouter> { public static String DATA_SOURCE_ID = "RouterDataSourceDS"; private static RouterDataSource instance = null; public static RouterDataSource getInstance() { if (instance == null) { instance = new RouterDataSource(); } return instance; } public RouterDataSource() { super(); //setID(dataSourceId); setFetchEndpoint(new GwtRpcDataSourceEndpoint<GWTMgtNetRouter>() { @Override public void callEndpoint(AsyncCallback callback, Object... parameters) { ClientSession.getInstance().getLogger().info("event", null); MgtNetServiceAsync mgtNetService = ClientSession.getInstance().getMgtNetService(); GWTUserContext context = ClientSession.getInstance().getGWTUserContext(); mgtNetService.getMgtNetRouters(context, callback); } }); setUpdateEndpoint(new GwtRpcDataSourceEndpoint<GWTMgtNetRouter>() { @Override public void callEndpoint(AsyncCallback callback, Object... parameters) { MgtNetServiceAsync stockService = GWT.create(MgtNetService.class); ListGridRecord record = (ListGridRecord) parameters[0]; // edit //stockService.editStock(record.getAttributeAsInt("id"), record.getAttribute("symbol"), callback); } }); setRemoveEndpoint(new GwtRpcDataSourceEndpoint<GWTMgtNetRouter>() { @Override public void callEndpoint(AsyncCallback callback, Object... parameters) { MgtNetServiceAsync stockService = GWT.create(MgtNetService.class); ListGridRecord record = (ListGridRecord) parameters[0]; // remove //stockService.removeStock(record.getAttributeAsInt("id"), callback); } }); setAddEndpoint(new GwtRpcDataSourceEndpoint<GWTMgtNetRouter>() { @Override public void callEndpoint(AsyncCallback callback, Object... parameters) { MgtNetServiceAsync stockService = GWT.create(MgtNetService.class); ListGridRecord record = (ListGridRecord) parameters[0]; // add //stockService.addStock(record.getAttribute("symbol"), callback); } }); DataSourceIntegerField idDataField = new DataSourceIntegerField("id", "ID"); idDataField.setPrimaryKey(true); DataSourceTextField nameDataField = new DataSourceTextField("name", "Router Name"); nameDataField.setCanEdit(false); DataSourceTextField ipAddressDataField = new DataSourceTextField("ipadress", "IP Adress"); ipAddressDataField.setCanEdit(false); DataSourceDateField regDateDataField = new DataSourceDateField("regdate", "Register Date"); regDateDataField.setCanEdit(false); DataSourceDateField updDateDataField = new DataSourceDateField("upddate", "Update Date"); updDateDataField.setCanEdit(false); setFields(idDataField, nameDataField, ipAddressDataField, regDateDataField, updDateDataField); } @Override protected void populateRecord(ListGridRecord record, GWTMgtNetRouter gWTMgtNetRouter) { record.setAttribute("id", gWTMgtNetRouter.getId().intValue()); record.setAttribute("name", gWTMgtNetRouter.getName()); record.setAttribute("ipadress", gWTMgtNetRouter.getIpAddress()); record.setAttribute("regdate", gWTMgtNetRouter.getRegDate()); record.setAttribute("upddate", gWTMgtNetRouter.getUpdDate()); } }
Comment