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