Column grouping with Widget (Ext GWT) : Table Grouping « GWT « Java

Home
Java
1.2D Graphics GUI
2.3D
3.Advanced Graphics
4.Ant
5.Apache Common
6.Chart
7.Class
8.Collections Data Structure
9.Data Type
10.Database SQL JDBC
11.Design Pattern
12.Development Class
13.EJB3
14.Email
15.Event
16.File Input Output
17.Game
18.Generics
19.GWT
20.Hibernate
21.I18N
22.J2EE
23.J2ME
24.JDK 6
25.JNDI LDAP
26.JPA
27.JSP
28.JSTL
29.Language Basics
30.Network Protocol
31.PDF RTF
32.Reflection
33.Regular Expressions
34.Scripting
35.Security
36.Servlets
37.Spring
38.Swing Components
39.Swing JFC
40.SWT JFace Eclipse
41.Threads
42.Tiny Application
43.Velocity
44.Web Services SOA
45.XML
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Java » GWT » Table GroupingScreenshots 
Column grouping with Widget (Ext GWT)
Column grouping with Widget (Ext GWT)
 

/*
 * Ext GWT - Ext for GWT
 * Copyright(c) 2007-2009, Ext JS, LLC.
 * licensing@extjs.com
 
 * http://extjs.com/license
 */
 
 
package com.google.gwt.sample.hello.client;

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

import com.extjs.gxt.ui.client.Style.HorizontalAlignment;
import com.extjs.gxt.ui.client.data.BaseModel;
import com.extjs.gxt.ui.client.event.ButtonEvent;
import com.extjs.gxt.ui.client.event.Events;
import com.extjs.gxt.ui.client.event.Listener;
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.Slider;
import com.extjs.gxt.ui.client.widget.VerticalPanel;
import com.extjs.gxt.ui.client.widget.button.Button;
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.grid.HeaderGroupConfig;
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
import com.extjs.gxt.ui.client.widget.table.NumberCellRenderer;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.i18n.client.DateTimeFormat;
import com.google.gwt.i18n.client.NumberFormat;
import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.RootPanel;

public class Hello implements EntryPoint {
  public void onModuleLoad() {
    RootPanel.get().add(new ColumnGroupingExample());
  }
}
class ColumnGroupingExample extends LayoutContainer {

  private NumberFormat currency = NumberFormat.getCurrencyFormat();
  private NumberFormat number = NumberFormat.getFormat("0.00");
  private NumberCellRenderer<Grid<Stock>> numberRenderer;
  private GridCellRenderer<Stock> change;
  private GridCellRenderer<Stock> gridNumber;
  private VerticalPanel vp;

