# HG changeset patch # User Daniele Nicolodi # Date 1323098406 -3600 # Node ID 960fe1aa1c10b7b23fa89032f2c816eb96081362 # Parent 18e956c96a1bbe6b8fd7c61e5169f279120bd6ed Add LTPDADatabaseConnectionManager implementation. Java code diff -r 18e956c96a1b -r 960fe1aa1c10 src/ConnectionManager/build.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/ConnectionManager/build.xml Mon Dec 05 16:20:06 2011 +0100 @@ -0,0 +1,74 @@ + + + + + + + + + + + Builds, tests, and runs the project ConnectionManager. + + + diff -r 18e956c96a1b -r 960fe1aa1c10 src/ConnectionManager/dist/README.TXT --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/ConnectionManager/dist/README.TXT Mon Dec 05 16:20:06 2011 +0100 @@ -0,0 +1,32 @@ +======================== +BUILD OUTPUT DESCRIPTION +======================== + +When you build an Java application project that has a main class, the IDE +automatically copies all of the JAR +files on the projects classpath to your projects dist/lib folder. The IDE +also adds each of the JAR files to the Class-Path element in the application +JAR files manifest file (MANIFEST.MF). + +To run the project from the command line, go to the dist folder and +type the following: + +java -jar "ConnectionManager.jar" + +To distribute this project, zip up the dist folder (including the lib folder) +and distribute the ZIP file. + +Notes: + +* If two JAR files on the project classpath have the same name, only the first +JAR file is copied to the lib folder. +* Only JAR files are copied to the lib folder. +If the classpath contains other types of files or folders, these files (folders) +are not copied. +* If a library on the projects classpath also has a Class-Path element +specified in the manifest,the content of the Class-Path element has to be on +the projects runtime path. +* To set a main class in a standard Java project, right-click the project node +in the Projects window and choose Properties. Then click Run and enter the +class name in the Main Class field. Alternatively, you can manually type the +class name in the manifest Main-Class element. diff -r 18e956c96a1b -r 960fe1aa1c10 src/ConnectionManager/dist/lib/swing-layout-1.0.4.jar Binary file src/ConnectionManager/dist/lib/swing-layout-1.0.4.jar has changed diff -r 18e956c96a1b -r 960fe1aa1c10 src/ConnectionManager/nbproject/.cvsignore --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/ConnectionManager/nbproject/.cvsignore Mon Dec 05 16:20:06 2011 +0100 @@ -0,0 +1,1 @@ +private diff -r 18e956c96a1b -r 960fe1aa1c10 src/ConnectionManager/nbproject/build-impl.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/ConnectionManager/nbproject/build-impl.xml Mon Dec 05 16:20:06 2011 +0100 @@ -0,0 +1,1042 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 one file in the IDE or set profile.class + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 18e956c96a1b -r 960fe1aa1c10 src/ConnectionManager/nbproject/genfiles.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/ConnectionManager/nbproject/genfiles.properties Mon Dec 05 16:20:06 2011 +0100 @@ -0,0 +1,8 @@ +build.xml.data.CRC32=ec3fbd9f +build.xml.script.CRC32=1b3d25dd +build.xml.stylesheet.CRC32=28e38971@1.44.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=4fce1b85 +nbproject/build-impl.xml.stylesheet.CRC32=0ae3a408@1.44.1.45 diff -r 18e956c96a1b -r 960fe1aa1c10 src/ConnectionManager/nbproject/private/config.properties diff -r 18e956c96a1b -r 960fe1aa1c10 src/ConnectionManager/nbproject/private/private.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/ConnectionManager/nbproject/private/private.properties Mon Dec 05 16:20:06 2011 +0100 @@ -0,0 +1,7 @@ +compile.on.save=true +do.depend=false +do.jar=true +javac.debug=true +javadoc.preview=true +jaxbwiz.endorsed.dirs=/Applications/NetBeans/NetBeans 6.8.app/Contents/Resources/NetBeans/ide12/modules/ext/jaxb/api +user.properties.file=/home/daniele/.netbeans/7.0/build.properties diff -r 18e956c96a1b -r 960fe1aa1c10 src/ConnectionManager/nbproject/private/private.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/ConnectionManager/nbproject/private/private.xml Mon Dec 05 16:20:06 2011 +0100 @@ -0,0 +1,4 @@ + + + + diff -r 18e956c96a1b -r 960fe1aa1c10 src/ConnectionManager/nbproject/project.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/ConnectionManager/nbproject/project.properties Mon Dec 05 16:20:06 2011 +0100 @@ -0,0 +1,70 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.run.all.processors=true +application.title=ConnectionManager +application.vendor=daniele +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 +endorsed.classpath= +excludes= +includes=** +jar.compress=false +javac.classpath=\ + ${libs.swing-layout.classpath} +# Space-separated list of extra javac options +javac.compilerargs=-Xlint:unchecked +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.5 +javac.target=1.5 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +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 +mkdist.disabled=false +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 18e956c96a1b -r 960fe1aa1c10 src/ConnectionManager/nbproject/project.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/ConnectionManager/nbproject/project.xml Mon Dec 05 16:20:06 2011 +0100 @@ -0,0 +1,15 @@ + + + org.netbeans.modules.java.j2seproject + + + ConnectionManager + + + + + + + + + diff -r 18e956c96a1b -r 960fe1aa1c10 src/ConnectionManager/src/connectionmanager/CredentialsDialog.form --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/ConnectionManager/src/connectionmanager/CredentialsDialog.form Mon Dec 05 16:20:06 2011 +0100 @@ -0,0 +1,132 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff -r 18e956c96a1b -r 960fe1aa1c10 src/ConnectionManager/src/connectionmanager/CredentialsDialog.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/ConnectionManager/src/connectionmanager/CredentialsDialog.java Mon Dec 05 16:20:06 2011 +0100 @@ -0,0 +1,183 @@ +package connectionmanager; + +public class CredentialsDialog extends javax.swing.JDialog { + + public boolean cancelled = true; + public boolean cache = true; + public String username = null; + public String password = null; + + public CredentialsDialog(javax.swing.JDialog parent, String hostname, String[] usernames) { + super(parent, true); + initComponents(); + super.setLocationRelativeTo(parent); + this.cacheCheckBox.setVisible(false); + titleLabel.setText(String.format("Credentials for mysql://%s/", hostname)); + if ((usernames != null) && (usernames.length > 0)) { + usernameField.setModel(new javax.swing.DefaultComboBoxModel(usernames)); + passwordField.requestFocus(); + } + super.getRootPane().setDefaultButton(okButton); + } + + public CredentialsDialog(java.awt.Frame parent, String hostname, String database, String[] usernames, int cache) { + super(parent, true); + initComponents(); + super.setLocationRelativeTo(parent); + + switch (cache) { + case 0: + this.cache = false; + this.cacheCheckBox.setVisible(false); + break; + case 1: + this.cache = true; + this.cacheCheckBox.setVisible(false); + break; + case 2: + this.cache = true; + this.cacheCheckBox.setVisible(true); + break; + } + + titleLabel.setText(String.format("Credentials for mysql://%s/%s/", hostname, database)); + if ((usernames != null) && (usernames.length > 0)) { + usernameField.setModel(new javax.swing.DefaultComboBoxModel(usernames)); + passwordField.requestFocus(); + } + super.getRootPane().setDefaultButton(okButton); + } + + @SuppressWarnings("unchecked") + // //GEN-BEGIN:initComponents + private void initComponents() { + + okButton = new javax.swing.JButton(); + cancelButton = new javax.swing.JButton(); + titleLabel = 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(); + + setTitle("Database connection"); + addWindowListener(new java.awt.event.WindowAdapter() { + public void windowClosing(java.awt.event.WindowEvent evt) { + closeDialog(evt); + } + }); + + okButton.setText("Connect"); + 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); + } + }); + + titleLabel.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(layout.createSequentialGroup() + .addContainerGap() + .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(titleLabel) + .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup() + .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(jLabel1) + .add(jLabel2)) + .add(18, 18, 18) + .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(passwordField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 240, Short.MAX_VALUE) + .add(usernameField, 0, 240, Short.MAX_VALUE))) + .add(layout.createSequentialGroup() + .add(cacheCheckBox, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 190, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 12, Short.MAX_VALUE) + .add(cancelButton) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) + .add(okButton))) + .addContainerGap()) + ); + layout.setVerticalGroup( + layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(layout.createSequentialGroup() + .addContainerGap() + .add(titleLabel) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED) + .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) + .add(usernameField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) + .add(jLabel1)) + .add(12, 12, 12) + .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)) + .add(18, 18, 18) + .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE, false) + .add(cacheCheckBox) + .add(okButton) + .add(cancelButton)) + .addContainerGap()) + ); + + 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.JButton okButton; + private javax.swing.JPasswordField passwordField; + private javax.swing.JLabel titleLabel; + private javax.swing.JComboBox usernameField; + // End of variables declaration//GEN-END:variables +} diff -r 18e956c96a1b -r 960fe1aa1c10 src/ConnectionManager/src/connectionmanager/DatabaseDialog.form --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/ConnectionManager/src/connectionmanager/DatabaseDialog.form Mon Dec 05 16:20:06 2011 +0100 @@ -0,0 +1,123 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff -r 18e956c96a1b -r 960fe1aa1c10 src/ConnectionManager/src/connectionmanager/DatabaseDialog.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/ConnectionManager/src/connectionmanager/DatabaseDialog.java Mon Dec 05 16:20:06 2011 +0100 @@ -0,0 +1,164 @@ +package connectionmanager; + +import java.util.HashSet; +import javax.swing.DefaultComboBoxModel; +import javax.swing.table.TableModel; + +public class DatabaseDialog extends javax.swing.JDialog { + + public boolean cancelled = true; + public String hostname; + public String database; + private TableModel model; + + public DatabaseDialog(javax.swing.JDialog parent, TableModel model) { + super(parent, true); + this.model = model; + initComponents(); + initHostnameCombo(); + initDatabaseCombo(); + super.setLocationRelativeTo(parent); + super.getRootPane().setDefaultButton(okButton); + if (hostnameCombo.getModel().getSize() == 1) { + databaseCombo.requestFocus(); + } + } + + @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(); + + setTitle("Database 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); + + okButton.setText("Ok"); + 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) + .add(18, 18, 18) + .add(hostnameCombo, 0, 240, Short.MAX_VALUE)) + .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup() + .add(cancelButton) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) + .add(okButton)) + .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup() + .add(jLabel10) + .add(21, 21, 21) + .add(databaseCombo, 0, 240, 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(hostnameCombo, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) + .add(jLabel9)) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED) + .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(18, 18, 18) + .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) + .add(cancelButton) + .add(okButton)) + .addContainerGap()) + ); + + 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 hostnameComboActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_hostnameComboActionPerformed + initDatabaseCombo(); + }//GEN-LAST:event_hostnameComboActionPerformed + + private void initHostnameCombo() { + HashSet hostnames = new HashSet(); + int rows = model.getRowCount(); + for (int i = 0; i < rows; i++) { + hostnames.add((String) model.getValueAt(i, 0)); + } + hostnameCombo.setModel(new DefaultComboBoxModel(hostnames.toArray())); + } + + private void initDatabaseCombo() { + HashSet databases = new HashSet(); + hostname = (String) hostnameCombo.getSelectedItem(); + int rows = model.getRowCount(); + for (int i = 0; i < rows; i++) { + if (hostname.equals((String) model.getValueAt(i, 0))) { + databases.add((String) model.getValueAt(i, 1)); + } + } + databaseCombo.setModel(new DefaultComboBoxModel(databases.toArray())); + } + + 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 18e956c96a1b -r 960fe1aa1c10 src/ConnectionManager/src/connectionmanager/DatabaseSelectorDialog.form --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/ConnectionManager/src/connectionmanager/DatabaseSelectorDialog.form Mon Dec 05 16:20:06 2011 +0100 @@ -0,0 +1,138 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + + + <Editor/> + <Renderer/> + </Column> + <Column maxWidth="-1" minWidth="-1" prefWidth="-1" resizable="true"> + <Title/> + <Editor/> + <Renderer/> + </Column> + <Column maxWidth="-1" minWidth="-1" prefWidth="-1" resizable="true"> + <Title/> + <Editor/> + <Renderer/> + </Column> + </TableColumnModel> + </Property> + <Property name="gridColor" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor"> + <Color blue="cc" green="cc" red="cc" type="rgb"/> + </Property> + <Property name="intercellSpacing" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor"> + <Dimension value="[0, 0]"/> + </Property> + <Property name="rowHeight" type="int" value="24"/> + <Property name="selectionModel" type="javax.swing.ListSelectionModel" editor="org.netbeans.modules.form.editors2.JTableSelectionModelEditor"> + <JTableSelectionModel selectionMode="0"/> + </Property> + <Property name="showVerticalLines" type="boolean" value="false"/> + </Properties> + <Events> + <EventHandler event="keyPressed" listener="java.awt.event.KeyListener" parameters="java.awt.event.KeyEvent" handler="tableKeyPressed"/> + </Events> + </Component> + </SubComponents> + </Container> + </SubComponents> +</Form> diff -r 18e956c96a1b -r 960fe1aa1c10 src/ConnectionManager/src/connectionmanager/DatabaseSelectorDialog.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/ConnectionManager/src/connectionmanager/DatabaseSelectorDialog.java Mon Dec 05 16:20:06 2011 +0100 @@ -0,0 +1,244 @@ +package connectionmanager; + +import java.awt.Component; +import java.awt.Point; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import javax.swing.JTable; +import javax.swing.table.DefaultTableModel; +import javax.swing.table.DefaultTableCellRenderer; + +class CellRenderer extends DefaultTableCellRenderer { + + @Override + public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { + return super.getTableCellRendererComponent(table, value, isSelected, false, row, column); + } +} + +public class DatabaseSelectorDialog extends javax.swing.JDialog { + + public boolean cancelled = true; + public String hostname; + public String database; + public String username; + + public DatabaseSelectorDialog(java.awt.Frame parent) { + super(parent, true); + initComponents(); + // center in parent window + super.setLocationRelativeTo(parent); + databasesTable.setDefaultRenderer(Object.class, new CellRenderer()); + databasesTable.addMouseListener(new MouseListenerDoubleClick()); + } + + public DatabaseSelectorDialog() { + super(new javax.swing.JFrame(), true); + initComponents(); + databasesTable.setDefaultRenderer(Object.class, new CellRenderer()); + 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); + doSelect(row); + } + } + } + + @SuppressWarnings("unchecked") + // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents + private void initComponents() { + + cancelButton = new javax.swing.JButton(); + newButton = new javax.swing.JButton(); + selectButton = new javax.swing.JButton(); + scrollPane = new javax.swing.JScrollPane(); + databasesTable = new javax.swing.JTable(); + + setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); + setTitle("Database connection"); + setResizable(false); + + 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]; + } + }); + databasesTable.setGridColor(new java.awt.Color(204, 204, 204)); + databasesTable.setIntercellSpacing(new java.awt.Dimension(0, 0)); + databasesTable.setRowHeight(24); + databasesTable.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION); + databasesTable.setShowVerticalLines(false); + databasesTable.addKeyListener(new java.awt.event.KeyAdapter() { + public void keyPressed(java.awt.event.KeyEvent evt) { + tableKeyPressed(evt); + } + }); + scrollPane.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(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup() + .addContainerGap() + .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING) + .add(org.jdesktop.layout.GroupLayout.LEADING, scrollPane, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 409, Short.MAX_VALUE) + .add(layout.createSequentialGroup() + .add(newButton, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 62, Short.MAX_VALUE) + .add(184, 184, 184) + .add(cancelButton, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 77, Short.MAX_VALUE) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED) + .add(selectButton, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 74, Short.MAX_VALUE))) + .addContainerGap()) + ); + layout.setVerticalGroup( + layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup() + .addContainerGap() + .add(scrollPane, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 218, Short.MAX_VALUE) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED) + .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.CENTER) + .add(newButton) + .add(selectButton) + .add(cancelButton)) + .addContainerGap()) + ); + + pack(); + }// </editor-fold>//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 + int row = databasesTable.getSelectedRow(); + if (row > -1) { + doSelect(row); + } + }//GEN-LAST:event_selectButtonActionPerformed + + private void newButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_newButtonActionPerformed + DatabaseDialog dialog = new DatabaseDialog(this, databasesTable.getModel()); + setVisible(false); + dialog.setVisible(true); + if (!dialog.cancelled) { + cancelled = false; + hostname = dialog.hostname; + database = dialog.database; + username = ""; + doClose(); + } else { + setVisible(true); + } + }//GEN-LAST:event_newButtonActionPerformed + +private void tableKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tableKeyPressed + if (evt.getKeyCode() == java.awt.event.KeyEvent.VK_ENTER) { + int row = databasesTable.getSelectedRow(); + if (row > -1) { + doSelect(row); + } + } +}//GEN-LAST:event_tableKeyPressed + + private void doSelect(int row) { + cancelled = false; + + DefaultTableModel model = (DefaultTableModel) databasesTable.getModel(); + hostname = (String) model.getValueAt(row, 0); + database = (String) model.getValueAt(row, 1); + username = (String) model.getValueAt(row, 2); + + if (database == null) { + // filter model + DefaultTableModel submodel = new DefaultTableModel(0, 3); + int rows = model.getRowCount(); + for (int i = 0; i < rows; i++) { + String h = (String) model.getValueAt(i, 0); + if ((h != null) && h.equals(hostname)) { + submodel.addRow(new Object[]{hostname, + model.getValueAt(i, 1), + model.getValueAt(i, 2)}); + } + } + DatabaseDialog dialog = new DatabaseDialog(this, submodel); + setVisible(false); + dialog.setVisible(true); + if (!dialog.cancelled) { + cancelled = false; + hostname = dialog.hostname; + database = dialog.database; + username = ""; + doClose(); + } + } + doClose(); + } + + 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}); + databasesTable.addRowSelectionInterval(0, 0); + } + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JButton cancelButton; + private javax.swing.JTable databasesTable; + private javax.swing.JButton newButton; + private javax.swing.JScrollPane scrollPane; + private javax.swing.JButton selectButton; + // End of variables declaration//GEN-END:variables +}