1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krms.util;
17
18 import org.kuali.rice.krad.uif.component.Component;
19 import org.kuali.rice.krad.uif.container.CollectionGroupBase;
20 import org.kuali.rice.krad.uif.container.CollectionGroupBuilder;
21 import org.kuali.rice.krad.uif.container.Group;
22 import org.kuali.rice.krad.uif.container.TreeGroup;
23 import org.kuali.rice.krad.uif.element.Action;
24 import org.kuali.rice.krad.uif.field.DataField;
25 import org.kuali.rice.krad.uif.lifecycle.ViewLifecycleUtils;
26 import org.kuali.rice.krad.uif.util.ComponentUtils;
27 import org.kuali.rice.krms.dto.AgendaEditor;
28 import org.kuali.rice.krms.dto.RuleEditor;
29 import org.kuali.rice.krms.service.RuleViewHelperService;
30
31 import java.util.ArrayList;
32 import java.util.List;
33
34
35
36
37 public class AgendaBuilder {
38
39 public static final String AGENDA = "_agenda";
40 public static final String RULE = "_rule";
41
42 private RuleViewHelperService viewHelperService;
43
44
45
46
47
48
49
50 public Component buildAgenda(AgendaEditor agenda, int index, AgendaSection agendaSection) {
51 String agendaSuffix = AGENDA + Integer.toString(index);
52 Group group = ComponentUtils.copy(agendaSection.getAgendaPrototype(), agendaSuffix);
53 group.setHeaderText(agenda.getAgendaTypeInfo().getDescription());
54
55 String bindingPrefix = agendaSection.getPropertyName() + "[" + index + "].";
56 List<Component> components = new ArrayList<Component>();
57 for (RuleEditor rule : agenda.getRuleEditors().values()) {
58 components.add(buildRule(rule, bindingPrefix, agendaSection));
59 }
60
61 group.setItems(components);
62
63 return group;
64 }
65
66
67
68
69
70
71
72 protected Component buildRule(RuleEditor rule, String bindingPrefix, AgendaSection agendaSection) {
73 String ruleSuffix = RULE + rule.getKey();
74 Group group = ComponentUtils.copy(agendaSection.getRulePrototype(), ruleSuffix);
75 group.setHeaderText(rule.getRuleTypeInfo().getDescription());
76
77
78 List<Action> actionLinks = ViewLifecycleUtils.getElementsOfTypeDeep(group, Action.class);
79 for (Action actionLink : actionLinks) {
80 actionLink.getActionParameters().put("ruleKey", rule.getKey());
81 actionLink.getActionParameters().put("ruleType", rule.getRuleTypeInfo().getType());
82 }
83
84 ComponentUtils.updateContextForLine(group, null, rule, 0, ruleSuffix);
85
86 String bindingPath = bindingPrefix + "ruleEditors[" + rule.getKey() + "].";
87 this.setPropertyBindingPaths(group, bindingPath);
88
89 return group;
90 }
91
92 protected void setPropertyBindingPaths(Group group, String bindingPath) {
93
94 List<DataField> dataFields = ViewLifecycleUtils.getElementsOfTypeDeep(group.getItems(), DataField.class);
95 for (DataField collectionField : dataFields) {
96 collectionField.getBindingInfo().setBindingName(bindingPath + collectionField.getBindingInfo().getBindingName());
97 }
98
99 List<TreeGroup> treeFields = ViewLifecycleUtils.getElementsOfTypeDeep(group.getItems(), TreeGroup.class);
100 for (TreeGroup collectionField : treeFields) {
101 collectionField.getBindingInfo().setBindingName(bindingPath + collectionField.getBindingInfo().getBindingName());
102 }
103 }
104
105 public RuleViewHelperService getViewHelperService() {
106 return viewHelperService;
107 }
108
109 public void setViewHelperService(RuleViewHelperService viewHelperService) {
110 this.viewHelperService = viewHelperService;
111 }
112 }