1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.sys.document.web;
17
18 import java.util.List;
19 import java.util.Map;
20 import java.util.Set;
21
22 import org.kuali.ole.sys.OLEPropertyConstants;
23 import org.kuali.ole.sys.businessobject.AccountingLine;
24 import org.kuali.ole.sys.context.SpringContext;
25 import org.kuali.ole.sys.document.datadictionary.AccountingLineViewDebitCreditAmountFieldDefinition;
26 import org.kuali.ole.sys.document.datadictionary.AccountingLineViewFieldDefinition;
27 import org.kuali.ole.sys.document.service.AccountingLineFieldRenderingTransformation;
28 import org.kuali.rice.core.api.config.property.ConfigurationService;
29 import org.kuali.rice.kns.web.ui.Field;
30
31
32
33
34 public class AccountingLineViewDebitCreditAmountLayoutElement implements TableJoiningWithHeader, ReadOnlyable {
35 private Field debitAmountField;
36 private Field creditAmountField;
37 private AccountingLineViewDebitCreditAmountFieldDefinition definition;
38 private AccountingLineViewFieldDefinition debitFieldDefinition;
39 private AccountingLineViewFieldDefinition creditFieldDefinition;
40
41
42
43
44
45 public boolean isReadOnly() {
46 return (debitAmountField == null || debitAmountField.isReadOnly()) && (creditAmountField == null || creditAmountField.isReadOnly());
47 }
48
49
50
51
52
53 public void readOnlyize() {
54 if (debitAmountField != null) {
55 debitAmountField.setReadOnly(true);
56 }
57 if (creditAmountField != null) {
58 creditAmountField.setReadOnly(true);
59 }
60 }
61
62
63
64
65
66 public HeaderLabel createHeaderLabel() {
67 return null;
68 }
69
70
71
72
73
74 public boolean isHidden() {
75 return false;
76 }
77
78
79
80
81
82 public String getName() {
83 return null;
84 }
85
86
87
88
89
90 public int getRequestedRowCount() {
91 return 2;
92 }
93
94
95
96
97 public void joinRow(AccountingLineTableRow headerLabelRow, AccountingLineTableRow row) {
98 if (debitAmountField != null) {
99 headerLabelRow.addCell(createHeaderCellForField(true));
100 row.addCell(createCellForField(debitAmountField, debitFieldDefinition, true));
101 }
102 if (creditAmountField != null) {
103 headerLabelRow.addCell(createHeaderCellForField(false));
104 row.addCell(createCellForField(creditAmountField, creditFieldDefinition, false));
105 }
106 }
107
108
109
110
111 public void joinTable(List<AccountingLineTableRow> rows) {
112 final int remainingRowCount = rows.size() - 1;
113
114 if (debitAmountField != null) {
115 rows.get(0).addCell(createHeaderCellForField(true));
116
117 AccountingLineTableCell currentCell = createCellForField(debitAmountField, debitFieldDefinition, true);
118 currentCell.setRowSpan(remainingRowCount);
119 rows.get(1).addCell(currentCell);
120 }
121 if (creditAmountField != null) {
122 rows.get(0).addCell(createHeaderCellForField(false));
123
124 AccountingLineTableCell baseCell = createCellForField(creditAmountField, creditFieldDefinition, false);
125 baseCell.setRowSpan(remainingRowCount);
126 rows.get(1).addCell(baseCell);
127 }
128 }
129
130
131
132
133
134
135
136
137 protected AccountingLineTableCell createCellForField(Field field, AccountingLineViewFieldDefinition definition, boolean isDebit) {
138 AccountingLineTableCell cell = new AccountingLineTableCell();
139 AccountingLineViewDebitCreditAmountField renderableField = new AccountingLineViewDebitCreditAmountField(field, definition, isDebit, (isDebit ? this.definition.getNewLineDebitAmountProperty() : this.definition.getNewLineCreditAmountProperty()), this.definition.getVoucherLineHelperProperty());
140 cell.addRenderableElement(renderableField);
141 return cell;
142 }
143
144
145
146
147
148
149 protected AccountingLineTableCell createHeaderCellForField(boolean isDebit) {
150 AccountingLineTableCell headerCell = new AccountingLineTableCell();
151 headerCell.setRendersAsHeader(true);
152 final String propertyName = isDebit ? getDebitPropertyName() : getCreditPropertyName();
153 final String label = SpringContext.getBean(ConfigurationService.class).getPropertyValueAsString(propertyName);
154 headerCell.addRenderableElement(new LiteralHeaderLabel(label));
155 return headerCell;
156 }
157
158
159
160
161 protected String getDebitPropertyName() {
162 return "label.document.journalVoucher.accountingLine.debit";
163 }
164
165
166
167
168 protected String getCreditPropertyName() {
169 return "label.document.journalVoucher.accountingLine.credit";
170 }
171
172
173
174
175 public void performFieldTransformations(List<AccountingLineFieldRenderingTransformation> fieldTransformations, AccountingLine accountingLine, Map unconvertedValues) {
176 for (AccountingLineFieldRenderingTransformation fieldTransformation : fieldTransformations) {
177 fieldTransformation.transformField(accountingLine, getDebitAmountField(), getDebitFieldDefinition(), unconvertedValues);
178 fieldTransformation.transformField(accountingLine, getCreditAmountField(), getCreditFieldDefinition(), unconvertedValues);
179 }
180 }
181
182
183
184
185 public void readOnlyizeReadOnlyBlocks(Set<String> readOnlyBlocks) {
186 if (readOnlyBlocks.contains(OLEPropertyConstants.AMOUNT)) {
187 if (debitAmountField != null) {
188 debitAmountField.setReadOnly(true);
189 }
190 if (creditAmountField != null) {
191 creditAmountField.setReadOnly(true);
192 }
193 }
194 }
195
196
197
198
199
200 public void removeAllActionBlocks() {}
201
202
203
204
205 public void removeUnviewableBlocks(Set<String> unviewableBlocks) {
206 if (unviewableBlocks.contains(OLEPropertyConstants.AMOUNT)) {
207 if (debitAmountField != null) {
208 debitAmountField = null;
209 }
210 if (creditAmountField != null) {
211 creditAmountField = null;
212 }
213 }
214 }
215
216
217
218
219
220
221
222
223 public Field getCreditAmountField() {
224 return creditAmountField;
225 }
226
227
228
229
230
231
232 public void setCreditAmountField(Field creditAmountField) {
233 this.creditAmountField = creditAmountField;
234 }
235
236
237
238
239 public AccountingLineViewFieldDefinition getCreditFieldDefinition() {
240 return creditFieldDefinition;
241 }
242
243
244
245
246 public void setCreditFieldDefinition(AccountingLineViewFieldDefinition creditFieldDefinition) {
247 this.creditFieldDefinition = creditFieldDefinition;
248 }
249
250
251
252
253 public Field getDebitAmountField() {
254 return debitAmountField;
255 }
256
257
258
259
260 public void setDebitAmountField(Field debitAmountField) {
261 this.debitAmountField = debitAmountField;
262 }
263
264
265
266
267 public AccountingLineViewFieldDefinition getDebitFieldDefinition() {
268 return debitFieldDefinition;
269 }
270
271
272
273
274 public void setDebitFieldDefinition(AccountingLineViewFieldDefinition debitFieldDefinition) {
275 this.debitFieldDefinition = debitFieldDefinition;
276 }
277
278
279
280
281 public AccountingLineViewDebitCreditAmountFieldDefinition getDefinition() {
282 return definition;
283 }
284
285
286
287
288 public void setDefinition(AccountingLineViewDebitCreditAmountFieldDefinition definition) {
289 this.definition = definition;
290 }
291
292
293
294
295 public void setEditableBlocks(Set<String> editableBlocks) {
296 if (editableBlocks.contains(OLEPropertyConstants.AMOUNT)) {
297 if (debitAmountField != null) {
298 debitAmountField.setReadOnly(false);
299 }
300 if (creditAmountField != null) {
301 creditAmountField.setReadOnly(false);
302 }
303 }
304 }
305
306
307
308
309 public void setEditable() {
310 if (debitAmountField != null) {
311 debitAmountField.setReadOnly(false);
312 }
313
314 if (creditAmountField != null) {
315 creditAmountField.setReadOnly(false);
316 }
317 }
318 }