import java.util.ArrayList;
import java.util.List;

import com.google.gwt.core.client.GWT;
import com.smartgwt.client.data.DataSourceField;
import com.smartgwt.client.data.fields.DataSourceIntegerField;
import com.smartgwt.client.data.fields.DataSourceTextField;
import com.smartgwt.client.widgets.tile.TileRecord;

public class YourGwtRcpDataSource extends
		GenericGwtRpcDataSource<YourDataObject, TileRecord, YourServiceAsync> {

	@Override
	public List<DataSourceField> getDataSourceFields() {
		List<DataSourceField> fields = new ArrayList<DataSourceField>();
		DataSourceTextField itemNameField = new DataSourceTextField("itemName",
				"Product Name");
		itemNameField.setRequired(true);
		fields.add(itemNameField);

		DataSourceIntegerField idField = new DataSourceIntegerField("itemId",
				"Product Id");
		idField.setPrimaryKey(true);
		idField.setRequired(true);
		fields.add(idField);
		
		return (fields);
	}

	@Override
	public void copyValues(TileRecord from, YourDataObject to) {
		to.setName(from.getAttribute("itemName"));
		to.setId(from.getAttributeAsInt("itemId"));
	}

	@Override
	public void copyValues(YourDataObject from, TileRecord to) {
		to.setAttribute("itemName", from.getName());
		to.setAttribute("itemId", from.getId());
	}

	@Override
	public YourDataObject getNewDataObjectInstance() {
		return new YourDataObject();
	}

	@Override
	public TileRecord getNewRecordInstance() {
		return new TileRecord();
	}

	@Override
	public YourServiceAsync getServiceAsync() {
		return GWT.create(YourService.class);
	}

}
