package com.smartgwt.sample.client;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.smartgwt.client.bean.BeanFactory;
import com.smartgwt.client.rpc.LoadScreenCallback;
import com.smartgwt.client.rpc.RPCManager;
import com.smartgwt.client.util.SC;
import com.smartgwt.client.widgets.Button;
import com.smartgwt.client.widgets.Canvas;
import com.smartgwt.client.widgets.events.ClickEvent;
import com.smartgwt.client.widgets.events.ClickHandler;
import com.smartgwt.client.widgets.form.DynamicForm;

/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
public class BuiltInDS implements EntryPoint {
    @Override  
    public void onModuleLoad() {   
    	 // Make all form items (including CKEditorItem) reflectable:
 		GWT.create(BeanFactory.FormItemMetaFactory.class);
        final Canvas layout = new Canvas();   
        RPCManager.loadScreen("ckeditor", new LoadScreenCallback() {   
            @Override  
            public void execute() {   
                Button saveButton = (Button) this.getScreen().getByLocalId("saveButton");   
                final DynamicForm saveForm = (DynamicForm) this.getScreen().getByLocalId("saveForm");   
                saveButton.addClickHandler(new ClickHandler() {   
                    @Override  
                    public void onClick(ClickEvent event) {   
                      /*  if (Boolean.FALSE.equals((Boolean)saveForm.getValue("inStock")) &&   
                            saveForm.getValue("nextShipment") == null) {   
                            SC.warn("New stock items which are not already stocked must have a Stock Date");   
                        }   */
                    	Object obj = saveForm.getValue("testItem");
                    	
                    	
                    	
                    	if ( null != obj ) {
                    		SC.say( obj.toString() );
                    	} else {
                    		
                    		SC.say(" can not get the value ");
                    	}
                    	saveForm.saveData();
                    }   
                });   
                layout.addChild(this.getScreen());   
            }   

        });   
        
        layout.draw();   
    }
}
