Skip to content

Commit 0a44637

Browse files
committed
Add a 'File' field to the Add Database Connection dialog. Use it for SQLite and DuckDB URL templates.
Also validate the selected file in the SQLite and DuckDB cases.
1 parent ab20d9a commit 0a44637

File tree

8 files changed

+342
-90
lines changed

8 files changed

+342
-90
lines changed

ide/db/nbproject/project.properties

Lines changed: 0 additions & 58 deletions
This file was deleted.

ide/db/src/org/netbeans/modules/db/explorer/action/ConnectAction.java

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import java.awt.event.ActionListener;
2929
import java.beans.PropertyChangeEvent;
3030
import java.beans.PropertyChangeListener;
31-
import java.lang.reflect.InvocationTargetException;
3231
import java.sql.DatabaseMetaData;
3332
import java.sql.ResultSet;
3433
import java.sql.SQLException;
@@ -41,6 +40,7 @@
4140
import javax.swing.Action;
4241
import javax.swing.JComponent;
4342
import javax.swing.SwingUtilities;
43+
import org.netbeans.api.db.explorer.JDBCDriver;
4444
import org.netbeans.api.progress.ProgressHandle;
4545
import org.netbeans.api.progress.ProgressHandleFactory;
4646
import org.netbeans.lib.ddl.DDLException;
@@ -54,6 +54,8 @@
5454
import org.netbeans.modules.db.explorer.dlg.ConnectionDialog;
5555
import org.netbeans.modules.db.explorer.dlg.ConnectionDialogMediator;
5656
import org.netbeans.modules.db.explorer.dlg.SchemaPanel;
57+
import org.netbeans.modules.db.util.DriverListUtil;
58+
import org.netbeans.modules.db.util.JdbcUrl;
5759
import org.openide.DialogDescriptor;
5860
import org.openide.DialogDisplayer;
5961
import org.openide.NotifyDescriptor;
@@ -62,7 +64,6 @@
6264
import org.openide.awt.ActionRegistration;
6365
import org.openide.awt.ActionState;
6466
import org.openide.util.ContextAwareAction;
65-
import org.openide.util.Exceptions;
6667
import org.openide.util.HelpCtx;
6768
import org.openide.util.Lookup;
6869
import org.openide.util.Mutex;
@@ -370,13 +371,20 @@ protected boolean retrieveSchemas(SchemaPanel schemaPanel, DatabaseConnection db
370371
}
371372

