01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
03: */
04: package com.tc.admin;
05:
06: import java.util.prefs.Preferences;
07:
08: import com.tc.admin.ConnectionContext;
09:
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 SERVERS = ServersHelper.SERVERS;
16: private static final String HOST = ServersHelper.HOST;
17: private static final String PORT = ServersHelper.PORT;
18: private static final String AUTO_CONNECT = ServersHelper.AUTO_CONNECT;
19:
20: public NavTreeModel() {
21: super ();
22:
23: AdminClientContext acc = AdminClient.getContext();
24: Preferences prefs = acc.prefs.node("AdminClient");
25: Preferences serverPrefs = prefs.node(SERVERS);
26: PrefsHelper prefsHelper = PrefsHelper.getHelper();
27: String[] children = prefsHelper.childrenNames(serverPrefs);
28: int count = children.length;
29: Preferences serverPref;
30: ServerNode serverNode;
31: String 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,
39: ConnectionContext.DEFAULT_HOST);
40: port = serverPref.getInt(PORT,
41: ConnectionContext.DEFAULT_PORT);
42: autoConnect = serverPref.getBoolean(AUTO_CONNECT,
43: ConnectionContext.DEFAULT_AUTO_CONNECT);
44: serverNode = new ServerNode(host, port, autoConnect);
45:
46: insertNodeInto(serverNode, (XTreeNode) getRoot(), i);
47: }
48: } else {
49: serverNode = new ServerNode();
50: serverNode.setPreferences(serverPrefs.node("server-0"));
51:
52: acc.client.storePrefs();
53:
54: insertNodeInto(new ServerNode(), (XTreeNode) getRoot(), 0);
55: }
56: }
57: }
|