1 56 package org.objectstyle.cayenne.modeler.action; 57 58 import java.awt.event.ActionEvent ; 59 import java.sql.Connection ; 60 61 import org.objectstyle.cayenne.access.DataDomain; 62 import org.objectstyle.cayenne.dba.DbAdapter; 63 import org.objectstyle.cayenne.modeler.Application; 64 import org.objectstyle.cayenne.modeler.dialog.db.ConnectionWizard; 65 import org.objectstyle.cayenne.modeler.dialog.db.DbLoaderHelper; 66 import org.objectstyle.cayenne.modeler.pref.DBConnectionInfo; 67 import org.objectstyle.cayenne.project.ProjectPath; 68 69 72 public class ImportDBAction extends DBWizardAction { 73 74 public static String getActionName() { 75 return "Reengineer Database Schema"; 76 } 77 78 public ImportDBAction(Application application) { 79 super(getActionName(), application); 80 } 81 82 86 public void performAction(ActionEvent event) { 87 88 DBConnectionInfo nodeInfo = preferredDataSource(); 90 String nodeKey = preferredDataSourceLabel(nodeInfo); 91 92 ConnectionWizard connectWizard = new ConnectionWizard( 94 getProjectController(), 95 "Reengineer DB Schema: Connect to Database", 96 nodeKey, 97 nodeInfo); 98 99 if (!connectWizard.startupAction()) { 100 return; 102 } 103 104 Connection connection = connectWizard.getConnection(); 105 DbAdapter adapter = connectWizard.getAdapter(); 106 DBConnectionInfo dataSourceInfo = connectWizard.getConnectionInfo(); 107 108 111 final DbLoaderHelper helper = new DbLoaderHelper( 112 getProjectController(), 113 connection, 114 adapter, 115 dataSourceInfo.getUserName()); 116 Thread th = new Thread (new Runnable () { 117 118 public void run() { 119 helper.execute(); 120 } 121 }); 122 th.start(); 123 } 124 125 128 public boolean enableForPath(ProjectPath path) { 129 if (path == null) { 130 return false; 131 } 132 133 return path.firstInstanceOf(DataDomain.class) != null; 134 } 135 } | Popular Tags |