package com.rv.gwtsample.client;

import com.smartgwt.client.types.Alignment;  
import com.smartgwt.client.types.ListGridFieldType;  
import com.smartgwt.client.util.SC;  
import com.smartgwt.client.widgets.Canvas;  
import com.smartgwt.client.widgets.ImgButton;  
import com.smartgwt.client.widgets.events.ClickEvent;  
import com.smartgwt.client.widgets.events.ClickHandler;  
import com.smartgwt.client.widgets.grid.ListGrid;  
import com.smartgwt.client.widgets.grid.ListGridField;  
import com.smartgwt.client.widgets.grid.ListGridRecord;  
import com.smartgwt.client.widgets.layout.HLayout;  

import com.google.gwt.core.client.EntryPoint;



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

    private HLayout rollOverCanvas;  
    private ListGridRecord rollOverRecord;  
    
	/**
	 * This is the entry point method.
	 */
	public void onModuleLoad() {
//		showListGridSample();
		JobInputDialog dialog = new JobInputDialog();
		dialog.draw();
	      
	}

	
	
	private void showListGridSample() {
		final ListGrid countryGrid = new ListGrid() {  
            @Override  
            protected Canvas getRollOverCanvas(Integer rowNum, Integer colNum) {  
                rollOverRecord = this.getRecord(rowNum);  
  
                if(rollOverCanvas == null) {  
                    rollOverCanvas = new HLayout(3);  
                    rollOverCanvas.setSnapTo("TR");  
                    rollOverCanvas.setWidth(50);  
                    rollOverCanvas.setHeight(22);  
  
                    ImgButton editImg = new ImgButton();  
                    editImg.setShowDown(false);  
                    editImg.setShowRollOver(false);  
                    editImg.setLayoutAlign(Alignment.CENTER);  
                    editImg.setSrc("success-icon.png");  
                    editImg.setPrompt("Edit Comments");  
                    editImg.setHeight(16);  
                    editImg.setWidth(16);  
                    editImg.addClickHandler(new ClickHandler() {  
                        public void onClick(ClickEvent event) {  
                            SC.say("Edit Comment Icon Clicked for country : " + rollOverRecord.getAttribute("countryName"));  
                        }  
                    });  
  
                    ImgButton chartImg = new ImgButton();  
                    chartImg.setShowDown(false);  
                    chartImg.setShowRollOver(false);  
                    chartImg.setLayoutAlign(Alignment.CENTER);  
                    chartImg.setSrc("warning-icon.png");  
                    chartImg.setPrompt("View Chart");  
                    chartImg.setHeight(16);  
                    chartImg.setWidth(16);  
                    chartImg.addClickHandler(new ClickHandler() {  
                        public void onClick(ClickEvent event) {  
                            SC.say("Chart Icon Clicked for country : " + rollOverRecord.getAttribute("countryName"));  
                        }  
                    });  
                    
                    ImgButton brokenImg = new ImgButton();  
                    brokenImg.setShowDown(false);  
                    brokenImg.setShowRollOver(false);  
                    brokenImg.setLayoutAlign(Alignment.CENTER);  
                    brokenImg.setSrc("broken.png");  
                    brokenImg.setPrompt("Broken Job!");  
                    brokenImg.setHeight(16);  
                    brokenImg.setWidth(16);  
                    brokenImg.addClickHandler(new ClickHandler() {  
                        public void onClick(ClickEvent event) {  
                            SC.say("Broken Job Clicked for country : " + rollOverRecord.getAttribute("countryName"));  
                        }  
                    });  
                    ImgButton startImg = new ImgButton();  
                    startImg.setShowDown(false);  
                    startImg.setShowRollOver(false);  
                    startImg.setLayoutAlign(Alignment.CENTER);  
                    startImg.setSrc("add-icon.png");  
                    startImg.setPrompt("Start Job!");  
                    startImg.setHeight(16);  
                    startImg.setWidth(16);  
                    startImg.addClickHandler(new ClickHandler() {  
                        public void onClick(ClickEvent event) {  
                            SC.say("Start Job Clicked for country : " + rollOverRecord.getAttribute("countryName"));  
                        }  
                    });  
                    
                    
                    ImgButton stopImg = new ImgButton();  
                    stopImg.setShowDown(false);  
                    stopImg.setShowRollOver(false);  
                    stopImg.setLayoutAlign(Alignment.CENTER);  
                    stopImg.setSrc("delete-icon.png");  
                    stopImg.setPrompt("Start Job!");  
                    stopImg.setHeight(16);  
                    stopImg.setWidth(16);  
                    stopImg.addClickHandler(new ClickHandler() {  
                        public void onClick(ClickEvent event) {  
                            SC.say("Start Job Clicked for country : " + rollOverRecord.getAttribute("countryName"));  
                        }  
                    });  
  
                    ImgButton pauseImg = new ImgButton();  
                    pauseImg.setShowDown(false);  
                    pauseImg.setShowRollOver(false);  
                    pauseImg.setLayoutAlign(Alignment.CENTER);  
                    pauseImg.setSrc("edit-icon.png");  
                    pauseImg.setPrompt("Start Job!");  
                    pauseImg.setHeight(16);  
                    pauseImg.setWidth(16);  
                    pauseImg.addClickHandler(new ClickHandler() {  
                        public void onClick(ClickEvent event) {  
                            SC.say("Start Job Clicked for country : " + rollOverRecord.getAttribute("countryName"));  
                        }  
                    });  
                    rollOverCanvas.addMember(editImg);  
                    rollOverCanvas.addMember(chartImg);
                    rollOverCanvas.addMember(brokenImg);
                    rollOverCanvas.addMember(startImg);
                    rollOverCanvas.addMember(stopImg);
                    rollOverCanvas.addMember(pauseImg);
                    
                }  
                return rollOverCanvas;  
  
            }  
        };  
        countryGrid.setShowRollOverCanvas(true);  
  
  
        countryGrid.setWidth(550);  
        countryGrid.setHeight(224);  
        countryGrid.setShowAllRecords(true);  
  
        ListGridField countryCodeField = new ListGridField("countryCode", "Flag", 40);  
        countryCodeField.setAlign(Alignment.CENTER);  
        countryCodeField.setType(ListGridFieldType.IMAGE);  
        countryCodeField.setImageURLPrefix("flags/16/");  
        countryCodeField.setImageURLSuffix(".png");  
  
        ListGridField nameField = new ListGridField("countryName", "Country");  
        ListGridField capitalField = new ListGridField("capital", "Capital");  
        ListGridField continentField = new ListGridField("continent", "Continent");  
        countryGrid.setFields(countryCodeField, nameField, capitalField, continentField);  
        countryGrid.setCanResizeFields(true);  
        countryGrid.setData(CountryData.getRecords());  
  
        countryGrid.draw();  
    }  
}