001/** 002 * Copyright 2005-2013 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.kuali.rice.krms.util; 017 018import org.kuali.rice.core.api.util.tree.Node; 019import org.kuali.rice.core.api.util.tree.Tree; 020import org.kuali.rice.krad.uif.component.Component; 021import org.kuali.rice.krad.uif.container.Group; 022import org.kuali.rice.krad.uif.container.TreeGroup; 023import org.kuali.rice.krad.uif.element.Message; 024import org.kuali.rice.krad.uif.util.ObjectPropertyUtils; 025import org.kuali.rice.krad.uif.view.View; 026import org.kuali.rice.krms.dto.PropositionEditor; 027import org.kuali.rice.krms.tree.node.RuleEditorTreeNode; 028 029/** 030 * @author Kuali Student Team 031 */ 032public class EditTreeGroup extends TreeGroup { 033 034 protected void buildTreeGroups(View view, Object model) { 035 // get Tree data property 036 Tree<Object, String> treeData = ObjectPropertyUtils.getPropertyValue(model, getBindingInfo().getBindingPath()); 037 038 if(treeData==null){ 039 return; 040 } 041 042 // build component tree that corresponds with tree data 043 Tree<Group, Message> treeGroups = new Tree<Group, Message>(); 044 045 String bindingPrefix = getBindingInfo().getBindingPrefixForNested(); 046 Node<Group, Message> rootNode = buildTreeNode(treeData.getRootElement(), 047 bindingPrefix + ".rootElement", "root"); 048 treeGroups.setRootElement(rootNode); 049 050 setTreeGroups(treeGroups); 051 } 052 053 protected Node<Group, Message> buildTreeNode(Node<Object, String> nodeData, String bindingPrefix, 054 String parentNode) { 055 Node<Group, Message> node = super.buildTreeNode(nodeData, bindingPrefix, parentNode); 056 057 // Set the binding path on the proposition. 058 if(nodeData.getData() instanceof RuleEditorTreeNode){ 059 PropositionEditor proposition = ((RuleEditorTreeNode) nodeData.getData()).getProposition(); 060 proposition.setBindingPath(bindingPrefix + ".data"); 061 } 062 063 // Reset this id to a static id, can only have one proposition in edit mode at a time. 064 if(node.getData().getId().startsWith("KRMS-PropositionEdit-BoxSection")){ 065 node.getData().setId(node.getData().getBaseId()); 066 for(Component component : node.getData().getItems()){ 067 component.setId(component.getBaseId()); 068 } 069 } 070 071 return node; 072 } 073}