001: package com.gwtext.client.widgets.grid;
002:
003: import com.google.gwt.core.client.JavaScriptObject;
004: import com.gwtext.client.core.NameValuePair;
005: import com.gwtext.client.util.JavaScriptObjectHelper;
006: import com.gwtext.client.widgets.grid.event.PropertyGridPanelListener;
007:
008: import java.util.Map;
009:
010: /**
011: * A specialized grid implementation intended to mimic the traditional property grid as typically seen in development IDEs.
012: * Each row in the grid represents a property of some object, and the data is stored as a set of name/value pairs
013: */
014: public class PropertyGridPanel extends EditorGridPanel {
015:
016: static {
017: init();
018: }
019:
020: //http://extjs.com/forum/showthread.php?t=23138
021: private static native void init()/*-{
022: $wnd.Ext.reg('propertygrid', $wnd.Ext.grid.PropertyGrid);
023: }-*/;
024:
025: public String getXType() {
026: return "propertygrid";
027: }
028:
029: /**
030: * Create a new PropertGridPanel.
031: */
032: public PropertyGridPanel() {
033: }
034:
035: public PropertyGridPanel(JavaScriptObject jsObj) {
036: super (jsObj);
037: }
038:
039: protected native JavaScriptObject create(JavaScriptObject configJS) /*-{
040: return new $wnd.Ext.grid.PropertyGrid(configJS);
041: }-*/;
042:
043: private void setSourceRendered(Map source) {
044: JavaScriptObject sourceJS = JavaScriptObjectHelper
045: .convertMapToJavascriptObject(source);
046: doSetSource(sourceJS);
047: }
048:
049: /**
050: * Sets the source data object containing the property data. The data object can contain one or more name/value pairs
051: * representing all of the properties of an object to display in the grid, and this data will automatically be loaded
052: * into the grid's store. If the grid already contains data, this method will replace any existing data.
053: *
054: * @param source the data source
055: */
056: private void setSourceRendered(NameValuePair[] source) {
057: JavaScriptObject sourceJS = NameValuePair.getJsObj(source);
058: doSetSource(sourceJS);
059: }
060:
061: private native void doSetSource(JavaScriptObject source) /*-{
062: var grid = this.@com.gwtext.client.widgets.Component::getOrCreateJsObj()();
063: grid.setSource(source);
064: }-*/;
065:
066: /**
067: * Add a PropertGridPanel listener.
068: *
069: * @param listener the listener.
070: */
071: public native void addPropertyGridPanelListener(
072: PropertyGridPanelListener listener) /*-{
073: var gridJ = this;
074:
075: this.@com.gwtext.client.widgets.Component::addListener(Ljava/lang/String;Lcom/google/gwt/core/client/JavaScriptObject;)('beforepropertychange',
076: function(self, recordID, value, oldValue) {
077: if(recordID === undefined) recordID = null;
078: var valueJ = (value == null || value === undefined ) ? null : $wnd.GwtExt.convertToJavaType(value);
079: var oldValueJ = (oldValue == null || oldValue === undefined ) ? null : $wnd.GwtExt.convertToJavaType(oldValue);
080: return listener.@com.gwtext.client.widgets.grid.event.PropertyGridPanelListener::doBeforePropertyChange(Lcom/gwtext/client/widgets/grid/PropertyGridPanel;Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)(gridJ, recordID, valueJ, oldValueJ);
081: }
082: );
083:
084: this.@com.gwtext.client.widgets.Component::addListener(Ljava/lang/String;Lcom/google/gwt/core/client/JavaScriptObject;)('propertychange',
085: function(self, recordID, value, oldValue) {
086: if(recordID === undefined) recordID = null;
087: var valueJ = (value == null || value === undefined ) ? null : $wnd.GwtExt.convertToJavaType(value);
088: var oldValueJ = (oldValue == null || oldValue === undefined ) ? null : $wnd.GwtExt.convertToJavaType(oldValue);
089: listener.@com.gwtext.client.widgets.grid.event.PropertyGridPanelListener::onPropertyChange(Lcom/gwtext/client/widgets/grid/PropertyGridPanel;Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)(gridJ, recordID, valueJ, oldValueJ);
090: }
091: );
092: }-*/;
093:
094: //--- config properties ---
095:
096: /**
097: * Sets the source data object containing the property data. The data object can contain one or more name/value pairs
098: * representing all of the properties of an object to display in the grid, and this data will automatically be loaded
099: * into the grid's store. If the grid already contains data, this method will replace any existing data.
100: *
101: * @param source the data source
102: */
103: public void setSource(NameValuePair[] source) {
104: if (!isRendered()) {
105: JavaScriptObject sourceJS = NameValuePair.getJsObj(source);
106: setAttribute("source", sourceJS, true);
107: } else {
108: setSourceRendered(source);
109: }
110: }
111:
112: /**
113: * Sets the source data object containing the property data. The data object can contain one or more name/value pairs
114: * representing all of the properties of an object to display in the grid, and this data will automatically be loaded
115: * into the grid's store. If the grid already contains data, this method will replace any existing data.
116: *
117: * @param source the data source
118: */
119: public void setSource(Map source) {
120: if (!isRendered()) {
121: JavaScriptObject sourceJS = JavaScriptObjectHelper
122: .convertMapToJavascriptObject(source);
123: setAttribute("source", sourceJS, true);
124: } else {
125: setSourceRendered(source);
126: }
127: }
128:
129: /**
130: * The value of the property name text.
131: *
132: * @param nameText the property name text
133: * @throws IllegalStateException this property cannot be changed after the Component has been rendered
134: */
135: public void setNameText(String nameText)
136: throws IllegalStateException {
137: setAttribute("nameText", nameText, true);
138: }
139:
140: /**
141: * An object containing name/value pairs of custom editor type definitions that allow the grid to support additional
142: * types of editable fields. By default, the grid supports strongly-typed editing of strings, dates, numbers and booleans
143: * using built-in form editors, but any custom type can be supported and associated with a custom input control by specifying
144: * a custom editor. The name of the editor type should correspond with the name of the property that will use the editor.
145: * <p/>
146: * <pre>
147: * <code>
148: * PropertyGridPanel grid = new PropertyGridPanel();
149: * Map source = new HashMap();
150: * source.put("Edit Time", "10:00 AM");
151: * Map customEditors = new HashMap();
152: * GridEditor timeEditor = new GridEditor(new TimeField());
153: * customEditors.put("Edit Time", timeEditor);
154: * grid.setCustomEditors(customEditors);</code>
155: * </pre>
156: *
157: * @param customEditors custom editors
158: * @throws IllegalStateException this property cannot be changed after the Component has been rendered
159: */
160: public void setCustomEditors(Map customEditors)
161: throws IllegalStateException {
162: JavaScriptObjectHelper.setAttribute(config, "customEditors",
163: customEditors);
164: }
165: }
|