View Javadoc
1   /**
2    * Copyright 2005-2013 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.krms.util;
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.krad.uif.component.Component;
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.Message;
24  import org.kuali.rice.krad.uif.util.ObjectPropertyUtils;
25  import org.kuali.rice.krad.uif.view.View;
26  import org.kuali.rice.krms.dto.PropositionEditor;
27  import org.kuali.rice.krms.tree.node.RuleEditorTreeNode;
28  
29  /**
30   * @author Kuali Student Team
31   */
32  public class EditTreeGroup extends TreeGroup {
33  
34      protected void buildTreeGroups(Object model) {
35          // get Tree data property
36          Tree<Object, String> treeData = ObjectPropertyUtils.getPropertyValue(model, getBindingInfo().getBindingPath());
37  
38          if(treeData==null){
39              return;
40          }
41  
42          // build component tree that corresponds with tree data
43          Tree<Group, Message> treeGroups = new Tree<Group, Message>();
44  
45          String bindingPrefix = getBindingInfo().getBindingPrefixForNested();
46          Node<Group, Message> rootNode = buildTreeNode(treeData.getRootElement(),
47                  bindingPrefix + ".rootElement", "root");
48          treeGroups.setRootElement(rootNode);
49  
50          setTreeGroups(treeGroups);
51      }
52  
53      protected Node<Group, Message> buildTreeNode(Node<Object, String> nodeData, String bindingPrefix,
54                                                   String parentNode) {
55          Node<Group, Message> node = super.buildTreeNode(nodeData, bindingPrefix, parentNode);
56  
57          // Set the binding path on the proposition.
58          if(nodeData.getData() instanceof RuleEditorTreeNode){
59              PropositionEditor proposition = ((RuleEditorTreeNode) nodeData.getData()).getProposition();
60              proposition.setBindingPath(bindingPrefix + ".data");
61              proposition.setIdSuffix(parentNode);
62          }
63  
64          return node;
65      }
66  }