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