View Javadoc

1   /*
2    * Copyright 2011 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 1.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/ecl1.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.impl.ui;
17  
18  import java.util.List;
19  
20  import org.kuali.rice.core.util.Node;
21  import org.kuali.rice.core.util.Tree;
22  import org.kuali.rice.krad.bo.PersistableBusinessObjectBase;
23  import org.kuali.rice.krms.impl.repository.AgendaBo;
24  import org.kuali.rice.krms.impl.repository.AgendaItemBo;
25  import org.kuali.rice.krms.impl.repository.ContextBo;
26  
27  /**
28   * BO for the KRMS agenda editor
29   * 
30   * @author Kuali Rice Team (rice.collab@kuali.org)
31   *
32   */
33  // TODO: this is not a document, rename?
34  public class AgendaEditor extends PersistableBusinessObjectBase {
35  	
36  	private static final long serialVersionUID = 1L;
37  	
38  	private ContextBo context;
39  	private AgendaBo agenda;
40  	private AgendaItemBo agendaItemAddLine;
41  	
42  	private void addAgendaItemAndChildren(Node<AgendaTreeNode, String> parent, AgendaItemBo agendaItem) {
43  	    Node<AgendaTreeNode, String> child = new Node<AgendaTreeNode, String>();
44  	    child.setNodeLabel(agendaItem.getRuleText());
45  	    child.setNodeType("agendaNode ruleNode");
46  	    child.setData(new AgendaTreeRuleNode(agendaItem));
47  	    parent.getChildren().add(child);
48  	    
49  	    // deal with peer nodes:
50  	    if (agendaItem.getAlways() != null) addAgendaItemAndChildren(parent, agendaItem.getAlways());
51  	    
52  	    // deal with child nodes:
53  	    if (agendaItem.getWhenTrue() != null) {
54  	        Node<AgendaTreeNode, String> whenTrue = new Node<AgendaTreeNode, String>();
55  	        whenTrue.setNodeLabel("When TRUE");
56  	        whenTrue.setNodeType("agendaNode logicNode whenTrueNode");
57  	        whenTrue.setData(new AgendaTreeLogicNode());
58  	        child.getChildren().add(whenTrue);
59  	        
60  	        addAgendaItemAndChildren(whenTrue, agendaItem.getWhenTrue());
61  	    }
62          if (agendaItem.getWhenFalse() != null) {
63              Node<AgendaTreeNode, String> whenFalse = new Node<AgendaTreeNode, String>();
64              whenFalse.setNodeLabel("When FALSE");
65              whenFalse.setNodeType("agendaNode logicNode whenFalseNode");
66              whenFalse.setData(new AgendaTreeLogicNode());
67              child.getChildren().add(whenFalse);
68              
69              addAgendaItemAndChildren(whenFalse, agendaItem.getWhenFalse());
70          }
71  	}
72  	
73      public Tree<? extends AgendaTreeNode, String> getAgendaRuleTree() {
74          Tree<AgendaTreeNode, String> agendaTree = new Tree<AgendaTreeNode, String>();
75  
76          Node<AgendaTreeNode, String> rootNode = new Node<AgendaTreeNode, String>();
77          agendaTree.setRootElement(rootNode);
78          
79          if (agenda != null) {
80              String firstItemId = agenda.getFirstItemId();
81              List<AgendaItemBo> items = agenda.getItems();
82              AgendaItemBo firstItem = null;
83  
84              if (items != null && firstItemId != null) {
85                  for (AgendaItemBo item : items) {
86                      if (firstItemId.equals(item.getId())) {
87                          firstItem = item;
88                          break;
89                      }
90                  }
91              }
92  
93              if (firstItem != null) addAgendaItemAndChildren(rootNode, firstItem);
94          } 
95          
96          return agendaTree;
97      }	
98  	
99  	/**
100      * @return the agendaItemAddLine
101      */
102     public AgendaItemBo getAgendaItemAddLine() {
103         return this.agendaItemAddLine;
104     }
105     /**
106      * @param agendaItemAddLine the agendaItemAddLine to set
107      */
108     public void setAgendaItemAddLine(AgendaItemBo agendaItemAddLine) {
109         this.agendaItemAddLine = agendaItemAddLine;
110     }
111     /**
112 	 * @return the context
113 	 */
114 	public ContextBo getContext() {
115 		return this.context;
116 	}
117 	/**
118 	 * @param context the context to set
119 	 */
120 	public void setContext(ContextBo context) {
121 		this.context = context;
122 	}
123 	/**
124 	 * @return the agenda
125 	 */
126 	public AgendaBo getAgenda() {
127 		return this.agenda;
128 	}
129 	/**
130 	 * @param agenda the agenda to set
131 	 */
132 	public void setAgenda(AgendaBo agenda) {
133 		this.agenda = agenda;
134 	}
135 	
136 	
137 }