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 com.google.common.collect.Lists;
19 import org.kuali.rice.core.api.util.ConcreteKeyValue;
20 import org.kuali.rice.core.api.util.KeyValue;
21 import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute;
22 import org.kuali.rice.krad.uif.UifConstants;
23 import org.kuali.rice.krad.uif.component.Component;
24 import org.kuali.rice.krad.uif.container.Container;
25 import org.kuali.rice.krad.uif.element.Message;
26 import org.kuali.rice.krad.uif.field.InputField;
27 import org.kuali.rice.krad.uif.view.ExpressionEvaluator;
28 import org.kuali.rice.krad.uif.util.ComponentFactory;
29 import org.kuali.rice.krad.uif.util.ExpressionUtils;
30 import org.kuali.rice.krad.uif.util.KeyMessage;
31 import org.kuali.rice.krad.uif.util.UrlInfo;
32 import org.kuali.rice.krad.uif.util.UifKeyValueLocation;
33 import org.kuali.rice.krad.uif.view.View;
34
35 import java.util.ArrayList;
36 import java.util.List;
37
38
39
40
41
42
43 public abstract class MultiValueControlBase extends ControlBase implements MultiValueControl {
44 private static final long serialVersionUID = -8691367056245775455L;
45
46 private List<KeyValue> options;
47 private List<KeyMessage> richOptions;
48 private List<Component> inlineComponents;
49
50 private boolean locationSelect = false;
51
52 public MultiValueControlBase() {
53 super();
54 }
55
56
57
58
59
60
61
62 @Override
63 public void performApplyModel(View view, Object model, Component parent) {
64 super.performApplyModel(view, model, parent);
65
66 if (options != null && richOptions == null) {
67 richOptions = new ArrayList<KeyMessage>();
68
69 for (KeyValue option : options) {
70 Message message = ComponentFactory.getMessage();
71 view.assignComponentIds(message);
72 message.setMessageText(option.getValue());
73 message.setInlineComponents(inlineComponents);
74 message.setGenerateSpan(false);
75
76 view.getViewHelperService().performComponentInitialization(view, model, message);
77 richOptions.add(new KeyMessage(option.getKey(), option.getValue(), message));
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 ExpressionEvaluator expressionEvaluator =
93 view.getViewHelperService().getExpressionEvaluator();
94
95 if (options != null && !options.isEmpty()) {
96 for (KeyValue option : options) {
97 if (option instanceof UifKeyValueLocation) {
98 locationSelect = true;
99
100 UrlInfo url = ((UifKeyValueLocation) option).getLocation();
101
102 ExpressionUtils.populatePropertyExpressionsFromGraph(url, false);
103 expressionEvaluator.evaluateExpressionsOnConfigurable(view, url, view.getContext());
104 }
105 }
106 }
107
108 if (richOptions == null || richOptions.isEmpty()) {
109 return;
110 }
111
112
113
114 for (KeyMessage richOption : richOptions) {
115 List<Component> components = richOption.getMessage().getMessageComponentStructure();
116
117 if (components != null && !components.isEmpty()) {
118 for (Component c : components) {
119 if (c instanceof Container || c instanceof InputField) {
120 c.addDataAttribute(UifConstants.DataAttributes.PARENT, parent.getId());
121 }
122 }
123 }
124 }
125
126 }
127
128
129
130
131 @Override
132 public List<Component> getComponentsForLifecycle() {
133 List<Component> components = super.getComponentsForLifecycle();
134
135 if (richOptions != null) {
136 for (KeyMessage richOption : richOptions) {
137 components.add(richOption.getMessage());
138 }
139 }
140
141 return components;
142 }
143
144
145
146
147 @BeanTagAttribute(name = "options", type = BeanTagAttribute.AttributeType.LISTBEAN)
148 public List<KeyValue> getOptions() {
149 return this.options;
150 }
151
152
153
154
155 public void setOptions(List<KeyValue> options) {
156 this.options = options;
157 }
158
159
160
161
162
163
164
165 @BeanTagAttribute(name = "inlineComponents", type = BeanTagAttribute.AttributeType.LISTBEAN)
166 public List<Component> getInlineComponents() {
167 return inlineComponents;
168 }
169
170
171
172
173
174
175
176 public void setInlineComponents(List<Component> inlineComponents) {
177 this.inlineComponents = inlineComponents;
178 }
179
180
181
182
183 public List<KeyMessage> getRichOptions() {
184 return richOptions;
185 }
186
187
188
189
190
191
192
193
194
195
196 public void setRichOptions(List<KeyMessage> richOptions) {
197 this.richOptions = richOptions;
198 }
199
200
201
202
203
204
205 public boolean isLocationSelect() {
206 return locationSelect;
207 }
208
209 public void setLocationSelect(boolean locationSelect) {
210 this.locationSelect = locationSelect;
211 }
212
213
214
215
216 @Override
217 protected <T> void copyProperties(T component) {
218 super.copyProperties(component);
219 MultiValueControlBase multiValueControlBaseCopy = (MultiValueControlBase) component;
220
221 if(options != null) {
222 List<KeyValue> optionsCopy = Lists.newArrayListWithExpectedSize(options.size());
223 for(KeyValue option : options) {
224 KeyValue keyValue = null;
225 keyValue = new ConcreteKeyValue(option.getKey(), option.getValue());
226 optionsCopy.add(keyValue);
227 }
228 multiValueControlBaseCopy.setOptions(optionsCopy);
229 }
230
231 if(richOptions != null) {
232 List<KeyMessage> richOptionsCopy = Lists.newArrayListWithExpectedSize(richOptions.size());
233 for(KeyMessage richOption : richOptions) {
234 KeyMessage keyMessage = new KeyMessage(richOption.getKey(),richOption.getValue(),richOption.getMessage());
235 richOptionsCopy.add(keyMessage);
236 }
237 multiValueControlBaseCopy.setRichOptions(richOptionsCopy);
238 }
239
240 if(inlineComponents != null) {
241 List<Component> inlineComponentsCopy = Lists.newArrayListWithExpectedSize(inlineComponents.size());
242 for(Component inlineComponent : inlineComponents) {
243 inlineComponentsCopy.add((Component)inlineComponent.copy());
244 }
245 multiValueControlBaseCopy.setInlineComponents(inlineComponentsCopy);
246 }
247
248 multiValueControlBaseCopy.setLocationSelect(this.isLocationSelect());
249 }
250 }