package com.tid.test.client.ds;

import com.smartgwt.client.data.DataSource;
import com.smartgwt.client.data.fields.DataSourceTextField;
import com.smartgwt.client.widgets.grid.ListGridRecord;

public class SimpleDataSource extends DataSource {
	public static final String NAME = "name";
	public static final String CODE = "code";
	
	private static SimpleDataSource instance = null;
	
	private static class SimpleRecord extends ListGridRecord {
		public SimpleRecord(String name, String code) {
			setAttribute(NAME, name);
			setAttribute(CODE, code);
		}
	}

	public static SimpleDataSource getInstance() {
		if (instance == null) {
			instance = new SimpleDataSource();
			instance.addData(new SimpleRecord("One", "D001"));
			instance.addData(new SimpleRecord("Two", "D002"));
			instance.addData(new SimpleRecord("Three", "D003"));
			instance.addData(new SimpleRecord("Four", "D004"));
		}
		return instance;
	}
	
	protected SimpleDataSource() {
        setClientOnly(true);
        
		DataSourceTextField field = new DataSourceTextField(NAME, "Name");
		field.setRequired(true);
		field.setPrimaryKey(true);
		addField(field);
		
		field = new DataSourceTextField(CODE, "Code");
		field.setRequired(true);
		addField(field);
	}
}
