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.businessobject.AccountingLine;
23 import org.kuali.ole.sys.document.datadictionary.AccountingLineViewCurrentBaseAmountFieldDefinition;
24 import org.kuali.ole.sys.document.datadictionary.AccountingLineViewFieldDefinition;
25 import org.kuali.ole.sys.document.service.AccountingLineFieldRenderingTransformation;
26 import org.kuali.rice.kns.web.ui.Field;
27
28
29
30
31 public class AccountingLineViewCurrentBaseAmount implements TableJoiningWithHeader, ReadOnlyable {
32 private Field currentAmountField;
33 private Field baseAmountField;
34 private AccountingLineViewCurrentBaseAmountFieldDefinition definition;
35 private AccountingLineViewFieldDefinition currentAmountFieldDefinition;
36 private AccountingLineViewFieldDefinition baseAmountFieldDefinition;
37
38
39
40
41
42 public String getName() {
43 return null;
44 }
45
46
47
48
49
50 public void readOnlyizeReadOnlyBlocks(Set<String> readOnlyBlocks) {
51 if (currentAmountField != null) {
52 readOnlyizeField(currentAmountField, readOnlyBlocks);
53 }
54 if (baseAmountField != null) {
55 readOnlyizeField(baseAmountField, readOnlyBlocks);
56 }
57 if (baseAmountField != null && currentAmountField != null) {
58 if (baseAmountField.isReadOnly() && !currentAmountField.isReadOnly()) {
59 currentAmountField.setFieldRequired(true);
60 } else if (currentAmountField.isReadOnly() && !baseAmountField.isReadOnly()) {
61 baseAmountField.setFieldRequired(true);
62 }
63 }
64 }
65
66
67
68
69 public boolean isReadOnly() {
70 boolean readOnly = true;
71 if (currentAmountField != null) {
72 readOnly &= currentAmountField.isReadOnly();
73 }
74 if (baseAmountField != null) {
75 readOnly &= baseAmountField.isReadOnly();
76 }
77 return readOnly;
78 }
79
80
81
82
83 public void readOnlyize() {
84 if (currentAmountField != null) {
85 currentAmountField.setReadOnly(true);
86 }
87 if (baseAmountField != null) {
88 baseAmountField.setReadOnly(true);
89 }
90 }
91
92
93
94
95
96
97
98
99 protected void readOnlyizeField(Field field, Set<String> readOnlyBlocks) {
100 if (field != null && readOnlyBlocks.contains(field.getPropertyName())) {
101 field.setReadOnly(true);
102 }
103 }
104
105
106
107
108
109 public int getRequestedRowCount() {
110 return 2;
111 }
112
113
114
115
116
117 public void joinRow(AccountingLineTableRow headerLabelRow, AccountingLineTableRow row) {
118 if (currentAmountField != null) {
119 headerLabelRow.addCell(createHeaderCellForField(currentAmountField));
120 row.addCell(createCellForField(currentAmountField, currentAmountFieldDefinition));
121 }
122 if (baseAmountField != null) {
123 headerLabelRow.addCell(createHeaderCellForField(baseAmountField));
124 row.addCell(createCellForField(baseAmountField, baseAmountFieldDefinition));
125 }
126 }
127
128
129
130
131
132 public void joinTable(List<AccountingLineTableRow> rows) {
133 final int remainingRowCount = rows.size() - 1;
134
135 if (currentAmountField != null) {
136 rows.get(0).addCell(createHeaderCellForField(currentAmountField));
137
138 AccountingLineTableCell currentCell = createCellForField(currentAmountField, currentAmountFieldDefinition);
139 currentCell.setRowSpan(remainingRowCount);
140 rows.get(1).addCell(currentCell);
141 }
142 if (baseAmountField != null) {
143 rows.get(0).addCell(createHeaderCellForField(baseAmountField));
144
145 AccountingLineTableCell baseCell = createCellForField(baseAmountField, baseAmountFieldDefinition);
146 baseCell.setRowSpan(remainingRowCount);
147 rows.get(1).addCell(baseCell);
148 }
149
150 }
151
152
153
154
155
156 public void removeAllActionBlocks() {}
157
158
159
160
161
162 public void removeUnviewableBlocks(Set<String> unviewableBlocks) {
163 if (isFieldUnviewable(currentAmountField, unviewableBlocks)) {
164 currentAmountField = null;
165 }
166 if (isFieldUnviewable(baseAmountField, unviewableBlocks)) {
167 baseAmountField = null;
168 }
169 }
170
171
172
173
174
175
176
177 protected boolean isFieldUnviewable(Field field, Set<String> unviewableBlocks) {
178 return field != null && unviewableBlocks.contains(field.getPropertyName());
179 }
180
181
182
183
184
185
186
187
188 protected AccountingLineTableCell createCellForField(Field field, AccountingLineViewFieldDefinition definition) {
189 AccountingLineTableCell cell = new AccountingLineTableCell();
190 AccountingLineViewField renderableField = new AccountingLineViewField();
191 renderableField.setField(field);
192 renderableField.setDefinition(definition);
193 cell.addRenderableElement(renderableField);
194 return cell;
195 }
196
197
198
199
200
201
202
203
204
205 protected AccountingLineTableCell createHeaderCellForField(Field field) {
206 AccountingLineTableCell headerCell = new AccountingLineTableCell();
207 headerCell.setRendersAsHeader(true);
208 headerCell.addRenderableElement(new LiteralHeaderLabel(field.getFieldLabel()));
209 return headerCell;
210 }
211
212
213
214
215 public void performFieldTransformations(List<AccountingLineFieldRenderingTransformation> fieldTransformations, AccountingLine accountingLine, Map unconvertedValues) {
216 for (AccountingLineFieldRenderingTransformation fieldTransformation : fieldTransformations) {
217 fieldTransformation.transformField(accountingLine, getCurrentAmountField(), getCurrentAmountFieldDefinition(), unconvertedValues);
218 fieldTransformation.transformField(accountingLine, getBaseAmountField(), getBaseAmountFieldDefinition(), unconvertedValues);
219 }
220 }
221
222
223
224
225
226 public HeaderLabel createHeaderLabel() {
227 return null;
228 }
229
230
231
232
233
234 public boolean isHidden() {
235 return false;
236 }
237
238
239
240
241
242
243
244 public Field getBaseAmountField() {
245 return baseAmountField;
246 }
247
248
249
250
251
252
253
254 public void setBaseAmountField(Field baseAmountField) {
255 this.baseAmountField = baseAmountField;
256 }
257
258
259
260
261
262 public Field getCurrentAmountField() {
263 return currentAmountField;
264 }
265
266
267
268
269
270 public void setCurrentAmountField(Field currentAmountField) {
271 this.currentAmountField = currentAmountField;
272 }
273
274
275
276
277
278 public AccountingLineViewCurrentBaseAmountFieldDefinition getDefinition() {
279 return definition;
280 }
281
282
283
284
285
286 public void setDefinition(AccountingLineViewCurrentBaseAmountFieldDefinition definition) {
287 this.definition = definition;
288 }
289
290
291
292
293
294 public AccountingLineViewFieldDefinition getBaseAmountFieldDefinition() {
295 return baseAmountFieldDefinition;
296 }
297
298
299
300
301
302 public void setBaseAmountFieldDefinition(AccountingLineViewFieldDefinition baseAmountFieldDefinition) {
303 this.baseAmountFieldDefinition = baseAmountFieldDefinition;
304 }
305
306
307
308
309
310 public AccountingLineViewFieldDefinition getCurrentAmountFieldDefinition() {
311 return currentAmountFieldDefinition;
312 }
313
314
315
316
317
318 public void setCurrentAmountFieldDefinition(AccountingLineViewFieldDefinition currentAmountFieldDefinition) {
319 this.currentAmountFieldDefinition = currentAmountFieldDefinition;
320 }
321
322
323
324
325 public void setEditableBlocks(Set<String> editableBlocks) {
326 if (currentAmountField != null) {
327 setEditableField(currentAmountField, editableBlocks);
328 }
329 if (baseAmountField != null) {
330 setEditableField(baseAmountField, editableBlocks);
331 }
332
333 if (baseAmountField != null && currentAmountField != null) {
334 if (baseAmountField.isReadOnly() && !currentAmountField.isReadOnly()) {
335 currentAmountField.setReadOnly(false);
336 }
337 else if (currentAmountField.isReadOnly() && !baseAmountField.isReadOnly()) {
338 baseAmountField.setReadOnly(false);
339 }
340 }
341 }
342
343
344
345
346 public void setEditable() {
347 if (currentAmountField != null) {
348 currentAmountField.setReadOnly(false);
349 }
350
351 if (baseAmountField != null) {
352 baseAmountField.setReadOnly(false);
353 }
354 }
355
356
357
358
359
360
361
362
363 protected void setEditableField(Field field, Set<String> editableBlocks) {
364 if (field != null && editableBlocks.contains(field.getPropertyName())) {
365 field.setReadOnly(false);
366 }
367 }
368 }