# HG changeset patch # User Daniele Nicolodi # Date 1323098406 -3600 # Node ID 01b86b780ba7b399341c7e64a49dc3a572b0b443 # Parent 29276498ebdb58d664562eea3d2b3d53cc5e27b9 Remove LTPDARepositoryManager implementation. Java code diff -r 29276498ebdb -r 01b86b780ba7 src/MPipeline2/src/mpipeline/repository/ConnectionSelector.form --- a/src/MPipeline2/src/mpipeline/repository/ConnectionSelector.form Mon Dec 05 16:20:06 2011 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,105 +0,0 @@ - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
-
-
-
-
- - - - - - - - - - - - - - - - - - - - - - - - -
-
diff -r 29276498ebdb -r 01b86b780ba7 src/MPipeline2/src/mpipeline/repository/ConnectionSelector.java --- a/src/MPipeline2/src/mpipeline/repository/ConnectionSelector.java Mon Dec 05 16:20:06 2011 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,207 +0,0 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ - -/* - * ConnectionSelector.java - * - * Created on Jan 8, 2010, 3:29:50 PM - */ -package mpipeline.repository; - -import java.awt.Point; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; -import javax.swing.JButton; -import mpipeline.main.MainWindow; - -/** - * - * @author hewitson - */ -public class ConnectionSelector extends javax.swing.JDialog { - - private RepositoryManager manager = null; - private MainWindow mw = null; - private RepositoryConnectionTableModel tableModel = null; - private boolean cancelled = true; - private int selectedIndex = -1; - - /** Creates new form ConnectionSelector */ - public ConnectionSelector(MainWindow parent, RepositoryManager manager) { - super(parent, true); - initComponents(); - - this.manager = manager; - this.mw = parent; - tableModel = new RepositoryConnectionTableModel(manager.getConnections()); - repositoryConnectionsTable.setModel(tableModel); - repositoryConnectionsTable.addMouseListener(new MouseListenerDoubleClick()); - } - - private class MouseListenerDoubleClick extends MouseAdapter { - - @Override - public void mouseClicked(MouseEvent e) { - if (e.getClickCount() >= 2) { - Point p = e.getPoint(); - selectedIndex = repositoryConnectionsTable.rowAtPoint(p); - cancelled = false; - dispose(); - } - } - } - - public void reloadConnectionTable() { - tableModel.fireTableDataChanged(); - } - - public void selectLast() { - repositoryConnectionsTable.getSelectionModel().setSelectionInterval(tableModel.getRowCount()-1, tableModel.getRowCount()-1); - } - - /** This method is called from within the constructor to - * initialize the form. - * WARNING: Do NOT modify this code. The content of this method is - * always regenerated by the Form Editor. - */ - @SuppressWarnings("unchecked") - // //GEN-BEGIN:initComponents - private void initComponents() { - - jScrollPane1 = new javax.swing.JScrollPane(); - repositoryConnectionsTable = new mpipeline.repository.RepositoryConnectionsTable(); - cancelBtn = new javax.swing.JButton(); - newConnectionBtn = new javax.swing.JButton(); - selectBtn = new javax.swing.JButton(); - - setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); - setTitle("Select a connection"); - - repositoryConnectionsTable.setModel(new javax.swing.table.DefaultTableModel( - new Object [][] { - {null, null, null, null}, - {null, null, null, null}, - {null, null, null, null}, - {null, null, null, null} - }, - new String [] { - "Title 1", "Title 2", "Title 3", "Title 4" - } - )); - jScrollPane1.setViewportView(repositoryConnectionsTable); - - cancelBtn.setText("Cancel"); - cancelBtn.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - cancelBtnActionPerformed(evt); - } - }); - - newConnectionBtn.setText("New Connection"); - newConnectionBtn.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - newConnectionBtnActionPerformed(evt); - } - }); - - selectBtn.setText("Select"); - selectBtn.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - selectBtnActionPerformed(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(cancelBtn, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 99, Short.MAX_VALUE) - .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) - .add(newConnectionBtn, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 160, Short.MAX_VALUE) - .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) - .add(selectBtn, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 97, Short.MAX_VALUE) - .addContainerGap()) - .add(org.jdesktop.layout.GroupLayout.CENTER, layout.createSequentialGroup() - .add(12, 12, 12) - .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 368, Short.MAX_VALUE) - .add(12, 12, 12)) - ); - layout.setVerticalGroup( - layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) - .add(layout.createSequentialGroup() - .addContainerGap() - .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 412, Short.MAX_VALUE) - .add(12, 12, 12) - .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.CENTER) - .add(selectBtn) - .add(newConnectionBtn) - .add(cancelBtn)) - .addContainerGap()) - ); - - pack(); - }// //GEN-END:initComponents - - private void cancelBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelBtnActionPerformed - - cancelled = true; - this.dispose(); - }//GEN-LAST:event_cancelBtnActionPerformed - - private void selectBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_selectBtnActionPerformed - - cancelled = false; - selectedIndex = repositoryConnectionsTable.getSelectedRow(); - this.dispose(); - }//GEN-LAST:event_selectBtnActionPerformed - - private void newConnectionBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_newConnectionBtnActionPerformed - - RepositoryConnectionDialog rcd = new RepositoryConnectionDialog(mw, true, manager.getRepoHosts(), null); - rcd.setVisible(true); - - if (!rcd.isCancelled()) { - RepositoryConnection conn = rcd.getRepositoryConnection(); - manager.addConnection(conn); - reloadConnectionTable(); - int rowCount = repositoryConnectionsTable.getRowCount(); - repositoryConnectionsTable.getSelectionModel().setSelectionInterval(rowCount-1, rowCount-1); - } - }//GEN-LAST:event_newConnectionBtnActionPerformed - - public boolean isCancelled() { - return cancelled; - } - - public JButton getNewConnectionBtn() { - return newConnectionBtn; - } - - public int getSelectedIndex() { - return selectedIndex; - } - - public RepositoryConnection getSelectedConnection() { - if (!cancelled) { - if (selectedIndex >= 0 ) { - return(manager.getConnections().get(selectedIndex)); - } - } - return(null); - } - - public JButton getSelectBtn() { - return selectBtn; - } - // Variables declaration - do not modify//GEN-BEGIN:variables - private javax.swing.JButton cancelBtn; - private javax.swing.JScrollPane jScrollPane1; - private javax.swing.JButton newConnectionBtn; - private mpipeline.repository.RepositoryConnectionsTable repositoryConnectionsTable; - private javax.swing.JButton selectBtn; - // End of variables declaration//GEN-END:variables -} diff -r 29276498ebdb -r 01b86b780ba7 src/MPipeline2/src/mpipeline/repository/RepositoryConnection.java --- a/src/MPipeline2/src/mpipeline/repository/RepositoryConnection.java Mon Dec 05 16:20:06 2011 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,423 +0,0 @@ -/* - * Class RepositoryConnection - * - * Copyright (c) 2009 Max-Planck-Gesellschaft, Martin Hewitson - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ -package mpipeline.repository; - -import java.sql.Connection; -import java.sql.DriverManager; -import java.sql.ResultSet; -import java.sql.ResultSetMetaData; -import java.sql.SQLException; -import java.sql.Statement; -import java.util.ArrayList; -import java.util.logging.Level; -import java.util.logging.Logger; -import javax.swing.JOptionPane; -import mpipeline.main.MainWindow; - -/** - * - * @author Martin Hewitson - */ -public class RepositoryConnection { - - private String hostname = ""; - private String database = ""; - private String username = ""; - private String password = ""; - private MainWindow mw = null; - private Connection conn = null; - private long connectedAt = -1; - private long passwordSetAt = -1; - private boolean locked = false; - - public RepositoryConnection(MainWindow mw) { - this.mw = mw; - try { - Class.forName("com.mysql.jdbc.Driver"); - } - catch (ClassNotFoundException ex) { - Logger.getLogger(SubmitInfoDialog.class.getName()).log(Level.SEVERE, null, ex); - } - } - - public RepositoryConnection(MainWindow mw, String aHost, String aDB, String aUser) { - // Call first constructor - this(mw); - // Set all other information - this.hostname = aHost; - this.database = aDB; - this.username = aUser; - } - - public RepositoryConnection(MainWindow mw, String aHost, String aDB, String aUser, String aPassword) { - // Call constructor - this(mw, aHost, aDB, aUser); - // Set all other information - setPassword(aPassword); - } - - public String getDatabase() { - return database; - } - - public void setDatabase(String database) { - if (database != null) { - this.database = database; - } - } - - public String getHostname() { - return hostname; - } - - public void setHostname(String hostname) { - if (hostname != null) { - this.hostname = hostname; - } - } - - public String getPassword() { - return password; - } - - public void setPassword(String password) { - if (password != null) { - this.password = password; - - if (password.length() == 0) - this.passwordSetAt = -1; - else - this.passwordSetAt = System.currentTimeMillis(); - } - } - - public String getUsername() { - return username; - } - - public void setUsername(String username) { - if (username != null) { - this.username = username; - } - } - - public long getConnectedAt() { - return connectedAt; - } - - public void setConnectedAt(long connectedAt) { - this.connectedAt = connectedAt; - } - - public long getPasswordSetAt() { - return passwordSetAt; - } - - public void setPasswordSetAt(long passwordSetAt) { - this.passwordSetAt = passwordSetAt; - } - - public Connection getConn() { - return conn; - } - - public boolean isLocked() { - return locked; - } - - public void setLocked(boolean locked) { - this.locked = locked; - - // Reset the timers because if the user lock the connection - // then I assume that he will use it. - if (locked) { - touch(); - } - } - - public String getDescription() { - return hostname + "/" + database + " as " + username; - } - - public String getURL() { - return "jdbc:mysql://" + hostname + "/" + database; - } - - public static Object[][] resultSetToObjectArray(ResultSet rs) { - Object[][] objects = null; - try { - ResultSetMetaData rsmd = rs.getMetaData(); - int Ncol = rsmd.getColumnCount(); - rs.last(); - int Nrow = rs.getRow(); - rs.beforeFirst(); - - objects = new Object[Nrow][Ncol]; - int kk = 0; - while (rs.next()) { - for (int ll = 0; ll < Ncol; ll++) { - Object o = rs.getObject(ll + 1); - if (o == null) { - objects[kk][ll] = ""; - } - else { - objects[kk][ll] = rs.getObject(ll + 1); - } - } - kk++; - } - } - catch (SQLException ex) { - Logger.getLogger(RepositoryConnection.class.getName()).log(Level.SEVERE, null, ex); - } - - return objects; - } - - public Connection openConnection() { - - // check we have a hostname - if (this.getHostname().equals("")) { - - JOptionPane.showMessageDialog(mw, - "Please set a repository hostname.", - "Connection error", - JOptionPane.ERROR_MESSAGE); - return null; - } - - // check we have a database - if (this.getDatabase().equals("")) { - - JOptionPane.showMessageDialog(mw, - "Please set a repository database.", - "Connection error", - JOptionPane.ERROR_MESSAGE); - return null; - } - - // check we have a username - if (this.getUsername().equals("")) { - - JOptionPane.showMessageDialog(mw, - "Please set a username to log in to the repository", - "Connection error", - JOptionPane.ERROR_MESSAGE); - return null; - } - - // ask for password if no exist - if (this.getPassword().equals("")) { - ArrayList hosts = new ArrayList(); - hosts.add(getHostname()); - - RepositoryConnectionPasswordDialog rpwdd = new RepositoryConnectionPasswordDialog(null, true, this); - rpwdd.setVisible(true); - - if (rpwdd.isCancelled()) { - return null; - } - else { - conn = rpwdd.getConn().getConn(); - } - } - - try { - if (!isConnected()) { - conn = DriverManager.getConnection(getURL(), username, password); - connectedAt = System.currentTimeMillis(); - } - - } - catch (SQLException ex) { - System.err.println("error: " + ex); -// JOptionPane.showMessageDialog(mw, -// "Failed to connect to the repository.", -// "Connection error", -// JOptionPane.ERROR_MESSAGE); - this.setPassword(""); - return null; - } - return conn; - } - - public boolean isConnected() { - if (conn == null) { - return false; - } - try { - return !conn.isClosed(); - } - catch (SQLException ex) { - return false; - } - } - - public void touch() { - this.connectedAt = System.currentTimeMillis(); - this.passwordSetAt = System.currentTimeMillis(); - } - - public void closeConnection() { - if ((conn != null) && (!isLocked())) { - try { - conn.close(); - conn = null; - connectedAt = -1; - } - catch (SQLException ex) { - JOptionPane.showMessageDialog(mw, - "Failed to close connection to the repository.", - "Connection close error", - JOptionPane.ERROR_MESSAGE); - } - } - if (isLocked()) { - System.err.println("Cannot disconnect; the connection is locked."); - } - } - - public ArrayList getTableList() { - openConnection(); - ArrayList tables = new ArrayList(); - try { - ResultSet rs = this.query("show tables;"); - while (rs.next()) { - String str = rs.getString(1); - tables.add(str); - } - } - catch (SQLException ex) { - Logger.getLogger(RepositoryConnection.class.getName()).log(Level.SEVERE, null, ex); - } - return tables; - } - - public ResultSet query(String aQuery) { - - try { - this.openConnection(); - - //Get a Statement object - Statement stmt = conn.createStatement(); - // List databases - ResultSet rs = stmt.executeQuery(aQuery); - return rs; - } - catch (SQLException ex) { - Logger.getLogger(RepositoryConnection.class.getName()).log(Level.SEVERE, null, ex); - } - - return null; - } - - public Statement createStatement() { - try { - this.openConnection(); - Statement s = conn.createStatement(); - return s; - } - catch (SQLException ex) { - return null; - } - } - - public ArrayList getDatabaseList() { - ArrayList dbs = new ArrayList(); - - this.openConnection(); - if (this.isConnected()) { - try { - // List databases - ResultSet rs = this.query("SHOW DATABASES"); - while (rs.next()) { - String str = rs.getString(1); - System.out.println("database: " + str); - if (!str.equals("information_schema") && !str.equals("test") && !str.equals("mysql")) { - dbs.add(str); - } - } - } - catch (SQLException ex) { - JOptionPane.showMessageDialog(mw, - "Failed to retrieve a database list from the repository.", - "Query error", - JOptionPane.ERROR_MESSAGE); - } - } - else { - JOptionPane.showMessageDialog(mw, - "This repository connection is not connected. Please connect first.", - "Connection error", - JOptionPane.ERROR_MESSAGE); - } - return dbs; - } - - public void display() { - System.out.println("--- Repository connection ----- "); - System.out.println(this.getDescription()); - System.out.println(" connected: " + this.isConnected()); - System.out.println(" active: " + this.ageConnected() + " seconds"); - System.out.println(" locked: " + this.isLocked()); - System.out.println("------------------------------- "); - } - - @Override - public String toString() { - return getDescription(); - } - - /** - * Returns the age of the connection in seconds. - * @return - */ - public double ageConnected() { - if (this.isConnected()) { - return (1.0 * System.currentTimeMillis() - this.connectedAt) / 1000.0; - } - else { - return -1.0; - } - } - - /** - * Returns the age of the connection in seconds. - * @return - */ - public double agePassword() { - if (passwordSetAt != -1) { - return (1.0 * System.currentTimeMillis() - this.passwordSetAt) / 1000.0; - } - else { - return -1.0; - } - } - - @Override - protected void finalize() throws Throwable { - //do finalization here - if (conn != null) { - conn.close(); - conn = null; - } - super.finalize(); //not necessary if extending Object. - } -} diff -r 29276498ebdb -r 01b86b780ba7 src/MPipeline2/src/mpipeline/repository/RepositoryConnectionCellRenderer.java --- a/src/MPipeline2/src/mpipeline/repository/RepositoryConnectionCellRenderer.java Mon Dec 05 16:20:06 2011 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,85 +0,0 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ -package mpipeline.repository; - -import java.awt.Color; -import java.awt.Component; -import javax.swing.BorderFactory; -import javax.swing.JTable; -import javax.swing.JTextField; -import javax.swing.UIManager; -import javax.swing.table.DefaultTableCellRenderer; -import javax.swing.table.TableModel; - -/** - * - * @author hewitson - */ -public class RepositoryConnectionCellRenderer extends DefaultTableCellRenderer { - - public JTextField textarea = new JTextField(); - - /** - * Returns the component used for drawing the cell. This method is - * used to configure the renderer appropriately before drawing. - * - * @param table the JTable that is asking the - * renderer to draw. - * @param value the value of the cell to be rendered. - * @param isSelected true if the cell is to be rendered with the - * selection highlighted; otherwise false - * @param hasFocus if true, render cell appropriately. - * @param row the row index of the cell being drawn. - * @param col the column index of the cell being drawn - * - * @return Component - */ - @Override - public Component getTableCellRendererComponent(JTable table, - Object value, - boolean isSelected, - boolean hasFocus, - int row, - int col) { - - Color textcol = Color.green; - - // we need to get the connection from the model - TableModel mdl = table.getModel(); - if (mdl instanceof RepositoryConnectionTableModel) { - RepositoryConnectionTableModel connmdl = (RepositoryConnectionTableModel) mdl; - - RepositoryConnection conn = connmdl.connectionAtRow(row); - - if (!conn.isConnected() && conn.getPassword().equals("")) { - textcol = Color.red; - } - - } - - /* Set default values from table object and UI manager*/ - if (isSelected) { - textarea.setBackground(table.getSelectionBackground()); - textarea.setForeground(textcol); - } else { - textarea.setBackground(table.getBackground()); - textarea.setForeground(textcol); - } - - textarea.setEnabled(table.isEnabled()); - textarea.setFont(table.getFont()); - - if (hasFocus) { - textarea.setBorder(UIManager.getBorder("Table.focusCellHighlightBorder")); - } else { - textarea.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1)); - } - - textarea.setHorizontalAlignment(JTextField.CENTER); - textarea.setText(value.toString()); - - return textarea; - } -} diff -r 29276498ebdb -r 01b86b780ba7 src/MPipeline2/src/mpipeline/repository/RepositoryConnectionDialog.form --- a/src/MPipeline2/src/mpipeline/repository/RepositoryConnectionDialog.form Mon Dec 05 16:20:06 2011 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,179 +0,0 @@ - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
diff -r 29276498ebdb -r 01b86b780ba7 src/MPipeline2/src/mpipeline/repository/RepositoryConnectionDialog.java --- a/src/MPipeline2/src/mpipeline/repository/RepositoryConnectionDialog.java Mon Dec 05 16:20:06 2011 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,384 +0,0 @@ -/* - * Class RepositoryConnectionDialog - * - * Copyright (c) 2009 Max-Planck-Gesellschaft, Martin Hewitson - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -/* - * RepositoryConnectionDialog.java - * - * Created on 25-Jul-2009, 17:12:21 - */ -package mpipeline.repository; - -import java.util.ArrayList; -import java.util.logging.Level; -import java.util.logging.Logger; -import javax.swing.DefaultComboBoxModel; -import mpipeline.main.MainWindow; - -/** - * - * @author Martin Hewitson - */ -public class RepositoryConnectionDialog extends javax.swing.JDialog { - - private RepositoryConnection repoConnection = null; - private boolean cancelled = true; - private MainWindow mw = null; - - /** Creates new form RepositoryConnectionDialog - * @param parent - * @param modal - * @param hostnames - * @param repocon - */ - public RepositoryConnectionDialog(MainWindow parent, boolean modal, ArrayList hostnames, RepositoryConnection repocon) { - super(parent, modal); - initComponents(); - this.mw = parent; - - try { - Class.forName("com.mysql.jdbc.Driver"); - } - catch (ClassNotFoundException ex) { - Logger.getLogger(SubmitInfoDialog.class.getName()).log(Level.SEVERE, null, ex); - } - - repositoryHostsCombo.setModel(new DefaultComboBoxModel(hostnames.toArray())); - if (repocon != null) { - repoConnection = repocon; - usernameTxtField.setText(repocon.getUsername()); - passwordTxtField.setText(repocon.getPassword()); - repositoryHostsCombo.setSelectedItem(repocon.getHostname()); - - if (repocon.getHostname().equals("")) { - if (hostnames.size() > 0) { - repositoryHostTxtField.setText(hostnames.get(0)); - } - } - else { - repositoryHostTxtField.setText(repocon.getHostname()); - } - String[] dbs = new String[1]; - dbs[0] = repocon.getDatabase(); - databaseCombo.setModel(new DefaultComboBoxModel(dbs)); - } - else { - if (hostnames.size() > 0) { - repositoryHostTxtField.setText(hostnames.get(0)); - } - } - } - - public RepositoryConnection getRepositoryConnection() { - return repoConnection; - } - - public boolean isCancelled() { - return cancelled; - } - - /** This method is called from within the constructor to - * initialize the form. - * WARNING: Do NOT modify this code. The content of this method is - * always regenerated by the Form Editor. - */ - @SuppressWarnings("unchecked") - // //GEN-BEGIN:initComponents - private void initComponents() { - - jLabel10 = new javax.swing.JLabel(); - jLabel9 = new javax.swing.JLabel(); - repositoryHostsCombo = new javax.swing.JComboBox(); - repositoryHostTxtField = new javax.swing.JTextField(); - databaseCombo = new javax.swing.JComboBox(); - getDatabaseListBtn = new javax.swing.JButton(); - usernameTxtField = new javax.swing.JTextField(); - jLabel11 = new javax.swing.JLabel(); - jLabel12 = new javax.swing.JLabel(); - passwordTxtField = new javax.swing.JPasswordField(); - connectBtn = new javax.swing.JButton(); - cancelBtn = new javax.swing.JButton(); - - 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"); - - repositoryHostsCombo.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - repositoryHostsComboActionPerformed(evt); - } - }); - repositoryHostsCombo.addKeyListener(new java.awt.event.KeyAdapter() { - public void keyTyped(java.awt.event.KeyEvent evt) { - repositoryHostsComboKeyTyped(evt); - } - }); - - repositoryHostTxtField.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - repositoryHostTxtFieldActionPerformed(evt); - } - }); - - databaseCombo.setEditable(true); - databaseCombo.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - databaseComboActionPerformed(evt); - } - }); - - getDatabaseListBtn.setText("Get list"); - getDatabaseListBtn.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - getDatabaseListBtnActionPerformed(evt); - } - }); - - usernameTxtField.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - usernameTxtFieldActionPerformed(evt); - } - }); - - jLabel11.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); - jLabel11.setText("username"); - - jLabel12.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); - jLabel12.setText("password"); - - passwordTxtField.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - passwordTxtFieldActionPerformed(evt); - } - }); - - connectBtn.setText("Connect"); - connectBtn.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - connectBtnActionPerformed(evt); - } - }); - - cancelBtn.setText("Cancel"); - cancelBtn.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - cancelBtnActionPerformed(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(org.jdesktop.layout.GroupLayout.TRAILING, jLabel11) - .add(org.jdesktop.layout.GroupLayout.TRAILING, jLabel9) - .add(org.jdesktop.layout.GroupLayout.TRAILING, jLabel12) - .add(org.jdesktop.layout.GroupLayout.TRAILING, jLabel10)) - .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) - .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) - .add(org.jdesktop.layout.GroupLayout.TRAILING, getDatabaseListBtn) - .add(org.jdesktop.layout.GroupLayout.TRAILING, repositoryHostTxtField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 216, Short.MAX_VALUE) - .add(org.jdesktop.layout.GroupLayout.TRAILING, passwordTxtField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 216, Short.MAX_VALUE) - .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup() - .add(cancelBtn) - .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) - .add(connectBtn)) - .add(org.jdesktop.layout.GroupLayout.TRAILING, usernameTxtField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 216, Short.MAX_VALUE) - .add(org.jdesktop.layout.GroupLayout.TRAILING, databaseCombo, 0, 216, Short.MAX_VALUE) - .add(org.jdesktop.layout.GroupLayout.TRAILING, repositoryHostsCombo, 0, 216, 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(repositoryHostsCombo, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) - .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) - .add(repositoryHostTxtField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) - .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) - .add(jLabel11) - .add(usernameTxtField, 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(jLabel12) - .add(passwordTxtField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) - .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED) - .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) - .add(jLabel10) - .add(databaseCombo, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) - .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED) - .add(getDatabaseListBtn) - .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) - .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) - .add(connectBtn) - .add(cancelBtn)) - .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - ); - - pack(); - }// //GEN-END:initComponents - - private void repositoryHostsComboActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_repositoryHostsComboActionPerformed - - repositoryHostTxtField.setText(repositoryHostsCombo.getSelectedItem().toString()); - passwordTxtField.setText(""); - checkInputsAndConnect(); - }//GEN-LAST:event_repositoryHostsComboActionPerformed - - private void getDatabaseListBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_getDatabaseListBtnActionPerformed - - RepositoryConnection conn = new RepositoryConnection(mw); - conn.setHostname(repositoryHostTxtField.getText()); - conn.setDatabase("test"); - conn.setUsername(usernameTxtField.getText()); - conn.setPassword(new String(passwordTxtField.getPassword())); - - conn.openConnection(); - if (conn.isConnected()) { - ArrayList dbs = conn.getDatabaseList(); - conn.closeConnection(); - // fill combo list - databaseCombo.setModel(new DefaultComboBoxModel(dbs.toArray())); - } - }//GEN-LAST:event_getDatabaseListBtnActionPerformed - - private void cancelBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelBtnActionPerformed - - cancelled = true; - this.dispose(); - }//GEN-LAST:event_cancelBtnActionPerformed - - private void connectBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_connectBtnActionPerformed - - checkInputsAndConnect(); - }//GEN-LAST:event_connectBtnActionPerformed - - private void repositoryHostTxtFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_repositoryHostTxtFieldActionPerformed - - checkInputsAndConnect(); - }//GEN-LAST:event_repositoryHostTxtFieldActionPerformed - - private void usernameTxtFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_usernameTxtFieldActionPerformed - - checkInputsAndConnect(); - }//GEN-LAST:event_usernameTxtFieldActionPerformed - - private void passwordTxtFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_passwordTxtFieldActionPerformed - - checkInputsAndConnect(); - }//GEN-LAST:event_passwordTxtFieldActionPerformed - - private void databaseComboActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_databaseComboActionPerformed - - // Connect only if the user enters RETURN - if (evt.getActionCommand().equals("comboBoxEdited")) { - checkInputsAndConnect(); - } - }//GEN-LAST:event_databaseComboActionPerformed - - private void repositoryHostsComboKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_repositoryHostsComboKeyTyped - - if (evt.getKeyChar() == '\n') { - checkInputsAndConnect(); - } - }//GEN-LAST:event_repositoryHostsComboKeyTyped - // Variables declaration - do not modify//GEN-BEGIN:variables - private javax.swing.JButton cancelBtn; - private javax.swing.JButton connectBtn; - private javax.swing.JComboBox databaseCombo; - private javax.swing.JButton getDatabaseListBtn; - private javax.swing.JLabel jLabel10; - private javax.swing.JLabel jLabel11; - private javax.swing.JLabel jLabel12; - private javax.swing.JLabel jLabel9; - private javax.swing.JPasswordField passwordTxtField; - private javax.swing.JTextField repositoryHostTxtField; - private javax.swing.JComboBox repositoryHostsCombo; - private javax.swing.JTextField usernameTxtField; - // End of variables declaration//GEN-END:variables - - private void checkInputsAndConnect() { - - String hostname = repositoryHostTxtField.getText(); - String username = usernameTxtField.getText(); - String password = new String(passwordTxtField.getPassword()); - String database = null; - - Object selObj = databaseCombo.getSelectedItem(); - if (selObj == null) { - database = ""; - } - else { - database = selObj.toString(); - } - - // Set the focus to the host-textfield if no hostname is entered. - if (hostname.length() == 0) { - repositoryHostTxtField.requestFocusInWindow(); - return; - } - // Set the focus to the username-textfield if no username is entered. - if (username.length() == 0) { - usernameTxtField.requestFocusInWindow(); - return; - } - // Set the focus to the database-textfield if no database is entered. - if (database.length() == 0) { - databaseCombo.requestFocusInWindow(); - return; - } - - // test the connection - if (repoConnection == null) { - - repoConnection = new RepositoryConnection(mw, hostname, database, username, password); - repoConnection.display(); - - } - else { - - if (repoConnection.isConnected()) { - repoConnection.closeConnection(); - } - - repoConnection.setHostname(hostname); - repoConnection.setDatabase(database); - repoConnection.setUsername(username); - repoConnection.setPassword(password); - } - - cancelled = false; - this.dispose(); - - } -} diff -r 29276498ebdb -r 01b86b780ba7 src/MPipeline2/src/mpipeline/repository/RepositoryConnectionPasswordDialog.form --- a/src/MPipeline2/src/mpipeline/repository/RepositoryConnectionPasswordDialog.form Mon Dec 05 16:20:06 2011 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,100 +0,0 @@ - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
diff -r 29276498ebdb -r 01b86b780ba7 src/MPipeline2/src/mpipeline/repository/RepositoryConnectionPasswordDialog.java --- a/src/MPipeline2/src/mpipeline/repository/RepositoryConnectionPasswordDialog.java Mon Dec 05 16:20:06 2011 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,211 +0,0 @@ -/* - * Class RepositoryConnectionPasswordDialog - * - * Copyright (c) 2010 Max-Planck-Gesellschaft, Ingo Diepholz - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -/* - * RepositoryConnectionPasswordDialog.java - * - * Created on 14-Jan-2010, 18:29:29 - */ -package mpipeline.repository; - -import java.awt.Dimension; -import java.awt.FontMetrics; -import java.util.logging.Level; -import java.util.logging.Logger; -import mpipeline.main.MainWindow; - -/** - * - * @author Ingo Diepholz - */ -public class RepositoryConnectionPasswordDialog extends javax.swing.JDialog { - - private RepositoryConnection conn; - private boolean cancelled = false; - - /** Creates new form RepositoryConnectionPasswordDialog */ - public RepositoryConnectionPasswordDialog(MainWindow parent, boolean modal, RepositoryConnection repocon) { - super(parent, modal); - initComponents(); - - try { - Class.forName("com.mysql.jdbc.Driver"); - } - catch (ClassNotFoundException ex) { - Logger.getLogger(SubmitInfoDialog.class.getName()).log(Level.SEVERE, null, ex); - } - - conn = repocon; - - if (conn != null) { - jInfoLabel.setText(conn.getUsername() + "@" + conn.getHostname() + ": " + conn.getDatabase()); - } - else { - jInfoLabel.setText("null"); - } - - // Make sure that the width of the label string fits into the dialog - FontMetrics fm = jInfoLabel.getFontMetrics(jInfoLabel.getFont()); - int width = fm.stringWidth(jInfoLabel.getText()); - jInfoLabel.setPreferredSize(new Dimension(width, jInfoLabel.getPreferredSize().height)); - jInfoLabel.setMaximumSize(new Dimension(width, jInfoLabel.getPreferredSize().height)); - jInfoLabel.invalidate(); - pack(); - - } - - public boolean isCancelled() { - return cancelled; - } - - public void setCancelled(boolean cancelled) { - this.cancelled = cancelled; - } - - public RepositoryConnection getConn() { - return conn; - } - - public void setConn(RepositoryConnection conn) { - this.conn = conn; - } - - /** This method is called from within the constructor to - * initialize the form. - * WARNING: Do NOT modify this code. The content of this method is - * always regenerated by the Form Editor. - */ - @SuppressWarnings("unchecked") - // //GEN-BEGIN:initComponents - private void initComponents() { - - jPasswordLable = new javax.swing.JLabel(); - passwordTxtField = new javax.swing.JPasswordField(); - connectBtn = new javax.swing.JButton(); - cancelBtn = new javax.swing.JButton(); - jInfoLabel = new javax.swing.JLabel(); - - setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); - setTitle("Login"); - setLocationByPlatform(true); - - jPasswordLable.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); - jPasswordLable.setText("password"); - - passwordTxtField.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - passwordTxtFieldActionPerformed(evt); - } - }); - - connectBtn.setText("Connect"); - connectBtn.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - connectBtnActionPerformed(evt); - } - }); - - cancelBtn.setText("Cancel"); - cancelBtn.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - cancelBtnActionPerformed(evt); - } - }); - - jInfoLabel.setText("username@hostname: database"); - - 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(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup() - .add(cancelBtn) - .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) - .add(connectBtn)) - .add(layout.createSequentialGroup() - .add(jPasswordLable) - .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) - .add(passwordTxtField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 217, Short.MAX_VALUE)) - .add(jInfoLabel)) - .addContainerGap()) - ); - layout.setVerticalGroup( - layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) - .add(layout.createSequentialGroup() - .add(20, 20, 20) - .add(jInfoLabel) - .add(18, 18, 18) - .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) - .add(jPasswordLable) - .add(passwordTxtField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) - .add(18, 18, Short.MAX_VALUE) - .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) - .add(connectBtn) - .add(cancelBtn)) - .addContainerGap()) - ); - - pack(); - }// //GEN-END:initComponents - - private void connectBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_connectBtnActionPerformed - - connectToRepository(); - }//GEN-LAST:event_connectBtnActionPerformed - - private void cancelBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelBtnActionPerformed - - cancelled = true; - this.dispose(); -}//GEN-LAST:event_cancelBtnActionPerformed - - private void passwordTxtFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_passwordTxtFieldActionPerformed - - connectToRepository(); - }//GEN-LAST:event_passwordTxtFieldActionPerformed - - // Variables declaration - do not modify//GEN-BEGIN:variables - private javax.swing.JButton cancelBtn; - private javax.swing.JButton connectBtn; - private javax.swing.JLabel jInfoLabel; - private javax.swing.JLabel jPasswordLable; - private javax.swing.JPasswordField passwordTxtField; - // End of variables declaration//GEN-END:variables - - private void connectToRepository() { - this.dispose(); - String password = new String(passwordTxtField.getPassword()); - -// if (password.length() > 0) { - conn.setPassword(password); - - conn.openConnection(); - if (conn.isConnected()) { - cancelled = false; - } - else { - conn.setPassword(""); - } - } -// } -} diff -r 29276498ebdb -r 01b86b780ba7 src/MPipeline2/src/mpipeline/repository/RepositoryConnectionTableModel.java --- a/src/MPipeline2/src/mpipeline/repository/RepositoryConnectionTableModel.java Mon Dec 05 16:20:06 2011 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,86 +0,0 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ -package mpipeline.repository; - -import java.util.ArrayList; -import javax.swing.event.TableModelEvent; -import javax.swing.event.TableModelListener; -import javax.swing.table.AbstractTableModel; - -/** - * - * @author hewitson - */ -public class RepositoryConnectionTableModel extends AbstractTableModel implements TableModelListener { - - private ArrayList connections = null; - private final String columnName[] = {"Hostname", "Database", "Username", "Age [s]"}; - - public RepositoryConnectionTableModel(ArrayList conns) { - - this.connections = conns; - this.addTableModelListener(this); - } - - public void tableChanged(TableModelEvent e) { - // System.out.println("tableChanged"); - } - - public RepositoryConnection connectionAtRow(int row) { - if (row >= 0 && row < connections.size()) { - return connections.get(row); - } - else { - return null; - } - } - - @Override - public String getColumnName(int col) { - return columnName[col]; - } - - @Override - public boolean isCellEditable(int rowIndex, int columnIndex) { - return false; - } - - public int getRowCount() { - return connections.size(); - } - - public int getColumnCount() { - return 4; - } - - public Object getValueAt(int rowIndex, int columnIndex) { - - if (columnIndex == 0) { - return connections.get(rowIndex).getHostname(); - } - else if (columnIndex == 1) { - return connections.get(rowIndex).getDatabase(); - } - else if (columnIndex == 2) { - return connections.get(rowIndex).getUsername(); - } - else if (columnIndex == 3) { - int age = (int) connections.get(rowIndex).ageConnected(); - if (age < 0) { - return "not connected"; - } - - return age; - } - else { - return connections.get(rowIndex).getHostname(); - } - } - - @Override - public void addTableModelListener(TableModelListener l) { - super.addTableModelListener(l); - } -} diff -r 29276498ebdb -r 01b86b780ba7 src/MPipeline2/src/mpipeline/repository/RepositoryConnectionsTable.java --- a/src/MPipeline2/src/mpipeline/repository/RepositoryConnectionsTable.java Mon Dec 05 16:20:06 2011 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,63 +0,0 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ -package mpipeline.repository; - -import java.awt.Color; -import java.awt.event.MouseEvent; -import javax.swing.JTable; -import javax.swing.ListSelectionModel; -import javax.swing.table.DefaultTableCellRenderer; -import javax.swing.table.TableCellEditor; -import javax.swing.table.TableCellRenderer; - -/** - * - * @author hewitson - */ -public class RepositoryConnectionsTable extends JTable{ - - public RepositoryConnectionsTable() { - - setDefaultRenderer(String.class, new RepositoryConnectionCellRenderer()); - - this.setGridColor(Color.gray); - this.getTableHeader().setReorderingAllowed(false); - this.setSelectionBackground(Color.lightGray); - - this.getTableHeader().setReorderingAllowed(false); - - this.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); - - this.setSelectionBackground(Color.lightGray); - } - - @Override - public String getToolTipText(MouseEvent e) { - String tip = null; - java.awt.Point p = e.getPoint(); - int rowIndex = rowAtPoint(p); - int colIndex = columnAtPoint(p); - - tip = getValueAt(rowIndex, colIndex).toString(); - - return tip; - } - - @Override - public TableCellRenderer getCellRenderer(int row, int column) { - - Object obj = getValueAt(row, column); - if (obj == null) { - return new DefaultTableCellRenderer(); - } - - return new RepositoryConnectionCellRenderer(); - } - - @Override - public TableCellEditor getCellEditor(int row, int column) { - return null; - } -} diff -r 29276498ebdb -r 01b86b780ba7 src/MPipeline2/src/mpipeline/repository/RepositoryManager.java --- a/src/MPipeline2/src/mpipeline/repository/RepositoryManager.java Mon Dec 05 16:20:06 2011 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,235 +0,0 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ -package mpipeline.repository; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.ListIterator; -import mpipeline.main.MainWindow; - -/** - * - * @author hewitson - */ -public class RepositoryManager { - - private ArrayList connections = new ArrayList(); - private ArrayList repoHosts = new ArrayList(); - - public RepositoryManager() { - } - - public void addConnection(RepositoryConnection aConnection) { - - boolean add = true; - ListIterator it = connections.listIterator(); - while (it.hasNext()) { - RepositoryConnection conn = it.next(); - if ((conn.getHostname().equals(aConnection.getHostname())) && - (conn.getDatabase().equals(aConnection.getDatabase())) && - (conn.getUsername().equals(aConnection.getUsername()))) { - // If an existing connection have the same hostname, database - // and user name then don't add the connection - if (conn.getPassword().length() == 0) { - conn.setPassword(aConnection.getPassword()); - } - add = false; - break; - } - } - - if (add) { - connections.add(aConnection); - } - } - - public void removeConnection(RepositoryConnection aConnection) { - connections.remove(aConnection); - } - - public void removeAll() { - this.closeAllConnections(); - connections.clear(); - } - - public void closeAllConnections() { - Iterator it = connections.iterator(); - while (it.hasNext()) { - RepositoryConnection conn = (RepositoryConnection) it.next(); - conn.setLocked(false); - conn.closeConnection(); - } - } - - public ArrayList findConnections(String hostname, String database, String username) { - - ArrayList conns = new ArrayList(); - - Iterator it = connections.iterator(); - while (it.hasNext()) { - RepositoryConnection conn = (RepositoryConnection) it.next(); - - boolean found = true; - - // check hostname if it's not empty - if (hostname.length() != 0 && !conn.getHostname().equals(hostname)) { - found = false; - } - - // check database if it's not empty - if (database.length() != 0 && !conn.getDatabase().equals(database)) { - found = false; - } - - // check username if it's not empty - if (username.length() != 0 && !conn.getUsername().equals(username)) { - found = false; - } - - if (found) { - conns.add(conn); - } - } - - return conns; - } - - public RepositoryConnection findConnection(String hostname, String database, String username) { - - RepositoryConnection connFound = null; - - Iterator it = connections.iterator(); - while (it.hasNext()) { - RepositoryConnection conn = (RepositoryConnection) it.next(); - - boolean found = true; - - // check hostname if it's not empty - if (hostname.length() != 0 && !conn.getHostname().equals(hostname)) { - found = false; - } - - // check database if it's not empty - if (database.length() != 0 && !conn.getDatabase().equals(database)) { - found = false; - } - - // check username if it's not empty - if (username.length() != 0 && !conn.getUsername().equals(username)) { - found = false; - } - - if (found) { - connFound = conn; - break; - } - } - - return connFound; - } - - public RepositoryConnection findExactConnection(String hostname, String database, String username) { - - RepositoryConnection connFound = null; - - Iterator it = connections.iterator(); - while (it.hasNext()) { - RepositoryConnection conn = (RepositoryConnection) it.next(); - - // check hostname - if (conn.getHostname().equals(hostname) && - conn.getDatabase().equals(database) && - conn.getUsername().equals(username)) { - connFound = conn; - break; - } - } - return connFound; - } - - /** - * - * @param mw LTPDA main window - * @return selected connection - */ - public RepositoryConnection selectConnection(MainWindow mw) { - - RepositoryConnection conn = null; - - if (connections.size() >= 1) { - ConnectionSelector cs = new ConnectionSelector(mw, this); - cs.setVisible(true); - - if (!cs.isCancelled()) { - conn = cs.getSelectedConnection(); - } - } - else { - RepositoryConnectionDialog rcd = new RepositoryConnectionDialog(mw, true, repoHosts, null); - rcd.setVisible(true); - - if (!rcd.isCancelled()) { - conn = rcd.getRepositoryConnection(); - addConnection(conn); - } - } - - if (conn != null) { - conn.openConnection(); - if (!conn.isConnected()) { - conn = null; - } - } - return (conn); - } - - public int count() { - return connections.size(); - } - - public int countConnected() { - int count = 0; - Iterator it = connections.iterator(); - while (it.hasNext()) { - RepositoryConnection conn = (RepositoryConnection) it.next(); - if (conn.isConnected()) { - count++; - } - } - return count; - } - - public ArrayList getConnections() { - return connections; - } - - public void setConnections(ArrayList connections) { - this.connections = connections; - } - - public ArrayList getRepoHosts() { - return repoHosts; - } - - public void setRepoHosts(ArrayList repoHosts) { - this.repoHosts = repoHosts; - } - - public void display() { - System.out.println("---- Repository Manager ----- "); - System.out.println(" connections: " + this.count()); - System.out.println(" connected: " + this.countConnected()); - System.out.println("------------------------------ "); - } - - @Override - protected void finalize() throws Throwable { - System.out.println("Finalized repository manager"); - closeAllConnections(); - - //do finalization here - super.finalize(); //not necessary if extending Object. - } -} diff -r 29276498ebdb -r 01b86b780ba7 src/MPipeline2/src/mpipeline/repository/RepositoryManagerGUI.form --- a/src/MPipeline2/src/mpipeline/repository/RepositoryManagerGUI.form Mon Dec 05 16:20:06 2011 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,135 +0,0 @@ - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
diff -r 29276498ebdb -r 01b86b780ba7 src/MPipeline2/src/mpipeline/repository/RepositoryManagerGUI.java --- a/src/MPipeline2/src/mpipeline/repository/RepositoryManagerGUI.java Mon Dec 05 16:20:06 2011 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,329 +0,0 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ - -/* - * RepositoryManagerGUI.java - * - * Created on Jan 6, 2010, 10:38:55 AM - */ -package mpipeline.repository; - -import mpipeline.dialogs.KeyBindingDialog; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.KeyEvent; -import javax.swing.AbstractAction; -import javax.swing.ImageIcon; -import javax.swing.JComponent; -import javax.swing.KeyStroke; -import javax.swing.Timer; -import javax.swing.event.ListSelectionEvent; -import javax.swing.event.ListSelectionListener; -import mpipeline.main.MainWindow; - -/** - * - * @author hewitson - */ -public class RepositoryManagerGUI extends KeyBindingDialog { - - private RepositoryManager manager = null; - private MainWindow mw = null; - private RepositoryConnectionTableModel tableModel = null; - private ImageIcon disconnectIcon; - private ImageIcon connectIcon; - private javax.swing.Timer guiTimer = null; - - /** Creates new form RepositoryManagerGUI */ - public RepositoryManagerGUI(MainWindow parent, RepositoryManager manager) { - super(parent, false); - this.manager = manager; - this.mw = parent; - - initComponents(); - - tableModel = (RepositoryConnectionTableModel) repositoryConnectionsTable.getModel(); - - repositoryConnectionsTable.getSelectionModel().addListSelectionListener(new SelectionListener()); - - disconnectIcon = new javax.swing.ImageIcon(getClass().getResource("/mpipeline/icons/disconnect.png")); - connectIcon = new javax.swing.ImageIcon(getClass().getResource("/mpipeline/icons/connect.png")); - guiTimer = new Timer(1000, new ActionListenerTimer()); - guiTimer.start(); - - // Connect/Disconnect the selected connection with CTRL+C - KeyStroke keyStrokeC = KeyStroke.getKeyStroke(KeyEvent.VK_C, keyModifier, false); - rootPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(keyStrokeC, "CTRL_C"); - rootPane.getInputMap(JComponent.WHEN_FOCUSED).put(keyStrokeC, "CTRL_C"); -// rootPane.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(keyStrokeC, "CTRL_C"); - rootPane.getActionMap().put("CTRL_C", new ActionCTRL_C()); - repositoryConnectionsTable.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(keyStrokeC, "CTRL_C"); - repositoryConnectionsTable.getInputMap(JComponent.WHEN_FOCUSED).put(keyStrokeC, "CTRL_C"); - repositoryConnectionsTable.getActionMap().put("CTRL_C", new ActionCTRL_C()); - - // Clear the password of the selected connection with CTRL+P - KeyStroke keyStrokeP = KeyStroke.getKeyStroke(KeyEvent.VK_P, keyModifier, false); - rootPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(keyStrokeP, "CTRL_P"); - rootPane.getActionMap().put("CTRL_P", new ActionCTRL_P()); - - // Remove the selected connection with CTRL+R - KeyStroke keyStrokeR = KeyStroke.getKeyStroke(KeyEvent.VK_R, keyModifier); - rootPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(keyStrokeR, "CTRL_R"); - rootPane.getActionMap().put("CTRL_R", new ActionCTRL_R()); - - // Create a new connection with CTRL+N - KeyStroke keyStrokeN = KeyStroke.getKeyStroke(KeyEvent.VK_N, keyModifier); - rootPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(keyStrokeN, "CTRL_N"); - rootPane.getActionMap().put("CTRL_N", new ActionCTRL_N()); -} - - private class ActionCTRL_N extends AbstractAction { - - public void actionPerformed(ActionEvent e) { - newConnectionBtnActionPerformed(e); - } - } - - private class ActionCTRL_R extends AbstractAction { - - public void actionPerformed(ActionEvent e) { - removeConnBtnActionPerformed(e); - } - } - - private class ActionCTRL_P extends AbstractAction { - - public void actionPerformed(ActionEvent e) { - removePwdBtnActionPerformed(e); - } - } - - private class ActionCTRL_C extends AbstractAction { - - public void actionPerformed(ActionEvent e) { - connectBtnActionPerformed(e); - } - } - - private class ActionListenerTimer implements ActionListener { - - public void actionPerformed(ActionEvent evt) { - for (int i = 0; i < tableModel.getRowCount(); i++) { - tableModel.fireTableCellUpdated(i, 3); - } - } - } - - private class SelectionListener implements ListSelectionListener { - - public void valueChanged(ListSelectionEvent e) { - - int row = repositoryConnectionsTable.getSelectedRow(); - - if (row >= 0) { - // get connection at this row - RepositoryConnection conn = tableModel.connectionAtRow(row); - - if (conn != null) { - if (conn.isConnected()) { - connectBtn.setText("Disconnect"); - connectBtn.setIcon(disconnectIcon); - connectBtn.setDisplayedMnemonicIndex(3); - } - else { - connectBtn.setText("Connect"); - connectBtn.setIcon(connectIcon); - connectBtn.setDisplayedMnemonicIndex(0); - } - } - } - } - } - - private String getConnectTooltip() { - return ("Connect/Disconnect selected connection " + getKeyBindingText(KeyEvent.VK_C, true)); - } - - /** This method is called from within the constructor to - * initialize the form. - * WARNING: Do NOT modify this code. The content of this method is - * always regenerated by the Form Editor. - */ - @SuppressWarnings("unchecked") - // //GEN-BEGIN:initComponents - private void initComponents() { - - jScrollPane1 = new javax.swing.JScrollPane(); - repositoryConnectionsTable = new mpipeline.repository.RepositoryConnectionsTable(); - connectBtn = new javax.swing.JButton(); - removeConnBtn = new javax.swing.JButton(); - newConnectionBtn = new javax.swing.JButton(); - removePwdBtn = new javax.swing.JButton(); - - setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); - setTitle("Repository Manager"); - - repositoryConnectionsTable.setModel(new RepositoryConnectionTableModel(manager.getConnections()) ); - jScrollPane1.setViewportView(repositoryConnectionsTable); - - connectBtn.setIcon(new javax.swing.ImageIcon(getClass().getResource("/mpipeline/icons/connect.png"))); // NOI18N - connectBtn.setText("Connect"); - connectBtn.setToolTipText(getConnectTooltip()); - connectBtn.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - connectBtnActionPerformed(evt); - } - }); - - removeConnBtn.setText("Remove Connection"); - removeConnBtn.setToolTipText("Remove selected connection from the repository manager"); - removeConnBtn.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - removeConnBtnActionPerformed(evt); - } - }); - - newConnectionBtn.setIcon(new javax.swing.ImageIcon(getClass().getResource("/mpipeline/icons/newconnection.png"))); // NOI18N - newConnectionBtn.setText("New"); - newConnectionBtn.setToolTipText("Create new connection"); - newConnectionBtn.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - newConnectionBtnActionPerformed(evt); - } - }); - - removePwdBtn.setText("Clear Password"); - removePwdBtn.setToolTipText("Clears password from selected connection"); - removePwdBtn.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - removePwdBtnActionPerformed(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(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup() - .addContainerGap() - .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 366, Short.MAX_VALUE) - .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) - .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false) - .add(newConnectionBtn, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .add(org.jdesktop.layout.GroupLayout.TRAILING, removePwdBtn, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .add(org.jdesktop.layout.GroupLayout.TRAILING, connectBtn, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .add(org.jdesktop.layout.GroupLayout.TRAILING, removeConnBtn, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - .addContainerGap()) - ); - layout.setVerticalGroup( - layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) - .add(layout.createSequentialGroup() - .addContainerGap() - .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING) - .add(org.jdesktop.layout.GroupLayout.LEADING, jScrollPane1, 0, 0, Short.MAX_VALUE) - .add(org.jdesktop.layout.GroupLayout.LEADING, layout.createSequentialGroup() - .add(connectBtn, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 51, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) - .add(removePwdBtn, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 53, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) - .add(removeConnBtn, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 51, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) - .add(newConnectionBtn, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 51, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))) - .addContainerGap()) - ); - - connectBtn.setDisplayedMnemonicIndex(0); - removeConnBtn.setDisplayedMnemonicIndex(0); - newConnectionBtn.setDisplayedMnemonicIndex(0); - removePwdBtn.setDisplayedMnemonicIndex(6); - - pack(); - }// //GEN-END:initComponents - - public void reloadConnectionTable() { - tableModel.fireTableDataChanged(); - } - - private void connectBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_connectBtnActionPerformed - - // get selected connection - int row = repositoryConnectionsTable.getSelectedRow(); - if (row >= 0) { - RepositoryConnection conn = tableModel.connectionAtRow(row); - if (conn != null) { - if (conn.isConnected()) { - conn.closeConnection(); - connectBtn.setText("Connect"); - connectBtn.setIcon(connectIcon); - connectBtn.setDisplayedMnemonicIndex(0); - } - else { - conn.openConnection(); - if (conn.isConnected()) { - connectBtn.setText("Disconnect"); - connectBtn.setIcon(disconnectIcon); - connectBtn.setDisplayedMnemonicIndex(3); - } - } - - tableModel.fireTableDataChanged(); - repositoryConnectionsTable.getSelectionModel().setSelectionInterval(row, row); - } - } - - }//GEN-LAST:event_connectBtnActionPerformed - - private void removeConnBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeConnBtnActionPerformed - - int row = repositoryConnectionsTable.getSelectedRow(); - if (row >= 0) { - RepositoryConnection conn = tableModel.connectionAtRow(row); - if (conn != null) { - conn.closeConnection(); - manager.removeConnection(conn); - tableModel.fireTableDataChanged(); - } - } - - }//GEN-LAST:event_removeConnBtnActionPerformed - - private void removePwdBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removePwdBtnActionPerformed - - int row = repositoryConnectionsTable.getSelectedRow(); - if (row >= 0) { - RepositoryConnection conn = tableModel.connectionAtRow(row); - if (conn != null) { - if (conn.isConnected()) { - conn.closeConnection(); - } - conn.setPassword(""); - - tableModel.fireTableDataChanged(); - repositoryConnectionsTable.getSelectionModel().setSelectionInterval(row, row); - } - } - - }//GEN-LAST:event_removePwdBtnActionPerformed - - private void newConnectionBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_newConnectionBtnActionPerformed - - RepositoryConnectionDialog rcd = new RepositoryConnectionDialog(mw, true, manager.getRepoHosts(), null); - rcd.setVisible(true); - - if (!rcd.isCancelled()) { - RepositoryConnection conn = rcd.getRepositoryConnection(); - manager.addConnection(conn); - reloadConnectionTable(); - } - }//GEN-LAST:event_newConnectionBtnActionPerformed - // Variables declaration - do not modify//GEN-BEGIN:variables - private javax.swing.JButton connectBtn; - private javax.swing.JScrollPane jScrollPane1; - private javax.swing.JButton newConnectionBtn; - private javax.swing.JButton removeConnBtn; - private javax.swing.JButton removePwdBtn; - private mpipeline.repository.RepositoryConnectionsTable repositoryConnectionsTable; - // End of variables declaration//GEN-END:variables -}