Index: apichanges.xml =================================================================== RCS file: /cvs/db/apichanges.xml,v retrieving revision 1.1.4.2.2.3 diff -u -r1.1.4.2.2.3 apichanges.xml --- apichanges.xml 20 Jul 2006 14:29:39 -0000 1.1.4.2.2.3 +++ apichanges.xml 20 Jul 2006 15:22:50 -0000 @@ -84,6 +84,24 @@ + Addded a method to open the NewConnectionDialog with an user and password pre-filled and methods which open the NewConnectionDialog and return the newly added database connection + + + + + + This change adds a showAddConnectionDialog which opens the + New Connection Dialog while pre-filling a specified database user and password. + It also adds showAddConnectionDialogFromEventThread methods + which are counterparts to the showAddConnectionDialog methods, + with the difference that they return the newly added database connection, + but must be called from the event dispatching thread. + + + + + + Addded an utility method to fill a combo box with database connections Index: arch.xml =================================================================== RCS file: /cvs/db/arch.xml,v retrieving revision 1.3.2.2.2.5 diff -u -r1.3.2.2.2.5 arch.xml --- arch.xml 20 Jul 2006 10:24:30 -0000 1.3.2.2.2.5 +++ arch.xml 20 Jul 2006 15:22:50 -0000 @@ -263,8 +263,8 @@

Usually when displaying a list of connections (usually in a combo box), the last item is "New Connection", which displays the standard New Database Connection - dialog of the Database Explorer. This can be achieved by calling - ConnectionManager.showAddConnectionDialog(). + dialog of the Database Explorer. This can be achieved by calling one of the + ConnectionManager.showAddConnectionDialog() methods.

@@ -800,8 +800,10 @@ -->

