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