View Javadoc

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 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      private int nextRow =1 ;
37      private Object[][] rowData = null;
38  
39  
40      public SectionTable(Object[][] rowData) {
41          this();
42          this.rowData = rowData;
43          createRows(DATA_INDEX_ZERO);
44  
45      }
46  
47  
48      public SectionTable() {
49          insertRow(HEADER_ROW);
50          setCellSpacing(DEFAULT_TABLE_CELL_SPACING);
51          addStyleName("ks-table-container");
52          addStyleName("ks-table");
53          getRowFormatter().addStyleName(HEADER_ROW, "ks-table th");
54      }
55  
56      public void createRows(int rowIndex) {
57          if (rowData == null)
58              return;
59  
60          for (int row = rowIndex; row < rowData.length; row++) {
61              addRow(rowData[row]);
62          }
63      }
64  
65      public void addRow(Object[] cellObjects) {
66          for (int cell = FIRST_COLUMN; cell < cellObjects.length; cell++) {
67              addCell(nextRow, cell, cellObjects[cell]);
68          }
69          nextRow++;
70      }
71  
72      public void addCell(int row, int cell, Object cellObject) {
73          Widget widget = createCellWidget(cellObject);
74          setWidget(row, cell, widget);
75  
76          // Removed until we know the styling formats
77          // getCellFormatter().addStyleName(row, cell, cell == 0 ? "": "");
78  
79      }
80  
81      /**
82      *
83      * Do some fancy formatting of rows
84      * Nothing for now
85      */
86      public void applyDataRowStyles() {
87          HTMLTable.RowFormatter rf = getRowFormatter();
88  
89      }
90  
91      public void addColumn(Object columnHeading) {
92          Widget widget = createCellWidget(columnHeading);
93          int columnIndex = getColumnCount();
94  
95          widget.setWidth("100%");
96          // widget.addStyleName("");
97  
98          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     }
105 
106     public void addSection(Object sectionHeading) {
107 
108         Object[] sectionRow = {sectionHeading};
109 
110         for (int cell = FIRST_COLUMN+1; cell < getColumnCount(); cell++) {
111             addCell(nextRow, cell, "");
112         }
113 
114         addRow(sectionRow);
115 
116         // Style the row we just created
117         getRowFormatter().addStyleName(nextRow-1, "td-subhead");
118 
119     }
120 
121 
122     protected Widget createCellWidget(Object cellObject) {
123         Widget widget = null;
124 
125         if (cellObject instanceof Widget)
126             widget = (Widget) cellObject;
127         else
128             widget = new Label(cellObject.toString());
129 
130             // widget.setHorizontalAlignment(Label.ALIGN_CENTER);
131 
132 
133         return widget;
134 
135     }
136 
137     /**
138     *
139     * Returns the number of Coulmns in the Table
140     */
141     public int getColumnCount() {
142         return getCellCount(HEADER_ROW);
143     }
144 
145 
146 }