package com.ho.nomad.client;

import com.google.gwt.core.client.EntryPoint;
import com.smartgwt.client.types.Side;   
import com.smartgwt.client.widgets.Canvas;   
import com.smartgwt.client.widgets.IButton;   
import com.smartgwt.client.widgets.Img;   
import com.smartgwt.client.widgets.events.ClickEvent;   
import com.smartgwt.client.widgets.events.ClickHandler;   
import com.smartgwt.client.widgets.layout.HLayout;   
import com.smartgwt.client.widgets.layout.VLayout;   
import com.smartgwt.client.widgets.tab.Tab;   
import com.smartgwt.client.widgets.tab.TabSet;   

import com.smartgwt.client.data.DataSource;   
import com.smartgwt.client.widgets.Label;   
import com.smartgwt.client.widgets.form.DynamicForm;   
import com.smartgwt.client.widgets.grid.ListGrid;   
import com.smartgwt.client.widgets.grid.events.RecordClickEvent;   
import com.smartgwt.client.widgets.grid.events.RecordClickHandler;  



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

	/**
	 * This is the entry point method.
	 */
	public void onModuleLoad()
	{
		
		final TabSet topTabSet = new TabSet();   
        topTabSet.setTabBarPosition(Side.TOP);   
        topTabSet.setWidth("100%");   
        topTabSet.setHeight("100%");   
  
        Tab tTab1 = new Tab("PDA List");   
        Tab tTab2 = new Tab("PDA Data Matrix");
        Tab tTab3 = new Tab("PDA Sych rules");
        Tab tTab4 = new Tab("PDA Roles");
  
        topTabSet.addTab(tTab1);   
        topTabSet.addTab(tTab2);  
        topTabSet.addTab(tTab3);   
        topTabSet.addTab(tTab4);  
  
        createTabContent(tTab1);
  
        VLayout vLayout = new VLayout();   
        vLayout.setMembersMargin(15);   
        vLayout.addMember(topTabSet);   

        vLayout.setHeight("100%");
        vLayout.setWidth("100%");
        
        vLayout.draw();   

	}
	
	public void createTabContent(Tab tab)
	{
        final Canvas canvas = new Canvas();   
		
		VLayout layout = new VLayout(15);   
        
		DataSource ds = DataSource.get("PDA");
		
        final DynamicForm form = new DynamicForm();   
        form.setIsGroup(true);   
        form.setGroupTitle("Update");   
        form.setNumCols(4);   
        form.setDataSource(ds);   
  
  
        final ListGrid listGrid = new ListGrid();   
        listGrid.setWidth100();   
        listGrid.setHeight(200);   
        listGrid.setDataSource(DataSource.get("PDA"));   
        listGrid.setAutoFetchData(true);   
        listGrid.addRecordClickHandler(new RecordClickHandler() {   
            public void onRecordClick(RecordClickEvent event) {   
                form.reset();   
                form.editSelectedData(listGrid);   
            }   
        });   
  
        layout.addMember(listGrid);   
        layout.addMember(form);   
  
        IButton button = new IButton("Save");   
        button.addClickHandler(new ClickHandler() {   
            public void onClick(ClickEvent event) {   
                form.saveData();                   
            }   
        });   
        layout.addMember(button);
        canvas.addChild(layout);
        tab.setPane(canvas);   
	}
	
}
