package com.ssdi.test.client;

import com.google.gwt.core.client.EntryPoint;
import com.smartgwt.client.types.Alignment;
import com.smartgwt.client.types.Overflow;
import com.smartgwt.client.types.VisibilityMode;
import com.smartgwt.client.widgets.Button;
import com.smartgwt.client.widgets.Canvas;
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.grid.ListGridField;
import com.smartgwt.client.widgets.layout.SectionStack;
import com.smartgwt.client.widgets.layout.SectionStackSection;
import com.smartgwt.client.widgets.layout.VLayout;

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

	ListGrid changeLogGrid;
	public void onModuleLoad() {

		//
		// Canvas
		Canvas mainCanvas = new Canvas(); 
		mainCanvas.setHeight100();
		mainCanvas.setWidth100();
		mainCanvas.setMargin(25);
		mainCanvas.setAlign(Alignment.CENTER);

		//
		// Display Button
		Button btnShowButton = new Button();
		btnShowButton.setTitle("SHOW");

		btnShowButton.addClickHandler(new ClickHandler() {

			@Override
			public void onClick(ClickEvent event) {

				DisplayInfo();

			}
		});

		//
		// Display Canvas
		mainCanvas.addChild(btnShowButton);
		mainCanvas.show();

	}

	/**
	 * DisplayInfo()
	 */

	private void DisplayInfo() {

		final Canvas mainCanvas = new Canvas();

		//
		// / Vertical Layout
		VLayout verticalLayout = new VLayout();
		verticalLayout.setHeight100();
		verticalLayout.setWidth100();
		verticalLayout.setMinWidth(540);
		verticalLayout.setMinHeight(250);
		verticalLayout.setMembersMargin(5);
		verticalLayout.setMargin(5);

		//
		// / Main Section Stack
		SectionStack mainSectionStack = new SectionStack();
		mainSectionStack.setWidth100();
		mainSectionStack.setHeight100();
		mainSectionStack.setVisibilityMode(VisibilityMode.MULTIPLE);
		mainSectionStack.setOverflow(Overflow.VISIBLE);

		//
		// / Inner section stack
		SectionStackSection innerSectionStack = new SectionStackSection();
		innerSectionStack.setTitle("ChangeLogList");
		innerSectionStack.setExpanded(true);

		//
		// / List Grid
		changeLogGrid = new DBListgrid() {

			@Override
			public void addListGridField() {
				ListGridField dateNTimeField = new ListGridField("ChangeConfirmTime");
				dateNTimeField.setWidth("25%");

				ListGridField modelNameField = new ListGridField("Name");
				modelNameField.setWidth("25%");

				ListGridField ipAddressField = new ListGridField("Address");
				ipAddressField.setWidth("25%");

				ListGridField changeAvailField = new ListGridField("Availability");
				changeAvailField.setWidth("25%");

				setFields(dateNTimeField, modelNameField, ipAddressField, changeAvailField);
			}

			@Override
			public String getListGridId() {
				// TODO Auto-generated method stub
				return null;
			}
		};

		changeLogGrid.setCanAutoFitFields(false);
		changeLogGrid.setWidth("100%");
		changeLogGrid.setDrawAheadRatio(4);
		changeLogGrid.setCanExpandRecords(true);

		innerSectionStack.addItem(changeLogGrid);
		mainSectionStack.setSections(innerSectionStack);

		// Close Button
		Button btnCloseButton = new Button();
		btnCloseButton.setTitle("CLOSE");

		btnCloseButton.addClickHandler(new ClickHandler() {

			@Override
			public void onClick(ClickEvent event) {

				mainCanvas.hide();
			}

		});

		//
		// / Add main section stack to Vlayout
		verticalLayout.addMember(mainSectionStack);
		verticalLayout.addMember(btnCloseButton);

		//
		// / Add vlayout to canvas and show
		mainCanvas.addChild(verticalLayout);
		mainCanvas.show();

	}

}
