1 4 package com.tc.admin; 5 6 import java.util.prefs.Preferences ; 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 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, 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 |