View Javadoc
1   /**
2    * Copyright 2014 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  package org.kuali.student.cm.course.modifiers;
16  
17  import org.kuali.rice.krad.uif.component.Component;
18  import org.kuali.rice.krad.uif.container.Group;
19  import org.kuali.rice.krad.uif.layout.GridLayoutManager;
20  import org.kuali.rice.krad.uif.modifier.CompareFieldCreateModifier;
21  import org.kuali.rice.krad.web.form.MaintenanceDocumentForm;
22  import org.kuali.student.cm.course.form.ViewCourseForm;
23  import org.kuali.student.cm.course.form.wrapper.CourseInfoWrapper;
24  import org.kuali.student.cm.course.util.CourseProposalUtil;
25  
26  import java.util.ArrayList;
27  import java.util.List;
28  
29  /**
30   * A compare modifier which deals with comparing requisites. It doesn't do a line by line comparison. It simply
31   * highlights the entire requisites section.
32   */
33  public class RequisitesCompareModifier extends CompareFieldCreateModifier {
34  
35      @Override
36      public void performModification(Object model, Component component) {
37          if (component == null) {
38              return;
39          }
40  
41          if ((component != null) && !(component instanceof Group)) {
42              throw new IllegalArgumentException(
43                      "Compare field initializer only support Group components which contain requisites: " + component.getClass());
44          }
45  
46          Group group = (Group) component;
47          CourseInfoWrapper leftDataObject = null;
48          CourseInfoWrapper rightDataObject = null;
49  
50          if (model instanceof MaintenanceDocumentForm) {
51              leftDataObject = (CourseInfoWrapper) ((MaintenanceDocumentForm) model).getDocument().getNewMaintainableObject().getDataObject();
52              rightDataObject = (CourseInfoWrapper) ((MaintenanceDocumentForm) model).getDocument().getOldMaintainableObject().getDataObject();
53          } else if (model instanceof ViewCourseForm) {
54              leftDataObject = ((ViewCourseForm) model).getCourseInfoWrapper();
55              rightDataObject = ((ViewCourseForm) model).getCompareCourseInfoWrapper();
56          } else {
57              throw new RuntimeException("Unsupported model class.");
58          }
59  
60          boolean isRequisitesEqual = CourseProposalUtil.isRequisitesEqual(leftDataObject.getAgendas(), rightDataObject.getAgendas());
61  
62          //  If the requisites aren't equal then highlight the row
63          if (! isRequisitesEqual) {
64              List<String> rowCssClasses = new ArrayList<>();
65              rowCssClasses.add("cm-compare-highlighter");
66              if (group.getLayoutManager() instanceof GridLayoutManager) {
67                  ((GridLayoutManager)group.getLayoutManager()).setRowCssClasses(rowCssClasses);
68              }
69          }
70      }
71  }