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