package fr.sayn.client;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.Random;
import com.google.gwt.user.client.ui.TextArea;
import com.smartgwt.client.widgets.Window;
import com.smartgwt.client.widgets.grid.ListGrid;
import com.smartgwt.client.widgets.grid.ListGridField;
import com.smartgwt.client.widgets.grid.ListGridRecord;
import com.smartgwt.client.widgets.grid.SummaryFunction;

/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
public class TestEE implements EntryPoint {
    public static ListGridRecord createRecord() {

	final ListGridRecord record = new ListGridRecord();
	record.setAttribute("area", Random.nextInt());
	return record;
    }

    private ListGridRecord[] records = new ListGridRecord[] { createRecord(), createRecord(), createRecord(), createRecord() };

    @Override
    public void onModuleLoad() {
	ListGrid countryGrid = new ListGrid();
	countryGrid.setSize("500", "500");
	countryGrid.setCanRemoveRecords(true);
	countryGrid.setDeferRemoval(true);
	countryGrid.setShowGridSummary(true);
	countryGrid.setShowGroupSummary(true);
	countryGrid.setCanEdit(true);
	ListGridField areaField = new ListGridField("area", "area");
	areaField.setShowHover(false);
	areaField.setShowGroupSummary(true);
	areaField.setSummaryFunction(new SummaryFunction() {
	    @Override
	    public Object getSummaryValue(com.smartgwt.client.data.Record[] records, ListGridField field) {
		return records.length + " items";
	    }
	});

	countryGrid.setFields(areaField);
	countryGrid.setData(records);
	countryGrid.draw();
	
	Window window = new Window();
	TextArea label = new TextArea();
	label.setText("Enterprise edition project\nStep to reproduce : \n1) Delete row 1, 2 and 3\n2)Move your mouse on 2 first rows");
	label.setSize("100%", "100%");
	window.addItem(label);
	window.show();
	window.setSize("300", "200");
	window.setLeft(510);
	
    }
}
