package com.example.client;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.smartgwt.client.data.Criteria;
import com.smartgwt.client.data.DSRequest;
import com.smartgwt.client.data.DSResponse;
import com.smartgwt.client.data.DataSource;
import com.smartgwt.client.types.Overflow;
import com.smartgwt.client.widgets.Canvas;
import com.smartgwt.client.widgets.Label;
import com.smartgwt.client.widgets.form.DynamicForm;
import com.smartgwt.client.widgets.form.fields.SelectItem;
import com.smartgwt.client.widgets.layout.SectionStack;
import com.smartgwt.client.widgets.layout.SectionStackSection;
import com.smartgwt.client.widgets.layout.VLayout;

public class SectionStackExample implements EntryPoint {
	DataSource ds=null;
	@Override
	public void onModuleLoad() {
		ds=new GwtRpcDataSource() {
			@Override
			protected void executeFetch(String requestId, DSRequest request, DSResponse response) {
				GWT.log("--------------executeFetch");
				GWT.log("criteria: "+request.getCriteria().getAttribute("deployType"));
			}
		};
		
		VLayout vLayout=new VLayout();
		SectionStack profileStack=new SectionStack();
		
		SectionStackSection createProfileSection=new SectionStackSection("Create Profile");
		SectionStackSection loadProfileSection=new SectionStackSection("Load Profile");
		final SectionStackSection editProfileSection=new SectionStackSection("Edit Profile");
		
		
		
		createProfileSection.addItem(new Label("create profile section..."));
		loadProfileSection.addItem(new Label("load profile section..."));
		editProfileSection.addItem(getEditProfileCanvas());
		
		
		profileStack.addSection(createProfileSection);
		profileStack.addSection(loadProfileSection);
		profileStack.addSection(editProfileSection);
				  
		profileStack.setWidth("650");
		 
		profileStack.setAutoHeight();
		/*profileStack.setAutoWidth();*/
		profileStack.setOverflow(Overflow.VISIBLE);
		vLayout.addMember(profileStack);
		vLayout.setMembersMargin(10);
		vLayout.draw();

	}

	private Canvas getEditProfileCanvas() {
		GWT.log("getEditProfileCanvas");
		VLayout vlayout=new VLayout();
		DynamicForm dForm=new DynamicForm();
		dForm.setDataSource(ds);
		final SelectItem profiles=new SelectItem("selProfile","Available Profiles");
		Criteria crit=new Criteria("deployType", "Release");
		dForm.setInitialCriteria(crit);
		dForm.setAutoFetchData(true);
		dForm.setItems(profiles);
		vlayout.addMember(dForm);
		return vlayout;
	}

}
