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