package test.client;

import com.google.gwt.core.client.EntryPoint;
import com.smartgwt.client.data.DataSource;
import com.smartgwt.client.data.fields.DataSourceTextField;
import com.smartgwt.client.types.VisibilityMode;
import com.smartgwt.client.widgets.Canvas;
import com.smartgwt.client.widgets.IButton;
import com.smartgwt.client.widgets.events.ClickEvent;
import com.smartgwt.client.widgets.events.ClickHandler;
import com.smartgwt.client.widgets.layout.SectionStack;
import com.smartgwt.client.widgets.layout.SectionStackSection;
import com.smartgwt.client.widgets.layout.VLayout;

public class TestIso implements EntryPoint {

	public void onModuleLoad() {

		final DataSource ds = new DataSource();

        DataSourceTextField textField = new DataSourceTextField("textItem");  
        DataSourceTextField commentField1 = new DataSourceTextField("comment");  
  
        ds.setFields(textField, commentField1);  

		final AForm editForm = new AForm();
		
		editForm.setDataSource(ds);
		editForm.setCanEdit(false);

		final SectionStack sectionStack = new SectionStack();
		sectionStack.setVisibilityMode(VisibilityMode.MULTIPLE);
		sectionStack.setWidth100();
		sectionStack.setHeight100();

		SectionStackSection section1 = new SectionStackSection("Form Section");
		section1.setExpanded(false);
		section1.addItem(editForm);
		sectionStack.addSection(section1);

		Canvas textCanvas = new Canvas("canvas");
		textCanvas.setContents("Press 'Edit form' button. ");
		
		SectionStackSection section3 = new SectionStackSection("Text Section");
		section3.setExpanded(true);
		section3.setCanCollapse(false);
		section3.addItem(textCanvas);
		sectionStack.addSection(section3);

		IButton editButton = new IButton("Edit form");
		editButton.setWidth(150);
		editButton.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				sectionStack.expandSection(0);
				editForm.setCanEdit(true);
			}
		});

		IButton noEditButton = new IButton("noEdit form");
		noEditButton.setWidth(150);
		noEditButton.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				editForm.setCanEdit(false);
			}
		});

		VLayout layout = new VLayout();
		layout.setMembersMargin(10);
		layout.setHeight100();
		layout.setWidth100();
		layout.addMember(editButton);
		layout.addMember(noEditButton);
		layout.addMember(sectionStack);
		
		layout.draw();
	}

}