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.google.gwt.user.client.Element;
013: import com.gwtext.client.core.JsObject;
014: import com.gwtext.client.data.Record;
015: import com.gwtext.client.data.Store;
016: import com.gwtext.client.util.JavaScriptObjectHelper;
017:
018: /**
019: * A Grid's View class.
020: */
021: public class GridView extends JsObject {
022:
023: protected JavaScriptObject configJS = JavaScriptObjectHelper
024: .createObject();
025:
026: public GridView(JavaScriptObject jsObj) {
027: super (jsObj);
028: configJS = jsObj;
029: }
030:
031: /**
032: * Constructs a new GridView.
033: *
034: */
035: public GridView() {
036: }
037:
038: public JavaScriptObject getJsObj() {
039: if (!isCreated()) {
040: jsObj = create(configJS);
041: }
042: return jsObj;
043: }
044:
045: protected native JavaScriptObject create(JavaScriptObject config) /*-{
046: var gridJ = this;
047: var gridV = new $wnd.Ext.grid.GridView(config);
048: gridV.getRowClass = function(record, index, rp, store) {
049: var recordJ = @com.gwtext.client.data.Record::instance(Lcom/google/gwt/core/client/JavaScriptObject;)(record);
050: var rpJ = @com.gwtext.client.widgets.grid.RowParams::instance(Lcom/google/gwt/core/client/JavaScriptObject;)(rp);
051: var storeJ = @com.gwtext.client.data.Store::instance(Lcom/google/gwt/core/client/JavaScriptObject;)(store);
052: return gridJ.@com.gwtext.client.widgets.grid.GridView::getRowClass(Lcom/gwtext/client/data/Record;ILcom/gwtext/client/widgets/grid/RowParams;Lcom/gwtext/client/data/Store;)(recordJ, index, rpJ, storeJ);
053: }
054: return gridV;
055: }-*/;
056:
057: /**
058: * Refreshes the grid.
059: */
060: public native void refresh() /*-{
061: var view = this.@com.gwtext.client.core.JsObject::getJsObj()();
062: view.refresh();
063: }-*/;
064:
065: /**
066: * Refreshes the grid.
067: *
068: * @param headersToo true to refresh the headers too
069: */
070: public native void refresh(boolean headersToo) /*-{
071: var view = this.@com.gwtext.client.core.JsObject::getJsObj()();
072: view.refresh(headersToo);
073: }-*/;
074:
075: /**
076: * Override this function to apply custom css classes to rows during rendering.
077: *
078: * @param record the record for the row
079: * @param index the row index
080: * @param rowParams row class passed to the method to support custom row rendering
081: * @param store the grids store
082: * @return the row CSS class
083: */
084: public String getRowClass(Record record, int index,
085: RowParams rowParams, Store store) {
086: return "";
087: }
088:
089: /**
090: * Refresh a row.
091: *
092: * @param index the row to refresh
093: */
094: public native void refreshRow(int index) /*-{
095: var view = this.@com.gwtext.client.core.JsObject::getJsObj()();
096: view.refreshRow(index);
097: }-*/;
098:
099: /**
100: * The record to refresh.
101: *
102: * @param record the record
103: */
104: public native void refreshRow(Record record) /*-{
105: var view = this.@com.gwtext.client.core.JsObject::getJsObj()();
106: var recordJS = record.@com.gwtext.client.core.JsObject::getJsObj()();
107: view.refreshRow(recordJS);
108: }-*/;
109:
110: /**
111: * Scrolls the grid to the top.
112: */
113: public native void scrollToTop() /*-{
114: var view = this.@com.gwtext.client.core.JsObject::getJsObj()();
115: view.scrollToTop();
116: }-*/;
117:
118: /**
119: * Return the header cell.
120: *
121: * @param index header index
122: * @return the header cell
123: */
124: public native Element getHeaderCell(int index)/*-{
125: var view = this.@com.gwtext.client.core.JsObject::getJsObj()();
126: var headerCellEl = view.getHeaderCell(index);
127: return headerCellEl === undefined ? null : headerCellEl;
128: }-*/;
129:
130: /**
131: * Returns the row element.
132: *
133: * @param index row index
134: * @return the row element
135: */
136: public native Element getRow(int index)/*-{
137: var view = this.@com.gwtext.client.core.JsObject::getJsObj()();
138: var rowEl = view.getRow(index);
139: return rowEl === undefined ? null : rowEl;
140: }-*/;
141:
142: /**
143: * Returns a cells element.
144: *
145: * @param rowIndex the row index
146: * @param colIndex the column index
147: * @return the cell element
148: */
149: public native Element getCell(int rowIndex, int colIndex)/*-{
150: var view = this.@com.gwtext.client.core.JsObject::getJsObj()();
151: var el = view.getCell(rowIndex, colIndex);
152: return el=== undefined ? null : el;
153: }-*/;
154:
155: /**
156: * Focusses the specified row.
157: *
158: * @param rowIndex the row index
159: */
160: public native void focusRow(int rowIndex) /*-{
161: var view = this.@com.gwtext.client.core.JsObject::getJsObj()();
162: view.focusRow(rowIndex);
163: }-*/;
164:
165: /**
166: * Focuses the specified cell.
167: *
168: * @param rowIndex the row index
169: * @param colIndex the column index
170: * @param hscroll false to disable horizontal scrolling
171: */
172: public native void focusCell(int rowIndex, int colIndex,
173: boolean hscroll) /*-{
174: var view = this.@com.gwtext.client.core.JsObject::getJsObj()();
175: view.focusCell(rowIndex, colIndex, hscroll);
176: }-*/;
177:
178: /**
179: * Autofits all columns to the grid's width proportionate with their current size.
180: *
181: * @param reserveScrollSpace reserve space for a scrollbar
182: */
183: public native void fitColumns(boolean reserveScrollSpace) /*-{
184: var view = this.@com.gwtext.client.core.JsObject::getJsObj()();
185: view.fitColumns(reserveScrollSpace);
186: }-*/;
187:
188: /**
189: * Update the headers sort state.
190: */
191: public native void updateHeaderSortState() /*-{
192: var view = this.@com.gwtext.client.core.JsObject::getJsObj()();
193: view.updateHeaderSortState();
194: }-*/;
195:
196: /**
197: * True to auto expand the columns to fit the grid <b>when the grid is created</b>.
198: *
199: * @param autoFill true to auto expand the columns to fit the grid when the grid is created.
200: */
201: public void setAutoFill(boolean autoFill) {
202: JavaScriptObjectHelper.setAttribute(configJS, "autoFill",
203: autoFill);
204: }
205:
206: /**
207: * Default text to display in the grid body when no rows are available (defaults to '').
208: *
209: * @param emptyText default text to display in the grid body when no rows are available (defaults to '').
210: */
211: public void setEmptyText(String emptyText) {
212: JavaScriptObjectHelper.setAttribute(configJS, "emptyText",
213: emptyText);
214: }
215:
216: /**
217: * True to add a second TR element per row that can be used to provide a row body that spans beneath the data row.
218: * Use the getRowClass method's rowParams config to customize the row body
219: *
220: * @param enableRowBody true to add a second TR element per row that can be used to provide a row body that spans beneath the data row.
221: */
222: public void setEnableRowBody(boolean enableRowBody) {
223: JavaScriptObjectHelper.setAttribute(configJS, "enableRowBody",
224: enableRowBody);
225: }
226:
227: /**
228: * True to auto expand/contract the size of the columns to fit the grid width and prevent horizontal scrolling.
229: *
230: * @param forceFit true to force fit
231: */
232: public void setForceFit(boolean forceFit) {
233: JavaScriptObjectHelper.setAttribute(configJS, "forceFit",
234: forceFit);
235: }
236:
237: //todo this is doced as a property and not a config but used in example as a config
238: /**
239: * The amount of space to reserve for the scrollbar (defaults to 19 pixels).
240: *
241: * @param scrollOffset the scroll offset
242: */
243: public void setScrollOffset(int scrollOffset) {
244: JavaScriptObjectHelper.setAttribute(configJS, "scrollOffset",
245: scrollOffset);
246: }
247: }
|