package com.smartgwt.sample.client;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Date;  

import com.smartgwt.client.widgets.form.fields.FormItem;
import com.smartgwt.client.widgets.form.fields.RichTextItem;
import com.smartgwt.client.widgets.grid.ListGridRecord;  

import java.util.Date;  

import com.smartgwt.client.data.Criteria;
import com.smartgwt.client.data.Record;
import com.smartgwt.client.data.RecordList;
import com.smartgwt.client.types.Alignment;  
import com.smartgwt.client.types.AutoFitWidthApproach;
import com.smartgwt.client.types.Autofit;
import com.smartgwt.client.types.ListGridFieldType;  
import com.smartgwt.client.types.Overflow;
import com.smartgwt.client.util.JSOHelper;
import com.smartgwt.client.util.JSON;
import com.smartgwt.client.util.SC;
import com.smartgwt.client.widgets.Canvas;  
import com.smartgwt.client.widgets.IButton;  
import com.smartgwt.client.widgets.cube.CubeGrid;
import com.smartgwt.client.widgets.events.ClickEvent;  
import com.smartgwt.client.widgets.events.ClickHandler;  
import com.smartgwt.client.widgets.events.DrawEvent;
import com.smartgwt.client.widgets.events.DrawHandler;
import com.smartgwt.client.widgets.grid.ListGrid;  
import com.smartgwt.client.widgets.grid.ListGridEditorContext;
import com.smartgwt.client.widgets.grid.ListGridEditorCustomizer;
import com.smartgwt.client.widgets.grid.ListGridField;  
  
import com.google.gwt.core.client.EntryPoint;  
  

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

        String json = getJson();
        RecordList reclist = new RecordList();
        String[] decoded = JSOHelper.convertToJavaStringArray(JSON.decode(json));
        for (String mapToDecode : decoded) {
        	Map<String, Object> map = JSOHelper.convertToMap((JSON.decode(mapToDecode)));
        	Record rec = new Record(map);
        	reclist.add(rec);
        }
        
      Canvas canvas = new Canvas(); 
      canvas.setHeight100();
      canvas.setWidth100();
      canvas.setOverflow(Overflow.AUTO);
      
      final CubeGrid cubeGrid = new CubeGrid();

		cubeGrid.setRowFacets("PNR_StageName","metric");
		cubeGrid.setColumnFacets("ProjName_Revision","Block_Name", "Layout_Rundir_Name","Synth_Install_Name");
		cubeGrid.setValueProperty("Value");
		cubeGrid.setEmptyCellValue("EMPTY");
		cubeGrid.setWidth100();
		cubeGrid.setHeight100();
		cubeGrid.setData(reclist);
		cubeGrid.setHideEmptyFacetValues(true);
		cubeGrid.setAutoFitWidthApproach(AutoFitWidthApproach.BOTH);
