Coverage Report - org.kuali.student.core.statement.ui.client.widgets.table.SectionTable
 
Classes in this File Line Coverage Branch Coverage Complexity
SectionTable
0%
0/44
0%
0/10
1.6
 
 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.core.statement.ui.client.widgets.table;
 17  
 
 18  
 import com.google.gwt.user.client.ui.FlexTable;
 19  
 import com.google.gwt.user.client.ui.HTMLTable;
 20  
 import com.google.gwt.user.client.ui.Label;
 21  
 import com.google.gwt.user.client.ui.Widget;
 22  
 
 23  
 /**
 24  
  * This is a generic table for assembling non-sortable tables with sections
 25  
  *
 26  
  */
 27  
 
 28  
 public class SectionTable extends FlexTable {
 29  
 
 30  
     protected static final int HEADER_ROW = 0;
 31  
     protected static final int FIRST_DATA_ROW = 1;
 32  
     protected static final int FIRST_COLUMN = 0;
 33  
     protected static final int DATA_INDEX_ZERO = 0;
 34  
     protected static final int DEFAULT_TABLE_CELL_SPACING = 0;
 35  
 
 36  0
     private int nextRow =1 ;
 37  0
     private Object[][] rowData = null;
 38  
 
 39  
 
 40  
     public SectionTable(Object[][] rowData) {
 41  0
         this();
 42  0
         this.rowData = rowData;
 43  0
         createRows(DATA_INDEX_ZERO);
 44  
 
 45  0
     }
 46  
 
 47  
 
 48  0
     public SectionTable() {
 49  0
         insertRow(HEADER_ROW);
 50  0
         setCellSpacing(DEFAULT_TABLE_CELL_SPACING);
 51  0
         addStyleName("ks-table-container");
 52  0
         addStyleName("ks-table");
 53  0
         getRowFormatter().addStyleName(HEADER_ROW, "ks-table th");
 54  0
     }
 55  
 
 56  
     public void createRows(int rowIndex) {
 57  0
         if (rowData == null)
 58  0
             return;
 59  
 
 60  0
         for (int row = rowIndex; row < rowData.length; row++) {
 61  0
             addRow(rowData[row]);
 62  
         }
 63  0
     }
 64  
 
 65  
     public void addRow(Object[] cellObjects) {
 66  0
         for (int cell = FIRST_COLUMN; cell < cellObjects.length; cell++) {
 67  0
             addCell(nextRow, cell, cellObjects[cell]);
 68  
         }
 69  0
         nextRow++;
 70  0
     }
 71  
 
 72  
     public void addCell(int row, int cell, Object cellObject) {
 73  0
         Widget widget = createCellWidget(cellObject);
 74  0
         setWidget(row, cell, widget);
 75  
 
 76  
         // Removed until we know the styling formats
 77  
         // getCellFormatter().addStyleName(row, cell, cell == 0 ? "": "");
 78  
 
 79  0
     }
 80  
 
 81  
     /**
 82  
     *
 83  
     * Do some fancy formatting of rows
 84  
     * Nothing for now
 85  
     */
 86  
     public void applyDataRowStyles() {
 87  0
         HTMLTable.RowFormatter rf = getRowFormatter();
 88  
 
 89  0
     }
 90  
 
 91  
     public void addColumn(Object columnHeading) {
 92  0
         Widget widget = createCellWidget(columnHeading);
 93  0
         int columnIndex = getColumnCount();
 94  
 
 95  0
         widget.setWidth("100%");
 96  
         // widget.addStyleName("");
 97  
 
 98  0
         setWidget(HEADER_ROW, columnIndex, widget);
 99  
 
 100  
         // getCellFormatter().addStyleName(HEADER_ROW, columnIndex, "ks-table-th");
 101  
         // getRowFormatter().addStyleName(HEADER_ROW, "ks-table-th");
 102  
         // getCellFormatter().setStyleName(HEADER_ROW, columnIndex, "");
 103  
 
 104  0
     }
 105  
 
 106  
     public void addSection(Object sectionHeading) {
 107  
 
 108  0
         Object[] sectionRow = {sectionHeading};
 109  
 
 110  0
         for (int cell = FIRST_COLUMN+1; cell < getColumnCount(); cell++) {
 111  0
             addCell(nextRow, cell, "");
 112  
         }
 113  
 
 114  0
         addRow(sectionRow);
 115  
 
 116  
         // Style the row we just created
 117  0
         getRowFormatter().addStyleName(nextRow-1, "td-subhead");
 118  
 
 119  0
     }
 120  
 
 121  
 
 122  
     protected Widget createCellWidget(Object cellObject) {
 123  0
         Widget widget = null;
 124  
 
 125  0
         if (cellObject instanceof Widget)
 126  0
             widget = (Widget) cellObject;
 127  
         else
 128  0
             widget = new Label(cellObject.toString());
 129  
 
 130  
             // widget.setHorizontalAlignment(Label.ALIGN_CENTER);
 131  
 
 132  
 
 133  0
         return widget;
 134  
 
 135  
     }
 136  
 
 137  
     /**
 138  
     *
 139  
     * Returns the number of Coulmns in the Table
 140  
     */
 141  
     public int getColumnCount() {
 142  0
         return getCellCount(HEADER_ROW);
 143  
     }
 144  
 
 145  
 
 146  
 }