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.validator.ErrorReport;
20 import org.kuali.rice.krad.datadictionary.validator.RDValidator;
21 import org.kuali.rice.krad.datadictionary.validator.TracerToken;
22 import org.kuali.rice.krad.uif.UifConstants.Position;
23 import org.kuali.rice.krad.uif.component.Component;
24 import org.kuali.rice.krad.uif.util.ComponentFactory;
25 import org.kuali.rice.krad.uif.view.View;
26 import org.kuali.rice.krad.util.KRADConstants;
27
28 import java.util.ArrayList;
29 import java.util.List;
30
31
32
33
34
35
36
37
38
39
40 public class Label extends ContentElementBase {
41 private static final long serialVersionUID = -6491546893195180114L;
42
43 private String labelText;
44 private String labelForComponentId;
45
46 private boolean renderColon;
47
48 private Position requiredMessagePlacement;
49 private Message requiredMessage;
50
51 private Message richLabelMessage;
52 private List<Component> inlineComponents;
53
54 public Label() {
55 renderColon = true;
56
57 requiredMessagePlacement = Position.LEFT;
58 }
59
60
61
62
63
64
65 @Override
66 public void performApplyModel(View view, Object model, Component parent) {
67 super.performApplyModel(view, model, parent);
68
69 if (richLabelMessage == null
70 && labelText != null
71 && labelText.contains(KRADConstants.MessageParsing.LEFT_TOKEN)
72 &&
73 labelText.contains(KRADConstants.MessageParsing.RIGHT_TOKEN)) {
74 Message message = ComponentFactory.getMessage();
75 view.assignComponentIds(message);
76 message.setMessageText(labelText);
77 message.setInlineComponents(inlineComponents);
78 message.setGenerateSpan(false);
79 view.getViewHelperService().performComponentInitialization(view, model, message);
80 this.setRichLabelMessage(message);
81 }
82 }
83
84
85
86
87
88
89
90
91
92
93 @Override
94 public void performFinalize(View view, Object model, Component parent) {
95 super.performFinalize(view, model, parent);
96
97 if (StringUtils.isBlank(getLabelText())) {
98 setRender(false);
99 }
100 }
101
102
103
104
105 @Override
106 public List<Component> getComponentsForLifecycle() {
107 List<Component> components = super.getComponentsForLifecycle();
108
109 components.add(requiredMessage);
110 components.add(richLabelMessage);
111
112 return components;
113 }
114
115
116
117
118
119
120
121
122
123
124
125 public String getLabelForComponentId() {
126 return this.labelForComponentId;
127 }
128
129
130
131
132
133
134 public void setLabelForComponentId(String labelForComponentId) {
135 this.labelForComponentId = labelForComponentId;
136 }
137
138
139
140
141
142
143 public String getLabelText() {
144 return this.labelText;
145 }
146
147
148
149
150
151
152 public void setLabelText(String labelText) {
153 this.labelText = labelText;
154 }
155
156
157
158
159
160
161
162
163
164 public boolean isRenderColon() {
165 return this.renderColon;
166 }
167
168
169
170
171
172
173 public void setRenderColon(boolean renderColon) {
174 this.renderColon = renderColon;
175 }
176
177
178
179
180
181
182
183
184
185
186
187
188
189 public Message getRequiredMessage() {
190 return this.requiredMessage;
191 }
192
193
194
195
196
197
198 public void setRequiredMessage(Message requiredMessage) {
199 this.requiredMessage = requiredMessage;
200 }
201
202
203
204
205
206
207
208 public Position getRequiredMessagePlacement() {
209 return this.requiredMessagePlacement;
210 }
211
212
213
214
215
216
217 public void setRequiredMessagePlacement(Position requiredMessagePlacement) {
218 this.requiredMessagePlacement = requiredMessagePlacement;
219 }
220
221
222
223
224
225
226
227
228 public Message getRichLabelMessage() {
229 return richLabelMessage;
230 }
231
232
233
234
235
236
237
238
239 public void setRichLabelMessage(Message richLabelMessage) {
240 this.richLabelMessage = richLabelMessage;
241 }
242
243
244
245
246
247
248 public List<Component> getInlineComponents() {
249 return inlineComponents;
250 }
251
252
253
254
255
256
257 public void setInlineComponents(List<Component> inlineComponents) {
258 this.inlineComponents = inlineComponents;
259 }
260
261
262
263
264 @Override
265 public ArrayList<ErrorReport> completeValidation(TracerToken tracer){
266 ArrayList<ErrorReport> reports=new ArrayList<ErrorReport>();
267 tracer.addBean(this);
268
269 if(tracer.getValidationStage()==TracerToken.BUILD){
270
271 if(isRender() && getLabelText()==null){
272 if(!RDValidator.checkExpressions(this,"labelText")) {
273 ErrorReport error = ErrorReport.createError("LabelText should be set if render is true",tracer);
274 error.addCurrentValue("render = "+isRender());
275 error.addCurrentValue("labelText ="+getLabelText());
276 reports.add(error);
277 }
278 }
279 }
280
281 reports.addAll(super.completeValidation(tracer.getCopy()));
282
283 return reports;
284 }
285 }