//		cubeGrid.setAutoFitData(Autofit.BOTH);
		cubeGrid.addDrawHandler(new DrawHandler(){

			@Override
			public void onDraw(DrawEvent event) {
				cubeGrid.autoFitFields();
			}});
		
      canvas.addChild(cubeGrid);  

      canvas.draw();  
        
		
	}
	private String getJson() {
		return "[\"{\\\"Value\\\":0.011856000,\\\"Layout_Rundir_Name\\\":\\\"2016_02_03.14_54\\\",\\\"PNR_StageName\\\":\\\"plan\\\",\\\"metric\\\":\\\"DieArea\\\",\\\"Block_Name\\\":\\\"jtag_wrap\\\",\\\"Synth_Install_Name\\\":\\\"2016_02_01.10_13_trial0_syn\\\",\\\"ProjName_Revision\\\":\\\"BCM3465 A0\\\"}\",\"{\\\"Value\\\":0E-9,\\\"Layout_Rundir_Name\\\":\\\"2016_02_03.14_54\\\",\\\"PNR_StageName\\\":\\\"plan\\\",\\\"metric\\\":\\\"MacroCellArea\\\",\\\"Block_Name\\\":\\\"jtag_wrap\\\",\\\"Synth_Install_Name\\\":\\\"2016_02_01.10_13_trial0_syn\\\",\\\"ProjName_Revision\\\":\\\"BCM3465 A0\\\"}\",\"{\\\"Value\\\":0,\\\"Layout_Rundir_Name\\\":\\\"2016_02_03.14_54\\\",\\\"PNR_StageName\\\":\\\"plan\\\",\\\"metric\\\":\\\"MacroCellCount\\\",\\\"Block_Name\\\":\\\"jtag_wrap\\\",\\\"Synth_Install_Name\\\":\\\"2016_02_01.10_13_trial0_syn\\\",\\\"ProjName_Revision\\\":\\\"BCM3465 A0\\\"}\",\"{\\\"Value\\\":\\\"Feb 4, 2016 8:04:52 PM\\\",\\\"Layout_Rundir_Name\\\":\\\"2016_02_03.14_54\\\",\\\"PNR_StageName\\\":\\\"plan\\\",\\\"metric\\\":\\\"Real_CPU_DateTime\\\",\\\"Block_Name\\\":\\\"jtag_wrap\\\",\\\"Synth_Install_Name\\\":\\\"2016_02_01.10_13_trial0_syn\\\",\\\"ProjName_Revision\\\":\\\"BCM3465 A0\\\"}\",\"{\\\"Value\\\":0.011856000,\\\"Layout_Rundir_Name\\\":\\\"2016_02_03.14_54\\\",\\\"PNR_StageName\\\":\\\"place_opt\\\",\\\"metric\\\":\\\"DieArea\\\",\\\"Block_Name\\\":\\\"jtag_wrap\\\",\\\"Synth_Install_Name\\\":\\\"2016_02_01.10_13_trial0_syn\\\",\\\"ProjName_Revision\\\":\\\"BCM3465 A0\\\"}\",\"{\\\"Value\\\":0E-9,\\\"Layout_Rundir_Name\\\":\\\"2016_02_03.14_54\\\",\\\"PNR_StageName\\\":\\\"place_opt\\\",\\\"metric\\\":\\\"MacroCellArea\\\",\\\"Block_Name\\\":\\\"jtag_wrap\\\",\\\"Synth_Install_Name\\\":\\\"2016_02_01.10_13_trial0_syn\\\",\\\"ProjName_Revision\\\":\\\"BCM3465 A0\\\"}\",\"{\\\"Value\\\":0,\\\"Layout_Rundir_Name\\\":\\\"2016_02_03.14_54\\\",\\\"PNR_StageName\\\":\\\"place_opt\\\",\\\"metric\\\":\\\"MacroCellCount\\\",\\\"Block_Name\\\":\\\"jtag_wrap\\\",\\\"Synth_Install_Name\\\":\\\"2016_02_01.10_13_trial0_syn\\\",\\\"ProjName_Revision\\\":\\\"BCM3465 A0\\\"}\",\"{\\\"Value\\\":\\\"Feb 4, 2016 9:01:26 PM\\\",\\\"Layout_Rundir_Name\\\":\\\"2016_02_03.14_54\\\",\\\"PNR_StageName\\\":\\\"place_opt\\\",\\\"metric\\\":\\\"Real_CPU_DateTime\\\",\\\"Block_Name\\\":\\\"jtag_wrap\\\",\\\"Synth_Install_Name\\\":\\\"2016_02_01.10_13_trial0_syn\\\",\\\"ProjName_Revision\\\":\\\"BCM3465 A0\\\"}\",\"{\\\"Value\\\":0.013440000,\\\"Layout_Rundir_Name\\\":\\\"2016_03_02.16_36\\\",\\\"PNR_StageName\\\":\\\"plan\\\",\\\"metric\\\":\\\"DieArea\\\",\\\"Block_Name\\\":\\\"jtag_wrap\\\",\\\"Synth_Install_Name\\\":\\\"2016_03_02.16_08_trial1_syn\\\",\\\"ProjName_Revision\\\":\\\"BCM3465 A0\\\"}\",\"{\\\"Value\\\":0E-9,\\\"Layout_Rundir_Name\\\":\\\"2016_03_02.16_36\\\",\\\"PNR_StageName\\\":\\\"plan\\\",\\\"metric\\\":\\\"MacroCellArea\\\",\\\"Block_Name\\\":\\\"jtag_wrap\\\",\\\"Synth_Install_Name\\\":\\\"2016_03_02.16_08_trial1_syn\\\",\\\"ProjName_Revision\\\":\\\"BCM3465 A0\\\"}\",\"{\\\"Value\\\":0,\\\"Layout_Rundir_Name\\\":\\\"2016_03_02.16_36\\\",\\\"PNR_StageName\\\":\\\"plan\\\",\\\"metric\\\":\\\"MacroCellCount\\\",\\\"Block_Name\\\":\\\"jtag_wrap\\\",\\\"Synth_Install_Name\\\":\\\"2016_03_02.16_08_trial1_syn\\\",\\\"ProjName_Revision\\\":\\\"BCM3465 A0\\\"}\",\"{\\\"Value\\\":\\\"Mar 4, 2016 8:23:16 PM\\\",\\\"Layout_Rundir_Name\\\":\\\"2016_03_02.16_36\\\",\\\"PNR_StageName\\\":\\\"plan\\\",\\\"metric\\\":\\\"Real_CPU_DateTime\\\",\\\"Block_Name\\\":\\\"jtag_wrap\\\",\\\"Synth_Install_Name\\\":\\\"2016_03_02.16_08_trial1_syn\\\",\\\"ProjName_Revision\\\":\\\"BCM3465 A0\\\"}\",\"{\\\"Value\\\":0.013440000,\\\"Layout_Rundir_Name\\\":\\\"2016_03_02.16_36\\\",\\\"PNR_StageName\\\":\\\"place_opt\\\",\\\"metric\\\":\\\"DieArea\\\",\\\"Block_Name\\\":\\\"jtag_wrap\\\",\\\"Synth_Install_Name\\\":\\\"2016_03_02.16_08_trial1_syn\\\",\\\"ProjName_Revision\\\":\\\"BCM3465 A0\\\"}\",\"{\\\"Value\\\":0E-9,\\\"Layout_Rundir_Name\\\":\\\"2016_03_02.16_36\\\",\\\"PNR_StageName\\\":\\\"place_opt\\\",\\\"metric\\\":\\\"MacroCellArea\\\",\\\"Block_Name\\\":\\\"jtag_wrap\\\",\\\"Synth_Install_Name\\\":\\\"2016_03_02.16_08_trial1_syn\\\",\\\"ProjName_Revision\\\":\\\"BCM3465 A0\\\"}\",\"{\\\"Value\\\":0,\\\"Layout_Rundir_Name\\\":\\\"2016_03_02.16_36\\\",\\\"PNR_StageName\\\":\\\"place_opt\\\",\\\"metric\\\":\\\"MacroCellCount\\\",\\\"Block_Name\\\":\\\"jtag_wrap\\\",\\\"Synth_Install_Name\\\":\\\"2016_03_02.16_08_trial1_syn\\\",\\\"ProjName_Revision\\\":\\\"BCM3465 A0\\\"}\",\"{\\\"Value\\\":\\\"Mar 4, 2016 9:20:50 PM\\\",\\\"Layout_Rundir_Name\\\":\\\"2016_03_02.16_36\\\",\\\"PNR_StageName\\\":\\\"place_opt\\\",\\\"metric\\\":\\\"Real_CPU_DateTime\\\",\\\"Block_Name\\\":\\\"jtag_wrap\\\",\\\"Synth_Install_Name\\\":\\\"2016_03_02.16_08_trial1_syn\\\",\\\"ProjName_Revision\\\":\\\"BCM3465 A0\\\"}\",\"{\\\"Value\\\":0.012144000,\\\"Layout_Rundir_Name\\\":\\\"2016_04_08.09_03\\\",\\\"PNR_StageName\\\":\\\"plan\\\",\\\"metric\\\":\\\"DieArea\\\",\\\"Block_Name\\\":\\\"jtag_wrap\\\",\\\"Synth_Install_Name\\\":\\\"2016_04_06.20_03_final_syn\\\",\\\"ProjName_Revision\\\":\\\"BCM3465 A0\\\"}\",\"{\\\"Value\\\":0E-9,\\\"Layout_Rundir_Name\\\":\\\"2016_04_08.09_03\\\",\\\"PNR_StageName\\\":\\\"plan\\\",\\\"metric\\\":\\\"MacroCellArea\\\",\\\"Block_Name\\\":\\\"jtag_wrap\\\",\\\"Synth_Install_Name\\\":\\\"2016_04_06.20_03_final_syn\\\",\\\"ProjName_Revision\\\":\\\"BCM3465 A0\\\"}\",\"{\\\"Value\\\":0,\\\"Layout_Rundir_Name\\\":\\\"2016_04_08.09_03\\\",\\\"PNR_StageName\\\":\\\"plan\\\",\\\"metric\\\":\\\"MacroCellCount\\\",\\\"Block_Name\\\":\\\"jtag_wrap\\\",\\\"Synth_Install_Name\\\":\\\"2016_04_06.20_03_final_syn\\\",\\\"ProjName_Revision\\\":\\\"BCM3465 A0\\\"}\",\"{\\\"Value\\\":\\\"Apr 8, 2016 6:17:08 PM\\\",\\\"Layout_Rundir_Name\\\":\\\"2016_04_08.09_03\\\",\\\"PNR_StageName\\\":\\\"plan\\\",\\\"metric\\\":\\\"Real_CPU_DateTime\\\",\\\"Block_Name\\\":\\\"jtag_wrap\\\",\\\"Synth_Install_Name\\\":\\\"2016_04_06.20_03_final_syn\\\",\\\"ProjName_Revision\\\":\\\"BCM3465 A0\\\"}\",\"{\\\"Value\\\":0.012144000,\\\"Layout_Rundir_Name\\\":\\\"2016_04_08.09_03\\\",\\\"PNR_StageName\\\":\\\"place_opt\\\",\\\"metric\\\":\\\"DieArea\\\",\\\"Block_Name\\\":\\\"jtag_wrap\\\",\\\"Synth_Install_Name\\\":\\\"2016_04_06.20_03_final_syn\\\",\\\"ProjName_Revision\\\":\\\"BCM3465 A0\\\"}\",\"{\\\"Value\\\":0E-9,\\\"Layout_Rundir_Name\\\":\\\"2016_04_08.09_03\\\",\\\"PNR_StageName\\\":\\\"place_opt\\\",\\\"metric\\\":\\\"MacroCellArea\\\",\\\"Block_Name\\\":\\\"jtag_wrap\\\",\\\"Synth_Install_Name\\\":\\\"2016_04_06.20_03_final_syn\\\",\\\"ProjName_Revision\\\":\\\"BCM3465 A0\\\"}\",\"{\\\"Value\\\":0,\\\"Layout_Rundir_Name\\\":\\\"2016_04_08.09_03\\\",\\\"PNR_StageName\\\":\\\"place_opt\\\",\\\"metric\\\":\\\"MacroCellCount\\\",\\\"Block_Name\\\":\\\"jtag_wrap\\\",\\\"Synth_Install_Name\\\":\\\"2016_04_06.20_03_final_syn\\\",\\\"ProjName_Revision\\\":\\\"BCM3465 A0\\\"}\",\"{\\\"Value\\\":\\\"Apr 8, 2016 7:22:43 PM\\\",\\\"Layout_Rundir_Name\\\":\\\"2016_04_08.09_03\\\",\\\"PNR_StageName\\\":\\\"place_opt\\\",\\\"metric\\\":\\\"Real_CPU_DateTime\\\",\\\"Block_Name\\\":\\\"jtag_wrap\\\",\\\"Synth_Install_Name\\\":\\\"2016_04_06.20_03_final_syn\\\",\\\"ProjName_Revision\\\":\\\"BCM3465 A0\\\"}\"]";
	}
	
}
