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 java.util.ArrayList;
19 import java.util.List;
20
21 import org.apache.commons.lang.StringUtils;
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.validator.ValidationTrace;
25 import org.kuali.rice.krad.uif.UifConstants;
26 import org.kuali.rice.krad.uif.component.Component;
27 import org.kuali.rice.krad.uif.element.ContentElementBase;
28 import org.kuali.rice.krad.uif.lifecycle.ViewLifecycle;
29 import org.kuali.rice.krad.uif.util.LifecycleElement;
30 import org.kuali.rice.krad.uif.view.ExpressionEvaluator;
31 import org.kuali.rice.krad.uif.view.View;
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 @Override
71 public void performApplyModel(Object model, LifecycleElement parent) {
72 super.performApplyModel(model, parent);
73
74 disabledExpression = this.getPropertyExpression("disabled");
75 if (disabledExpression != null) {
76 ExpressionEvaluator expressionEvaluator = ViewLifecycle.getExpressionEvaluator();
77
78 disabledExpression = expressionEvaluator.replaceBindingPrefixes(ViewLifecycle.getView(), this,
79 disabledExpression);
80 disabled = (Boolean) expressionEvaluator.evaluateExpression(this.getContext(), disabledExpression);
81 }
82 }
83
84
85
86
87
88
89
90
91 @Override
92 public void performFinalize(Object model, LifecycleElement parent) {
93 super.performFinalize(model, parent);
94
95 ExpressionEvaluator expressionEvaluator = ViewLifecycle.getExpressionEvaluator();
96
97 if (StringUtils.isNotEmpty(disabledExpression)
98 && !disabledExpression.equalsIgnoreCase("true")
99 && !disabledExpression.equalsIgnoreCase("false")) {
100 disabledConditionControlNames = new ArrayList<String>();
101 disabledConditionJs = expressionEvaluator.parseExpression(disabledExpression, disabledConditionControlNames,
102 this.getContext());
103 }
104
105 View view = ViewLifecycle.getView();
106 List<String> adjustedDisablePropertyNames = new ArrayList<String>();
107 for (String propertyName : disabledWhenChangedPropertyNames) {
108 adjustedDisablePropertyNames.add(expressionEvaluator.replaceBindingPrefixes(view, this, propertyName));
109 }
110 disabledWhenChangedPropertyNames = adjustedDisablePropertyNames;
111
112 List<String> adjustedEnablePropertyNames = new ArrayList<String>();
113 for (String propertyName : enabledWhenChangedPropertyNames) {
114 adjustedEnablePropertyNames.add(expressionEvaluator.replaceBindingPrefixes(view, this, propertyName));
115 }
116 enabledWhenChangedPropertyNames = adjustedEnablePropertyNames;
117
118
119 this.addDataAttribute(UifConstants.DataAttributes.ROLE, UifConstants.RoleTypes.CONTROL);
120 }
121
122
123
124
125 @Override
126 public final String getComponentTypeName() {
127 return "control";
128 }
129
130
131
132
133 @BeanTagAttribute(name = "tabIndex")
134 public int getTabIndex() {
135 return this.tabIndex;
136 }
137
138
139
140
141 public void setTabIndex(int tabIndex) {
142 this.tabIndex = tabIndex;
143 }
144
145
146
147
148 @BeanTagAttribute(name = "disabled")
149 public boolean isDisabled() {
150 return disabled;
151 }
152
153
154
155
156 public void setDisabled(boolean disabled) {
157 this.disabled = disabled;
158 }
159
160
161
162
163 @BeanTagAttribute(name = "disabledReason")
164 public String getDisabledReason() {
165 return disabledReason;
166 }
167
168
169
170
171 public void setDisabledReason(String disabledReason) {
172 this.disabledReason = disabledReason;
173 }
174
175
176
177
178
179
180 @BeanTagAttribute(name = "evaluateDisabledOnKeyUp")
181 public boolean isEvaluateDisabledOnKeyUp() {
182 return evaluateDisabledOnKeyUp;
183 }
184
185
186
187
188
189
190 public void setEvaluateDisabledOnKeyUp(boolean evaluateDisabledOnKeyUp) {
191 this.evaluateDisabledOnKeyUp = evaluateDisabledOnKeyUp;
192 }
193
194
195
196
197
198
199 public String getDisabledConditionJs() {
200 return disabledConditionJs;
201 }
202
203
204
205
206
207
208 public List<String> getDisabledConditionControlNames() {
209 return disabledConditionControlNames;
210 }
211
212
213
214
215
216
217 @BeanTagAttribute(name = "disabledWhenChangedPropertyNames", type = BeanTagAttribute.AttributeType.LISTVALUE)
218 public List<String> getDisabledWhenChangedPropertyNames() {
219 return disabledWhenChangedPropertyNames;
220 }
221
222
223
224
225
226
227 public void setDisabledWhenChangedPropertyNames(List<String> disabledWhenChangedPropertyNames) {
228 this.disabledWhenChangedPropertyNames = disabledWhenChangedPropertyNames;
229 }
230
231
232
233
234
235
236 @BeanTagAttribute(name = "ensabledConditionControlNames", type = BeanTagAttribute.AttributeType.LISTVALUE)
237 public List<String> getEnabledWhenChangedPropertyNames() {
238 return enabledWhenChangedPropertyNames;
239 }
240
241
242
243
244
245
246 public void setEnabledWhenChangedPropertyNames(List<String> enabledWhenChangedPropertyNames) {
247 this.enabledWhenChangedPropertyNames = enabledWhenChangedPropertyNames;
248 }
249
250
251
252
253
254
255 protected void setDisabledExpression(String disabledExpression) {
256 this.disabledExpression = disabledExpression;
257 }
258
259
260
261
262
263
264 protected void setDisabledConditionJs(String disabledConditionJs) {
265 this.disabledConditionJs = disabledConditionJs;
266 }
267
268
269
270
271
272
273 protected void setDisabledConditionControlNames(List<String> disabledConditionControlNames) {
274 this.disabledConditionControlNames = disabledConditionControlNames;
275 }
276
277
278
279
280 @Override
281 public void completeValidation(ValidationTrace tracer) {
282 tracer.addBean(this);
283
284 super.completeValidation(tracer.getCopy());
285 }
286 }