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.ArrayList;
19 import java.util.List;
20 import java.util.Map;
21 import java.util.Set;
22
23 import org.kuali.ole.sys.businessobject.AccountingLine;
24 import org.kuali.ole.sys.document.datadictionary.AccountingLineViewHideShowLinesDefinition;
25 import org.kuali.ole.sys.document.service.AccountingLineFieldRenderingTransformation;
26
27
28
29
30 public class HideShowLayoutElement implements AccountingLineViewLineFillingElement {
31 private List<AccountingLineViewLineFillingElement> lines;
32 private AccountingLineViewHideShowLinesDefinition definition;
33
34
35
36
37
38 public String getName() {
39 return definition.getName();
40 }
41
42
43
44
45
46 public int getRequestedRowCount() {
47 return 1;
48 }
49
50
51
52
53
54 public void joinRow(AccountingLineTableRow headerLabelRow, AccountingLineTableRow row) {
55 AccountingLineTableCell cell = new AccountingLineTableCell();
56 if (row != null) {
57 cell.setRowSpan(2);
58 }
59 cell.setStyleClassOverride("total-line");
60 cell.addRenderableElement(createHideShowBlock((row == null ? 1 : 2)));
61 headerLabelRow.addCell(cell);
62 }
63
64
65
66
67
68 public boolean shouldStretchToFillLine() {
69 return true;
70 }
71
72
73
74
75
76 public void joinTable(List<AccountingLineTableRow> rows) {
77 throw new IllegalStateException("Line elements may not join a table directly; the specified rendering is incorrect");
78 }
79
80
81
82
83
84
85 protected HideShowBlock createHideShowBlock(int headerRowCount) {
86 HideShowBlock block = new HideShowBlock();
87 List<AccountingLineTableRow> rows = createBlankRows(getRowsRequested());
88
89 haveLinesJoinRows(rows, headerRowCount);
90
91 block.setContentRows(rows);
92 block.setDefinition(definition);
93 return block;
94 }
95
96
97
98
99
100 protected int getRowsRequested() {
101 int count = 0;
102 for (AccountingLineViewLineFillingElement line : lines) {
103 count += line.getRequestedRowCount();
104 }
105 return count;
106 }
107
108
109
110
111
112
113 protected List<AccountingLineTableRow> createBlankRows(int cellCount) {
114 List<AccountingLineTableRow> rows = new ArrayList<AccountingLineTableRow>();
115 int count = 0;
116 while (count < cellCount) {
117 rows.add(new AccountingLineTableRow());
118 count += 1;
119 }
120 return rows;
121 }
122
123
124
125
126
127
128 protected void haveLinesJoinRows(List<AccountingLineTableRow> rows, int headerRowCount) {
129 int count = 0;
130 for (AccountingLineViewLineFillingElement line : lines) {
131
132 if (line.getRequestedRowCount() > 1) {
133 line.joinRow(rows.get(count), rows.get(count+1));
134 count += 2;
135 } else {
136 line.joinRow(rows.get(count), null);
137 count += 1;
138 }
139 }
140 }
141
142
143
144
145
146 public void performFieldTransformations(List<AccountingLineFieldRenderingTransformation> fieldTransformations, AccountingLine accountingLine, Map unconvertedValues) {
147 for (AccountingLineViewLineFillingElement line : lines) {
148 line.performFieldTransformations(fieldTransformations, accountingLine, unconvertedValues);
149 }
150 }
151
152
153
154
155
156 public void readOnlyizeReadOnlyBlocks(Set<String> readOnlyBlocks) {
157 for (AccountingLineViewLineFillingElement line : lines) {
158 line.readOnlyizeReadOnlyBlocks(readOnlyBlocks);
159 }
160 }
161
162
163
164
165
166 public void removeAllActionBlocks() {
167 for (AccountingLineViewLineFillingElement line : lines) {
168 line.removeAllActionBlocks();
169 }
170 }
171
172
173
174
175
176 public void removeUnviewableBlocks(Set<String> unviewableBlocks) {
177 List<AccountingLineViewLineFillingElement> unviewableLines = new ArrayList<AccountingLineViewLineFillingElement>();
178 for (AccountingLineViewLineFillingElement line : lines) {
179 if (unviewableBlocks.contains(line.getName())) {
180 unviewableLines.add(line);
181 } else {
182 line.removeUnviewableBlocks(unviewableBlocks);
183 }
184 }
185 lines.removeAll(unviewableLines);
186 }
187
188
189
190
191
192 public List<AccountingLineViewLineFillingElement> getLines() {
193 return lines;
194 }
195
196
197
198
199
200 public void setLines(List<AccountingLineViewLineFillingElement> lines) {
201 this.lines = lines;
202 }
203
204
205
206
207
208 public void addLine(AccountingLineViewLineFillingElement line) {
209 if (lines == null) {
210 lines = new ArrayList<AccountingLineViewLineFillingElement>();
211 }
212 lines.add(line);
213 }
214
215
216
217
218
219 public AccountingLineViewHideShowLinesDefinition getDefinition() {
220 return definition;
221 }
222
223
224
225
226
227 public void setDefinition(AccountingLineViewHideShowLinesDefinition definition) {
228 this.definition = definition;
229 }
230
231
232
233
234
235 public boolean isReadOnly() {
236 for (AccountingLineViewLineFillingElement line : lines) {
237 if (!line.isReadOnly()) return false;
238 }
239 return true;
240 }
241
242
243
244
245
246 public void readOnlyize() {
247 for (AccountingLineViewLineFillingElement line : lines) {
248 line.readOnlyize();
249 }
250 }
251
252
253
254
255
256 public int getDisplayingFieldWidth() {
257 return 1;
258 }
259
260
261
262
263 public void setEditableBlocks(Set<String> editableBlocks) {
264 for (AccountingLineViewLineFillingElement line : lines) {
265 line.setEditableBlocks(editableBlocks);
266 }
267 }
268
269
270
271
272 public void setEditable() {
273 for (AccountingLineViewLineFillingElement line : lines) {
274 line.setEditable();
275 }
276 }
277
278 }