1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.uif.control;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.kuali.rice.krad.datadictionary.parse.BeanTag;
20 import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute;
21 import org.kuali.rice.krad.datadictionary.validator.ValidationTrace;
22 import org.kuali.rice.krad.uif.UifConstants;
23 import org.kuali.rice.krad.uif.component.Component;
24 import org.kuali.rice.krad.uif.element.ContentElementBase;
25 import org.kuali.rice.krad.uif.view.ExpressionEvaluator;
26 import org.kuali.rice.krad.uif.util.ExpressionUtils;
27 import org.kuali.rice.krad.uif.view.View;
28
29 import java.util.ArrayList;
30 import java.util.List;
31
32
33
34
35
36
37
38 @BeanTag(name = "controlBase-bean", parent = "Uif-ControlBase")
39 public abstract class ControlBase extends ContentElementBase implements Control {
40 private static final long serialVersionUID = -7898244978136312663L;
41
42 private int tabIndex;
43
44 private boolean disabled;
45 private String disabledExpression;
46 private String disabledReason;
47 private boolean evaluateDisabledOnKeyUp;
48
49 private String disabledConditionJs;
50 private List<String> disabledConditionControlNames;
51
52 private List<String> disabledWhenChangedPropertyNames;
53 private List<String> enabledWhenChangedPropertyNames;
54
55 public ControlBase() {
56 super();
57
58 disabled = false;
59 disabledWhenChangedPropertyNames = new ArrayList<String>();
60 enabledWhenChangedPropertyNames = new ArrayList<String>();
61 }
62
63
64
65
66
67
68
69
70
71 public void performApplyModel(View view, Object model, Component parent) {
72 super.performApplyModel(view, model, parent);
73
74 disabledExpression = this.getPropertyExpression("disabled");
75 if(disabledExpression != null){
76 ExpressionEvaluator expressionEvaluator =
77 view.getViewHelperService().getExpressionEvaluator();
78
79 disabledExpression = expressionEvaluator.replaceBindingPrefixes(view, this,
80 disabledExpression);
81 disabled = (Boolean) expressionEvaluator.evaluateExpression(this.getContext(), disabledExpression);
82 }
83 }
84
85
86
87
88
89
90
91
92
93 public void performFinalize(View view, Object model, Component parent) {
94 super.performApplyModel(view, model, parent);
95
96 ExpressionEvaluator expressionEvaluator =
97 view.getViewHelperService().getExpressionEvaluator();
98
99 if (StringUtils.isNotEmpty(disabledExpression) && !disabledExpression.equalsIgnoreCase("true")
100 && !disabledExpression.equalsIgnoreCase("false")) {
101 disabledConditionControlNames = new ArrayList<String>();
102 disabledConditionJs = ExpressionUtils.parseExpression(disabledExpression,
103 disabledConditionControlNames);
104 }
105
106 List<String> adjustedDisablePropertyNames = new ArrayList<String>();
107 for (String propertyName : disabledWhenChangedPropertyNames) {
108 adjustedDisablePropertyNames.add(expressionEvaluator.replaceBindingPrefixes(view, this,
109 propertyName));
110 }
111 disabledWhenChangedPropertyNames = adjustedDisablePropertyNames;
112
113 List<String> adjustedEnablePropertyNames = new ArrayList<String>();
114 for (String propertyName : enabledWhenChangedPropertyNames) {
115 adjustedEnablePropertyNames.add(expressionEvaluator.replaceBindingPrefixes(view, this,
116 propertyName));
117 }
118 enabledWhenChangedPropertyNames = adjustedEnablePropertyNames;
119
120
121 this.addDataAttribute(UifConstants.DataAttributes.ROLE, UifConstants.RoleTypes.CONTROL);
122 }
123
124
125
126
127 @Override
128 public final String getComponentTypeName() {
129 return "control";
130 }
131
132
133
134
135 @BeanTagAttribute(name="tabIndex")
136 public int getTabIndex() {
137 return this.tabIndex;
138 }
139
140
141
142
143 public void setTabIndex(int tabIndex) {
144 this.tabIndex = tabIndex;
145 }
146
147
148
149
150 @BeanTagAttribute(name="disabled")
151 public boolean isDisabled() {
152 return disabled;
153 }
154
155
156
157
158 public void setDisabled(boolean disabled) {
159 this.disabled = disabled;
160 }
161
162
163
164
165 @BeanTagAttribute(name="disabledReason")
166 public String getDisabledReason() {
167 return disabledReason;
168 }
169
170
171
172
173 public void setDisabledReason(String disabledReason) {
174 this.disabledReason = disabledReason;
175 }
176
177
178
179
180 @Override
181 public void completeValidation(ValidationTrace tracer){
182 tracer.addBean(this);
183
184 super.completeValidation(tracer.getCopy());
185 }
186
187
188
189
190
191
192
193 @BeanTagAttribute(name="evaluateDisabledOnKeyUp")
194 public boolean isEvaluateDisabledOnKeyUp() {
195 return evaluateDisabledOnKeyUp;
196 }
197
198
199
200
201
202
203 public void setEvaluateDisabledOnKeyUp(boolean evaluateDisabledOnKeyUp) {
204 this.evaluateDisabledOnKeyUp = evaluateDisabledOnKeyUp;
205 }
206
207
208
209
210
211
212 public String getDisabledConditionJs() {
213 return disabledConditionJs;
214 }
215
216
217
218
219
220
221 public List<String> getDisabledConditionControlNames() {
222 return disabledConditionControlNames;
223 }
224
225
226
227
228
229
230 @BeanTagAttribute(name="disabledWhenChangedPropertyNames",type= BeanTagAttribute.AttributeType.LISTVALUE)
231 public List<String> getDisabledWhenChangedPropertyNames() {
232 return disabledWhenChangedPropertyNames;
233 }
234
235
236
237
238
239
240 public void setDisabledWhenChangedPropertyNames(List<String> disabledWhenChangedPropertyNames) {
241 this.disabledWhenChangedPropertyNames = disabledWhenChangedPropertyNames;
242 }
243
244
245
246
247
248
249 @BeanTagAttribute(name="ensabledConditionControlNames",type= BeanTagAttribute.AttributeType.LISTVALUE)
250 public List<String> getEnabledWhenChangedPropertyNames() {
251 return enabledWhenChangedPropertyNames;
252 }
253
254
255
256
257
258
259 public void setEnabledWhenChangedPropertyNames(List<String> enabledWhenChangedPropertyNames) {
260 this.enabledWhenChangedPropertyNames = enabledWhenChangedPropertyNames;
261 }
262
263
264
265
266
267
268 protected void setDisabledExpression(String disabledExpression) {
269 this.disabledExpression = disabledExpression;
270 }
271
272
273
274
275
276
277 protected void setDisabledConditionJs(String disabledConditionJs) {
278 this.disabledConditionJs = disabledConditionJs;
279 }
280
281
282
283
284
285
286 protected void setDisabledConditionControlNames(List<String> disabledConditionControlNames) {
287 this.disabledConditionControlNames = disabledConditionControlNames;
288 }
289
290
291
292
293 @Override
294 protected <T> void copyProperties(T component) {
295 super.copyProperties(component);
296 ControlBase controlBaseCopy = (ControlBase) component;
297 controlBaseCopy.setTabIndex(this.tabIndex);
298 controlBaseCopy.setDisabled(this.disabled);
299 controlBaseCopy.setDisabledExpression(this.disabledExpression);
300 controlBaseCopy.setDisabledReason(this.disabledReason);
301 controlBaseCopy.setEvaluateDisabledOnKeyUp(this.evaluateDisabledOnKeyUp);
302 controlBaseCopy.setDisabledConditionJs(this.disabledConditionJs);
303
304 if (disabledConditionControlNames != null) {
305 controlBaseCopy.setDisabledConditionControlNames(new ArrayList<String>(this.disabledConditionControlNames));
306 }
307
308 if (disabledWhenChangedPropertyNames != null) {
309 controlBaseCopy.setDisabledWhenChangedPropertyNames(new ArrayList<String>(this.disabledWhenChangedPropertyNames));
310 }
311
312 if (enabledWhenChangedPropertyNames != null) {
313 controlBaseCopy.setEnabledWhenChangedPropertyNames(new ArrayList<String>(this.enabledWhenChangedPropertyNames));
314 }
315 }
316 }