package com.smartgwt.demo.client;
import java.util.Date;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.i18n.client.DateTimeFormat;
import com.google.gwt.user.client.ui.RootLayoutPanel;
import com.smartgwt.client.data.DataSource;
import com.smartgwt.client.data.DataSourceField;
import com.smartgwt.client.data.fields.DataSourceDateTimeField;
import com.smartgwt.client.data.fields.DataSourceSequenceField;
import com.smartgwt.client.data.fields.DataSourceTextField;
import com.smartgwt.client.types.Alignment;
import com.smartgwt.client.types.DSDataFormat;
import com.smartgwt.client.types.FieldType;
import com.smartgwt.client.types.Overflow;
import com.smartgwt.client.types.Side;
import com.smartgwt.client.types.VerticalAlignment;
import com.smartgwt.client.util.DateUtil;
import com.smartgwt.client.widgets.HTMLPane;
import com.smartgwt.client.widgets.IButton;
import com.smartgwt.client.widgets.Img;
import com.smartgwt.client.widgets.Label;
import com.smartgwt.client.widgets.calendar.Calendar;
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.HLayout;
import com.smartgwt.client.widgets.layout.VLayout;
import com.smartgwt.client.widgets.tab.Tab;
import com.smartgwt.client.widgets.tab.TabSet;
import com.smartgwt.client.data.XMLTools;
import com.smartgwt.client.util.DateInputFormatter;

/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
public class Demo implements EntryPoint {

	public void onModuleLoad() {
	 DateUtil.setDateInputFormatter(new DateInputFormatter() {
		 public Date parse(String dateString) {
			 return DateTimeFormat.getFormat("yyyy-MM-dd HH:mm").parse(dateString);
		 }
	 });
	 DataSource ds = new DataSource();
	 ds.setDataFormat(DSDataFormat.XML);
	 ds.setRecordXPath("//DATATABLES/DATATABLE/ROW");
	 ds.setDataURL("ds/DataForTimeSlot.xml");
	 
	 DataSourceSequenceField id = new DataSourceSequenceField("Id","Id");
	 id.setPrimaryKey(true);
	 id.setValueXPath("COLUMN[@ID='Id']/@VALUE");   
	 
	 /*DataSourceTextField startDated = new DataSourceTextField("StartDate","StartDate");
	 startDated.setValueXPath("COLUMN[@ID='StartDate']/@VALUE");   

	 DataSourceTextField endDate = new DataSourceTextField("EndDate","EndDate");
	 endDate.setValueXPath("COLUMN[@ID='EndDate']/@VALUE");   */
	 
	 DataSourceDateTimeField startDated = new DataSourceDateTimeField("StartDate","StartDate");
//	 startDated.setType(FieldType.DATETIME);
	 startDated.setValueXPath("COLUMN[@ID='StartDate']/@VALUE");   

	 DataSourceDateTimeField endDate = new DataSourceDateTimeField("EndDate","EndDate");
//	 startDated.setType(FieldType.DATETIME);
	 endDate.setValueXPath("COLUMN[@ID='EndDate']/@VALUE");   

	 DataSourceTextField type = new DataSourceTextField("Type","Type");
	 type.setValueXPath("COLUMN[@ID='Type']/@VALUE");   

	 DataSourceTextField name = new DataSourceTextField("Name","Name");
	 name.setValueXPath("COLUMN[@ID='Name']/@VALUE");
	 
	 DataSourceTextField description = new DataSourceTextField("Description","Description");
	 description.setValueXPath("COLUMN[@ID='Description']/@VALUE");
	 
	 ds.setFields(id,name,description,startDated,endDate, type);
	 ds.setClientOnly(true);
	 
	/* String xmldata = xmlt.selectString(ds, "/row/column");	 */
	 HLayout headLayout = new HLayout();
	 VLayout mainLayout = new VLayout();	 
	 VLayout vlayout = new VLayout();
	 Label headlbl = new Label();
	 headlbl.setContents("welcome");
	 headlbl.setAlign(Alignment.CENTER);
	 headlbl.setOverflow(Overflow.AUTO);
	 headlbl.setBackgroundColor("blue");
	 //headlbl.setBackgroundImage("D:\\coupon.PNG");
	 Calendar calendar = new Calendar();  	 
	 calendar.setDataSource(ds);
	 //calendar.setData(CalendarData.getRecords());
	 calendar.setAutoFetchData(true);
     
	
	/* ListGrid grid = new ListGrid();
	 grid.setDataSource(ds);
     //grid.setDataSource(ds);   
     grid.setWidth100();   
     grid.setHeight(100);
     grid.setAutoFetchData(true);    
     grid.draw();*/
	 
	 vlayout.addChild(calendar);
    // vlayout.addChild(grid);
	 headLayout.setHeight("50px");
	 headLayout.setBorder("5px");
	 headLayout.addMember(headlbl);
	 vlayout.setSize("800px", "500px");
	 mainLayout.addMember(headLayout);
	 mainLayout.addMember(vlayout);
	 mainLayout.setWidth100();   
	 mainLayout.setHeight100();   
	 mainLayout.setSize("1000px", "1000px");
	 RootLayoutPanel.get().add(mainLayout);
	 
	}
}
