Mercurial > hg > ltpda
changeset 28:01b86b780ba7 database-connection-manager
Remove LTPDARepositoryManager implementation. Java code
author | Daniele Nicolodi <nicolodi@science.unitn.it> |
---|---|
date | Mon, 05 Dec 2011 16:20:06 +0100 |
parents | 29276498ebdb |
children | 54f14716c721 |
files | src/MPipeline2/src/mpipeline/repository/ConnectionSelector.form src/MPipeline2/src/mpipeline/repository/ConnectionSelector.java src/MPipeline2/src/mpipeline/repository/RepositoryConnection.java src/MPipeline2/src/mpipeline/repository/RepositoryConnectionCellRenderer.java src/MPipeline2/src/mpipeline/repository/RepositoryConnectionDialog.form src/MPipeline2/src/mpipeline/repository/RepositoryConnectionDialog.java src/MPipeline2/src/mpipeline/repository/RepositoryConnectionPasswordDialog.form src/MPipeline2/src/mpipeline/repository/RepositoryConnectionPasswordDialog.java src/MPipeline2/src/mpipeline/repository/RepositoryConnectionTableModel.java src/MPipeline2/src/mpipeline/repository/RepositoryConnectionsTable.java src/MPipeline2/src/mpipeline/repository/RepositoryManager.java src/MPipeline2/src/mpipeline/repository/RepositoryManagerGUI.form src/MPipeline2/src/mpipeline/repository/RepositoryManagerGUI.java |
diffstat | 13 files changed, 0 insertions(+), 2542 deletions(-) [+] |
line wrap: on
line diff
--- 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 @@ -<?xml version="1.0" encoding="UTF-8" ?> - -<Form version="1.3" maxVersion="1.7" type="org.netbeans.modules.form.forminfo.JDialogFormInfo"> - <Properties> - <Property name="defaultCloseOperation" type="int" value="2"/> - <Property name="title" type="java.lang.String" value="Select a connection"/> - </Properties> - <SyntheticProperties> - <SyntheticProperty name="formSizePolicy" type="int" value="1"/> - </SyntheticProperties> - <AuxValues> - <AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/> - <AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/> - <AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/> - <AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/> - <AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/> - <AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="2"/> - <AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/> - <AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/> - <AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/> - </AuxValues> - - <Layout> - <DimensionLayout dim="0"> - <Group type="103" groupAlignment="0" attributes="0"> - <Group type="102" attributes="0"> - <EmptySpace min="-2" max="-2" attributes="0"/> - <Component id="cancelBtn" pref="99" max="32767" attributes="0"/> - <EmptySpace min="-2" max="-2" attributes="0"/> - <Component id="newConnectionBtn" pref="160" max="32767" attributes="0"/> - <EmptySpace min="-2" max="-2" attributes="0"/> - <Component id="selectBtn" pref="97" max="32767" attributes="0"/> - <EmptySpace max="-2" attributes="0"/> - </Group> - <Group type="102" alignment="2" attributes="0"> - <EmptySpace min="12" pref="12" max="12" attributes="0"/> - <Component id="jScrollPane1" pref="368" max="32767" attributes="0"/> - <EmptySpace min="12" pref="12" max="12" attributes="0"/> - </Group> - </Group> - </DimensionLayout> - <DimensionLayout dim="1"> - <Group type="103" groupAlignment="0" attributes="0"> - <Group type="102" alignment="0" attributes="0"> - <EmptySpace min="-2" max="-2" attributes="0"/> - <Component id="jScrollPane1" pref="412" max="32767" attributes="0"/> - <EmptySpace min="-2" pref="12" max="-2" attributes="0"/> - <Group type="103" groupAlignment="2" attributes="0"> - <Component id="selectBtn" alignment="2" min="-2" max="-2" attributes="0"/> - <Component id="newConnectionBtn" alignment="2" min="-2" max="-2" attributes="0"/> - <Component id="cancelBtn" alignment="2" min="-2" max="-2" attributes="0"/> - </Group> - <EmptySpace max="-2" attributes="0"/> - </Group> - </Group> - </DimensionLayout> - </Layout> - <SubComponents> - <Container class="javax.swing.JScrollPane" name="jScrollPane1"> - <AuxValues> - <AuxValue name="autoScrollPane" type="java.lang.Boolean" value="true"/> - </AuxValues> - - <Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/> - <SubComponents> - <Component class="mpipeline.repository.RepositoryConnectionsTable" name="repositoryConnectionsTable"> - <Properties> - <Property name="model" type="javax.swing.table.TableModel" editor="org.netbeans.modules.form.editors2.TableModelEditor"> - <Table columnCount="4" rowCount="4"> - <Column editable="true" title="Title 1" type="java.lang.Object"/> - <Column editable="true" title="Title 2" type="java.lang.Object"/> - <Column editable="true" title="Title 3" type="java.lang.Object"/> - <Column editable="true" title="Title 4" type="java.lang.Object"/> - </Table> - </Property> - </Properties> - </Component> - </SubComponents> - </Container> - <Component class="javax.swing.JButton" name="cancelBtn"> - <Properties> - <Property name="text" type="java.lang.String" value="Cancel"/> - </Properties> - <Events> - <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="cancelBtnActionPerformed"/> - </Events> - </Component> - <Component class="javax.swing.JButton" name="newConnectionBtn"> - <Properties> - <Property name="text" type="java.lang.String" value="New Connection"/> - </Properties> - <Events> - <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="newConnectionBtnActionPerformed"/> - </Events> - </Component> - <Component class="javax.swing.JButton" name="selectBtn"> - <Properties> - <Property name="text" type="java.lang.String" value="Select"/> - </Properties> - <Events> - <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="selectBtnActionPerformed"/> - </Events> - </Component> - </SubComponents> -</Form>
--- 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") - // <editor-fold defaultstate="collapsed" desc="Generated Code">//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(); - }// </editor-fold>//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 -}
--- 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 <one line to give the program's name and a brief idea of what it does.> - * - * Copyright (c) 2009 Max-Planck-Gesellschaft, Martin Hewitson <martin.hewitson at aei.mpg.de> - * - * 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 <http://www.gnu.org/licenses/>. - * - */ -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 <martin.hewitson at aei.mpg.de> - */ -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<String> hosts = new ArrayList<String>(); - 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<String> getTableList() { - openConnection(); - ArrayList<String> tables = new ArrayList<String>(); - 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<String> getDatabaseList() { - ArrayList<String> dbs = new ArrayList<String>(); - - 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. - } -}
--- 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 <code>JTable</code> 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; - } -}
--- 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 @@ -<?xml version="1.0" encoding="UTF-8" ?> - -<Form version="1.3" maxVersion="1.7" type="org.netbeans.modules.form.forminfo.JDialogFormInfo"> - <Properties> - <Property name="defaultCloseOperation" type="int" value="2"/> - <Property name="title" type="java.lang.String" value="Repository Connection"/> - <Property name="locationByPlatform" type="boolean" value="true"/> - <Property name="modal" type="boolean" value="true"/> - <Property name="resizable" type="boolean" value="false"/> - </Properties> - <SyntheticProperties> - <SyntheticProperty name="formSizePolicy" type="int" value="1"/> - </SyntheticProperties> - <AuxValues> - <AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/> - <AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/> - <AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/> - <AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/> - <AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/> - <AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="2"/> - <AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/> - <AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/> - <AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/> - </AuxValues> - - <Layout> - <DimensionLayout dim="0"> - <Group type="103" groupAlignment="0" attributes="0"> - <Group type="102" attributes="0"> - <EmptySpace max="-2" attributes="0"/> - <Group type="103" groupAlignment="0" attributes="0"> - <Component id="jLabel11" alignment="1" min="-2" max="-2" attributes="0"/> - <Component id="jLabel9" alignment="1" min="-2" max="-2" attributes="0"/> - <Component id="jLabel12" alignment="1" min="-2" max="-2" attributes="0"/> - <Component id="jLabel10" alignment="1" min="-2" max="-2" attributes="0"/> - </Group> - <EmptySpace max="-2" attributes="0"/> - <Group type="103" groupAlignment="0" attributes="0"> - <Component id="getDatabaseListBtn" alignment="1" min="-2" max="-2" attributes="0"/> - <Component id="repositoryHostTxtField" alignment="1" pref="216" max="32767" attributes="0"/> - <Component id="passwordTxtField" alignment="1" pref="216" max="32767" attributes="0"/> - <Group type="102" alignment="1" attributes="0"> - <Component id="cancelBtn" min="-2" max="-2" attributes="0"/> - <EmptySpace max="-2" attributes="0"/> - <Component id="connectBtn" min="-2" max="-2" attributes="0"/> - </Group> - <Component id="usernameTxtField" alignment="1" pref="216" max="32767" attributes="0"/> - <Component id="databaseCombo" alignment="1" pref="216" max="32767" attributes="0"/> - <Component id="repositoryHostsCombo" alignment="1" pref="216" max="32767" attributes="0"/> - </Group> - <EmptySpace max="-2" attributes="0"/> - </Group> - </Group> - </DimensionLayout> - <DimensionLayout dim="1"> - <Group type="103" groupAlignment="0" attributes="0"> - <Group type="102" alignment="0" attributes="0"> - <EmptySpace max="-2" attributes="0"/> - <Group type="103" groupAlignment="3" attributes="0"> - <Component id="jLabel9" alignment="3" min="-2" max="-2" attributes="0"/> - <Component id="repositoryHostsCombo" alignment="3" min="-2" max="-2" attributes="0"/> - </Group> - <EmptySpace max="-2" attributes="0"/> - <Component id="repositoryHostTxtField" min="-2" max="-2" attributes="0"/> - <EmptySpace max="-2" attributes="0"/> - <Group type="103" groupAlignment="3" attributes="0"> - <Component id="jLabel11" alignment="3" min="-2" max="-2" attributes="0"/> - <Component id="usernameTxtField" alignment="3" min="-2" max="-2" attributes="0"/> - </Group> - <EmptySpace type="separate" max="-2" attributes="0"/> - <Group type="103" groupAlignment="3" attributes="0"> - <Component id="jLabel12" alignment="3" min="-2" max="-2" attributes="0"/> - <Component id="passwordTxtField" alignment="3" min="-2" max="-2" attributes="0"/> - </Group> - <EmptySpace type="unrelated" max="-2" attributes="0"/> - <Group type="103" groupAlignment="3" attributes="0"> - <Component id="jLabel10" alignment="3" min="-2" max="-2" attributes="0"/> - <Component id="databaseCombo" alignment="3" min="-2" max="-2" attributes="0"/> - </Group> - <EmptySpace type="unrelated" max="-2" attributes="0"/> - <Component id="getDatabaseListBtn" min="-2" max="-2" attributes="0"/> - <EmptySpace max="-2" attributes="0"/> - <Group type="103" groupAlignment="3" attributes="0"> - <Component id="connectBtn" alignment="3" min="-2" max="-2" attributes="0"/> - <Component id="cancelBtn" alignment="3" min="-2" max="-2" attributes="0"/> - </Group> - <EmptySpace max="32767" attributes="0"/> - </Group> - </Group> - </DimensionLayout> - </Layout> - <SubComponents> - <Component class="javax.swing.JLabel" name="jLabel10"> - <Properties> - <Property name="horizontalAlignment" type="int" value="4"/> - <Property name="text" type="java.lang.String" value="database"/> - </Properties> - </Component> - <Component class="javax.swing.JLabel" name="jLabel9"> - <Properties> - <Property name="horizontalAlignment" type="int" value="4"/> - <Property name="text" type="java.lang.String" value="hostname"/> - </Properties> - </Component> - <Component class="javax.swing.JComboBox" name="repositoryHostsCombo"> - <Properties> - <Property name="model" type="javax.swing.ComboBoxModel" editor="org.netbeans.modules.form.editors2.ComboBoxModelEditor"> - <StringArray count="0"/> - </Property> - </Properties> - <Events> - <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="repositoryHostsComboActionPerformed"/> - <EventHandler event="keyTyped" listener="java.awt.event.KeyListener" parameters="java.awt.event.KeyEvent" handler="repositoryHostsComboKeyTyped"/> - </Events> - </Component> - <Component class="javax.swing.JTextField" name="repositoryHostTxtField"> - <Events> - <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="repositoryHostTxtFieldActionPerformed"/> - </Events> - </Component> - <Component class="javax.swing.JComboBox" name="databaseCombo"> - <Properties> - <Property name="editable" type="boolean" value="true"/> - <Property name="model" type="javax.swing.ComboBoxModel" editor="org.netbeans.modules.form.editors2.ComboBoxModelEditor"> - <StringArray count="0"/> - </Property> - </Properties> - <Events> - <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="databaseComboActionPerformed"/> - </Events> - </Component> - <Component class="javax.swing.JButton" name="getDatabaseListBtn"> - <Properties> - <Property name="text" type="java.lang.String" value="Get list"/> - </Properties> - <Events> - <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="getDatabaseListBtnActionPerformed"/> - </Events> - </Component> - <Component class="javax.swing.JTextField" name="usernameTxtField"> - <Events> - <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="usernameTxtFieldActionPerformed"/> - </Events> - </Component> - <Component class="javax.swing.JLabel" name="jLabel11"> - <Properties> - <Property name="horizontalAlignment" type="int" value="4"/> - <Property name="text" type="java.lang.String" value="username"/> - </Properties> - </Component> - <Component class="javax.swing.JLabel" name="jLabel12"> - <Properties> - <Property name="horizontalAlignment" type="int" value="4"/> - <Property name="text" type="java.lang.String" value="password"/> - </Properties> - </Component> - <Component class="javax.swing.JPasswordField" name="passwordTxtField"> - <Events> - <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="passwordTxtFieldActionPerformed"/> - </Events> - </Component> - <Component class="javax.swing.JButton" name="connectBtn"> - <Properties> - <Property name="text" type="java.lang.String" value="Connect"/> - </Properties> - <Events> - <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="connectBtnActionPerformed"/> - </Events> - </Component> - <Component class="javax.swing.JButton" name="cancelBtn"> - <Properties> - <Property name="text" type="java.lang.String" value="Cancel"/> - </Properties> - <Events> - <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="cancelBtnActionPerformed"/> - </Events> - </Component> - </SubComponents> -</Form>
--- 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 <one line to give the program's name and a brief idea of what it does.> - * - * Copyright (c) 2009 Max-Planck-Gesellschaft, Martin Hewitson <martin.hewitson at aei.mpg.de> - * - * 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 <http://www.gnu.org/licenses/>. - * - */ - -/* - * 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 <martin.hewitson at aei.mpg.de> - */ -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<String> 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") - // <editor-fold defaultstate="collapsed" desc="Generated Code">//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(); - }// </editor-fold>//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<String> 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(); - - } -}
--- 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 @@ -<?xml version="1.1" encoding="UTF-8" ?> - -<Form version="1.3" maxVersion="1.7" type="org.netbeans.modules.form.forminfo.JDialogFormInfo"> - <Properties> - <Property name="defaultCloseOperation" type="int" value="2"/> - <Property name="title" type="java.lang.String" value="Login"/> - <Property name="locationByPlatform" type="boolean" value="true"/> - </Properties> - <SyntheticProperties> - <SyntheticProperty name="formSizePolicy" type="int" value="1"/> - </SyntheticProperties> - <AuxValues> - <AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/> - <AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/> - <AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/> - <AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/> - <AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/> - <AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="2"/> - <AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/> - <AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/> - <AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/> - </AuxValues> - - <Layout> - <DimensionLayout dim="0"> - <Group type="103" groupAlignment="0" attributes="0"> - <Group type="102" attributes="0"> - <EmptySpace max="-2" attributes="0"/> - <Group type="103" groupAlignment="0" attributes="0"> - <Group type="102" alignment="1" attributes="0"> - <Component id="cancelBtn" min="-2" max="-2" attributes="0"/> - <EmptySpace max="-2" attributes="0"/> - <Component id="connectBtn" min="-2" max="-2" attributes="0"/> - </Group> - <Group type="102" alignment="0" attributes="0"> - <Component id="jPasswordLable" min="-2" max="-2" attributes="0"/> - <EmptySpace max="-2" attributes="0"/> - <Component id="passwordTxtField" pref="217" max="32767" attributes="0"/> - </Group> - <Component id="jInfoLabel" alignment="0" min="-2" max="-2" attributes="0"/> - </Group> - <EmptySpace max="-2" attributes="0"/> - </Group> - </Group> - </DimensionLayout> - <DimensionLayout dim="1"> - <Group type="103" groupAlignment="0" attributes="0"> - <Group type="102" alignment="0" attributes="0"> - <EmptySpace min="-2" pref="15" max="-2" attributes="0"/> - <Component id="jInfoLabel" min="-2" max="-2" attributes="0"/> - <EmptySpace type="separate" max="-2" attributes="0"/> - <Group type="103" groupAlignment="3" attributes="0"> - <Component id="jPasswordLable" alignment="3" min="-2" max="-2" attributes="0"/> - <Component id="passwordTxtField" alignment="3" min="-2" max="-2" attributes="0"/> - </Group> - <EmptySpace type="separate" max="-2" attributes="0"/> - <Group type="103" groupAlignment="3" attributes="0"> - <Component id="connectBtn" alignment="3" min="-2" max="-2" attributes="0"/> - <Component id="cancelBtn" alignment="3" min="-2" max="-2" attributes="0"/> - </Group> - <EmptySpace max="32767" attributes="0"/> - </Group> - </Group> - </DimensionLayout> - </Layout> - <SubComponents> - <Component class="javax.swing.JLabel" name="jPasswordLable"> - <Properties> - <Property name="horizontalAlignment" type="int" value="4"/> - <Property name="text" type="java.lang.String" value="password"/> - </Properties> - </Component> - <Component class="javax.swing.JPasswordField" name="passwordTxtField"> - <Events> - <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="passwordTxtFieldActionPerformed"/> - </Events> - </Component> - <Component class="javax.swing.JButton" name="connectBtn"> - <Properties> - <Property name="text" type="java.lang.String" value="Connect"/> - </Properties> - <Events> - <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="connectBtnActionPerformed"/> - </Events> - </Component> - <Component class="javax.swing.JButton" name="cancelBtn"> - <Properties> - <Property name="text" type="java.lang.String" value="Cancel"/> - </Properties> - <Events> - <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="cancelBtnActionPerformed"/> - </Events> - </Component> - <Component class="javax.swing.JLabel" name="jInfoLabel"> - <Properties> - <Property name="text" type="java.lang.String" value="username@hostname: database"/> - </Properties> - </Component> - </SubComponents> -</Form>
--- 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 <one line to give the program's name and a brief idea of what it does.> - * - * Copyright (c) 2010 Max-Planck-Gesellschaft, Ingo Diepholz <ingo.diepholz@aei.mpg.de> - * - * 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 <http://www.gnu.org/licenses/>. - * - */ - -/* - * 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 <ingo.diepholz@aei.mpg.de> - */ -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") - // <editor-fold defaultstate="collapsed" desc="Generated Code">//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(); - }// </editor-fold>//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(""); - } - } -// } -}
--- 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<RepositoryConnection> connections = null; - private final String columnName[] = {"Hostname", "Database", "Username", "Age [s]"}; - - public RepositoryConnectionTableModel(ArrayList<RepositoryConnection> 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); - } -}
--- 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; - } -}
--- 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<RepositoryConnection> connections = new ArrayList<RepositoryConnection>(); - private ArrayList<String> repoHosts = new ArrayList<String>(); - - public RepositoryManager() { - } - - public void addConnection(RepositoryConnection aConnection) { - - boolean add = true; - ListIterator<RepositoryConnection> 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<RepositoryConnection> findConnections(String hostname, String database, String username) { - - ArrayList<RepositoryConnection> conns = new ArrayList<RepositoryConnection>(); - - 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<RepositoryConnection> getConnections() { - return connections; - } - - public void setConnections(ArrayList<RepositoryConnection> connections) { - this.connections = connections; - } - - public ArrayList<String> getRepoHosts() { - return repoHosts; - } - - public void setRepoHosts(ArrayList<String> 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. - } -}
--- 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 @@ -<?xml version="1.0" encoding="UTF-8" ?> - -<Form version="1.5" maxVersion="1.7" type="org.netbeans.modules.form.forminfo.JDialogFormInfo"> - <Properties> - <Property name="defaultCloseOperation" type="int" value="2"/> - <Property name="title" type="java.lang.String" value="Repository Manager"/> - </Properties> - <SyntheticProperties> - <SyntheticProperty name="formSizePolicy" type="int" value="1"/> - </SyntheticProperties> - <AuxValues> - <AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/> - <AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/> - <AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/> - <AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/> - <AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/> - <AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="2"/> - <AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/> - <AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/> - <AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/> - </AuxValues> - - <Layout> - <DimensionLayout dim="0"> - <Group type="103" groupAlignment="0" attributes="0"> - <Group type="102" alignment="1" attributes="0"> - <EmptySpace max="-2" attributes="0"/> - <Component id="jScrollPane1" pref="366" max="32767" attributes="0"/> - <EmptySpace max="-2" attributes="0"/> - <Group type="103" groupAlignment="0" max="-2" attributes="0"> - <Component id="newConnectionBtn" alignment="0" max="32767" attributes="1"/> - <Component id="removePwdBtn" alignment="1" max="32767" attributes="1"/> - <Component id="connectBtn" alignment="1" max="32767" attributes="1"/> - <Component id="removeConnBtn" alignment="1" max="32767" attributes="1"/> - </Group> - <EmptySpace min="-2" max="-2" attributes="0"/> - </Group> - </Group> - </DimensionLayout> - <DimensionLayout dim="1"> - <Group type="103" groupAlignment="0" attributes="0"> - <Group type="102" alignment="0" attributes="0"> - <EmptySpace min="-2" max="-2" attributes="0"/> - <Group type="103" groupAlignment="1" attributes="0"> - <Component id="jScrollPane1" alignment="0" min="0" pref="0" max="32767" attributes="2"/> - <Group type="102" alignment="0" attributes="0"> - <Component id="connectBtn" min="-2" pref="51" max="-2" attributes="0"/> - <EmptySpace max="-2" attributes="0"/> - <Component id="removePwdBtn" min="-2" pref="53" max="-2" attributes="0"/> - <EmptySpace max="-2" attributes="0"/> - <Component id="removeConnBtn" min="-2" pref="51" max="-2" attributes="0"/> - <EmptySpace max="-2" attributes="0"/> - <Component id="newConnectionBtn" min="-2" pref="51" max="-2" attributes="0"/> - </Group> - </Group> - <EmptySpace min="-2" max="-2" attributes="0"/> - </Group> - </Group> - </DimensionLayout> - </Layout> - <SubComponents> - <Container class="javax.swing.JScrollPane" name="jScrollPane1"> - <AuxValues> - <AuxValue name="autoScrollPane" type="java.lang.Boolean" value="true"/> - </AuxValues> - - <Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/> - <SubComponents> - <Component class="mpipeline.repository.RepositoryConnectionsTable" name="repositoryConnectionsTable"> - <Properties> - <Property name="model" type="javax.swing.table.TableModel" editor="org.netbeans.modules.form.RADConnectionPropertyEditor"> - <Connection code="new RepositoryConnectionTableModel(manager.getConnections()) " type="code"/> - </Property> - </Properties> - </Component> - </SubComponents> - </Container> - <Component class="javax.swing.JButton" name="connectBtn"> - <Properties> - <Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.editors2.IconEditor"> - <Image iconType="3" name="/mpipeline/icons/connect.png"/> - </Property> - <Property name="text" type="java.lang.String" value="Connect"/> - <Property name="toolTipText" type="java.lang.String" editor="org.netbeans.modules.form.RADConnectionPropertyEditor"> - <Connection code="getConnectTooltip()" type="code"/> - </Property> - </Properties> - <Events> - <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="connectBtnActionPerformed"/> - </Events> - <AuxValues> - <AuxValue name="JavaCodeGenerator_AddingCodePost" type="java.lang.String" value="connectBtn.setDisplayedMnemonicIndex(0);"/> - </AuxValues> - </Component> - <Component class="javax.swing.JButton" name="removeConnBtn"> - <Properties> - <Property name="text" type="java.lang.String" value="Remove Connection"/> - <Property name="toolTipText" type="java.lang.String" value="Remove selected connection from the repository manager"/> - </Properties> - <Events> - <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="removeConnBtnActionPerformed"/> - </Events> - <AuxValues> - <AuxValue name="JavaCodeGenerator_AddingCodePost" type="java.lang.String" value="removeConnBtn.setDisplayedMnemonicIndex(0);"/> - </AuxValues> - </Component> - <Component class="javax.swing.JButton" name="newConnectionBtn"> - <Properties> - <Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.editors2.IconEditor"> - <Image iconType="3" name="/mpipeline/icons/newconnection.png"/> - </Property> - <Property name="text" type="java.lang.String" value="New"/> - <Property name="toolTipText" type="java.lang.String" value="Create new connection"/> - </Properties> - <Events> - <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="newConnectionBtnActionPerformed"/> - </Events> - <AuxValues> - <AuxValue name="JavaCodeGenerator_AddingCodePost" type="java.lang.String" value="newConnectionBtn.setDisplayedMnemonicIndex(0);"/> - </AuxValues> - </Component> - <Component class="javax.swing.JButton" name="removePwdBtn"> - <Properties> - <Property name="text" type="java.lang.String" value="Clear Password"/> - <Property name="toolTipText" type="java.lang.String" value="Clears password from selected connection"/> - </Properties> - <Events> - <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="removePwdBtnActionPerformed"/> - </Events> - <AuxValues> - <AuxValue name="JavaCodeGenerator_AddingCodePost" type="java.lang.String" value="removePwdBtn.setDisplayedMnemonicIndex(6);"/> - </AuxValues> - </Component> - </SubComponents> -</Form>
--- 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") - // <editor-fold defaultstate="collapsed" desc="Generated Code">//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(); - }// </editor-fold>//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 -}