package no.lottstift.test.client;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.ui.RootPanel;
import com.smartgwt.client.data.Record;
import com.smartgwt.client.types.Overflow;
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.grid.ListGrid;
import com.smartgwt.client.widgets.grid.ListGridField;
import com.smartgwt.client.widgets.layout.VLayout;

/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
public class TestGrid implements EntryPoint {
	public void onModuleLoad() {
		final ListGrid grid = new ListGrid();
        ListGridField field1 = new ListGridField("name");
        ListGridField field2 = new ListGridField("phone");
		grid.setFields(field1, field2);
		grid.setWidth100();
		grid.setHeight100();
        grid.setCanEdit(true);
        grid.setCanRemoveRecords(true);
        grid.setAutoSaveEdits(false);

		IButton n = new IButton("Create", new ClickHandler() {
            
            @Override
            public void onClick(ClickEvent event) {
                Record r = new Record();
                r.setAttribute("name", "John Doe");
                grid.startEditingNew(r);
            }
        });

		VLayout layout = new VLayout();
       layout.setOverflow(Overflow.VISIBLE);

		layout.setMembersMargin(15);
		layout.addMembers(grid,n);
		layout.setWidth("98%");
		layout.setHeight("96%");
		
		RootPanel.get().add(layout);
	}

}
