package com.testApp.client;

import com.google.gwt.core.client.EntryPoint;
import com.smartgwt.client.callbacks.ClientOnlyDataSourceCallback;
import com.smartgwt.client.data.Criteria;
import com.smartgwt.client.data.DataSource;
import com.smartgwt.client.types.Alignment;
import com.smartgwt.client.util.SC;
import com.smartgwt.client.widgets.Button;
import com.smartgwt.client.widgets.events.ClickEvent;
import com.smartgwt.client.widgets.events.ClickHandler;
import com.smartgwt.client.widgets.layout.HLayout;

public class TestApp implements EntryPoint {

	/**
	 * This is the entry point method.
	 */
	public void onModuleLoad() {
		HLayout hlayout = new HLayout();
		hlayout.setWidth100();
		hlayout.setPadding(20);
		hlayout.setAlign(Alignment.CENTER);

		Button button = new Button("Click Me");
		button.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent clickEvent) {
				doDSFetch();
			}
		});

		hlayout.addMember(button);

		hlayout.show();
	}

	public void doDSFetch(){
		DataSource dataSource = DataSource.get("testDS");
		dataSource.getClientOnlyDataSource(new Criteria(), new ClientOnlyDataSourceCallback() {
			public void execute(DataSource dataSource) {
				SC.say("Response from fetch with timestamp " + dataSource.getCacheData()[0].getAttribute("field1"));
			}
		});
	}
}
