1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.uif.layout;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.kuali.rice.krad.uif.UifConstants.Orientation;
20 import org.kuali.rice.krad.uif.container.CollectionGroup;
21 import org.kuali.rice.krad.uif.container.Container;
22 import org.kuali.rice.krad.uif.container.Group;
23 import org.kuali.rice.krad.uif.container.View;
24 import org.kuali.rice.krad.uif.core.Component;
25 import org.kuali.rice.krad.uif.core.DataBinding;
26 import org.kuali.rice.krad.uif.field.ActionField;
27 import org.kuali.rice.krad.uif.field.Field;
28 import org.kuali.rice.krad.uif.field.GroupField;
29 import org.kuali.rice.krad.uif.util.ComponentUtils;
30 import org.kuali.rice.krad.uif.util.ObjectPropertyUtils;
31
32 import java.util.ArrayList;
33 import java.util.List;
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54 public class StackedLayoutManager extends BoxLayoutManager implements CollectionLayoutManager {
55 private static final long serialVersionUID = 4602368505430238846L;
56
57 private String summaryTitle;
58 private List<String> summaryFields;
59
60 private Group addLineGroup;
61 private Group lineGroupPrototype;
62 private GroupField subCollectionGroupFieldPrototype;
63
64 private List<Group> stackedGroups;
65
66 public StackedLayoutManager() {
67 super();
68
69 setOrientation(Orientation.VERTICAL);
70
71 summaryFields = new ArrayList<String>();
72 stackedGroups = new ArrayList<Group>();
73 }
74
75
76
77
78
79
80
81
82
83
84
85 @Override
86 public void performInitialization(View view, Container container) {
87 super.performInitialization(view, container);
88
89 view.getViewHelperService().performComponentInitialization(view, lineGroupPrototype);
90 view.getViewHelperService().performComponentInitialization(view, subCollectionGroupFieldPrototype);
91 }
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106 public void buildLine(View view, Object model, CollectionGroup collectionGroup, List<Field> lineFields,
107 List<GroupField> subCollectionFields, String bindingPath, List<ActionField> actions, String idSuffix,
108 Object currentLine, int lineIndex) {
109 boolean isAddLine = lineIndex == -1;
110
111
112 Group lineGroup = null;
113 if (isAddLine) {
114 stackedGroups = new ArrayList<Group>();
115
116 if (addLineGroup == null) {
117 lineGroup = ComponentUtils.copy(lineGroupPrototype, idSuffix);
118 }
119 else {
120 lineGroup = ComponentUtils.copy(getAddLineGroup(), idSuffix);
121 }
122 }
123 else {
124 lineGroup = ComponentUtils.copy(lineGroupPrototype, idSuffix);
125 }
126
127 ComponentUtils.updateContextForLine(lineGroup, currentLine, lineIndex);
128
129
130 String headerText = "";
131 if (isAddLine) {
132 headerText = collectionGroup.getAddLineLabel();
133 }
134 else {
135
136 List<Object> modelCollection = ObjectPropertyUtils.getPropertyValue(model, ((DataBinding) collectionGroup)
137 .getBindingInfo().getBindingPath());
138
139 headerText = buildLineHeaderText(modelCollection.get(lineIndex));
140 }
141 lineGroup.getHeader().setHeaderText(headerText);
142
143
144 List<Field> groupFields = new ArrayList<Field>();
145 groupFields.addAll(lineFields);
146 groupFields.addAll(subCollectionFields);
147
148 lineGroup.setItems(groupFields);
149
150
151 if (collectionGroup.isRenderLineActions() && !collectionGroup.isReadOnly()) {
152 lineGroup.getFooter().setItems(actions);
153 }
154
155 stackedGroups.add(lineGroup);
156 }
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172 protected String buildLineHeaderText(Object line) {
173 String summaryFieldString = "";
174 for (String summaryField : summaryFields) {
175 Object summaryFieldValue = ObjectPropertyUtils.getPropertyValue(line, summaryField);
176 if (StringUtils.isNotBlank(summaryFieldString)) {
177 summaryFieldString += " - ";
178 }
179
180 if (summaryFieldValue != null) {
181 summaryFieldString += summaryFieldValue;
182 }
183 else {
184 summaryFieldString += "Null";
185 }
186 }
187
188 String headerText = summaryTitle;
189 if (StringUtils.isNotBlank(summaryFieldString)) {
190 headerText += " ( " + summaryFieldString + " )";
191 }
192
193 return headerText;
194 }
195
196
197
198
199 @Override
200 public Class<? extends Container> getSupportedContainer() {
201 return CollectionGroup.class;
202 }
203
204
205
206
207 @Override
208 public List<Component> getNestedComponents() {
209 List<Component> components = super.getNestedComponents();
210
211 components.addAll(stackedGroups);
212
213 return components;
214 }
215
216
217
218
219
220
221
222
223 public String getSummaryTitle() {
224 return this.summaryTitle;
225 }
226
227
228
229
230
231
232 public void setSummaryTitle(String summaryTitle) {
233 this.summaryTitle = summaryTitle;
234 }
235
236
237
238
239
240
241
242
243
244
245 public List<String> getSummaryFields() {
246 return this.summaryFields;
247 }
248
249
250
251
252
253
254 public void setSummaryFields(List<String> summaryFields) {
255 this.summaryFields = summaryFields;
256 }
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271 public Group getAddLineGroup() {
272 return this.addLineGroup;
273 }
274
275
276
277
278
279
280 public void setAddLineGroup(Group addLineGroup) {
281 this.addLineGroup = addLineGroup;
282 }
283
284
285
286
287
288
289
290
291 public Group getLineGroupPrototype() {
292 return this.lineGroupPrototype;
293 }
294
295
296
297
298
299
300 public void setLineGroupPrototype(Group lineGroupPrototype) {
301 this.lineGroupPrototype = lineGroupPrototype;
302 }
303
304
305
306
307 public GroupField getSubCollectionGroupFieldPrototype() {
308 return this.subCollectionGroupFieldPrototype;
309 }
310
311
312
313
314
315
316 public void setSubCollectionGroupFieldPrototype(GroupField subCollectionGroupFieldPrototype) {
317 this.subCollectionGroupFieldPrototype = subCollectionGroupFieldPrototype;
318 }
319
320
321
322
323
324
325 public List<Group> getStackedGroups() {
326 return this.stackedGroups;
327 }
328
329
330
331
332
333
334 public void setStackedGroups(List<Group> stackedGroups) {
335 this.stackedGroups = stackedGroups;
336 }
337
338 }