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