# HG changeset patch # User Daniele Nicolodi # Date 1323098406 -3600 # Node ID 5e7477b94d944027f5c8e63af905d2eed89a5a71 # Parent e22b091498e41421e2eed54d8b054fab126493fc Add known repositories list to LTPDAPreferences diff -r e22b091498e4 -r 5e7477b94d94 m-toolbox/classes/@LTPDADatabaseConnectionManager/LTPDADatabaseConnectionManager.m --- a/m-toolbox/classes/@LTPDADatabaseConnectionManager/LTPDADatabaseConnectionManager.m Mon Dec 05 16:20:06 2011 +0100 +++ b/m-toolbox/classes/@LTPDADatabaseConnectionManager/LTPDADatabaseConnectionManager.m Mon Dec 05 16:20:06 2011 +0100 @@ -12,6 +12,7 @@ credentialsExpiry; % seconds cachePassword; % 0=no 1=yes 2=ask maxConnectionsNumber; + knownRepositories; % known repositories stored into prefereces end % dependent properties @@ -70,8 +71,22 @@ else cm = acm; end + + % add known repositories from preferences + repos = cm.knownRepositories; + for kk = 1:numel(repos) + repo = repos{kk}; + for jj = 1:3 + % null empty parameters + if isempty(repo{jj}) + repo{jj} = []; + end + end + cm.add(utils.credentials(repo{:})); + end end + function str = disp(cm) disp(sprintf('%s()\n', class(cm))); end @@ -98,6 +113,13 @@ end + function val = get.knownRepositories(cm) + % obtain from user preferences + p = getappdata(0, 'LTPDApreferences'); + val = cell(p.getRepoPrefs().getRepositories().toArray()); + end + + function n = count(cm) % COUNT Returns the number of open connections in the connections pool. % diff -r e22b091498e4 -r 5e7477b94d94 src/MPipeline2/src/mpipeline/ltpdapreferences/RepositoryDialog.form --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/MPipeline2/src/mpipeline/ltpdapreferences/RepositoryDialog.form Mon Dec 05 16:20:06 2011 +0100 @@ -0,0 +1,153 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff -r e22b091498e4 -r 5e7477b94d94 src/MPipeline2/src/mpipeline/ltpdapreferences/RepositoryDialog.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/MPipeline2/src/mpipeline/ltpdapreferences/RepositoryDialog.java Mon Dec 05 16:20:06 2011 +0100 @@ -0,0 +1,208 @@ +package mpipeline.ltpdapreferences; + +import java.util.HashSet; +import javax.swing.DefaultComboBoxModel; +import javax.swing.table.TableModel; + +public class RepositoryDialog extends javax.swing.JDialog { + + public boolean cancelled = true; + public String hostname; + public String database; + public String username; + private TableModel model; + + public RepositoryDialog(java.awt.Window parent, TableModel model) { + super(parent, java.awt.Dialog.ModalityType.APPLICATION_MODAL); + this.model = model; + initComponents(); + initHostnameCombo(); + initDatabaseCombo(); + initUsernameCombo(); + super.setLocationRelativeTo(parent); + } + + public RepositoryDialog(java.awt.Frame parent) { + super(parent, true); + initComponents(); + super.setLocationRelativeTo(parent); + } + + public RepositoryDialog() { + super(new java.awt.Frame(), true); + initComponents(); + } + + @SuppressWarnings("unchecked") + // //GEN-BEGIN:initComponents + private void initComponents() { + + jLabel9 = new javax.swing.JLabel(); + jLabel10 = new javax.swing.JLabel(); + jLabel11 = new javax.swing.JLabel(); + databaseCombo = new javax.swing.JComboBox(); + hostnameCombo = new javax.swing.JComboBox(); + usernameCombo = new javax.swing.JComboBox(); + okButton = new javax.swing.JButton(); + cancelButton = new javax.swing.JButton(); + + setTitle("Database connection"); + setLocationByPlatform(true); + setModal(true); + setResizable(false); + + jLabel9.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); + jLabel9.setText("Hostname:"); + + jLabel10.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); + jLabel10.setText("Database:"); + + jLabel11.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); + jLabel11.setText("Username:"); + + databaseCombo.setEditable(true); + + hostnameCombo.setEditable(true); + hostnameCombo.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + hostnameComboActionPerformed(evt); + } + }); + + usernameCombo.setEditable(true); + + okButton.setText("Ok"); + okButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + okButtonActionPerformed(evt); + } + }); + + cancelButton.setText("Cancel"); + cancelButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + cancelButtonActionPerformed(evt); + } + }); + + org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane()); + getContentPane().setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(layout.createSequentialGroup() + .addContainerGap() + .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(layout.createSequentialGroup() + .add(jLabel9) + .add(18, 18, 18) + .add(hostnameCombo, 0, 240, Short.MAX_VALUE)) + .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup() + .add(jLabel10) + .add(21, 21, 21) + .add(databaseCombo, 0, 240, Short.MAX_VALUE)) + .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup() + .add(cancelButton) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) + .add(okButton)) + .add(layout.createSequentialGroup() + .add(jLabel11) + .add(18, 18, 18) + .add(usernameCombo, 0, 240, Short.MAX_VALUE))) + .addContainerGap()) + ); + layout.setVerticalGroup( + layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(layout.createSequentialGroup() + .addContainerGap() + .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) + .add(hostnameCombo, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) + .add(jLabel9)) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED) + .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) + .add(databaseCombo, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) + .add(jLabel10)) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED) + .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) + .add(jLabel11) + .add(usernameCombo, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) + .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(layout.createSequentialGroup() + .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 12, Short.MAX_VALUE) + .add(okButton) + .addContainerGap()) + .add(layout.createSequentialGroup() + .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED) + .add(cancelButton) + .addContainerGap()))) + ); + + pack(); + }// //GEN-END:initComponents + + private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed + cancelled = true; + doClose(); + }//GEN-LAST:event_cancelButtonActionPerformed + + private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okButtonActionPerformed + cancelled = false; + hostname = (String) hostnameCombo.getSelectedItem(); + database = (String) databaseCombo.getSelectedItem(); + username = (String) usernameCombo.getSelectedItem(); + doClose(); + }//GEN-LAST:event_okButtonActionPerformed + + private void hostnameComboActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_hostnameComboActionPerformed + initDatabaseCombo(); + initUsernameCombo(); + }//GEN-LAST:event_hostnameComboActionPerformed + + private void initHostnameCombo() { + HashSet hostnames = new HashSet(); + int rows = model.getRowCount(); + for (int i = 0; i < rows; i++) { + hostnames.add((String) model.getValueAt(i, 0)); + } + hostnameCombo.setModel(new DefaultComboBoxModel(hostnames.toArray())); + } + + private void initDatabaseCombo() { + HashSet databases = new HashSet(); + hostname = (String) hostnameCombo.getSelectedItem(); + int rows = model.getRowCount(); + for (int i = 0; i < rows; i++) { + if (hostname.equals((String) model.getValueAt(i, 0))) { + databases.add((String) model.getValueAt(i, 1)); + } + } + databaseCombo.setModel(new DefaultComboBoxModel(databases.toArray())); + } + + private void initUsernameCombo() { + HashSet usernames = new HashSet(); + hostname = (String) hostnameCombo.getSelectedItem(); + int rows = model.getRowCount(); + for (int i = 0; i < rows; i++) { + if (hostname.equals((String) model.getValueAt(i, 0))) { + usernames.add((String) model.getValueAt(i, 2)); + } + } + usernameCombo.setModel(new DefaultComboBoxModel(usernames.toArray())); + } + + private void doClose() { + setVisible(false); + dispose(); + + } + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JButton cancelButton; + private javax.swing.JComboBox databaseCombo; + private javax.swing.JComboBox hostnameCombo; + private javax.swing.JLabel jLabel10; + private javax.swing.JLabel jLabel11; + private javax.swing.JLabel jLabel9; + private javax.swing.JButton okButton; + private javax.swing.JComboBox usernameCombo; + // End of variables declaration//GEN-END:variables +} diff -r e22b091498e4 -r 5e7477b94d94 src/MPipeline2/src/mpipeline/ltpdapreferences/RepositoryPrefGroup.java --- a/src/MPipeline2/src/mpipeline/ltpdapreferences/RepositoryPrefGroup.java Mon Dec 05 16:20:06 2011 +0100 +++ b/src/MPipeline2/src/mpipeline/ltpdapreferences/RepositoryPrefGroup.java Mon Dec 05 16:20:06 2011 +0100 @@ -4,6 +4,7 @@ */ package mpipeline.ltpdapreferences; +import java.util.List; import java.util.ArrayList; import mpipeline.utils.MXMLUtils; import org.w3c.dom.Document; @@ -25,10 +26,11 @@ private Integer expiry = 60; private Integer cachePassword = 2; private Integer maxConnectionsNumber = 10; + private ArrayList repositories = new ArrayList(0); public RepositoryPrefGroup() { } - + public RepositoryPrefGroup(Node node, float version) { NamedNodeMap nmap = node.getAttributes(); @@ -39,6 +41,21 @@ maxConnectionsNumber = MXMLUtils.getIntegerFromNode("maxConnectionsNumber", nmap, version, version); if (maxConnectionsNumber < 0) maxConnectionsNumber = 10; + + org.w3c.dom.NodeList nodes = node.getChildNodes(); + for (int i = 0; i < nodes.getLength(); i++) { + try { + if (nodes.item(i).getNodeName().equals("Entry")) { + NamedNodeMap map = nodes.item(i).getAttributes(); + String hostname = map.getNamedItem("hostname").getNodeValue(); + String database = map.getNamedItem("database").getNodeValue(); + String username = map.getNamedItem("username").getNodeValue(); + repositories.add(new String[]{hostname, database, username}); + } + } catch (NullPointerException ex) { + // continue + } + } } public void attachToDom(Document doc, Element tnode) { @@ -48,6 +65,13 @@ pnode.setAttribute("cachePassword", ""+cachePassword); pnode.setAttribute("maxConnectionsNumber", ""+maxConnectionsNumber); tnode.appendChild(pnode); + for (String[] repo : repositories) { + Element node = doc.createElement("Entry"); + node.setAttribute("hostname", repo[0]); + node.setAttribute("database", repo[1]); + node.setAttribute("username", repo[2]); + pnode.appendChild(node); + } } public Integer getExpiry() { @@ -61,28 +85,35 @@ } public Integer getCachePassword() { - return cachePassword; + return cachePassword; } - + public void setCachePassword(Integer value) { - cachePassword = value; - setChanged(); - notifyObservers(REPOSITORY_CACHE_PASSWORD_CHANGED); + cachePassword = value; + setChanged(); + notifyObservers(REPOSITORY_CACHE_PASSWORD_CHANGED); + } + + public Integer getMaxConnectionsNumber() { + return maxConnectionsNumber; + } + + public void setMaxConnectionsNumber(Integer value) { + maxConnectionsNumber = value; + setChanged(); + notifyObservers(REPOSITORY_MAX_CONNECTIONS_NUMBER_CHANGED); } - public Integer getMaxConnectionsNumber() { - return maxConnectionsNumber; + public ArrayList getRepositories() { + return repositories; } - public void setMaxConnectionsNumber(Integer value) { - maxConnectionsNumber = value; - setChanged(); - notifyObservers(REPOSITORY_MAX_CONNECTIONS_NUMBER_CHANGED); - } - - // for backward compatibility - public ArrayList getHostnames() { - return new ArrayList(); + public void setRepositories(ArrayList value) { + repositories.clear(); + for (String[] repo : value) { + repositories.add(repo); + } + setChanged(); } public void display() { diff -r e22b091498e4 -r 5e7477b94d94 src/MPipeline2/src/mpipeline/ltpdapreferences/RepositoryPrefGroupPanel.form --- a/src/MPipeline2/src/mpipeline/ltpdapreferences/RepositoryPrefGroupPanel.form Mon Dec 05 16:20:06 2011 +0100 +++ b/src/MPipeline2/src/mpipeline/ltpdapreferences/RepositoryPrefGroupPanel.form Mon Dec 05 16:20:06 2011 +0100 @@ -1,6 +1,6 @@ -
+ @@ -19,11 +19,7 @@ - - - - - + @@ -34,12 +30,23 @@ - + + + + + + + + + + + + - + @@ -51,7 +58,7 @@ - + @@ -62,7 +69,16 @@ - + + + + + + + + + + @@ -113,5 +129,57 @@ + + + + + + + + + + + + + + +
+
+ + + + + + + + + + + +
+
+
+
+ + + + + + + + + + + + + + + + + + + + + diff -r e22b091498e4 -r 5e7477b94d94 src/MPipeline2/src/mpipeline/ltpdapreferences/RepositoryPrefGroupPanel.java --- a/src/MPipeline2/src/mpipeline/ltpdapreferences/RepositoryPrefGroupPanel.java Mon Dec 05 16:20:06 2011 +0100 +++ b/src/MPipeline2/src/mpipeline/ltpdapreferences/RepositoryPrefGroupPanel.java Mon Dec 05 16:20:06 2011 +0100 @@ -10,18 +10,32 @@ */ package mpipeline.ltpdapreferences; +import java.awt.Component; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.util.ArrayList; import java.util.Observable; import java.util.Observer; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; +import javax.swing.event.TableModelListener; +import javax.swing.event.TableModelEvent; +import javax.swing.JTable; +import javax.swing.table.DefaultTableModel; +import javax.swing.table.DefaultTableCellRenderer; + +class CellRenderer extends DefaultTableCellRenderer { + @Override + public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { + return super.getTableCellRendererComponent(table, value, isSelected, false, row, column); + } +} /** * * @author hewitson */ -public class RepositoryPrefGroupPanel extends javax.swing.JPanel implements Observer, ChangeListener, ActionListener { +public class RepositoryPrefGroupPanel extends javax.swing.JPanel implements Observer, ChangeListener, ActionListener, TableModelListener { private RepositoryPrefGroup repoPrefs; @@ -29,19 +43,22 @@ public RepositoryPrefGroupPanel(RepositoryPrefGroup repoPrefs) { this.repoPrefs = repoPrefs; initComponents(); - + databasesTable.setDefaultRenderer(Object.class, new CellRenderer()); + setPreferences(); repoPrefs.addObserver(this); maxConnectionsNumberSpinner.addChangeListener(this); cachePasswordComboBox.addActionListener(this); expirySpinner.addChangeListener(this); + databasesTable.getModel().addTableModelListener(this); } public void setPreferences() { updateMaxConnectionsNumber(); updateCachePasswords(); updateExpiry(); + updateRepositories(); } /** This method is called from within the constructor to @@ -50,74 +67,154 @@ * always regenerated by the Form Editor. */ @SuppressWarnings("unchecked") - // //GEN-BEGIN:initComponents - private void initComponents() { + // //GEN-BEGIN:initComponents + private void initComponents() { + + jLabel3 = new javax.swing.JLabel(); + expirySpinner = new javax.swing.JSpinner(); + jLabel1 = new javax.swing.JLabel(); + jLabel2 = new javax.swing.JLabel(); + maxConnectionsNumberSpinner = new javax.swing.JSpinner(); + cachePasswordComboBox = new javax.swing.JComboBox(); + jLabel4 = new javax.swing.JLabel(); + scrollPane = new javax.swing.JScrollPane(); + databasesTable = new javax.swing.JTable(); + jLabel5 = new javax.swing.JLabel(); + addButton = new javax.swing.JButton(); + removeButton = new javax.swing.JButton(); - jLabel3 = new javax.swing.JLabel(); - expirySpinner = new javax.swing.JSpinner(); - jLabel1 = new javax.swing.JLabel(); - jLabel2 = new javax.swing.JLabel(); - maxConnectionsNumberSpinner = new javax.swing.JSpinner(); - cachePasswordComboBox = new javax.swing.JComboBox(); - jLabel4 = new javax.swing.JLabel(); + jLabel3.setText("Cached passwords expire after:"); + + expirySpinner.setModel(new javax.swing.SpinnerNumberModel(0, 0, 10000000, 10)); + + jLabel1.setText("Maximum number of simultaneous database connections:"); + + jLabel2.setText("Cache password:"); + + maxConnectionsNumberSpinner.setModel(new javax.swing.SpinnerNumberModel(Integer.valueOf(1), Integer.valueOf(1), null, Integer.valueOf(1))); + + cachePasswordComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "No", "Yes", "Ask" })); + + jLabel4.setText("[seconds]"); + + databasesTable.setModel(new javax.swing.table.DefaultTableModel( + new Object [][] { - jLabel3.setText("Cached passwords expire after:"); + }, + new String [] { + "Hostname", "Database", "Username" + } + ) { + Class[] types = new Class [] { + java.lang.String.class, java.lang.String.class, java.lang.String.class + }; + boolean[] canEdit = new boolean [] { + false, false, false + }; - expirySpinner.setModel(new javax.swing.SpinnerNumberModel(0, 0, 10000000, 10)); - - jLabel1.setText("Maximum number of simultaneous database connections:"); + public Class getColumnClass(int columnIndex) { + return types [columnIndex]; + } - jLabel2.setText("Cache password:"); - - maxConnectionsNumberSpinner.setModel(new javax.swing.SpinnerNumberModel(Integer.valueOf(1), Integer.valueOf(1), null, Integer.valueOf(1))); + public boolean isCellEditable(int rowIndex, int columnIndex) { + return canEdit [columnIndex]; + } + }); + databasesTable.setGridColor(new java.awt.Color(204, 204, 204)); + databasesTable.setIntercellSpacing(new java.awt.Dimension(0, 0)); + databasesTable.setRowHeight(24); + databasesTable.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION); + databasesTable.setShowVerticalLines(false); + scrollPane.setViewportView(databasesTable); - cachePasswordComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "No", "Yes", "Ask" })); + jLabel5.setText("Repositories:"); - jLabel4.setText("[seconds]"); + addButton.setText("Add"); + addButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + addButtonActionPerformed(evt); + } + }); - org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this); - this.setLayout(layout); - layout.setHorizontalGroup( - layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) - .add(layout.createSequentialGroup() - .addContainerGap() - .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) - .add(layout.createSequentialGroup() - .add(jLabel1) - .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) - .add(maxConnectionsNumberSpinner, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 48, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) - .add(layout.createSequentialGroup() - .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false) - .add(org.jdesktop.layout.GroupLayout.LEADING, layout.createSequentialGroup() - .add(jLabel2) - .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) - .add(cachePasswordComboBox, 0, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - .add(org.jdesktop.layout.GroupLayout.LEADING, jLabel3)) - .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) - .add(expirySpinner, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 59, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) - .add(jLabel4))) - .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - ); - layout.setVerticalGroup( - layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) - .add(layout.createSequentialGroup() - .addContainerGap() - .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) - .add(jLabel1) - .add(maxConnectionsNumberSpinner, 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(jLabel2) - .add(cachePasswordComboBox, 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(jLabel3) - .add(expirySpinner, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) - .add(jLabel4)) - .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - ); - }// //GEN-END:initComponents + removeButton.setText("Remove"); + removeButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + removeButtonActionPerformed(evt); + } + }); + + org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this); + this.setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(layout.createSequentialGroup() + .addContainerGap() + .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(scrollPane, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 422, Short.MAX_VALUE) + .add(layout.createSequentialGroup() + .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false) + .add(org.jdesktop.layout.GroupLayout.LEADING, layout.createSequentialGroup() + .add(jLabel2) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) + .add(cachePasswordComboBox, 0, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .add(org.jdesktop.layout.GroupLayout.LEADING, jLabel3)) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) + .add(expirySpinner, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 76, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) + .add(jLabel4)) + .add(jLabel5) + .add(layout.createSequentialGroup() + .add(addButton) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) + .add(removeButton)) + .add(layout.createSequentialGroup() + .add(jLabel1) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) + .add(maxConnectionsNumberSpinner, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 48, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))) + .addContainerGap()) + ); + layout.setVerticalGroup( + layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(layout.createSequentialGroup() + .addContainerGap() + .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) + .add(jLabel1) + .add(maxConnectionsNumberSpinner, 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(jLabel2) + .add(cachePasswordComboBox, 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(jLabel3) + .add(expirySpinner, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) + .add(jLabel4)) + .add(18, 18, 18) + .add(jLabel5) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) + .add(scrollPane, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 152, Short.MAX_VALUE) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) + .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) + .add(addButton) + .add(removeButton)) + .addContainerGap()) + ); + }// //GEN-END:initComponents + +private void addButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addButtonActionPerformed + DefaultTableModel model = (DefaultTableModel) databasesTable.getModel(); + RepositoryDialog dialog = new RepositoryDialog(javax.swing.SwingUtilities.windowForComponent(this), model); + dialog.setVisible(true); + if (! dialog.cancelled) + model.insertRow(model.getRowCount(), new Object[]{dialog.hostname, dialog.database, dialog.username}); +}//GEN-LAST:event_addButtonActionPerformed + +private void removeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeButtonActionPerformed + DefaultTableModel model = (DefaultTableModel) databasesTable.getModel(); + int selected = databasesTable.getSelectedRow(); + if (selected > -1) + model.removeRow(selected); +}//GEN-LAST:event_removeButtonActionPerformed public void update(Observable o, Object arg) { if (arg != null) { @@ -133,8 +230,6 @@ case RepositoryPrefGroup.REPOSITORY_CACHE_PASSWORD_CHANGED: updateCachePasswords(); break; - default: - System.err.println("Unknown observation argument: " + arg.toString()); } } } @@ -152,6 +247,14 @@ expirySpinner.setValue(repoPrefs.getExpiry()); } + private void updateRepositories() { + DefaultTableModel model = (DefaultTableModel) databasesTable.getModel(); + ArrayList repos = repoPrefs.getRepositories(); + for (String[] repo : repos) { + model.insertRow(model.getRowCount(), repo); + } + } + public void stateChanged(ChangeEvent e) { if (e.getSource() == expirySpinner) { repoPrefs.setExpiry((Integer) expirySpinner.getValue()); @@ -169,13 +272,35 @@ return; } } - // Variables declaration - do not modify//GEN-BEGIN:variables - private javax.swing.JComboBox cachePasswordComboBox; - private javax.swing.JSpinner expirySpinner; - private javax.swing.JLabel jLabel1; - private javax.swing.JLabel jLabel2; - private javax.swing.JLabel jLabel3; - private javax.swing.JLabel jLabel4; - private javax.swing.JSpinner maxConnectionsNumberSpinner; - // End of variables declaration//GEN-END:variables + + public void tableChanged(TableModelEvent e) { + + + if (e.getSource() == databasesTable.getModel()) { + DefaultTableModel model = (DefaultTableModel) databasesTable.getModel(); + int rows = model.getRowCount(); + ArrayList value = new ArrayList(rows); + for (int i = 0; i < rows; i++) + value.add(new String[]{(String) model.getValueAt(i, 0), + (String) model.getValueAt(i, 1), + (String) model.getValueAt(i, 2)}); + repoPrefs.setRepositories(value); + return; + } + } + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JButton addButton; + private javax.swing.JComboBox cachePasswordComboBox; + private javax.swing.JTable databasesTable; + private javax.swing.JSpinner expirySpinner; + private javax.swing.JLabel jLabel1; + private javax.swing.JLabel jLabel2; + private javax.swing.JLabel jLabel3; + private javax.swing.JLabel jLabel4; + private javax.swing.JLabel jLabel5; + private javax.swing.JSpinner maxConnectionsNumberSpinner; + private javax.swing.JButton removeButton; + private javax.swing.JScrollPane scrollPane; + // End of variables declaration//GEN-END:variables }