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.TableCellRenderer;
26  import org.kuali.ole.sys.document.web.renderers.TableHeaderRenderer;
27  import org.kuali.rice.kns.web.ui.Field;
28  
29  /**
30   * A class which represents a number of fields held in a table cell.
31   */
32  public class AccountingLineTableCell implements RenderableElement {
33      private int rowSpan = 1;
34      private int colSpan = 1;
35      private List<RenderableElement> renderableElements = new ArrayList<RenderableElement>();
36      private boolean rendersAsHeader = false;
37      private AccountingLineRenderingContext renderingContext;
38      private boolean neverEmpty;
39      private String extraStyle;
40      private String styleClassOverride;
41      
42      /**
43       * Gets the colSpan attribute. 
44       * @return Returns the colSpan.
45       */
46      public int getColSpan() {
47          return colSpan;
48      }
49      /**
50       * Sets the colSpan attribute value.
51       * @param colSpan The colSpan to set.
52       */
53      public void setColSpan(int colSpan) {
54          if (colSpan > 1) {
55              this.colSpan = colSpan;
56          }
57      }
58  
59      /**
60       * Gets the rowSpan attribute. 
61       * @return Returns the rowSpan.
62       */
63      public int getRowSpan() {
64          return rowSpan;
65      }
66      /**
67       * Sets the rowSpan attribute value.
68       * @param rowSpan The rowSpan to set.
69       */
70      public void setRowSpan(int rowSpan) {
71          if (rowSpan > 1) {
72              this.rowSpan = rowSpan;
73          }
74      }
75      
76      /**
77       * Gets the renderableElement attribute. 
78       * @return Returns the renderableElement.
79       */
80      public List<RenderableElement> getRenderableElement() {
81          return renderableElements;
82      }
83      
84      /**
85       * Sets the renderableElement attribute value.
86       * @param renderableElement The renderableElement to set.
87       */
88      public void setRenderableElement(List<RenderableElement> renderableElement) {
89          this.renderableElements = renderableElement;
90      }
91      
92      /**
93       * Adds a renderable element to the elements this cell can render
94       * @param element another element to render within this cell
95       */
96      public void addRenderableElement(RenderableElement element) {
97          renderableElements.add(element);
98      }
99      
100     /**
101      * @see org.kuali.ole.sys.document.web.RenderableElement#isHidden()
102      */
103     public boolean isHidden() {
104         for (RenderableElement element : renderableElements) {
105             if (!element.isHidden()) {
106                 return false;
107             }
108         }
109         return true;
110     }
111     
112     /**
113      * This is not an action block
114      * @see org.kuali.ole.sys.document.web.RenderableElement#isActionBlock()
115      */
116     public boolean isActionBlock() {
117         return false;
118     }
119     
120     /**
121      * @see org.kuali.ole.sys.document.web.RenderableElement#isEmpty()
122      */
123     public boolean isEmpty() {
124         if (neverEmpty) return false;
125         for (RenderableElement element : renderableElements) {
126             if (!element.isEmpty()) {
127                 return false;
128             }
129         }
130         return true;
131     }
132     
133     /**
134      * Gets the rendersAsHeader attribute. 
135      * @return Returns the rendersAsHeader.
136      */
137     public boolean isRendersAsHeader() {
138         return rendersAsHeader;
139     }
140     /**
141      * Sets the rendersAsHeader attribute value.
142      * @param rendersAsHeader The rendersAsHeader to set.
143      */
144     public void setRendersAsHeader(boolean rendersAsHeader) {
145         this.rendersAsHeader = rendersAsHeader;
146     }
147     
148     /**
149      * Gets the extraStyle attribute. 
150      * @return Returns the extraStyle.
151      */
152     public String getExtraStyle() {
153         return extraStyle;
154     }
155     /**
156      * Sets the extraStyle attribute value.
157      * @param extraStyle The extraStyle to set.
158      */
159     public void setExtraStyle(String extraStyle) {
160         this.extraStyle = extraStyle;
161     }
162     
163     /**
164      * Gets the neverEmpty attribute. 
165      * @return Returns the neverEmpty.
166      */
167     public boolean isNeverEmpty() {
168         return neverEmpty;
169     }
170     /**
171      * Sets the neverEmpty attribute value.
172      * @param neverEmpty The neverEmpty to set.
173      */
174     public void setNeverEmpty(boolean neverEmpty) {
175         this.neverEmpty = neverEmpty;
176     }
177     
178     /**
179      * Gets the styleClassOverride attribute. 
180      * @return Returns the styleClassOverride.
181      */
182     public String getStyleClassOverride() {
183         return styleClassOverride;
184     }
185     /**
186      * Sets the styleClassOverride attribute value.
187      * @param styleClassOverride The styleClassOverride to set.
188      */
189     public void setStyleClassOverride(String styleClassOverride) {
190         this.styleClassOverride = styleClassOverride;
191     }
192     /**
193      * @see org.kuali.ole.sys.document.web.RenderableElement#renderElement(javax.servlet.jsp.PageContext, javax.servlet.jsp.tagext.Tag)
194      */
195     public void renderElement(PageContext pageContext, Tag parentTag, AccountingLineRenderingContext renderingContext) throws JspException {
196         TableCellRenderer renderer;
197         if (isRendersAsHeader()) {
198             renderer = new TableHeaderRenderer();
199         } else {
200             renderer = new TableCellRenderer();
201         }
202         this.renderingContext = renderingContext;
203         renderer.setCell(this);
204         renderer.render(pageContext, parentTag);
205         renderer.clear();
206         this.renderingContext = null;
207     }
208     
209     /**
210      * Requests that this cell render all of its children cells
211      * @param pageContext the page context of the rendering
212      * @param parentTag the parent tag requesting all this rendering
213      * @param accountingLine the accounting line getting rendered
214      * @param accountingLineProperty the property to get from the form to the accounting line
215      * @throws JspException Oh.  Shoot.  Something went...wrong.
216      */
217     public void renderChildrenElements(PageContext pageContext, Tag parentTag) throws JspException {
218         for (RenderableElement element : renderableElements) {
219             element.renderElement(pageContext, parentTag, renderingContext);
220         }
221     }
222     
223     /**
224      * Determines if this cell has child elements
225      * @return True if this cell has child elements, false otherwise
226      */
227     public boolean hasChildElements() {
228         return renderableElements != null && renderableElements.size() > 0;
229     }
230     
231     /**
232      * Goes through fields, appending field names
233      * @see org.kuali.ole.sys.document.web.RenderableElement#appendFieldNames(java.util.List)
234      * 
235      * KRAD Conversion: Customization of the fields - No use of data dictionary
236      */
237     public void appendFields(List<Field> fields) {
238         for (RenderableElement element : renderableElements) {
239             element.appendFields(fields);
240         }
241     }
242     
243     /**
244      * @see org.kuali.ole.sys.document.web.RenderableElement#populateWithTabIndexIfRequested(int[], int)
245      */
246     public void populateWithTabIndexIfRequested(int reallyHighIndex) {
247         for (RenderableElement element : renderableElements) {
248             element.populateWithTabIndexIfRequested(reallyHighIndex);
249         }
250     }
251     
252     /**
253      * Determines if this field is safe to remove. If any child elements are instances of FieldTableJoining, then it assumes not
254      * @return true if this cell is safe to remove; false otherwise
255      */
256     public boolean safeToRemove() {
257         for (RenderableElement element : renderableElements) {
258             if (element instanceof FieldTableJoining) return false;
259         }
260         return true;
261     }
262 }