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;
20  
21  import java.util.List;
22  
23  import javax.servlet.jsp.JspException;
24  import javax.servlet.jsp.PageContext;
25  import javax.servlet.jsp.tagext.Tag;
26  
27  import org.kuali.kfs.sys.KFSConstants;
28  import org.kuali.kfs.sys.KFSKeyConstants;
29  import org.kuali.kfs.sys.context.SpringContext;
30  import org.kuali.kfs.sys.document.web.renderers.ActionsRenderer;
31  import org.kuali.rice.core.api.config.property.ConfigurationService;
32  import org.kuali.rice.kns.web.ui.Field;
33  
34  /**
35   * A field that can join tables and also be rendered, this represents a table cell
36   * that displays the actions available on an accounting line
37   */
38  public class AccountingLineViewActionsField extends FieldTableJoiningWithHeader {
39      private String name = KFSConstants.AccountingLineViewStandardBlockNames.ACTION_BLOCK;
40  
41      /**
42       * Returns the name of this actions field
43       * @see org.kuali.kfs.sys.document.web.TableJoining#getName()
44       */
45      public String getName() {
46          return name;
47      }
48      
49      /**
50       * Sets the name of this actions field
51       * @param name the name of this block
52       */
53      public void setName(String name) {
54          this.name = name;
55      }
56  
57      /**
58       * We are an action block.  For real, even
59       * @see org.kuali.kfs.sys.document.web.FieldTableJoining#isActionBlock()
60       */
61      @Override
62      public boolean isActionBlock() {
63          return true;
64      }
65  
66      /**
67       * @see org.kuali.kfs.sys.document.web.FieldTableJoiningWithHeader#joinTable(java.util.List)
68       */
69      @Override
70      public void joinTable(List<AccountingLineTableRow> rows) {
71          // 1. add header cell
72          AccountingLineTableCell headerCell = createHeaderLabelTableCell();
73          rows.get(0).addCell(headerCell);
74  
75          // 2. add blank cell to make sure this cell shows up on the bottom line
76          final int blankCellRowSpan = rows.size() - 2;
77          if (blankCellRowSpan > 0) {
78              AccountingLineTableCell blankCell = createBlankTableCell(blankCellRowSpan);
79              rows.get(1).addCell(blankCell);
80          }
81          // 3. add field cell
82          AccountingLineTableCell cell = createTableCell();
83          rows.get((rows.size()-1)).addCell(cell);
84      }
85      
86      /**
87       * Builds a blank cell for the action so the actions always appear below that
88       * @param rowSpan the row span of the blank cell
89       * @return the blank row-spanning table cell
90       */
91      protected AccountingLineTableCell createBlankTableCell(int rowSpan) {
92          AccountingLineTableCell blankCell = new AccountingLineTableCell();
93          blankCell.setNeverEmpty(true);
94          blankCell.setExtraStyle("border-bottom-style: none;");
95          if (rowSpan > 1) {
96              blankCell.setRowSpan(rowSpan);
97          }
98          return blankCell;
99      }
100 
101     /**
102      * @see org.kuali.kfs.sys.document.web.RenderableElement#renderElement(javax.servlet.jsp.PageContext, javax.servlet.jsp.tagext.Tag)
103      */
104     public void renderElement(PageContext pageContext, Tag parentTag, AccountingLineRenderingContext renderingContext) throws JspException {
105         ActionsRenderer renderer = new ActionsRenderer();
106         renderer.setActions(renderingContext.getActionsForLine());
107         renderer.render(pageContext, parentTag);
108         renderer.clear();
109     }
110 
111     /**
112      * @see org.kuali.kfs.sys.document.web.TableJoiningWithHeader#createHeaderLabel()
113      */
114     public HeaderLabel createHeaderLabel() {
115         return new LiteralHeaderLabel(SpringContext.getBean(ConfigurationService.class).getPropertyValueAsString(KFSKeyConstants.AccountingLineViewRendering.ACCOUNTING_LINE_ACTIONS_LABEL));
116     }
117 
118     /**
119      * This doesn't hold a field, so this implementation does nothing
120      * @see org.kuali.kfs.sys.document.web.RenderableElement#appendFieldNames(java.util.List)
121      * 
122      * KRAD Conversion: Customization of the fields - No use of data dictionary
123      */
124     public void appendFields(List<Field> fields) { }
125 
126     /**
127      * Doesn't do anything
128      * @see org.kuali.kfs.sys.document.web.RenderableElement#populateWithTabIndexIfRequested(int[], int)
129      */
130     public void populateWithTabIndexIfRequested(int reallyHighIndex) {}
131     
132 }