1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.uif.container;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute;
20 import org.kuali.rice.krad.datadictionary.validator.ValidationTrace;
21 import org.kuali.rice.krad.uif.UifConstants;
22 import org.kuali.rice.krad.uif.component.Component;
23 import org.kuali.rice.krad.uif.component.ComponentBase;
24 import org.kuali.rice.krad.uif.component.DelayedCopy;
25 import org.kuali.rice.krad.uif.element.Header;
26 import org.kuali.rice.krad.uif.element.Message;
27 import org.kuali.rice.krad.uif.element.ValidationMessages;
28 import org.kuali.rice.krad.uif.layout.LayoutManager;
29 import org.kuali.rice.krad.uif.lifecycle.ViewLifecycle;
30 import org.kuali.rice.krad.uif.lifecycle.ViewLifecycleRestriction;
31 import org.kuali.rice.krad.uif.util.ComponentFactory;
32 import org.kuali.rice.krad.uif.util.ComponentUtils;
33 import org.kuali.rice.krad.uif.util.LifecycleElement;
34 import org.kuali.rice.krad.uif.widget.Help;
35 import org.kuali.rice.krad.uif.widget.Tooltip;
36
37 import java.util.ArrayList;
38 import java.util.List;
39
40
41
42
43
44
45
46
47
48
49
50
51
52 public abstract class ContainerBase extends ComponentBase implements Container {
53 private static final long serialVersionUID = -4182226230601746657L;
54
55 private int defaultItemPosition;
56
57 private Help help;
58
59 private LayoutManager layoutManager;
60
61 private Header header;
62 private Group footer;
63
64 private String instructionalText;
65 private Message instructionalMessage;
66
67 @DelayedCopy
68 private ValidationMessages validationMessages;
69
70 private String enterKeyAction;
71
72
73
74
75 public ContainerBase() {
76 defaultItemPosition = 1;
77 }
78
79
80
81
82 @Override
83 public boolean isProcessRemoteFieldHolders() {
84 return true;
85 }
86
87
88
89
90
91
92
93
94
95
96
97
98 @SuppressWarnings("deprecation")
99 @Override
100 public void performInitialization(Object model) {
101 super.performInitialization(model);
102
103 if ((StringUtils.isNotBlank(instructionalText) || (getPropertyExpression("instructionalText") != null)) && (
104 instructionalMessage
105 == null)) {
106 instructionalMessage = ComponentFactory.getInstructionalMessage();
107 }
108
109 if (layoutManager != null && !this.getItems().isEmpty()) {
110 layoutManager.performInitialization(model);
111 }
112 }
113
114
115
116
117 @SuppressWarnings("deprecation")
118 @Override
119 public void performApplyModel(Object model, LifecycleElement parent) {
120 super.performApplyModel(model, parent);
121
122
123 if (instructionalMessage != null && StringUtils.isBlank(instructionalMessage.getMessageText())) {
124 instructionalMessage.setMessageText(instructionalText);
125 }
126
127 if (layoutManager != null && !this.getItems().isEmpty()) {
128 layoutManager.performApplyModel(model, this);
129 }
130 }
131
132
133
134
135
136
137
138
139
140
141
142
143 @SuppressWarnings("deprecation")
144 @Override
145 public void performFinalize(Object model, LifecycleElement parent) {
146 super.performFinalize(model, parent);
147
148 if (header != null) {
149 header.addDataAttribute(UifConstants.DataAttributes.HEADER_FOR, this.getId());
150 }
151
152 if (layoutManager != null && !this.getItems().isEmpty()) {
153 layoutManager.performFinalize(model, this);
154 }
155
156
157 if (validationMessages != null) {
158 validationMessages.generateMessages(ViewLifecycle.getView(), model, this);
159 }
160
161
162 if (this.getEnterKeyAction() != null && StringUtils.isNotBlank(this.getEnterKeyAction())) {
163 this.addDataAttribute(UifConstants.DataAttributes.ENTER_KEY, this.getEnterKeyAction());
164 }
165 }
166
167
168
169
170 @Override
171 public List<String> getAdditionalTemplates() {
172 List<String> additionalTemplates = super.getAdditionalTemplates();
173
174 if (layoutManager != null) {
175 if (additionalTemplates.isEmpty()) {
176 additionalTemplates = new ArrayList<String>();
177 }
178 additionalTemplates.add(layoutManager.getTemplate());
179 }
180
181 return additionalTemplates;
182 }
183
184
185
186
187 @Override
188 public void sortItems() {
189
190 List<? extends Component> sortedItems = ComponentUtils.sort(getItems(), defaultItemPosition);
191 setItems(sortedItems);
192 }
193
194
195
196
197 @Override
198 @ViewLifecycleRestriction
199 @BeanTagAttribute(name = "validationMessages", type = BeanTagAttribute.AttributeType.SINGLEBEAN)
200 public ValidationMessages getValidationMessages() {
201 return this.validationMessages;
202 }
203
204
205
206
207 @Override
208 public void setValidationMessages(ValidationMessages validationMessages) {
209 this.validationMessages = validationMessages;
210 }
211
212
213
214
215 @Override
216 @BeanTagAttribute(name = "help", type = BeanTagAttribute.AttributeType.SINGLEBEAN)
217 public Help getHelp() {
218 return this.help;
219 }
220
221
222
223
224 @Override
225 public void setHelp(Help help) {
226 this.help = help;
227 }
228
229
230
231
232
233
234 @Override
235 public void setTooltipOfComponent(Tooltip tooltip) {
236 getHeader().setToolTip(tooltip);
237 }
238
239
240
241
242
243
244
245 @Override
246 public String getHelpTitle() {
247 return this.getHeader().getHeaderText();
248 }
249
250
251
252
253 @Override
254 @BeanTagAttribute(name = "items", type = BeanTagAttribute.AttributeType.LISTBEAN)
255 public abstract List<? extends Component> getItems();
256
257
258
259
260
261
262 public abstract void setItems(List<? extends Component> items);
263
264
265
266
267
268
269
270
271
272
273 @BeanTagAttribute(name = "defaultItemPosition")
274 public int getDefaultItemPosition() {
275 return this.defaultItemPosition;
276 }
277
278
279
280
281
282
283 public void setDefaultItemPosition(int defaultItemPosition) {
284 this.defaultItemPosition = defaultItemPosition;
285 }
286
287
288
289
290 @Override
291 @BeanTagAttribute(name = "layoutManager", type = BeanTagAttribute.AttributeType.SINGLEBEAN)
292 public LayoutManager getLayoutManager() {
293 return this.layoutManager;
294 }
295
296
297
298
299 @Override
300 public void setLayoutManager(LayoutManager layoutManager) {
301 this.layoutManager = layoutManager;
302 }
303
304
305
306
307 @Override
308 @BeanTagAttribute(name = "header", type = BeanTagAttribute.AttributeType.SINGLEBEAN)
309 public Header getHeader() {
310 return this.header;
311 }
312
313
314
315
316 @Override
317 public void setHeader(Header header) {
318 this.header = header;
319 }
320
321
322
323
324 @Override
325 @BeanTagAttribute(name = "footer", type = BeanTagAttribute.AttributeType.SINGLEBEAN)
326 public Group getFooter() {
327 return this.footer;
328 }
329
330
331
332
333 @Override
334 public void setFooter(Group footer) {
335 this.footer = footer;
336 }
337
338
339
340
341
342
343
344
345
346
347
348
349
350 public void setRenderHeader(boolean renderHeader) {
351 if (header != null) {
352 header.setRender(renderHeader);
353 }
354 }
355
356
357
358
359
360
361 @BeanTagAttribute(name = "headertext")
362 public String getHeaderText() {
363 if (header != null && header.getHeaderText() != null) {
364 return header.getHeaderText();
365 } else {
366 return "";
367 }
368 }
369
370
371
372
373
374
375 public void setHeaderText(String headerText) {
376 if (header != null) {
377 header.setHeaderText(headerText);
378 }
379 }
380
381
382
383
384
385
386
387
388
389
390
391
392
393 public void setRenderFooter(boolean renderFooter) {
394 if (footer != null) {
395 footer.setRender(renderFooter);
396 }
397 }
398
399
400
401
402
403
404
405 @BeanTagAttribute(name = "instructionalText")
406 public String getInstructionalText() {
407 return this.instructionalText;
408 }
409
410
411
412
413
414
415 public void setInstructionalText(String instructionalText) {
416 this.instructionalText = instructionalText;
417 }
418
419
420
421
422
423
424
425
426
427
428
429 @BeanTagAttribute(name = "instructionalMessage", type = BeanTagAttribute.AttributeType.SINGLEBEAN)
430 public Message getInstructionalMessage() {
431 return this.instructionalMessage;
432 }
433
434
435
436
437
438
439
440
441
442
443
444 public void setInstructionalMessage(Message instructionalMessage) {
445 this.instructionalMessage = instructionalMessage;
446 }
447
448
449
450
451 @Override
452 public void completeValidation(ValidationTrace tracer) {
453 tracer.addBean(this);
454
455
456 if (getInstructionalText() != null && getInstructionalMessage() != null) {
457 String currentValues[] = {"instructionalMessage.text = " + getInstructionalMessage().getMessageText(),
458 "instructionalText = " + getInstructionalText()};
459 tracer.createWarning("InstructionalMessage will override instructioanlText", currentValues);
460 }
461
462 super.completeValidation(tracer.getCopy());
463 }
464
465
466
467
468 @Override
469 @BeanTagAttribute(name = "enterKeyAction")
470 public String getEnterKeyAction() {
471 return this.enterKeyAction;
472 }
473
474
475
476
477 public void setEnterKeyAction(String enterKeyAction) {
478 this.enterKeyAction = enterKeyAction;
479 }
480
481 }