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.RiceRemoteServiceConnectionException;
20 import org.kuali.rice.core.api.exception.RiceRuntimeException;
21 import org.kuali.rice.krad.uif.UifConstants.Position;
22 import org.kuali.rice.krad.uif.component.ComponentSecurity;
23 import org.kuali.rice.krad.uif.view.View;
24 import org.kuali.rice.krad.uif.component.Component;
25 import org.kuali.rice.krad.uif.component.ComponentBase;
26 import org.kuali.rice.krad.uif.util.ComponentFactory;
27
28 import java.util.List;
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45 public class FieldBase extends ComponentBase implements Field {
46 private static final long serialVersionUID = -5888414844802862760L;
47
48 private String shortLabel;
49 private LabelField labelField;
50
51 private Position labelPlacement;
52
53 private boolean labelFieldRendered;
54
55 public FieldBase() {
56 labelFieldRendered = false;
57 labelPlacement = Position.LEFT;
58 }
59
60
61
62
63
64
65
66
67
68 @Override
69 public void performInitialization(View view, Object model) {
70 super.performInitialization(view, model);
71 }
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88 @Override
89 public void performFinalize(View view, Object model, Component parent) {
90 super.performFinalize(view, model, parent);
91
92 if (labelField != null) {
93 labelField.setLabelForComponentId(this.getId());
94
95 if ((getRequired() != null) && getRequired().booleanValue()) {
96 labelField.getRequiredMessageField().setRender(true);
97 } else {
98 setRequired(new Boolean(false));
99 labelField.getRequiredMessageField().setRender(true);
100 String prefixStyle = "";
101 if (StringUtils.isNotBlank(labelField.getRequiredMessageField().getStyle())) {
102 prefixStyle = labelField.getRequiredMessageField().getStyle();
103 }
104 labelField.getRequiredMessageField().setStyle(prefixStyle + ";" + "display: none;");
105 }
106
107 if (labelPlacement.equals(Position.RIGHT)) {
108 labelField.setRenderColon(false);
109 }
110
111 if (labelPlacement.equals(Position.TOP) || labelPlacement.equals(Position.BOTTOM)){
112 labelField.addStyleClass("uif-labelBlock");
113 }
114 }
115 }
116
117
118
119
120 @Override
121 public final String getComponentTypeName() {
122 return "field";
123 }
124
125
126
127
128 @Override
129 public List<Component> getComponentsForLifecycle() {
130 List<Component> components = super.getComponentsForLifecycle();
131
132 components.add(labelField);
133
134 return components;
135 }
136
137
138
139
140 public String getLabel() {
141 if (labelField != null) {
142 return labelField.getLabelText();
143 }
144
145 return null;
146 }
147
148
149
150
151 public void setLabel(String label) {
152 if (StringUtils.isNotBlank(label) && labelField == null) {
153 labelField = ComponentFactory.getLabelField();
154 }
155
156 if (labelField != null) {
157 labelField.setLabelText(label);
158 }
159 }
160
161
162
163
164 public String getShortLabel() {
165 return this.shortLabel;
166 }
167
168
169
170
171 public void setShortLabel(String shortLabel) {
172 this.shortLabel = shortLabel;
173 }
174
175
176
177
178
179
180
181
182
183
184
185
186 public void setShowLabel(boolean showLabel) {
187 if (labelField != null) {
188 labelField.setRender(showLabel);
189 }
190 }
191
192
193
194
195 public LabelField getLabelField() {
196 return this.labelField;
197 }
198
199
200
201
202 public void setLabelField(LabelField labelField) {
203 this.labelField = labelField;
204 }
205
206
207
208
209
210
211
212 public Position getLabelPlacement() {
213 return this.labelPlacement;
214 }
215
216
217
218
219
220
221 public void setLabelPlacement(Position labelPlacement) {
222 this.labelPlacement = labelPlacement;
223 }
224
225
226
227
228 public boolean isLabelFieldRendered() {
229 return this.labelFieldRendered;
230 }
231
232
233
234
235 public void setLabelFieldRendered(boolean labelFieldRendered) {
236 this.labelFieldRendered = labelFieldRendered;
237 }
238
239
240
241
242
243
244 @Override
245 public FieldSecurity getComponentSecurity() {
246 return (FieldSecurity) super.getComponentSecurity();
247 }
248
249
250
251
252
253
254 @Override
255 public void setComponentSecurity(ComponentSecurity componentSecurity) {
256 if (!(componentSecurity instanceof FieldSecurity)) {
257 throw new RiceRuntimeException("Component security for Field should be instance of FieldSecurity");
258 }
259
260 super.setComponentSecurity(componentSecurity);
261 }
262
263 @Override
264 protected Class<? extends ComponentSecurity> getComponentSecurityClass() {
265 return FieldSecurity.class;
266 }
267 }