package com.example.testcase.smartgwt_tests.client;

import com.smartgwt.client.data.DSRequest;
import com.smartgwt.client.data.DSResponse;
import com.smartgwt.client.data.Record;
import com.smartgwt.client.data.fields.DataSourceSequenceField;
import com.smartgwt.client.data.fields.DataSourceTextField;

public class OptionsDataSource extends GwtRpcDataSource {

	private static OptionsDataSource ds;
	
	public static OptionsDataSource getInstance() {
		if (ds == null) {
			ds = new OptionsDataSource();
		}
		return ds;
	}
	
	private OptionsDataSource() {
		DataSourceSequenceField repIdField = new DataSourceSequenceField("id");
		repIdField.setPrimaryKey(true);

		DataSourceTextField repNameField = new DataSourceTextField("text");
		this.setFields(repIdField,repNameField);
		this.setClientOnly(false);
	}
	
	@Override
	protected void executeAdd(String requestId, DSRequest request,
			DSResponse response) {
		// TODO Auto-generated method stub
		
	}

	@Override
	protected void executeFetch(String requestId, DSRequest request,
			DSResponse response) {
		Record not = new Record();
		not.setAttribute("id", 1);
		not.setAttribute("text", "Does not repeat");
		
		Record yes = new Record();
		yes.setAttribute("id", 2);
		yes.setAttribute("text", "Daily");
		
		response.setData(new Record[]{yes,not});
		
		processResponse(requestId, response);
	}

	@Override
	protected void executeRemove(String requestId, DSRequest request,
			DSResponse response) {
		// TODO Auto-generated method stub
		
	}

	@Override
	protected void executeUpdate(String requestId, DSRequest request,
			DSResponse response) {
		// TODO Auto-generated method stub
		
	}

}