  @Override
  protected void onRender(Element parent, int index) {
    super.onRender(parent, index);
    numberRenderer = new NumberCellRenderer<Grid<Stock>>(currency);
    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 = (Doublemodel.get(property);
        String style = val < "red" "green";
        return "<span style='color:" + style + "'>" + number.format(val"</span>";
      }
    };

    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));
      }
    };

    vp = new VerticalPanel();
    vp.setSpacing(20);

    createGrid(false);
    createGrid(true);

    add(vp);
  }

  private void createGrid(boolean widget) {
    List<ColumnConfig> configs = new ArrayList<ColumnConfig>();

    ColumnConfig column = new ColumnConfig();
    column.setId("name");
    column.setHeader("Company");
    column.setWidth(200);
    configs.add(column);

    column = new ColumnConfig();
    column.setId("symbol");
    column.setHeader("Symbol");
    column.setWidth(100);
    configs.add(column);

    column = new ColumnConfig();
    column.setId("last");
    column.setHeader("Last");
    column.setAlignment(HorizontalAlignment.RIGHT);
    column.setWidth(75);
    column.setRenderer(gridNumber);
    configs.add(column);

    column = new ColumnConfig("change""Change"100);
    column.setAlignment(HorizontalAlignment.RIGHT);
    column.setRenderer(change);
    configs.add(column);

    column = new ColumnConfig("date"125);
    if (widget) {
      Button btn = new Button("Updated");
      btn.addListener(Events.OnClick, new Listener<ButtonEvent>() {
        public void handleEvent(ButtonEvent be) {
          // stop column from getting click and causing sort
          be.cancelBubble();
        }
      });
      btn.setStyleAttribute("float""left");
      column.setWidget(btn, "Last Updated");
    else {
      column.setAlignment(HorizontalAlignment.RIGHT);
      column.setHeader("Last Updated");
    }

    column.setDateTimeFormat(DateTimeFormat.getShortDateFormat());
    configs.add(column);

    ListStore<Stock> store = new ListStore<Stock>();
    store.add(getStocks());

    ColumnModel cm = new ColumnModel(configs);

    cm.addHeaderGroup(00new HeaderGroupConfig("Header Grouping Example"15));
    cm.addHeaderGroup(12new HeaderGroupConfig("Stock Performance"12));

    if (widget) {
      Slider s = new Slider();
      s.setWidth(100);

      // ugly, but centers slider
      FlexTable tbl = new FlexTable();
      tbl.setWidth("100%");
      tbl.setHTML(00"&nbsp;");
      tbl.setHTML(01"<span style='white-space: nowrap;font-size: 11px'>Slide Me: &nbsp;</span>");
      tbl.setWidget(02, s);
      tbl.setHTML(03"&nbsp;");
      tbl.getCellFormatter().setWidth(00"50%");
      tbl.getCellFormatter().setWidth(03"50%");
      cm.addHeaderGroup(10new HeaderGroupConfig(tbl, 12));
    else {
      cm.addHeaderGroup(10new HeaderGroupConfig("Stock Information"12));
    }

    ContentPanel cp = new ContentPanel();
    cp.setBodyBorder(false);
    //cp.setIcon(Resources.ICONS.table());
    cp.setHeading(widget ? "Column Grouping with Widget" "Column Grouping");
    cp.setButtonAlign(HorizontalAlignment.CENTER);
    cp.setLayout(new FitLayout());
    cp.setSize(600300);

    Grid<Stock> grid = new Grid<Stock>(store, cm);
    grid.setStyleAttribute("borderTop""none");
    grid.getView().setForceFit(true);
    grid.setBorders(true);
    cp.add(grid);

    vp.add(cp);
  }



  public static List<Stock> getStocks() {
    List<Stock> stocks = new ArrayList<Stock>();

    stocks.add(new Stock("Apple Inc.""AAPL"125.64123.43));
    stocks.add(new Stock("Cisco Systems, Inc.""CSCO"25.8426.3));
    stocks.add(new Stock("Google Inc.""GOOG"516.2512.6));
    stocks.add(new Stock("Intel Corporation""INTC"21.3621.53));
    stocks.add(new Stock("Level 3 Communications, Inc.""LVLT"5.555.54));
    stocks.add(new Stock("Microsoft Corporation""MSFT"29.5629.72));
    stocks.add(new Stock("Nokia Corporation (ADR)""NOK"27.8327.93));
    stocks.add(new Stock("Oracle Corporation""ORCL"18.7318.98));
    stocks.add(new Stock("Starbucks Corporation""SBUX"27.3327.36));
    stocks.add(new Stock("Yahoo! Inc.""YHOO"26.9727.29));
    stocks.add(new Stock("Applied Materials, Inc.""AMAT"18.418.66));
    stocks.add(new Stock("Comcast Corporation""CMCSA"25.926.4));
    stocks.add(new Stock("Sirius Satellite""SIRI"2.772.74));

    stocks.add(new Stock("Tellabs, Inc.""TLAB"10.6410.75));
    stocks.add(new Stock("eBay Inc.""EBAY"30.4331.21));
    stocks.add(new Stock("Broadcom Corporation""BRCM"30.8830.48));
    stocks.add(new Stock("CMGI Inc.""CMGI"2.142.13));
    stocks.add(new Stock("Amgen, Inc.""AMGN"56.2257.02));
    stocks.add(new Stock("Limelight Networks""LLNW"2322.11));
    stocks.add(new Stock("Amazon.com, Inc.""AMZN"72.4772.23));

    stocks.add(new Stock("E TRADE Financial Corporation""ETFC"24.3224.58));
    stocks.add(new Stock("AVANIR Pharmaceuticals""AVNR"3.73.52));
    stocks.add(new Stock("Gemstar-TV Guide, Inc.""GMST"4.414.55));
    stocks.add(new Stock("Akamai Technologies, Inc.""AKAM"43.0845.32));
    stocks.add(new Stock("Motorola, Inc.""MOT"17.7417.69));
    stocks.add(new Stock("Advanced Micro Devices, Inc.""AMD"13.7713.98));
    stocks.add(new Stock("General Electric Company""GE"36.836.91));
    stocks.add(new Stock("Texas Instruments Incorporated""TXN"35.0235.7));
    stocks.add(new Stock("Qwest Communications""Q"9.910.03));
    stocks.add(new Stock("Tyco International Ltd.""TYC"33.4833.26));
    stocks.add(new Stock("Pfizer Inc.""PFE"26.2126.19));
    stocks.add(new Stock("Time Warner Inc.""TWX"20.320.45));
    stocks.add(new Stock("Sprint Nextel Corporation""S"21.8521.76));
    stocks.add(new Stock("Bank of America Corporation""BAC"49.9249.73));
    stocks.add(new Stock("Taiwan Semiconductor""TSM"10.410.52));
    stocks.add(new Stock("AT&T Inc.""T"39.739.66));
    stocks.add(new Stock("United States Steel Corporation""X"115.81114.62));
    stocks.add(new Stock("Exxon Mobil Corporation""XOM"81.7781.86));
    stocks.add(new Stock("Valero Energy Corporation""VLO"72.4672.6));
    stocks.add(new Stock("Micron Technology, Inc.""MU"12.0212.27));
    stocks.add(new Stock("Verizon Communications Inc.""VZ"42.542.61));
    stocks.add(new Stock("Avaya Inc.""AV"16.9616.96));
    stocks.add(new Stock("The Home Depot, Inc.""HD"37.6637.79));

    stocks.add(new Stock("First Data Corporation""FDC"32.732.65));
    return stocks;

  }
}
class Stock extends BaseModel {

  public Stock() {
  }

  public Stock(String name, String symbol, double open, double last) {
    set("name", name);
    set("symbol", symbol);
    set("open", open);
    set("last", last);
    set("date"new Date());
    set("change", last - open);
  }

  public Stock(String name, double open, double change, double pctChange, Date date, String industry) {
    set("name", name);
    set("open", open);
    set("change", change);
    set("percentChange", pctChange);
    set("date", date);
    set("industry", industry);
  }

  public String getIndustry() {
    return get("industry");
  }

  public void setIndustry(String industry) {
    set("industry", industry);
  }

  public Date getLastTrans() {
    return (Dateget("date");
  }

  public String getName() {
    return (Stringget("name");
  }

  public String getSymbol() {
    return (Stringget("symbol");
  }

  public double getOpen() {
    Double open = (Doubleget("open");
    return open.doubleValue();
  }

  public double getLast() {
    Double open = (Doubleget("last");
    return open.doubleValue();
  }

  public double getChange() {
    return getLast() - getOpen();
  }

  public double getPercentChange() {
    return getChange() / getOpen();
  }

  public String toString() {
    return getName();
  }

}

   
  
Ext-GWT.zip( 4,297 k)
Related examples in the same category
1.Grid with Custom Grouping Sample (Smart GWT)Grid with Custom Grouping Sample (Smart GWT)
2.Grid with Dynamic Grouping Sample (Smart GWT)Grid with Dynamic Grouping Sample (Smart GWT)
3.Grid Grouped Editing Sample (Smart GWT)Grid Grouped Editing Sample (Smart GWT)
4.Three-level column grouping (Ext GWT)Three-level column grouping (Ext GWT)
5.Using GroupingStore to load grouped grid data (Ext GWT)Using GroupingStore to load grouped grid data (Ext GWT)
6.Using GroupingView to display grouped grid data (Ext GWT)Using GroupingView to display grouped grid data (Ext GWT)
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.