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.apache.commons.lang.StringUtils;
19 import org.kuali.rice.core.api.util.tree.Node;
20 import org.kuali.rice.core.api.util.tree.Tree;
21 import org.kuali.rice.krad.uif.UifConstants;
22 import org.kuali.rice.krad.uif.container.CollectionGroup;
23 import org.kuali.rice.krad.uif.container.Group;
24 import org.kuali.rice.krad.uif.container.NodePrototype;
25 import org.kuali.rice.krad.uif.container.TreeGroup;
26 import org.kuali.rice.krad.uif.element.Message;
27 import org.kuali.rice.krad.uif.util.ComponentUtils;
28 import org.kuali.rice.krad.uif.util.ObjectPropertyUtils;
29 import org.kuali.rice.krad.uif.view.View;
30
31 import java.util.ArrayList;
32 import java.util.List;
33
34
35
36
37 public class ViewTreeGroup extends TreeGroup {
38
39
40
41
42
43
44
45
46 protected void buildTreeGroups(View view, Object model) {
47
48 Tree<Object, String> treeData = ObjectPropertyUtils.getPropertyValue(model, getBindingInfo().getBindingPath());
49
50 if (treeData == null) {
51 return;
52 }
53
54
55 Tree<Group, Message> treeGroups = new Tree<Group, Message>();
56
57 String bindingPrefix = getBindingInfo().getBindingPrefixForNested();
58 Node<Group, Message> rootNode = buildTreeNode(treeData.getRootElement(),
59 bindingPrefix + ".rootElement", "_root");
60 treeGroups.setRootElement(rootNode);
61
62 setTreeGroups(treeGroups);
63 }
64
65
66
67
68
69
70
71
72
73 @Override
74 protected Node<Group, Message> buildTreeNode(Node<Object, String> nodeData, String bindingPrefix, String parentNode) {
75
76 if (nodeData == null) {
77 return null;
78 }
79
80 Node<Group, Message> node = new Node<Group, Message>();
81 node.setNodeType(nodeData.getNodeType());
82
83
84 NodePrototype prototype = this.getDefaultNodePrototype();
85
86 Message message = ComponentUtils.copy(prototype.getLabelPrototype(), parentNode);
87 ComponentUtils.pushObjectToContext(message, UifConstants.ContextVariableNames.NODE, nodeData);
88 message.setMessageText(nodeData.getNodeLabel());
89 node.setNodeLabel(message);
90
91 Group nodeGroup = ComponentUtils.copyComponent(prototype.getDataGroupPrototype(), bindingPrefix + ".data",
92 parentNode);
93 ComponentUtils.pushObjectToContext(nodeGroup, UifConstants.ContextVariableNames.NODE, nodeData);
94
95 String nodePath = bindingPrefix + ".data";
96 if (StringUtils.isNotBlank(getBindingInfo().getBindingObjectPath())) {
97 nodePath = getBindingInfo().getBindingObjectPath() + "." + nodePath;
98 }
99 ComponentUtils.pushObjectToContext(nodeGroup, UifConstants.ContextVariableNames.NODE_PATH, nodePath);
100
101
102 List<CollectionGroup> components = ComponentUtils.getComponentsOfTypeShallow(nodeGroup, CollectionGroup.class);
103 for (CollectionGroup fieldCollectionGroup : components) {
104 fieldCollectionGroup.setSubCollectionSuffix(parentNode);
105 }
106 node.setData(nodeGroup);
107
108 List<Node<Group, Message>> nodeChildren = new ArrayList<Node<Group, Message>>();
109
110 int childIndex = 0;
111 for (Node<Object, String> childDataNode : nodeData.getChildren()) {
112 String nextBindingPrefix = bindingPrefix + ".children[" + childIndex + "]";
113 Node<Group, Message> childNode = buildTreeNode(childDataNode, nextBindingPrefix,
114 "_node" + childIndex + parentNode);
115
116 nodeChildren.add(childNode);
117
118
119 ++childIndex;
120 }
121 node.setChildren(nodeChildren);
122
123 return node;
124 }
125 }