| 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.binding; | 
  | 17 |  |   | 
  | 18 |  |  import org.kuali.student.common.assembly.data.QueryPath; | 
  | 19 |  |  import org.kuali.student.common.ui.client.configurable.mvc.multiplicity.MultiplicityGroupItem; | 
  | 20 |  |  import org.kuali.student.common.ui.client.configurable.mvc.sections.Section; | 
  | 21 |  |  import org.kuali.student.common.ui.client.configurable.mvc.sections.SectionBinding; | 
  | 22 |  |  import org.kuali.student.common.ui.client.mvc.DataModel; | 
  | 23 |  |   | 
  | 24 |  |  import com.google.gwt.core.client.GWT; | 
  | 25 |  |  import com.google.gwt.user.client.ui.Widget; | 
  | 26 |  |   | 
  | 27 |  |   | 
  | 28 |  |   | 
  | 29 |  |   | 
  | 30 |  |   | 
  | 31 |  |   | 
  | 32 |  |   | 
  | 33 | 0 |  public class MultiplicityGroupItemBinding extends ModelWidgetBindingSupport<MultiplicityGroupItem> { | 
  | 34 | 0 |      public static MultiplicityGroupItemBinding INSTANCE = new MultiplicityGroupItemBinding(); | 
  | 35 |  |   | 
  | 36 | 0 |      protected static final String RT_CREATED = "_runtimeData" + QueryPath.getPathSeparator() + "created"; | 
  | 37 | 0 |      protected static final String RT_UPDATED = "_runtimeData" + QueryPath.getPathSeparator() + "updated"; | 
  | 38 | 0 |      protected static final String RT_DELETED = "_runtimeData" + QueryPath.getPathSeparator() + "deleted"; | 
  | 39 |  |   | 
  | 40 | 0 |      private MultiplicityGroupItemBinding() {}; | 
  | 41 |  |   | 
  | 42 |  |       | 
  | 43 |  |   | 
  | 44 |  |   | 
  | 45 |  |   | 
  | 46 |  |      @Override | 
  | 47 |  |      public void setModelValue(MultiplicityGroupItem multiplicityItem, DataModel model, String path) { | 
  | 48 | 0 |          String itemPath = QueryPath.concat(path, String.valueOf(multiplicityItem.getItemKey())).toString(); | 
  | 49 | 0 |              String itemRuntimePath = itemPath; | 
  | 50 | 0 |          Widget widget = multiplicityItem.getItemWidget(); | 
  | 51 |  |           | 
  | 52 | 0 |          boolean multiplicityItemIsDirty = false; | 
  | 53 | 0 |          if (widget instanceof Section) {                 | 
  | 54 | 0 |                  if (((Section)widget).isDirty()){ | 
  | 55 |  |                           | 
  | 56 | 0 |                          itemPath = ""; | 
  | 57 | 0 |                      SectionBinding.INSTANCE.setModelValue((Section) widget, model, itemPath); | 
  | 58 | 0 |                      multiplicityItemIsDirty = true; | 
  | 59 |  |                  }  | 
  | 60 | 0 |          } else if (widget instanceof ModelWidgetBinding) { | 
  | 61 | 0 |              ((ModelWidgetBinding) widget).setModelValue(widget, model, path); | 
  | 62 | 0 |              multiplicityItemIsDirty = true; | 
  | 63 |  |          } else { | 
  | 64 | 0 |              GWT.log(itemPath + " has no widget binding.", null); | 
  | 65 |  |          } | 
  | 66 |  |   | 
  | 67 |  |           | 
  | 68 | 0 |         if (multiplicityItemIsDirty || multiplicityItem.isDeleted()){ | 
  | 69 |  |                  QueryPath qPath; | 
  | 70 | 0 |                  if (multiplicityItem.isCreated()) { | 
  | 71 | 0 |                      qPath = QueryPath.parse(itemRuntimePath + QueryPath.getPathSeparator() + RT_CREATED); | 
  | 72 | 0 |                  } else if (multiplicityItem.isDeleted()) { | 
  | 73 | 0 |                      qPath = QueryPath.parse(itemRuntimePath + QueryPath.getPathSeparator() + RT_DELETED); | 
  | 74 |  |                  } else { | 
  | 75 | 0 |                      qPath = QueryPath.parse(itemRuntimePath + QueryPath.getPathSeparator() + RT_UPDATED); | 
  | 76 |  |                  } | 
  | 77 |  |                  try { | 
  | 78 | 0 |                      Boolean oldValue = model.get(qPath); | 
  | 79 | 0 |                      Boolean newValue = true; | 
  | 80 | 0 |                      if (!nullsafeEquals(oldValue, newValue)) { | 
  | 81 | 0 |                          model.set(qPath, newValue); | 
  | 82 | 0 |                          setDirtyFlag(model, qPath); | 
  | 83 |  |                      } | 
  | 84 | 0 |                  } catch (IllegalArgumentException e) { | 
  | 85 |  |                       | 
  | 86 | 0 |                      GWT.log("Warning: Ignoring error attempting to setValue for " + widget.getClass().getName() + " path: " + qPath, e); | 
  | 87 | 0 |                  } | 
  | 88 |  |         } | 
  | 89 |  |   | 
  | 90 | 0 |      } | 
  | 91 |  |   | 
  | 92 |  |       | 
  | 93 |  |   | 
  | 94 |  |   | 
  | 95 |  |   | 
  | 96 |  |      @Override | 
  | 97 |  |      public void setWidgetValue(MultiplicityGroupItem multiplicityItem, DataModel model, String path) { | 
  | 98 |  |   | 
  | 99 | 0 |          String itemPath =""; | 
  | 100 | 0 |          Widget widget = multiplicityItem.getItemWidget(); | 
  | 101 | 0 |          if (widget instanceof Section) { | 
  | 102 | 0 |              SectionBinding.INSTANCE.setWidgetValue((Section) widget, model, itemPath); | 
  | 103 | 0 |          } else if (widget instanceof ModelWidgetBinding) { | 
  | 104 | 0 |              ((ModelWidgetBinding) widget).setWidgetValue(widget, model, path); | 
  | 105 |  |          } else { | 
  | 106 | 0 |              GWT.log(itemPath + " has no widget binding.", null); | 
  | 107 |  |          } | 
  | 108 |  |   | 
  | 109 | 0 |          multiplicityItem.setCreated(false); | 
  | 110 | 0 |          multiplicityItem.setCreated(false); | 
  | 111 | 0 |      } | 
  | 112 |  |   | 
  | 113 |  |   | 
  | 114 |  |  } |