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.renderers;
17  
18  import java.io.IOException;
19  
20  import javax.servlet.jsp.JspException;
21  import javax.servlet.jsp.JspWriter;
22  import javax.servlet.jsp.PageContext;
23  import javax.servlet.jsp.tagext.Tag;
24  
25  import org.apache.commons.lang.StringUtils;
26  import org.apache.struts.taglib.html.HiddenTag;
27  import org.kuali.ole.sys.context.SpringContext;
28  import org.kuali.rice.core.api.config.property.ConfigurationService;
29  import org.kuali.rice.kns.web.taglib.html.KNSImageTag;
30  
31  /**
32   * Renders the header of an accounting line table
33   */
34  public class AccountingLineTableHeaderRenderer implements Renderer {
35      private int cellCount;
36      private boolean hideDetails;
37      private String accountingLineImportInstructionsUrl;
38      private KNSImageTag showHideTag = new KNSImageTag();
39      private HiddenTag hideStateTag = new HiddenTag();
40      
41      /**
42       * Constructs a AccountingLineTableHeaderRenderer, updating the tags used by this renderer to keep constant properties
43       */
44      public AccountingLineTableHeaderRenderer() {
45          hideStateTag.setName("KualiForm");
46          hideStateTag.setProperty("hideDetails");
47          
48          showHideTag.setStyleClass("tinybutton");
49      }
50  
51      /**
52       * Clears out the mutable, changing qualities of this renderer so it can be repooled
53       */
54      public void clear() {
55          cellCount = 0;
56          hideDetails = false;
57          accountingLineImportInstructionsUrl = null;
58          
59          showHideTag.setPageContext(null);
60          showHideTag.setParent(null);
61          showHideTag.setProperty(null);
62          showHideTag.setAlt(null);
63          showHideTag.setTitle(null);
64          showHideTag.setSrc(null);
65          
66          hideStateTag.setPageContext(null);
67          hideStateTag.setParent(null);
68      }
69  
70      /**
71       * Renders the header for the accounting line table to the screen
72       * @see org.kuali.ole.sys.document.web.renderers.Renderer#render(javax.servlet.jsp.PageContext, javax.servlet.jsp.tagext.Tag)
73       */
74      public void render(PageContext pageContext, Tag parentTag) throws JspException {
75          JspWriter out = pageContext.getOut();
76          
77          try {
78              out.write(buildDivStart());
79              out.write(buildTableStart());
80              out.write(buildSubheadingWithDetailToggleRowBeginning());
81              renderHideDetails(pageContext, parentTag);
82              out.write(buildSubheadingWithDetailToggleRowEnding());
83          }
84          catch (IOException ioe) {
85              throw new JspException("Difficulty rendering AccountingLineTableHeader", ioe);
86          }
87      }
88      
89      /**
90       * Builds the beginning of the tab-container div
91       * @return the beginning of the tab-container div in HTML
92       */
93      protected String buildDivStart() {
94          return "<div class=\"tab-container\" align=\"center\">\n";
95      }
96  
97      /**
98       * Builds the very start of the table
99       * @return the very start of the table expressed as HTML
100      */
101     protected String buildTableStart() {
102         return "<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" class=\"datatable\">\n";
103     }
104     
105     /**
106      * Builds the start of the subheading row of the table
107      * @return the start of the subheading row of the table expressed as HTML
108      */
109     protected String buildSubheadingWithDetailToggleRowBeginning() {
110         StringBuilder row = new StringBuilder();
111         row.append("\t<tr>\n");
112         row.append("\t\t<td colspan=\"");
113         row.append(cellCount);
114         row.append("\" class=\"subhead\">\n");
115         row.append("\t\t\t<span class=\"subhead-left\">");
116         row.append(buildSubHeading());
117         row.append("</span>\n");
118         row.append("\t\t\t<span class=\"subhead-right\">\n");
119         
120         return row.toString();
121     }
122     
123     /**
124      * Builds the subheading for the table
125      * @return the subheading for the table, expressed as HTML
126      */
127     protected String buildSubHeading() {
128         if (StringUtils.isBlank(accountingLineImportInstructionsUrl)) return "&nbsp;";
129         
130         StringBuilder subheading = new StringBuilder();
131 
132         subheading.append("Accounting Lines <a href=\"");
133         subheading.append(accountingLineImportInstructionsUrl);
134         subheading.append("\" target=\"helpWindow\">");
135         subheading.append("<img src=\"");
136         subheading.append(SpringContext.getBean(ConfigurationService.class).getPropertyValueAsString("kr.externalizable.images.url"));
137         subheading.append("my_cp_inf.gif\" title=\"Accounting Lines Help\" alt=\"Accounting Lines Help\" hspace=\"5\" border=\"0\" align=\"middle\" />");
138         subheading.append("</a>");
139         
140         return subheading.toString();
141     }
142     
143     /**
144      * Renders the show/hide button  
145      * @param pageContext the page context to render to
146      * @param parentTag the tag requesting all this rendering
147      * @throws JspException thrown under terrible circumstances when the rendering failed and had to be left behind like so much refuse
148      */
149     protected void renderHideDetails(PageContext pageContext, Tag parentTag) throws JspException {
150         hideStateTag.setPageContext(pageContext);
151         hideStateTag.setParent(parentTag);
152 
153         hideStateTag.doStartTag();
154         hideStateTag.doEndTag();
155         
156         String toggle = hideDetails ? "show" : "hide";
157         
158         showHideTag.setPageContext(pageContext);
159         showHideTag.setParent(parentTag);
160         showHideTag.setProperty("methodToCall."+toggle+"Details");
161         showHideTag.setSrc(SpringContext.getBean(ConfigurationService.class).getPropertyValueAsString("kr.externalizable.images.url")+"det-"+toggle+".gif");
162         showHideTag.setAlt(toggle+" transaction details");
163         showHideTag.setTitle(toggle+" transaction details");
164         
165         showHideTag.doStartTag();
166         showHideTag.doEndTag();
167     }
168     
169     /**
170      * Builds the ending of the toggle row
171      * @return the ending of the toggle row expressed as HTML
172      */
173     protected String buildSubheadingWithDetailToggleRowEnding() {
174         StringBuilder row = new StringBuilder();
175         row.append("\t\t\t</span>\n");
176         row.append("\t\t</td>\n");
177         row.append("\t</tr>\n");
178         return row.toString();
179     }
180 
181     /**
182      * Gets the accountingLineImportInstructionsUrl attribute. 
183      * @return Returns the accountingLineImportInstructionsUrl.
184      */
185     public String getAccountingLineImportInstructionsUrl() {
186         return accountingLineImportInstructionsUrl;
187     }
188 
189     /**
190      * Sets the accountingLineImportInstructionsUrl attribute value.
191      * @param accountingLineImportInstructionsUrl The accountingLineImportInstructionsUrl to set.
192      */
193     public void setAccountingLineImportInstructionsUrl(String accountingLineImportInstructionsUrl) {
194         this.accountingLineImportInstructionsUrl = accountingLineImportInstructionsUrl;
195     }
196 
197     /**
198      * Gets the cellCount attribute. 
199      * @return Returns the cellCount.
200      */
201     public int getCellCount() {
202         return cellCount;
203     }
204 
205     /**
206      * Sets the cellCount attribute value.
207      * @param cellCount The cellCount to set.
208      */
209     public void setCellCount(int cellCount) {
210         this.cellCount = cellCount;
211     }
212 
213     /**
214      * Gets the hideDetails attribute. 
215      * @return Returns the hideDetails.
216      */
217     public boolean getHideDetails() {
218         return hideDetails;
219     }
220 
221     /**
222      * Sets the hideDetails attribute value.
223      * @param hideDetails The hideDetails to set.
224      */
225     public void setHideDetails(boolean hideDetails) {
226         this.hideDetails = hideDetails;
227     }
228 }