1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krms.tree;
17
18 import org.kuali.rice.core.api.util.tree.Node;
19 import org.kuali.rice.core.api.util.tree.Tree;
20 import org.kuali.rice.krms.api.repository.LogicalOperator;
21 import org.kuali.rice.krms.api.repository.proposition.PropositionType;
22 import org.kuali.rice.krms.dto.PropositionEditor;
23 import org.kuali.rice.krms.dto.RuleEditor;
24 import org.kuali.rice.krms.tree.node.TreeNode;
25 import org.kuali.rice.krms.util.KRMSConstants;
26 import org.kuali.rice.krms.util.PropositionTreeUtil;
27
28 import java.util.HashMap;
29 import java.util.List;
30 import java.util.Map;
31
32
33
34
35
36
37
38 public class RuleViewTreeBuilder extends AbstractTreeBuilder {
39
40 private static final long serialVersionUID = 1L;
41
42 public Tree<TreeNode, String> buildTree(RuleEditor rule) {
43
44 Tree myTree = new Tree<TreeNode, String>();
45
46 Node<TreeNode, String> rootNode = new Node<TreeNode, String>();
47 rootNode.setNodeLabel("root");
48 rootNode.setNodeType("rootNode");
49 rootNode.setData(new TreeNode("Rule:"));
50 myTree.setRootElement(rootNode);
51
52 if (rule == null) {
53 return myTree;
54 }
55
56 if (rule.getPropositionEditor() != null) {
57
58 buildPreviewTree(rule, rootNode, rule.getPropositionEditor());
59
60
61 if ((rootNode.getChildren() != null) && (rootNode.getChildren().size() > 0)) {
62 Node<TreeNode, String> firstNode = rootNode.getChildren().get(0);
63 if ((firstNode.getChildren() != null) && (firstNode.getChildren().size() > 0)) {
64 firstNode.setNodeType(KRMSConstants.NODE_TYPE_SUBRULEHEADER);
65 addNodeType(firstNode, KRMSConstants.NODE_TYPE_SUBRULEELEMENT);
66 firstNode.setNodeLabel("<u>" + firstNode.getNodeLabel() + ":</u>");
67 }
68 }
69 }
70
71 return myTree;
72 }
73
74 private void buildPreviewTree(RuleEditor rule, Node<TreeNode, String> currentNode, PropositionEditor prop) {
75 if (prop != null) {
76
77 Node<TreeNode, String> newNode = new Node<TreeNode, String>();
78 newNode.setNodeType(KRMSConstants.NODE_TYPE_SUBRULEELEMENT);
79 addNodeType(newNode, KRMSConstants.NODE_TYPE_VIEWELEMENT);
80
81 if (PropositionType.SIMPLE.getCode().equalsIgnoreCase(prop.getPropositionTypeCode())) {
82 newNode.setNodeLabel(this.buildNodeLabel(prop));
83 } else if (PropositionType.COMPOUND.getCode().equalsIgnoreCase(prop.getPropositionTypeCode())) {
84 newNode.setNodeLabel(this.buildNodeLabel(prop));
85 boolean first = true;
86 for (PropositionEditor child : prop.getCompoundEditors()) {
87
88 if (!first) {
89
90 Node<TreeNode, String> opNode = new Node<TreeNode, String>();
91 opNode.setNodeLabel(PropositionTreeUtil.getLabelForOperator(prop.getCompoundOpCode()));
92 opNode.setData(new TreeNode(prop.getCompoundOpCode()));
93 newNode.getChildren().add(opNode);
94 }
95 first = false;
96
97 buildPreviewTree(rule, newNode, child);
98 }
99 }
100
101 TreeNode tNode = new TreeNode(newNode.getNodeLabel());
102 tNode.setListItems(this.getListItems(prop));
103 tNode.setKey(prop.getKey());
104 newNode.setData(tNode);
105 currentNode.getChildren().add(newNode);
106
107 }
108 }
109
110 public List<Object> getListItems(PropositionEditor propositionEditor) {
111 return null;
112 }
113
114 @Override
115 public String getNaturalLanguageUsageKey() {
116 return null;
117 }
118 }