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