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: package com.gwtext.sample.showcase2.client.grid;
009:
010: import com.gwtext.client.core.EventObject;
011: import com.gwtext.client.util.Format;
012: import com.gwtext.client.widgets.Panel;
013: import com.gwtext.client.widgets.grid.GridPanel;
014: import com.gwtext.client.widgets.grid.event.*;
015: import com.gwtext.sample.showcase2.client.SampleGrid;
016: import com.gwtext.sample.showcase2.client.ShowcasePanel;
017:
018: public class GridEventsSample extends ShowcasePanel {
019:
020: public String getSourceUrl() {
021: return "source/grid/GridEventsSample.java.html";
022: }
023:
024: public Panel getViewPanel() {
025: if (panel == null) {
026: panel = new Panel();
027:
028: GridPanel grid = new SampleGrid(true);
029: grid.setTitle("Grid Events");
030: grid.setHeight(350);
031: grid.setWidth(600);
032:
033: grid.addGridCellListener(new GridCellListener() {
034: public void onCellClick(GridPanel grid, int rowIndex,
035: int colindex, EventObject e) {
036: log(EVENT, "GridCellListener.onCellClick::row("
037: + rowIndex + "), col(" + colindex + ");");
038: }
039:
040: public void onCellContextMenu(GridPanel grid,
041: int rowIndex, int colIndex, EventObject e) {
042: log(EVENT,
043: "GridCellListener.onCellContextMenu::row("
044: + rowIndex + "), col(" + colIndex
045: + ");");
046: }
047:
048: public void onCellDblClick(GridPanel grid,
049: int rowIndex, int colIndex, EventObject e) {
050: log(EVENT, "GridCellListener.onCellDblClick::row("
051: + rowIndex + "), col(" + colIndex + ");");
052: }
053: });
054:
055: grid.addGridColumnListener(new GridColumnListener() {
056: public void onColumnMove(GridPanel grid, int oldIndex,
057: int newIndex) {
058: log(
059: EVENT,
060: Format
061: .format(
062: "GridCellListener.onColumnMove::oldIndex({0}), newIndex({1})",
063: oldIndex, newIndex));
064: }
065:
066: public void onColumnResize(GridPanel grid,
067: int colIndex, int newSize) {
068: log(
069: EVENT,
070: Format
071: .format(
072: "GridCellListener.onColumnResize::oldIndex({0}), newSize({1})",
073: colIndex, newSize));
074: }
075: });
076:
077: grid.addGridHeaderListener(new GridHeaderListener() {
078: public void onHeaderClick(GridPanel grid, int colIndex,
079: EventObject e) {
080: log(
081: EVENT,
082: Format
083: .format(
084: "GridHeaderListener.onHeaderClick::colIndex({0}))",
085: colIndex));
086: }
087:
088: public void onHeaderContextMenu(GridPanel grid,
089: int colIndex, EventObject e) {
090: log(
091: EVENT,
092: Format
093: .format(
094: "GridHeaderListener.onHeaderContextMenu::colIndex({0}))",
095: colIndex));
096: }
097:
098: public void onHeaderDblClick(GridPanel grid,
099: int colIndex, EventObject e) {
100: log(
101: EVENT,
102: Format
103: .format(
104: "GridHeaderListener.onHeaderDblClick::colIndex({0}))",
105: colIndex));
106: }
107: });
108:
109: grid.addGridListener(new GridListener() {
110: public void onBodyScroll(int scrollLeft, int scrollTop) {
111: log(
112: EVENT,
113: Format
114: .format(
115: "GridListener.onBodyScroll::scrollLeft({0}, scrollTop({1})))",
116: scrollLeft, scrollTop));
117: }
118:
119: public void onClick(EventObject e) {
120: log(EVENT, "GridListener.onClick");
121: }
122:
123: public void onContextMenu(EventObject e) {
124: log(EVENT, "GridListener.onContextMenu");
125: }
126:
127: public void onDblClick(EventObject e) {
128: log(EVENT, "GridListener.onDblClick");
129: }
130:
131: public void onKeyDown(EventObject e) {
132: log(EVENT, "GridListener.onKeyDown");
133: }
134:
135: public void onKeyPress(EventObject e) {
136: log(EVENT, "GridListener.onKeyPress");
137: }
138: });
139:
140: grid.addGridRowListener(new GridRowListener() {
141: public void onRowClick(GridPanel grid, int rowIndex,
142: EventObject e) {
143: log(
144: EVENT,
145: Format
146: .format(
147: "GridRowListener.onRowClick::rowIndex({0})",
148: rowIndex));
149: }
150:
151: public void onRowDblClick(GridPanel grid, int rowIndex,
152: EventObject e) {
153: log(
154: EVENT,
155: Format
156: .format(
157: "GridRowListener.onRowDblClick::rowIndex({0})",
158: rowIndex));
159: }
160:
161: public void onRowContextMenu(GridPanel grid,
162: int rowIndex, EventObject e) {
163: log(
164: EVENT,
165: Format
166: .format(
167: "GridRowListener.onRowContextMenu::rowIndex({0}), x({1}), y({2})",
168: rowIndex, e.getPageX(), e
169: .getPageY()));
170: }
171: });
172:
173: panel.add(grid);
174: }
175: return panel;
176: }
177:
178: protected boolean showEvents() {
179: return true;
180: }
181:
182: public String getIntro() {
183: return "This example illustrates various events that a Grid fires.";
184: }
185: }
|