View Javadoc

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  public class SwapCondition {
14      private FieldDescriptor fd;
15      private String value;
16      public FieldDescriptor getFd() {
17          return fd;
18      }
19      public void setFd(FieldDescriptor fd) {
20          this.fd = fd;
21      }
22      public String getValue() {
23          return value;
24      }
25      public void setValue(String value) {
26          this.value = value;
27      }
28      private String nvl(String inString) {
29          return (inString == null)? "" : inString;
30      }
31      public boolean evaluate(GroupSection section, Map<String, String> helperFieldKeys) {
32          boolean result = false;
33          String widgetValue = null;
34          // could have used getField(String) method here but the getField method does
35          // not check the fields of sub sections.
36          List<FieldDescriptor> sectionFds = section.getFields();
37          Widget fieldWidget = null;
38          if (sectionFds != null) {
39              for (FieldDescriptor sectionFd : sectionFds) {
40                  if (sectionFd.getFieldKey().equals(helperFieldKeys.get(fd.getFieldKey()))) {
41                      fieldWidget = sectionFd.getFieldWidget();
42                  }
43              }
44          }
45          if (fieldWidget != null && fieldWidget instanceof KSSelectItemWidgetAbstract) {
46              widgetValue = ((KSSelectItemWidgetAbstract)fieldWidget).getSelectedItem();
47          } else if (fieldWidget != null && fieldWidget instanceof KSPicker) {
48              Widget inputWidget = ((KSPicker)fieldWidget).getInputWidget();
49              widgetValue = ((KSSelectItemWidgetAbstract)inputWidget).getSelectedItem();
50          }
51          if (nvl(this.value).equals(widgetValue)) {
52              result = true;
53          }
54          return result;
55      }
56  }