1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.uif.field;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.kuali.rice.core.api.exception.RiceRuntimeException;
20 import org.kuali.rice.krad.datadictionary.parse.BeanTag;
21 import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute;
22 import org.kuali.rice.krad.datadictionary.parse.BeanTags;
23 import org.kuali.rice.krad.uif.UifConstants;
24 import org.kuali.rice.krad.uif.UifConstants.Position;
25 import org.kuali.rice.krad.uif.component.ComponentSecurity;
26 import org.kuali.rice.krad.uif.element.Label;
27 import org.kuali.rice.krad.uif.util.MessageStructureUtils;
28 import org.kuali.rice.krad.uif.view.View;
29 import org.kuali.rice.krad.uif.component.Component;
30 import org.kuali.rice.krad.uif.component.ComponentBase;
31 import org.kuali.rice.krad.uif.util.ComponentFactory;
32
33 import java.util.List;
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50 @BeanTags({@BeanTag(name = "fieldBase-bean", parent = "Uif-FieldBase"),
51 @BeanTag(name = "fieldBase-withLabel-bean", parent = "Uif-FieldBase-withLabel")})
52 public class FieldBase extends ComponentBase implements Field {
53 private static final long serialVersionUID = -5888414844802862760L;
54
55 private String shortLabel;
56 private Label fieldLabel;
57
58 private Position labelPlacement;
59
60 private boolean labelRendered;
61
62 public FieldBase() {
63 labelRendered = false;
64 labelPlacement = Position.LEFT;
65 }
66
67
68
69
70
71
72
73
74
75 @Override
76 public void performInitialization(View view, Object model) {
77 super.performInitialization(view, model);
78 }
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95 @Override
96 public void performFinalize(View view, Object model, Component parent) {
97 super.performFinalize(view, model, parent);
98
99 if (fieldLabel != null) {
100 fieldLabel.setLabelForComponentId(this.getId());
101
102 if ((getRequired() != null) && getRequired().booleanValue()) {
103 fieldLabel.getRequiredMessage().setRender(!isReadOnly());
104 } else {
105 setRequired(new Boolean(false));
106 fieldLabel.getRequiredMessage().setRender(true);
107
108 String prefixStyle = "";
109 if (StringUtils.isNotBlank(fieldLabel.getRequiredMessage().getStyle())) {
110 prefixStyle = fieldLabel.getRequiredMessage().getStyle();
111 }
112 fieldLabel.getRequiredMessage().setStyle(prefixStyle + ";" + "display: none;");
113 }
114
115 if (labelPlacement.equals(Position.RIGHT)) {
116 fieldLabel.setRenderColon(false);
117 }
118
119 if (labelPlacement.equals(Position.TOP) || labelPlacement.equals(Position.BOTTOM)){
120 fieldLabel.addStyleClass("uif-labelBlock");
121 }
122
123 fieldLabel.addDataAttribute(UifConstants.DataAttributes.LABEL_FOR, this.getId());
124 if(StringUtils.isNotBlank(this.getFieldLabel().getLabelText())){
125 this.addDataAttribute(UifConstants.DataAttributes.LABEL,
126 MessageStructureUtils.translateStringMessage(this.getFieldLabel().getLabelText()));
127 }
128 }
129 }
130
131
132
133
134
135
136
137 protected void setNestedComponentIdAndSuffix(Component component, String suffix) {
138 if (component != null) {
139 String fieldId = getId();
140 fieldId += suffix;
141
142 component.setId(fieldId);
143 }
144 }
145
146
147
148
149 @Override
150 public final String getComponentTypeName() {
151 return "field";
152 }
153
154
155
156
157 @Override
158 public List<Component> getComponentsForLifecycle() {
159 List<Component> components = super.getComponentsForLifecycle();
160
161 components.add(fieldLabel);
162
163 return components;
164 }
165
166
167
168
169 @BeanTagAttribute(name = "label")
170 public String getLabel() {
171 if (fieldLabel != null) {
172 return fieldLabel.getLabelText();
173 }
174
175 return null;
176 }
177
178
179
180
181 public void setLabel(String labelText) {
182 if (StringUtils.isNotBlank(labelText) && this.fieldLabel == null) {
183 this.fieldLabel = ComponentFactory.getLabel();
184 }
185
186 if (this.fieldLabel != null) {
187 this.fieldLabel.setLabelText(labelText);
188 }
189 }
190
191
192
193
194 @BeanTagAttribute(name="labelStyleClasses",type= BeanTagAttribute.AttributeType.LISTVALUE)
195 public List<String> getLabelStyleClasses() {
196 if (fieldLabel != null) {
197 return fieldLabel.getCssClasses();
198 }
199
200 return null;
201 }
202
203
204
205
206 public void setLabelStyleClasses(List<String> labelStyleClasses) {
207 if (labelStyleClasses != null && this.fieldLabel == null) {
208 this.fieldLabel = ComponentFactory.getLabel();
209 }
210
211 if (this.fieldLabel != null) {
212 this.fieldLabel.setCssClasses(labelStyleClasses);
213 }
214 }
215
216
217
218
219 @BeanTagAttribute(name="labelColSpan")
220 public int getLabelColSpan() {
221 if (fieldLabel != null) {
222 return fieldLabel.getColSpan();
223 }
224
225 return 1;
226 }
227
228
229
230
231 public void setLabelColSpan(int labelColSpan) {
232 if (this.fieldLabel == null) {
233 this.fieldLabel = ComponentFactory.getLabel();
234 }
235
236 if (this.fieldLabel != null) {
237 this.fieldLabel.setColSpan(labelColSpan);
238 }
239 }
240
241
242
243
244 @BeanTagAttribute(name="shortLabel")
245 public String getShortLabel() {
246 return this.shortLabel;
247 }
248
249
250
251
252 public void setShortLabel(String shortLabel) {
253 this.shortLabel = shortLabel;
254 }
255
256
257
258
259
260
261
262
263
264
265
266
267 public void setShowLabel(boolean showLabel) {
268 if (fieldLabel != null) {
269 fieldLabel.setRender(showLabel);
270 }
271 }
272
273
274
275
276 @BeanTagAttribute(name="fieldLabel",type= BeanTagAttribute.AttributeType.SINGLEBEAN)
277 public Label getFieldLabel() {
278 return this.fieldLabel;
279 }
280
281
282
283
284 public void setFieldLabel(Label fieldLabel) {
285 this.fieldLabel = fieldLabel;
286 }
287
288
289
290
291
292
293
294 @BeanTagAttribute(name="labelPlacement",type= BeanTagAttribute.AttributeType.SINGLEBEAN)
295 public Position getLabelPlacement() {
296 return this.labelPlacement;
297 }
298
299
300
301
302
303
304 public void setLabelPlacement(Position labelPlacement) {
305 this.labelPlacement = labelPlacement;
306 }
307
308
309
310
311 @BeanTagAttribute(name="labelRendered")
312 public boolean isLabelRendered() {
313 return this.labelRendered;
314 }
315
316
317
318
319 public void setLabelRendered(boolean labelRendered) {
320 this.labelRendered = labelRendered;
321 }
322
323
324
325
326 public FieldSecurity getFieldSecurity() {
327 return (FieldSecurity) super.getComponentSecurity();
328 }
329
330
331
332
333
334
335 @Override
336 public void setComponentSecurity(ComponentSecurity componentSecurity) {
337 if (!(componentSecurity instanceof FieldSecurity)) {
338 throw new RiceRuntimeException("Component security for Field should be instance of FieldSecurity");
339 }
340
341 super.setComponentSecurity(componentSecurity);
342 }
343
344
345
346
347 @Override
348 protected Class<? extends ComponentSecurity> getComponentSecurityClass() {
349 return FieldSecurity.class;
350 }
351
352
353
354
355 @Override
356 protected <T> void copyProperties(T component) {
357 super.copyProperties(component);
358 FieldBase fieldBaseCopy = (FieldBase) component;
359 fieldBaseCopy.setShortLabel(this.shortLabel);
360 fieldBaseCopy.setLabelRendered(this.labelRendered);
361
362 if (this.fieldLabel != null) {
363 fieldBaseCopy.setFieldLabel((Label)this.fieldLabel.copy());
364 }
365
366 fieldBaseCopy.setLabelPlacement(this.labelPlacement);
367 }
368 }