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: package com.gwtext.client.widgets.grid;
09:
10: import com.google.gwt.core.client.JavaScriptObject;
11: import com.gwtext.client.data.Record;
12: import com.gwtext.client.dd.DragData;
13: import com.gwtext.client.util.JavaScriptObjectHelper;
14:
15: /**
16: * An implementation of DragData that is passed to the drop target when the source is a TreeNode from a Draggable tree.
17: *
18: * @see com.gwtext.client.widgets.tree.event.TreePanelListener#doBeforeNodeDrop(com.gwtext.client.widgets.tree.TreePanel , com.gwtext.client.widgets.tree.TreeNode , com.gwtext.client.dd.DragData, String, com.gwtext.client.dd.DragDrop, com.gwtext.client.widgets.tree.TreeNode , com.gwtext.client.widgets.tree.DropNodeCallback)
19: * @see com.gwtext.client.widgets.tree.event.TreePanelListener#onNodeDrop(com.gwtext.client.widgets.tree.TreePanel , com.gwtext.client.widgets.tree.TreeNode , com.gwtext.client.dd.DragData, String, com.gwtext.client.dd.DragDrop, com.gwtext.client.widgets.tree.TreeNode)
20: */
21: public class GridDragData extends DragData {
22:
23: public GridDragData(JavaScriptObject jsObj) {
24: super (jsObj);
25: }
26:
27: /**
28: * The source GridPanel.
29: *
30: * @return the source GridPanel
31: */
32: public GridPanel getGrid() {
33: JavaScriptObject gridJS = getPropertyAsJavaScriptObject("grid");
34: return new GridPanel(gridJS);
35: }
36:
37: /**
38: * The rows selected in the source GridPanel.
39: *
40: * @return the selected rows
41: */
42: public Record[] getSelections() {
43: JavaScriptObject recordsJS = getPropertyAsJavaScriptObject("selections");
44: return convertFromNativeRecordsArray(recordsJS);
45: }
46:
47: private static Record[] convertFromNativeRecordsArray(
48: JavaScriptObject nativeArray) {
49: JavaScriptObject[] recordsj = JavaScriptObjectHelper
50: .toArray(nativeArray);
51: Record[] records = new Record[recordsj.length];
52: for (int i = 0; i < recordsj.length; i++) {
53: JavaScriptObject record = recordsj[i];
54: records[i] = new Record(record);
55: }
56: return records;
57: }
58:
59: /**
60: * The row index.
61: *
62: * @return the row index
63: */
64: public int getRowIndex() {
65: return getPropertyAsInt("rowIndex");
66: }
67: }
|