# HG changeset patch # User Daniele Nicolodi # Date 1275492558 -7200 # Node ID 35f1cfcaa5a928b6dd723f389456ec3b8010bebf # Parent c706c10a76bdc6b913a284a52a7dc979ed5ba977 Add crude Java GUI. diff -r c706c10a76bd -r 35f1cfcaa5a9 ConnectionManager/nbproject/build-impl.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ConnectionManager/nbproject/build-impl.xml Wed Jun 02 17:29:18 2010 +0200 @@ -0,0 +1,805 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + + + + + + java -cp "${run.classpath.with.dist.jar}" ${main.class} + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -r c706c10a76bd -r 35f1cfcaa5a9 ConnectionManager/nbproject/genfiles.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ConnectionManager/nbproject/genfiles.properties Wed Jun 02 17:29:18 2010 +0200 @@ -0,0 +1,8 @@ +build.xml.data.CRC32=ec3fbd9f +build.xml.script.CRC32=1b3d25dd +build.xml.stylesheet.CRC32=958a1d3e@1.32.1.45 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=ec3fbd9f +nbproject/build-impl.xml.script.CRC32=1e140bd3 +nbproject/build-impl.xml.stylesheet.CRC32=576378a2@1.32.1.45 diff -r c706c10a76bd -r 35f1cfcaa5a9 ConnectionManager/nbproject/private/private.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ConnectionManager/nbproject/private/private.properties Wed Jun 02 17:29:18 2010 +0200 @@ -0,0 +1,3 @@ +compile.on.save=true +jaxbwiz.endorsed.dirs=/Applications/NetBeans/NetBeans 6.8.app/Contents/Resources/NetBeans/ide12/modules/ext/jaxb/api +user.properties.file=/Users/daniele/.netbeans/6.8/build.properties diff -r c706c10a76bd -r 35f1cfcaa5a9 ConnectionManager/nbproject/project.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ConnectionManager/nbproject/project.properties Wed Jun 02 17:29:18 2010 +0200 @@ -0,0 +1,63 @@ +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/ConnectionManager.jar +dist.javadoc.dir=${dist.dir}/javadoc +excludes= +includes=** +jar.compress=false +javac.classpath=\ + ${libs.swing-layout.classpath} +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.source=1.5 +javac.target=1.5 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir}:\ + ${libs.junit.classpath}:\ + ${libs.junit_4.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +jaxbwiz.endorsed.dirs="${netbeans.home}/../ide12/modules/ext/jaxb/api" +main.class=connectionmanager.CredentialsDialog +meta.inf.dir=${src.dir}/META-INF +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value +# or test-sys-prop.name=value to set system properties for unit tests): +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff -r c706c10a76bd -r 35f1cfcaa5a9 ConnectionManager/nbproject/project.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ConnectionManager/nbproject/project.xml Wed Jun 02 17:29:18 2010 +0200 @@ -0,0 +1,15 @@ + + + org.netbeans.modules.java.j2seproject + + + ConnectionManager + + + + + + + + + diff -r c706c10a76bd -r 35f1cfcaa5a9 ConnectionManager/src/connectionmanager/CredentialsDialog.form --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ConnectionManager/src/connectionmanager/CredentialsDialog.form Wed Jun 02 17:29:18 2010 +0200 @@ -0,0 +1,139 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff -r c706c10a76bd -r 35f1cfcaa5a9 ConnectionManager/src/connectionmanager/CredentialsDialog.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ConnectionManager/src/connectionmanager/CredentialsDialog.java Wed Jun 02 17:29:18 2010 +0200 @@ -0,0 +1,174 @@ +package connectionmanager; + +public class CredentialsDialog extends javax.swing.JDialog { + + private String[] usernames; + private String[] passwords; + + public boolean cancelled = true; + public boolean cache = false; + public String username = null; + public String password = null; + + public CredentialsDialog(java.awt.Frame parent, boolean modal) { + super(parent, modal); + initComponents(); + } + + public CredentialsDialog() { + super(new javax.swing.JFrame(), true); + initComponents(); + } + + public CredentialsDialog(String[] usernames, String[] passwords) { + super(new javax.swing.JFrame(), true); + this.usernames = usernames; + this.passwords = passwords; + initComponents(); + + if (usernames != null) { + this.usernameField.setModel(new javax.swing.DefaultComboBoxModel(usernames)); + } + } + + @SuppressWarnings("unchecked") + // //GEN-BEGIN:initComponents + private void initComponents() { + + okButton = new javax.swing.JButton(); + cancelButton = new javax.swing.JButton(); + jLabel3 = new javax.swing.JLabel(); + passwordField = new javax.swing.JPasswordField(); + cacheCheckBox = new javax.swing.JCheckBox(); + usernameField = new javax.swing.JComboBox(); + jLabel2 = new javax.swing.JLabel(); + jLabel1 = new javax.swing.JLabel(); + + addWindowListener(new java.awt.event.WindowAdapter() { + public void windowClosing(java.awt.event.WindowEvent evt) { + closeDialog(evt); + } + }); + + okButton.setText("Connect"); + okButton.setSelected(true); + okButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + okButtonActionPerformed(evt); + } + }); + + cancelButton.setText("Cancel"); + cancelButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + cancelButtonActionPerformed(evt); + } + }); + + jLabel3.setText("Credentials for mysql://%s/%s/"); + + cacheCheckBox.setText("Remember this password"); + + usernameField.setEditable(true); + usernameField.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + usernameFieldActionPerformed(evt); + } + }); + + jLabel2.setText("Password:"); + + jLabel1.setText("Username:"); + + org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane()); + getContentPane().setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup() + .addContainerGap(251, Short.MAX_VALUE) + .add(cancelButton) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED) + .add(okButton) + .addContainerGap()) + .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(layout.createSequentialGroup() + .add(36, 36, 36) + .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(cacheCheckBox, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 351, Short.MAX_VALUE) + .add(layout.createSequentialGroup() + .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(jLabel1) + .add(jLabel2)) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED) + .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(passwordField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 271, Short.MAX_VALUE) + .add(usernameField, 0, 271, Short.MAX_VALUE))) + .add(jLabel3)) + .add(36, 36, 36))) + ); + layout.setVerticalGroup( + layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup() + .addContainerGap(266, Short.MAX_VALUE) + .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) + .add(okButton) + .add(cancelButton)) + .addContainerGap()) + .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(layout.createSequentialGroup() + .add(81, 81, 81) + .add(jLabel3) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) + .add(jLabel1) + .add(usernameField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 21, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) + .add(14, 14, 14) + .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) + .add(passwordField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) + .add(jLabel2)) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED) + .add(cacheCheckBox) + .add(116, 116, 116))) + ); + + pack(); + }// //GEN-END:initComponents + + private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okButtonActionPerformed + cancelled = false; + username = (String)usernameField.getSelectedItem(); + password = new String(passwordField.getPassword()); + cache = cacheCheckBox.isSelected(); + doClose(); + }//GEN-LAST:event_okButtonActionPerformed + + private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed + cancelled = true; + doClose(); + }//GEN-LAST:event_cancelButtonActionPerformed + + private void closeDialog(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_closeDialog + cancelled = true; + doClose(); + }//GEN-LAST:event_closeDialog + + private void usernameFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_usernameFieldActionPerformed + +}//GEN-LAST:event_usernameFieldActionPerformed + + private void doClose() { + setVisible(false); + dispose(); + } + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JCheckBox cacheCheckBox; + private javax.swing.JButton cancelButton; + private javax.swing.JLabel jLabel1; + private javax.swing.JLabel jLabel2; + private javax.swing.JLabel jLabel3; + private javax.swing.JButton okButton; + private javax.swing.JPasswordField passwordField; + private javax.swing.JComboBox usernameField; + // End of variables declaration//GEN-END:variables +} diff -r c706c10a76bd -r 35f1cfcaa5a9 ConnectionManager/src/connectionmanager/DatabaseDialog.form --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ConnectionManager/src/connectionmanager/DatabaseDialog.form Wed Jun 02 17:29:18 2010 +0200 @@ -0,0 +1,130 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff -r c706c10a76bd -r 35f1cfcaa5a9 ConnectionManager/src/connectionmanager/DatabaseDialog.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ConnectionManager/src/connectionmanager/DatabaseDialog.java Wed Jun 02 17:29:18 2010 +0200 @@ -0,0 +1,158 @@ +package connectionmanager; + +import javax.swing.DefaultComboBoxModel; + +public class DatabaseDialog extends javax.swing.JDialog { + + public boolean cancelled = true; + public String hostname; + public String database; + + public DatabaseDialog(java.awt.Frame parent, boolean modal, String[] hostnames) { + super(parent, modal); + initComponents(); + hostnameCombo.setModel(new DefaultComboBoxModel(hostnames)); + } + + public DatabaseDialog(java.awt.Frame parent, boolean modal) { + super(new java.awt.Frame(), true); + initComponents(); + hostnameCombo.setModel(new DefaultComboBoxModel()); + } + + public DatabaseDialog() { + super(new java.awt.Frame(), true); + initComponents(); + hostnameCombo.setModel(new DefaultComboBoxModel()); + } + + @SuppressWarnings("unchecked") + // //GEN-BEGIN:initComponents + private void initComponents() { + + jLabel10 = new javax.swing.JLabel(); + jLabel9 = new javax.swing.JLabel(); + databaseCombo = new javax.swing.JComboBox(); + okButton = new javax.swing.JButton(); + cancelButton = new javax.swing.JButton(); + hostnameCombo = new javax.swing.JComboBox(); + + setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); + setTitle("Repository Connection"); + setLocationByPlatform(true); + setModal(true); + setResizable(false); + + jLabel10.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); + jLabel10.setText("Database:"); + + jLabel9.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); + jLabel9.setText("Hostname:"); + + databaseCombo.setEditable(true); + databaseCombo.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + databaseComboActionPerformed(evt); + } + }); + + okButton.setText("Ok"); + okButton.setSelected(true); + okButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + okButtonActionPerformed(evt); + } + }); + + cancelButton.setText("Cancel"); + cancelButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + cancelButtonActionPerformed(evt); + } + }); + + hostnameCombo.setEditable(true); + hostnameCombo.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + hostnameComboActionPerformed(evt); + } + }); + + org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane()); + getContentPane().setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(layout.createSequentialGroup() + .addContainerGap() + .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(layout.createSequentialGroup() + .add(jLabel9) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) + .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup() + .add(cancelButton) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) + .add(okButton)) + .add(hostnameCombo, 0, 218, Short.MAX_VALUE))) + .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup() + .add(jLabel10) + .add(11, 11, 11) + .add(databaseCombo, 0, 218, Short.MAX_VALUE))) + .addContainerGap()) + ); + layout.setVerticalGroup( + layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(layout.createSequentialGroup() + .addContainerGap() + .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) + .add(jLabel9) + .add(hostnameCombo, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) + .add(18, 18, 18) + .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) + .add(databaseCombo, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) + .add(jLabel10)) + .add(118, 118, 118) + .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) + .add(okButton) + .add(cancelButton)) + .addContainerGap(34, Short.MAX_VALUE)) + ); + + pack(); + }// //GEN-END:initComponents + + private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed + cancelled = true; + doClose(); + }//GEN-LAST:event_cancelButtonActionPerformed + + private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okButtonActionPerformed + cancelled = false; + hostname = (String)hostnameCombo.getSelectedItem(); + database = (String)databaseCombo.getSelectedItem(); + doClose(); + }//GEN-LAST:event_okButtonActionPerformed + + private void databaseComboActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_databaseComboActionPerformed + + }//GEN-LAST:event_databaseComboActionPerformed + + private void hostnameComboActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_hostnameComboActionPerformed + + }//GEN-LAST:event_hostnameComboActionPerformed + + private void doClose() { + setVisible(false); + dispose(); + } + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JButton cancelButton; + private javax.swing.JComboBox databaseCombo; + private javax.swing.JComboBox hostnameCombo; + private javax.swing.JLabel jLabel10; + private javax.swing.JLabel jLabel9; + private javax.swing.JButton okButton; + // End of variables declaration//GEN-END:variables + +} diff -r c706c10a76bd -r 35f1cfcaa5a9 ConnectionManager/src/connectionmanager/DatabaseSelectorDialog.form --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ConnectionManager/src/connectionmanager/DatabaseSelectorDialog.form Wed Jun 02 17:29:18 2010 +0200 @@ -0,0 +1,107 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+
+
+
+
diff -r c706c10a76bd -r 35f1cfcaa5a9 ConnectionManager/src/connectionmanager/DatabaseSelectorDialog.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ConnectionManager/src/connectionmanager/DatabaseSelectorDialog.java Wed Jun 02 17:29:18 2010 +0200 @@ -0,0 +1,182 @@ +package connectionmanager; + +import java.awt.Point; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import javax.swing.table.DefaultTableModel; + +public class DatabaseSelectorDialog extends javax.swing.JDialog { + + private boolean cancelled = true; + + public String hostname; + public String database; + public String username; + + public DatabaseSelectorDialog(java.awt.Frame parent) { + super(parent, true); + initComponents(); + databasesTable.addMouseListener(new MouseListenerDoubleClick()); + } + + public DatabaseSelectorDialog() { + super(new javax.swing.JFrame(), true); + initComponents(); + databasesTable.addMouseListener(new MouseListenerDoubleClick()); + } + + private class MouseListenerDoubleClick extends MouseAdapter { + + @Override + public void mouseClicked(MouseEvent e) { + if (e.getClickCount() >= 2) { + cancelled = false; + Point p = e.getPoint(); + int row = databasesTable.rowAtPoint(p); + DefaultTableModel model = (DefaultTableModel)databasesTable.getModel(); + hostname = (String)model.getValueAt(row, 0); + database = (String)model.getValueAt(row, 1); + username = (String)model.getValueAt(row, 2); + doClose(); + } + } + } + + @SuppressWarnings("unchecked") + // //GEN-BEGIN:initComponents + private void initComponents() { + + cancelButton = new javax.swing.JButton(); + newButton = new javax.swing.JButton(); + selectButton = new javax.swing.JButton(); + jScrollPane1 = new javax.swing.JScrollPane(); + databasesTable = new javax.swing.JTable(); + + setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); + setTitle("Select a connection"); + + cancelButton.setText("Cancel"); + cancelButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + cancelButtonActionPerformed(evt); + } + }); + + newButton.setText("New"); + newButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + newButtonActionPerformed(evt); + } + }); + + selectButton.setText("Select"); + selectButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + selectButtonActionPerformed(evt); + } + }); + + databasesTable.setModel(new javax.swing.table.DefaultTableModel( + new Object [][] { + + }, + new String [] { + "Hostname", "Database", "Username" + } + ) { + Class[] types = new Class [] { + java.lang.String.class, java.lang.String.class, java.lang.String.class + }; + boolean[] canEdit = new boolean [] { + false, false, false + }; + + public Class getColumnClass(int columnIndex) { + return types [columnIndex]; + } + + public boolean isCellEditable(int rowIndex, int columnIndex) { + return canEdit [columnIndex]; + } + }); + jScrollPane1.setViewportView(databasesTable); + + org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane()); + getContentPane().setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(layout.createSequentialGroup() + .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup() + .add(183, 183, 183) + .add(cancelButton, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) + .add(newButton, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) + .add(selectButton, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup() + .addContainerGap() + .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE))) + .addContainerGap()) + ); + layout.setVerticalGroup( + layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup() + .addContainerGap(20, Short.MAX_VALUE) + .add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 225, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) + .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.CENTER) + .add(selectButton) + .add(newButton) + .add(cancelButton)) + .add(207, 207, 207)) + ); + + pack(); + }// //GEN-END:initComponents + + private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed + cancelled = true; + doClose(); + }//GEN-LAST:event_cancelButtonActionPerformed + + private void selectButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_selectButtonActionPerformed + cancelled = false; + int row = databasesTable.getSelectedRow(); + DefaultTableModel model = (DefaultTableModel)databasesTable.getModel(); + hostname = (String)model.getValueAt(row, 0); + database = (String)model.getValueAt(row, 1); + username = (String)model.getValueAt(row, 2); + doClose(); + }//GEN-LAST:event_selectButtonActionPerformed + + private void newButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_newButtonActionPerformed + DatabaseDialog dialog = new DatabaseDialog(); + dialog.setVisible(true); + if (!dialog.cancelled) { + cancelled = false; + hostname = dialog.hostname; + database = dialog.database; + username = new String(""); + doClose(); + } + }//GEN-LAST:event_newButtonActionPerformed + + private void doClose() { + setVisible(false); + dispose(); + } + + public void add(String hostname, String database, String username) { + DefaultTableModel model = (DefaultTableModel)databasesTable.getModel(); + model.insertRow(model.getRowCount(), new Object[] { hostname, database, username }); + } + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JButton cancelButton; + private javax.swing.JTable databasesTable; + private javax.swing.JScrollPane jScrollPane1; + private javax.swing.JButton newButton; + private javax.swing.JButton selectButton; + // End of variables declaration//GEN-END:variables +} diff -r c706c10a76bd -r 35f1cfcaa5a9 LTPDAConnectionManager.m --- a/LTPDAConnectionManager.m Mon May 24 00:14:37 2010 +0200 +++ b/LTPDAConnectionManager.m Wed Jun 02 17:29:18 2010 +0200 @@ -399,65 +399,40 @@ function [username, password, cache] = inputCredentials(cm, cred) % INPUTCREDENTIALS Queries the user for database username and password. - % this is a stubb that must be replaced by a graphical interface - % build a cell array of usernames and passwords users = { cred(:).username }; passw = { cred(:).password }; - % default to the latest used username + % sort on the expiry time [e, ids] = sort([ cred(:).expiry ]); - default = users{ids(1)}; - - username = choose('Username', users, default); + users = users{ids} + passw = passw{ids} - % pick the corresponding password - ids = find(strcmp(users, username)); - if ~isempty(ids) - default = passw{ids(1)}; - else - default = []; + dialog = connectionmanager.CredentialsDialog(users, passw); + dialog.show(); + if dialog.cancelled + throw(MException('utils:jmysql:connect:UserCancelled', '### user cancelled'); end - - password = ask('Password', ''); - - if cm.cachePassword == 2 - cache = ask('Store credentials', 'n'); - if ~isempty(cache) && cache(1) == 'y' - cache = true; - else - cache = false; - end - else - cache = logical(cm.cachePassword); - end + username = char(dialog.username); + password = char(dialog.password); + cache = logical(dialog.cache); end function [hostname, database, username] = selectDatabase(cm) % SELECTDATABASE Makes the user choose to which database connect to. - % this is a stubb that must be replaced by a graphical interface - - for kk = 1:numel(cm.credentials) - fprintf('% 2d. %s\n', char(cm.credentials{kk})); + dialog = connectionmanager.DatabaseSelectorDialog(); + for c = cm.credentials + dialog.add(c{1}.hostname, c{1}.database, c{1}.username); end - fprintf('%d. NEW (default)\n', numel(cm.credentials)+1); - str = input('Select connection: ', 's'); - if isempty(str) - id = numel(cm.credentials)+1; - else - id = eval(str); + dialog.show(); + if dialog.cancelled + throw(MException('utils:jmysql:connect:UserCancelled', '### user cancelled'); end - if id > numel(cm.credentials) - hostname = input('Hostname: ', 's'); - database = input('Database: ', 's'); - username = []; - else - hostname = cm.credentials{kk}.hostname; - database = cm.credentials{kk}.database; - username = cm.credentials{kk}.username; - end + hostname = char(dialog.hostname); + database = char(dialog.database); + username = char(dialog.username); end end % private methods @@ -500,26 +475,3 @@ rethrow(ex); end end - - -function str = ask(msg, default) - str = input(sprintf('%s (default: %s): ', msg, default), 's'); - if isempty(str) - str = default; - end - if ~ischar(str) - str = char(str); - end -end - -function str = choose(msg, choices, default) - options = sprintf('%s, ', choices{:}); - options = options(1:end-2); - str = input(sprintf('%s (options: %s, default: %s): ', msg, options, default), 's'); - if isempty(str) - str = default; - end - if ~ischar(str) - str = char(str); - end -end