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