1 19 20 package org.netbeans.modules.db.explorer.infos; 21 22 import java.util.*; 23 import org.openide.filesystems.*; 24 import org.openide.loaders.DataFolder; 25 import org.openide.loaders.DataObject; 26 27 import org.netbeans.lib.ddl.*; 28 import org.netbeans.api.db.explorer.DatabaseException; 29 import org.netbeans.modules.db.explorer.DatabaseConnection; 30 import org.netbeans.modules.db.explorer.DatabaseNodeChildren; 31 import org.netbeans.modules.db.explorer.ConnectionList; 32 import org.netbeans.modules.db.explorer.nodes.*; 33 34 public class RootNodeInfo extends DatabaseNodeInfo implements ConnectionOwnerOperations { 35 static final long serialVersionUID =-8079386805046070315L; 36 37 static RootNodeInfo rootInfo = null; 38 public static RootNodeInfo getInstance() throws DatabaseException { 39 if (rootInfo == null) { 40 rootInfo = (RootNodeInfo) DatabaseNodeInfo.createNodeInfo(null, "root"); } 42 return rootInfo; 43 } 44 public void initChildren(Vector children) throws DatabaseException { 45 try { 46 DatabaseConnection[] cinfos = ConnectionList.getDefault().getConnections(); 47 for (int i = 0; i < cinfos.length; i++) { 48 DatabaseConnection cinfo = cinfos[i]; 49 ConnectionNodeInfo ninfo = createConnectionNodeInfo(cinfo); 50 children.add(ninfo); 51 } 52 53 Repository r = Repository.getDefault(); 54 FileSystem rfs = r.getDefaultFileSystem(); 55 FileObject rootFolder = rfs.getRoot(); 56 FileObject databaseFileObject = rootFolder.getFileObject("Database"); if (databaseFileObject != null) { 58 FileObject adaptorsFolder = databaseFileObject.getFileObject("Adaptors"); DataObject dbdo = DataFolder.findFolder(adaptorsFolder); 60 if (dbdo != null) 61 children.add(dbdo.getNodeDelegate()); 62 } 63 64 } catch (Exception e) { 65 throw new DatabaseException(e.getMessage()); 66 } 67 } 68 69 private ConnectionNodeInfo createConnectionNodeInfo(DatabaseConnection dbconn) throws DatabaseException { 70 ConnectionNodeInfo ninfo = (ConnectionNodeInfo)createNodeInfo(this, DatabaseNode.CONNECTION); 71 ninfo.setUser(dbconn.getUser()); 72 ninfo.setDatabase(dbconn.getDatabase()); 73 ninfo.setSchema(dbconn.getSchema()); 74 ninfo.setName(dbconn.getName()); 75 ninfo.setDatabaseConnection(dbconn); 76 return ninfo; 77 } 78 79 public void refreshChildren() throws DatabaseException { 80 } 82 83 public void addConnectionNoConnect(DatabaseConnection dbconn) throws DatabaseException { 84 getChildren(); 86 if (ConnectionList.getDefault().contains(dbconn)) { 87 return; 88 } 89 90 DatabaseNode node = getNode(); 91 DatabaseNodeChildren children = (DatabaseNodeChildren) node.getChildren(); 92 ConnectionNodeInfo ninfo = createConnectionNodeInfo(dbconn); 93 ConnectionList.getDefault().add(dbconn); 94 children.createSubnode(ninfo, true); 95 } 96 97 public void addConnection(DBConnection cinfo) throws DatabaseException { 98 DatabaseConnection dbconn = (DatabaseConnection)cinfo; 99 getChildren(); 101 if (ConnectionList.getDefault().contains(dbconn)) { 102 throw new DatabaseException(bundle().getString("EXC_ConnectionAlreadyExists")); 103 } 104 105 DatabaseNode node = getNode(); 106 DatabaseNodeChildren children = (DatabaseNodeChildren) node.getChildren(); 107 108 children.getNodes(true); 112 113 ConnectionNodeInfo ninfo = createConnectionNodeInfo(dbconn); 114 ConnectionList.getDefault().add(dbconn); 115 DatabaseNode cnode = children.createSubnode(ninfo, true); 116 117 if (((DatabaseConnection) dbconn).getConnection() == null) 118 ((ConnectionNodeInfo) cnode.getInfo()).connect(); 119 else 120 ((ConnectionNodeInfo) cnode.getInfo()).connect(dbconn); 121 } 122 } 123 | Popular Tags |