package com.pci.unitoffer.client;

import java.util.ArrayList;
import java.util.List;

import com.google.gwt.core.client.EntryPoint;
import com.smartgwt.client.data.DSRequest;
import com.smartgwt.client.data.DataSource;
import com.smartgwt.client.types.ExportDisplay;
import com.smartgwt.client.types.ExportFormat;
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 UnitOffer implements EntryPoint
{

	public void onModuleLoad()
	{

		DataSource customDS = DataSource.get("customDataSource_user");

		final ListGrid userList = new ListGrid();
		userList.setWidth(600);
		userList.setHeight(224);
		userList.setDataSource(customDS);
		userList.setAutoFetchData(true);

		IButton console = new IButton("Console");
		console.setWidth(110);
		console.addClickHandler(new ClickHandler()
		{
			public void onClick(ClickEvent event)
			{
				SC.showConsole();
			}
		});
		IButton export = new IButton("Export");
		export.setWidth(110);
		export.addClickHandler(new ClickHandler()
		{
			public void onClick(ClickEvent event)
			{
				List<String> exportFields = new ArrayList<String>();
				//				for (ListGridField field : userList.getFields())
				//				exportFields.add(field.getName());

				DSRequest dsRequestProperties = new DSRequest();
				dsRequestProperties.setExportAs(ExportFormat.XLS);
				//				dsRequestProperties.setExportFields(exportFields.toArray(new String[exportFields.size()]));
				dsRequestProperties.setExportFilename("data.xls");
				dsRequestProperties.setExportDisplay(ExportDisplay.DOWNLOAD);

				userList.exportClientData(dsRequestProperties);
			}
		});

		VLayout layout = new VLayout(15);
		layout.addMember(userList);
		layout.addMember(console);
		layout.addMember(export);

		layout.draw();

	}

}