1 19 20 package org.netbeans.modules.db.explorer.actions; 21 22 import java.awt.Dialog ; 23 import java.awt.event.ActionEvent ; 24 import java.awt.event.ActionListener ; 25 import java.net.URL ; 26 import java.text.MessageFormat ; 27 import java.util.List ; 28 import org.netbeans.api.db.explorer.DatabaseException; 29 30 import org.openide.DialogDescriptor; 31 import org.openide.DialogDisplayer; 32 import org.openide.NotifyDescriptor; 33 import org.openide.nodes.Node; 34 35 import org.netbeans.modules.db.explorer.dlg.AddDriverDialog; 36 import org.netbeans.api.db.explorer.JDBCDriver; 37 import org.netbeans.api.db.explorer.JDBCDriverManager; 38 39 public class AddDriverAction extends DatabaseAction { 40 static final long serialVersionUID =-109193000951395612L; 41 42 public void performAction(Node[] activatedNodes) { 43 new AddDriverDialogDisplayer().showDialog(); 44 } 45 46 public static final class AddDriverDialogDisplayer { 47 48 private Dialog dialog; 49 private JDBCDriver driver; 50 51 public void showDialog() { 52 final AddDriverDialog dlgPanel = new AddDriverDialog(); 53 54 ActionListener actionListener = new ActionListener () { 55 public void actionPerformed(ActionEvent event) { 56 if (event.getSource() == DialogDescriptor.OK_OPTION) { 57 String name = dlgPanel.getDisplayName(); 58 List drvLoc = dlgPanel.getDriverLocation(); 59 String drvClass = dlgPanel.getDriverClass(); 60 61 StringBuffer err = new StringBuffer (); 62 if (drvLoc.size() < 1) 63 err.append(bundle().getString("AddDriverDialog_MissingFile")); if (drvClass == null || drvClass.equals("")) { 65 if (err.length() > 0) 66 err.append(", "); 68 err.append(bundle().getString("AddDriverDialog_MissingClass")); } 70 if (err.length() > 0) { 71 String message = MessageFormat.format(bundle().getString("AddDriverDialog_ErrorMessage"), new String [] {err.toString()}); DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message(message, NotifyDescriptor.INFORMATION_MESSAGE)); 73 74 return; 75 } 76 77 if (dialog != null) 78 dialog.dispose(); 79 80 if (name == null || name.equals("")) name = drvClass; 83 84 try { 85 driver = JDBCDriver.create(name, name, drvClass, (URL []) drvLoc.toArray(new URL [drvLoc.size()])); 86 JDBCDriverManager.getDefault().addDriver(driver); 87 } catch (DatabaseException exc) { 88 } 90 } 91 } 92 }; 93 94 DialogDescriptor descriptor = new DialogDescriptor(dlgPanel, bundle().getString("AddDriverDialogTitle"), true, actionListener); Object [] closingOptions = {DialogDescriptor.CANCEL_OPTION}; 96 descriptor.setClosingOptions(closingOptions); 97 dialog = DialogDisplayer.getDefault().createDialog(descriptor); 98 dialog.setVisible(true); 99 } 100 } 101 } 102 | Popular Tags |