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