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(type= BeanTagAttribute.AttributeType.DIRECTORBYTYPE)
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(type= BeanTagAttribute.AttributeType.DIRECTORBYTYPE)
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 @Override
233 public void setTooltipOfComponent(Tooltip tooltip) {
234 getHeader().setToolTip(tooltip);
235 }
236
237
238
239
240 @Override
241 public String getHelpTitle() {
242 return this.getHeader().getHeaderText();
243 }
244
245
246
247
248 @Override
249 @BeanTagAttribute
250 public abstract List<? extends Component> getItems();
251
252
253
254
255
256
257 public abstract void setItems(List<? extends Component> items);
258
259
260
261
262
263
264
265
266
267
268 @BeanTagAttribute
269 public int getDefaultItemPosition() {
270 return this.defaultItemPosition;
271 }
272
273
274
275
276
277
278 public void setDefaultItemPosition(int defaultItemPosition) {
279 this.defaultItemPosition = defaultItemPosition;
280 }
281
282
283
284
285 @Override
286 @BeanTagAttribute(type= BeanTagAttribute.AttributeType.BYTYPE)
287 public LayoutManager getLayoutManager() {
288 return this.layoutManager;
289 }
290
291
292
293
294 @Override
295 public void setLayoutManager(LayoutManager layoutManager) {
296 this.layoutManager = layoutManager;
297 }
298
299
300
301
302 @Override
303 @BeanTagAttribute(type= BeanTagAttribute.AttributeType.DIRECTORBYTYPE)
304 public Header getHeader() {
305 return this.header;
306 }
307
308
309
310
311 @Override
312 public void setHeader(Header header) {
313 this.header = header;
314 }
315
316
317
318
319 @Override
320 @BeanTagAttribute(type= BeanTagAttribute.AttributeType.DIRECT)
321 public Group getFooter() {
322 return this.footer;
323 }
324
325
326
327
328 @Override
329 public void setFooter(Group footer) {
330 this.footer = footer;
331 }
332
333
334
335
336
337
338
339
340
341
342
343
344
345 public void setRenderHeader(boolean renderHeader) {
346 if (header != null) {
347 header.setRender(renderHeader);
348 }
349 }
350
351
352
353
354
355
356 @BeanTagAttribute
357 public String getHeaderText () {
358 if (header != null && header.getHeaderText() != null) {
359 return header.getHeaderText();
360 } else {
361 return "";
362 }
363 }
364
365
366
367
368
369
370 public void setHeaderText(String headerText) {
371 if (header != null) {
372 header.setHeaderText(headerText);
373 }
374 }
375
376
377
378
379
380
381
382
383
384
385
386
387
388 public void setRenderFooter(boolean renderFooter) {
389 if (footer != null) {
390 footer.setRender(renderFooter);
391 }
392 }
393
394
395
396
397
398
399
400 @BeanTagAttribute
401 public String getInstructionalText() {
402 return this.instructionalText;
403 }
404
405
406
407
408
409
410 public void setInstructionalText(String instructionalText) {
411 this.instructionalText = instructionalText;
412 }
413
414
415
416
417
418
419
420
421
422
423
424 @BeanTagAttribute
425 public Message getInstructionalMessage() {
426 return this.instructionalMessage;
427 }
428
429
430
431
432
433
434
435
436
437
438
439 public void setInstructionalMessage(Message instructionalMessage) {
440 this.instructionalMessage = instructionalMessage;
441 }
442
443
444
445
446 @Override
447 @BeanTagAttribute
448 public String getEnterKeyAction() {
449 return this.enterKeyAction;
450 }
451
452
453
454
455 public void setEnterKeyAction(String enterKeyAction) {
456 this.enterKeyAction = enterKeyAction;
457 }
458
459
460
461
462 @Override
463 public void completeValidation(ValidationTrace tracer) {
464 tracer.addBean(this);
465
466
467 if (getInstructionalText() != null && getInstructionalMessage() != null) {
468 String currentValues[] = {"instructionalMessage.text = " + getInstructionalMessage().getMessageText(),
469 "instructionalText = " + getInstructionalText()};
470 tracer.createWarning("InstructionalMessage will override instructioanlText", currentValues);
471 }
472
473 super.completeValidation(tracer.getCopy());
474 }
475 }