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 java.util.ArrayList;
19 import java.util.List;
20
21 import com.google.gwt.user.client.DOM;
22 import com.google.gwt.user.client.Element;
23 import com.google.gwt.user.client.ui.Composite;
24 import com.google.gwt.user.client.ui.FlexTable;
25 import com.google.gwt.user.client.ui.Widget;
26
27 public class SimpleWidgetTable extends Composite{
28 private FlexTable simpleTable = new FlexTable();
29 private int rowCount = 0;
30 public List<String> columnList = new ArrayList<String>();
31
32 private static class TableRow{
33
34 public List<Widget> widgetList = new ArrayList<Widget>();
35 public List<Widget> getWidgetList() {
36 return widgetList;
37 }
38 public void setWidgetList(List<Widget> widgetList) {
39 this.widgetList = widgetList;
40 }
41 public TableRow(List<Widget> widgetList){
42 this.widgetList = widgetList;
43 }
44 }
45
46 public SimpleWidgetTable(List<String> columnNames){
47 Element thead = DOM.createElement("thead");
48 Element tr = DOM.createTR();
49 int columnPercentage = 100/columnNames.size();
50
51
52 Element table = simpleTable.getElement();
53 DOM.appendChild(thead,tr);
54 for (String columnName: columnNames) {
55 Element th = DOM.createTH();
56 DOM.appendChild(tr,th);
57 DOM.setInnerText(th,columnName);
58 th.setAttribute("width", columnPercentage + "%");
59 }
60
61 DOM.insertChild(table,thead,0);
62
63 simpleTable.setWidth("100%");
64 simpleTable.setStyleName("ks-table-plain");
65 this.initWidget(simpleTable);
66
67 }
68
69 public void addRow(List<Widget> widgets){
70 int columnNum = 0;
71 TableRow row = new TableRow(widgets);
72 for(Widget w: row.getWidgetList()){
73 simpleTable.setWidget(rowCount, columnNum, w);
74 columnNum++;
75 }
76 rowCount++;
77 }
78
79 public void clear(){
80 rowCount = 0;
81 for(int i=0; i < simpleTable.getRowCount(); i++){
82 simpleTable.removeRow(i);
83 }
84 }
85 }