1
2
3
4
5
6
7
8
9
10
11
12
13
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
31
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
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 }