372373
private boolean supportsConnectWithoutUsername(DatabaseConnection dc) {
373-
try {
374-
return dc.findJDBCDriver().getClassName().equals("org.sqlite.JDBC") //NOI18N
375-
|| dc.findJDBCDriver().getClassName().equals("org.h2.Driver"); //NOI18N
376-
} catch (NullPointerException ex) {
377-
// Most probably findJDBCDriver failed to find a driver
374+
JDBCDriver driver = dc.findJDBCDriver();
375+
if (driver == null) {
376+
return false;
377+
}
378+
List<JdbcUrl> urls = DriverListUtil.getJdbcUrls(driver);
379+
if (urls.isEmpty()) {
378380
return false;
379381
}
382+
for (JdbcUrl url : urls) {
383+
if (url.isUsernamePasswordDisplayed()) {
384+
return false;
385+
}
386+
}
387+
return true;
380388
}
381389

382390
private void connectWithNewInfo(DatabaseConnection dbcon, Credentials input) {

ide/db/src/org/netbeans/modules/db/explorer/dlg/Bundle.properties

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ ACS_AddDriverProgressBarA11yDesc=Progress bar showing the progress of searching
4949
# Select driver file chooser
5050
AddDriver_Chooser_Title=Select Driver
5151
AddDriver_Chooser_Filter=Archive Files (*.jar, *.zip)
52+
# Select database file chooser
53+
NewConnectionFile_Chooser_Title=Select Database File
5254

5355
NewConnectionDialogTitle=New Database Connection
5456
NewConnectionDriverName=Driver &Name:
@@ -66,6 +68,7 @@ NewConnectionSID=Service ID (SID):
6668
NewConnectionServiceName=Service:
6769
NewConnectionTNSName=TNS Name:
6870
NewConnectionDSN=DSN:
71+
NewConnectionFile=&File:
6972
NewConnectionInstanceName=Instance Name:
7073
NewCOnnectionInputMode=Data Input &Mode:
7174
NewConnectionFieldEntryMode=&Field Entry
@@ -105,6 +108,8 @@ ACS_NewConnectionTNSNameA11yDesc=The TNS name for this connection
105108
ACS_NewConnectionTNSNameTextFieldA11yName=Database server TNS text field
106109
ACS_NewConnectionDSNA11yDesc=The data source name for this connection
107110
ACS_NewConnectionDSNTextFieldA11yName=Database server data source name (DSN) text field
111+
ACS_NewConnectionFileA11yDesc=The database file for this connection
112+
ACS_NewConnectionFileTextFieldA11yName=Database file name text field
108113
ACS_NewConnectionInstanceNameA11yDesc=The instance name for this connection
109114
ACS_NewConnectionInstanceNameTextFieldA11yName=Database server instance name text field
110115
ACS_NewConnectionFieldEntryModeA11yDesc=Select this mode to enter individual field values.

ide/db/src/org/netbeans/modules/db/explorer/dlg/NewConnectionPanel.form

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
<Component id="instanceLabel" alignment="0" max="32767" attributes="1"/>
5757
<Component id="serverNameLabel" alignment="0" max="32767" attributes="1"/>
5858
<Component id="dsnLabel" alignment="0" max="32767" attributes="1"/>
59+
<Component id="fileLabel" alignment="0" max="32767" attributes="1"/>
5960
<Component id="tnsLabel" alignment="0" max="32767" attributes="1"/>
6061
<Component id="serviceLabel" alignment="0" max="32767" attributes="1"/>
6162
<Component id="sidLabel" alignment="0" max="32767" attributes="1"/>
@@ -73,7 +74,7 @@
7374
<Component id="bConnectionProperties" min="-2" max="-2" attributes="0"/>
7475
<EmptySpace max="-2" attributes="0"/>
7576
<Component id="bTestConnection" min="-2" max="-2" attributes="0"/>
76-
<EmptySpace pref="100" max="32767" attributes="0"/>
77+
<EmptySpace max="32767" attributes="0"/>
7778
</Group>
7879
<Component id="userField" alignment="1" max="32767" attributes="2"/>
7980
<Component id="sidField" alignment="0" max="32767" attributes="2"/>
@@ -97,6 +98,11 @@
9798
<Component id="passwordCheckBox" min="-2" pref="256" max="-2" attributes="0"/>
9899
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
99100
</Group>
101+
<Group type="102" attributes="0">
102+
<Component id="fileField" max="32767" attributes="2"/>
103+
<EmptySpace max="-2" attributes="0"/>
104+
<Component id="fileBrowseButton" min="-2" max="-2" attributes="0"/>
105+
</Group>
100106
</Group>
101107
</Group>
102108
</Group>
@@ -149,6 +155,12 @@
149155
<Component id="dsnField" alignment="3" min="-2" max="-2" attributes="0"/>
150156
</Group>
151157
<EmptySpace min="-2" max="-2" attributes="0"/>
158+
<Group type="103" groupAlignment="3" attributes="0">
159+
<Component id="fileLabel" alignment="3" min="-2" max="-2" attributes="0"/>
160+
<Component id="fileField" alignment="3" min="-2" max="-2" attributes="0"/>
161+
<Component id="fileBrowseButton" alignment="3" min="-2" max="-2" attributes="0"/>
162+
</Group>
163+
<EmptySpace min="-2" max="-2" attributes="0"/>
152164
<Group type="103" groupAlignment="3" attributes="0">
153165
<Component id="serverNameLabel" alignment="3" min="-2" max="-2" attributes="0"/>
154166
<Component id="serverNameField" alignment="3" min="-2" max="-2" attributes="0"/>
@@ -400,6 +412,31 @@
400412
</Property>
401413
</Properties>
402414
</Component>
415+
<Component class="javax.swing.JLabel" name="fileLabel">
416+
<Properties>
417+
<Property name="labelFor" type="java.awt.Component" editor="org.netbeans.modules.form.ComponentChooserEditor">
418+
<ComponentRef name="fileField"/>
419+
</Property>
420+
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
421+
<ResourceString bundle="org/netbeans/modules/db/explorer/dlg/Bundle.properties" key="NewConnectionFile" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
422+
</Property>
423+
</Properties>
424+
</Component>
425+
<Component class="javax.swing.JTextField" name="fileField">
426+
<Properties>
427+
<Property name="toolTipText" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
428+
<ResourceString bundle="org/netbeans/modules/db/explorer/dlg/Bundle.properties" key="ACS_NewConnectionFileA11yDesc" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
429+
</Property>
430+
</Properties>
431+
</Component>
432+
<Component class="javax.swing.JButton" name="fileBrowseButton">
433+
<Properties>
434+
<Property name="text" type="java.lang.String" value="&amp;Browse..."/>
435+
</Properties>
436+
<Events>
437+
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="fileBrowseButtonActionPerformed"/>
438+
</Events>
439+
</Component>
403440
<Component class="javax.swing.JTextField" name="urlField">
404441
<Properties>
405442
<Property name="toolTipText" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">

0 commit comments

Comments
 (0)