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.ArrayList;
019 import java.util.List;
020
021 import javax.servlet.jsp.JspException;
022 import javax.servlet.jsp.PageContext;
023 import javax.servlet.jsp.tagext.Tag;
024
025 import org.kuali.kfs.sys.document.web.renderers.TableRenderer;
026 import org.kuali.rice.kns.web.ui.Field;
027
028 /**
029 * An inner table inside a table cell.
030 */
031 public class AccountingLineTable implements RenderableElement {
032 private List<AccountingLineTableRow> rows;
033 private AccountingLineRenderingContext renderingContext;
034
035 /**
036 * Gets the rows attribute.
037 * @return Returns the rows.
038 */
039 public List<AccountingLineTableRow> getRows() {
040 return rows;
041 }
042
043 /**
044 * Sets the rows attribute value.
045 * @param rows The rows to set.
046 */
047 public void setRows(List<AccountingLineTableRow> rows) {
048 this.rows = rows;
049 }
050
051 /**
052 * @see org.kuali.kfs.sys.document.web.RenderableElement#isHidden()
053 */
054 public boolean isHidden() {
055 for(AccountingLineTableRow row : rows) {
056 if (!row.isHidden()) {
057 return false;
058 }
059 }
060 return true;
061 }
062
063 /**
064 * This is not an action block
065 * @see org.kuali.kfs.sys.document.web.RenderableElement#isActionBlock()
066 */
067 public boolean isActionBlock() {
068 return false;
069 }
070
071 /**
072 * Determines if this table is empty of any renderable elements
073 * @return true if this is empty, false otherwise
074 */
075 public boolean isEmpty() {
076 for (AccountingLineTableRow row : rows) {
077 if (!row.isEmpty()) {
078 return false;
079 }
080 }
081 return true;
082 }
083
084 /**
085 * @see org.kuali.kfs.sys.document.web.RenderableElement#renderElement(javax.servlet.jsp.PageContext, javax.servlet.jsp.tagext.Tag)
086 */
087 public void renderElement(PageContext pageContext, Tag parentTag, AccountingLineRenderingContext renderingContext) throws JspException {
088 TableRenderer renderer = new TableRenderer();
089 this.renderingContext = renderingContext;
090 renderer.setTable(this);
091 renderer.render(pageContext, parentTag);
092 renderer.clear();
093 this.renderingContext = null;
094 }
095
096 /**
097 * Requests that this table render all of its children rows
098 * @param pageContext the page context to render to
099 * @param parentTag the parent tag requesting the rendering
100 * @param accountingLine accounting line getting rendered
101 * @param accountingLineProperty property to the accounting line
102 * @throws JspException thrown when some sort of thing goes wrong
103 */
104 public void renderChildrenRows(PageContext pageContext, Tag parentTag) throws JspException {
105 for (AccountingLineTableRow row : rows) {
106 row.renderElement(pageContext, parentTag, renderingContext);
107 }
108 }
109
110 /**
111 * @see org.kuali.kfs.sys.document.web.RenderableElement#appendFieldNames(java.util.List)
112 */
113 public void appendFields(List<Field> fields) {
114 for (AccountingLineTableRow row : rows) {
115 row.appendFields(fields);
116 }
117 }
118
119 /**
120 * @see org.kuali.kfs.sys.document.web.RenderableElement#populateWithTabIndexIfRequested(int[], int)
121 */
122 public void populateWithTabIndexIfRequested(int reallyHighIndex) {
123 for (AccountingLineTableRow row : rows) {
124 row.populateWithTabIndexIfRequested(reallyHighIndex);
125 }
126 }
127
128 /**
129 * Adds a row to the bottom of this table's list of rows
130 * @param row the row to add
131 */
132 public void addRow(AccountingLineTableRow row) {
133 if (rows == null) {
134 rows = new ArrayList<AccountingLineTableRow>();
135 }
136 rows.add(row);
137 }
138 }