package es.ideiak.cliente;

import org.gwtmultipage.client.MultipageEntryPoint;

import com.google.gwt.core.client.EntryPoint;
import com.smartgwt.client.data.DSCallback;
import com.smartgwt.client.data.DSResponse;
import com.smartgwt.client.data.DataSource;
import com.smartgwt.client.util.SC;
import com.smartgwt.client.widgets.cube.CubeGrid;
import com.smartgwt.client.widgets.grid.ListGrid;
import com.smartgwt.client.widgets.grid.ListGridField;
import com.smartgwt.client.widgets.layout.VLayout;
import com.smartgwt.client.data.DSRequest;

/*
 * Isomorphic SmartGWT web presentation layer
 * Copyright 2000 and beyond Isomorphic Software, Inc.
 *
 * OWNERSHIP NOTICE
 * Isomorphic Software owns and reserves all rights not expressly granted in this source code,
 * including all intellectual property rights to the structure, sequence, and format of this code
 * and to all designs, interfaces, algorithms, schema, protocols, and inventions expressed herein.
 *
 *  If you have any questions, please email <sourcecode@isomorphic.com>.
 *
 *  This entire comment must accompany any portion of Isomorphic Software source code that is
 *  copied or moved from this file.
 */





@MultipageEntryPoint(urlPattern = "(index.html)(\\\\?.*)?")


public class TestCase implements EntryPoint {
	
	private CubeGrid advancedCube;
	
    public void onModuleLoad() {
        
         
    		final VLayout VLO = new VLayout();

				final CubeGrid advancedCube = new CubeGrid();
            	
           	 if(SC.hasDrawing()) {  
	    	    	   advancedCube.setEnableCharting(true);  
	                } 
   	       
   	       		advancedCube.setWidth(600);

   	             advancedCube.setHeight(200);

   	            // advancedCube.setFacets(serie,oferta,mes);
   	             
   	             advancedCube.setHideEmptyFacetValues(true);
					
   	             advancedCube.setShowCellContextMenus(true);
   	             
   	             advancedCube.setRowFacets("serie","oferta");
   	             advancedCube.setColumnFacets("mes");
   	             advancedCube.setValueProperty("_value"); 
           	
       	    

       	    

 	            DataSource.get("testcase").fetchData(null, new DSCallback() {

 	                     @Override

 	                     public void execute(DSResponse response, Object rawData, DSRequest request) {

 	                    	 advancedCube.setData(response.getData());
           	
 	                    	 ListGrid grid = new ListGrid();
 	                    	 grid.setHeight(200);
 	                    	 grid.setWidth(600);
 	                    	 ListGridField serie = new ListGridField("serie");
 	                    	ListGridField _value = new ListGridField("_value");
 	                    	
 	                    	grid.setFields(serie,_value);
	                    	 
 	                    	 
 	                    	 for (int i=0; i<response.getData().length; i++)
 	                    	 {
 	                    		 System.out.println("Grid:"+response.getData()[i].getAttribute("serie")+" - "+response.getData()[i].getAttribute("_value"));
 	                    		 
 	                    	 }
 	                    	 
 	                    	 grid.setData(response.getData());
 	                    	 
 	                    	 VLO.addMember(advancedCube);
 	                    	 VLO.addMember(grid);
 	                    	 
 	                    	 VLO.draw();

 	                     }
 	            });
				
				
    }

			
	
}
