1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.student.common.ui.client.widgets.table;
17
18 import com.google.gwt.user.client.ui.FlexTable;
19 import com.google.gwt.user.client.ui.HTMLTable;
20 import com.google.gwt.user.client.ui.Label;
21 import com.google.gwt.user.client.ui.Widget;
22
23
24
25
26
27
28 public class SectionTable extends FlexTable {
29
30 protected static final int HEADER_ROW = 0;
31 protected static final int FIRST_DATA_ROW = 1;
32 protected static final int FIRST_COLUMN = 0;
33 protected static final int DATA_INDEX_ZERO = 0;
34 protected static final int DEFAULT_TABLE_CELL_SPACING = 0;
35
36 private int nextRow =1 ;
37 private Object[][] rowData = null;
38
39
40 public SectionTable(Object[][] rowData) {
41 this();
42 this.rowData = rowData;
43 createRows(DATA_INDEX_ZERO);
44
45 }
46
47
48 public SectionTable() {
49 insertRow(HEADER_ROW);
50 setCellSpacing(DEFAULT_TABLE_CELL_SPACING);
51 addStyleName("ks-table-container");
52 addStyleName("ks-table");
53 getRowFormatter().addStyleName(HEADER_ROW, "ks-table th");
54 }
55
56 public void createRows(int rowIndex) {
57 if (rowData == null)
58 return;
59
60 for (int row = rowIndex; row < rowData.length; row++) {
61 addRow(rowData[row]);
62 }
63 }
64
65 public void addRow(Object[] cellObjects) {
66 for (int cell = FIRST_COLUMN; cell < cellObjects.length; cell++) {
67 addCell(nextRow, cell, cellObjects[cell]);
68 }
69 nextRow++;
70 }
71
72 public void addCell(int row, int cell, Object cellObject) {
73 Widget widget = createCellWidget(cellObject);
74 setWidget(row, cell, widget);
75
76
77
78
79 }
80
81
82
83
84
85
86 public void applyDataRowStyles() {
87 HTMLTable.RowFormatter rf = getRowFormatter();
88
89 }
90
91 public void addColumn(Object columnHeading) {
92 Widget widget = createCellWidget(columnHeading);
93 int columnIndex = getColumnCount();
94
95 widget.setWidth("100%");
96
97
98 setWidget(HEADER_ROW, columnIndex, widget);
99
100
101
102
103
104 }
105
106 public void addSection(Object sectionHeading) {
107
108 Object[] sectionRow = {sectionHeading};
109
110 for (int cell = FIRST_COLUMN+1; cell < getColumnCount(); cell++) {
111 addCell(nextRow, cell, "");
112 }
113
114 addRow(sectionRow);
115
116
117 getRowFormatter().addStyleName(nextRow-1, "td-subhead");
118
119 }
120
121
122 protected Widget createCellWidget(Object cellObject) {
123 Widget widget = null;
124
125 if (cellObject instanceof Widget)
126 widget = (Widget) cellObject;
127 else
128 widget = new Label(cellObject.toString());
129
130
131
132
133 return widget;
134
135 }
136
137
138
139
140
141 public int getColumnCount() {
142 return getCellCount(HEADER_ROW);
143 }
144
145
146 }