001: /*
002: * GWT-Ext Widget Library
003: * Copyright(c) 2007-2008, GWT-Ext.
004: * licensing@gwt-ext.com
005: *
006: * http://www.gwt-ext.com/license
007: */
008: package com.gwtext.sample.showcase2.client.grid;
009:
010: import com.gwtext.client.core.TextAlign;
011: import com.gwtext.client.data.*;
012: import com.gwtext.client.widgets.Panel;
013: import com.gwtext.client.widgets.grid.*;
014: import com.gwtext.sample.showcase2.client.ShowcasePanel;
015:
016: public class LocalXmlGridSample extends ShowcasePanel {
017:
018: public String getSourceUrl() {
019: return "source/grid/LocalXmlGridSample.java.html";
020: }
021:
022: public Panel getViewPanel() {
023: if (panel == null) {
024: panel = new Panel();
025:
026: StringBuffer xml = new StringBuffer();
027: xml.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
028: xml.append("<catalog> ");
029:
030: xml.append("<plant> ");
031: xml.append("<common>Bloodroot</common> ");
032: xml.append("<botanical>Caltha palustris</botanical> ");
033: xml.append("<zone>4</zone> ");
034: xml.append("<light>Mostly Shady</light> ");
035: xml.append("<price>2.44</price> ");
036: xml.append("<availability>03/15/2006</availability> ");
037: xml.append("<indoor>true</indoor> ");
038: xml.append("</plant> ");
039:
040: xml.append("<plant> ");
041: xml.append("<common>Marsh Marigold</common> ");
042: xml
043: .append("<botanical>Sanguinaria canadensis</botanical> ");
044: xml.append("<zone>1</zone> ");
045: xml.append("<light>Mostly Sunny</light> ");
046: xml.append("<price>6.45</price> ");
047: xml.append("<availability>07/12/2007</availability> ");
048: xml.append("<indoor>false</indoor> ");
049: xml.append("</plant> ");
050:
051: xml.append("</catalog> ");
052:
053: XmlReader reader = new XmlReader("plant", new RecordDef(
054: new FieldDef[] {
055: new StringFieldDef("common"),
056: new StringFieldDef("botanical"),
057: new StringFieldDef("light"),
058: new FloatFieldDef("price"),
059: new DateFieldDef("availDate",
060: "availability", "m/d/Y"),
061: new BooleanFieldDef("indoor") }));
062:
063: final Store store = new Store(reader);
064: store.loadXmlData(xml.toString(), true);
065:
066: //setup column model
067: ColumnConfig commonCol = new ColumnConfig("Common Name",
068: "common", 120, true, null, "common");
069: ColumnConfig lightCol = new ColumnConfig("Light", "light",
070: 130);
071:
072: ColumnConfig priceCol = new ColumnConfig("Price", "price",
073: 70, true);
074: priceCol.setAlign(TextAlign.RIGHT);
075: priceCol.setRenderer(new Renderer() {
076: public String render(Object value,
077: CellMetadata cellMetadata, Record record,
078: int rowIndex, int colNum, Store store) {
079: return "$" + value;
080: }
081: });
082: ColumnConfig availableCol = new ColumnConfig("Available",
083: "availDate", 95, true);
084:
085: ColumnConfig indoorCol = new ColumnConfig("Indoor?",
086: "indoor", 55);
087: indoorCol.setRenderer(new Renderer() {
088: public String render(Object value,
089: CellMetadata cellMetadata, Record record,
090: int rowIndex, int colNum, Store store) {
091: boolean checked = ((Boolean) value).booleanValue();
092: return "<img class=\"checkbox\" src=\"js/ext/resources/images/default/menu/"
093: + (checked ? "checked.gif"
094: : "unchecked.gif") + "\"/>";
095: }
096: });
097:
098: ColumnConfig[] columnConfigs = { commonCol, lightCol,
099: priceCol, availableCol, indoorCol };
100:
101: ColumnModel columnModel = new ColumnModel(columnConfigs);
102: columnModel.setDefaultSortable(true);
103:
104: GridPanel grid = new GridPanel();
105: grid.setStore(store);
106: grid.setColumnModel(columnModel);
107: grid.setTitle("Local XML Grid");
108: grid.setWidth(500);
109: grid.setHeight(350);
110: grid.stripeRows(true);
111: grid.setFrame(true);
112: grid.setAutoExpandColumn("common");
113: grid.setIconCls("grid-icon");
114:
115: panel.add(grid);
116: }
117: return panel;
118: }
119:
120: public String getIntro() {
121: return "In this example a Grid is loaded using local XML String data.";
122: }
123: }
|