package com.ssdi.test.client;



import com.google.gwt.core.client.JavaScriptObject;
import com.smartgwt.client.types.Alignment;
import com.smartgwt.client.types.VerticalAlignment;
import com.smartgwt.client.util.JSOHelper;
import com.smartgwt.client.widgets.IButton;
import com.smartgwt.client.widgets.form.DynamicForm;
import com.smartgwt.client.widgets.form.fields.PasswordItem;
import com.smartgwt.client.widgets.form.fields.SectionItem;
import com.smartgwt.client.widgets.form.fields.events.BlurEvent;
import com.smartgwt.client.widgets.form.fields.events.BlurHandler;
import com.smartgwt.client.widgets.layout.HLayout;
import com.smartgwt.client.widgets.layout.VLayout;

public class SystemSettings {

    // Creating instance to SystemSettings
    private static SystemSettings instance = new SystemSettings();
    //private static WebUIConstants CONSTANTS = ResourceString.getConstants();
    // Providing single point of access to SystemSettings
    public static SystemSettings getInstance() {
	return instance;
    }
    
    public void showPasswordWindow(){


    	final WebUIPopUPWindow passwordWindow = new WebUIPopUPWindow() {

    	    @Override
    	    public String getTitle() {
    		
    		return "Test Window";
    	    }

    	   

    	    @Override
    	    public HLayout createFooterLayout() {

    		HLayout okAndCancleLayoput = new HLayout();
    		okAndCancleLayoput.setWidth(525);
    		okAndCancleLayoput.setHeight(20);
    		okAndCancleLayoput.setAlign(Alignment.CENTER);
    		okAndCancleLayoput.setMembersMargin(5);
    		okAndCancleLayoput.setMargin(10);

    		// setting Id to the Button Component for automation
    		JavaScriptObject chngPswJso = JavaScriptObject.createObject();
    		String chngPswId = "page_ChangePassword_IButton_savePasswordBtn";
    		JSOHelper.setAttribute(chngPswJso, "ID", chngPswId);

    		IButton okButton = new IButton("OK");
    		okButton.setAutoFit(true);
    		okButton.setID(chngPswId);
    		okButton.setAlign(Alignment.CENTER);
    		okButton.addClickHandler(new com.smartgwt.client.widgets.events.ClickHandler() {

    		    @Override
    		    public void onClick(
    			    com.smartgwt.client.widgets.events.ClickEvent event) {


    		    }

    		   
    		});

    		// setting Id to the Button Component for automation
    		JavaScriptObject cancelPswJso = JavaScriptObject.createObject();
    		String cancelPswbtnId = "page_ChangePassword_IButton_cancelPasswordBtn";
    		JSOHelper.setAttribute(cancelPswJso, "ID", cancelPswbtnId);

    		IButton cancleButton = new IButton("CLOSE");
    		cancleButton.setAutoFit(true);
    		cancleButton.setID(cancelPswbtnId);
    		cancleButton.setAlign(Alignment.CENTER);
    		cancleButton
    			.addClickHandler(new com.smartgwt.client.widgets.events.ClickHandler() {

    			    @Override
    			    public void onClick(
    				    com.smartgwt.client.widgets.events.ClickEvent event) {
    			    }
    			});

    		okAndCancleLayoput.addMember(okButton);
    		okAndCancleLayoput.addMember(cancleButton);

    		return okAndCancleLayoput;
    	    }

    	    @Override
    	    public void addHandler() {
    		

    	    }

    	    @Override
    	    public WebUIWindow createWindow() {
    		return new WebUIWindow(getTitle()) {
    		    public int getRequiredWindowHeight() {
    			return 175;

    		    }

    		    public int getRequiredWindowWidth() {
    			return 650;
    		    }

    		    public void destroyWindow() {
    			this.destroy();
    		    }

    		};
    	    }

    	    @Override
    	    public void addCustomLayout(VLayout layout) {

    		/*passwordWindowins = getWindow();
    		passwordWindowins.setMinHeight(175);*/

    		layout.setWidth100();
    		layout.setHeight(120);
    		layout.setAlign(VerticalAlignment.TOP);
    		layout.addMember(getpasswordChangeWIndowForm());

    	    }

    	};

    	passwordWindow.openWindow();

        
    }
    private DynamicForm passwordChangeForm;
    private SectionItem passwordChangeSectionItem;
    private PasswordItem newPasswordTextItem;
    private PasswordItem newPasswordConfirmationTextItem;

    protected DynamicForm getpasswordChangeWIndowForm() {

    	passwordChangeForm = new DynamicForm();
    	passwordChangeForm.setRequiredTitlePrefix("");
    	passwordChangeForm.setNumCols(3);
    	passwordChangeForm.setBorder("1px solid gray");
    	passwordChangeForm.setMargin(2);

    	passwordChangeSectionItem = new SectionItem();
    	passwordChangeSectionItem.setDefaultValue("test");
    	passwordChangeSectionItem.setCanCollapse(false);

    	newPasswordTextItem = new PasswordItem();
    	newPasswordTextItem.setTitle("TEST PASSWORD");
    	newPasswordTextItem.setCanEdit(true);
    	newPasswordTextItem.setWidth(250);
    	newPasswordTextItem.setHeight("25px");
    	newPasswordTextItem.setRequired(true);
    	
    								
    	newPasswordTextItem.addBlurHandler(new BlurHandler() {

    	    @Override
    	    public void onBlur(BlurEvent event) {

    		if (!(newPasswordTextItem.validate())) {
    		    ////fieldValidator = false;
    		    // newPasswordTextItem.setValue("");
    		    newPasswordTextItem.clearValue();

    		} else {
    		    ////fieldValidator = true;

    		}

    	    }
    	});

    	newPasswordConfirmationTextItem = new PasswordItem();
    	newPasswordConfirmationTextItem.setTitle("CONFORM");
    	
    	newPasswordConfirmationTextItem.setCanEdit(true);
    	newPasswordConfirmationTextItem.setWidth(250);
    	newPasswordConfirmationTextItem.setHeight("25px");
    	newPasswordConfirmationTextItem.setWrapTitle(false);
    	newPasswordConfirmationTextItem.setRequired(true);
    	
    	newPasswordConfirmationTextItem.addBlurHandler(new BlurHandler() {

    	    @Override
    	    public void onBlur(BlurEvent event) {

    		if (!(newPasswordConfirmationTextItem.validate())) {
    		    ////fieldValidator = false;
    		    newPasswordConfirmationTextItem.setValue("");

    		} else {
    		    ////fieldValidator = true;

    		}

    	    }
    	});

    	passwordChangeForm.setItems(passwordChangeSectionItem,
    		newPasswordTextItem, newPasswordConfirmationTextItem);

    	return passwordChangeForm;

        }


}
