package com.ssdi.test.client;

import com.smartgwt.client.types.Alignment;
import com.smartgwt.client.widgets.IButton;
import com.smartgwt.client.widgets.Window;
import com.smartgwt.client.widgets.events.ClickEvent;
import com.smartgwt.client.widgets.events.ClickHandler;
import com.smartgwt.client.widgets.form.DynamicForm;
import com.smartgwt.client.widgets.form.fields.PasswordItem;
import com.smartgwt.client.widgets.form.fields.StaticTextItem;
import com.smartgwt.client.widgets.layout.HLayout;
import com.smartgwt.client.widgets.layout.VLayout;

public class FileDownloadWindow extends Window{

	DynamicForm downloadForm;
	private VLayout mainVLayout;
	private HLayout buttonHLayout;
	PasswordItem downloadPwdField;
	private Window sampleWindow;
	public FileDownloadWindow()
	{
		
	}
		 
	public void createMainSection() {
		mainVLayout = new VLayout();
		mainVLayout.setWidth("100%");
		mainVLayout.setMargin(5);
		mainVLayout.setLayoutTopMargin(20);
		mainVLayout.setMinWidth(120);
		mainVLayout.setMinHeight(310);
		mainVLayout.setAlign(Alignment.CENTER);
		
		buttonHLayout = new HLayout(5);
		buttonHLayout.setAlign(Alignment.CENTER);
		
		createButtonLayout();
		
		downloadForm = new DynamicForm();
		downloadForm.setNumCols(2);
		downloadForm.setWidth100();
		downloadForm.setHeight(60);
		downloadForm.setAlign(Alignment.CENTER);
		downloadForm.setHiliteRequiredFields(false);
		downloadForm.setRequiredTitlePrefix("");
		downloadForm.setRequiredRightTitlePrefix("*");
		StaticTextItem fileNameField = new StaticTextItem("File Name");
		fileNameField.setWrap(false);
		fileNameField.setValue("sample text String for testing the Static text item value");
		
		
		downloadPwdField=new PasswordItem("Passowrd Item");
		downloadPwdField.setTitleAlign(Alignment.LEFT);
		downloadPwdField.setWrapTitle(false);
		downloadPwdField.setRequired(true);
		downloadPwdField.setShowErrorStyle(false);
		downloadForm.setItems(fileNameField,downloadPwdField);
		
		mainVLayout.addMember(downloadForm);
		mainVLayout.addMember(buttonHLayout);
		
		sampleWindow=new Window();
		sampleWindow.centerInPage();
		sampleWindow.setHeight(160);
		sampleWindow.setWidth(350);
		sampleWindow.setTitle("File Download");
        
        sampleWindow.setCanDragResize(true);  
        sampleWindow.addItem(mainVLayout);  
        sampleWindow.show();
		
	}

	private void createButtonLayout() {
		
		IButton okButton = new IButton();
		okButton.setTitle("OK");
		
		okButton.addClickHandler(new ClickHandler() {
			
			@Override
			public void onClick(ClickEvent event) {}
		});
		
		IButton cancelButton = new IButton();
		cancelButton.setTitle("Cancel");
		
		cancelButton.addClickHandler(new ClickHandler() {
			
			@Override
			public void onClick(ClickEvent event) {
				sampleWindow.destroy();
			}
		});
		
		
		buttonHLayout.addMembers(okButton,cancelButton);
		
		
		
	}

}
