001 /**
002 * Copyright 2010 The Kuali Foundation Licensed under the
003 * Educational Community License, Version 2.0 (the "License"); you may
004 * not use this file except in compliance with the License. You may
005 * obtain a copy of the License at
006 *
007 * http://www.osedu.org/licenses/ECL-2.0
008 *
009 * Unless required by applicable law or agreed to in writing,
010 * software distributed under the License is distributed on an "AS IS"
011 * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
012 * or implied. See the License for the specific language governing
013 * permissions and limitations under the License.
014 */
015
016 package org.kuali.student.common.ui.client.widgets.table;
017
018 import java.util.ArrayList;
019 import java.util.List;
020
021 import com.google.gwt.user.client.DOM;
022 import com.google.gwt.user.client.Element;
023 import com.google.gwt.user.client.ui.Composite;
024 import com.google.gwt.user.client.ui.FlexTable;
025 import com.google.gwt.user.client.ui.Widget;
026
027 public class SimpleWidgetTable extends Composite{
028 private FlexTable simpleTable = new FlexTable();
029 private int rowCount = 0;
030 public List<String> columnList = new ArrayList<String>();
031
032 private static class TableRow{
033
034 public List<Widget> widgetList = new ArrayList<Widget>();
035 public List<Widget> getWidgetList() {
036 return widgetList;
037 }
038 public void setWidgetList(List<Widget> widgetList) {
039 this.widgetList = widgetList;
040 }
041 public TableRow(List<Widget> widgetList){
042 this.widgetList = widgetList;
043 }
044 }
045
046 public SimpleWidgetTable(List<String> columnNames){
047 Element thead = DOM.createElement("thead");
048 Element tr = DOM.createTR();
049 int columnPercentage = 100/columnNames.size();
050
051
052 Element table = simpleTable.getElement();
053 DOM.appendChild(thead,tr);
054 for (String columnName: columnNames) {
055 Element th = DOM.createTH();
056 DOM.appendChild(tr,th);
057 DOM.setInnerText(th,columnName);
058 th.setAttribute("width", columnPercentage + "%");
059 }
060
061 DOM.insertChild(table,thead,0);
062
063 simpleTable.setWidth("100%");
064 simpleTable.setStyleName("ks-table-plain");
065 this.initWidget(simpleTable);
066
067 }
068
069 public void addRow(List<Widget> widgets){
070 int columnNum = 0;
071 TableRow row = new TableRow(widgets);
072 for(Widget w: row.getWidgetList()){
073 simpleTable.setWidget(rowCount, columnNum, w);
074 columnNum++;
075 }
076 rowCount++;
077 }
078
079 public void clear(){
080 rowCount = 0;
081 for(int i=0; i < simpleTable.getRowCount(); i++){
082 simpleTable.removeRow(i);
083 }
084 }
085 }