1 /*
2 * The contents of this file are subject to the BT "ZEUS" Open Source
3 * Licence (L77741), Version 1.0 (the "Licence"); you may not use this file
4 * except in compliance with the Licence. You may obtain a copy of the Licence
5 * from $ZEUS_INSTALL/licence.html or alternatively from
6 * http://www.labs.bt.com/projects/agents/zeus/licence.htm
7 *
8 * Except as stated in Clause 7 of the Licence, software distributed under the
9 * Licence is distributed WITHOUT WARRANTY OF ANY KIND, either express or
10 * implied. See the Licence for the specific language governing rights and
11 * limitations under the Licence.
12 *
13 * The Original Code is within the package zeus.*.
14 * The Initial Developer of the Original Code is British Telecommunications
15 * public limited company, whose registered office is at 81 Newgate Street,
16 * London, EC1A 7AJ, England. Portions created by British Telecommunications
17 * public limited company are Copyright 1996-9. All Rights Reserved.
18 *
19 * THIS NOTICE MUST BE INCLUDED ON ANY COPY OF THIS FILE
20 */
21
22
23
24 package zeus.agentviewer.engine;
25
26 import zeus.util.OrderedHashtable;
27 import zeus.actors.rtn.Node;
28 import zeus.actors.event.NodeEvent;
29 import zeus.gui.graph.*;
30
31
32 public class GraphsModel {
33
34 private OrderedHashtable data;
35 //--------------------------------------------------------------------------
36 public GraphsModel() {
37 data = new OrderedHashtable();
38 }
39 //--------------------------------------------------------------------------
40 public GraphNode addToGraph(NodeEvent event){
41 GraphNode parent;
42 Node node = event.getNode();
43 GraphNode gNode = new GraphNode(node);
44 String nodeName = event.getNodeName();
45 String[] parentNames = event.getParentNames();
46
47 for(int i = 0; i< parentNames.length; i++) {
48 if ( data.containsKey(parentNames[i]) ) {
49 parent = (GraphNode) data.get(parentNames[i]);
50 parent.addChild(gNode);
51 gNode.addParent(parent);
52 }
53 }
54 data.put(nodeName,gNode);
55 return gNode;
56 }
57 //--------------------------------------------------------------------------
58 public GraphNode changeNode(NodeEvent event){
59 GraphNode aGraphNode = null;
60
61 if (data.containsKey(event.getNodeName())) {
62 aGraphNode = (GraphNode) data.get(event.getNodeName());
63 aGraphNode.setUserObject(event.getNode());
64 }
65 return aGraphNode;
66 }
67 //--------------------------------------------------------------------------
68 public void addRoot(String rootName, GraphNode root) {
69 data.put(rootName,root);
70 }
71 //--------------------------------------------------------------------------
72 public void removeAll(){
73 data.clear();
74 }
75 //--------------------------------------------------------------------------
76 public void removeNode(NodeEvent event){
77 data.remove(event.getNodeName());
78 }
79 public void removeNode(GraphNode gnode){
80 Node node = (Node)gnode.getUserObject();
81 data.remove(node.getDescription());
82 }
83
84 //--------------------------------------------------------------------------
85 public GraphNode getRoot(String name) {
86 GraphNode root = null;
87 GraphNode node = (GraphNode)data.get(name);
88 GraphNode[] parents = node.getParents();
89 if ( parents.length == 0 ) return node;
90
91 while( parents.length != 0 ) {
92 root = parents[0];
93 parents = parents[0].getParents();
94 }
95 return root;
96 }
97 }