package com.smartgwt.sample.client;

import java.util.ArrayList;
import java.util.List;

import com.google.gwt.core.client.EntryPoint;
import com.smartgwt.client.data.Criteria;
import com.smartgwt.client.types.Alignment;
import com.smartgwt.client.types.VerticalAlignment;
import com.smartgwt.client.widgets.form.DynamicForm;
import com.smartgwt.client.widgets.form.fields.FormItem;
import com.smartgwt.client.widgets.form.fields.SelectItem;
import com.smartgwt.client.widgets.form.fields.TextItem;
import com.smartgwt.client.widgets.grid.ListGrid;
import com.smartgwt.client.widgets.layout.HStack;

/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
public class Testcase implements EntryPoint {

    /**
     * This is the entry point method.
     */
    public void onModuleLoad() {
    	HStack hStack = new HStack(10);  
        hStack.setHeight(160);  
  
        DynamicForm form = new DynamicForm();
        form.setIsGroup(true);
        form.setTitle("title");
		form.setHeight100();
		form.setValidateOnExit(true);
		form.setTitleAlign(Alignment.LEFT);
		form.setTitleWidth(150);
		form.setFixedColWidths(true);
		form.setTitleSuffix("");
		form.setRequiredTitleSuffix("");
		form.setLayoutAlign(VerticalAlignment.BOTTOM);
		List<SelectItem> items = new ArrayList<SelectItem>();
        for (int i=1; i<4; i++) {
        	SelectItem sitem = new SelectItem("Name"+i, "text");
			sitem.setOptionDataSource(ClientOnlyDS.getInstance());
			Criteria criteria = new Criteria();
			criteria.addCriteria("answerId", i);
//			sitem.setOptionCriteria(criteria);
			sitem.setPickListCriteria(criteria);
			sitem.setValueField("value");
			sitem.setDisplayField("displayText");
			sitem.setAlwaysFetchMissingValues(true);
			sitem.setValue("ODP"+i);									
			items.add(sitem);
        }
		form.setFields(items.toArray(new FormItem[items.size()]));
        
        hStack.addMember(form);  
  
        hStack.draw();  
    }
    
    public void onModuleLoadboo() {
    	HStack hStack = new HStack(10);  
        hStack.setHeight(160);  
  
        ListGrid userGrid = new ListGrid();
        userGrid.setDataSource(ClientOnlyDS.getInstance());
        userGrid.setAutoFetchData(true); 
        
        DynamicForm form = new DynamicForm();
        form.setIsGroup(true);
		form.setHeight100();
		form.setValidateOnExit(true);
		form.setTitleAlign(Alignment.LEFT);
		form.setTitleWidth(150);
		form.setFixedColWidths(true);
		form.setTitleSuffix("");
		form.setRequiredTitleSuffix("");
		form.setLayoutAlign(VerticalAlignment.BOTTOM);
		form.setDataSource(ClientOnlyDS.getInstance());
		
        SelectItem item = new SelectItem("boo", "Title");
        TextItem codeItem = new TextItem("code");
		codeItem.setWidth(300);
		codeItem.setValue("Some text");
		codeItem.setDisabled(true);
		
		form.setFields(item, codeItem);
        
        hStack.addMember(userGrid);  
        hStack.addMember(form);  
  
        hStack.draw();  
    }
}
