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.HashSet;
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.AccountingLineViewLineDefinition;
25 import org.kuali.ole.sys.document.service.AccountingLineFieldRenderingTransformation;
26
27
28
29
30 public class AccountingLineViewLine implements ReadOnlyable, AccountingLineViewLineFillingElement {
31 private List<RenderableElement> elements;
32 private AccountingLineViewLineDefinition definition;
33
34
35
36
37
38 public AccountingLineViewLineDefinition getDefinition() {
39 return definition;
40 }
41
42
43
44
45 public void setDefinition(AccountingLineViewLineDefinition definition) {
46 this.definition = definition;
47 }
48
49
50
51
52 public String getName() {
53 return definition.getElementName();
54 }
55
56
57
58
59 public List<RenderableElement> getElements() {
60 return elements;
61 }
62
63
64
65
66 public void setElements(List<RenderableElement> fields) {
67 this.elements = fields;
68 }
69
70
71
72
73
74 public int getRequestedRowCount() {
75 return getMaxRequestedRowCount();
76 }
77
78
79
80
81
82 protected int getMaxRequestedRowCount() {
83 for (RenderableElement element : elements) {
84 if (element instanceof TableJoiningWithHeader && !element.isHidden()) {
85 return 2;
86 }
87 }
88 return 1;
89 }
90
91
92
93
94 public void joinRow(AccountingLineTableRow headerRow, AccountingLineTableRow row) {
95 for (RenderableElement element : elements) {
96 if (element instanceof TableJoining) {
97 ((TableJoining)element).joinRow(headerRow, row);
98 } else {
99 headerRow.addCell(createTableCellForNonTableJoining(element));
100 }
101 }
102 }
103
104
105
106
107
108
109 protected AccountingLineTableCell createTableCellForNonTableJoining(RenderableElement element) {
110 AccountingLineTableCell cell = new AccountingLineTableCell();
111 cell.addRenderableElement(element);
112 cell.setRowSpan(getRequestedRowCount());
113 return cell;
114 }
115
116
117
118
119
120 public void joinTable(List<AccountingLineTableRow> rows) {
121 throw new IllegalStateException("Line elements may not join a table directly; the specified rendering is incorrect");
122 }
123
124
125
126
127
128 public boolean shouldStretchToFillLine() {
129 return false;
130 }
131
132
133
134
135 public void readOnlyize() {
136 for (RenderableElement element : elements) {
137 if (element instanceof ReadOnlyable) {
138 ((ReadOnlyable)element).readOnlyize();
139 }
140 }
141 }
142
143
144
145
146 public boolean isReadOnly() {
147 for (RenderableElement element : elements) {
148 if (element instanceof ReadOnlyable && !((ReadOnlyable)element).isReadOnly()) {
149 return false;
150 }
151 }
152 return true;
153 }
154
155
156
157
158 public void removeAllActionBlocks() {
159 Set<RenderableElement> actionBlocksToRemove = new HashSet<RenderableElement>();
160 for (RenderableElement element : elements) {
161 if (element.isActionBlock()) {
162 actionBlocksToRemove.add(element);
163 }
164 }
165 elements.removeAll(actionBlocksToRemove);
166 }
167
168
169
170
171 public void removeUnviewableBlocks(Set<String> unviewableBlocks) {
172 Set<RenderableElement> elementsToRemove = new HashSet<RenderableElement>();
173 for (RenderableElement element : elements) {
174 if (element instanceof TableJoining) {
175 if (unviewableBlocks.contains(((TableJoining)element).getName())) {
176 elementsToRemove.add(element);
177 } else {
178 ((TableJoining)element).removeUnviewableBlocks(unviewableBlocks);
179 }
180 }
181 }
182 elements.removeAll(elementsToRemove);
183 }
184
185
186
187
188
189 public void readOnlyizeReadOnlyBlocks(Set<String> readOnlyBlocks) {
190 for (RenderableElement element : elements) {
191 if (element instanceof TableJoining) {
192 ((TableJoining)element).readOnlyizeReadOnlyBlocks(readOnlyBlocks);
193 }
194 }
195 }
196
197
198
199
200 public void performFieldTransformations(List<AccountingLineFieldRenderingTransformation> fieldTransformations, AccountingLine accountingLine, Map unconvertedValues) {
201 for (RenderableElement element : elements) {
202 if (element instanceof TableJoining) {
203 ((TableJoining)element).performFieldTransformations(fieldTransformations, accountingLine, unconvertedValues);
204 }
205 }
206 }
207
208
209
210
211
212 public int getDisplayingFieldWidth() {
213 int count = 0;
214 for (RenderableElement element : elements) {
215 if (!element.isHidden()) {
216 if (element instanceof AccountingLineViewField && ((AccountingLineViewField)element).getColSpanOverride() > 1) {
217 count += ((AccountingLineViewField)element).getColSpanOverride();
218 } else {
219 count += 1;
220 }
221 }
222 }
223 return count;
224 }
225
226
227
228
229 public void setEditable() {
230 for (RenderableElement element : elements) {
231 if (element instanceof ReadOnlyable) {
232 ((ReadOnlyable)element).setEditable();
233 }
234 }
235 }
236
237
238
239
240 public void setEditableBlocks(Set<String> editableBlocks) {
241 for (RenderableElement element : elements) {
242 if (element instanceof TableJoining) {
243 ((TableJoining)element).setEditableBlocks(editableBlocks);
244 }
245 }
246 }
247 }