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:
009: package com.gwtext.client.widgets.grid;
010:
011: import com.google.gwt.core.client.JavaScriptObject;
012: import com.gwtext.client.data.Store;
013: import com.gwtext.client.widgets.grid.event.EditorGridListener;
014:
015: /**
016: * Class for creating and editable grid.
017: */
018: public class EditorGridPanel extends GridPanel {
019:
020: private static JavaScriptObject configPrototype;
021:
022: static {
023: init();
024: }
025:
026: private static native void init()/*-{
027: var c = new $wnd.Ext.grid.EditorGridPanel();
028: @com.gwtext.client.widgets.grid.EditorGridPanel::configPrototype = c.initialConfig;
029: }-*/;
030:
031: protected JavaScriptObject getConfigPrototype() {
032: return configPrototype;
033: }
034:
035: public String getXType() {
036: return "editorgrid";
037: }
038:
039: public EditorGridPanel() {
040: }
041:
042: /**
043: * Creates a new Editor Grid.
044: *
045: * @param store the Grid's data store
046: * @param columnModel the Grids column model
047: */
048: public EditorGridPanel(Store store, ColumnModel columnModel) {
049: super (store, columnModel);
050: }
051:
052: public EditorGridPanel(JavaScriptObject jsObj) {
053: super (jsObj);
054: }
055:
056: /**
057: * Creates a new Editor Grid.
058: *
059: * @param id the Grid ID
060: * @param width the Grid width
061: * @param height the Grid height
062: * @param store the Grid's data store
063: * @param columnModel the Grids column model
064: */
065: public EditorGridPanel(String id, int width, int height,
066: Store store, ColumnModel columnModel) {
067: super (id, width, height, store, columnModel);
068: }
069:
070: protected native JavaScriptObject create(JavaScriptObject configJS) /*-{
071: return new $wnd.Ext.grid.EditorGridPanel(configJS);
072: }-*/;
073:
074: /**
075: * Add an EditorGridPanel listener.
076: *
077: * @param listener the listener
078: */
079: public native void addEditorGridListener(EditorGridListener listener)/*-{
080: var gridJ = this;
081:
082: this.@com.gwtext.client.widgets.Component::addListener(Ljava/lang/String;Lcom/google/gwt/core/client/JavaScriptObject;)('afteredit',
083: function(e) {
084: var recordJ = @com.gwtext.client.data.Record::instance(Lcom/google/gwt/core/client/JavaScriptObject;)(e.record);
085: var value = e.value === undefined ? null : $wnd.GwtExt.convertToJavaType(e.value);
086: var originalValue = e.originalValue === undefined ? null : $wnd.GwtExt.convertToJavaType(e.originalValue);
087: listener.@com.gwtext.client.widgets.grid.event.EditorGridListener::onAfterEdit(Lcom/gwtext/client/widgets/grid/GridPanel;Lcom/gwtext/client/data/Record;Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;II)(gridJ, recordJ, e.field, value , originalValue, e.row, e.column);
088: }
089: );
090:
091: this.@com.gwtext.client.widgets.Component::addListener(Ljava/lang/String;Lcom/google/gwt/core/client/JavaScriptObject;)('beforeedit',
092: function(e) {
093: var recordJ = @com.gwtext.client.data.Record::instance(Lcom/google/gwt/core/client/JavaScriptObject;)(e.record);
094: var value = e.value === undefined ? null : $wnd.GwtExt.convertToJavaType(e.value);
095: return listener.@com.gwtext.client.widgets.grid.event.EditorGridListener::doBeforeEdit(Lcom/gwtext/client/widgets/grid/GridPanel;Lcom/gwtext/client/data/Record;Ljava/lang/String;Ljava/lang/Object;II)(gridJ, recordJ, e.field, value, e.row, e.column);
096: }
097: );
098:
099: this.@com.gwtext.client.widgets.Component::addListener(Ljava/lang/String;Lcom/google/gwt/core/client/JavaScriptObject;)('validateedit',
100: function(e) {
101: var recordJ = @com.gwtext.client.data.Record::instance(Lcom/google/gwt/core/client/JavaScriptObject;)(e.record);
102: var value = e.value === undefined ? null : $wnd.GwtExt.convertToJavaType(e.value);
103: var originalValue = e.originalValue === undefined ? null : $wnd.GwtExt.convertToJavaType(e.originalValue);
104: return listener.@com.gwtext.client.widgets.grid.event.EditorGridListener::doValidateEdit(Lcom/gwtext/client/widgets/grid/GridPanel;Lcom/gwtext/client/data/Record;Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;II)(gridJ, recordJ, e.field, value, originalValue, e.row, e.column);
105: }
106: );
107: }-*/;
108:
109: /**
110: * Starts editing the specified for the specified row/column.
111: *
112: * @param rowIndex row to edit
113: * @param colIndex column to edit
114: */
115: public native void startEditing(int rowIndex, int colIndex) /*-{
116: var grid = this.@com.gwtext.client.widgets.Component::getOrCreateJsObj()();
117: grid.startEditing(rowIndex, colIndex);
118: }-*/;
119:
120: /**
121: * Stops any active editing.
122: */
123: public native void stopEditing() /*-{
124: var grid = this.@com.gwtext.client.widgets.Component::getOrCreateJsObj()();
125: grid.stopEditing();
126: }-*/;
127:
128: /**
129: * Get the Grids Cell selection model
130: *
131: * @return the cell selection model
132: */
133: public CellSelectionModel getCellSelectionModel() {
134: return new CellSelectionModel(
135: getSelectionModel(getOrCreateJsObj()));
136: }
137:
138: private native JavaScriptObject getSelectionModel(
139: JavaScriptObject grid) /*-{
140: return grid.getSelectionModel();
141: }-*/;
142:
143: // --- config proeprties ---
144: /**
145: * The number of clicks on a cell required to display the cell's editor (defaults to 2).
146: *
147: * @param clicksToEdit the number of clicks to edit
148: * @throws IllegalStateException this property cannot be changed after the Component has been rendered
149: */
150: public void setClicksToEdit(int clicksToEdit)
151: throws IllegalStateException {
152: setAttribute("clicksToEdit", clicksToEdit, true);
153: }
154:
155: /**
156: * True to automatically HTML encode and decode values pre and post edit (defaults to false)
157: *
158: * @param autoEncode true to auto encode
159: */
160: public void setAutoEncode(boolean autoEncode) {
161: setAttribute("autoEncode", autoEncode, true);
162: }
163: }
|