1 | |
package org.kuali.student.common.ui.client.configurable.mvc.multiplicity; |
2 | |
|
3 | |
import java.util.List; |
4 | |
import java.util.Map; |
5 | |
|
6 | |
import org.kuali.student.common.ui.client.configurable.mvc.FieldDescriptor; |
7 | |
import org.kuali.student.common.ui.client.configurable.mvc.sections.GroupSection; |
8 | |
import org.kuali.student.common.ui.client.widgets.list.KSSelectItemWidgetAbstract; |
9 | |
import org.kuali.student.common.ui.client.widgets.search.KSPicker; |
10 | |
|
11 | |
import com.google.gwt.user.client.ui.Widget; |
12 | |
|
13 | 0 | public class SwapCondition { |
14 | |
private FieldDescriptor fd; |
15 | |
private String value; |
16 | |
public FieldDescriptor getFd() { |
17 | 0 | return fd; |
18 | |
} |
19 | |
public void setFd(FieldDescriptor fd) { |
20 | 0 | this.fd = fd; |
21 | 0 | } |
22 | |
public String getValue() { |
23 | 0 | return value; |
24 | |
} |
25 | |
public void setValue(String value) { |
26 | 0 | this.value = value; |
27 | 0 | } |
28 | |
private String nvl(String inString) { |
29 | 0 | return (inString == null)? "" : inString; |
30 | |
} |
31 | |
public boolean evaluate(GroupSection section, Map<String, String> helperFieldKeys) { |
32 | 0 | boolean result = false; |
33 | 0 | String widgetValue = null; |
34 | |
|
35 | |
|
36 | 0 | List<FieldDescriptor> sectionFds = section.getFields(); |
37 | 0 | Widget fieldWidget = null; |
38 | 0 | if (sectionFds != null) { |
39 | 0 | for (FieldDescriptor sectionFd : sectionFds) { |
40 | 0 | if (sectionFd.getFieldKey().equals(helperFieldKeys.get(fd.getFieldKey()))) { |
41 | 0 | fieldWidget = sectionFd.getFieldWidget(); |
42 | |
} |
43 | |
} |
44 | |
} |
45 | 0 | if (fieldWidget != null && fieldWidget instanceof KSSelectItemWidgetAbstract) { |
46 | 0 | widgetValue = ((KSSelectItemWidgetAbstract)fieldWidget).getSelectedItem(); |
47 | 0 | } else if (fieldWidget != null && fieldWidget instanceof KSPicker) { |
48 | 0 | Widget inputWidget = ((KSPicker)fieldWidget).getInputWidget(); |
49 | 0 | widgetValue = ((KSSelectItemWidgetAbstract)inputWidget).getSelectedItem(); |
50 | |
} |
51 | 0 | if (nvl(this.value).equals(widgetValue)) { |
52 | 0 | result = true; |
53 | |
} |
54 | 0 | return result; |
55 | |
} |
56 | |
} |