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.gwtext.client.core.TextAlign;
012: import com.gwtext.client.util.JavaScriptObjectHelper;
013:
014: /**
015: * The Grid Column configuration.
016: *
017: * @see com.gwtext.client.widgets.grid.ColumnModel
018: */
019: public class ColumnConfig extends BaseColumnConfig {
020:
021: /**
022: * Create a new ColumnConfig.
023: */
024: public ColumnConfig() {
025: }
026:
027: /**
028: * Create a new ColumnConfig.
029: *
030: * @param header the column header
031: * @param dataIndex the data index (the field name pf the Store associated with the Grid)
032: * @param width the column width
033: */
034: public ColumnConfig(String header, String dataIndex, int width) {
035: this (header, dataIndex, width, false);
036: }
037:
038: /**
039: * Create a new ColumnConfig.
040: *
041: * @param header the column header
042: * @param dataIndex the data index (the field name pf the Store associated with the Grid)
043: * @param width the column width
044: * @param sortable true for sortable
045: */
046: public ColumnConfig(String header, String dataIndex, int width,
047: boolean sortable) {
048: this (header, dataIndex, width, sortable, null);
049: }
050:
051: /**
052: * Create a new ColumnConfig.
053: *
054: * @param header the column header
055: * @param dataIndex the data index (the field name pf the Store associated with the Grid)
056: * @param width the column width
057: * @param sortable true for sortable
058: * @param renderer a renderer to allow custom formating of cells of this column
059: */
060: public ColumnConfig(String header, String dataIndex, int width,
061: boolean sortable, Renderer renderer) {
062: this (header, dataIndex, width, sortable, renderer, null);
063: }
064:
065: /**
066: * Create a new ColumnConfig.
067: *
068: * @param header the column header
069: * @param dataIndex the data index (the field name pf the Store associated with the Grid)
070: * @param width the column width
071: * @param sortable true for sortable
072: * @param renderer a renderer to allow custom formating of cells of this column
073: * @param id the grid ID
074: */
075: public ColumnConfig(String header, String dataIndex, int width,
076: boolean sortable, Renderer renderer, String id) {
077: if (id != null)
078: setId(id);
079: setHeader(header);
080: setDataIndex(dataIndex);
081: setWidth(width);
082: setSortable(sortable);
083: if (renderer != null)
084: setRenderer(renderer);
085: }
086:
087: /**
088: * Set the CSS text-align property of the column. Defaults to undefined.
089: *
090: * @param align the text-align position
091: */
092: public void setAlign(TextAlign align) {
093: JavaScriptObjectHelper.setAttribute(jsObj, "align", align
094: .getPosition());
095: }
096:
097: public String getTextAlign() {
098: return JavaScriptObjectHelper.getAttribute(jsObj, "textAlign");
099: }
100:
101: /**
102: * Assigning id to ColumnConfig results in the column dom element having that ID.
103: * This is useful to apply custom css to the entire column. (e.g. .x-grid-col-topic b { color:#333 }) .
104: *
105: * @param id the column ID
106: */
107: public void setId(String id) {
108: JavaScriptObjectHelper.setAttribute(jsObj, "id", id);
109: }
110:
111: public String getId() {
112: return JavaScriptObjectHelper.getAttribute(jsObj, "id");
113: }
114:
115: /**
116: * The name of the field in the grid's {@link com.gwtext.client.data.Store}'s {@link com.gwtext.client.data.Record} definition
117: * from which to draw the column's value. If not specified, the column's index is used as an index into the Record's data array.
118: *
119: * @param dataIndex the data index
120: */
121: public void setDataIndex(String dataIndex) {
122: JavaScriptObjectHelper.setAttribute(jsObj, "dataIndex",
123: dataIndex);
124: }
125:
126: public String getDataIndex() {
127: return JavaScriptObjectHelper.getAttribute(jsObj, "dataIndex");
128: }
129:
130: /**
131: * A text string to use as the column header's tooltip. If Quicktips are enabled, this value will be used as the text
132: * of the quick tip, otherwise it will be set as the header's HTML title attribute. Defaults to ''.
133: *
134: * @param tooltip the tooltip
135: */
136: public void setTooltip(String tooltip) {
137: JavaScriptObjectHelper.setAttribute(jsObj, "tooltip", tooltip);
138: }
139:
140: public String getTooltip() {
141: return JavaScriptObjectHelper.getAttribute(jsObj, "tooltip");
142: }
143:
144: /**
145: * Sets teh CSS class for the column,
146: *
147: * @param css the CSS class
148: */
149: public void setCss(String css) {
150: JavaScriptObjectHelper.setAttribute(jsObj, "css", css);
151: }
152:
153: public String getCss() {
154: return JavaScriptObjectHelper.getAttribute(jsObj, "css");
155: }
156:
157: /**
158: * The header text to display in the Grid view. You can use arbitrary html for the header.
159: *
160: * @param header the column header
161: */
162: public void setHeader(String header) {
163: JavaScriptObjectHelper.setAttribute(jsObj, "header", header);
164: }
165:
166: public String getHeader() {
167: return JavaScriptObjectHelper.getAttribute(jsObj, "header");
168: }
169:
170: /**
171: * True to hide the column. Defaults to false.
172: *
173: * @param hidden true to hide column
174: */
175: public void setHidden(boolean hidden) {
176: JavaScriptObjectHelper.setAttribute(jsObj, "hidden", hidden);
177: }
178:
179: public boolean getHidden() {
180: return JavaScriptObjectHelper.getAttributeAsBoolean(jsObj,
181: "hidden");
182: }
183:
184: /**
185: * True to make the column width fixed.
186: *
187: * @param fixed true for fixed width
188: */
189: public void setFixed(boolean fixed) {
190: JavaScriptObjectHelper.setAttribute(jsObj, "fixed", fixed);
191: }
192:
193: public boolean getFixed() {
194: return JavaScriptObjectHelper.getAttributeAsBoolean(jsObj,
195: "fixed");
196: }
197:
198: /**
199: * Sets the rendering (formatting) function for a column.
200: *
201: * @param renderer the column renderer
202: */
203: public native void setRenderer(Renderer renderer) /*-{
204: var config = this.@com.gwtext.client.core.JsObject::getJsObj()();
205:
206: config['renderer'] = function(val, cell, r, rowIndex, colNum, store) {
207: var valJ = (val == null || val === undefined || val === '') ? null : $wnd.GwtExt.convertToJavaType(val);
208: var recJ = @com.gwtext.client.data.Record::instance(Lcom/google/gwt/core/client/JavaScriptObject;)(r);
209: var cellJ = @com.gwtext.client.widgets.grid.ColumnModel::createCellMetadata(Lcom/google/gwt/core/client/JavaScriptObject;)(cell);
210: var storeJ = @com.gwtext.client.data.Store::instance(Lcom/google/gwt/core/client/JavaScriptObject;)(store);
211: return renderer.@com.gwtext.client.widgets.grid.Renderer::render(Ljava/lang/Object;Lcom/gwtext/client/widgets/grid/CellMetadata;Lcom/gwtext/client/data/Record;IILcom/gwtext/client/data/Store;)(valJ, cellJ, recJ, rowIndex, colNum, storeJ);
212: }
213: }-*/;
214:
215: /**
216: * False to disable column resizing. Defaults to true.
217: *
218: * @param resizable false to disable column resizing
219: */
220: public void setResizable(boolean resizable) {
221: JavaScriptObjectHelper.setAttribute(jsObj, "resizable",
222: resizable);
223: }
224:
225: public boolean getResizable() {
226: return JavaScriptObjectHelper.getAttributeAsBoolean(jsObj,
227: "resizable");
228: }
229:
230: //todo see possible format strings in Ext.util.Format
231: public void setRenderer(String renderer) {
232: JavaScriptObjectHelper
233: .setAttribute(jsObj, "renderer", renderer);
234: }
235:
236: /**
237: * True if sorting is to be allowed on this column. Defaults to the value of {@link com.gwtext.client.widgets.grid.ColumnModel#setDefaultSortable(boolean)}.
238: * Whether local/remote sorting is used is specified in {@link com.gwtext.client.data.Store#Store(com.gwtext.client.data.DataProxy, com.gwtext.client.data.Reader, boolean)}
239: *
240: * @param sortable false to disable sorting
241: */
242: public void setSortable(boolean sortable) {
243: JavaScriptObjectHelper
244: .setAttribute(jsObj, "sortable", sortable);
245: }
246:
247: public boolean getSortable() {
248: return JavaScriptObjectHelper.getAttributeAsBoolean(jsObj,
249: "sortable");
250: }
251:
252: /**
253: * The initial width in pixels of the column.
254: *
255: * @param width the column width
256: */
257: public void setWidth(int width) {
258: JavaScriptObjectHelper.setAttribute(jsObj, "width", width);
259: }
260:
261: public int getWidth() {
262: return JavaScriptObjectHelper.getAttributeAsInt(jsObj, "width");
263: }
264:
265: /**
266: * Sets the editor for a column.
267: *
268: * @param editor the column editor
269: */
270: public void setEditor(GridEditor editor) {
271: JavaScriptObjectHelper.setAttribute(jsObj, "editor", editor
272: .getJsObj());
273: }
274: }
|