Mercurial > hg > ltpda
changeset 33:5e7477b94d94 database-connection-manager
Add known repositories list to LTPDAPreferences
author | Daniele Nicolodi <nicolodi@science.unitn.it> |
---|---|
date | Mon, 05 Dec 2011 16:20:06 +0100 |
parents | e22b091498e4 |
children | 03d92954b939 |
files | m-toolbox/classes/@LTPDADatabaseConnectionManager/LTPDADatabaseConnectionManager.m src/MPipeline2/src/mpipeline/ltpdapreferences/RepositoryDialog.form src/MPipeline2/src/mpipeline/ltpdapreferences/RepositoryDialog.java src/MPipeline2/src/mpipeline/ltpdapreferences/RepositoryPrefGroup.java src/MPipeline2/src/mpipeline/ltpdapreferences/RepositoryPrefGroupPanel.form src/MPipeline2/src/mpipeline/ltpdapreferences/RepositoryPrefGroupPanel.java |
diffstat | 6 files changed, 708 insertions(+), 101 deletions(-) [+] |
line wrap: on
line diff
--- 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. %
--- /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 @@ +<?xml version="1.1" encoding="UTF-8" ?> + +<Form version="1.3" maxVersion="1.7" type="org.netbeans.modules.form.forminfo.JDialogFormInfo"> + <Properties> + <Property name="title" type="java.lang.String" value="Database 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"> + <Group type="102" alignment="0" attributes="0"> + <Component id="jLabel9" min="-2" max="-2" attributes="0"/> + <EmptySpace min="-2" pref="18" max="-2" attributes="0"/> + <Component id="hostnameCombo" pref="240" max="32767" attributes="0"/> + </Group> + <Group type="102" alignment="1" attributes="0"> + <Component id="jLabel10" min="-2" max="-2" attributes="0"/> + <EmptySpace min="-2" pref="21" max="-2" attributes="0"/> + <Component id="databaseCombo" pref="240" max="32767" attributes="0"/> + </Group> + <Group type="102" alignment="1" attributes="0"> + <Component id="cancelButton" min="-2" max="-2" attributes="0"/> + <EmptySpace max="-2" attributes="0"/> + <Component id="okButton" min="-2" max="-2" attributes="0"/> + </Group> + <Group type="102" alignment="0" attributes="0"> + <Component id="jLabel11" min="-2" max="-2" attributes="0"/> + <EmptySpace type="separate" max="-2" attributes="0"/> + <Component id="usernameCombo" pref="240" max="32767" attributes="0"/> + </Group> + </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="hostnameCombo" alignment="3" min="-2" max="-2" attributes="0"/> + <Component id="jLabel9" 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="databaseCombo" alignment="3" min="-2" max="-2" attributes="0"/> + <Component id="jLabel10" 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="jLabel11" alignment="3" min="-2" max="-2" attributes="0"/> + <Component id="usernameCombo" alignment="3" min="-2" max="-2" attributes="0"/> + </Group> + <Group type="103" groupAlignment="0" attributes="0"> + <Group type="102" attributes="0"> + <EmptySpace pref="12" max="32767" attributes="0"/> + <Component id="okButton" min="-2" max="-2" attributes="0"/> + <EmptySpace max="-2" attributes="0"/> + </Group> + <Group type="102" alignment="0" attributes="0"> + <EmptySpace type="unrelated" max="-2" attributes="0"/> + <Component id="cancelButton" min="-2" max="-2" attributes="0"/> + <EmptySpace max="-2" attributes="0"/> + </Group> + </Group> + </Group> + </Group> + </DimensionLayout> + </Layout> + <SubComponents> + <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.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="jLabel11"> + <Properties> + <Property name="horizontalAlignment" type="int" value="4"/> + <Property name="text" type="java.lang.String" value="Username:"/> + </Properties> + </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> + </Component> + <Component class="javax.swing.JComboBox" name="hostnameCombo"> + <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="hostnameComboActionPerformed"/> + </Events> + </Component> + <Component class="javax.swing.JComboBox" name="usernameCombo"> + <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> + </Component> + <Component class="javax.swing.JButton" name="okButton"> + <Properties> + <Property name="text" type="java.lang.String" value="Ok"/> + </Properties> + <Events> + <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="okButtonActionPerformed"/> + </Events> + </Component> + <Component class="javax.swing.JButton" name="cancelButton"> + <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="cancelButtonActionPerformed"/> + </Events> + </Component> + </SubComponents> +</Form>
--- /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") + // <editor-fold defaultstate="collapsed" desc="Generated Code">//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(); + }// </editor-fold>//GEN-END:initComponents + + private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed + cancelled = true; + doClose(); + }//GEN-LAST:event_cancelButtonActionPerformed + + private void 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<String> hostnames = new HashSet<String>(); + 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<String> databases = new HashSet<String>(); + 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<String> usernames = new HashSet<String>(); + 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 +}
--- 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<String[]> repositories = new ArrayList<String[]>(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<String[]> getRepositories() { + return repositories; } - public void setMaxConnectionsNumber(Integer value) { - maxConnectionsNumber = value; - setChanged(); - notifyObservers(REPOSITORY_MAX_CONNECTIONS_NUMBER_CHANGED); - } - - // for backward compatibility - public ArrayList<String> getHostnames() { - return new ArrayList<String>(); + public void setRepositories(ArrayList<String[]> value) { + repositories.clear(); + for (String[] repo : value) { + repositories.add(repo); + } + setChanged(); } public void display() {
--- 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 @@ <?xml version="1.1" encoding="UTF-8" ?> -<Form version="1.5" maxVersion="1.7" type="org.netbeans.modules.form.forminfo.JPanelFormInfo"> +<Form version="1.6" maxVersion="1.7" type="org.netbeans.modules.form.forminfo.JPanelFormInfo"> <AuxValues> <AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/> <AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/> @@ -19,11 +19,7 @@ <Group type="102" attributes="0"> <EmptySpace max="-2" attributes="0"/> <Group type="103" groupAlignment="0" attributes="0"> - <Group type="102" alignment="0" attributes="0"> - <Component id="jLabel1" min="-2" max="-2" attributes="0"/> - <EmptySpace max="-2" attributes="0"/> - <Component id="maxConnectionsNumberSpinner" min="-2" pref="48" max="-2" attributes="1"/> - </Group> + <Component id="scrollPane" alignment="0" pref="422" max="32767" attributes="0"/> <Group type="102" alignment="0" attributes="0"> <Group type="103" groupAlignment="1" max="-2" attributes="0"> <Group type="102" alignment="0" attributes="1"> @@ -34,12 +30,23 @@ <Component id="jLabel3" alignment="0" min="-2" max="-2" attributes="0"/> </Group> <EmptySpace max="-2" attributes="0"/> - <Component id="expirySpinner" min="-2" pref="59" max="-2" attributes="1"/> + <Component id="expirySpinner" min="-2" pref="76" max="-2" attributes="1"/> <EmptySpace max="-2" attributes="0"/> <Component id="jLabel4" min="-2" max="-2" attributes="0"/> </Group> + <Component id="jLabel5" alignment="0" min="-2" max="-2" attributes="0"/> + <Group type="102" alignment="0" attributes="0"> + <Component id="addButton" min="-2" max="-2" attributes="0"/> + <EmptySpace max="-2" attributes="0"/> + <Component id="removeButton" min="-2" max="-2" attributes="0"/> + </Group> + <Group type="102" alignment="0" attributes="0"> + <Component id="jLabel1" min="-2" max="-2" attributes="0"/> + <EmptySpace max="-2" attributes="0"/> + <Component id="maxConnectionsNumberSpinner" min="-2" pref="48" max="-2" attributes="1"/> + </Group> </Group> - <EmptySpace max="32767" attributes="0"/> + <EmptySpace max="-2" attributes="0"/> </Group> </Group> </DimensionLayout> @@ -51,7 +58,7 @@ <Component id="jLabel1" alignment="3" min="-2" max="-2" attributes="0"/> <Component id="maxConnectionsNumberSpinner" alignment="3" min="-2" max="-2" attributes="0"/> </Group> - <EmptySpace type="unrelated" max="-2" attributes="0"/> + <EmptySpace max="-2" attributes="0"/> <Group type="103" groupAlignment="3" attributes="0"> <Component id="jLabel2" alignment="3" min="-2" max="-2" attributes="0"/> <Component id="cachePasswordComboBox" alignment="3" min="-2" max="-2" attributes="0"/> @@ -62,7 +69,16 @@ <Component id="expirySpinner" alignment="3" min="-2" max="-2" attributes="0"/> <Component id="jLabel4" alignment="3" min="-2" max="-2" attributes="0"/> </Group> - <EmptySpace max="32767" attributes="0"/> + <EmptySpace type="separate" max="-2" attributes="0"/> + <Component id="jLabel5" min="-2" max="-2" attributes="0"/> + <EmptySpace max="-2" attributes="0"/> + <Component id="scrollPane" pref="152" max="32767" attributes="0"/> + <EmptySpace max="-2" attributes="0"/> + <Group type="103" groupAlignment="3" attributes="0"> + <Component id="addButton" alignment="3" min="-2" max="-2" attributes="0"/> + <Component id="removeButton" alignment="3" min="-2" max="-2" attributes="0"/> + </Group> + <EmptySpace max="-2" attributes="0"/> </Group> </Group> </DimensionLayout> @@ -113,5 +129,57 @@ <Property name="text" type="java.lang.String" value="[seconds]"/> </Properties> </Component> + <Container class="javax.swing.JScrollPane" name="scrollPane"> + <AuxValues> + <AuxValue name="autoScrollPane" type="java.lang.Boolean" value="true"/> + </AuxValues> + + <Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/> + <SubComponents> + <Component class="javax.swing.JTable" name="databasesTable"> + <Properties> + <Property name="model" type="javax.swing.table.TableModel" editor="org.netbeans.modules.form.editors2.TableModelEditor"> + <Table columnCount="3" rowCount="0"> + <Column editable="false" title="Hostname" type="java.lang.String"/> + <Column editable="false" title="Database" type="java.lang.String"/> + <Column editable="false" title="Username" type="java.lang.String"/> + </Table> + </Property> + <Property name="gridColor" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor"> + <Color blue="cc" green="cc" red="cc" type="rgb"/> + </Property> + <Property name="intercellSpacing" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor"> + <Dimension value="[0, 0]"/> + </Property> + <Property name="rowHeight" type="int" value="24"/> + <Property name="selectionModel" type="javax.swing.ListSelectionModel" editor="org.netbeans.modules.form.editors2.JTableSelectionModelEditor"> + <JTableSelectionModel selectionMode="0"/> + </Property> + <Property name="showVerticalLines" type="boolean" value="false"/> + </Properties> + </Component> + </SubComponents> + </Container> + <Component class="javax.swing.JLabel" name="jLabel5"> + <Properties> + <Property name="text" type="java.lang.String" value="Repositories:"/> + </Properties> + </Component> + <Component class="javax.swing.JButton" name="addButton"> + <Properties> + <Property name="text" type="java.lang.String" value="Add"/> + </Properties> + <Events> + <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="addButtonActionPerformed"/> + </Events> + </Component> + <Component class="javax.swing.JButton" name="removeButton"> + <Properties> + <Property name="text" type="java.lang.String" value="Remove"/> + </Properties> + <Events> + <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="removeButtonActionPerformed"/> + </Events> + </Component> </SubComponents> </Form>
--- 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") - // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents - private void initComponents() { + // <editor-fold defaultstate="collapsed" desc="Generated Code">//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)) - ); - }// </editor-fold>//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()) + ); + }// </editor-fold>//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<String[]> 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<String[]> value = new ArrayList<String[]>(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 }