01: /*
02: * GWT-Ext Widget Library
03: * Copyright(c) 2007-2008, GWT-Ext.
04: * licensing@gwt-ext.com
05: *
06: * http://www.gwt-ext.com/license
07: */
08:
09: package com.gwtext.client.widgets.grid;
10:
11: import com.google.gwt.core.client.JavaScriptObject;
12: import com.gwtext.client.widgets.grid.event.CellSelectionModelListener;
13:
14: /**
15: * This class provides the basic implementation for cell selection in a grid.
16: */
17: public class CellSelectionModel extends AbstractSelectionModel {
18:
19: public CellSelectionModel(JavaScriptObject jsObj) {
20: super (jsObj);
21: }
22:
23: /**
24: * Clears all selections.
25: */
26: public native void clearSelections() /*-{
27: var sm = this.@com.gwtext.client.core.JsObject::getJsObj()();
28: sm.clearSelections();
29: }-*/;
30:
31: /**
32: * Clears all selections.
33: *
34: * @param disableNotifications true to disable notifications to the {@link GridView}
35: */
36: public native void clearSelections(boolean disableNotifications) /*-{
37: var sm = this.@com.gwtext.client.core.JsObject::getJsObj()();
38: sm.clearSelections(disableNotifications);
39: }-*/;
40:
41: /**
42: * Returns the currently selected cell.
43: *
44: * @return array containing rowIndex, colIndex
45: */
46: public native int[] getSelectedCell() /*-{
47: var sm = this.@com.gwtext.client.core.JsObject::getJsObj()();
48: var sc = sm.getSelectedCell();
49: return sc == null ? null : @com.gwtext.client.util.JavaScriptObjectHelper::convertToJavaIntArray(Lcom/google/gwt/core/client/JavaScriptObject;)(sc);
50: }-*/;
51:
52: /**
53: * Selects a cell.
54: *
55: * @param rowIndex row index of cell
56: * @param cellIndex column index of cell
57: */
58: public native void select(int rowIndex, int cellIndex)/*-{
59: var sm = this.@com.gwtext.client.core.JsObject::getJsObj()();
60: sm.select(rowIndex, cellIndex);
61: }-*/;
62:
63: /**
64: * Adds a Cell Selection model listener.
65: *
66: * @param listener the listener
67: */
68: public native void addListener(CellSelectionModelListener listener) /*-{
69: var sm = this.@com.gwtext.client.core.JsObject::getJsObj()();
70: var smJ = this;
71:
72: sm.addListener('beforerowselect',
73: function(source, rowIndex, colIndex) {
74: return listener.@com.gwtext.client.widgets.grid.event.CellSelectionModelListener::doBeforeRowSelect(Lcom/gwtext/client/widgets/grid/CellSelectionModel;II)(smJ, rowIndex, colIndex);
75: }
76: );
77:
78: sm.addListener('cellselect',
79: function(source, rowIndex, colIndex) {
80: listener.@com.gwtext.client.widgets.grid.event.CellSelectionModelListener::onCellSelect(Lcom/gwtext/client/widgets/grid/CellSelectionModel;II)(smJ, rowIndex, colIndex);
81: }
82: );
83:
84: sm.addListener('selectionchange',
85: function(source, selection) {
86: var recordJ = null;
87: var cell = null;
88: if(selection != null && selection.record != null) {
89: recordJ = @com.gwtext.client.data.Record::instance(Lcom/google/gwt/core/client/JavaScriptObject;)(selection.record);
90: cell = selection.cell;
91: }
92: var cellJ = (cell == null || cell === undefined) ? null : @com.gwtext.client.util.JavaScriptObjectHelper::convertToJavaIntArray(Lcom/google/gwt/core/client/JavaScriptObject;)(cell);
93: listener.@com.gwtext.client.widgets.grid.event.CellSelectionModelListener::onSelectionChange(Lcom/gwtext/client/widgets/grid/CellSelectionModel;Lcom/gwtext/client/data/Record;[I)(smJ, recordJ, cellJ);
94: }
95: );
96: }-*/;
97: }
|