package com.friesenretail.exploregwt.client;

import com.google.gwt.core.client.EntryPoint;
import com.smartgwt.client.data.DataSource;
import com.smartgwt.client.types.ListGridEditEvent;
import com.smartgwt.client.util.SC;
import com.smartgwt.client.widgets.grid.ListGrid;
import com.smartgwt.client.widgets.grid.ListGridField;

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

    /**
     * This is the entry point method.
     */
    public void onModuleLoad() {
        SC.showConsole();
        showList();
    }
    
    protected void showList() {
      DataSource dataSource = DataSource.get("sample01");
      System.out.println("datasource="+dataSource);
      
      ListGridField field01 = new ListGridField("field01");  
      ListGridField field02 = new ListGridField("field02", 100);  
      ListGridField field03 = new ListGridField("field03", 100);  
      ListGridField field04 = new ListGridField("field04", 150);  
      ListGridField field05 = new ListGridField("field05", 100);  

      final ListGrid listGrid = new ListGrid();  
      listGrid.setCanEdit(true);  
      listGrid.setWidth(740);  
      listGrid.setHeight100();  
      listGrid.setCanEdit(true);  
      listGrid.setAutoFetchData(true);
      
      //The following line fails because dataSource is null.
      listGrid.setDataSource(dataSource);  
      listGrid.setEditEvent(ListGridEditEvent.DOUBLECLICK);  
      listGrid.setModalEditing(true);  

      listGrid.setFields(field01, field02, field03, field04, field05);  

      listGrid.draw();  
      }
}
