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