1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.uif.container;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.kuali.rice.krad.datadictionary.validator.ErrorReport;
20 import org.kuali.rice.krad.datadictionary.validator.RDValidator;
21 import org.kuali.rice.krad.datadictionary.validator.TracerToken;
22 import org.kuali.rice.krad.uif.component.Component;
23 import org.kuali.rice.krad.uif.component.DataBinding;
24 import org.kuali.rice.krad.uif.field.Field;
25 import org.kuali.rice.krad.uif.field.FieldGroup;
26 import org.kuali.rice.krad.uif.view.View;
27 import org.kuali.rice.krad.uif.widget.Scrollpane;
28 import org.kuali.rice.krad.uif.widget.Disclosure;
29
30 import java.util.ArrayList;
31 import java.util.HashSet;
32 import java.util.List;
33 import java.util.Set;
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55 public class Group extends ContainerBase {
56 private static final long serialVersionUID = 7953641325356535509L;
57
58 private String fieldBindByNamePrefix;
59 private String fieldBindingObjectPath;
60
61 private Disclosure disclosure;
62 private Scrollpane scrollpane;
63
64 private List<? extends Component> items;
65
66
67
68
69 public Group() {
70 items = new ArrayList<Component>();
71 }
72
73
74
75
76
77
78
79
80
81
82
83 @Override
84 public void performInitialization(View view, Object model) {
85 super.performInitialization(view, model);
86
87 for (Component component : getItems()) {
88
89
90 if (component instanceof DataBinding) {
91 DataBinding dataBinding = (DataBinding) component;
92
93 if (StringUtils.isNotBlank(getFieldBindByNamePrefix())) {
94 String bindByNamePrefixToSet = getFieldBindByNamePrefix();
95
96 if (StringUtils.isNotBlank(dataBinding.getBindingInfo().getBindByNamePrefix())) {
97 bindByNamePrefixToSet += "." + dataBinding.getBindingInfo().getBindByNamePrefix();
98 }
99 dataBinding.getBindingInfo().setBindByNamePrefix(bindByNamePrefixToSet);
100 }
101
102 if (StringUtils.isNotBlank(fieldBindingObjectPath) &&
103 StringUtils.isBlank(dataBinding.getBindingInfo().getBindingObjectPath())) {
104 dataBinding.getBindingInfo().setBindingObjectPath(fieldBindingObjectPath);
105 }
106 }
107
108 else if (component instanceof FieldGroup) {
109 FieldGroup fieldGroup = (FieldGroup) component;
110
111 if (fieldGroup.getGroup() != null) {
112 if (StringUtils.isBlank(fieldGroup.getGroup().getFieldBindByNamePrefix())) {
113 fieldGroup.getGroup().setFieldBindByNamePrefix(fieldBindByNamePrefix);
114 }
115 if (StringUtils.isBlank(fieldGroup.getGroup().getFieldBindingObjectPath())) {
116 fieldGroup.getGroup().setFieldBindingObjectPath(fieldBindingObjectPath);
117 }
118 }
119 } else if (component instanceof Group) {
120 Group subGroup = (Group) component;
121 if (StringUtils.isNotBlank(getFieldBindByNamePrefix())) {
122 if (StringUtils.isNotBlank(subGroup.getFieldBindByNamePrefix())) {
123 subGroup.setFieldBindByNamePrefix(
124 getFieldBindByNamePrefix() + "." + subGroup.getFieldBindByNamePrefix());
125 } else {
126 subGroup.setFieldBindByNamePrefix(getFieldBindByNamePrefix());
127 }
128 }
129 if (StringUtils.isNotBlank(getFieldBindingObjectPath())) {
130 if (StringUtils.isNotBlank(subGroup.getFieldBindingObjectPath())) {
131 subGroup.setFieldBindingObjectPath(
132 getFieldBindingObjectPath() + "." + subGroup.getFieldBindingObjectPath());
133 } else {
134 subGroup.setFieldBindingObjectPath(getFieldBindingObjectPath());
135 }
136 }
137 }
138 }
139 }
140
141
142
143
144 @Override
145 public List<Component> getComponentsForLifecycle() {
146 List<Component> components = super.getComponentsForLifecycle();
147
148 components.add(disclosure);
149 components.add(scrollpane);
150
151 return components;
152 }
153
154
155
156
157 @Override
158 public Set<Class<? extends Component>> getSupportedComponents() {
159 Set<Class<? extends Component>> supportedComponents = new HashSet<Class<? extends Component>>();
160 supportedComponents.add(Field.class);
161 supportedComponents.add(Group.class);
162
163 return supportedComponents;
164 }
165
166
167
168
169 @Override
170 public String getComponentTypeName() {
171 return "group";
172 }
173
174
175
176
177
178
179
180
181
182
183
184
185
186 public String getFieldBindByNamePrefix() {
187 return this.fieldBindByNamePrefix;
188 }
189
190
191
192
193
194
195 public void setFieldBindByNamePrefix(String fieldBindByNamePrefix) {
196 this.fieldBindByNamePrefix = fieldBindByNamePrefix;
197 }
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214 public String getFieldBindingObjectPath() {
215 return this.fieldBindingObjectPath;
216 }
217
218
219
220
221
222
223 public void setFieldBindingObjectPath(String fieldBindingObjectPath) {
224 this.fieldBindingObjectPath = fieldBindingObjectPath;
225 }
226
227
228
229
230
231
232
233 public Disclosure getDisclosure() {
234 return this.disclosure;
235 }
236
237
238
239
240
241
242 public void setDisclosure(Disclosure disclosure) {
243 this.disclosure = disclosure;
244 }
245
246
247
248
249
250
251
252 public Scrollpane getScrollpane() {
253 return this.scrollpane;
254 }
255
256
257
258
259
260
261 public void setScrollpane(Scrollpane scrollpane) {
262 this.scrollpane = scrollpane;
263 }
264
265
266
267
268 @Override
269 public List<? extends Component> getItems() {
270 return this.items;
271 }
272
273
274
275
276
277
278 @Override
279 public void setItems(List<? extends Component> items) {
280 this.items = items;
281 }
282
283
284
285
286 @Override
287 public ArrayList<ErrorReport> completeValidation(TracerToken tracer){
288 ArrayList<ErrorReport> reports=new ArrayList<ErrorReport>();
289 tracer.addBean(this);
290
291
292 for(int i=0;i<getItems().size();i++){
293 if(getItems().get(i).getClass()==PageGroup.class || getItems().get(i).getClass()==NavigationGroup.class){
294 ErrorReport error = ErrorReport.createError("Items in Group cannot be PageGroup or NaviagtionGroup",tracer);
295 error.addCurrentValue("item("+i+").class ="+getItems().get(i).getClass());
296 reports.add(error);
297 }
298 }
299
300
301 if(getLayoutManager()==null){
302 if(RDValidator.checkExpressions(this,"layoutManager")){
303 ErrorReport error = ErrorReport.createError("LayoutManager must be set",tracer);
304 error.addCurrentValue("layoutManager = "+getLayoutManager());
305 reports.add(error);
306 }
307 }
308
309 reports.addAll(super.completeValidation(tracer.getCopy()));
310
311 return reports;
312 }
313 }