package com.smartgwt.sample.client;

import com.smartgwt.client.types.Alignment;
import com.smartgwt.client.types.VerticalAlignment;
import com.smartgwt.client.widgets.Canvas;
import com.smartgwt.client.widgets.Window;
import com.smartgwt.client.widgets.events.CloseClickEvent;
import com.smartgwt.client.widgets.events.CloseClickHandler;
import com.smartgwt.client.widgets.form.DynamicForm;
import com.smartgwt.client.widgets.form.fields.ButtonItem;
import com.smartgwt.client.widgets.form.fields.FileItem;
import com.smartgwt.client.widgets.form.fields.SpacerItem;
import com.smartgwt.client.widgets.layout.VLayout;

public class MyWindow extends Window {
	private FileItem fileItem;

	public MyWindow(String title) {
		init(title);
	}

	private void init(String title) {
		this.setTitle(title);
		this.setShowMinimizeButton(false);
		this.setIsModal(true);
		this.setShowModalMask(true);
		this.addItem(createContent());
		this.addCloseClickHandler(new CloseClickHandler() {
			public void onCloseClick(CloseClickEvent event) {
				destroy();
			}
		});
		this.setAutoSize(true);
		this.setAutoCenter(true);
		this.setShowFooter(true);
	}

	private Canvas createContent() {
		VLayout mainLayout = new VLayout();
		mainLayout.setWidth100();
		mainLayout.setHeight100();
		mainLayout.setMargin(10);
		mainLayout.setMembersMargin(10);

		final DynamicForm form = new DynamicForm();
		form.setIsGroup(true);
		form.setPadding(10);
		form.setWidth(470);
		form.setValidateOnExit(true);
		form.setValidateOnChange(false);
		form.setTitleAlign(Alignment.LEFT);
		form.setTitleWidth(150);
		form.setFixedColWidths(true);
		form.setTitleSuffix("");
		form.setRequiredTitleSuffix("");
		form.setLayoutAlign(VerticalAlignment.BOTTOM);
		form.setGroupTitle("File selection");
		form.setAutoFetchData(false);

		fileItem = new FileItem("report", "Name of import file");
		fileItem.setWidth(300);
		fileItem.setRequired(true);

		SpacerItem spacerItem = new SpacerItem();
		spacerItem.setEndRow(false);
		ButtonItem uploadItem = new ButtonItem("save", "Upload");
		uploadItem.setStartRow(false);
		uploadItem.setDisabled(true);
		form.setFields(fileItem, spacerItem, uploadItem);

		mainLayout.addMember(form);

		return mainLayout;
	}
}
