1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.uif.element;
17
18 import java.util.ArrayList;
19 import java.util.Collections;
20 import java.util.List;
21
22 import org.apache.commons.lang.StringUtils;
23 import org.kuali.rice.krad.datadictionary.parse.BeanTag;
24 import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute;
25 import org.kuali.rice.krad.datadictionary.parse.BeanTags;
26 import org.kuali.rice.krad.datadictionary.validator.ValidationTrace;
27 import org.kuali.rice.krad.datadictionary.validator.Validator;
28 import org.kuali.rice.krad.uif.UifConstants;
29 import org.kuali.rice.krad.uif.component.Component;
30 import org.kuali.rice.krad.uif.container.Group;
31 import org.kuali.rice.krad.uif.lifecycle.ViewLifecycleRestriction;
32 import org.kuali.rice.krad.uif.util.ComponentFactory;
33 import org.kuali.rice.krad.uif.util.ComponentUtils;
34 import org.kuali.rice.krad.uif.util.LifecycleElement;
35 import org.kuali.rice.krad.uif.view.View;
36 import org.kuali.rice.krad.uif.widget.Help;
37 import org.kuali.rice.krad.uif.util.LifecycleElement;
38 import org.kuali.rice.krad.util.KRADConstants;
39
40
41
42
43
44
45
46
47
48
49
50
51 @BeanTags({@BeanTag(name = "header", parent = "Uif-HeaderBase"),
52 @BeanTag(name = "headerOne", parent = "Uif-HeaderOne"),
53 @BeanTag(name = "headerTwo", parent = "Uif-HeaderTwo"),
54 @BeanTag(name = "headerThree", parent = "Uif-HeaderThree"),
55 @BeanTag(name = "headerFour", parent = "Uif-HeaderFour"),
56 @BeanTag(name = "headerFive", parent = "Uif-HeaderFive"),
57 @BeanTag(name = "headerSix", parent = "Uif-HeaderSix"),
58 @BeanTag(name = "pageHeader", parent = "Uif-PageHeader"),
59 @BeanTag(name = "sectionHeader", parent = "Uif-SectionHeader"),
60 @BeanTag(name = "subSectionHeader", parent = "Uif-SubSectionHeader"),
61 @BeanTag(name = "subCollectionHeader", parent = "Uif-SubCollectionHeader")})
62 public class Header extends ContentElementBase {
63 private static final long serialVersionUID = -6950408292923393244L;
64
65 private String headerText;
66 private String headerLevel;
67
68 private String headerTagStyle;
69 private List<String> headerTagCssClasses;
70 private boolean headerTagOnly;
71
72 private Message richHeaderMessage;
73 private List<Component> inlineComponents;
74
75 private Group upperGroup;
76 private Group rightGroup;
77 private Group lowerGroup;
78
79 private boolean renderWrapper;
80
81 public Header() {
82 super();
83
84 headerTagCssClasses = new ArrayList<String>();
85 renderWrapper = true;
86 }
87
88
89
90
91
92
93 @Override
94 public void performApplyModel(Object model, LifecycleElement parent) {
95 super.performApplyModel(model, parent);
96
97 if (richHeaderMessage == null && headerText != null && headerText.contains(
98 KRADConstants.MessageParsing.LEFT_TOKEN) && headerText.contains(
99 KRADConstants.MessageParsing.RIGHT_TOKEN)) {
100 Message message = ComponentFactory.getMessage();
101 message.setMessageText(headerText);
102 message.setInlineComponents(inlineComponents);
103 message.setRenderWrapperTag(false);
104
105 this.setRichHeaderMessage(message);
106 }
107 }
108
109
110
111
112
113
114
115
116
117
118 @Override
119 public void performFinalize(Object model, LifecycleElement parent) {
120 super.performFinalize(model, parent);
121
122
123 if ((getUpperGroup() != null) && (getUpperGroup().getItems().isEmpty())) {
124 getUpperGroup().setRender(false);
125 }
126
127 if ((getRightGroup() != null) && (getRightGroup().getItems().isEmpty())) {
128 getRightGroup().setRender(false);
129 }
130
131 if ((getLowerGroup() != null) && (getLowerGroup().getItems().isEmpty())) {
132 getLowerGroup().setRender(false);
133 }
134
135
136 if (getUpperGroup() != null) {
137 getUpperGroup().addStyleClass("uif-header-upperGroup");
138 }
139
140 if (getRightGroup() != null) {
141 getRightGroup().addStyleClass("uif-header-rightGroup");
142 }
143
144 if (getLowerGroup() != null) {
145 getLowerGroup().addStyleClass("uif-header-lowerGroup");
146 }
147 }
148
149
150
151
152 @Override
153 public List<String> getAdditionalTemplates() {
154 List<String> additionalTemplates = super.getAdditionalTemplates();
155
156 Object parent = getContext().get(UifConstants.ContextVariableNames.PARENT);
157
158 Help help = null;
159 if (parent instanceof Group) {
160 help = ((Group) parent).getHelp();
161 } else if (parent instanceof View) {
162 help = ((View) parent).getHelp();
163 }
164
165 if (help != null) {
166 String helpTemplate = help.getTemplate();
167 if (additionalTemplates.isEmpty()) {
168 additionalTemplates = new ArrayList<String>();
169 }
170 additionalTemplates.add(helpTemplate);
171 }
172
173 return additionalTemplates;
174 }
175
176
177
178
179
180
181 @BeanTagAttribute
182 public String getHeaderText() {
183 return this.headerText;
184 }
185
186
187
188
189
190
191 public void setHeaderText(String headerText) {
192 this.headerText = headerText;
193 }
194
195
196
197
198
199
200 @BeanTagAttribute
201 public String getHeaderLevel() {
202 return this.headerLevel;
203 }
204
205
206
207
208
209
210 public void setHeaderLevel(String headerLevel) {
211 this.headerLevel = headerLevel;
212 }
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227 @BeanTagAttribute
228 public List<String> getHeaderTagCssClasses() {
229 return this.headerTagCssClasses;
230 }
231
232
233
234
235
236
237 public void setHeaderTagCssClasses(List<String> headerTagCssClasses) {
238 this.headerTagCssClasses = headerTagCssClasses;
239 }
240
241
242
243
244
245
246
247 public String getHeaderStyleClassesAsString() {
248 if (headerTagCssClasses != null) {
249 return StringUtils.join(headerTagCssClasses, " ");
250 }
251
252 return "";
253 }
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268 @BeanTagAttribute
269 public String getHeaderTagStyle() {
270 return this.headerTagStyle;
271 }
272
273
274
275
276
277
278 public void setHeaderTagStyle(String headerTagStyle) {
279 this.headerTagStyle = headerTagStyle;
280 }
281
282 @BeanTagAttribute
283 public boolean isHeaderTagOnly() {
284 return headerTagOnly;
285 }
286
287 public void setHeaderTagOnly(boolean headerTagOnly) {
288 this.headerTagOnly = headerTagOnly;
289 }
290
291
292
293
294
295
296
297
298
299
300 @BeanTagAttribute
301 public Group getUpperGroup() {
302 return upperGroup;
303 }
304
305
306
307
308
309
310 public void setUpperGroup(Group upperGroup) {
311 this.upperGroup = upperGroup;
312 }
313
314
315
316
317
318
319
320
321
322
323 @BeanTagAttribute
324 public Group getRightGroup() {
325 return rightGroup;
326 }
327
328
329
330
331
332
333 public void setRightGroup(Group rightGroup) {
334 this.rightGroup = rightGroup;
335 }
336
337
338
339
340
341
342
343
344
345
346 @BeanTagAttribute
347 public Group getLowerGroup() {
348 return lowerGroup;
349 }
350
351
352
353
354
355
356 public void setLowerGroup(Group lowerGroup) {
357 this.lowerGroup = lowerGroup;
358 }
359
360
361
362
363
364
365
366
367
368
369
370 @ViewLifecycleRestriction
371 @BeanTagAttribute
372 public List<? extends Component> getItems() {
373 if (lowerGroup != null) {
374 return lowerGroup.getItems();
375 }
376
377 return null;
378 }
379
380
381
382
383
384
385
386
387
388
389
390 public void setItems(List<? extends Component> items) {
391 if (lowerGroup != null) {
392 lowerGroup.setItems(items);
393 }
394 }
395
396
397
398
399
400
401
402
403
404 @BeanTagAttribute
405 public Message getRichHeaderMessage() {
406 return richHeaderMessage;
407 }
408
409
410
411
412
413
414
415
416
417
418 public void setRichHeaderMessage(Message richHeaderMessage) {
419 this.richHeaderMessage = richHeaderMessage;
420 }
421
422
423
424
425
426
427 @BeanTagAttribute
428 public List<Component> getInlineComponents() {
429 return inlineComponents;
430 }
431
432
433
434
435
436
437 public void setInlineComponents(List<Component> inlineComponents) {
438 this.inlineComponents = inlineComponents;
439 }
440
441
442
443
444 @Override
445 public void completeValidation(ValidationTrace tracer) {
446 tracer.addBean(this);
447
448
449 String headerLevel = getHeaderLevel().toUpperCase();
450 boolean correctHeaderLevel = false;
451 if (headerLevel.compareTo("H1") == 0) {
452 correctHeaderLevel = true;
453 } else if (headerLevel.compareTo("H2") == 0) {
454 correctHeaderLevel = true;
455 } else if (headerLevel.compareTo("H3") == 0) {
456 correctHeaderLevel = true;
457 } else if (headerLevel.compareTo("H4") == 0) {
458 correctHeaderLevel = true;
459 } else if (headerLevel.compareTo("H5") == 0) {
460 correctHeaderLevel = true;
461 } else if (headerLevel.compareTo("H6") == 0) {
462 correctHeaderLevel = true;
463 } else if (headerLevel.compareTo("LABEL") == 0) {
464 correctHeaderLevel = true;
465 }
466 if (!correctHeaderLevel) {
467 String currentValues[] = {"headerLevel =" + getHeaderLevel()};
468 tracer.createError("HeaderLevel must be of values h1, h2, h3, h4, h5, h6, or label", currentValues);
469 }
470
471
472 if (getHeaderText() == null) {
473 if (!Validator.checkExpressions(this, "headerText")) {
474 String currentValues[] = {"headertText =" + getHeaderText()};
475 tracer.createWarning("HeaderText should be set", currentValues);
476 }
477 }
478
479 super.completeValidation(tracer.getCopy());
480 }
481 }