Coverage Report - org.kuali.student.common.ui.client.widgets.table.SimpleWidgetTable
 
Classes in this File Line Coverage Branch Coverage Complexity
SimpleWidgetTable
0%
0/31
0%
0/6
1.5
SimpleWidgetTable$TableRow
0%
0/7
N/A
1.5
 
 1  
 /**
 2  
  * Copyright 2010 The Kuali Foundation Licensed under the
 3  
  * Educational Community License, Version 2.0 (the "License"); you may
 4  
  * not use this file except in compliance with the License. You may
 5  
  * obtain a copy of the License at
 6  
  *
 7  
  * http://www.osedu.org/licenses/ECL-2.0
 8  
  *
 9  
  * Unless required by applicable law or agreed to in writing,
 10  
  * software distributed under the License is distributed on an "AS IS"
 11  
  * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 12  
  * or implied. See the License for the specific language governing
 13  
  * permissions and limitations under the License.
 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  
 }