package com.gwt.test;

import java.util.Date;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.ui.RootLayoutPanel;
import com.google.gwt.user.client.ui.RootPanel;
import com.smartgwt.client.types.ViewName;
import com.smartgwt.client.widgets.Button;
import com.smartgwt.client.widgets.calendar.Calendar;
import com.smartgwt.client.widgets.calendar.CalendarEvent;
import com.smartgwt.client.widgets.events.ClickEvent;
import com.smartgwt.client.widgets.events.ClickHandler;
import com.smartgwt.client.widgets.layout.VLayout;

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

	public class MyCalendar extends Calendar {
		public native void myScrollTo() /*-{
			var self = this.@com.smartgwt.client.widgets.BaseWidget::getOrCreateJsObj()();
			self.dayView.scrollToWorkdayStart();
			self.weekView.scrollToWorkdayStart();
		}-*/;
	};

	/**
	 * Entry point method.
	 */
	public void onModuleLoad() {
		VLayout mainPanel = new VLayout();
		mainPanel.setWidth100();
		mainPanel.setHeight100();

		Date today = new Date();
		int year = today.getYear();
		int month = today.getMonth();
		int start = today.getDate();

		final MyCalendar calendar = new MyCalendar();
		calendar.setData(new CalendarEvent[] { new CalendarEvent(1, "Event 1",
				"x", new Date(year, month, start, 9, 15, 0), new Date(year,
						month, start, 9, 44, 0)) });

		calendar.setAutoFetchData(true);

		calendar.setCurrentViewName(ViewName.WEEK);

		calendar.setWorkdayStart("9:00am");
		calendar.setWorkdayEnd("9:00pm");
		calendar.setShowWorkday(true);
		calendar.setScrollToWorkday(true);

		Button button = new Button("Scroll to workday (open day view once before clicking this button)");
		button.setWidth100();
		button.addClickHandler(new ClickHandler() {
			@Override
			public void onClick(ClickEvent event) {
				calendar.myScrollTo();
			}
		});
		mainPanel.addMember(calendar);
		mainPanel.addMember(button);

		RootLayoutPanel.get().add(mainPanel);
		RootPanel.get().add(RootLayoutPanel.get());
	}

}
