001 /* 002 * Copyright 2011 The Kuali Foundation. 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 package org.kuali.kfs.sys.document.web; 017 018 import java.util.List; 019 020 /** 021 * Extension of FieldTableJoining that adds header cells correctly 022 */ 023 public abstract class FieldTableJoiningWithHeader extends FieldTableJoining implements TableJoiningWithHeader { 024 025 /** 026 * @see org.kuali.kfs.sys.document.web.FieldTableJoining#joinTable(java.util.List) 027 */ 028 @Override 029 public void joinTable(List<AccountingLineTableRow> rows) { 030 int rowsTaken = 0; 031 // 1. add header cell 032 if (!isHidden()) { 033 AccountingLineTableCell headerCell = createHeaderLabelTableCell(); 034 rows.get(0).addCell(headerCell); 035 rowsTaken += 1; 036 } 037 // 2. add field cell 038 AccountingLineTableCell cell = createTableCell(); 039 cell.setRowSpan(rows.size() - rowsTaken); 040 rows.get(rowsTaken).addCell(cell); 041 } 042 043 /** 044 * Creates a header label cell for this element 045 * @return a table cell holding the header label to render 046 */ 047 protected AccountingLineTableCell createHeaderLabelTableCell() { 048 AccountingLineTableCell cell = new AccountingLineTableCell(); 049 cell.addRenderableElement(createHeaderLabel()); 050 cell.setRendersAsHeader(true); 051 return cell; 052 } 053 054 /** 055 * This joins a row but adds a header to the header label row 056 * @see org.kuali.kfs.sys.document.web.TableJoining#joinRow(org.kuali.kfs.sys.document.web.AccountingLineTableRow, org.kuali.kfs.sys.document.web.AccountingLineTableRow) 057 */ 058 public void joinRow(AccountingLineTableRow headerLabelRow, AccountingLineTableRow row) { 059 if (!isHidden()) { 060 headerLabelRow.addCell(createHeaderLabelTableCell()); 061 } 062 row.addCell(createTableCell()); 063 } 064 065 /** 066 * Always returns 2 - one row for the header, one for the row 067 * @see org.kuali.kfs.sys.document.web.FieldTableJoining#getRequestedRowCount() 068 */ 069 @Override 070 public int getRequestedRowCount() { 071 return 2; 072 } 073 074 }