View Javadoc
1   /**
2    * Copyright 2010 The Kuali Foundation Licensed under the
3    * Educational Community License, Version 2.0 (the "License"); you may
4    * not use this file except in compliance with the License. You may
5    * obtain a copy of the License at
6    *
7    * http://www.osedu.org/licenses/ECL-2.0
8    *
9    * Unless required by applicable law or agreed to in writing,
10   * software distributed under the License is distributed on an "AS IS"
11   * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12   * or implied. See the License for the specific language governing
13   * permissions and limitations under the License.
14   */
15  
16  package org.kuali.student.common.ui.client.configurable.mvc.binding;
17  
18  import org.kuali.student.common.ui.client.configurable.mvc.multiplicity.MultiplicityItem;
19  import org.kuali.student.common.ui.client.configurable.mvc.sections.Section;
20  import org.kuali.student.common.ui.client.configurable.mvc.sections.SectionBinding;
21  import org.kuali.student.common.ui.client.mvc.DataModel;
22  import org.kuali.student.r1.common.assembly.data.QueryPath;
23  
24  import com.google.gwt.core.client.GWT;
25  import com.google.gwt.user.client.ui.Widget;
26  
27  /**
28   * This binding simply adds an index key to the multiplicity item's parent path and then calls the binding ModelWidgetBinding
29   * of the underlying multiplicity item's widget.
30   * 
31   * @author Kuali Student Team
32   */
33  
34  /**
35   * @deprecated
36   */
37  public class MultiplicityItemBinding extends ModelWidgetBindingSupport<MultiplicityItem> {
38      public static MultiplicityItemBinding INSTANCE = new MultiplicityItemBinding();
39  
40      protected static final String RT_CREATED = "_runtimeData" + QueryPath.getPathSeparator() + "created";
41      protected static final String RT_UPDATED = "_runtimeData" + QueryPath.getPathSeparator() + "updated";
42      protected static final String RT_DELETED = "_runtimeData" + QueryPath.getPathSeparator() + "deleted";
43  
44      private MultiplicityItemBinding() {};
45  
46      /**
47       * @see org.kuali.student.common.ui.client.configurable.mvc.binding.ModelWidgetBindingSupport#setModelValue(java.lang.Object,
48       *      org.kuali.student.common.ui.client.mvc.DataModel, java.lang.String)
49       */
50      @Override
51      public void setModelValue(MultiplicityItem multiplicityItem, DataModel model, String path) {
52          // TODO modify this method to use QueryPath.add to build paths, rather than string manipulation
53          String itemPath = path + QueryPath.getPathSeparator() + multiplicityItem.getItemKey();
54      	String mutiRuntimePath = itemPath;
55          Widget widget = multiplicityItem.getItemWidget();
56          if (widget instanceof Section) {
57          	itemPath = "";
58              SectionBinding.INSTANCE.setModelValue((Section) widget, model, itemPath);
59          } else if (widget instanceof ModelWidgetBinding) {
60              ((ModelWidgetBinding) widget).setModelValue(widget, model, path);
61          } else {
62              GWT.log(itemPath + " has no widget binding.", null);
63          }
64  
65          // Multiplicity metadata?
66         QueryPath qPath;
67          if (multiplicityItem.isCreated()) {
68              qPath = QueryPath.parse(mutiRuntimePath + QueryPath.getPathSeparator() + RT_CREATED);
69          } else if (multiplicityItem.isDeleted()) {
70              qPath = QueryPath.parse(mutiRuntimePath + QueryPath.getPathSeparator() + RT_DELETED);
71          } else {
72              qPath = QueryPath.parse(mutiRuntimePath + QueryPath.getPathSeparator() + RT_UPDATED);
73          }
74          try {
75              Boolean oldValue = model.get(qPath);
76              Boolean newValue = true;
77              if (!nullsafeEquals(oldValue, newValue)) {
78                  model.set(qPath, newValue);
79                  setDirtyFlag(model, qPath);
80              }
81          } catch (java.lang.IllegalArgumentException e) {
82              // model.get(qPath) will throw this exception if there is no such path
83              GWT.log("Warning: Ignoring error attempting to setValue for " + widget.getClass().getName() + " path: " + qPath, e);
84          }
85  
86      }
87  
88      /**
89       * @see org.kuali.student.common.ui.client.configurable.mvc.binding.ModelWidgetBindingSupport#setWidgetValue(java.lang.Object,
90       *      org.kuali.student.common.ui.client.mvc.DataModel, java.lang.String)
91       */
92      @Override
93      public void setWidgetValue(MultiplicityItem multiplicityItem, DataModel model, String path) {
94  //        String itemPath = path + QueryPath.getPathSeparator() + multiplicityItem.getItemKey();
95          String itemPath ="";
96          Widget widget = multiplicityItem.getItemWidget();
97          if (widget instanceof Section) {
98              SectionBinding.INSTANCE.setWidgetValue((Section) widget, model, itemPath);
99          } else if (widget instanceof ModelWidgetBinding) {
100             ((ModelWidgetBinding) widget).setWidgetValue(widget, model, path);
101         } else {
102             GWT.log(itemPath + " has no widget binding.", null);
103         }
104 
105         multiplicityItem.setCreated(false);
106         multiplicityItem.setCreated(false);
107     }
108     
109     
110 }