package com.ssdi.test.client;

import com.ssdi.test.client.DBListgrid;
import com.smartgwt.client.types.Alignment;
import com.smartgwt.client.types.Overflow;
import com.smartgwt.client.types.SortDirection;
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;

public class ChangesDisplayWindows {
	ListGrid changeLogListforGroup;

	/***
	 * createWindowInfoForGroup()
	 */
	public void DisplayDetailes() {
		DisplayInfo();
	}

	/***
	 * DisplayInfo()
	 */

	private void DisplayInfo() {
		
		final Canvas strCanvas = new Canvas();
		
		VLayout groupChangeConfLayout = new VLayout();
		groupChangeConfLayout.setHeight100();
		groupChangeConfLayout.setWidth100();
		groupChangeConfLayout.setMinWidth(540);
		groupChangeConfLayout.setMinHeight(250);
		groupChangeConfLayout.setMembersMargin(5);
		groupChangeConfLayout.setMargin(5);
		
		// Close Button
		Button btnCloseButton = new Button();
		btnCloseButton.setTitle("CLOSE");
		btnCloseButton.setAlign(Alignment.CENTER);
		btnCloseButton.addClickHandler(new ClickHandler() {

			@Override
			public void onClick(ClickEvent event) {
				// TODO Auto-generated method stub

				strCanvas.hide();
			}
		});
		

		// Filter Section
		SectionStack changeConfirmStack = getGroupChangeConfirmStack();
		groupChangeConfLayout.addMember(changeConfirmStack);
		groupChangeConfLayout.addMember(btnCloseButton);
		
		strCanvas.addChild(groupChangeConfLayout);
		
		strCanvas.show();	
		
	}
	
	

	/***
	 * getGroupChangeConfirmStack()
	 * 
	 * @return
	 */
	private SectionStack getGroupChangeConfirmStack() {
		SectionStack changeConfStack = new SectionStack();
		changeConfStack.setWidth100();
		changeConfStack.setCanReorderSections(false);
		changeConfStack.setCanResizeSections(false);
		changeConfStack.setVisibilityMode(VisibilityMode.MULTIPLE);
		changeConfStack.setOverflow(Overflow.VISIBLE);

		SectionStackSection changeLogSection = new SectionStackSection();
		changeLogSection.setTitle("ChangeLogList");
		changeLogSection.setExpanded(true);

		ListGrid changeLogGrid = getChangeLogGridforGroup();
		changeLogSection.addItem(changeLogGrid);

		changeConfStack.setSections(changeLogSection);

		return changeConfStack;
	}

	
	
	/***
	 * getChangeLogGridforGroup()
	 * 
	 * @return
	 */
	private ListGrid getChangeLogGridforGroup() {

		changeLogListforGroup = new DBListgrid() {

			@Override
			public boolean isSelectionType() {
				return false;
			}

			@Override
			public String getListGridId() {

				return "changeLogListforGroup";
			}

			@Override
			public void addListGridField() {

				ListGridField dateNTimeField = new ListGridField(
						"ChangeConfirmTime");
				dateNTimeField.setWidth("25%");
				dateNTimeField.setAlign(Alignment.LEFT);
				dateNTimeField.setSortByDisplayField(true);
				dateNTimeField.setSortDirection(SortDirection.DESCENDING);

				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);

			}

		};

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

		return changeLogListforGroup;

	}	
}
	

