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.sample.showcase2.client.grid;
09:
10: import com.gwtext.client.core.EventObject;
11: import com.gwtext.client.data.Record;
12: import com.gwtext.client.widgets.Button;
13: import com.gwtext.client.widgets.Panel;
14: import com.gwtext.client.widgets.event.ButtonListenerAdapter;
15: import com.gwtext.client.widgets.grid.*;
16: import com.gwtext.client.widgets.layout.VerticalLayout;
17: import com.gwtext.sample.showcase2.client.SampleGrid;
18: import com.gwtext.sample.showcase2.client.ShowcasePanel;
19:
20: public class CheckboxSelectionSample extends ShowcasePanel {
21:
22: public String getSourceUrl() {
23: return "source/grid/CheckboxSelectionSample.java.html";
24: }
25:
26: public Panel getViewPanel() {
27: if (panel == null) {
28: panel = new Panel();
29: panel.setLayout(new VerticalLayout(15));
30:
31: final CheckboxSelectionModel cbSelectionModel = new CheckboxSelectionModel();
32:
33: GridPanel grid = new SampleGrid() {
34:
35: protected ColumnModel getColumnConfigs() {
36: BaseColumnConfig[] columnConfigs = new BaseColumnConfig[columns.length + 1];
37: columnConfigs[0] = new CheckboxColumnConfig(
38: cbSelectionModel);
39: for (int i = 0; i < columns.length; i++) {
40: BaseColumnConfig column = columns[i];
41: columnConfigs[i + 1] = column;
42: }
43: return new ColumnModel(columnConfigs);
44: }
45: };
46:
47: grid.setSelectionModel(cbSelectionModel);
48: grid.setWidth(600);
49: grid.setHeight(300);
50: grid.setFrame(true);
51: grid
52: .setTitle("Framed with Checkbox Selection with Horizontal Scrolling");
53: grid.setIconCls("grid-icon");
54:
55: Button button = new Button("Get Selected",
56: new ButtonListenerAdapter() {
57: public void onClick(Button button, EventObject e) {
58: Record[] records = cbSelectionModel
59: .getSelections();
60: String msg = "";
61: for (int i = 0; i < records.length; i++) {
62: Record record = records[i];
63: msg += record.getAsString("company")
64: + " ";
65: }
66: log(MESSAGE, "Records Selected :" + msg);
67: }
68: });
69:
70: panel.add(grid);
71: panel.add(button);
72: }
73: return panel;
74: }
75:
76: protected boolean showEvents() {
77: return true;
78: }
79:
80: public String getIntro() {
81: return "In this example the Grid has a Frame with a Checkbox selection column.";
82: }
83: }
|