1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.student.common.ui.client.widgets.pagetable;
17 import java.util.ArrayList;
18 import java.util.List;
19
20 import org.kuali.student.common.dto.Idable;
21 import org.kuali.student.common.ui.client.widgets.searchtable.ResultRow;
22
23 import com.google.gwt.gen2.table.client.AbstractColumnDefinition;
24 import com.google.gwt.gen2.table.client.CellRenderer;
25 import com.google.gwt.gen2.table.client.ColumnDefinition;
26 import com.google.gwt.gen2.table.client.DefaultTableDefinition;
27 import com.google.gwt.gen2.table.client.PagingScrollTable;
28 import com.google.gwt.gen2.table.client.SelectionGrid.SelectionPolicy;
29 import com.google.gwt.gen2.table.client.TableDefinition.AbstractCellView;
30 import com.google.gwt.user.client.ui.HTML;
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56 public class PagingScrollTableBuilder<RowType extends Idable> {
57 private PagingScrollTable<RowType> pagingScrollTable;
58 private int tablePixelWidth = 0;
59 private int tablePixelHeight = 0;
60 private boolean isPagable = false;
61 private int numPageRows = 0;
62 private int numPages = 0;
63 private SelectionPolicy selectionPolicy = SelectionPolicy.MULTI_ROW;
64 private List<AbstractColumnDefinition<RowType, ?>> columnDefs;
65 private List<Integer> columnPixelWidths = new ArrayList<Integer>();
66
67
68
69
70
71
72 public PagingScrollTableBuilder() {
73 super();
74 }
75
76
77
78
79
80
81
82
83
84
85 public PagingScrollTableBuilder<RowType> tablePixelSize(int tablePixelWidth,int tablePixelHeight) {
86 this.tablePixelWidth = tablePixelWidth;
87 this.tablePixelHeight = tablePixelHeight;
88 return this;
89 }
90
91
92
93
94
95
96
97
98
99 public PagingScrollTableBuilder<RowType> cacheTable(int numPageRows,int numPages) {
100 this.numPageRows = numPageRows;
101 this.numPages = numPages;
102 this.isPagable = true;
103 return this;
104 }
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122 public PagingScrollTableBuilder<RowType> columnDefinitions(List<AbstractColumnDefinition<RowType, ?>> columnDefs) {
123 this.columnDefs = columnDefs;
124 return this;
125 }
126
127
128
129
130
131
132
133
134
135 public PagingScrollTableBuilder<RowType> setSelectionPolicy(SelectionPolicy selectionPolicy){
136 this.selectionPolicy = selectionPolicy;
137 return this;
138 }
139
140
141
142
143
144
145
146 @SuppressWarnings("unchecked")
147 public PagingScrollTable<RowType> build(GenericTableModel tableModel) {
148 DefaultTableDefinition<RowType> tableDefinition = new DefaultTableDefinition<RowType>();
149 if(columnDefs!=null){
150 for (AbstractColumnDefinition columnDef: columnDefs) {
151 columnPixelWidths.add(columnDef.getPreferredColumnWidth());
152 CellRenderer renderer = new CellRenderer(){
153
154 @Override
155 public void renderRowValue(Object rowValue,
156 ColumnDefinition columnDef, AbstractCellView view) {
157 if(rowValue!=null&& rowValue instanceof ResultRow){
158 view.setHTML((String)columnDef.getCellValue(rowValue));
159 }
160 }
161
162 };
163 columnDef.setCellRenderer(renderer);
164 tableDefinition.addColumnDefinition(columnDef);
165 }
166 }
167
168 if(isPagable){
169 pagingScrollTable = new PagingScrollTable<RowType>(tableModel.createCachedTableModel(numPageRows,numPages),tableDefinition);
170 pagingScrollTable.setPageSize(numPageRows);
171
172 }else {
173 pagingScrollTable = new PagingScrollTable<RowType>(tableModel,tableDefinition);
174 pagingScrollTable.setPageSize(tableModel.getRowCount());
175 }
176 pagingScrollTable.setPixelSize(tablePixelWidth,tablePixelHeight);
177 pagingScrollTable.setEmptyTableWidget(new HTML("There is no data to display"));
178
179 pagingScrollTable.getDataTable().setSelectionPolicy(selectionPolicy);
180
181 pagingScrollTable.getHeaderTable().setWidth("100%");
182 pagingScrollTable.getDataTable().setWidth("100%");
183
184 return this.pagingScrollTable;
185 }
186
187 }