Using Text box as table cell renderer (Ext GWT) : Table Cell Renderer « 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.JavaFX
25.JDK 6
26.JDK 7
27.JNDI LDAP
28.JPA
29.JSP
30.JSTL
31.Language Basics
32.Network Protocol
33.PDF RTF
34.Reflection
35.Regular Expressions
36.Scripting
37.Security
38.Servlets
39.Spring
40.Swing Components
41.Swing JFC
42.SWT JFace Eclipse
43.Threads
44.Tiny Application
45.Velocity
46.Web Services SOA
47.XML
Java » GWT » Table Cell Renderer 




Using Text box as table cell renderer (Ext GWT)
Using Text box as table cell renderer (Ext GWT)
 

/*
 * Ext GWT - Ext for GWT
 * Copyright(c) 2007-2009, Ext JS, LLC.
 [email protected]
 
 * 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.data.BaseModelData;
import com.extjs.gxt.ui.client.data.ModelData;
import com.extjs.gxt.ui.client.event.ButtonEvent;
import com.extjs.gxt.ui.client.event.SelectionListener;
import com.extjs.gxt.ui.client.store.ListStore;
import com.extjs.gxt.ui.client.util.DateWrapper;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.button.Button;
import com.extjs.gxt.ui.client.widget.form.CheckBox;
import com.extjs.gxt.ui.client.widget.form.DateField;
import com.extjs.gxt.ui.client.widget.form.NumberField;
import com.extjs.gxt.ui.client.widget.form.SimpleComboBox;
import com.extjs.gxt.ui.client.widget.form.TextField;
import com.extjs.gxt.ui.client.widget.form.ComboBox.TriggerAction;
import com.extjs.gxt.ui.client.widget.grid.CellEditor;
import com.extjs.gxt.ui.client.widget.grid.CheckColumnConfig;
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
import com.extjs.gxt.ui.client.widget.grid.EditorGrid;
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.toolbar.ToolBar;
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.impl.WindowImplIE.Resources;
import com.google.gwt.user.client.ui.RootPanel;

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

  @Override
  protected void onRender(Element parent, int index) {
    super.onRender(parent, index);

    setLayout(new FlowLayout(10));

    List<Stock> stocks = getStocks();
    for (Stock s : stocks) {
      DateWrapper w = new DateWrapper();
      w = w.clearTime();
      w = w.addDays((int) (Math.random() 1000));
      s.set("date", w.asDate());
    }

    List<ColumnConfig> configs = new ArrayList<ColumnConfig>();

    ColumnConfig column = new ColumnConfig();
    column.setId("name");
    column.setHeader("Common Name");
    column.setWidth(220);

    TextField<String> text = new TextField<String>();
    text.setAllowBlank(false);
    column.setEditor(new CellEditor(text));
    configs.add(column);

    final SimpleComboBox<String> combo = new SimpleComboBox<String>();
    combo.setForceSelection(true);
    combo.setTriggerAction(TriggerAction.ALL);
    combo.add("Shade");
    combo.add("Mostly Shady");
    combo.add("Sun or Shade");
    combo.add("Mostly Sunny");
    combo.add("Sunny");

    CellEditor editor = new CellEditor(combo) {
      @Override
      public Object preProcessValue(Object value) {
        if (value == null) {
          return value;
        }
        return combo.findModel(value.toString());
      }

      @Override
      public Object postProcessValue(Object value) {
        if (value == null) {
          return value;
        }
        return ((ModelDatavalue).get("value");
      }
    };

    column = new ColumnConfig();
    column.setId("light");
    column.setHeader("Light");
    column.setWidth(130);
    column.setEditor(editor);
    configs.add(column);

    column = new ColumnConfig();
    column.setId("price");
    column.setHeader("Price");
    column.setAlignment(HorizontalAlignment.RIGHT);
    column.setWidth(70);
    column.setNumberFormat(NumberFormat.getCurrencyFormat());
    column.setEditor(new CellEditor(new NumberField()));

    configs.add(column);

    DateField dateField = new DateField();
    dateField.getPropertyEditor().setFormat(DateTimeFormat.getFormat("MM/dd/y"));

    column = new ColumnConfig();
    column.setId("available");
    column.setHeader("Available");
    column.setWidth(95);
    column.setEditor(new CellEditor(dateField));
    column.setDateTimeFormat(DateTimeFormat.getMediumDateFormat());
    configs.add(column);

    CheckColumnConfig checkColumn = new CheckColumnConfig("indoor""Indoor?"55);
    CellEditor checkBoxEditor = new CellEditor(new CheckBox());
    checkColumn.setEditor(checkBoxEditor);
    configs.add(checkColumn);

    final ListStore<Plant> store = new ListStore<Plant>();
    store.add(getPlants());

    ColumnModel cm = new ColumnModel(configs);

    ContentPanel cp = new ContentPanel();
    cp.setHeading("Edit Plants");
    cp.setFrame(true);
    //cp.setIcon(Resources.ICONS.table());
    cp.setSize(600300);
    cp.setLayout(new FitLayout());

    final EditorGrid<Plant> grid = new EditorGrid<Plant>(store, cm);
    grid.setAutoExpandColumn("name");
    grid.setBorders(true);
    grid.addPlugin(checkColumn);
    cp.add(grid);

    ToolBar toolBar = new ToolBar();
    Button add = new Button("Add Plant");
    add.addSelectionListener(new SelectionListener<ButtonEvent>() {

      @Override
      public void componentSelected(ButtonEvent ce) {
        Plant plant = new Plant();
        plant.setName("New Plant 1");
        plant.setLight("Mostly Shady");
        plant.setPrice(0);
        plant.setAvailable(new DateWrapper().clearTime().asDate());
        plant.setIndoor(false);

        grid.stopEditing();
        store.insert(plant, 0);
        grid.startEditing(00);

      }

    });
    toolBar.add(add);
    cp.setTopComponent(toolBar);
    cp.setButtonAlign(HorizontalAlignment.CENTER);
    cp.addButton(new Button("Reset"new SelectionListener<ButtonEvent>() {

      @Override
      public void componentSelected(ButtonEvent ce) {
        store.rejectChanges();
      }
    }));

    cp.addButton(new Button("Save"new SelectionListener<ButtonEvent>() {

      @Override
      public void componentSelected(ButtonEvent ce) {
        store.commitChanges();
      }
    }));

    add(cp);
  }
  public static List<Plant> getPlants() {
    List<Plant> plants = new ArrayList<Plant>();
    plants.add(new Plant("Bloodroot""Mostly Shady"2.44"03/15/2006"true));
    plants.add(new Plant("Columbine""Shade"9.37"03/15/2006"true));
    plants.add(new Plant("Marsh Marigold""Mostly Sunny"6.81"05/17/2006"false));
    plants.add(new Plant("Cowslip""Mostly Shady"9.90"03/06/2006"true));
    plants.add(new Plant("Dutchman's-Breeches""Mostly Shady"6.44"01/20/2006"true));
    plants.add(new Plant("Ginger, Wild""Mostly Shady"9.03"04/18/2006"true));
    plants.add(new Plant("Hepatica""Sunny"4.45"01/26/2006"true));
    plants.add(new Plant("Liverleaf""Mostly Sunny"3.99"01/02/2006"true));
    plants.add(new Plant("Jack-In-The-Pulpit""Mostly Shady"3.23"02/01/2006"true));
    plants.add(new Plant("Mayapple""Mostly Shady"2.98"06/05/2006"true));
    plants.add(new Plant("Phlox, Woodland""Sun or Shade"2.80"01/22/2006"false));
    plants.add(new Plant("Phlox, Blue""Sun or Shade"5.59"02/16/2006"false));
    plants.add(new Plant("Spring-Beauty""Mostly Shady"6.59"02/01/2006"true));
    plants.add(new Plant("Trillium""Sun or Shade"3.90"04/29/2006"false));
    plants.add(new Plant("Wake Robin""Sun or Shade"3.20"02/21/2006"false));
    plants.add(new Plant("Violet, Dog-Tooth""Shade"9.04"02/01/2006"true));
    plants.add(new Plant("Trout Lily""Shade"6.94"03/24/2006"true));
    plants.add(new Plant("Adder's-Tongue""Mostly Shady"6.59"02/01/2006"true));
    plants.add(new Plant("Trillium""Shade"9.58"04/13/2006"true));
    plants.add(new Plant("Anemone""Mostly Shady"8.86"12/26/2006"true));
    plants.add(new Plant("Grecian Windflower""Mostly Shady"9.16"07/10/2006"true));
    plants.add(new Plant("Bee Balm""Shade"4.59"05/03/2006"true));
    plants.add(new Plant("Bergamot""Shade"7.16"04/27/2006"true));
    plants.add(new Plant("Black-Eyed Susan""Sunny"9.80"06/18/2006"false));
    plants.add(new Plant("Buttercup""Shade"2.57"06/10/2006"true));
    plants.add(new Plant("Crowfoot""Shade"9.34"04/03/2006"true));
    plants.add(new Plant("Butterfly Weed""Sunny"2.78"06/30/2006"false));
    plants.add(new Plant("Cinquefoil""Shade"7.06"05/25/2006"true));
    plants.add(new Plant("Primrose""Sunny"6.56"01/30/2006"false));
    plants.add(new Plant("Gentian""Sun or Shade"7.81"05/18/2006"false));
    plants.add(new Plant("Greek Valerian""Shade"3.41"04/03/2006"true));
    plants.add(new Plant("California Poppy""Mostly Shady"2.78"05/13/2006"false));
    plants.add(new Plant("Shooting Star""Shade"7.06"07/11/2006"true));
    plants.add(new Plant("Snakeroot""Sunny"6.56"02/22/2006"false));
    plants.add(new Plant("Cardinal Flower""Shade"7.81"05/18/2006"false));
    return plants;
  }
  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();
  }
  public static List<Plant> getPlants() {
    List<Plant> plants = new ArrayList<Plant>();
    plants.add(new Plant("Bloodroot""Mostly Shady"2.44"03/15/2006"true));
    plants.add(new Plant("Columbine""Shade"9.37"03/15/2006"true));
    plants.add(new Plant("Marsh Marigold""Mostly Sunny"6.81"05/17/2006"false));
    plants.add(new Plant("Cowslip""Mostly Shady"9.90"03/06/2006"true));
    plants.add(new Plant("Dutchman's-Breeches""Mostly Shady"6.44"01/20/2006"true));
    plants.add(new Plant("Ginger, Wild""Mostly Shady"9.03"04/18/2006"true));
    plants.add(new Plant("Hepatica""Sunny"4.45"01/26/2006"true));
    plants.add(new Plant("Liverleaf""Mostly Sunny"3.99"01/02/2006"true));
    plants.add(new Plant("Jack-In-The-Pulpit""Mostly Shady"3.23"02/01/2006"true));
    plants.add(new Plant("Mayapple""Mostly Shady"2.98"06/05/2006"true));
    plants.add(new Plant("Phlox, Woodland""Sun or Shade"2.80"01/22/2006"false));
    plants.add(new Plant("Phlox, Blue""Sun or Shade"5.59"02/16/2006"false));
    plants.add(new Plant("Spring-Beauty""Mostly Shady"6.59"02/01/2006"true));
    plants.add(new Plant("Trillium""Sun or Shade"3.90"04/29/2006"false));
    plants.add(new Plant("Wake Robin""Sun or Shade"3.20"02/21/2006"false));
    plants.add(new Plant("Violet, Dog-Tooth""Shade"9.04"02/01/2006"true));
    plants.add(new Plant("Trout Lily""Shade"6.94"03/24/2006"true));
    plants.add(new Plant("Adder's-Tongue""Mostly Shady"6.59"02/01/2006"true));
    plants.add(new Plant("Trillium""Shade"9.58"04/13/2006"true));
    plants.add(new Plant("Anemone""Mostly Shady"8.86"12/26/2006"true));
    plants.add(new Plant("Grecian Windflower""Mostly Shady"9.16"07/10/2006"true));
    plants.add(new Plant("Bee Balm""Shade"4.59"05/03/2006"true));
    plants.add(new Plant("Bergamot""Shade"7.16"04/27/2006"true));
    plants.add(new Plant("Black-Eyed Susan""Sunny"9.80"06/18/2006"false));
    plants.add(new Plant("Buttercup""Shade"2.57"06/10/2006"true));
    plants.add(new Plant("Crowfoot""Shade"9.34"04/03/2006"true));
    plants.add(new Plant("Butterfly Weed""Sunny"2.78"06/30/2006"false));
    plants.add(new Plant("Cinquefoil""Shade"7.06"05/25/2006"true));
    plants.add(new Plant("Primrose""Sunny"6.56"01/30/2006"false));
    plants.add(new Plant("Gentian""Sun or Shade"7.81"05/18/2006"false));
    plants.add(new Plant("Greek Valerian""Shade"3.41"04/03/2006"true));
    plants.add(new Plant("California Poppy""Mostly Shady"2.78"05/13/2006"false));
    plants.add(new Plant("Shooting Star""Shade"7.06"07/11/2006"true));
    plants.add(new Plant("Snakeroot""Sunny"6.56"02/22/2006"false));
    plants.add(new Plant("Cardinal Flower""Shade"7.81"05/18/2006"false));
    return plants;
  }
}

class Plant extends BaseModelData {

  private DateTimeFormat df = DateTimeFormat.getFormat("MM/dd/y");

  public Plant() {

  }

  public Plant(String name, String light, double price, String available, boolean indoor) {
    setName(name);
    setLight(light);
    setPrice(price);
    setAvailable(df.parse(available));
    setIndoor(indoor);
  }

  public Date getAvailable() {
    return get("available");
  }

  public void setAvailable(Date available) {
    set("available", available);
  }

  public boolean isIndoor() {
    return (Booleanget("indoor");
  }

  public void setIndoor(boolean indoor) {
    set("indoor", indoor);
  }

  public String getLight() {
    return get("light");
  }

  public void setLight(String light) {
    set("light", light);
  }

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

  public void setName(String name) {
    set("name", name);
  }

  public double getPrice() {
    return (Doubleget("price");
  }

  public void setPrice(double price) {
    set("price", price);
  }

}

   
  














Ext-GWT.zip( 4,297 k)
Related examples in the same category
1.Image cell renderer (Smart GWT)Image cell renderer (Smart GWT)
2.Table integer value cell renderer (Smart GWT)Table integer value cell renderer (Smart GWT)
3.Linkable image cell renderer (Smart GWT)Linkable image cell renderer (Smart GWT)
4.Linkable text cell renderer (Smart GWT)Linkable text cell renderer (Smart GWT)
5.ComboBox cell renderer (Smart GWT)ComboBox cell renderer (Smart GWT)
6.Long text cell renderer (Smart GWT)Long text cell renderer (Smart GWT)
7.TextField cell renderer (Smart GWT)TextField cell renderer (Smart GWT)
8.Multi-line ListGridField (Smart GWT)Multi-line ListGridField (Smart GWT)
9.Adding image to table cell (Smart GWT)Adding image to table cell (Smart GWT)
10.Using Cell style to shade one another row (Smart GWT)Using Cell style to shade one another row (Smart GWT)
11.Change cell style based on its value (Smart GWT)Change cell style based on its value (Smart GWT)
12.Cell with style (Smart GWT)Cell with style (Smart GWT)
13.Format Cell Values Sample (Smart GWT)Format Cell Values Sample (Smart GWT)
14.Set default cell value (Smart GWT)Set default cell value (Smart GWT)
15.Cell value based on calculation(sum of the current row) (Smart GWT)Cell value based on calculation(sum of the current row) (Smart GWT)
16.Autofit value (Smart GWT)Autofit value (Smart GWT)
17.Using ComboBox as table cell renderer (Ext GWT)Using ComboBox as table cell renderer (Ext GWT)
18.Using Calendar as table cell renderer (Ext GWT)Using Calendar as table cell renderer (Ext GWT)
19.Using CheckBox as table cell renderer (Ext GWT)Using CheckBox as table cell renderer (Ext GWT)
20.Using NumberField as table cell renderer (Ext GWT)Using NumberField as table cell renderer (Ext GWT)
21.Using GridCellRenderer to display digits in red (Ext GWT)Using GridCellRenderer to display digits in red (Ext GWT)
22.Using GridCellRenderer to format number (Ext GWT)Using GridCellRenderer to format number (Ext GWT)
23.Grid with Numbered Rows and Force Fit (Ext GWT)Grid with Numbered Rows and Force Fit (Ext GWT)
24.Set column alignment, name and height (Ext GWT)Set column alignment, name and height (Ext GWT)
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.