package com.example.test.client;

import java.util.Date;

import com.google.gwt.core.client.EntryPoint;
import com.smartgwt.client.data.DataSource;
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.widgets.Button;
import com.smartgwt.client.widgets.calendar.Calendar;
import com.smartgwt.client.widgets.layout.VLayout;

/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
public class CTest implements EntryPoint {
  private Calendar calendar;
  /**
   * This is the entry point method.
   */
  public void onModuleLoad() {
    VLayout layout = new VLayout();
    layout.setWidth100();
    layout.setHeight100();
    Button button = new Button("Add event");
    button.addClickHandler(new com.smartgwt.client.widgets.events.ClickHandler() {
      
      @Override
      public void onClick(com.smartgwt.client.widgets.events.ClickEvent event) {
        Date start, end;
        start = new Date();
        end = new Date();
        end.setTime(end.getTime() + 3600 * 1000);
        calendar.addEvent(start, end, "test event", "created from button");
        
      }
    });
    layout.addMember(button);
    DataSource eventDS = new DataSource();
    DataSourceSequenceField eventIdField = new DataSourceSequenceField("eventId");
    eventIdField.setPrimaryKey(true);

    DataSourceTextField nameField = new DataSourceTextField("name");
    DataSourceTextField descField = new DataSourceTextField("description");
    DataSourceDateTimeField startDateField = new DataSourceDateTimeField("startDate");
    DataSourceDateTimeField endDateField = new DataSourceDateTimeField("endDate");

    eventDS.setFields(eventIdField, nameField, descField, startDateField, endDateField);
    eventDS.setClientOnly(true);
    calendar = new Calendar();
    calendar.setDataSource(eventDS);
    calendar.setAutoFetchData(true);
    layout.addMember(calendar);
    layout.draw();
  }
}
