I just wanted to point out that with the nifty use of generics you can only have to implement this class once. We've got an initial implementation up and running very nicely by using a Resource interface that bridges between Models and SmartGWT constructs.
Here's a snippet, just enough to get you started thinking about it and yes, this requires the you have a pretty good handle on coding with generics.
Here's a snippet, just enough to get you started thinking about it and yes, this requires the you have a pretty good handle on coding with generics.
Code:
public interface HasSmartGWTResources<M extends DTObjectModel> { List<DataSourceField> getDataSourceFields(); M newModel(); ListGridRecord toListGridRecord(M model); M toModel(ListGridRecord record); DvTreeNode toTreeNode(M model, String parentid); List<DvTreeNode> toTreeNodeWithChildren(M model, String parentid); } public interface DataService<M extends DTObjectModel> extends RemoteService { List<M> fetch(int startIndex, int count); M add(M model); M update(M model); void remove(M model); } public interface DataServiceAsync<M extends DTObjectModel> { void fetch(int startIndex, int count, AsyncCallback<List<M>> async); void add(M model, AsyncCallback<M> async); void update(M model, AsyncCallback<M> async); void remove(M model, AsyncCallback<M> async); } public class SmartGWTDataSource<M extends DTObjectModel, R extends HasSmartGWTResources<M>, S extends DataService<M>> extends DataSource { private HasSmartGWTResources<M> resource; private DataServiceAsync<M> service; /** * Creates new data source which communicates with server by GWT RPC. * It is normal server side SmartClient data source with data protocol * set to <code>DSProtocol.CLIENTCUSTOM</code> ("clientCustom" - natively * supported by SmartClient but should be added to smartGWT) and with data * format <code>DSDataFormat.CUSTOM</code>. */ @SuppressWarnings("unchecked") public SmartGWTDataSource(HasSmartGWTResources<M> resource, Class<S> serviceClass) { super(); setDataProtocol (DSProtocol.CLIENTCUSTOM); setDataFormat (DSDataFormat.CUSTOM); setClientOnly (false); this.resource = resource; service = (DataServiceAsync<M>) GWT.create(serviceClass); for (DataSourceField field: resource.getDataSourceFields()) { addField(field); } GWT.log("SourcebookDataSource() initialized.", null); } . . . }
Comment