Sponsored Project Grid In Ext GWT


Sponsored Project Grid In Ext GWT Sample Code


  1. package com.extjs.gxt.samples.client.examples.grid;  
  2.   
  3. import java.util.ArrayList;  
  4. import java.util.List;  
  5. import java.util.Map;  
  6.   
  7. import com.extjs.gxt.samples.resources.client.Resources;  
  8. import com.extjs.gxt.samples.resources.client.TestData;  
  9. import com.extjs.gxt.samples.resources.client.model.Task;  
  10. import com.extjs.gxt.ui.client.Style.HorizontalAlignment;  
  11. import com.extjs.gxt.ui.client.data.ModelData;  
  12. import com.extjs.gxt.ui.client.store.GroupingStore;  
  13. import com.extjs.gxt.ui.client.store.ListStore;  
  14. import com.extjs.gxt.ui.client.widget.ContentPanel;  
  15. import com.extjs.gxt.ui.client.widget.LayoutContainer;  
  16. import com.extjs.gxt.ui.client.widget.form.NumberField;  
  17. import com.extjs.gxt.ui.client.widget.grid.CellEditor;  
  18. import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;  
  19. import com.extjs.gxt.ui.client.widget.grid.ColumnData;  
  20. import com.extjs.gxt.ui.client.widget.grid.ColumnModel;  
  21. import com.extjs.gxt.ui.client.widget.grid.EditorGrid;  
  22. import com.extjs.gxt.ui.client.widget.grid.Grid;  
  23. import com.extjs.gxt.ui.client.widget.grid.GridCellRenderer;  
  24. import com.extjs.gxt.ui.client.widget.grid.GroupSummaryView;  
  25. import com.extjs.gxt.ui.client.widget.grid.SummaryColumnConfig;  
  26. import com.extjs.gxt.ui.client.widget.grid.SummaryRenderer;  
  27. import com.extjs.gxt.ui.client.widget.grid.SummaryType;  
  28. import com.extjs.gxt.ui.client.widget.layout.FitLayout;  
  29. import com.extjs.gxt.ui.client.widget.layout.FlowLayout;  
  30. import com.google.gwt.i18n.client.NumberFormat;  
  31. import com.google.gwt.user.client.Element;  
  32.   
  33. public class TotalsGridExample extends LayoutContainer {  
  34.   
  35.   @Override  
  36.   protected void onRender(Element parent, int index) {  
  37.     super.onRender(parent, index);  
  38.     setLayout(new FlowLayout(10));  
  39.   
  40.     List<Task> tasks = TestData.getTasks();  
  41.     GroupingStore<Task> store = new GroupingStore<Task>();  
  42.     store.groupBy("project");  
  43.     store.add(tasks);  
  44.   
  45.     List<ColumnConfig> columns = new ArrayList<ColumnConfig>();  
  46.   
  47.     SummaryColumnConfig<Integer> desc = new SummaryColumnConfig<Integer>("description""Task"65);  
  48.     desc.setSummaryType(SummaryType.COUNT);  
  49.     desc.setSummaryRenderer(new SummaryRenderer() {  
  50.       public String render(Number value, Map<String, Number> data) {  
  51.         return value.intValue() > 1 ? "(" + value.intValue() + " Tasks)" : "(1 Task)";  
  52.       }  
  53.     });  
  54.   
  55.     SummaryColumnConfig<Double> project = new SummaryColumnConfig<Double>("project""Project"55);  
  56.     SummaryColumnConfig<Double> due = new SummaryColumnConfig<Double>("due""Due Date"20);  
  57.   
  58.     SummaryColumnConfig<Double> estimate = new SummaryColumnConfig<Double>("estimate""Estimate"20);  
  59.     estimate.setRenderer(new GridCellRenderer<Task>() {  
  60.       public String render(Task model, String property, ColumnData config, int rowIndex, int colIndex,  
  61.           ListStore<Task> store, Grid<Task> grid) {  
  62.         return model.get(property) + " hours";  
  63.       }  
  64.     });  
  65.     estimate.setSummaryType(SummaryType.SUM);  
  66.     estimate.setSummaryRenderer(new SummaryRenderer() {  
  67.       public String render(Number value, Map<String, Number> data) {  
  68.         return value.intValue() + " hours";  
  69.       }  
  70.     });  
  71.     estimate.setEditor(new CellEditor(new NumberField()));  
  72.   
  73.     SummaryColumnConfig<Double> rate = new SummaryColumnConfig<Double>("rate""Rate"20);  
  74.     rate.setNumberFormat(NumberFormat.getCurrencyFormat());  
  75.     rate.setSummaryFormat(NumberFormat.getCurrencyFormat());  
  76.     rate.setSummaryType(SummaryType.AVG);  
  77.     rate.setAlignment(HorizontalAlignment.RIGHT);  
  78.   
  79.     NumberField nf = new NumberField();  
  80.     nf.setAutoValidate(true);  
  81.     CellEditor ce = new CellEditor(nf);  
  82.     ce.setCancelOnEsc(true);  
  83.     rate.setEditor(ce);  
  84.   
  85.     SummaryColumnConfig<Double> cost = new SummaryColumnConfig<Double>("cost""Cost"20);  
  86.     cost.setSummaryFormat(NumberFormat.getCurrencyFormat());  
  87.     cost.setSummaryType(new SummaryType<Double>() {  
  88.       @Override  
  89.       public Double render(Object v, ModelData m, String field, Map<String, Object> data) {  
  90.         if (v == null) {  
  91.           v = 0d;  
  92.         }  
  93.         Task task = (Task) m;  
  94.         return ((Double) v).doubleValue() + (task.getEstimate() * task.getRate());  
  95.       }  
  96.   
  97.     });  
  98.     cost.setAlignment(HorizontalAlignment.RIGHT);  
  99.     cost.setRenderer(new GridCellRenderer<Task>() {  
  100.       public String render(Task model, String property, ColumnData config, int rowIndex, int colIndex,  
  101.           ListStore<Task> store, Grid<Task> grid) {  
  102.         Task task = (Task) model;  
  103.         return NumberFormat.getCurrencyFormat().format(task.getRate() * task.getEstimate());  
  104.       }  
  105.     });  
  106.   
  107.     columns.add(desc);  
  108.     columns.add(project);  
  109.     columns.add(due);  
  110.     columns.add(estimate);  
  111.     columns.add(rate);  
  112.     columns.add(cost);  
  113.     ColumnModel cm = new ColumnModel(columns);  
  114.   
  115.     GroupSummaryView summary = new GroupSummaryView();  
  116.     summary.setForceFit(true);  
  117.     summary.setShowGroupedColumn(false);  
  118.   
  119.     EditorGrid<Task> grid = new EditorGrid<Task>(store, cm);  
  120.     grid.setBorders(true);  
  121.     grid.setView(summary);  
  122.     grid.getView().setShowDirtyCells(false);  
  123.   
  124.     ContentPanel panel = new ContentPanel();  
  125.     panel.setHeading("Sponsored Projects");  
  126.     panel.setIcon(Resources.ICONS.table());  
  127.     panel.setCollapsible(true);  
  128.     panel.setFrame(true);  
  129.     panel.setSize(800450);  
  130.     panel.setLayout(new FitLayout());  
  131.     panel.add(grid);  
  132.     add(panel);  
  133.   }  
  134.   
  135. }  

Comments

Popular posts from this blog

Five More Indian Languages - Google Translate

Connect To JioFi Device Without Knowing The Passwords Using WPS