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