package com.smartgwt.sample.client;

import com.smartgwt.client.data.Criteria;
import com.smartgwt.client.data.DataSource;
import com.smartgwt.client.widgets.Canvas;
import com.smartgwt.client.widgets.form.DynamicForm;
import com.smartgwt.client.widgets.form.fields.FormItemCriteriaFunction;
import com.smartgwt.client.widgets.form.fields.FormItemFunctionContext;
import com.smartgwt.client.widgets.form.fields.SelectItem;
import com.smartgwt.client.widgets.layout.VLayout;
import com.smartgwt.client.widgets.tab.Tab;

public class MyTab extends Tab {
	
	public MyTab() {
		setCanClose(true);
		setTitle("title");
		setPane(createPane());
	}

	private Canvas createPane() {
  
        final DynamicForm form = new DynamicForm();
		form.setHeight100();
		
    	SelectItem sitem = new SelectItem("question", "question") {
//    		@Override  
//    		public Criteria getOptionCriteria()  {
//            protected Criteria getPickListFilterCriteria() {
//    			Criteria criteria = new Criteria();
//    			criteria.addCriteria("answerId", 1);
//                return criteria;
//            } 
    	};
    	sitem.setPickListFilterCriteriaFunction(new FormItemCriteriaFunction(){
			@Override
			public Criteria getCriteria(FormItemFunctionContext itemContext) {
				Criteria criteria = new Criteria();
    			criteria.addCriteria("answerId", 1);
                return criteria;
			}});
		sitem.setOptionDataSource(DataSource.get("brancheFlagDS"));
		sitem.setAlwaysFetchMissingValues(true);
		sitem.setValueField("id");
		sitem.setDisplayField("name");
		sitem.setAutoFetchData(false);
		form.setFields(sitem);
		VLayout layout = new VLayout();
		layout.addMember(form);  
  
        return layout;
	}

}
