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.util.Format;
011: import com.gwtext.client.widgets.Panel;
012: import com.gwtext.client.widgets.form.TimeField;
013: import com.gwtext.client.widgets.grid.GridEditor;
014: import com.gwtext.client.widgets.grid.GridView;
015: import com.gwtext.client.widgets.grid.PropertyGridPanel;
016: import com.gwtext.client.widgets.grid.event.PropertyGridPanelListener;
017: import com.gwtext.sample.showcase2.client.ShowcasePanel;
018:
019: import java.util.Date;
020: import java.util.HashMap;
021: import java.util.Map;
022:
023: public class PropertyGridSample extends ShowcasePanel {
024:
025: public String getSourceUrl() {
026: return "source/grid/PropertyGridSample.java.html";
027: }
028:
029: public Panel getViewPanel() {
030: if (panel == null) {
031: panel = new Panel();
032:
033: PropertyGridPanel grid = new PropertyGridPanel();
034: grid.setId("props-grid");
035: grid.setNameText("Properties Grid");
036: grid.setWidth(300);
037: grid.setAutoHeight(true);
038:
039: GridView view = new GridView();
040: view.setForceFit(true);
041: view.setScrollOffset(2); // the grid will never have scrollbars
042: grid.setView(view);
043:
044: Map source = new HashMap();
045: source.put("(name)", "Properties Grid");
046: source.put("grouping", Boolean.FALSE);
047: source.put("autoFitColumns", Boolean.TRUE);
048: source.put("productionQuality", Boolean.FALSE);
049: source.put("created", new Date());
050: source.put("tested", Boolean.FALSE);
051: source.put("version", new Float(0.1f));
052: source.put("borderWidth", new Integer(1));
053:
054: Map customEditors = new HashMap();
055: GridEditor timeEditor = new GridEditor(new TimeField());
056:
057: customEditors.put("Edit Time", timeEditor);
058: grid.setCustomEditors(customEditors);
059:
060: grid.setSource(source);
061:
062: grid
063: .addPropertyGridPanelListener(new PropertyGridPanelListener() {
064: public boolean doBeforePropertyChange(
065: PropertyGridPanel source,
066: String recordID, Object value,
067: Object oldValue) {
068: return true;
069: }
070:
071: public void onPropertyChange(
072: PropertyGridPanel source,
073: String recordID, Object value,
074: Object oldValue) {
075: log(
076: EVENT,
077: Format
078: .format(
079: "Property '{0}' changed from {1} to {2}.",
080: recordID,
081: String
082: .valueOf(oldValue),
083: String
084: .valueOf(value)));
085: }
086: });
087: panel.add(grid);
088:
089: }
090: return panel;
091: }
092:
093: protected boolean showEvents() {
094: return true;
095: }
096:
097: public String getIntro() {
098: return "<p>This is an example of a PropertyGrid which is a specialized grid implementation intended to mimic the "
099: + "traditional property grid as typically seen in development IDEs.</p>"
100: + " <p>Each row in the grid represents a property of some object, and the data is stored as a set of name/value pairs.</p>";
101: }
102: }
|