- The API is thread-safe. The methods are not required to run on the event queue (although + The API is thread-safe. Most methods are not required to run on the event queue (although the implementation of methods which display an UI switches to the event thread where necessary). + The methods which are required to run on the event queue say so in the + Javadoc and exceptions are thrown if this condition does not hold. Events are fired synchronously.

Index: nbproject/project.properties =================================================================== RCS file: /cvs/db/nbproject/project.properties,v retrieving revision 1.8.2.3.2.6 diff -u -r1.8.2.3.2.6 project.properties --- nbproject/project.properties 12 Jul 2006 15:12:23 -0000 1.8.2.3.2.6 +++ nbproject/project.properties 20 Jul 2006 15:22:50 -0000 @@ -19,7 +19,7 @@ javadoc.arch=${basedir}/arch.xml javadoc.apichanges=${basedir}/apichanges.xml -spec.version.base=1.18.20 +spec.version.base=1.19.20 extra.module.files=modules/ext/ddl.jar Index: src/org/netbeans/api/db/explorer/ConnectionManager.java =================================================================== RCS file: /cvs/db/src/org/netbeans/api/db/explorer/ConnectionManager.java,v retrieving revision 1.2.2.1.2.3 diff -u -r1.2.2.1.2.3 ConnectionManager.java --- src/org/netbeans/api/db/explorer/ConnectionManager.java 20 Jul 2006 10:39:22 -0000 1.2.2.1.2.3 +++ src/org/netbeans/api/db/explorer/ConnectionManager.java 20 Jul 2006 15:22:50 -0000 @@ -19,6 +19,7 @@ package org.netbeans.api.db.explorer; +import javax.swing.SwingUtilities; import org.netbeans.lib.ddl.DBConnection; import org.netbeans.modules.db.explorer.ConnectionList; import org.netbeans.modules.db.explorer.actions.ConnectUsingDriverAction; @@ -123,7 +124,7 @@ * @param driver the JDBC driver; can be null. */ public void showAddConnectionDialog(JDBCDriver driver) { - showAddConnectionDialog(driver, null); + showAddConnectionDialog(driver, null, null, null); } /** @@ -137,13 +138,99 @@ * @param databaseUrl the database URL; can be null. */ public void showAddConnectionDialog(JDBCDriver driver, final String databaseUrl) { - final String driverClass = (driver != null) ? driver.getClassName() : null; - final String driverName = (driver != null) ? driver.getName() : null; + showAddConnectionDialog(driver, databaseUrl, null, null); + } + + /** + * Shows the dialog for adding a new connection with the specified database URL, user and password + * The specified driver be filled as the single element of the + * Driver combo box of the New Database Connection dialog box. + * The database URL will be filled in the Database URL field in the + * New Database Connection dialog box. + * The user and password will be filled in the User Name and Password + * fields in the New Database Connection dialog box. + * + * @param driver the JDBC driver; can be null. + * @param databaseUrl the database URL; can be null. + * @param user the database user; can be null. + * @param password user's password; can be null. + * + * @since 1.19 + */ + public void showAddConnectionDialog(final JDBCDriver driver, final String databaseUrl, final String user, final String password) { Mutex.EVENT.readAccess(new Runnable() { public void run() { - new ConnectUsingDriverAction.NewConnectionDialogDisplayer().showDialog(driverName, driverClass, databaseUrl); + new ConnectUsingDriverAction.NewConnectionDialogDisplayer().showDialog(driver, databaseUrl, user, password); } }); + } + + /** + * The counterpart of {@link #showAddConnectionDialog(JDBCDriver) } which returns + * the newly created database connection, but must be called from the event dispatching + * thread. + * + * @param driver the JDBC driver; can be null. + * + * @return the new database connection or null if no database connection + * was created (e.g. the user pressed Cancel). + * + * @throws IllegalStateException if the calling thread is not the event + * dispatching thread. + * + * @since 1.19 + */ + public DatabaseConnection showAddConnectionDialogFromEventThread(JDBCDriver driver) { + return showAddConnectionDialogFromEventThread(driver, null, null, null); + } + + /** + * The counterpart of {@link #showAddConnectionDialog(JDBCDriver, String) } which returns + * the newly created database connection, but must be called from the event dispatching + * thread. + * + * @param driver the JDBC driver; can be null. + * @param databaseUrl the database URL; can be null. + * + * @return the new database connection or null if no database connection + * was created (e.g. the user pressed Cancel). + * + * @throws IllegalStateException if the calling thread is not the event + * dispatching thread. + * + * @since 1.19 + */ + public DatabaseConnection showAddConnectionDialogFromEventThread(JDBCDriver driver, String databaseUrl) { + return showAddConnectionDialogFromEventThread(driver, databaseUrl, null, null); + } + + /** + * The counterpart of {@link #showAddConnectionDialog(JDBCDriver, String, String, String) } + * which returns the newly created database connection, but must be called + * from the event dispatching thread. + * + * @param driver the JDBC driver; can be null. + * @param databaseUrl the database URL; can be null. + * @param user the database user; can be null. + * @param password user's password; can be null. + * + * @return the new database connection or null if no database connection + * was created (e.g. the user pressed Cancel). + * + * @throws IllegalStateException if the calling thread is not the event + * dispatching thread. + * + * @since 1.19 + */ + public DatabaseConnection showAddConnectionDialogFromEventThread(JDBCDriver driver, String databaseUrl, String user, String password) { + if (!SwingUtilities.isEventDispatchThread()) { + throw new IllegalStateException("The current thread is not the event dispatching thread."); // NOI18N + } + org.netbeans.modules.db.explorer.DatabaseConnection internalDBConn = new ConnectUsingDriverAction.NewConnectionDialogDisplayer().showDialog(driver, databaseUrl, user, password); + if (internalDBConn != null) { + return internalDBConn.getDatabaseConnection(); + } + return null; } /** Index: src/org/netbeans/modules/db/explorer/actions/ConnectUsingDriverAction.java =================================================================== RCS file: /cvs/db/src/org/netbeans/modules/db/explorer/actions/ConnectUsingDriverAction.java,v retrieving revision 1.28.2.1.2.3 diff -u -r1.28.2.1.2.3 ConnectUsingDriverAction.java --- src/org/netbeans/modules/db/explorer/actions/ConnectUsingDriverAction.java 10 Jul 2006 14:05:16 -0000 1.28.2.1.2.3 +++ src/org/netbeans/modules/db/explorer/actions/ConnectUsingDriverAction.java 20 Jul 2006 15:22:50 -0000 @@ -32,6 +32,7 @@ import javax.swing.JTabbedPane; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; +import org.netbeans.modules.db.explorer.ConnectionList; import org.netbeans.modules.db.explorer.dlg.ConnectionDialogMediator; import org.openide.DialogDescriptor; @@ -93,10 +94,16 @@ boolean okPressed = false; public void showDialog(String driverName, String driverClass) { - showDialog(driverName, driverClass, null); + showDialog(driverName, driverClass, null, null, null); } - public void showDialog(String driverName, String driverClass, String databaseUrl) { + public DatabaseConnection showDialog(JDBCDriver driver, String databaseUrl, String user, String password) { + String driverName = (driver != null) ? driver.getName() : null; + String driverClass = (driver != null) ? driver.getClassName() : null; + return showDialog(driverName, driverClass, databaseUrl, user, password); + } + + public DatabaseConnection showDialog(String driverName, String driverClass, String databaseUrl, String user, String password) { String finalDriverClass = null; JDBCDriver[] drivers; @@ -133,11 +140,17 @@ final DatabaseConnection cinfo = new DatabaseConnection(); cinfo.setDriverName(selectedDriverName); cinfo.setDriver(selectedDriverClass); + if (user != null) { + cinfo.setUser(user); + } + if (password != null) { + cinfo.setPassword(password); + } if (null != databaseUrl) { cinfo.setDatabase(databaseUrl); } - + final NewConnectionPanel basePanel = new NewConnectionPanel(this, finalDriverClass, cinfo); final SchemaPanel schemaPanel = new SchemaPanel(this, cinfo); @@ -284,6 +297,8 @@ dlg = new ConnectionDialog(this, basePanel, schemaPanel, basePanel.getTitle(), actionListener, changeTabListener); dlg.setVisible(true); + + return ConnectionList.getDefault().getConnection(cinfo); } // private void removeListeners() { Index: src/org/netbeans/modules/db/explorer/dlg/NewConnectionPanel.java =================================================================== RCS file: /cvs/db/src/org/netbeans/modules/db/explorer/dlg/NewConnectionPanel.java,v retrieving revision 1.14.2.1.2.3 diff -u -r1.14.2.1.2.3 NewConnectionPanel.java --- src/org/netbeans/modules/db/explorer/dlg/NewConnectionPanel.java 28 Jun 2006 22:22:54 -0000 1.14.2.1.2.3 +++ src/org/netbeans/modules/db/explorer/dlg/NewConnectionPanel.java 20 Jul 2006 15:22:50 -0000 @@ -79,6 +79,7 @@ driverTextField.setText(connection.getDriver()); urlComboBox.setSelectedItem(connection.getDatabase()); userTextField.setText(connection.getUser()); + passwordField.setText(connection.getPassword()); String driver = connection.getDriver(); String driverName = connection.getDriverName();