import com.smartgwt.client.data.DataSource;
import com.smartgwt.client.data.Record;
import com.smartgwt.client.data.fields.DataSourceIntegerField;
import com.smartgwt.client.widgets.grid.ListGrid;
import com.smartgwt.client.widgets.layout.Layout;

public class MainEntryPoint implements EntryPoint
{
	@Override
	public void onModuleLoad()
	{
		ListGrid grid = new ListGrid();
		grid.setShowGridSummary(true);
		grid.setWidth(200);
		grid.setHeight(150);

		grid.setDataSource(new BodyDataSource());
		grid.setSummaryRowDataSource(new SummaryDataSource());

		grid.fetchData();

		Layout layout = new Layout();
		layout.setWidth100();
		layout.setHeight100();
		layout.addMember(grid);
		layout.draw();
	}

	private static class BodyDataSource extends DataSource
	{
		public BodyDataSource()
		{
			setFields(new DataSourceIntegerField("one"), new DataSourceIntegerField("two"));
			setClientOnly(true);
			Record[] records = new Record[2];

			records[0] = new Record();
			records[0].setAttribute("one", 1);
			records[0].setAttribute("two", 2);

			records[1] = new Record();
			records[1].setAttribute("one", 2);
			records[1].setAttribute("two", 4);

			setTestData(records);
		}
	}

	private static class SummaryDataSource extends DataSource
	{
		public SummaryDataSource()
		{
			setFields(new DataSourceIntegerField("one"), new DataSourceIntegerField("two"));
			setClientOnly(true);
			Record[] records = new Record[1];

			records[0] = new Record();
			records[0].setAttribute("one", 3);
			records[0].setAttribute("two", 6);

			setTestData(records);
		}
	}
}
