1 19 20 21 package org.netbeans.modules.derby; 22 23 import java.awt.Dialog ; 24 import java.io.File ; 25 import org.netbeans.modules.derby.ui.CreateDatabasePanel; 26 import org.netbeans.modules.derby.ui.DerbySystemHomePanel; 27 import org.openide.DialogDescriptor; 28 import org.openide.DialogDisplayer; 29 import org.openide.ErrorManager; 30 import org.openide.util.HelpCtx; 31 import org.openide.util.NbBundle; 32 import org.openide.util.actions.CallableSystemAction; 33 34 38 public class CreateDatabaseAction extends CallableSystemAction { 39 40 41 43 public CreateDatabaseAction() { 44 putValue("noIconInMenu", Boolean.TRUE); 45 } 46 47 public void performAction() { 48 if (!Util.hasInstallLocation()) { 49 Util.showInformation(NbBundle.getMessage(RegisterDerby.class, "MSG_DerbyLocationIncorrect")); 50 return; 51 } 52 53 String derbySystemHome = DerbyOptions.getDefault().getSystemHome(); 54 if (derbySystemHome.length() <= 0) { 55 derbySystemHome = DerbySystemHomePanel.findDerbySystemHome(); 56 if (derbySystemHome.length() > 0) { 57 DerbyOptions.getDefault().setSystemHome(derbySystemHome); 58 } 59 } 60 if (derbySystemHome.length() <= 0) { 61 return; 62 } 63 64 CreateDatabasePanel panel = new CreateDatabasePanel(derbySystemHome); 65 DialogDescriptor desc = new DialogDescriptor(panel, NbBundle.getMessage(CreateDatabaseAction.class, "LBL_CreateDatabaseTitle"), true, null); 66 panel.setDialogDescriptor(desc); 67 Dialog dialog = DialogDisplayer.getDefault().createDialog(desc); 68 String acsd = NbBundle.getMessage(CreateDatabaseAction.class, "ACSD_CreateDatabaseAction"); 69 dialog.getAccessibleContext().setAccessibleDescription(acsd); 70 dialog.setVisible(true); 71 dialog.dispose(); 72 73 if (!DialogDescriptor.OK_OPTION.equals(desc.getValue())) { 74 return; 75 } 76 77 String databaseName = panel.getDatabaseName(); 78 String user = panel.getUser(); 79 String password = panel.getPassword(); 80 81 if (user == null || password == null) { 83 user = null; 84 password = null; 85 } 86 87 try { 88 makeDatabase(databaseName, user, password); 89 } catch (Exception e) { 90 ErrorManager.getDefault().notify(ErrorManager.WARNING, e); 91 } 92 } 93 94 void makeDatabase(String dbname, String user, String password) throws Exception { 95 RegisterDerby.getDefault().postCreateNewDatabase(dbname, user, password); 96 } 97 98 protected boolean asynchronous() { 99 return false; 100 } 101 102 103 public String getName() { 104 return NbBundle.getBundle(CreateDatabaseAction.class).getString("LBL_CreateDBAction"); 105 } 106 107 108 public HelpCtx getHelpCtx() { 109 return new HelpCtx(CreateDatabaseAction.class); 110 } 111 112 } 113 | Popular Tags |