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