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 java.util.*;
27 import zeus.util.*;
28 import zeus.gui.graph.*;
29
30 public class EngineGraphModel extends AbstractGraphModel{
31 final static int ADD = 0;
32 final static int DELETE = 1;
33 final static int CHANGE = 2;
34 private int BUFFER_CAPACITY = 50;
35 private int REMOVE_INDEX = 0;
36
37
38 GraphNode root;
39 Hashtable allNodes = new Hashtable();
40
41 public EngineGraphModel(GraphNode root){
42 this.root = root;
43 }
44 //--------------------------------------------------------------------------
45 public Enumeration nodes() {
46 addNode(root);
47 getAllNodesOf(root);
48 return allNodes.elements();
49 }
50 //--------------------------------------------------------------------------
51 public boolean isLinkVisible(GraphNode from, GraphNode to) {
52 return to.hasParent(from) ;
53 }
54 //--------------------------------------------------------------------------
55 public void setValue(GraphNode node, Object user_object) {}
56 //--------------------------------------------------------------------------
57 public boolean isNodeEditable(GraphNode node) { return false; }
58 //--------------------------------------------------------------------------
59 private void getAllNodesOf(GraphNode a_node) {
60 GraphNode[] children = a_node.getChildren();
61
62 for(int i = 0; i < children.length; i++ ) {
63 addNode(children[i]);
64 getAllNodesOf(children[i]);
65 }
66 }
67 //--------------------------------------------------------------------------
68 public GraphNode getRoot() {
69 return root;
70 }
71 //--------------------------------------------------------------------------
72 private void addNode(GraphNode gNode){
73
74 zeus.actors.rtn.Node node = (zeus.actors.rtn.Node)gNode.getUserObject();
75 allNodes.put(node.getDescription(),gNode);
76 }
77 //--------------------------------------------------------------------------
78 public void refresh(int val, GraphNode aNode) {
79 if ( val == CHANGE )
80 fireGraphNodeStateChanged(aNode);
81 else
82 fireGraphStructureChanged();
83 }
84 //--------------------------------------------------------------------------
85 void deleteTree(GraphsModel graphsModel) {
86 deleteTreeNode(root,graphsModel);
87 }
88
89 protected void deleteTreeNode(GraphNode a_node, GraphsModel graphsModel) {
90 GraphNode[] children = a_node.getChildren();
91
92 for(int i = 0; i < children.length; i++ )
93 deleteTreeNode(children[i],graphsModel);
94
95 graphsModel.removeNode(a_node);
96 }
97
98 }