1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krms.impl.repository;
17
18 import java.util.ArrayList;
19 import java.util.List;
20
21 import org.kuali.rice.krad.inquiry.InquirableImpl;
22 import org.kuali.rice.krad.uif.component.Component;
23 import org.kuali.rice.krad.uif.container.Container;
24 import org.kuali.rice.krad.uif.container.Group;
25 import org.kuali.rice.krad.uif.element.Message;
26 import org.kuali.rice.krad.uif.field.SpaceField;
27 import org.kuali.rice.krad.uif.layout.GridLayoutManager;
28 import org.kuali.rice.krad.uif.util.ComponentFactory;
29 import org.kuali.rice.krad.uif.view.ViewModel;
30 import org.kuali.rice.krad.web.form.InquiryForm;
31 import org.kuali.rice.krms.api.repository.proposition.PropositionType;
32
33
34
35
36 public class RuleStudentInquiryViewHelperServiceImpl extends InquirableImpl {
37
38 private static int ID = 1;
39
40 private static final String PROPOSITION_GROUP_ID = "propositionGroup";
41
42 private static final String PROPOSITION_ID = "proposition";
43
44 private enum Operator {
45 OR("|"), AND("&");
46
47 private String code;
48
49 Operator(String code) {
50 this.code = code;
51 }
52
53 private static Operator fromCode(String code) {
54 if (code == null) {
55 return null;
56 }
57 for (Operator operator : values()) {
58 if (operator.code.equals(code)) {
59 return operator;
60 }
61 }
62 throw new IllegalArgumentException("Failed to locate the Operator with the given code: " + code);
63 }
64 }
65
66
67
68 @Override
69 public void addCustomContainerComponents(ViewModel model, Container container) {
70 if (PROPOSITION_GROUP_ID.equals(container.getId())) {
71 RuleBo ruleDataObj = (RuleBo)((InquiryForm)model).getDataObject();
72 PropositionBo proposition = ruleDataObj.getProposition();
73 if (proposition != null) {
74 if (PropositionType.COMPOUND.getCode().equals(proposition.getPropositionTypeCode())) {
75 List<Component> groups = new ArrayList<Component>();
76 handleCompoundPropositions(groups, proposition);
77 container.setItems(groups);
78 } else {
79 Message simplePropName = ComponentFactory.getMessage();
80 simplePropName.setId(PROPOSITION_ID + "_" + ID++);
81 simplePropName.setMessageText(proposition.getDescription());
82 List<Message> simpleProps = new ArrayList<Message>();
83 simpleProps.add(simplePropName);
84 container.setItems(simpleProps);
85 }
86 }
87 }
88 }
89
90 private void handleCompoundPropositions(List<Component> components, PropositionBo proposition) {
91 Group compoundGroup = getPropositionGroup();
92 compoundGroup.setId(String.valueOf(PROPOSITION_GROUP_ID + "_" + ID++));
93 ((GridLayoutManager)compoundGroup.getLayoutManager()).setNumberOfColumns(2);
94
95 List<Component> componentItems = new ArrayList<Component>();
96
97
98 Message propositionName = ComponentFactory.getMessage();
99 propositionName.setId(PROPOSITION_ID + "_" + ID++);
100 propositionName.setMessageText(proposition.getDescription());
101
102 componentItems.add(propositionName);
103
104
105 SpaceField spaceField1 = ComponentFactory.getSpaceField();
106 spaceField1.setId("space" + "_" + ID++);
107 componentItems.add(spaceField1);
108
109
110 SpaceField spaceField2 = ComponentFactory.getSpaceField();
111 spaceField2.setId("space" + "_" + ID++);
112 componentItems.add(spaceField2);
113
114 if (proposition.getCompoundComponents() != null) {
115 int loopCounter = 0;
116 for (PropositionBo nestedProposition : proposition.getCompoundComponents()) {
117 if (loopCounter != 0) {
118
119
120 SpaceField spaceField3 = ComponentFactory.getSpaceField();
121 spaceField3.setId("space" + "_" + ID++);
122 componentItems.add(spaceField3);
123
124 Message operator = ComponentFactory.getMessage();
125 operator.setId(PROPOSITION_ID + "_" + ID++);
126 operator.setMessageText(Operator.fromCode(proposition.getCompoundOpCode()).toString());
127 componentItems.add(operator);
128
129
130 SpaceField spaceField4 = ComponentFactory.getSpaceField();
131 spaceField4.setId("space" + "_" + ID++);
132 componentItems.add(spaceField4);
133 }
134 if (PropositionType.COMPOUND.getCode().equals(nestedProposition.getPropositionTypeCode())) {
135 handleCompoundPropositions(components, nestedProposition);
136 } else {
137 Message simplePropName = ComponentFactory.getMessage();
138 simplePropName.setId(PROPOSITION_ID + "_" + ID++);
139 simplePropName.setMessageText(nestedProposition.getDescription());
140
141 componentItems.add(simplePropName);
142 }
143 loopCounter++;
144 }
145 }
146 compoundGroup.setItems(componentItems);
147
148 components.add(compoundGroup);
149 }
150
151 private static Group getPropositionGroup() {
152 Group group = (Group) ComponentFactory.getGroupGridBodyOnly();
153 group.getDisclosure().setId(String.valueOf(ID++));
154 return group;
155 }
156
157 }