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 import java.util.Map;
23 import java.util.Set;
24
25 import org.kuali.kfs.sys.businessobject.AccountingLine;
26 import org.kuali.kfs.sys.document.service.AccountingLineFieldRenderingTransformation;
27
28 /**
29 * Abstract class which contains functionality of table joining layout elements that will eventually render fields
30 */
31 public abstract class FieldTableJoining implements TableJoining, RenderableElement {
32
33 /**
34 * Always returns 1 - any field can live within 1 row.
35 * @see org.kuali.kfs.sys.document.web.AccountingLineViewRenderableElement#getRequestedRowCount()
36 */
37 public int getRequestedRowCount() {
38 return 1;
39 }
40
41 /**
42 * Creates a table cell that encapsulates this field
43 * @return the created table cell
44 */
45 protected AccountingLineTableCell createTableCell() {
46 AccountingLineTableCell cell = new AccountingLineTableCell();
47 cell.addRenderableElement(this);
48 return cell;
49 }
50
51 /**
52 * @see org.kuali.kfs.sys.document.web.AccountingLineViewRenderableElement#joinTable(java.util.List)
53 */
54 public void joinTable(List<AccountingLineTableRow> rows) {
55 AccountingLineTableCell cell = createTableCell();
56 cell.setRowSpan(rows.size());
57 rows.get(0).addCell(cell);
58 }
59
60 /**
61 * @see org.kuali.kfs.sys.document.web.TableJoining#removeAllActionBlocks()
62 */
63 public void removeAllActionBlocks() {
64 // do nothing - fields don't really have child action blocks (and action blocks which
65 // extend this method can't really do much of anything)
66 }
67
68 /**
69 * Default: assumes the field is not hidden
70 * @see org.kuali.kfs.sys.document.web.RenderableElement#isHidden()
71 */
72 public boolean isHidden() {
73 return false;
74 }
75
76 /**
77 * We're going to go out on a limb and bet that this isn't an action block
78 * @see org.kuali.kfs.sys.document.web.RenderableElement#isActionBlock()
79 */
80 public boolean isActionBlock() {
81 return false;
82 }
83
84 /**
85 * Joins ths field to the header row, spans the regular row
86 * @see org.kuali.kfs.sys.document.web.TableJoining#joinRow(org.kuali.kfs.sys.document.web.AccountingLineTableRow, org.kuali.kfs.sys.document.web.AccountingLineTableRow)
87 */
88 public void joinRow(AccountingLineTableRow headerLabelRow, AccountingLineTableRow row) {
89 AccountingLineTableCell cell = createTableCell();
90 cell.setRowSpan(2);
91 headerLabelRow.addCell(cell);
92 }
93
94 /**
95 * This is a field. It's never empty.
96 * @see org.kuali.kfs.sys.document.web.RenderableElement#isEmpty()
97 */
98 public boolean isEmpty() {
99 return false;
100 }
101
102 /**
103 * This method really doesn't do much - it assumes there are no child fields to remove
104 * @see org.kuali.kfs.sys.document.web.TableJoining#removeUnviewableBlocks()
105 */
106 public void removeUnviewableBlocks(Set<String> unviewableBlocks) {
107 // take a nap
108 }
109
110 /**
111 * Sets this to read only if possible
112 * @see org.kuali.kfs.sys.document.web.TableJoining#readOnlyizeReadOnlyBlocks(java.util.Set)
113 */
114 public void readOnlyizeReadOnlyBlocks(Set<String> readOnlyBlocks) {
115 if (this instanceof ReadOnlyable && readOnlyBlocks.contains(getName())) {
116 ((ReadOnlyable)this).readOnlyize();
117 }
118 }
119
120 /**
121 * @see org.kuali.kfs.sys.document.web.TableJoining#setEditableBlocks(java.util.Set)
122 */
123 public void setEditableBlocks(Set<String> editableBlocks) {
124 if (this instanceof ReadOnlyable && editableBlocks.contains(getName())) {
125 ((ReadOnlyable)this).setEditable();
126 }
127 }
128
129 /**
130 * @see org.kuali.kfs.sys.document.web.TableJoining#performFieldTransformation(org.kuali.kfs.sys.document.service.AccountingLineFieldRenderingTransformation, org.kuali.kfs.sys.businessobject.AccountingLine, java.util.Map, java.util.Map)
131 */
132 public void performFieldTransformations(List<AccountingLineFieldRenderingTransformation> fieldTransformations, AccountingLine accountingLine, Map unconvertedValues) {
133 // don't do nothing - we don't have no child fields
134 }
135
136 }