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 | |
import java.util.Set; |
23 | |
import java.util.Map.Entry; |
24 | |
|
25 | |
import org.kuali.student.common.assembly.data.Data; |
26 | |
import org.kuali.student.common.assembly.data.MetadataInterrogator; |
27 | |
import org.kuali.student.common.assembly.data.QueryPath; |
28 | |
import org.kuali.student.common.ui.client.configurable.mvc.FieldDescriptor; |
29 | |
import org.kuali.student.common.ui.client.configurable.mvc.binding.ModelWidgetBinding; |
30 | |
import org.kuali.student.common.ui.client.configurable.mvc.sections.BaseSection; |
31 | |
import org.kuali.student.common.ui.client.configurable.mvc.sections.GroupSection; |
32 | |
import org.kuali.student.common.ui.client.configurable.mvc.sections.MultiplicitySection; |
33 | |
import org.kuali.student.common.ui.client.configurable.mvc.sections.Section; |
34 | |
import org.kuali.student.common.ui.client.configurable.mvc.sections.SwapSection; |
35 | |
import org.kuali.student.common.ui.client.configurable.mvc.sections.VerticalSection; |
36 | |
import org.kuali.student.common.ui.client.mvc.Callback; |
37 | |
import org.kuali.student.common.ui.client.mvc.DataModel; |
38 | |
import org.kuali.student.common.ui.client.widgets.KSButton; |
39 | |
import org.kuali.student.common.ui.client.widgets.KSButtonAbstract.ButtonStyle; |
40 | |
import org.kuali.student.common.ui.client.widgets.ListOfStringWidget; |
41 | |
import org.kuali.student.common.ui.client.widgets.list.KSRadioButtonList; |
42 | |
import org.kuali.student.common.ui.client.widgets.list.KSSelectItemWidgetAbstract; |
43 | |
import org.kuali.student.common.ui.client.widgets.list.ListItems; |
44 | |
import org.kuali.student.common.ui.client.widgets.list.SelectionChangeEvent; |
45 | |
import org.kuali.student.common.ui.client.widgets.list.SelectionChangeHandler; |
46 | |
import org.kuali.student.common.ui.client.widgets.list.impl.KSRadioButtonListImpl; |
47 | |
import org.kuali.student.common.ui.client.widgets.list.impl.SimpleListItems; |
48 | |
import org.kuali.student.common.ui.client.widgets.search.KSPicker; |
49 | |
|
50 | |
import com.google.gwt.core.client.GWT; |
51 | |
import com.google.gwt.event.dom.client.BlurHandler; |
52 | |
import com.google.gwt.event.dom.client.ClickEvent; |
53 | |
import com.google.gwt.event.dom.client.ClickHandler; |
54 | |
import com.google.gwt.event.dom.client.FocusHandler; |
55 | |
import com.google.gwt.event.shared.HandlerRegistration; |
56 | |
import com.google.gwt.user.client.ui.Composite; |
57 | |
import com.google.gwt.user.client.ui.FlowPanel; |
58 | |
import com.google.gwt.user.client.ui.Widget; |
59 | |
|
60 | |
|
61 | 0 | public class MultiplicityGroup extends Composite { |
62 | |
|
63 | |
private MultiplicityConfiguration config; |
64 | |
|
65 | 0 | private List<MultiplicityGroupItem> items = new ArrayList<MultiplicityGroupItem>(); |
66 | 0 | private List<MultiplicityGroupItem> removed = new ArrayList<MultiplicityGroupItem>(); |
67 | |
|
68 | 0 | private FlowPanel mainPanel = new FlowPanel(); |
69 | 0 | private FlowPanel itemsPanel = new FlowPanel(); |
70 | 0 | private boolean loaded = false; |
71 | 0 | private int itemCount = 0; |
72 | |
private String parentPath; |
73 | 0 | private boolean isDirty = false; |
74 | |
|
75 | |
private Map<SwapCompositeCondition, List<SwapCompositeConditionFieldConfig>> swappableFieldsDefinition; |
76 | |
private List<String> deletionParentKeys; |
77 | |
|
78 | 0 | public MultiplicityGroup() { |
79 | 0 | } |
80 | |
|
81 | |
public MultiplicityGroup(MultiplicityConfiguration config, |
82 | |
Map<SwapCompositeCondition, List<SwapCompositeConditionFieldConfig>> swappableFieldsDefinition, |
83 | 0 | List<String> deletionParentKeys) { |
84 | 0 | this.config = config; |
85 | 0 | initWidget(mainPanel); |
86 | 0 | this.swappableFieldsDefinition = swappableFieldsDefinition; |
87 | 0 | this.deletionParentKeys = deletionParentKeys; |
88 | 0 | } |
89 | |
|
90 | |
|
91 | |
|
92 | |
|
93 | |
|
94 | |
|
95 | |
|
96 | |
|
97 | |
|
98 | |
|
99 | |
|
100 | |
|
101 | 0 | public MultiplicityGroup(MultiplicityConfiguration config){ |
102 | 0 | this.config = config; |
103 | 0 | initWidget(mainPanel); |
104 | 0 | } |
105 | |
|
106 | 0 | protected Callback<MultiplicityGroupItem> removeCallback = new Callback<MultiplicityGroupItem>(){ |
107 | |
|
108 | |
public void exec(MultiplicityGroupItem itemToRemove) { |
109 | 0 | itemToRemove.setDeleted(true); |
110 | 0 | removed.add(itemToRemove); |
111 | 0 | itemsPanel.remove(itemToRemove); |
112 | 0 | } |
113 | |
}; |
114 | |
|
115 | |
public void onLoad() { |
116 | 0 | if (!loaded) { |
117 | 0 | mainPanel.add(itemsPanel); |
118 | |
|
119 | 0 | if(config.isUpdateable()){ |
120 | 0 | Widget addWidget = generateAddWidget(); |
121 | 0 | mainPanel.add(addWidget); |
122 | |
} |
123 | |
|
124 | 0 | loaded = true; |
125 | |
} |
126 | |
|
127 | 0 | if (!loaded || itemCount == 0){ |
128 | 0 | Integer minOccurs = MetadataInterrogator.getLargestMinOccurs(config.getMetaData()); |
129 | |
|
130 | 0 | if (minOccurs != null && minOccurs > 0) { |
131 | 0 | for (int i=0; i < minOccurs; i++){ |
132 | 0 | createItem(); |
133 | |
} |
134 | |
} |
135 | 0 | else if(config.getDefaultItemsCreated() != 0){ |
136 | 0 | for (int i=0; i < config.getDefaultItemsCreated(); i++){ |
137 | 0 | createItem(); |
138 | |
} |
139 | |
} |
140 | |
|
141 | |
} |
142 | 0 | } |
143 | |
|
144 | |
private Widget generateAddWidget() { |
145 | |
KSButton addWidget; |
146 | 0 | if(config.getStyleType() == MultiplicityConfiguration.StyleType.TOP_LEVEL_GROUP){ |
147 | 0 | addWidget = new KSButton(config.getAddItemLabel(), ButtonStyle.FORM_LARGE); |
148 | |
} |
149 | |
else{ |
150 | 0 | addWidget = new KSButton(config.getAddItemLabel(), ButtonStyle.FORM_SMALL); |
151 | |
} |
152 | 0 | addWidget.addClickHandler(new ClickHandler(){ |
153 | |
public void onClick(ClickEvent event) { |
154 | 0 | createItem(); |
155 | 0 | } |
156 | |
}); |
157 | 0 | return addWidget; |
158 | |
} |
159 | |
|
160 | |
|
161 | |
|
162 | |
|
163 | |
|
164 | |
|
165 | |
public MultiplicityGroupItem createItem(){ |
166 | |
|
167 | 0 | itemCount++; |
168 | |
|
169 | 0 | MultiplicityGroupItem item = new MultiplicityGroupItem(config.getItemLabel() + " " + itemCount, config.getStyleType(), config.isUpdateable()); |
170 | |
|
171 | 0 | Widget itemWidget = createWidget(); |
172 | |
|
173 | 0 | if (item != null){ |
174 | 0 | item.setItemKey(new Integer(itemCount -1)); |
175 | 0 | item.setItemWidget(itemWidget); |
176 | 0 | item.setRemoveCallback(removeCallback); |
177 | 0 | } else if (itemWidget instanceof MultiplicityGroupItem){ |
178 | 0 | item = (MultiplicityGroupItem)itemWidget; |
179 | 0 | item.setItemKey(new Integer(itemCount -1)); |
180 | |
} |
181 | 0 | items.add(item); |
182 | 0 | item.redraw(); |
183 | 0 | itemsPanel.add(item); |
184 | 0 | isDirty = true; |
185 | |
|
186 | 0 | return item; |
187 | |
} |
188 | |
|
189 | |
public FlowPanel getItemsPanel() { |
190 | 0 | return itemsPanel; |
191 | |
} |
192 | |
|
193 | |
private Widget createWidget() { |
194 | |
|
195 | 0 | GroupSection section = new GroupSection(); |
196 | 0 | final SwappableFieldsHelper helper = new SwappableFieldsHelper(); |
197 | |
|
198 | 0 | final Map<String, String> helperFieldKeys = new HashMap<String, String>(); |
199 | 0 | SwapSection swapSection = null; |
200 | |
|
201 | |
|
202 | |
|
203 | 0 | if (config.getNestedConfig() != null) { |
204 | 0 | MultiplicitySection ms = new MultiplicitySection(config.getNestedConfig().copy()); |
205 | 0 | String p = config.getNestedConfig().getParentFd().getFieldKey().replace('*', Character.forDigit(itemCount-1, 10)); |
206 | 0 | ms.setParentPath(p); |
207 | 0 | section.addSection(ms); |
208 | 0 | } |
209 | |
else { |
210 | 0 | for (Integer row : config.getFields().keySet()) { |
211 | 0 | List<MultiplicityFieldConfiguration> fieldConfigs = config.getFields().get(row); |
212 | 0 | for (MultiplicityFieldConfiguration fieldConfig : fieldConfigs) { |
213 | |
|
214 | 0 | FieldDescriptor newfd = null; |
215 | 0 | Widget fieldWidget = null; |
216 | 0 | if (fieldConfig.getFieldWidgetInitializer() != null) { |
217 | 0 | fieldWidget = fieldConfig.getFieldWidgetInitializer().getNewWidget(); |
218 | 0 | ModelWidgetBinding mwb = fieldConfig.getFieldWidgetInitializer() |
219 | |
.getModelWidgetBindingInstance(); |
220 | 0 | newfd = new FieldDescriptor( |
221 | |
translatePath(fieldConfig.getFieldPath()), |
222 | |
fieldConfig.getMessageKeyInfo(), |
223 | |
fieldConfig.getMetadata(), |
224 | |
fieldWidget); |
225 | 0 | newfd.setWidgetBinding(mwb); |
226 | 0 | } else { |
227 | 0 | newfd = new FieldDescriptor( |
228 | |
translatePath(fieldConfig.getFieldPath()), |
229 | |
fieldConfig.getMessageKeyInfo(), |
230 | |
fieldConfig.getMetadata()); |
231 | 0 | fieldWidget = newfd.getFieldWidget(); |
232 | |
} |
233 | 0 | newfd.getFieldElement().setRequired(fieldConfig.isRequired()); |
234 | 0 | section.addField(newfd); |
235 | 0 | helperFieldKeys.put(fieldConfig.getFieldPath(), newfd.getFieldKey()); |
236 | |
|
237 | |
|
238 | |
|
239 | 0 | if (fieldWidget instanceof KSSelectItemWidgetAbstract) { |
240 | 0 | ((KSSelectItemWidgetAbstract)fieldWidget).addSelectionChangeHandler(new SelectionChangeHandler() { |
241 | |
@Override |
242 | |
public void onSelectionChange(SelectionChangeEvent event) { |
243 | 0 | helper.updateFieldDisplay(); |
244 | 0 | } |
245 | |
}); |
246 | 0 | } else if (fieldWidget instanceof KSPicker) { |
247 | 0 | Widget inputWidget = ((KSPicker)fieldWidget).getInputWidget(); |
248 | 0 | if (inputWidget instanceof KSSelectItemWidgetAbstract) { |
249 | 0 | ((KSSelectItemWidgetAbstract)inputWidget).addSelectionChangeHandler(new SelectionChangeHandler() { |
250 | |
@Override |
251 | |
public void onSelectionChange(SelectionChangeEvent event) { |
252 | 0 | helper.updateFieldDisplay(); |
253 | 0 | } |
254 | |
}); |
255 | |
} |
256 | |
} |
257 | 0 | } |
258 | 0 | section.nextLine(); |
259 | 0 | } |
260 | 0 | if (swappableFieldsDefinition != null) { |
261 | 0 | ConditionChoices conditionChoices = new ConditionChoices( |
262 | |
new ArrayList<SwapCompositeCondition>( |
263 | |
swappableFieldsDefinition.keySet())); |
264 | 0 | List<String> newDeletionParentKeys = null; |
265 | 0 | swapSection = new SwapSection(conditionChoices); |
266 | 0 | if (deletionParentKeys != null) { |
267 | 0 | for (String deletionParentKey : deletionParentKeys) { |
268 | 0 | newDeletionParentKeys = (newDeletionParentKeys == null)? |
269 | |
new ArrayList<String>() : newDeletionParentKeys; |
270 | 0 | newDeletionParentKeys.add(translatePath(deletionParentKey)); |
271 | |
} |
272 | |
} |
273 | 0 | swapSection.setDeletionParentKey(newDeletionParentKeys); |
274 | 0 | helper.setConditionChoices(conditionChoices); |
275 | |
|
276 | |
|
277 | 0 | for (Entry<SwapCompositeCondition, List<SwapCompositeConditionFieldConfig>> entry : swappableFieldsDefinition.entrySet()) { |
278 | 0 | SwapCompositeCondition condition = entry.getKey(); |
279 | 0 | List<SwapCompositeConditionFieldConfig> fieldConfigs = entry.getValue(); |
280 | 0 | Section conditionSection = new VerticalSection(); |
281 | 0 | if (fieldConfigs != null) { |
282 | 0 | for (SwapCompositeConditionFieldConfig conditionFieldConfig : fieldConfigs) { |
283 | 0 | if (conditionFieldConfig.useMultiplicity()) { |
284 | 0 | MultiplicityConfiguration newSubMultiplicityConfig = |
285 | |
configSwappableMultiplicitySection( |
286 | |
conditionFieldConfig.getMultiplicityConfiguration()); |
287 | 0 | MultiplicitySection subMultiplicitySection = |
288 | |
new MultiplicitySection(newSubMultiplicityConfig); |
289 | 0 | conditionSection.addSection(subMultiplicitySection); |
290 | 0 | } else { |
291 | 0 | MultiplicityFieldConfiguration fieldConfig = |
292 | |
conditionFieldConfig.getMultiplicityFieldConfiguration(); |
293 | 0 | FieldDescriptor concreteFieldDescriptor = new FieldDescriptor( |
294 | |
translatePath(fieldConfig.getFieldPath()), |
295 | |
fieldConfig.getMessageKeyInfo(), |
296 | |
fieldConfig.getMetadata()); |
297 | 0 | concreteFieldDescriptor.getFieldElement().setRequired(fieldConfig.isRequired()); |
298 | 0 | if (fieldConfig.getFieldWidgetInitializer() != null) { |
299 | 0 | Widget fieldWidget = fieldConfig.getFieldWidgetInitializer().getNewWidget(); |
300 | 0 | ModelWidgetBinding mwb = fieldConfig.getFieldWidgetInitializer() |
301 | |
.getModelWidgetBindingInstance(); |
302 | 0 | concreteFieldDescriptor.setFieldWidget(fieldWidget); |
303 | 0 | if(fieldWidget instanceof ListOfStringWidget){ |
304 | 0 | ((ListOfStringWidget)fieldWidget).setFd(concreteFieldDescriptor); |
305 | |
} |
306 | |
|
307 | 0 | concreteFieldDescriptor.setWidgetBinding(mwb); |
308 | |
} |
309 | 0 | conditionSection.addField(concreteFieldDescriptor); |
310 | 0 | helperFieldKeys.put(fieldConfig.getFieldPath(), translatePath(fieldConfig.getFieldPath())); |
311 | 0 | } |
312 | |
} |
313 | |
} |
314 | 0 | swapSection.addSection(conditionSection, condition.getConditionId()); |
315 | 0 | } |
316 | 0 | section.addWidget(conditionChoices); |
317 | 0 | section.addSection(swapSection); |
318 | 0 | helper.setSwapSection(swapSection); |
319 | |
} |
320 | |
|
321 | 0 | helper.setParentSection(section); |
322 | 0 | helper.setSwappableFieldsDefinition(swappableFieldsDefinition); |
323 | 0 | helper.setHelperFieldKeys(helperFieldKeys); |
324 | |
} |
325 | 0 | return section; |
326 | |
} |
327 | |
|
328 | |
public MultiplicityConfiguration configSwappableMultiplicitySection(MultiplicityConfiguration origConfig) { |
329 | 0 | MultiplicityConfiguration newSubMultiplicityConfig = |
330 | |
origConfig.copy(); |
331 | |
|
332 | 0 | FieldDescriptor parentFd = origConfig.getParentFd(); |
333 | 0 | FieldDescriptor subMultParentConfig = |
334 | |
new FieldDescriptor( |
335 | |
translatePath(parentFd.getFieldKey()), |
336 | |
parentFd.getMessageKey(), |
337 | |
parentFd.getMetadata()); |
338 | 0 | subMultParentConfig.getFieldElement().setRequired(parentFd.getFieldElement().isRequired()); |
339 | 0 | newSubMultiplicityConfig.setParent(subMultParentConfig); |
340 | 0 | Map<Integer, List<MultiplicityFieldConfiguration>> fieldConfigsMap = newSubMultiplicityConfig.getFields(); |
341 | 0 | Map<Integer, List<MultiplicityFieldConfiguration>> newFieldsMap = new HashMap<Integer, List<MultiplicityFieldConfiguration>>(); |
342 | 0 | int lineCounter = 0; |
343 | 0 | if (fieldConfigsMap != null) { |
344 | 0 | for (List<MultiplicityFieldConfiguration> fieldConfigsInLine : fieldConfigsMap.values()) { |
345 | 0 | List<MultiplicityFieldConfiguration> newFieldConfigs = new ArrayList<MultiplicityFieldConfiguration>(); |
346 | 0 | for (MultiplicityFieldConfiguration fieldConfig : fieldConfigsInLine) { |
347 | 0 | String configParentKey = (parentFd.getFieldKey() == null)? "" : parentFd.getFieldKey(); |
348 | 0 | String configFieldKey = (fieldConfig.getFieldPath() == null)? "" : fieldConfig.getFieldPath(); |
349 | 0 | String trimmedFieldKey = null; |
350 | 0 | MultiplicityFieldConfiguration newFieldConfig = null; |
351 | 0 | trimmedFieldKey = configFieldKey.substring(configParentKey.length()); |
352 | |
|
353 | 0 | QueryPath fieldPath = QueryPath.concat(subMultParentConfig.getFieldKey(), |
354 | |
trimmedFieldKey);; |
355 | 0 | newFieldConfig = new MultiplicityFieldConfiguration( |
356 | |
fieldPath.toString(), fieldConfig.getMessageKeyInfo(), fieldConfig.getMetadata(), |
357 | |
fieldConfig.getFieldWidgetInitializer()); |
358 | 0 | newFieldConfig.setRequired(fieldConfig.isRequired()); |
359 | 0 | newFieldConfigs.add(newFieldConfig); |
360 | |
|
361 | 0 | } |
362 | 0 | newFieldsMap.put(Integer.valueOf(lineCounter), newFieldConfigs); |
363 | 0 | lineCounter++; |
364 | 0 | } |
365 | |
} |
366 | 0 | newSubMultiplicityConfig.setFields(newFieldsMap); |
367 | |
|
368 | 0 | return newSubMultiplicityConfig; |
369 | |
} |
370 | |
|
371 | |
public String translatePath(String path) { |
372 | |
String fieldPath; |
373 | 0 | if (parentPath != null) { |
374 | 0 | QueryPath parent = QueryPath.concat(parentPath); |
375 | 0 | int i = parent.size(); |
376 | |
|
377 | 0 | QueryPath subPath = QueryPath.concat(path); |
378 | 0 | String itemPath = subPath.subPath(i, subPath.size()).toString(); |
379 | |
|
380 | 0 | QueryPath qp = QueryPath.concat(parentPath, itemPath); |
381 | 0 | fieldPath = qp.toString(); |
382 | 0 | } |
383 | |
else { |
384 | 0 | fieldPath = path; |
385 | |
} |
386 | |
|
387 | 0 | fieldPath = fieldPath.replace('*', Character.forDigit(itemCount-1, 10)); |
388 | 0 | return fieldPath; |
389 | |
} |
390 | |
|
391 | |
|
392 | |
public void clear(){ |
393 | 0 | itemsPanel.clear(); |
394 | 0 | items.clear(); |
395 | 0 | removed.clear(); |
396 | 0 | itemCount = 0; |
397 | 0 | } |
398 | |
|
399 | |
public void redraw(){ |
400 | 0 | for (MultiplicityGroupItem item:items){ |
401 | 0 | item.redraw(); |
402 | |
} |
403 | 0 | } |
404 | |
|
405 | |
public void incrementItemKey(){ |
406 | 0 | itemCount++; |
407 | 0 | } |
408 | |
|
409 | |
|
410 | |
|
411 | |
|
412 | |
|
413 | |
|
414 | |
public int getAddItemKey(){ |
415 | 0 | return itemCount-1; |
416 | |
} |
417 | |
|
418 | |
|
419 | |
public List<MultiplicityGroupItem> getItems() { |
420 | 0 | return items; |
421 | |
} |
422 | |
|
423 | |
public List<MultiplicityGroupItem> getRemovedItems() { |
424 | 0 | return removed; |
425 | |
} |
426 | |
|
427 | |
public int getItemCount() { |
428 | 0 | return itemCount; |
429 | |
} |
430 | |
|
431 | |
public void setItemCount(int itemCount) { |
432 | 0 | this.itemCount = itemCount; |
433 | 0 | } |
434 | |
|
435 | |
public String getParentPath() { |
436 | 0 | return parentPath; |
437 | |
} |
438 | |
|
439 | |
|
440 | |
|
441 | |
|
442 | |
|
443 | |
|
444 | |
public void setParentPath(String parentPath) { |
445 | 0 | this.parentPath = parentPath; |
446 | 0 | } |
447 | |
|
448 | |
public MultiplicityConfiguration getConfig() { |
449 | 0 | return config; |
450 | |
} |
451 | |
|
452 | |
public void setConfig(MultiplicityConfiguration config) { |
453 | 0 | this.config = config; |
454 | 0 | } |
455 | |
|
456 | |
public void resetDirtyFlags() { |
457 | 0 | isDirty = false; |
458 | 0 | for (MultiplicityGroupItem item:items){ |
459 | 0 | item.resetDirtyFlags(); |
460 | 0 | Widget itemWidget = item.getItemWidget(); |
461 | 0 | if (itemWidget instanceof BaseSection){ |
462 | 0 | ((BaseSection)itemWidget).resetDirtyFlags(); |
463 | |
} |
464 | 0 | } |
465 | 0 | } |
466 | |
|
467 | |
public boolean isDirty(){ |
468 | 0 | isDirty = false; |
469 | 0 | if (removed != null && !removed.isEmpty()){ |
470 | 0 | isDirty = true; |
471 | |
} else { |
472 | 0 | for (MultiplicityGroupItem item:items){ |
473 | 0 | if (item.isDirty()){ |
474 | 0 | isDirty = true; |
475 | 0 | break; |
476 | |
} else { |
477 | 0 | Widget itemWidget = item.getItemWidget(); |
478 | 0 | if (itemWidget instanceof BaseSection && ((BaseSection)itemWidget).isDirty()){ |
479 | 0 | isDirty = true; |
480 | 0 | break; |
481 | |
} |
482 | 0 | } |
483 | |
} |
484 | |
} |
485 | 0 | return isDirty; |
486 | |
} |
487 | |
|
488 | |
public void setIsDirty(boolean dirty){ |
489 | 0 | isDirty = dirty; |
490 | 0 | } |
491 | |
|
492 | |
public class ConditionChoices extends KSRadioButtonList{ |
493 | 0 | private KSRadioButtonListImpl selectItemWidget = GWT.create(KSRadioButtonListImpl.class); |
494 | 0 | public ConditionChoices(List<SwapCompositeCondition> conditions){ |
495 | 0 | SimpleListItems choices = new SimpleListItems(); |
496 | 0 | if (conditions != null) { |
497 | 0 | for (SwapCompositeCondition condition : conditions) { |
498 | 0 | choices.addItem(condition.getConditionId(), condition.getConditionId()); |
499 | |
} |
500 | |
} |
501 | 0 | selectItemWidget.setListItems(choices); |
502 | 0 | } |
503 | |
|
504 | |
|
505 | |
|
506 | |
|
507 | |
public void deSelectItem(String id) { |
508 | 0 | selectItemWidget.deSelectItem(id); |
509 | 0 | } |
510 | |
|
511 | |
|
512 | |
|
513 | |
|
514 | |
public List<String> getSelectedItems() { |
515 | 0 | return selectItemWidget.getSelectedItems(); |
516 | |
} |
517 | |
|
518 | |
|
519 | |
|
520 | |
|
521 | |
public void selectItem(String id) { |
522 | 0 | selectItemWidget.selectItem(id); |
523 | 0 | } |
524 | |
|
525 | |
public void setListItems(ListItems listItems) { |
526 | 0 | selectItemWidget.setListItems(listItems); |
527 | 0 | } |
528 | |
|
529 | |
|
530 | |
|
531 | |
|
532 | |
|
533 | |
public void setColumnSize(int cols){ |
534 | 0 | selectItemWidget.setColumnSize(cols); |
535 | 0 | } |
536 | |
|
537 | 0 | public void setMultipleSelect(boolean isMultipleSelect) {} |
538 | |
|
539 | |
|
540 | |
|
541 | |
|
542 | |
|
543 | |
|
544 | |
@Override |
545 | 0 | public void onLoad() {} |
546 | |
|
547 | |
public HandlerRegistration addSelectionChangeHandler(SelectionChangeHandler handler) { |
548 | 0 | return selectItemWidget.addSelectionChangeHandler(handler); |
549 | |
} |
550 | |
|
551 | |
public ListItems getListItems() { |
552 | 0 | return selectItemWidget.getListItems(); |
553 | |
} |
554 | |
|
555 | |
public String getName() { |
556 | 0 | return selectItemWidget.getName(); |
557 | |
} |
558 | |
|
559 | |
public void setName(String name) { |
560 | 0 | selectItemWidget.setName(name); |
561 | 0 | } |
562 | |
|
563 | |
@Override |
564 | |
public void setEnabled(boolean b) { |
565 | 0 | selectItemWidget.setEnabled(b); |
566 | 0 | } |
567 | |
|
568 | |
@Override |
569 | |
public boolean isEnabled() { |
570 | 0 | return selectItemWidget.isEnabled(); |
571 | |
} |
572 | |
|
573 | |
@Override |
574 | |
public boolean isMultipleSelect() { |
575 | 0 | return selectItemWidget.isMultipleSelect(); |
576 | |
} |
577 | |
|
578 | |
@Override |
579 | |
public void redraw() { |
580 | 0 | selectItemWidget.redraw(); |
581 | 0 | } |
582 | |
|
583 | |
@Override |
584 | |
public void clear() { |
585 | 0 | selectItemWidget.clear(); |
586 | 0 | } |
587 | |
|
588 | |
@Override |
589 | |
public HandlerRegistration addBlurHandler(BlurHandler handler) { |
590 | 0 | return selectItemWidget.addBlurHandler(handler); |
591 | |
} |
592 | |
|
593 | |
@Override |
594 | |
public HandlerRegistration addFocusHandler(FocusHandler handler) { |
595 | 0 | return selectItemWidget.addFocusHandler(handler); |
596 | |
} |
597 | |
|
598 | |
public void addWidgetReadyCallback(Callback<Widget> callback) { |
599 | 0 | selectItemWidget.addWidgetReadyCallback(callback); |
600 | 0 | } |
601 | |
|
602 | |
public boolean isInitialized() { |
603 | 0 | return selectItemWidget.isInitialized(); |
604 | |
} |
605 | |
|
606 | |
public void setInitialized(boolean initialized) { |
607 | 0 | selectItemWidget.setInitialized(initialized); |
608 | 0 | } |
609 | |
|
610 | |
|
611 | |
|
612 | |
|
613 | |
|
614 | |
|
615 | |
|
616 | |
|
617 | |
public void setIgnoreMultipleAttributes(boolean ignoreMultiple){ |
618 | 0 | selectItemWidget.setIgnoreMultipleAttributes(ignoreMultiple); |
619 | 0 | } |
620 | |
} |
621 | |
|
622 | 0 | public class SwappableFieldsHelper { |
623 | |
|
624 | |
private GroupSection parentSection; |
625 | 0 | private Map<SwapCompositeCondition, List<SwapCompositeConditionFieldConfig>> swappableFieldsDefinition = |
626 | |
new HashMap<SwapCompositeCondition, List<SwapCompositeConditionFieldConfig>>(); |
627 | |
private Map<String, String> helperFieldKeys; |
628 | |
private ConditionChoices conditionChoices; |
629 | |
private SwapSection swapSection; |
630 | |
public void updateFieldDisplay() { |
631 | 0 | Set<Entry<SwapCompositeCondition, List<SwapCompositeConditionFieldConfig>>> entries = |
632 | |
(swappableFieldsDefinition == null)? null : swappableFieldsDefinition.entrySet(); |
633 | 0 | if (parentSection == null) { |
634 | 0 | throw new RuntimeException("parentSection cannot be null"); |
635 | |
} |
636 | 0 | if (entries != null) { |
637 | 0 | for (Entry<SwapCompositeCondition, List<SwapCompositeConditionFieldConfig>> entry : entries) { |
638 | 0 | SwapCompositeCondition condition = entry.getKey(); |
639 | 0 | if (condition.evaluate(parentSection, helperFieldKeys)) { |
640 | |
|
641 | 0 | List<Section> deletedSections = swapSection.getDeletedSections(); |
642 | 0 | List<FieldDescriptor> fields = null; |
643 | 0 | if (deletedSections != null) { |
644 | 0 | for (Section deletedSection : deletedSections) { |
645 | 0 | fields = (fields == null)? new ArrayList() : fields; |
646 | 0 | fields.addAll(deletedSection.getFields()); |
647 | |
} |
648 | |
} |
649 | 0 | if (fields != null) { |
650 | 0 | for (FieldDescriptor field : fields) { |
651 | 0 | Widget fieldWidget = field.getFieldWidget(); |
652 | 0 | DataModel dataModel = new DataModel(); |
653 | 0 | dataModel.setRoot(new Data()); |
654 | 0 | ((ModelWidgetBinding)field.getModelWidgetBinding()) |
655 | |
.setWidgetValue(fieldWidget, |
656 | |
dataModel, field.getFieldKey()); |
657 | 0 | } |
658 | |
} |
659 | |
|
660 | |
|
661 | 0 | SelectionChangeEvent selectionChangeEvent = |
662 | |
new SelectionChangeEvent(conditionChoices); |
663 | 0 | selectionChangeEvent.setUserInitiated(true); |
664 | 0 | conditionChoices.selectItem(condition.getConditionId()); |
665 | 0 | conditionChoices.fireEvent(selectionChangeEvent); |
666 | |
} |
667 | 0 | } |
668 | |
} |
669 | 0 | } |
670 | |
public GroupSection getParentSection() { |
671 | 0 | return parentSection; |
672 | |
} |
673 | |
public void setParentSection(GroupSection parentSection) { |
674 | 0 | this.parentSection = parentSection; |
675 | 0 | } |
676 | |
public Map<SwapCompositeCondition, List<SwapCompositeConditionFieldConfig>> getSwappableFieldsDefinition() { |
677 | 0 | return swappableFieldsDefinition; |
678 | |
} |
679 | |
public void setSwappableFieldsDefinition(Map<SwapCompositeCondition, List<SwapCompositeConditionFieldConfig>> swappableFieldsDefinition) { |
680 | 0 | this.swappableFieldsDefinition = swappableFieldsDefinition; |
681 | 0 | } |
682 | |
public Map<String, String> getHelperFieldKeys() { |
683 | 0 | return helperFieldKeys; |
684 | |
} |
685 | |
public void setHelperFieldKeys(Map<String, String> helperFieldKeys) { |
686 | 0 | this.helperFieldKeys = helperFieldKeys; |
687 | 0 | } |
688 | |
public ConditionChoices getConditionChoices() { |
689 | 0 | return conditionChoices; |
690 | |
} |
691 | |
public void setConditionChoices(ConditionChoices conditionChoices) { |
692 | 0 | this.conditionChoices = conditionChoices; |
693 | 0 | } |
694 | |
public SwapSection getSwapSection() { |
695 | 0 | return swapSection; |
696 | |
} |
697 | |
public void setSwapSection(SwapSection swapSection) { |
698 | 0 | this.swapSection = swapSection; |
699 | 0 | } |
700 | |
} |
701 | |
|
702 | |
} |