package my.client;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.ui.RootPanel;
import com.smartgwt.client.core.KeyIdentifier;
import com.smartgwt.client.util.KeyCallback;
import com.smartgwt.client.util.Page;
import com.smartgwt.client.util.SC;
import com.smartgwt.client.widgets.IButton;
import com.smartgwt.client.widgets.events.ClickEvent;
import com.smartgwt.client.widgets.events.ClickHandler;
import com.smartgwt.client.widgets.form.DynamicForm;
import com.smartgwt.client.widgets.grid.ListGrid;
import com.smartgwt.client.widgets.layout.VLayout;

public class Ds0604 implements EntryPoint {

  public void onModuleLoad() {
    if (!GWT.isScript()) {
      KeyIdentifier debugKey = new KeyIdentifier();
      debugKey.setCtrlKey(true);
      debugKey.setKeyName("D");

      Page.registerKey(debugKey, new KeyCallback() {
        public void execute(String keyName) {
          SC.showConsole();
        }
      });
    }
    SimpleGwtRPCDS dataSource = new SimpleGwtRPCDS();
    VLayout layout = new VLayout();
    layout.setWidth100();
    layout.setHeight100();
    
    final ListGrid listGrid = new ListGrid();

    listGrid.setWidth100();
    listGrid.setHeight("30%");
    listGrid.setAutoFetchData(true);
    listGrid.setDataSource(dataSource);
//    listGrid.setDataPageSize(2);
    listGrid.setAlternateRecordStyles(true);

//    listGrid.draw();
    
    final DynamicForm form = new DynamicForm();

    form.setDataSource(dataSource);
    
    IButton saveButton = new IButton("Save");
    saveButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            form.saveData();
        }
    });

    layout.setMembers(listGrid, form, saveButton);

    RootPanel.get().add(layout);

  }
}
