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