package de.smartgwttest.client;

import com.google.gwt.core.client.EntryPoint;
import com.smartgwt.client.data.AdvancedCriteria;
import com.smartgwt.client.data.Criterion;
import com.smartgwt.client.data.DataSource;
import com.smartgwt.client.types.FetchMode;
import com.smartgwt.client.types.OperatorId;
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.events.DrawEvent;
import com.smartgwt.client.widgets.events.DrawHandler;
import com.smartgwt.client.widgets.grid.ListGrid;
import com.smartgwt.client.widgets.layout.VLayout;

/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
public class SmartGWTTest implements EntryPoint {
	/**
	 * This is the entry point method.
	 */
	public void onModuleLoad() {
		final ListGrid listGrid = new ListGrid();
		listGrid.setWidth(700);
		listGrid.setHeight(224);
		listGrid.setDataSource(DataSource.get("testDataSource"));
		listGrid.setDataFetchMode(FetchMode.BASIC);
		listGrid.setUseAllDataSourceFields(true);

		listGrid.addDrawHandler(new DrawHandler() {

			@Override
			public void onDraw(DrawEvent event) {
				// TODO Auto-generated method stub
				String[] list = new String[] { "1", "2", "3", "4" };
				Criterion ppp = new Criterion("kind", OperatorId.IN_SET, list);
				AdvancedCriteria ac = new AdvancedCriteria(ppp);
				listGrid.fetchData(ac);
			}

		});

		IButton newButton = new IButton("Add New");
		newButton.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				listGrid.startEditingNew();
			}
		});

		VLayout layout = new VLayout(15);
		layout.addMember(listGrid);
		layout.addMember(newButton);

		layout.draw();
	}
}
