1 /* 2 * Copyright 2008 The Kuali Foundation 3 * 4 * Licensed under the Educational Community License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.opensource.org/licenses/ecl2.php 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package org.kuali.ole.sys.document.web; 17 18 import java.util.List; 19 20 /** 21 * Extension of FieldTableJoining that adds header cells correctly 22 */ 23 public abstract class FieldTableJoiningWithHeader extends FieldTableJoining implements TableJoiningWithHeader { 24 25 /** 26 * @see org.kuali.ole.sys.document.web.FieldTableJoining#joinTable(java.util.List) 27 */ 28 @Override 29 public void joinTable(List<AccountingLineTableRow> rows) { 30 int rowsTaken = 0; 31 // 1. add header cell 32 if (!isHidden()) { 33 AccountingLineTableCell headerCell = createHeaderLabelTableCell(); 34 rows.get(0).addCell(headerCell); 35 rowsTaken += 1; 36 } 37 // 2. add field cell 38 AccountingLineTableCell cell = createTableCell(); 39 cell.setRowSpan(rows.size() - rowsTaken); 40 rows.get(rowsTaken).addCell(cell); 41 } 42 43 /** 44 * Creates a header label cell for this element 45 * @return a table cell holding the header label to render 46 */ 47 protected AccountingLineTableCell createHeaderLabelTableCell() { 48 AccountingLineTableCell cell = new AccountingLineTableCell(); 49 cell.addRenderableElement(createHeaderLabel()); 50 cell.setRendersAsHeader(true); 51 return cell; 52 } 53 54 /** 55 * This joins a row but adds a header to the header label row 56 * @see org.kuali.ole.sys.document.web.TableJoining#joinRow(org.kuali.ole.sys.document.web.AccountingLineTableRow, org.kuali.ole.sys.document.web.AccountingLineTableRow) 57 */ 58 public void joinRow(AccountingLineTableRow headerLabelRow, AccountingLineTableRow row) { 59 if (!isHidden()) { 60 headerLabelRow.addCell(createHeaderLabelTableCell()); 61 } 62 row.addCell(createTableCell()); 63 } 64 65 /** 66 * Always returns 2 - one row for the header, one for the row 67 * @see org.kuali.ole.sys.document.web.FieldTableJoining#getRequestedRowCount() 68 */ 69 @Override 70 public int getRequestedRowCount() { 71 return 2; 72 } 73 74 }