package com.curiam.client;

 import java.util.ArrayList;
import java.util.List;

import com.extjs.gxt.ui.client.store.ListStore;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
import com.extjs.gxt.ui.client.widget.grid.ColumnData;
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
import com.extjs.gxt.ui.client.widget.grid.Grid;
import com.extjs.gxt.ui.client.widget.grid.GridCellRenderer;
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
import com.extjs.gxt.ui.client.widget.layout.FlowLayout;
import com.extjs.gxt.ui.client.widget.table.NumberCellRenderer;
import com.google.gwt.i18n.client.NumberFormat;
import com.google.gwt.user.client.Element;
   
 public class GridExample extends LayoutContainer {  
   
	 ResultBeanTPB rbi = new ResultBeanTPB();
	 String clasi = new String("");
	public GridExample(String clasif ,ResultBeanTPB rb){
			
			for(int i=0;i<rb.getProbabilities().size();i++){
				rbi.setProbabilities(rb.getProbabilities().get(i));
				rbi.setLabels(rb.getLabels().get(i));
				rbi.setLegends(rb.getLegends().get(i));
				clasi = clasif;
			}	
	}
	 
   @Override  
   protected void onRender(Element parent, int index) {  
     super.onRender(parent, index);  
     setLayout(new FlowLayout(10));  
   
     final NumberFormat currency = NumberFormat.getCurrencyFormat();  
     final NumberFormat number = NumberFormat.getFormat("0.00");  
     final NumberCellRenderer<Grid<Stock>> numberRenderer = new NumberCellRenderer<Grid<Stock>>(  
         currency);  
   
     GridCellRenderer<Stock> change = new GridCellRenderer<Stock>() {  
       public String render(Stock model, String property, ColumnData config, int rowIndex,  
           int colIndex, ListStore<Stock> store, Grid<Stock> grid) {  
         double val = (Double) model.get(property);   
         return number.format(val);  
       }  
     };  
   
     GridCellRenderer<Stock> gridNumber = new GridCellRenderer<Stock>() {  
       public String render(Stock model, String property, ColumnData config, int rowIndex,  
           int colIndex, ListStore<Stock> store, Grid<Stock> grid) {  
         return numberRenderer.render(null, property, model.get(property));  
       }  
     };  
       List<ColumnConfig> configs = new ArrayList<ColumnConfig>();  
   
     ColumnConfig column = new ColumnConfig();  
     column.setId("name");  
     column.setHeader("Caracteristica");  
     column.setWidth(80);  
     configs.add(column);  
   
     column = new ColumnConfig();  
     column.setId("symbol");  
     column.setHeader("Resultado");  
     column.setWidth(150);  
     configs.add(column);  
   
   
     ListStore<Stock> store = new ListStore<Stock>();  
     store.add(TestData.getStocks(clasi ,rbi));  
   
     ColumnModel cm = new ColumnModel(configs);  
   
     ContentPanel cp = new ContentPanel();  
     cp.setBodyBorder(true);  
    // cp.setIcon(Resources.ICONS.table());  
     cp.setHeading("Resultados de la clasificaci&oacute;n");  
     //cp.setButtonAlign(HorizontalAlignment.CENTER);  
     cp.setLayout(new FitLayout());  
     cp.setSize(300, 250);  

     
     Grid<Stock> grid = new Grid<Stock>(store, cm);  
     grid.setStyleAttribute("borderTop", "none");  
     grid.setAutoExpandColumn("name");  
     grid.setBorders(true);  
     grid.setStripeRows(true);  
     cp.add(grid);  
     //add(cp, new MarginData(150,0, 50, 100));
     add(cp);  
   }  
   
}  