package com.reed.playground.client;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.ui.RootPanel;
import com.smartgwt.client.data.DataSource;
import com.smartgwt.client.data.DataSourceField;
import com.smartgwt.client.data.Record;
import com.smartgwt.client.data.fields.DataSourceTextField;
import com.smartgwt.client.util.SC;
import com.smartgwt.client.widgets.form.DynamicForm;
import com.smartgwt.client.widgets.form.fields.ComboBoxItem;
import com.smartgwt.client.widgets.grid.ListGrid;
import com.smartgwt.client.widgets.grid.ListGridField;
import com.smartgwt.client.widgets.grid.events.RecordClickEvent;
import com.smartgwt.client.widgets.grid.events.RecordClickHandler;

/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
public class SmartGWTPlayground implements EntryPoint {

	public void onModuleLoad() {

	  DataSource myDS = new DataSource();
	  myDS.setClientOnly(true);
	  DataSourceField testField = new DataSourceTextField("test");
	  testField.setPrimaryKey(true);
	  myDS.setFields(testField);
	  
	  Record r = new Record();
	  r.setAttribute("test", "Record 1");
	  myDS.addData(r);
	  Record r2 = new Record();
    r2.setAttribute("test", "Record 2");
    myDS.addData(r2);
	  
	  ComboBoxItem combo = new ComboBoxItem("combo","Combo");
	  combo.setOptionDataSource(myDS);
	  combo.setPickListFields(new ListGridField("test"));
	  ListGrid grid = new ListGrid();
	  grid.addRecordClickHandler(new RecordClickHandler() {
      @Override
      public void onRecordClick(RecordClickEvent event)
      {
        SC.say("Clicked on record "+event.getRecordNum());
      }
    });
	  combo.setPickListProperties(grid);
	  
		DynamicForm form = new DynamicForm();
		form.setFields(combo);
		
		RootPanel.get("app").add(form);
	}
}
