1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.student.common.ui.client.configurable.mvc.multiplicity;
17
18 import java.util.ArrayList;
19 import java.util.HashMap;
20 import java.util.List;
21 import java.util.Map;
22
23 import org.kuali.student.common.ui.client.configurable.mvc.FieldDescriptor;
24 import org.kuali.student.common.ui.client.configurable.mvc.SectionTitle;
25 import org.kuali.student.common.ui.client.widgets.field.layout.element.MessageKeyInfo;
26 import org.kuali.student.r1.common.assembly.data.Metadata;
27 import org.kuali.student.r1.common.assembly.data.QueryPath;
28
29 import com.google.gwt.core.client.GWT;
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48 public class MultiplicityConfiguration {
49
50 private MultiplicityType multiplicityType;
51
52 private StyleType styleType;
53 private boolean updateable = false;
54
55 private String itemLabel;
56 private String addItemLabel;
57
58 private Metadata metaData;
59
60 private SectionTitle title;
61 private int defaultItemsCreated = 0;
62
63 int row = 0;
64
65 private FieldDescriptor parentFd;
66 private Map<Integer, List<MultiplicityFieldConfiguration>> fields = new HashMap<Integer, List<MultiplicityFieldConfiguration>>();
67 private Map<String, FieldDescriptor> fieldMap = new HashMap<String, FieldDescriptor>();
68 protected Map<String, String> concatenatedFields = new HashMap<String, String>();
69
70 private MultiplicityConfiguration nestedConfig ;
71 private MultiplicityGroup customMultiplicityGroup;
72 private boolean showHeaders;
73
74 public static enum MultiplicityType {GROUP, TABLE }
75 public static enum StyleType {
76 TOP_LEVEL_GROUP, SUB_LEVEL_GROUP, BORDERLESS_TABLE, BORDERED_TABLE
77 }
78
79 public MultiplicityConfiguration() {}
80
81
82
83
84
85
86
87
88
89
90 public MultiplicityConfiguration(MultiplicityType multiplicityType, StyleType styleType, Metadata metaData) {
91 init(multiplicityType, styleType, metaData);
92 }
93
94 public void init(MultiplicityType multiplicityType, StyleType styleType, Metadata metaData) {
95 this.multiplicityType = multiplicityType;
96 this.styleType = styleType;
97 this.metaData = metaData;
98 }
99
100
101
102
103
104 public void nextLine() {
105 row++;
106 }
107
108
109
110
111
112
113
114 public void addFieldConfiguration(MultiplicityFieldConfiguration fieldDescriptor) {
115
116 List<MultiplicityFieldConfiguration> fds;
117 if (fields.containsKey(row)) {
118 fds = fields.get(row);
119 }
120 else {
121 fds = new ArrayList<MultiplicityFieldConfiguration>();
122 }
123 fds.add(fieldDescriptor);
124 fields.put(row, fds);
125 }
126
127 public void setFields(Map<Integer, List<MultiplicityFieldConfiguration>> fields) {
128 if (fields == null || fields.isEmpty()) {
129 row = 0;
130 } else {
131 row = fields.size() - 1;
132 }
133 this.fields = fields;
134 }
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151 public void addConcatenatedField(MultiplicityFieldConfiguration parentField, String fieldKey){
152 addFieldConfiguration(parentField);
153 concatenatedFields.put(parentField.getFieldPath(), fieldKey);
154 }
155
156
157
158
159
160
161 public MultiplicityConfiguration copy() {
162 MultiplicityConfiguration copy = GWT.create(MultiplicityConfiguration.class);
163 copy.init(getMultiplicityType(), getStyleType(), getMetaData());
164 copy.setAddItemLabel(getAddItemLabel());
165 copy.setItemLabel(getItemLabel());
166 copy.setMetaData(getMetaData());
167 copy.setUpdateable(isUpdateable());
168 copy.setDefaultItemsCreated(getDefaultItemsCreated());
169 if (getNestedConfig() != null) {
170 copy.setNestedConfig(getNestedConfig().copy());
171 }
172 FieldDescriptor parent = new FieldDescriptor(getParentFd().getFieldKey(), getParentFd().getMessageKey(), getParentFd().getMetadata());
173 if(!getParentFd().isLabelShown()){
174 parent.hideLabel();
175 }
176 copy.setParent(parent);
177 for (Map.Entry<Integer, List<MultiplicityFieldConfiguration>> entry: getFields().entrySet()) {
178 List<MultiplicityFieldConfiguration> fields = entry.getValue();
179 for (MultiplicityFieldConfiguration fieldConfig : fields) {
180 MultiplicityFieldConfiguration newfieldConfig = new MultiplicityFieldConfiguration(fieldConfig.getFieldPath(), fieldConfig.getMessageKeyInfo(), fieldConfig.getMetadata(), fieldConfig.getFieldWidgetInitializer());
181 newfieldConfig.setOptional(fieldConfig.isOptional());
182 newfieldConfig.setModelWidgetBinding(fieldConfig.getModelWidgetBinding());
183 copy.addFieldConfiguration(newfieldConfig);
184 }
185 copy.nextLine();
186 }
187 return copy;
188 }
189
190 public MultiplicityType getMultiplicityType() {
191 return multiplicityType;
192 }
193
194
195
196
197
198
199
200 public void setMultiplicityType(MultiplicityType multiplicityType) {
201 this.multiplicityType = multiplicityType;
202 }
203
204 public FieldDescriptor getParentFd() {
205 return parentFd;
206 }
207
208
209
210
211
212
213 public void setParent(FieldDescriptor parentFd) {
214 this.parentFd = parentFd;
215 }
216
217
218
219 public Map<Integer, List<MultiplicityFieldConfiguration>> getFields() {
220 return fields;
221 }
222
223 public String getItemLabel() {
224 return itemLabel;
225 }
226
227
228
229
230
231 public void setItemLabel(String itemLabel) {
232 this.itemLabel = itemLabel;
233 }
234
235 public String getAddItemLabel() {
236 return addItemLabel;
237 }
238
239
240
241
242
243 public void setAddItemLabel(String addItemLabel) {
244 this.addItemLabel = addItemLabel;
245 }
246
247 public StyleType getStyleType() {
248 return styleType;
249 }
250
251 public void setStyleType(StyleType styleType) {
252 this.styleType = styleType;
253 }
254
255 public MultiplicityConfiguration getNestedConfig() {
256 return nestedConfig;
257 }
258
259
260
261
262
263
264
265 public void setNestedConfig(MultiplicityConfiguration config) {
266 this.nestedConfig = config;
267 }
268
269 public boolean isShowHeaders() {
270 return showHeaders;
271 }
272
273
274
275
276
277 public void setShowHeaders(boolean showHeaders) {
278 this.showHeaders = showHeaders;
279 }
280
281 public Map<String, String> getConcatenatedFields() {
282 return concatenatedFields;
283 }
284
285 public boolean isUpdateable() {
286 return updateable;
287 }
288
289
290
291
292
293
294
295 public void setUpdateable(boolean updateable) {
296 this.updateable = updateable;
297 }
298
299 public MultiplicityType getLayoutType() {
300 return multiplicityType;
301 }
302
303 public void setLayoutType(MultiplicityType multiplicityType) {
304 this.multiplicityType = multiplicityType;
305 }
306
307 public Metadata getMetaData() {
308 return metaData;
309 }
310
311 public void setMetaData(Metadata metaData) {
312 this.metaData = metaData;
313 }
314
315
316 public SectionTitle getTitle() {
317 return title;
318 }
319
320 public void setTitle(SectionTitle title) {
321 this.title = title;
322 }
323
324
325
326
327
328
329
330
331
332
333
334
335 public void setParent(String fieldKey, String messageKey, String parentPath, Metadata meta) {
336
337 QueryPath path = QueryPath.concat(parentPath, fieldKey);
338 FieldDescriptor fd = new FieldDescriptor(path.toString(), new MessageKeyInfo(messageKey), meta);
339 fd.getFieldElement().setRequired(false);
340
341 setParent(fd);
342
343 }
344
345
346
347
348
349
350
351
352
353
354
355
356 public void addField(String fieldKey, String messageKey, String parentPath, Metadata meta) {
357
358 QueryPath path = QueryPath.concat(parentPath, QueryPath.getWildCard(), fieldKey);
359
360 MultiplicityFieldConfiguration fieldConfig = new MultiplicityFieldConfiguration(path.toString(), new MessageKeyInfo(messageKey), meta, null);
361 fieldConfig.setRequired(false);
362 addFieldConfiguration(fieldConfig);
363 }
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383 public MultiplicityGroup getCustomMultiplicityGroup() {
384 return customMultiplicityGroup;
385 }
386
387 public void setCustomMultiplicityGroup(MultiplicityGroup customMultiplicityGroup) {
388 this.customMultiplicityGroup = customMultiplicityGroup;
389 }
390
391 public void setDefaultItemsCreated(int defaultItemsCreated) {
392 this.defaultItemsCreated = defaultItemsCreated;
393 }
394
395 public int getDefaultItemsCreated() {
396 return defaultItemsCreated;
397 }
398
399
400 }
401