KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > admin > NavTreeModel


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package com.tc.admin;
5
6 import java.util.prefs.Preferences JavaDoc;
7
8 import com.tc.admin.ConnectionContext;
9
10 import com.tc.admin.common.PrefsHelper;
11 import com.tc.admin.common.XTreeModel;
12 import com.tc.admin.common.XTreeNode;
13
14 public class NavTreeModel extends XTreeModel {
15   private static final String JavaDoc SERVERS = ServersHelper.SERVERS;
16   private static final String JavaDoc HOST = ServersHelper.HOST;
17   private static final String JavaDoc PORT = ServersHelper.PORT;
18   private static final String JavaDoc AUTO_CONNECT = ServersHelper.AUTO_CONNECT;
19
20   public NavTreeModel() {
21     super();
22
23     AdminClientContext acc = AdminClient.getContext();
24     Preferences JavaDoc prefs = acc.prefs.node("AdminClient");
25     Preferences JavaDoc serverPrefs = prefs.node(SERVERS);
26     PrefsHelper prefsHelper = PrefsHelper.getHelper();
27     String JavaDoc[] children = prefsHelper.childrenNames(serverPrefs);
28     int count = children.length;
29     Preferences JavaDoc serverPref;
30     ServerNode serverNode;
31     String JavaDoc host;
32     int port;
33     boolean autoConnect;
34
35     if(count > 0) {
36       for(int i = 0; i < count; i++) {
37         serverPref = serverPrefs.node(children[i]);
38         host = serverPref.get(HOST, ConnectionContext.DEFAULT_HOST);
39         port = serverPref.getInt(PORT, ConnectionContext.DEFAULT_PORT);
40         autoConnect = serverPref.getBoolean(AUTO_CONNECT, ConnectionContext.DEFAULT_AUTO_CONNECT);
41         serverNode = new ServerNode(host, port, autoConnect);
42
43         insertNodeInto(serverNode, (XTreeNode)getRoot(), i);
44       }
45     }
46     else {
47       serverNode = new ServerNode();
48       serverNode.setPreferences(serverPrefs.node("server-0"));
49
50       acc.client.storePrefs();
51
52       insertNodeInto(new ServerNode(), (XTreeNode)getRoot(), 0);
53     }
54   }
55 }
56
Popular Tags