View Javadoc
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.TableRowRenderer;
26  import org.kuali.rice.kns.web.ui.Field;
27  
28  /**
29   * Represents a table row to display in an accounting view table.
30   */
31  public class AccountingLineTableRow implements RenderableElement {
32      private List<AccountingLineTableCell> cells;
33      private AccountingLineRenderingContext renderingContext;
34      
35      /**
36       * Constructs a AccountingLineTableRow
37       */
38      public AccountingLineTableRow() {
39          cells = new ArrayList<AccountingLineTableCell>();
40      }
41  
42      /**
43       * Gets the cells attribute. 
44       * @return Returns the cells.
45       */
46      public List<AccountingLineTableCell> getCells() {
47          return cells;
48      }
49  
50      /**
51       * Sets the cells attribute value.
52       * @param cells The cells to set.
53       */
54      public void setCells(List<AccountingLineTableCell> cells) {
55          this.cells = cells;
56      }
57      
58      /**
59       * Adds a new table cell to the row
60       * @param cell the cell to add to the row
61       */
62      public void addCell(AccountingLineTableCell cell) {
63          cells.add(cell);
64      }
65  
66      /**
67       * @see org.kuali.ole.sys.document.web.RenderableElement#isHidden()
68       */
69      public boolean isHidden() {
70          for (AccountingLineTableCell cell : cells) {
71              if (!cell.isHidden()) {
72                  return false;
73              }
74          }
75          return true;
76      }
77  
78      /**
79       * This is not an action block
80       * @see org.kuali.ole.sys.document.web.RenderableElement#isActionBlock()
81       */
82      public boolean isActionBlock() {
83          return false;
84      }
85  
86      /**
87       * @see org.kuali.ole.sys.document.web.RenderableElement#isEmpty()
88       */
89      public boolean isEmpty() {
90          for (AccountingLineTableCell cell : cells) {
91              if (!cell.isEmpty()) {
92                  return false;
93              }
94          }
95          return true;
96      }
97  
98      /**
99       * @see org.kuali.ole.sys.document.web.RenderableElement#renderElement(javax.servlet.jsp.PageContext, javax.servlet.jsp.tagext.Tag)
100      */
101     public void renderElement(PageContext pageContext, Tag parentTag, AccountingLineRenderingContext renderingContext) throws JspException {
102         TableRowRenderer renderer = new TableRowRenderer();
103         this.renderingContext = renderingContext;
104         renderer.setRow(this);
105         renderer.render(pageContext, parentTag);
106         renderer.clear();
107         this.renderingContext = null;
108     }
109     
110     /**
111      * Requests that the row renders all of its children cells
112      * @param pageContext the page contex to render to
113      * @param parentTag the tag requesting all this rendering
114      * @param accountingLine the accounting line to render
115      * @param accountingLineProperty the property from the form to the accounting line
116      * @throws JspException exception thrown when...something...goes, I don't know...wrong or somethin'
117      */
118     public void renderChildrenCells(PageContext pageContext, Tag parentTag) throws JspException {
119         for (AccountingLineTableCell cell : cells) {
120             cell.renderElement(pageContext, parentTag, renderingContext);
121         }
122     }
123     
124     /**
125      * Returns the number of children cells this row has
126      * @return the number of children cells this row has
127      */
128     public int getChildCellCount() {
129         return cells.size();
130     }
131     
132     /**
133      * @return returns the number of cells which will actually be rendered (ie, colspans are taken into account)
134      */
135     public int getChildRenderableCount() {
136         int count = 0;
137         for (AccountingLineTableCell cell : cells) {
138             count += cell.getColSpan();
139         }
140         return count;
141     }
142     
143     /**
144      * Dutifully appends the names of any fields it knows about to the given List of field names
145      * @param fieldNames a List of field names to append other names to
146      * 
147      * KRAD Conversion: Customization of the fields - No use of data dictionary
148      */
149     public void appendFields(List<Field> fields) {
150         for (AccountingLineTableCell cell : cells) {
151             cell.appendFields(fields);
152         }
153     }
154 
155     /**
156      * @see org.kuali.ole.sys.document.web.RenderableElement#populateWithTabIndexIfRequested(int[], int)
157      */
158     public void populateWithTabIndexIfRequested(int reallyHighIndex) {
159         for (AccountingLineTableCell cell : cells) {
160             cell.populateWithTabIndexIfRequested(reallyHighIndex);
161         }
162     }
163     
164     /**
165      * Determines whether each cell is safe to remove; if so, simply removes that cell
166      * @return true if the row can be safely removed; false otherwise
167      */
168     public boolean safeToRemove() {
169         for (AccountingLineTableCell cell : cells) {
170             if (!cell.safeToRemove()) return false;
171         }
172         return true;
173     }
174 }