1   
2   
3   
4   
5   
6   
7   
8   
9   
10  
11  
12  
13  
14  
15  
16  package org.kuali.rice.krms.impl.ui;
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.impl.repository.ActionBo;
21  import org.kuali.rice.krms.impl.repository.AgendaBo;
22  import org.kuali.rice.krms.impl.repository.AgendaItemBo;
23  import org.kuali.rice.krms.impl.repository.ContextBo;
24  
25  import java.io.Serializable;
26  import java.util.HashMap;
27  import java.util.List;
28  import java.util.Map;
29  
30  
31  
32  
33  
34  
35  
36  public class AgendaEditor implements Serializable {
37  	
38  	private static final long serialVersionUID = 1L;
39  	
40  	private ContextBo context;
41      private String namespace;
42  	private AgendaBo agenda;
43      private String contextName;
44  	private AgendaItemBo agendaItemLine;
45      private ActionBo agendaItemLineRuleAction;
46      private String selectedAgendaItemId;
47      private String cutAgendaItemId;
48      private String selectedPropositionId;
49      private String cutPropositionId;
50      private String copyRuleName;
51      private String oldContextId;
52      private String ruleEditorMessage;
53      private boolean addRuleInProgress = false;
54      private boolean disableButtons = false;
55      private Map<String, String> customAttributesMap = new HashMap<String, String>();
56      private Map<String, String> customRuleAttributesMap = new HashMap<String, String>();
57      private Map<String, String> customRuleActionAttributesMap = new HashMap<String, String>();
58  
59      public AgendaEditor() {
60          agenda = new AgendaBo();
61          
62          agenda.setTypeId("");
63          agendaItemLine = new AgendaItemBo();
64          agendaItemLineRuleAction = new ActionBo();
65      }
66  
67  	private void addAgendaItemAndChildren(Node<AgendaTreeNode, String> parent, AgendaItemBo agendaItem) {
68  	    Node<AgendaTreeNode, String> child = new Node<AgendaTreeNode, String>();
69  	    child.setNodeLabel(agendaItem.getRuleText());
70  	    child.setNodeType("agendaNode ruleNode");
71  	    child.setData(new AgendaTreeRuleNode(agendaItem));
72  	    parent.getChildren().add(child);
73  	    
74  	    
75  	    if (agendaItem.getAlways() != null) addAgendaItemAndChildren(parent, agendaItem.getAlways());
76  	    
77  	    
78  	    if (agendaItem.getWhenTrue() != null) {
79  	        Node<AgendaTreeNode, String> whenTrue = new Node<AgendaTreeNode, String>();
80  	        whenTrue.setNodeLabel("When TRUE");
81  	        whenTrue.setNodeType("agendaNode logicNode whenTrueNode");
82  	        whenTrue.setData(new AgendaTreeLogicNode());
83  	        child.getChildren().add(whenTrue);
84  	        
85  	        addAgendaItemAndChildren(whenTrue, agendaItem.getWhenTrue());
86  	    }
87          if (agendaItem.getWhenFalse() != null) {
88              Node<AgendaTreeNode, String> whenFalse = new Node<AgendaTreeNode, String>();
89              whenFalse.setNodeLabel("When FALSE");
90              whenFalse.setNodeType("agendaNode logicNode whenFalseNode");
91              whenFalse.setData(new AgendaTreeLogicNode());
92              child.getChildren().add(whenFalse);
93              
94              addAgendaItemAndChildren(whenFalse, agendaItem.getWhenFalse());
95          }
96  	}
97  	
98      public Tree<? extends AgendaTreeNode, String> getAgendaRuleTree() {
99          Tree<AgendaTreeNode, String> agendaTree = new Tree<AgendaTreeNode, String>();
100 
101         Node<AgendaTreeNode, String> rootNode = new Node<AgendaTreeNode, String>();
102         agendaTree.setRootElement(rootNode);
103         
104         if (agenda != null) {
105             String firstItemId = agenda.getFirstItemId();
106             List<AgendaItemBo> items = agenda.getItems();
107             AgendaItemBo firstItem = null;
108 
109             if (items != null && firstItemId != null) {
110                 for (AgendaItemBo item : items) {
111                     if (firstItemId.equals(item.getId())) {
112                         firstItem = item;
113                         break;
114                     }
115                 }
116             }
117 
118             if (firstItem != null) addAgendaItemAndChildren(rootNode, firstItem);
119         } 
120         
121         return agendaTree;
122     }	
123 	
124 	
125 
126 
127     public AgendaItemBo getAgendaItemLine() {
128         return this.agendaItemLine;
129     }
130 
131     
132 
133 
134     public void setAgendaItemLine(AgendaItemBo agendaItemLine) {
135         this.agendaItemLine = agendaItemLine;
136     }
137 
138     public ActionBo getAgendaItemLineRuleAction() {
139         return agendaItemLineRuleAction;
140     }
141 
142     public void setAgendaItemLineRuleAction(ActionBo actionBo) {
143         this.agendaItemLineRuleAction = actionBo;
144     }
145 
146     
147 
148 
149     public String getSelectedAgendaItemId() {
150         return this.selectedAgendaItemId;
151     }
152 
153     
154 
155 
156     public void setSelectedAgendaItemId(String selectedAgendaItemId) {
157         this.selectedAgendaItemId = selectedAgendaItemId;
158     }
159 
160     
161 
162 
163     public String getCutAgendaItemId() {
164         return this.cutAgendaItemId;
165     }
166 
167     
168 
169 
170     public void setCutAgendaItemId(String cutAgendaItemId) {
171         this.cutAgendaItemId = cutAgendaItemId;
172     }
173 
174     
175 
176 
177 	public ContextBo getContext() {
178 		return this.context;
179 	}
180 
181 	
182 
183 
184 	public void setContext(ContextBo context) {
185 		this.context = context;
186 	}
187 
188 	
189 
190 
191 	public AgendaBo getAgenda() {
192 		return this.agenda;
193 	}
194 
195 	
196 
197 
198 	public void setAgenda(AgendaBo agenda) {
199 		this.agenda = agenda;
200 	}
201 
202     public Map<String, String> getCustomAttributesMap() {
203         return customAttributesMap;
204     }
205 
206     public void setCustomAttributesMap(Map<String, String> customAttributesMap) {
207         this.customAttributesMap = customAttributesMap;
208     }
209 
210     public Map<String, String> getCustomRuleAttributesMap() {
211         return customRuleAttributesMap;
212     }
213 
214     public void setCustomRuleAttributesMap(Map<String, String> customRuleAttributesMap) {
215         this.customRuleAttributesMap = customRuleAttributesMap;
216     }
217 
218     public Map<String, String> getCustomRuleActionAttributesMap() {
219         return customRuleActionAttributesMap;
220     }
221 
222     public void setCustomRuleActionAttributesMap(Map<String, String> customRuleActionAttributesMap) {
223         this.customRuleActionAttributesMap = customRuleActionAttributesMap;
224     }
225 
226     
227 
228 
229     public void setCopyRuleName(String copyRuleName) {
230         this.copyRuleName = copyRuleName;
231     }
232 
233     
234 
235 
236     public String getCopyRuleName() {
237         return copyRuleName;
238     }
239 
240     
241 
242 
243     public void setOldContextId(String oldContextId) {
244         this.oldContextId = oldContextId;
245     }
246 
247     
248 
249 
250     public String getOldContextId() {
251         return oldContextId;
252     }
253 
254     
255 
256 
257     public String getSelectedPropositionId() {
258         return this.selectedPropositionId;
259     }
260 
261     
262 
263 
264     public void setSelectedPropositionId(String selectedPropositionId) {
265         this.selectedPropositionId = selectedPropositionId;
266     }
267 
268 
269     
270 
271 
272     public String getCutPropositionId() {
273         return cutPropositionId;
274     }
275 
276     public String getContextName() {
277         return contextName;
278     }
279 
280     public void setContextName(String contextName) {
281         this.contextName = contextName;
282     }
283 
284     public String getNamespace() {
285         return namespace;
286     }
287 
288     public void setNamespace(String namespace) {
289         this.namespace = namespace;
290     }
291 
292     public String getRuleEditorMessage() {
293         return this.ruleEditorMessage;
294     }
295 
296     public void setRuleEditorMessage(String message) {
297         this.ruleEditorMessage = message;
298     }
299 
300     public boolean isAddRuleInProgress() {
301         return addRuleInProgress;
302     }
303 
304     public void setAddRuleInProgress(boolean addRuleInProgress) {
305         this.addRuleInProgress = addRuleInProgress;
306     }
307 
308     
309 
310 
311 
312     public boolean isDisableButtons() {
313         return disableButtons;
314     }
315 
316     
317 
318 
319 
320 
321     public void setDisableButtons(boolean disableButtons) {
322         this.disableButtons = disableButtons;
323     }
324 
325     
326 
327 
328     public void setCutPropositionId(String cutPropositionId) {
329         this.cutPropositionId = cutPropositionId;
330     }
331 }