package com.focussscm.client.gwt.browser;

import com.focussscm.client.gwt.browser.rpc.FocussClientServiceCaller;
import com.focussscm.client.gwt.browser.tmp.MultiAxisChartData;
import com.focussscm.model.dto.DummyDTO;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.RootPanel;
import com.smartgwt.client.types.ChartType;
import com.smartgwt.client.types.TitleOrientation;  
import com.smartgwt.client.widgets.Canvas;  
import com.smartgwt.client.widgets.IButton;  
import com.smartgwt.client.widgets.chart.FacetChart;
import com.smartgwt.client.widgets.chart.MetricSettings;
import com.smartgwt.client.widgets.cube.Facet;
import com.smartgwt.client.widgets.cube.FacetValue;
import com.smartgwt.client.widgets.events.ClickEvent;  
import com.smartgwt.client.widgets.events.ClickHandler;  
import com.smartgwt.client.widgets.form.DynamicForm;  
import com.smartgwt.client.widgets.form.fields.FormItem;  
import com.smartgwt.client.widgets.form.fields.PasswordItem;  
import com.smartgwt.client.widgets.form.fields.TextItem;  
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;

/**
 * This class is the entry point for the GWT framework
 * @author rosorio
 *
 */
public class FocussClientEntryPoint implements EntryPoint {
	TitleOrientation titleOrientation = TitleOrientation.LEFT;  
	 
	/**
	 * First method executed when a GWT page is opened
	 */
    public void onModuleLoad() {
    	
    	 
    	
        
        try{
        	
        	RootPanel.get("formContainer").add(getChart1());
        	
        }catch(Exception e){
        	
        	Window.alert(e.getMessage());
        }
        
        /*
        HLayout layout = new HLayout();  
    	layout.setLayoutMargin(20);
    	layout.setWidth(800);
        
        final DynamicForm form = new DynamicForm();  
        form.setWidth(250);  
          
        final TextItem usernameItem = new TextItem();  
        usernameItem.setTitle("Username");  
        usernameItem.setRequired(true);  
        usernameItem.setDefaultValue("bob");  
  
        TextItem emailItem = new TextItem();  
        emailItem.setTitle("Email");  
        emailItem.setRequired(true);  
        emailItem.setDefaultValue("bob@isomorphic.com");  
  
        PasswordItem passwordItem = new PasswordItem();  
        passwordItem.setTitle("Password");  
        passwordItem.setRequired(true);  
  
        PasswordItem password2Item = new PasswordItem();  
        password2Item.setTitle("Password again");  
        password2Item.setRequired(true);  
        password2Item.setType("password");  
  
        form.setFields(usernameItem, emailItem, passwordItem, password2Item);  
          
        IButton swapButton = new IButton("Swap titles");  
        swapButton.setLeft(300);  
        swapButton.addClickHandler(new ClickHandler() {  
            public void onClick(ClickEvent event) {  
                if (form.getTitleOrientation() == TitleOrientation.TOP) {  
                    titleOrientation = TitleOrientation.LEFT;  
                }  
                else {  
                    titleOrientation = TitleOrientation.TOP;  
                }  
                form.setTitleOrientation(titleOrientation);  
                DummyDTO dto = new DummyDTO();
                dto.setName(usernameItem.getValueAsString());
                FocussClientServiceCaller.helloWorld(dto);
            }  
        });  
        form.setShowResizeBar(true);  
        layout.addMember(form);  
        layout.addMember(swapButton);
        RootPanel.get("formContainer").add(layout);*/
    	 
    }  
    
    
    public VLayout getChart1(){
    	Window.alert("aqui0.1");
    	FacetChart chart = new FacetChart();  
        chart.setWidth(508);  
        chart.setHeight(400);  
        chart.setChartType(ChartType.COLUMN);  
        chart.setStacked(true);  
        chart.setValueTitle("Percent");  
        chart.setBorder("1px solid black");  
        chart.setShowTitle(false);  
        chart.setShowChartRect(true);  
  
        Window.alert("aqui0.2");
        Facet areaFacet = new Facet();  
        areaFacet.setValues(new FacetValue("1", "North America"));  
        areaFacet.setId("area");  
        Facet metricFacet = new Facet();  
        metricFacet.setValues(new FacetValue("percent", "Percent"),  
                              new FacetValue("events", "Events"));  
        metricFacet.setInlinedValues(true);  
        metricFacet.setId("metric");  
  
        Window.alert("aqui0.3");
        chart.setFacets(new Facet("date"), areaFacet, metricFacet);  
        chart.setExtraAxisMetrics("events");  
        MetricSettings metricSettings = new MetricSettings();  
        metricSettings.setChartType(ChartType.LINE);  
        metricSettings.setMultiFacet(true);
        Window.alert("aqui0.4");
        metricSettings.setShowDataPoints(true);  
        metricSettings.setValueTitle("Events");  
        chart.setExtraAxisSettings(metricSettings);  
        Window.alert("aqui0.5");
        chart.setData(MultiAxisChartData.getData());  
        Window.alert("aqui0.61");
        VLayout layout = new VLayout(15);
        Window.alert("aqui6.11"+chart.toString());
        layout.addMember(chart);  
        Window.alert("aqui0.7");
        return layout; 
    }
    
    
        
}

 
