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.ErrorReport;
23 import org.kuali.rice.krad.datadictionary.validator.Validator;
24 import org.kuali.rice.krad.datadictionary.validator.ValidationTrace;
25 import org.kuali.rice.krad.uif.component.Component;
26 import org.kuali.rice.krad.uif.util.ComponentFactory;
27 import org.kuali.rice.krad.uif.view.View;
28
29 import java.util.ArrayList;
30 import java.util.List;
31
32
33
34
35
36
37 @BeanTags({@BeanTag(name = "image-bean", parent = "Uif-Image"),
38 @BeanTag(name = "helpImage-bean", parent = "Uif-HelpImage"),
39 @BeanTag(name = "quickLookupImage-bean", parent = "Uif-QuickLookupImage"),
40 @BeanTag(name = "directInquiryImage-bean", parent = "Uif-DirectInquiryImage")})
41 public class Image extends ContentElementBase {
42 private static final long serialVersionUID = -3911849875276940507L;
43
44 private String source;
45 private String altText;
46 private String height;
47 private String width;
48
49 private boolean captionHeaderPlacementAboveImage;
50
51 private String captionHeaderText;
52 private Header captionHeader;
53
54 private String cutlineText;
55 private Message cutlineMessage;
56
57 public Image() {
58 super();
59
60 altText = "";
61 }
62
63
64
65
66
67
68
69
70
71
72
73 @Override
74 public void performInitialization(View view, Object model) {
75 super.performInitialization(view, model);
76
77 if ((StringUtils.isNotBlank(captionHeaderText) || (getPropertyExpression("captionHeaderText") != null)) && (
78 captionHeader == null)) {
79 captionHeader = ComponentFactory.getImageCaptionHeader();
80 view.assignComponentIds(captionHeader);
81 }
82
83 if ((StringUtils.isNotBlank(cutlineText) || (getPropertyExpression("cutlineText") != null)) && (cutlineMessage
84 == null)) {
85 cutlineMessage = ComponentFactory.getImageCutlineMessage();
86 view.assignComponentIds(cutlineMessage);
87 }
88 }
89
90
91
92
93
94
95
96
97
98
99
100
101 @Override
102 public void performApplyModel(View view, Object model, Component parent) {
103 super.performApplyModel(view, model, parent);
104
105 if (StringUtils.isNotBlank(captionHeaderText)) {
106 captionHeader.setHeaderText(captionHeaderText);
107 }
108
109 if (StringUtils.isNotBlank(cutlineText)) {
110 cutlineMessage.setMessageText(cutlineText);
111 }
112 }
113
114
115
116
117 @Override
118 public List<Component> getComponentsForLifecycle() {
119 List<Component> components = super.getComponentsForLifecycle();
120
121 components.add(captionHeader);
122 components.add(cutlineMessage);
123
124 return components;
125 }
126
127
128
129
130
131
132 @BeanTagAttribute(name="source")
133 public String getSource() {
134 return this.source;
135 }
136
137
138
139
140
141
142 public void setSource(String source) {
143 this.source = source;
144 }
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164 @BeanTagAttribute(name="altText")
165 public String getAltText() {
166 return this.altText;
167 }
168
169
170
171
172
173
174 public void setAltText(String altText) {
175 this.altText = altText;
176 }
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191 @BeanTagAttribute(name="height")
192 public String getHeight() {
193 return this.height;
194 }
195
196
197
198
199
200
201 public void setHeight(String height) {
202 this.height = height;
203 }
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218 @BeanTagAttribute(name="width")
219 public String getWidth() {
220 return width;
221 }
222
223
224
225
226
227
228 public void setWidth(String width) {
229 this.width = width;
230 }
231
232
233
234
235
236
237
238
239
240
241 @BeanTagAttribute(name="captionHeaderText")
242 public String getCaptionHeaderText() {
243 return captionHeaderText;
244 }
245
246
247
248
249
250
251 public void setCaptionHeaderText(String captionHeaderText) {
252 this.captionHeaderText = captionHeaderText;
253 }
254
255
256
257
258
259
260 @BeanTagAttribute(name="captionHeader",type= BeanTagAttribute.AttributeType.SINGLEBEAN)
261 public Header getCaptionHeader() {
262 return captionHeader;
263 }
264
265
266
267
268
269
270 public void setCaptionHeader(Header captionHeader) {
271 this.captionHeader = captionHeader;
272 }
273
274
275
276
277
278
279
280
281
282
283
284 @BeanTagAttribute(name="cutlineText")
285 public String getCutlineText() {
286 return cutlineText;
287 }
288
289
290
291
292
293
294 public void setCutlineText(String cutlineText) {
295 this.cutlineText = cutlineText;
296 }
297
298
299
300
301
302
303
304
305
306
307 @BeanTagAttribute(name="cutlineMessage",type= BeanTagAttribute.AttributeType.SINGLEBEAN)
308 public Message getCutlineMessage() {
309 return cutlineMessage;
310 }
311
312
313
314
315
316
317 public void setCutlineMessage(Message cutlineMessage) {
318 this.cutlineMessage = cutlineMessage;
319 }
320
321
322
323
324
325
326 @BeanTagAttribute(name="captionHeaderPlacmentAboveImage")
327 public boolean isCaptionHeaderPlacementAboveImage() {
328 return captionHeaderPlacementAboveImage;
329 }
330
331
332
333
334
335
336 public void setCaptionHeaderPlacementAboveImage(boolean captionHeaderPlacementAboveImage) {
337 this.captionHeaderPlacementAboveImage = captionHeaderPlacementAboveImage;
338 }
339
340
341
342
343 @Override
344 public void completeValidation(ValidationTrace tracer){
345 tracer.addBean(this);
346
347
348 if(getSource()==null){
349 if(!Validator.checkExpressions(this, "source")){
350 String currentValues [] = {"source ="+getSource()};
351 tracer.createError("Source must be set",currentValues);
352 }
353 }
354
355
356 if(getAltText().compareTo("")==0){
357 if(Validator.checkExpressions(this, "altText")){
358 String currentValues [] = {"altText ="+getAltText()};
359 tracer.createWarning("Alt text should be set, violates accessibility standards if not set",currentValues);
360 }
361 }
362
363 super.completeValidation(tracer.getCopy());
364 }
365
366
367
368
369 @Override
370 protected <T> void copyProperties(T component) {
371 super.copyProperties(component);
372 Image imageCopy = (Image) component;
373 imageCopy.setAltText(this.altText);
374
375 if (this.captionHeader != null) {
376 imageCopy.setCaptionHeader((Header)this.captionHeader.copy());
377 }
378
379 imageCopy.setCaptionHeaderPlacementAboveImage(this.captionHeaderPlacementAboveImage);
380 imageCopy.setCaptionHeaderText(this.captionHeaderText);
381
382 if (this.cutlineMessage != null) {
383 imageCopy.setCutlineMessage((Message)this.cutlineMessage.copy());
384 }
385
386 imageCopy.setCutlineText(this.cutlineText);
387 imageCopy.setHeight(this.height);
388 imageCopy.setSource(this.source);
389 imageCopy.setWidth(this.width);
390 }
391 }