Issue 129633: Provide API that let's you call showAddDriver on AWT thread and return the driver diff --git a/db/apichanges.xml b/db/apichanges.xml --- a/db/apichanges.xml +++ b/db/apichanges.xml @@ -105,6 +105,20 @@ + + + Add ability to show the Add JDBC Driver dialog synchronously + + + + + + Add the ability to show the Add Driver dialog synchronously. This + must be run on the AWT event thread, but it gives you the ability to + immediately get the resulting JDBCDriver that was added. + + + Add ability to connect a database connection directly with no UI diff --git a/db/manifest.mf b/db/manifest.mf --- a/db/manifest.mf +++ b/db/manifest.mf @@ -1,7 +1,7 @@ Manifest-Version: 1.0 OpenIDE-Module: org.netbeans.modules.db/1 OpenIDE-Module-Install: org/netbeans/modules/db/DatabaseModule.class -OpenIDE-Module-Implementation-Version: 26 +OpenIDE-Module-Implementation-Version: 27 OpenIDE-Module-Layer: org/netbeans/modules/db/resources/mf-layer.xml OpenIDE-Module-Requires: org.netbeans.api.javahelp.Help OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/db/resources/Bundle.properties diff --git a/db/src/org/netbeans/api/db/explorer/JDBCDriverManager.java b/db/src/org/netbeans/api/db/explorer/JDBCDriverManager.java --- a/db/src/org/netbeans/api/db/explorer/JDBCDriverManager.java +++ b/db/src/org/netbeans/api/db/explorer/JDBCDriverManager.java @@ -184,6 +184,23 @@ new AddDriverAction.AddDriverDialogDisplayer().showDialog(); } } + + /** + * Shows the Add Driver dialog synchronously. Must be run from the + * AWT event thread; an IllegalStateException will be thrown if this + * method is called from any other thread. + * + * @return the new driver that was added, or null if the driver was + * not successfully created + * + * @since 1.27 + */ + public JDBCDriver showAddDriverDialogFromEventThread() { + if (!SwingUtilities.isEventDispatchThread()) { + throw new IllegalStateException("The current thread is not the event dispatching thread."); // NOI18N + } + return new AddDriverAction.AddDriverDialogDisplayer().showDialog(); + } /** * Registers a JDBCDriverListener. diff --git a/db/src/org/netbeans/modules/db/explorer/actions/AddDriverAction.java b/db/src/org/netbeans/modules/db/explorer/actions/AddDriverAction.java --- a/db/src/org/netbeans/modules/db/explorer/actions/AddDriverAction.java +++ b/db/src/org/netbeans/modules/db/explorer/actions/AddDriverAction.java @@ -57,10 +57,12 @@ import org.netbeans.modules.db.explorer.dlg.AddDriverDialog; import org.netbeans.api.db.explorer.JDBCDriver; import org.netbeans.api.db.explorer.JDBCDriverManager; +import org.openide.util.Exceptions; public class AddDriverAction extends DatabaseAction { static final long serialVersionUID =-109193000951395612L; - + + @Override public void performAction(Node[] activatedNodes) { new AddDriverDialogDisplayer().showDialog(); } @@ -68,9 +70,9 @@ public static final class AddDriverDialogDisplayer { private Dialog dialog; - private JDBCDriver driver; + private JDBCDriver driver = null; - public void showDialog() { + public JDBCDriver showDialog() { final AddDriverDialog dlgPanel = new AddDriverDialog(); ActionListener actionListener = new ActionListener() { @@ -90,7 +92,8 @@ err.append(bundle().getString("AddDriverDialog_MissingClass")); //NOI18N } if (err.length() > 0) { - String message = MessageFormat.format(bundle().getString("AddDriverDialog_ErrorMessage"), new String[] {err.toString()}); //NOI18N + String message = MessageFormat.format(bundle().getString("AddDriverDialog_ErrorMessage"), + err.toString()); //NOI18N DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message(message, NotifyDescriptor.INFORMATION_MESSAGE)); return; @@ -107,7 +110,7 @@ driver = JDBCDriver.create(name, name, drvClass, (URL[]) drvLoc.toArray(new URL[drvLoc.size()])); JDBCDriverManager.getDefault().addDriver(driver); } catch (DatabaseException exc) { - //PENDING + Exceptions.printStackTrace(exc); } } } @@ -118,6 +121,7 @@ descriptor.setClosingOptions(closingOptions); dialog = DialogDisplayer.getDefault().createDialog(descriptor); dialog.setVisible(true); + return driver; } } }