# HG changeset patch # User Daniele Nicolodi # Date 1323098406 -3600 # Node ID 5a49956df427a76c329bddb0a46d2762225890f7 # Parent e3c5468b1bfeded62ef038875e0821cf4460fafc LTPDAPreferences panel for new LTPDADatabaseConnectionManager diff -r e3c5468b1bfe -r 5a49956df427 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 @@ -5,15 +5,11 @@ package mpipeline.ltpdapreferences; import java.util.ArrayList; -import java.util.Arrays; -import java.util.Iterator; import mpipeline.utils.MXMLUtils; -import mpipeline.utils.Utils; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; -import org.w3c.dom.NodeList; /** * @@ -26,7 +22,6 @@ public static final int REPOSITORY_CACHE_PASSWORD_CHANGED = 3; public static final int REPOSITORY_MAX_CONNECTIONS_NUMBER_CHANGED = 4; - private ArrayList hostnames = new ArrayList(); private Integer expiry = 60; private Integer cachePassword = 2; private Integer maxConnectionsNumber = 10; @@ -38,45 +33,21 @@ NamedNodeMap nmap = node.getAttributes(); expiry = MXMLUtils.getIntegerFromNode("expiry", nmap, version, version); - - NodeList nl = node.getChildNodes(); - for (int ii = 0; ii < nl.getLength(); ii++) { - Node n = nl.item(ii); - Utils.dmsg(" reading child node: " + n.getNodeName()); - if (n.getNodeName().equals("Hostname")) { - NamedNodeMap wbnm = n.getAttributes(); - String path = MXMLUtils.getStringFromNode("Host", wbnm, version, version); - this.addHostname(path); - } - } + cachePassword = MXMLUtils.getIntegerFromNode("cachePassword", nmap, version, version); + if (cachePassword < 0) + cachePassword = 2; + maxConnectionsNumber = MXMLUtils.getIntegerFromNode("maxConnectionsNumber", nmap, version, version); + if (maxConnectionsNumber < 0) + maxConnectionsNumber = 10; } public void attachToDom(Document doc, Element tnode) { Element pnode = doc.createElement("Repository"); - pnode.setAttribute("expiry", ""+expiry); - - Iterator it = hostnames.iterator(); - while (it.hasNext()) { - String path = (String) it.next(); - Element snode = doc.createElement("Hostname"); - snode.setAttribute("Host", path); - pnode.appendChild(snode); - } - + pnode.setAttribute("cachePassword", ""+cachePassword); + pnode.setAttribute("maxConnectionsNumber", ""+maxConnectionsNumber); tnode.appendChild(pnode); - - } - - public void addHostname(String host) { - hostnames.add(host); - this.setChanged(); - this.notifyObservers(REPOSITORY_HOSTNAMES_CHANGED); - } - - public ArrayList getHostnames() { - return hostnames; } public Integer getExpiry() { @@ -88,18 +59,6 @@ setChanged(); notifyObservers(REPOSITORY_EXPIRY_CHANGED); } - - public void setHostnames(ArrayList hostnames) { - this.hostnames = hostnames; - setChanged(); - notifyObservers(REPOSITORY_HOSTNAMES_CHANGED); - } - - public void removeHostnames(Object objs[]) { - hostnames.removeAll(Arrays.asList(objs)); - this.setChanged(); - this.notifyObservers(REPOSITORY_HOSTNAMES_CHANGED); - } public Integer getCachePassword() { return cachePassword; @@ -121,6 +80,11 @@ notifyObservers(REPOSITORY_MAX_CONNECTIONS_NUMBER_CHANGED); } + // for backward compatibility + public ArrayList getHostnames() { + return new ArrayList(); + } + public void display() { System.out.printf( "RepositoryPrefGroup(expiry=%d, cachePassword=%d, maxConnectionsNumber=%d)\n", diff -r e3c5468b1bfe -r 5a49956df427 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 @@ -16,30 +16,30 @@ - + - - - - - - - - + + + + + + + + + + - + - - - - - + - - + + + + - + @@ -47,23 +47,20 @@ - + + + + - - - - - - - - + + + - - - - - - + + + + + @@ -71,63 +68,9 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + @@ -137,5 +80,38 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -r e3c5468b1bfe -r 5a49956df427 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 @@ -12,13 +12,8 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; -import java.util.Arrays; -import java.util.Collection; -import java.util.Iterator; -import java.util.List; import java.util.Observable; import java.util.Observer; -import javax.swing.DefaultListModel; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; @@ -35,17 +30,17 @@ this.repoPrefs = repoPrefs; initComponents(); - DefaultListModel mdl = new DefaultListModel(); - hostnameList.setModel(mdl); setPreferences(); repoPrefs.addObserver(this); + maxConnectionsNumberSpinner.addChangeListener(this); + cachePasswordComboBox.addActionListener(this); expirySpinner.addChangeListener(this); - } public void setPreferences() { - updateHostnames(); + updateMaxConnectionsNumber(); + updateCachePasswords(); updateExpiry(); } @@ -55,157 +50,132 @@ * always regenerated by the Form Editor. */ @SuppressWarnings("unchecked") - // //GEN-BEGIN:initComponents - private void initComponents() { + // //GEN-BEGIN:initComponents + private void initComponents() { - jScrollPane1 = new javax.swing.JScrollPane(); - hostnameList = new javax.swing.JList(); - newHostnameTextField = new javax.swing.JTextField(); - jLabel1 = new javax.swing.JLabel(); - addBtn = new javax.swing.JButton(); - removeBtn = new javax.swing.JButton(); - jLabel2 = new javax.swing.JLabel(); - jLabel3 = new javax.swing.JLabel(); - expirySpinner = new javax.swing.JSpinner(); - - jScrollPane1.setViewportView(hostnameList); - - jLabel1.setText("New Hostname:"); + 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(); - addBtn.setIcon(new javax.swing.ImageIcon(getClass().getResource("/mpipeline/icons/add_small.png"))); // NOI18N - addBtn.setRolloverEnabled(true); - addBtn.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/mpipeline/icons/add_small_ro.png"))); // NOI18N - addBtn.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - addBtnActionPerformed(evt); - } - }); + jLabel3.setText("Cached passwords expire after:"); + + expirySpinner.setModel(new javax.swing.SpinnerNumberModel(0, 0, 10000000, 10)); + + jLabel1.setText("Maximum number of simultaneous database connections:"); - removeBtn.setIcon(new javax.swing.ImageIcon(getClass().getResource("/mpipeline/icons/subtract_small.png"))); // NOI18N - removeBtn.setRolloverEnabled(true); - removeBtn.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/mpipeline/icons/subtract_small_ro.png"))); // NOI18N - removeBtn.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - removeBtnActionPerformed(evt); - } - }); + jLabel2.setText("Cache password:"); + + maxConnectionsNumberSpinner.setModel(new javax.swing.SpinnerNumberModel(Integer.valueOf(1), Integer.valueOf(1), null, Integer.valueOf(1))); - jLabel2.setText("User-defined LTPDA Repository Hostnames"); + cachePasswordComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "No", "Yes", "Ask" })); - jLabel3.setText("Repository Login Expiry (s):"); - - expirySpinner.setModel(new javax.swing.SpinnerNumberModel(0, 0, 10000000, 10)); + jLabel4.setText("[seconds]"); - org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this); - this.setLayout(layout); - layout.setHorizontalGroup( - layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) - .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup() - .addContainerGap() - .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING) - .add(removeBtn) - .add(org.jdesktop.layout.GroupLayout.LEADING, jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 372, Short.MAX_VALUE) - .add(org.jdesktop.layout.GroupLayout.LEADING, jLabel2) - .add(layout.createSequentialGroup() - .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING) - .add(layout.createSequentialGroup() - .add(jLabel3) - .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) - .add(expirySpinner)) - .add(layout.createSequentialGroup() - .add(jLabel1) - .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) - .add(newHostnameTextField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 222, Short.MAX_VALUE))) - .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED) - .add(addBtn))) - .addContainerGap()) - ); - layout.setVerticalGroup( - layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) - .add(layout.createSequentialGroup() - .addContainerGap() - .add(jLabel2) - .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED) - .add(jScrollPane1, 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.LEADING) - .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) - .add(jLabel1) - .add(newHostnameTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) - .add(addBtn)) - .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) - .add(removeBtn) - .add(10, 10, 10) - .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.CENTER) - .add(jLabel3) - .add(expirySpinner, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) - .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - ); - }// //GEN-END:initComponents - - private void removeBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeBtnActionPerformed - // get selected index - Object objs[] = hostnameList.getSelectedValues(); - repoPrefs.removeHostnames(objs); - }//GEN-LAST:event_removeBtnActionPerformed - - private void addBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addBtnActionPerformed - - if (newHostnameTextField.getText().length() != 0) { - repoPrefs.addHostname(newHostnameTextField.getText()); - } - }//GEN-LAST:event_addBtnActionPerformed + 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 public void update(Observable o, Object arg) { if (arg != null) { - if (arg instanceof Integer) { int identifier = ((Integer) arg).intValue(); - - if (identifier == RepositoryPrefGroup.REPOSITORY_EXPIRY_CHANGED) { - updateExpiry(); - } - else if (identifier == RepositoryPrefGroup.REPOSITORY_HOSTNAMES_CHANGED) { - updateHostnames(); - } - else { - System.err.println("Unknown observation argument: " + arg.toString()); + switch (identifier) { + case RepositoryPrefGroup.REPOSITORY_EXPIRY_CHANGED: + updateExpiry(); + break; + case RepositoryPrefGroup.REPOSITORY_MAX_CONNECTIONS_NUMBER_CHANGED: + updateMaxConnectionsNumber(); + break; + case RepositoryPrefGroup.REPOSITORY_CACHE_PASSWORD_CHANGED: + updateCachePasswords(); + break; + default: + System.err.println("Unknown observation argument: " + arg.toString()); } } } } + private void updateMaxConnectionsNumber() { + maxConnectionsNumberSpinner.setValue(repoPrefs.getMaxConnectionsNumber()); + } + + private void updateCachePasswords() { + cachePasswordComboBox.setSelectedIndex(repoPrefs.getCachePassword().intValue()); + } + private void updateExpiry() { expirySpinner.setValue(repoPrefs.getExpiry()); } - private void updateHostnames() { - DefaultListModel mmdl = (DefaultListModel) hostnameList.getModel(); - mmdl.removeAllElements(); - Iterator it = repoPrefs.getHostnames().iterator(); - while (it.hasNext()) { - String path = (String) it.next(); - mmdl.addElement(path); - } - } - public void stateChanged(ChangeEvent e) { if (e.getSource() == expirySpinner) { repoPrefs.setExpiry((Integer) expirySpinner.getValue()); + return; + } + if (e.getSource() == maxConnectionsNumberSpinner) { + repoPrefs.setMaxConnectionsNumber((Integer) maxConnectionsNumberSpinner.getValue()); + return; } } public void actionPerformed(ActionEvent e) { + if (e.getSource() == cachePasswordComboBox) { + repoPrefs.setCachePassword((Integer) cachePasswordComboBox.getSelectedIndex()); + return; + } } - // Variables declaration - do not modify//GEN-BEGIN:variables - private javax.swing.JButton addBtn; - private javax.swing.JSpinner expirySpinner; - private javax.swing.JList hostnameList; - private javax.swing.JLabel jLabel1; - private javax.swing.JLabel jLabel2; - private javax.swing.JLabel jLabel3; - private javax.swing.JScrollPane jScrollPane1; - private javax.swing.JTextField newHostnameTextField; - private javax.swing.JButton removeBtn; - // End of variables declaration//GEN-END:variables + // 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 } diff -r e3c5468b1bfe -r 5a49956df427 src/MPipeline2/src/mpipeline/plisttable/JPlist.java --- a/src/MPipeline2/src/mpipeline/plisttable/JPlist.java Mon Dec 05 16:20:06 2011 +0100 +++ b/src/MPipeline2/src/mpipeline/plisttable/JPlist.java Mon Dec 05 16:20:06 2011 +0100 @@ -564,22 +564,6 @@ String defaultWin = ltpdaPreferences2.getMiscPrefs().getDefaultWindow(); p.setDefaultVal(defaultWin); } - else if (p.getKey().equalsIgnoreCase("HOSTNAME")) { - - Object currentHostname = p.getDefaultVal(); - p.getVal().clearOptions(); - // Get hostnames from the preferences - ArrayList prefsHosts = ltpdaPreferences2.getRepoPrefs().getHostnames(); - // Add this hostnames to the options of the param object - for (int i = 0; i < prefsHosts.size(); i++) { - p.addOption(prefsHosts.get(i), "char"); - } - p.setDefaultVal(currentHostname); - - if (p.getOptions().isEmpty()) { - p.addOption("", "char"); - } - } } } }