package com.nolmecolindor.sgweet.test.client;

import com.google.gwt.core.client.EntryPoint;
import com.smartgwt.client.core.Function;
import com.smartgwt.client.data.Criteria;
import com.smartgwt.client.data.DSRequest;
import com.smartgwt.client.data.DataSource;
import com.smartgwt.client.types.TextMatchStyle;
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.grid.ListGrid;
import com.smartgwt.client.widgets.layout.VLayout;

public class SurplussFetches extends VLayout implements EntryPoint {

	private final IButton consoleButton = new IButton("show console") {{ addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) {
		SC.showConsole();
	}}); }};
	
	@Override public void onModuleLoad() {
		final ListGrid grid = new ListGrid();
		grid.setShowFilterEditor(true);
		grid.setWidth(500);
		grid.setHeight(300);
		DataSource.load(
				"fetchtest"
				, new Function() {
					@Override public void execute() {
						grid.setDataSource(DataSource.get("fetchtest"));
						grid.hideField("some_string");
						grid.hideField("item2_number");
						final DSRequest req = new DSRequest();
						req.setTextMatchStyle(TextMatchStyle.SUBSTRING);
						grid.fetchData(new Criteria("item2_name", "23"), null, req);

					}}
				, false
		);

		addMember(consoleButton);
		addMember(grid);

		draw();
	}
	

}
