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.ArrayList;
19 import java.util.List;
20
21 import javax.servlet.jsp.JspException;
22 import javax.servlet.jsp.PageContext;
23 import javax.servlet.jsp.tagext.Tag;
24
25 import org.kuali.ole.sys.document.web.renderers.TableRenderer;
26 import org.kuali.rice.kns.web.ui.Field;
27
28 /**
29 * An inner table inside a table cell.
30 */
31 public class AccountingLineTable implements RenderableElement {
32 private List<AccountingLineTableRow> rows;
33 private AccountingLineRenderingContext renderingContext;
34
35 /**
36 * Gets the rows attribute.
37 * @return Returns the rows.
38 */
39 public List<AccountingLineTableRow> getRows() {
40 return rows;
41 }
42
43 /**
44 * Sets the rows attribute value.
45 * @param rows The rows to set.
46 */
47 public void setRows(List<AccountingLineTableRow> rows) {
48 this.rows = rows;
49 }
50
51 /**
52 * @see org.kuali.ole.sys.document.web.RenderableElement#isHidden()
53 */
54 public boolean isHidden() {
55 for(AccountingLineTableRow row : rows) {
56 if (!row.isHidden()) {
57 return false;
58 }
59 }
60 return true;
61 }
62
63 /**
64 * This is not an action block
65 * @see org.kuali.ole.sys.document.web.RenderableElement#isActionBlock()
66 */
67 public boolean isActionBlock() {
68 return false;
69 }
70
71 /**
72 * Determines if this table is empty of any renderable elements
73 * @return true if this is empty, false otherwise
74 */
75 public boolean isEmpty() {
76 for (AccountingLineTableRow row : rows) {
77 if (!row.isEmpty()) {
78 return false;
79 }
80 }
81 return true;
82 }
83
84 /**
85 * @see org.kuali.ole.sys.document.web.RenderableElement#renderElement(javax.servlet.jsp.PageContext, javax.servlet.jsp.tagext.Tag)
86 */
87 public void renderElement(PageContext pageContext, Tag parentTag, AccountingLineRenderingContext renderingContext) throws JspException {
88 TableRenderer renderer = new TableRenderer();
89 this.renderingContext = renderingContext;
90 renderer.setTable(this);
91 renderer.render(pageContext, parentTag);
92 renderer.clear();
93 this.renderingContext = null;
94 }
95
96 /**
97 * Requests that this table render all of its children rows
98 * @param pageContext the page context to render to
99 * @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.ole.sys.document.web.RenderableElement#appendFieldNames(java.util.List)
112 *
113 * KRAD Conversion: Customization of the fields - No use of data dictionary
114 */
115 public void appendFields(List<Field> fields) {
116 for (AccountingLineTableRow row : rows) {
117 row.appendFields(fields);
118 }
119 }
120
121 /**
122 * @see org.kuali.ole.sys.document.web.RenderableElement#populateWithTabIndexIfRequested(int[], int)
123 */
124 public void populateWithTabIndexIfRequested(int reallyHighIndex) {
125 for (AccountingLineTableRow row : rows) {
126 row.populateWithTabIndexIfRequested(reallyHighIndex);
127 }
128 }
129
130 /**
131 * Adds a row to the bottom of this table's list of rows
132 * @param row the row to add
133 */
134 public void addRow(AccountingLineTableRow row) {
135 if (rows == null) {
136 rows = new ArrayList<AccountingLineTableRow>();
137 }
138 rows.add(row);
139 }
140 }