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.ui.client.widgets.searchtable.ResultRow;
21 import org.kuali.student.r1.common.dto.Idable;
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 @Deprecated
57 public class PagingScrollTableBuilder<RowType extends Idable> {
58 private PagingScrollTable<RowType> pagingScrollTable;
59 private int tablePixelWidth = 0;
60 private int tablePixelHeight = 0;
61 private boolean isPagable = false;
62 private int numPageRows = 0;
63 private int numPages = 0;
64 private SelectionPolicy selectionPolicy = SelectionPolicy.MULTI_ROW;
65 private List<AbstractColumnDefinition<RowType, ?>> columnDefs;
66 private List<Integer> columnPixelWidths = new ArrayList<Integer>();
67
68
69
70
71
72
73 public PagingScrollTableBuilder() {
74 super();
75 }
76
77
78
79
80
81
82
83
84
85
86 public PagingScrollTableBuilder<RowType> tablePixelSize(int tablePixelWidth,int tablePixelHeight) {
87 this.tablePixelWidth = tablePixelWidth;
88 this.tablePixelHeight = tablePixelHeight;
89 return this;
90 }
91
92
93
94
95
96
97
98
99
100 public PagingScrollTableBuilder<RowType> cacheTable(int numPageRows,int numPages) {
101 this.numPageRows = numPageRows;
102 this.numPages = numPages;
103 this.isPagable = true;
104 return this;
105 }
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123 public PagingScrollTableBuilder<RowType> columnDefinitions(List<AbstractColumnDefinition<RowType, ?>> columnDefs) {
124 this.columnDefs = columnDefs;
125 return this;
126 }
127
128
129
130
131
132
133
134
135
136 public PagingScrollTableBuilder<RowType> setSelectionPolicy(SelectionPolicy selectionPolicy){
137 this.selectionPolicy = selectionPolicy;
138 return this;
139 }
140
141
142
143
144
145
146
147 @SuppressWarnings("unchecked")
148 public PagingScrollTable<RowType> build(GenericTableModel tableModel) {
149 DefaultTableDefinition<RowType> tableDefinition = new DefaultTableDefinition<RowType>();
150 if(columnDefs!=null){
151 for (AbstractColumnDefinition columnDef: columnDefs) {
152 columnPixelWidths.add(columnDef.getPreferredColumnWidth());
153 CellRenderer renderer = new CellRenderer(){
154
155 @Override
156 public void renderRowValue(Object rowValue,
157 ColumnDefinition columnDef, AbstractCellView view) {
158 if(rowValue!=null&& rowValue instanceof ResultRow){
159 view.setHTML((String)columnDef.getCellValue(rowValue));
160 }
161 }
162
163 };
164 columnDef.setCellRenderer(renderer);
165 tableDefinition.addColumnDefinition(columnDef);
166 }
167 }
168
169 if(isPagable){
170 pagingScrollTable = new PagingScrollTable<RowType>(tableModel.createCachedTableModel(numPageRows,numPages),tableDefinition);
171 pagingScrollTable.setPageSize(numPageRows);
172
173 }else {
174 pagingScrollTable = new PagingScrollTable<RowType>(tableModel,tableDefinition);
175 pagingScrollTable.setPageSize(tableModel.getRowCount());
176 }
177 pagingScrollTable.setPixelSize(tablePixelWidth,tablePixelHeight);
178 pagingScrollTable.setEmptyTableWidget(new HTML("There is no data to display"));
179
180 pagingScrollTable.getDataTable().setSelectionPolicy(selectionPolicy);
181
182 pagingScrollTable.getHeaderTable().setWidth("100%");
183 pagingScrollTable.getDataTable().setWidth("100%");
184
185 return this.pagingScrollTable;
186 }
187
188 }