1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 package uk.ac.rdg.resc.jstyx.gridservice.client;
30
31 import java.util.Vector;
32
33 import javax.swing.tree.DefaultTreeModel;
34 import javax.swing.tree.DefaultMutableTreeNode;
35
36 import javax.swing.event.TreeExpansionEvent;
37 import javax.swing.event.TreeExpansionListener;
38
39 import uk.ac.rdg.resc.jstyx.client.StyxConnection;
40 import uk.ac.rdg.resc.jstyx.client.CStyxFileChangeListener;
41 import uk.ac.rdg.resc.jstyx.client.CStyxFile;
42
43
44 /***
45 * Data model for tree view of SGS servers and services in the SGSExplorer.
46 * Only allows drilling down to the level of service instances. Hierarchy is
47 * server -> service -> instance.
48 *
49 * @author Jon Blower
50 * $Revision: 310 $
51 * $Date: 2005-07-06 18:53:44 +0100 (Wed, 06 Jul 2005) $
52 * $Log$
53 * Revision 1.6 2005/07/06 17:53:44 jonblower
54 * Implementing automatic update of SGS instances in SGS Explorer
55 *
56 * Revision 1.5 2005/05/17 18:20:50 jonblower
57 * Separated CStyxFileNode from SGSExplorerTreeModel
58 *
59 * Revision 1.4 2005/05/17 15:51:43 jonblower
60 * Correct operation of display of tree of SGS servers, services and instances
61 *
62 * Revision 1.3 2005/05/17 07:52:23 jonblower
63 * Further developments
64 *
65 * Revision 1.2 2005/05/16 16:49:22 jonblower
66 * Updated to use CStyxFileNode as a general node in the model
67 *
68 * Revision 1.1 2005/05/16 16:17:47 jonblower
69 * Initial import
70 *
71 */
72 public class SGSExplorerTreeModel extends DefaultTreeModel implements TreeExpansionListener
73 {
74
75 /*** Creates a new instance of SGSExplorerTreeModel */
76 public SGSExplorerTreeModel()
77 {
78 super(new DefaultMutableTreeNode("/", true), true);
79 }
80
81 /***
82 * Adds a new connection to a server to this tree model
83 */
84 public void addNewConnection(StyxConnection conn)
85 {
86
87 String str = conn.getRemoteHost() + ":" + conn.getRemotePort();
88 String str2 = str;
89
90
91 int j = 1;
92 boolean exists;
93 synchronized (this.root)
94 {
95 do
96 {
97 exists = false;
98 for (int i = 0; i < this.root.getChildCount(); i++)
99 {
100 CStyxFileNode node =
101 (CStyxFileNode)this.root.getChildAt(i);
102 if (str2.equals(node.toString()))
103 {
104 exists = true;
105 break;
106 }
107 }
108 if (exists)
109 {
110
111
112 str2 = str + " [" + j + "]";
113 j++;
114 }
115 } while (exists);
116
117
118 int insertLocation = this.root.getChildCount();
119 DefaultMutableTreeNode newNode =
120 new CStyxFileNode(this, conn.getRootDirectory(), str2);
121
122 this.insertNodeInto(newNode, (DefaultMutableTreeNode)this.root,
123 insertLocation);
124 }
125 }
126
127 /***
128 * Required by TreeExpansionListener. Causes the node's children to be
129 * loaded.
130 */
131 public void treeExpanded(TreeExpansionEvent event)
132 {
133 Object source = event.getPath().getLastPathComponent();
134 if (source instanceof CStyxFileNode)
135 {
136 CStyxFileNode node = (CStyxFileNode)source;
137
138
139 node.findChildren();
140 }
141 }
142
143 /***
144 * Required by TreeExpansionListener. Does nothing here.
145 */
146 public void treeCollapsed(TreeExpansionEvent event) {}
147
148 }