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