Cleaning up
diff --git a/credential-manager-ui/src/main/java/net/sf/taverna/t2/workbench/ui/credentialmanager/CMStrings.java b/credential-manager-ui/src/main/java/net/sf/taverna/t2/workbench/ui/credentialmanager/CMStrings.java
new file mode 100644
index 0000000..3f6664c
--- /dev/null
+++ b/credential-manager-ui/src/main/java/net/sf/taverna/t2/workbench/ui/credentialmanager/CMStrings.java
@@ -0,0 +1,7 @@
+package net.sf.taverna.t2.workbench.ui.credentialmanager;
+
+interface CMStrings {
+	String ALERT_TITLE = "Credential Manager Alert";
+	String ERROR_TITLE = "Credential Manager Error";
+	String WARN_TITLE = "Credential Manager Warning";
+}
diff --git a/credential-manager-ui/src/main/java/net/sf/taverna/t2/workbench/ui/credentialmanager/ChangeMasterPasswordDialog.java b/credential-manager-ui/src/main/java/net/sf/taverna/t2/workbench/ui/credentialmanager/ChangeMasterPasswordDialog.java
index 73d1f95..26086bc 100644
--- a/credential-manager-ui/src/main/java/net/sf/taverna/t2/workbench/ui/credentialmanager/ChangeMasterPasswordDialog.java
+++ b/credential-manager-ui/src/main/java/net/sf/taverna/t2/workbench/ui/credentialmanager/ChangeMasterPasswordDialog.java
@@ -20,6 +20,15 @@
  ******************************************************************************/
 package net.sf.taverna.t2.workbench.ui.credentialmanager;
 
+import static java.awt.BorderLayout.CENTER;
+import static java.awt.BorderLayout.NORTH;
+import static java.awt.BorderLayout.SOUTH;
+import static java.awt.Font.PLAIN;
+import static javax.swing.BoxLayout.Y_AXIS;
+import static javax.swing.JOptionPane.WARNING_MESSAGE;
+import static javax.swing.JOptionPane.showMessageDialog;
+import static net.sf.taverna.t2.workbench.ui.credentialmanager.CMStrings.WARN_TITLE;
+
 import java.awt.BorderLayout;
 import java.awt.FlowLayout;
 import java.awt.Font;
@@ -33,7 +42,6 @@
 import javax.swing.JButton;
 import javax.swing.JFrame;
 import javax.swing.JLabel;
-import javax.swing.JOptionPane;
 import javax.swing.JPanel;
 import javax.swing.JPasswordField;
 import javax.swing.border.CompoundBorder;
@@ -44,204 +52,183 @@
 import net.sf.taverna.t2.workbench.helper.NonBlockedHelpEnabledDialog;
 
 /**
- * Dialog used by users to change their
- * master password for the Credential Manager.
+ * Dialog used by users to change their master password for the Credential
+ * Manager.
  */
 @SuppressWarnings("serial")
 public class ChangeMasterPasswordDialog extends NonBlockedHelpEnabledDialog {
-
-    // Old password entry field
-    private JPasswordField oldPasswordField;
-
-    // New password entry field
-    private JPasswordField newPasswordField;
-
-    // New password confirmation entry field
-    private JPasswordField newPasswordConfirmField;
-
-    // The entered new password
-    private String password = null;
-
-    // Instructions to the users as to what to do in the dialog
-    private String instructions;
-
+	/** Old password entry field */
+	private JPasswordField oldPasswordField;
+	/** New password entry field */
+	private JPasswordField newPasswordField;
+	/** New password confirmation entry field */
+	private JPasswordField newPasswordConfirmField;
+	/** The entered new password */
+	private String password = null;
+	/** Instructions to the users as to what to do in the dialog */
+	private String instructions;
 	private final CredentialManager credentialManager;
 
 	public ChangeMasterPasswordDialog(JFrame parent, String title,
-			boolean modal, String instructions, CredentialManager credentialManager)    {
-        super(parent, title, modal, null);
-        this.instructions = instructions;
+			boolean modal, String instructions,
+			CredentialManager credentialManager) {
+		super(parent, title, modal, null);
+		this.instructions = instructions;
 		this.credentialManager = credentialManager;
-        initComponents();
-    }
+		initComponents();
+	}
 
-    private void initComponents()
-    {
-        getContentPane().setLayout(new BorderLayout());
+	private void initComponents() {
+		getContentPane().setLayout(new BorderLayout());
 
-        JLabel instructionsLabel = new JLabel (instructions);
-    	instructionsLabel.setFont(new Font(null, Font.PLAIN, 11));
+		JLabel instructionsLabel = new JLabel(instructions);
+		instructionsLabel.setFont(new Font(null, PLAIN, 11));
 
-    	JPanel instructionsPanel = new JPanel();
-    	instructionsPanel.setLayout(new BoxLayout(instructionsPanel, BoxLayout.Y_AXIS));
-    	instructionsPanel.add(instructionsLabel);
-    	instructionsPanel.setBorder(new EmptyBorder(10,5,10,0));
+		JPanel instructionsPanel = new JPanel();
+		instructionsPanel.setLayout(new BoxLayout(instructionsPanel, Y_AXIS));
+		instructionsPanel.add(instructionsLabel);
+		instructionsPanel.setBorder(new EmptyBorder(10, 5, 10, 0));
 
-        JLabel oldPasswordLabel = new JLabel("Old master password");
-        oldPasswordLabel.setBorder(new EmptyBorder(0,5,0,0));
+		JLabel oldPasswordLabel = new JLabel("Old master password");
+		oldPasswordLabel.setBorder(new EmptyBorder(0, 5, 0, 0));
 
-        JLabel newPasswordLabel = new JLabel("New master password");
-        newPasswordLabel.setBorder(new EmptyBorder(0,5,0,0));
+		JLabel newPasswordLabel = new JLabel("New master password");
+		newPasswordLabel.setBorder(new EmptyBorder(0, 5, 0, 0));
 
-        JLabel newPasswordConfirmLabel = new JLabel("Confirm new master password");
-        newPasswordConfirmLabel.setBorder(new EmptyBorder(0,5,0,0));
+		JLabel newPasswordConfirmLabel = new JLabel(
+				"Confirm new master password");
+		newPasswordConfirmLabel.setBorder(new EmptyBorder(0, 5, 0, 0));
 
-        oldPasswordField = new JPasswordField(15);
-        newPasswordField = new JPasswordField(15);
-        newPasswordConfirmField = new JPasswordField(15);
+		oldPasswordField = new JPasswordField(15);
+		newPasswordField = new JPasswordField(15);
+		newPasswordConfirmField = new JPasswordField(15);
 
-        JPanel jpPassword = new JPanel(new GridLayout(0, 2, 5, 5));
-        jpPassword.add(oldPasswordLabel);
-        jpPassword.add(oldPasswordField);
-        jpPassword.add(newPasswordLabel);
-        jpPassword.add(newPasswordField);
-        jpPassword.add(newPasswordConfirmLabel);
-        jpPassword.add(newPasswordConfirmField);
+		JPanel jpPassword = new JPanel(new GridLayout(0, 2, 5, 5));
+		jpPassword.add(oldPasswordLabel);
+		jpPassword.add(oldPasswordField);
+		jpPassword.add(newPasswordLabel);
+		jpPassword.add(newPasswordField);
+		jpPassword.add(newPasswordConfirmLabel);
+		jpPassword.add(newPasswordConfirmField);
 
-        JPanel mainPanel = new JPanel(new BorderLayout());
-        mainPanel.setBorder(new CompoundBorder(
-                new EmptyBorder(10, 10, 10, 10), new EtchedBorder()));
-        mainPanel.add(instructionsPanel, BorderLayout.NORTH);
-        mainPanel.add(jpPassword, BorderLayout.CENTER);
+		JPanel mainPanel = new JPanel(new BorderLayout());
+		mainPanel.setBorder(new CompoundBorder(new EmptyBorder(10, 10, 10, 10),
+				new EtchedBorder()));
+		mainPanel.add(instructionsPanel, NORTH);
+		mainPanel.add(jpPassword, CENTER);
 
-        JButton okButton = new JButton("OK");
-        okButton.addActionListener(new ActionListener()
-        {
-            public void actionPerformed(ActionEvent evt)
-            {
-                okPressed();
-            }
-        });
-
-        JButton cancelButton = new JButton("Cancel");
-        cancelButton.addActionListener(new ActionListener()
-        {
-            public void actionPerformed(ActionEvent evt)
-            {
-                cancelPressed();
-            }
-        });
-        JPanel buttonsPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
-        buttonsPanel.add(okButton);
-        buttonsPanel.add(cancelButton);
-
-        getContentPane().add(mainPanel, BorderLayout.CENTER);
-        getContentPane().add(buttonsPanel, BorderLayout.SOUTH);
-
-        addWindowListener(new WindowAdapter()
-        {
-            public void windowClosing(WindowEvent evt)
-            {
-                closeDialog();
-            }
-        });
-
-        setResizable(false);
-
-        getRootPane().setDefaultButton(okButton);
-
-        pack();
-    }
-
-    /**
-     * Get the password set in the dialog or null if none was set.
-     */
-    public String getPassword()
-    {
-    	return password;
-    }
-
-    /**
-     * Check that the user has provided the correct old master password,
-     * that the user has supplied the new password and confirmed it and
-     * that it is not empty. If all is OK, stores the new password in
-     * the password field.
-     *
-     */
-    private boolean checkPassword()
-    {
-    	String oldPassword = new String (oldPasswordField.getPassword());
-
-    	 if (oldPassword.length()== 0) { //old password must not be empty
-             JOptionPane.showMessageDialog(this,
-                     "You must provide your current master password",
-                     "Credential Manager Warning",
-                     JOptionPane.WARNING_MESSAGE);
-             return false;
-         }
-    	try {
-			if (!credentialManager.confirmMasterPassword(oldPassword)){
-			    JOptionPane.showMessageDialog(this,
-			            "You have provided an incorrect master password",
-			            "Credential Manager Warning",
-			            JOptionPane.WARNING_MESSAGE);
-			        return false;
+		JButton okButton = new JButton("OK");
+		okButton.addActionListener(new ActionListener() {
+			@Override
+			public void actionPerformed(ActionEvent evt) {
+				okPressed();
 			}
-		} catch (Exception e) {
-		    JOptionPane.showMessageDialog(this,
-		            "Credential Manager could not verify your current master password",
-		            "Credential Manager Warning",
-		            JOptionPane.WARNING_MESSAGE);
+		});
+
+		JButton cancelButton = new JButton("Cancel");
+		cancelButton.addActionListener(new ActionListener() {
+			@Override
+			public void actionPerformed(ActionEvent evt) {
+				cancelPressed();
+			}
+		});
+		JPanel buttonsPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
+		buttonsPanel.add(okButton);
+		buttonsPanel.add(cancelButton);
+
+		getContentPane().add(mainPanel, CENTER);
+		getContentPane().add(buttonsPanel, SOUTH);
+
+		addWindowListener(new WindowAdapter() {
+			@Override
+			public void windowClosing(WindowEvent evt) {
+				closeDialog();
+			}
+		});
+
+		setResizable(false);
+		getRootPane().setDefaultButton(okButton);
+		pack();
+	}
+
+	/**
+	 * Get the password set in the dialog or null if none was set.
+	 */
+	public String getPassword() {
+		return password;
+	}
+
+	/**
+	 * Check that the user has provided the correct old master password, that
+	 * the user has supplied the new password and confirmed it and that it is
+	 * not empty. If all is OK, stores the new password in the password field.
+	 * 
+	 */
+	private boolean checkPassword() {
+		String oldPassword = new String(oldPasswordField.getPassword());
+
+		if (oldPassword.length() == 0) {
+			// old password must not be empty
+			showMessageDialog(this,
+					"You must provide your current master password",
+					WARN_TITLE, WARNING_MESSAGE);
 			return false;
 		}
 
-        String newPassword = new String(newPasswordField.getPassword());
-        String newPasswordConfirm = new String(newPasswordConfirmField.getPassword());
+		try {
+			if (!credentialManager.confirmMasterPassword(oldPassword)) {
+				showMessageDialog(this,
+						"You have provided an incorrect master password",
+						WARN_TITLE, WARNING_MESSAGE);
+				return false;
+			}
+		} catch (Exception e) {
+			showMessageDialog(
+					this,
+					"Credential Manager could not verify your current master password",
+					WARN_TITLE, WARNING_MESSAGE);
+			return false;
+		}
 
-        if ((newPassword.equals(newPasswordConfirm)) && (newPassword.length()!= 0)) { //passwords match and not empty
-            password = newPassword;
-            return true;
-        }
-        else if ((newPassword.equals(newPasswordConfirm)) && (newPassword.length() == 0)) { //passwords match but are empty
-            JOptionPane.showMessageDialog(this,
-                    "The new master password cannot be empty",
-                    "Credential Manager Warning",
-                    JOptionPane.WARNING_MESSAGE);
+		String newPassword = new String(newPasswordField.getPassword());
+		String newPasswordConfirm = new String(
+				newPasswordConfirmField.getPassword());
 
-                return false;
-        }
-        else{ // passwords do not match
+		if (!newPassword.equals(newPasswordConfirm)) {
+			// passwords do not match
+			showMessageDialog(this, "Passwords do not match", WARN_TITLE,
+					WARNING_MESSAGE);
+			return false;
+		}
 
-        	JOptionPane.showMessageDialog(this,
-       			"Passwords do not match",
-       			"Credential Manager Warning",
-       			JOptionPane.WARNING_MESSAGE);
+		if (newPassword.isEmpty()) {
+			// passwords match but are empty
+			showMessageDialog(this, "The new master password cannot be empty",
+					WARN_TITLE, WARNING_MESSAGE);
+			return false;
+		}
 
-        	return false;
-        }
-    }
+		// passwords match and not empty
+		password = newPassword;
+		return true;
+	}
 
-    private void okPressed()
-    {
-        if (checkPassword()) {
-            closeDialog();
-        }
-    }
+	private void okPressed() {
+		if (checkPassword())
+			closeDialog();
+	}
 
-    private void cancelPressed()
-    {
-    	// Set the password to null as it might have changed in the meantime
-    	// if user entered something then cancelled.
-    	password = null;
-        closeDialog();
-    }
+	private void cancelPressed() {
+		/*
+		 * Set the password to null as it might have changed in the meantime if
+		 * user entered something then cancelled.
+		 */
+		password = null;
+		closeDialog();
+	}
 
-    private void closeDialog()
-    {
-        setVisible(false);
-        dispose();
-    }
+	private void closeDialog() {
+		setVisible(false);
+		dispose();
+	}
 }
-
-
-
diff --git a/credential-manager-ui/src/main/java/net/sf/taverna/t2/workbench/ui/credentialmanager/ConfirmTrustedCertificateDialog.java b/credential-manager-ui/src/main/java/net/sf/taverna/t2/workbench/ui/credentialmanager/ConfirmTrustedCertificateDialog.java
index 3110db7..82bbc7b 100644
--- a/credential-manager-ui/src/main/java/net/sf/taverna/t2/workbench/ui/credentialmanager/ConfirmTrustedCertificateDialog.java
+++ b/credential-manager-ui/src/main/java/net/sf/taverna/t2/workbench/ui/credentialmanager/ConfirmTrustedCertificateDialog.java
@@ -20,8 +20,16 @@
  ******************************************************************************/
 package net.sf.taverna.t2.workbench.ui.credentialmanager;
 
+import static java.awt.BorderLayout.CENTER;
+import static java.awt.BorderLayout.NORTH;
+import static java.awt.BorderLayout.SOUTH;
+import static java.awt.Color.WHITE;
+import static java.awt.Font.BOLD;
+import static java.awt.Font.PLAIN;
+import static java.awt.GridBagConstraints.LINE_START;
+import static javax.security.auth.x500.X500Principal.RFC2253;
+
 import java.awt.BorderLayout;
-import java.awt.Color;
 import java.awt.Dialog;
 import java.awt.FlowLayout;
 import java.awt.Font;
@@ -36,18 +44,20 @@
 import java.math.BigInteger;
 import java.security.cert.CertificateEncodingException;
 import java.security.cert.X509Certificate;
-import javax.security.auth.x500.X500Principal;
+
 import javax.swing.JButton;
 import javax.swing.JLabel;
 import javax.swing.JPanel;
 import javax.swing.border.CompoundBorder;
 import javax.swing.border.EmptyBorder;
 import javax.swing.border.EtchedBorder;
+
 import net.sf.taverna.t2.lang.ui.DialogTextArea;
 import net.sf.taverna.t2.security.credentialmanager.CMException;
 import net.sf.taverna.t2.security.credentialmanager.DistinguishedNameParser;
 import net.sf.taverna.t2.security.credentialmanager.ParsedDistinguishedName;
 import net.sf.taverna.t2.workbench.helper.NonBlockedHelpEnabledDialog;
+
 import org.apache.log4j.Logger;
 
 /**
@@ -57,82 +67,145 @@
  */
 @SuppressWarnings("serial")
 public class ConfirmTrustedCertificateDialog extends NonBlockedHelpEnabledDialog {
-	
 	private static Logger logger = Logger.getLogger(ConfirmTrustedCertificateDialog.class);
 
-	// The certificate to display
+	/** The certificate to display */
 	private X509Certificate cert;
-
-	// User's decision as whether to trust this service's certificate or not
+	/** User's decision as whether to trust this service's certificate or not */
 	private boolean shouldTrust;
-
-	// Should the decision also be saved in Credential Manager (actually - 
-	// it is always saved now as it was really hard to implement trusting for
-	// one connection only - so we can either "trust" or "not" trust but not "trust once".)
+	/**
+	 * Should the decision also be saved in Credential Manager? Actually - it is
+	 * always saved now as it was really hard to implement trusting for one
+	 * connection only - so we can either "trust" or "not" trust but not
+	 * "trust once".
+	 */
 	private boolean shouldSave = false;
+	private final DistinguishedNameParser dnParser;
 
-        private final DistinguishedNameParser dnParser;
-        
 	public ConfirmTrustedCertificateDialog(Frame parent, String title,
-			boolean modal, X509Certificate crt, DistinguishedNameParser dnParser){
+			boolean modal, X509Certificate crt, DistinguishedNameParser dnParser) {
 		super(parent, title, modal);
 		this.cert = crt;
-                this.dnParser = dnParser;
+		this.dnParser = dnParser;
 		initComponents();
 	}
-	
+
 	public ConfirmTrustedCertificateDialog(Dialog parent, String title,
 			boolean modal, X509Certificate crt, DistinguishedNameParser dnParser)
 			throws CMException {
 		super(parent, title, modal);
 		this.cert = crt;
-                this.dnParser = dnParser;
+		this.dnParser = dnParser;
 		initComponents();
 	}
 
-	private void initComponents(){
-		
+	private void initComponents(){		
 		// title panel
 		JPanel titlePanel = new JPanel(new BorderLayout());
-		titlePanel.setBackground(Color.WHITE);
+		titlePanel.setBackground(WHITE);
 		JLabel titleLabel = new JLabel("View service's certificate");
-		titleLabel.setFont(titleLabel.getFont().deriveFont(Font.BOLD, 13.5f));
+		titleLabel.setFont(titleLabel.getFont().deriveFont(BOLD, 13.5f));
 		titleLabel.setBorder(new EmptyBorder(10, 10, 0, 10));
+
 		DialogTextArea titleMessage = new DialogTextArea();
 		titleMessage.setMargin(new Insets(5, 20, 10, 10));
 		titleMessage.setFont(titleMessage.getFont().deriveFont(11f));
 		titleMessage.setEditable(false);
 		titleMessage.setFocusable(false);
 		titlePanel.setBorder( new EmptyBorder(10, 10, 0, 10));
-		titlePanel.add(titleLabel, BorderLayout.NORTH);
-		titlePanel.add(titleMessage, BorderLayout.CENTER);
+		titlePanel.add(titleLabel, NORTH);
+		titlePanel.add(titleMessage, CENTER);
 		
 		// Certificate details:
 
-		// Grid Bag Constraints templates for labels (column 1) and
-		// values (column 2) of certificate details
+		ParsedDistinguishedName subjectDN = dnParser.parseDN(cert
+				.getSubjectX500Principal().getName(RFC2253));
+		ParsedDistinguishedName issuerDN = dnParser.parseDN(cert
+				.getIssuerX500Principal().getName(RFC2253));
+		JPanel certificatePanel = createCertificateDetailsPanel(subjectDN, issuerDN);
+		titleMessage.setText("The service host " + subjectDN.getCN() + " requires HTTPS connection and has identified itself with the certificate below.\n" +
+				"Do you want to trust this service? (Refusing to trust means you will not be able to invoke services on this host from a workflow.)");
+
+		// OK button
+		JPanel buttonsPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
+
+//		final JButton trustButton = new JButton("Trust once");
+//		trustButton.addActionListener(new ActionListener() {
+//			public void actionPerformed(ActionEvent evt) {
+//				trustPressed();
+//			}
+//		});
+		
+		//final JButton trustAlwaysButton = new JButton("Trust always");
+		final JButton trustAlwaysButton = new JButton("Trust");
+		trustAlwaysButton.addActionListener(new ActionListener() {
+			@Override
+			public void actionPerformed(ActionEvent evt) {
+				trustAlwaysPressed();
+			}
+		});
+		
+		final JButton dontTrustButton = new JButton("Do not trust");
+		dontTrustButton.addActionListener(new ActionListener() {
+			@Override
+			public void actionPerformed(ActionEvent evt) {
+				dontTrustPressed();
+			}
+		});
+
+		//jpButtons.add(trustButton);
+		buttonsPanel.add(trustAlwaysButton);
+		buttonsPanel.add(dontTrustButton);
+
+		getContentPane().add(titlePanel, NORTH);
+		getContentPane().add(certificatePanel, CENTER);
+		getContentPane().add(buttonsPanel, SOUTH);
+
+		setResizable(false);
+
+		addWindowListener(new WindowAdapter() {
+			@Override
+			public void windowClosing(WindowEvent evt) {
+				closeDialog();
+			}
+		});
+
+		getRootPane().setDefaultButton(trustAlwaysButton);
+		pack();
+	}
+
+	private JPanel createCertificateDetailsPanel(ParsedDistinguishedName subjectDN, ParsedDistinguishedName issuerDN) {
+		/*
+		 * Grid Bag Constraints templates for labels (column 1) and values
+		 * (column 2) of certificate details
+		 */
 		GridBagConstraints gbc_labels = new GridBagConstraints();
 		gbc_labels.gridx = 0;
 		gbc_labels.ipadx = 20;
 		gbc_labels.gridwidth = 1;
 		gbc_labels.gridheight = 1;
 		gbc_labels.insets = new Insets(2, 15, 2, 2);
-		gbc_labels.anchor = GridBagConstraints.LINE_START;
+		gbc_labels.anchor = LINE_START;
 
 		GridBagConstraints gbc_values = new GridBagConstraints();
 		gbc_values.gridx = 1;
 		gbc_values.gridwidth = 1;
 		gbc_values.gridheight = 1;
 		gbc_values.insets = new Insets(2, 5, 2, 2);
-		gbc_values.anchor = GridBagConstraints.LINE_START;
+		gbc_values.anchor = LINE_START;
 
-		// Netscape Certificate Type non-critical extension (if any)
-		// defines the intended uses of the certificate - to make it look like
-		// Firefox's view certificate dialog
-        // From openssl's documentation: "The [above] extension is non standard, Netscape 
-        // specific and largely obsolete. Their use in new applications is discouraged."
-        // TODO replace with "basicConstraints, keyUsage and extended key usage extensions 
-        // which are now used instead."
+		/*
+		 * Netscape Certificate Type non-critical extension (if any) defines the
+		 * intended uses of the certificate - to make it look like Firefox's
+		 * view certificate dialog
+		 * 
+		 * From openssl's documentation: "The [above] extension is non standard,
+		 * Netscape specific and largely obsolete. Their use in new applications
+		 * is discouraged."
+		 * 
+		 * TODO replace with "basicConstraints, keyUsage and extended key usage
+		 * extensions which are now used instead."
+		 */
 //		byte[] intendedUses = cert.getExtensionValue("2.16.840.1.113730.1.1"); // Netscape Certificate Type OID
 //		JLabel intendedUsesLabel = null;
 //		JTextField intendedUsesTextField = null;
@@ -163,50 +236,45 @@
 
 		// Issued To
 		JLabel issuedToLabel = new JLabel("Issued To");
-		issuedToLabel.setFont(new Font(null, Font.BOLD, 11));
+		issuedToLabel.setFont(new Font(null, BOLD, 11));
 		GridBagConstraints gbc_issuedTo = (GridBagConstraints) gbc_labels
 				.clone();
 		gbc_issuedTo.gridy = 1;
 		gbc_issuedTo.gridwidth = 2; // takes two columns
 		gbc_issuedTo.insets = new Insets(5, 5, 5, 5);// has slightly bigger insets
 		// Subject's Distinguished Name (DN)
-		String subjectDN = cert.getSubjectX500Principal().getName(
-				X500Principal.RFC2253);
-                ParsedDistinguishedName parsedDN =  dnParser.parseDN(subjectDN);
 		// Extract the CN, O, OU and EMAILADDRESS fields
-		String subjectCN = parsedDN.getCN();
-		String subjectOrg = parsedDN.getO();
-		String subjectOU = parsedDN.getOU();
-		titleMessage.setText("The service host " + subjectCN + " requires HTTPS connection and has identified itself with the certificate below.\n" +
-				"Do you want to trust this service? (Refusing to trust means you will not be able to invoke services on this host from a workflow.)");
+		String subjectCN = subjectDN.getCN();
+		String subjectOrg = subjectDN.getO();
+		String subjectOU = subjectDN.getOU();
 		// String sEMAILADDRESS = CMUtils.getEmilAddress();
 		// Subject's Common Name (CN)
 		JLabel subjectCNLabel = new JLabel("Common Name (CN)");
-		subjectCNLabel.setFont(new Font(null, Font.PLAIN, 11));
+		subjectCNLabel.setFont(new Font(null, PLAIN, 11));
 		GridBagConstraints gbc_subjectCNLabel = (GridBagConstraints) gbc_labels.clone();
 		gbc_subjectCNLabel.gridy = 2;
 		JLabel subjectCNValue = new JLabel(subjectCN);
-		subjectCNValue.setFont(new Font(null, Font.PLAIN, 11));
+		subjectCNValue.setFont(new Font(null, PLAIN, 11));
 		GridBagConstraints gbc_subjectCNValue = (GridBagConstraints) gbc_values
 				.clone();
 		gbc_subjectCNValue.gridy = 2;
 		// Subject's Organisation (O)
 		JLabel subjectOrgLabel = new JLabel("Organisation (O)");
-		subjectOrgLabel.setFont(new Font(null, Font.PLAIN, 11));
+		subjectOrgLabel.setFont(new Font(null, PLAIN, 11));
 		GridBagConstraints gbc_subjectOrgLabel = (GridBagConstraints) gbc_labels.clone();
 		gbc_subjectOrgLabel.gridy = 3;
 		JLabel subjectOrgValue = new JLabel(subjectOrg);
-		subjectOrgValue.setFont(new Font(null, Font.PLAIN, 11));
+		subjectOrgValue.setFont(new Font(null, PLAIN, 11));
 		GridBagConstraints gbc_subjectOrgValue = (GridBagConstraints) gbc_values
 				.clone();
 		gbc_subjectOrgValue.gridy = 3;
 		// Subject's Organisation Unit (OU)
 		JLabel subjectOULabel = new JLabel("Organisation Unit (OU)");
-		subjectOULabel.setFont(new Font(null, Font.PLAIN, 11));
+		subjectOULabel.setFont(new Font(null, PLAIN, 11));
 		GridBagConstraints gbc_subjectOULabel = (GridBagConstraints) gbc_labels.clone();
 		gbc_subjectOULabel.gridy = 4;
 		JLabel subjectOUValue = new JLabel(subjectOU);
-		subjectOUValue.setFont(new Font(null, Font.PLAIN, 11));
+		subjectOUValue.setFont(new Font(null, PLAIN, 11));
 		GridBagConstraints gbc_subjectOUValue = (GridBagConstraints) gbc_values
 				.clone();
 		gbc_subjectOUValue.gridy = 4;
@@ -223,7 +291,7 @@
 		// gbc_jlEmailValue.gridy = 5;
 		// Serial Number
 		JLabel snLabel = new JLabel("Serial Number");
-		snLabel.setFont(new Font(null, Font.PLAIN, 11));
+		snLabel.setFont(new Font(null, PLAIN, 11));
 		GridBagConstraints gbc_snLabel = (GridBagConstraints) gbc_labels.clone();
 		gbc_snLabel.gridy = 6;
 		JLabel snValue = new JLabel();
@@ -231,104 +299,97 @@
 		StringBuffer strBuff = new StringBuffer(new BigInteger(1, cert
 				.getSerialNumber().toByteArray()).toString(16).toUpperCase());
 		// Place colons at every two hexadecimal characters
-		if (strBuff.length() > 2) {
-			for (int iCnt = 2; iCnt < strBuff.length(); iCnt += 3) {
+		if (strBuff.length() > 2)
+			for (int iCnt = 2; iCnt < strBuff.length(); iCnt += 3)
 				strBuff.insert(iCnt, ':');
-			}
-		}
 		snValue.setText(strBuff.toString());
-		snValue.setFont(new Font(null, Font.PLAIN, 11));
+		snValue.setFont(new Font(null, PLAIN, 11));
 		GridBagConstraints gbc_snValue = (GridBagConstraints) gbc_values
 				.clone();
 		gbc_snValue.gridy = 6;
 		// Certificate version number
 		JLabel versionLabel = new JLabel("Version");
-		versionLabel.setFont(new Font(null, Font.PLAIN, 11));
+		versionLabel.setFont(new Font(null, PLAIN, 11));
 		GridBagConstraints gbc_versionLabel = (GridBagConstraints) gbc_labels
 				.clone();
 		gbc_versionLabel.gridy = 7;
 		JLabel versionValue = new JLabel(Integer.toString(cert.getVersion()));
-		versionValue.setFont(new Font(null, Font.PLAIN, 11));
+		versionValue.setFont(new Font(null, PLAIN, 11));
 		GridBagConstraints gbc_versionValue = (GridBagConstraints) gbc_values
 				.clone();
 		gbc_versionValue.gridy = 7;
 
 		// Issued By
 		JLabel issuedByLabel = new JLabel("Issued By");
-		issuedByLabel.setFont(new Font(null, Font.BOLD, 11));
+		issuedByLabel.setFont(new Font(null, BOLD, 11));
 		GridBagConstraints gbc_issuedByLabel = (GridBagConstraints) gbc_labels
 				.clone();
 		gbc_issuedByLabel.gridy = 8;
 		gbc_issuedByLabel.gridwidth = 2; // takes two columns
-		gbc_issuedByLabel.insets = new Insets(5, 5, 5, 5);// has slightly bigger
-														// insets
+		gbc_issuedByLabel.insets = new Insets(5, 5, 5, 5);// has slightly bigger insets
 		// Issuer's Distinguished Name (DN)
-		String issuerDN = cert.getIssuerX500Principal().getName(
-				X500Principal.RFC2253);
-		parsedDN =  dnParser.parseDN(issuerDN);
 		// Extract the CN, O and OU fields for the issuer
-		String issuerCN = parsedDN.getCN();
-		String issuerOrg = parsedDN.getO();
-		String issuerOU = parsedDN.getOU();
+		String issuerCN = issuerDN.getCN();
+		String issuerOrg = issuerDN.getO();
+		String issuerOU = issuerDN.getOU();
 		// Issuer's Common Name (CN)
 		JLabel issuerCNLabel = new JLabel("Common Name (CN)");
-		issuerCNLabel.setFont(new Font(null, Font.PLAIN, 11));
+		issuerCNLabel.setFont(new Font(null, PLAIN, 11));
 		GridBagConstraints gbc_issuerCNLabel = (GridBagConstraints) gbc_labels.clone();
 		gbc_issuerCNLabel.gridy = 9;
 		JLabel issuerCNValue = new JLabel(issuerCN);
-		issuerCNValue.setFont(new Font(null, Font.PLAIN, 11));
+		issuerCNValue.setFont(new Font(null, PLAIN, 11));
 		GridBagConstraints gbc_issuerCNValue = (GridBagConstraints) gbc_values
 				.clone();
 		gbc_issuerCNValue.gridy = 9;
 		// Issuer's Organisation (O)
 		JLabel issuerOrgLabel = new JLabel("Organisation (O)");
-		issuerOrgLabel.setFont(new Font(null, Font.PLAIN, 11));
+		issuerOrgLabel.setFont(new Font(null, PLAIN, 11));
 		GridBagConstraints gbc_issuerOrgLabel = (GridBagConstraints) gbc_labels.clone();
 		gbc_issuerOrgLabel.gridy = 10;
 		JLabel issuerOrgValue = new JLabel(issuerOrg);
-		issuerOrgValue.setFont(new Font(null, Font.PLAIN, 11));
+		issuerOrgValue.setFont(new Font(null, PLAIN, 11));
 		GridBagConstraints gbc_issuerOrgValue = (GridBagConstraints) gbc_values
 				.clone();
 		gbc_issuerOrgValue.gridy = 10;
 		// Issuer's Organisation Unit (OU)
 		JLabel issuerOULabel = new JLabel("Organisation Unit (OU)");
-		issuerOULabel.setFont(new Font(null, Font.PLAIN, 11));
+		issuerOULabel.setFont(new Font(null, PLAIN, 11));
 		GridBagConstraints gbc_issuerOULabel = (GridBagConstraints) gbc_labels.clone();
 		gbc_issuerOULabel.gridy = 11;
 		JLabel issuerOUValue = new JLabel(issuerOU);
-		issuerOUValue.setFont(new Font(null, Font.PLAIN, 11));
+		issuerOUValue.setFont(new Font(null, PLAIN, 11));
 		GridBagConstraints gbc_issuerOUValue = (GridBagConstraints) gbc_values
 				.clone();
 		gbc_issuerOUValue.gridy = 11;
 		
 		// Validity
 		JLabel validityLabel = new JLabel("Validity");
-		validityLabel.setFont(new Font(null, Font.BOLD, 11));
+		validityLabel.setFont(new Font(null, BOLD, 11));
 		GridBagConstraints gbc_validityLabel = (GridBagConstraints) gbc_labels
 				.clone();
 		gbc_validityLabel.gridy = 12;
 		gbc_validityLabel.gridwidth = 2; // takes two columns
-		gbc_validityLabel.insets = new Insets(5, 5, 5, 5);// has slightly bigger
-														// insets
+		gbc_validityLabel.insets = new Insets(5, 5, 5, 5);// has slightly bigger insets
 		// Issued On
 		JLabel issuedOnLabel = new JLabel("Issued On");
-		issuedOnLabel.setFont(new Font(null, Font.PLAIN, 11));
+		issuedOnLabel.setFont(new Font(null, PLAIN, 11));
 		GridBagConstraints gbc_issuedOnLabel = (GridBagConstraints) gbc_labels
 				.clone();
 		gbc_issuedOnLabel.gridy = 13;
 		JLabel issuedOnValue = new JLabel(cert.getNotBefore().toString());
-		issuedOnValue.setFont(new Font(null, Font.PLAIN, 11));
+		issuedOnValue.setFont(new Font(null, PLAIN, 11));
 		GridBagConstraints gbc_issuedOnValue = (GridBagConstraints) gbc_values
 				.clone();
 		gbc_issuedOnValue.gridy = 13;
 		// Expires On
 		JLabel expiresOnLabel = new JLabel("Expires On");
-		expiresOnLabel.setFont(new Font(null, Font.PLAIN, 11));
+		expiresOnLabel.setFont(new Font(null, PLAIN, 11));
 		GridBagConstraints gbc_expiresOnLabel = (GridBagConstraints) gbc_labels
 				.clone();
 		gbc_expiresOnLabel.gridy = 14;
 		JLabel expiresOnValue = new JLabel(cert.getNotAfter().toString());
-		expiresOnValue.setFont(new Font(null, Font.PLAIN, 11));
+		expiresOnValue.setFont(new Font(null, PLAIN, 11));
 		GridBagConstraints gbc_expiresOnValue = (GridBagConstraints) gbc_values
 				.clone();
 		gbc_expiresOnValue.gridy = 14;
@@ -342,40 +403,43 @@
 			logger.error("Could not get the encoded form of the certificate.", ex);
 		}
 		JLabel fingerprintsLabel = new JLabel("Fingerprints");
-		fingerprintsLabel.setFont(new Font(null, Font.BOLD, 11));
+		fingerprintsLabel.setFont(new Font(null, BOLD, 11));
 		GridBagConstraints gbc_fingerprintsLabel = (GridBagConstraints) gbc_labels
 				.clone();
 		gbc_fingerprintsLabel.gridy = 15;
 		gbc_fingerprintsLabel.gridwidth = 2; // takes two columns
-		gbc_fingerprintsLabel.insets = new Insets(5, 5, 5, 5);// has slightly
-															// bigger insets
+		gbc_fingerprintsLabel.insets = new Insets(5, 5, 5, 5);// has slightly bigger insets
 		// SHA-1 Fingerprint
 		JLabel sha1FingerprintLabel = new JLabel("SHA1 Fingerprint");
-		sha1FingerprintLabel.setFont(new Font(null, Font.PLAIN, 11));
+		sha1FingerprintLabel.setFont(new Font(null, PLAIN, 11));
 		GridBagConstraints gbc_sha1FingerprintLabel = (GridBagConstraints) gbc_labels
 				.clone();
 		gbc_sha1FingerprintLabel.gridy = 16;
-		JLabel sha1FingerprintValue = new JLabel(dnParser.getMessageDigestAsFormattedString(binaryCertificateEncoding,
-				"SHA1"));
-		sha1FingerprintValue.setFont(new Font(null, Font.PLAIN, 11));
+		JLabel sha1FingerprintValue = new JLabel(
+				dnParser.getMessageDigestAsFormattedString(
+						binaryCertificateEncoding, "SHA1"));
+		sha1FingerprintValue.setFont(new Font(null, PLAIN, 11));
 		GridBagConstraints gbc_sha1FingerprintValue = (GridBagConstraints) gbc_values
 				.clone();
 		gbc_sha1FingerprintValue.gridy = 16;
 		// MD5 Fingerprint
 		JLabel md5FingerprintLabel = new JLabel("MD5 Fingerprint");
-		md5FingerprintLabel.setFont(new Font(null, Font.PLAIN, 11));
+		md5FingerprintLabel.setFont(new Font(null, PLAIN, 11));
 		GridBagConstraints gbc_md5FingerprinLabel = (GridBagConstraints) gbc_labels
 				.clone();
 		gbc_md5FingerprinLabel.gridy = 17;
 		JLabel md5FingerprintValue = new JLabel(
-				dnParser.getMessageDigestAsFormattedString(binaryCertificateEncoding, "MD5"));
-		md5FingerprintValue.setFont(new Font(null, Font.PLAIN, 11));
+				dnParser.getMessageDigestAsFormattedString(
+						binaryCertificateEncoding, "MD5"));
+		md5FingerprintValue.setFont(new Font(null, PLAIN, 11));
 		GridBagConstraints gbc_md5FingerprintValue = (GridBagConstraints) gbc_values
 				.clone();
 		gbc_md5FingerprintValue.gridy = 17;
 
-		// Empty label to add a bit space at the bottom of the panel
-		// to make it look like Firefox's view certificate dialog
+		/*
+		 * Empty label to add a bit space at the bottom of the panel to make it
+		 * look like Firefox's view certificate dialog
+		 */
 		JLabel emptyLabel = new JLabel("");
 		GridBagConstraints gbc_emptyLabel = (GridBagConstraints) gbc_labels.clone();
 		gbc_emptyLabel.gridy = 18;
@@ -386,9 +450,8 @@
 		certificatePanel.setBorder(new CompoundBorder(new EmptyBorder(15, 15, 15,
 				15), new EtchedBorder()));
 
-//		if (intendedUses != null) {
+//		if (intendedUses != null)
 //			certificatePanel.add(intendedUsesPanel, gbc_intendedUsesLabel);
-//		}
 		certificatePanel.add(issuedToLabel, gbc_issuedTo); // Issued To
 		certificatePanel.add(subjectCNLabel, gbc_subjectCNLabel);
 		certificatePanel.add(subjectCNValue, gbc_subjectCNValue);
@@ -419,52 +482,9 @@
 		certificatePanel.add(sha1FingerprintValue, gbc_sha1FingerprintValue);
 		certificatePanel.add(md5FingerprintLabel, gbc_md5FingerprinLabel);
 		certificatePanel.add(md5FingerprintValue, gbc_md5FingerprintValue);
-		certificatePanel.add(emptyLabel, gbc_emptyLabel); // Empty label to get some vertical space on the frame
-
-		// OK button
-		JPanel buttonsPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
-
-//		final JButton trustButton = new JButton("Trust once");
-//		trustButton.addActionListener(new ActionListener() {
-//			public void actionPerformed(ActionEvent evt) {
-//				trustPressed();
-//			}
-//		});
-		
-		//final JButton trustAlwaysButton = new JButton("Trust always");
-		final JButton trustAlwaysButton = new JButton("Trust");
-		trustAlwaysButton.addActionListener(new ActionListener() {
-			public void actionPerformed(ActionEvent evt) {
-				trustAlwaysPressed();
-			}
-		});
-		
-		final JButton dontTrustButton = new JButton("Do not trust");
-		dontTrustButton.addActionListener(new ActionListener() {
-			public void actionPerformed(ActionEvent evt) {
-				dontTrustPressed();
-			}
-		});
-
-		//jpButtons.add(trustButton);
-		buttonsPanel.add(trustAlwaysButton);
-		buttonsPanel.add(dontTrustButton);
-
-		getContentPane().add(titlePanel, BorderLayout.NORTH);
-		getContentPane().add(certificatePanel, BorderLayout.CENTER);
-		getContentPane().add(buttonsPanel, BorderLayout.SOUTH);
-
-		setResizable(false);
-
-		addWindowListener(new WindowAdapter() {
-			public void windowClosing(WindowEvent evt) {
-				closeDialog();
-			}
-		});
-
-		getRootPane().setDefaultButton(trustAlwaysButton);
-
-		pack();
+		// Empty label to get some vertical space on the frame
+		certificatePanel.add(emptyLabel, gbc_emptyLabel);
+		return certificatePanel;
 	}
 
 //	private void trustPressed() {
@@ -472,20 +492,19 @@
 //		shouldSave = false;
 //		closeDialog();
 //	}
-	
-	
+
 	private void trustAlwaysPressed() {
 		shouldTrust = true;
-		shouldSave  = true;
+		shouldSave = true;
 		closeDialog();
 	}
-	
+
 	private void dontTrustPressed() {
 		shouldTrust = false;
 		shouldSave = false;
 		closeDialog();
-	}	
-	
+	}
+
 	public void closeDialog() {
 		setVisible(false);
 		dispose();
diff --git a/credential-manager-ui/src/main/java/net/sf/taverna/t2/workbench/ui/credentialmanager/ConfirmTrustedCertificateUI.java b/credential-manager-ui/src/main/java/net/sf/taverna/t2/workbench/ui/credentialmanager/ConfirmTrustedCertificateUI.java
index bf4b828..0845543 100644
--- a/credential-manager-ui/src/main/java/net/sf/taverna/t2/workbench/ui/credentialmanager/ConfirmTrustedCertificateUI.java
+++ b/credential-manager-ui/src/main/java/net/sf/taverna/t2/workbench/ui/credentialmanager/ConfirmTrustedCertificateUI.java
@@ -20,24 +20,27 @@
  ******************************************************************************/

 package net.sf.taverna.t2.workbench.ui.credentialmanager;

 

+import static javax.swing.JOptionPane.INFORMATION_MESSAGE;

+import static javax.swing.JOptionPane.showMessageDialog;

+

 import java.awt.Frame;

 import java.security.cert.X509Certificate;

-import javax.swing.JOptionPane;

+

 import net.sf.taverna.t2.security.credentialmanager.DistinguishedNameParser;

 import net.sf.taverna.t2.security.credentialmanager.TrustConfirmationProvider;

+

 import org.apache.log4j.Logger;

 

 /**

  * @author Stian Soiland-Reyes

- *

  */

 public class ConfirmTrustedCertificateUI implements TrustConfirmationProvider {

-

 	private static Logger logger = Logger

 			.getLogger(ConfirmTrustedCertificateUI.class);

-        

-        private DistinguishedNameParser dnParser;

-        

+

+	private DistinguishedNameParser dnParser;

+

+	@Override

 	public Boolean shouldTrustCertificate(X509Certificate[] chain) {

 		boolean trustConfirm = false;

 		logger.info("Asking the user if they want to trust a certificate.");

@@ -49,23 +52,20 @@
 		confirmCertTrustDialog.setVisible(true);

 		trustConfirm = confirmCertTrustDialog.shouldTrust();

 //		trustConfirm.setShouldSave(confirmCertTrustDialog.shouldSave());

-		if (!confirmCertTrustDialog.shouldTrust()) {

-			JOptionPane

-					.showMessageDialog(

-							null,

-							"As you refused to trust this host, you will not be able to use its services from a workflow.",

-							"Untrusted HTTPS connection",

-							JOptionPane.INFORMATION_MESSAGE);

-		}

+		if (!confirmCertTrustDialog.shouldTrust())

+			showMessageDialog(

+					null,

+					"As you refused to trust this host, you will not be able to use its services from a workflow.",

+					"Untrusted HTTPS connection", INFORMATION_MESSAGE);

 

 		return trustConfirm;

 	}

 

-    /**

-     * @param dnParser the dnParser to set

-     */

-    public void setDistinguishedNameParser(DistinguishedNameParser dnParser) {

-        this.dnParser = dnParser;

-    }

-

+	/**

+	 * @param dnParser

+	 *            the dnParser to set

+	 */

+	public void setDistinguishedNameParser(DistinguishedNameParser dnParser) {

+		this.dnParser = dnParser;

+	}

 }

diff --git a/credential-manager-ui/src/main/java/net/sf/taverna/t2/workbench/ui/credentialmanager/CredentialManagerUI.java b/credential-manager-ui/src/main/java/net/sf/taverna/t2/workbench/ui/credentialmanager/CredentialManagerUI.java
index ff0433d..41d7a15 100644
--- a/credential-manager-ui/src/main/java/net/sf/taverna/t2/workbench/ui/credentialmanager/CredentialManagerUI.java
+++ b/credential-manager-ui/src/main/java/net/sf/taverna/t2/workbench/ui/credentialmanager/CredentialManagerUI.java
@@ -20,14 +20,33 @@
  ******************************************************************************/
 package net.sf.taverna.t2.workbench.ui.credentialmanager;
 
+import static java.awt.BorderLayout.CENTER;
+import static java.awt.BorderLayout.NORTH;
+import static java.awt.BorderLayout.PAGE_END;
+import static java.awt.Dialog.ModalExclusionType.APPLICATION_EXCLUDE;
+import static java.awt.Toolkit.getDefaultToolkit;
+import static javax.swing.JFileChooser.APPROVE_OPTION;
+import static javax.swing.JOptionPane.ERROR_MESSAGE;
+import static javax.swing.JOptionPane.INFORMATION_MESSAGE;
+import static javax.swing.JOptionPane.NO_OPTION;
+import static javax.swing.JOptionPane.WARNING_MESSAGE;
+import static javax.swing.JOptionPane.YES_NO_OPTION;
+import static javax.swing.JOptionPane.YES_OPTION;
+import static javax.swing.JOptionPane.showConfirmDialog;
+import static javax.swing.JOptionPane.showMessageDialog;
+import static javax.swing.JTable.AUTO_RESIZE_ALL_COLUMNS;
+import static javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;
+import static javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;
+import static net.sf.taverna.t2.security.credentialmanager.CredentialManager.KeystoreType.KEYSTORE;
+import static net.sf.taverna.t2.security.credentialmanager.CredentialManager.KeystoreType.TRUSTSTORE;
+import static net.sf.taverna.t2.workbench.ui.credentialmanager.CMStrings.ALERT_TITLE;
+import static net.sf.taverna.t2.workbench.ui.credentialmanager.CMStrings.ERROR_TITLE;
+
 import java.awt.BorderLayout;
-import java.awt.Dialog;
 import java.awt.Dimension;
 import java.awt.FlowLayout;
-import java.awt.Frame;
 import java.awt.Image;
 import java.awt.Point;
-import java.awt.Toolkit;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
 import java.awt.event.MouseAdapter;
@@ -37,7 +56,6 @@
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileWriter;
-import java.io.IOException;
 import java.io.InputStreamReader;
 import java.net.URI;
 import java.security.Key;
@@ -46,28 +64,27 @@
 import java.security.cert.CertificateFactory;
 import java.security.cert.X509Certificate;
 import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Iterator;
 import java.util.List;
 import java.util.prefs.Preferences;
+
 import javax.swing.JButton;
 import javax.swing.JFileChooser;
 import javax.swing.JFrame;
-import javax.swing.JOptionPane;
 import javax.swing.JPanel;
 import javax.swing.JScrollPane;
 import javax.swing.JTabbedPane;
 import javax.swing.JTable;
-import javax.swing.WindowConstants;
 import javax.swing.border.EmptyBorder;
 import javax.swing.event.ListSelectionEvent;
 import javax.swing.event.ListSelectionListener;
 import javax.swing.table.TableColumn;
+
 import net.sf.taverna.t2.security.credentialmanager.CMException;
 import net.sf.taverna.t2.security.credentialmanager.CredentialManager;
 import net.sf.taverna.t2.security.credentialmanager.CredentialManager.KeystoreType;
 import net.sf.taverna.t2.security.credentialmanager.DistinguishedNameParser;
 import net.sf.taverna.t2.security.credentialmanager.UsernamePassword;
+
 import org.apache.log4j.Logger;
 import org.bouncycastle.openssl.PEMReader;
 import org.bouncycastle.openssl.PEMWriter;
@@ -89,72 +106,59 @@
 
 @SuppressWarnings("serial")
 public class CredentialManagerUI extends JFrame {
-
-	// Logger
 	private static Logger logger = Logger.getLogger(CredentialManagerUI.class);
-
-	// Default tabbed pane width
+	/** Default tabbed pane width */
 	private static final int DEFAULT_FRAME_WIDTH = 650;
-
-	// Default tabbed pane height
+	/** Default tabbed pane height */
 	private static final int DEFAULT_FRAME_HEIGHT = 400;
-
-	// Credential Manager icon (when frame is minimised)
-	private static final Image credManagerIconImage = Toolkit
-			.getDefaultToolkit()
+	/** Credential Manager icon (when frame is minimised)*/
+	private static final Image credManagerIconImage = getDefaultToolkit()
 			.createImage(
 					CredentialManagerUI.class
 							.getResource("/images/cred_manager_transparent.png"));
 
+	/**
+	 * Credential Manager to manage all operations on the Keystore and
+	 * Truststore
+	 */
+	public final CredentialManager credManager;
+	private final DistinguishedNameParser dnParser;
+	
 	////////////// Tabs //////////////
 
-	// Credential Manager to manage all operations on the Keystore and Truststore
-	public final CredentialManager credManager;
-
-        private final DistinguishedNameParser dnParser;
-        
-	// Tabbed pane to hold tables containing various entries in the Keystore and Truststore
+	/**
+	 * Tabbed pane to hold tables containing various entries in the Keystore and
+	 * Truststore
+	 */
 	private JTabbedPane keyStoreTabbedPane;
-
-	// Tab 1: holds passwords table
+	/** Tab 1: holds passwords table */
 	private JPanel passwordsTab = new JPanel(new BorderLayout(10, 10));
-
-	// Tab 1: name
+	/** Tab 1: name */
 	public static final String PASSWORDS = "Passwords";
-
-	// Tab 2: holds key pairs (user certificates) table
+	/** Tab 2: holds key pairs (user certificates) table */
 	private JPanel keyPairsTab = new JPanel(new BorderLayout(10, 10));
-
-	// Tab 2: name
+	/** Tab 2: name */
 	public static final String KEYPAIRS = "Your Certificates";
-
-	// Tab 3: holds trusted certificates table
+	/** Tab 3: holds trusted certificates table */
 	private JPanel trustedCertificatesTab = new JPanel(new BorderLayout(10, 10));
-
-	// Tab 3: name
+	/** Tab 3: name */
 	public static final String TRUSTED_CERTIFICATES = "Trusted Certificates";
 
 	////////////// Tables //////////////
 
-	// Password entries' table
+	/** Password entries' table */
 	private JTable passwordsTable;
-
-	// Key pair entries' table
+	/** Key pair entries' table */
 	private JTable keyPairsTable;
-
-	// Trusted certificate entries' table
+	/** Trusted certificate entries' table */
 	private JTable trustedCertsTable;
-
-	// Password entry column type
+	/** Password entry column type */
 	public static final String PASSWORD_ENTRY_TYPE = "Password";
-
-	// Key pair entry column type
+	/** Key pair entry column type */
 	public static final String KEY_PAIR_ENTRY_TYPE = "Key Pair";
-
-	// Trusted cert entry column type
+	/** Trusted cert entry column type */
 	public static final String TRUST_CERT_ENTRY_TYPE = "Trusted Certificate";
 
-
 	/**
 	 * Overrides the Object's clone method to prevent the singleton object to be
 	 * cloned.
@@ -167,41 +171,53 @@
 	/**
 	 * Creates a new Credential Manager UI's frame.
 	 */
-	public CredentialManagerUI(CredentialManager credentialManager, DistinguishedNameParser dnParser) {
+	public CredentialManagerUI(CredentialManager credentialManager,
+			DistinguishedNameParser dnParser) {
 		credManager = credentialManager;
-                this.dnParser = dnParser;
-		this.setModalExclusionType(Dialog.ModalExclusionType.APPLICATION_EXCLUDE);
+		this.dnParser = dnParser;
+		setModalExclusionType(APPLICATION_EXCLUDE);
 		// Initialise the UI components
 		initComponents();
 	}
 
 	private void initComponents() {
-
-		// Initialise the tabbed pane that contains the tabs with tabular
-		// representations of the Keystore's content.
+		/*
+		 * Initialise the tabbed pane that contains the tabs with tabular
+		 * representations of the Keystore's content.
+		 */
 		keyStoreTabbedPane = new JTabbedPane();
-		// Initialise the tab containing the table for username/password entries
-		// from the
-		// Keystore
+		/*
+		 * Initialise the tab containing the table for username/password entries
+		 * from the Keystore
+		 */
 		passwordsTable = initTable(PASSWORDS, passwordsTab);
-		// Initialise the tab containing the table for key pair entries from the
-		// Keystore
+		/*
+		 * Initialise the tab containing the table for key pair entries from the
+		 * Keystore
+		 */
 		keyPairsTable = initTable(KEYPAIRS, keyPairsTab);
-		// Initialise the tab containing the table for proxy entries from the
-		// Keystore
+		/*
+		 * Initialise the tab containing the table for proxy entries from the
+		 * Keystore
+		 */
 		//proxiesTable = initTable(PROXIES, proxiesTab);
-		// Initialise the tab containing the table for trusted certificate
-		// entries from the Truststore
+		/*
+		 * Initialise the tab containing the table for trusted certificate
+		 * entries from the Truststore
+		 */
 		trustedCertsTable = initTable(TRUSTED_CERTIFICATES,
 				trustedCertificatesTab);
-		// Set the size of the tabbed pane to the preferred size - the size of
-		// the main application frame depends on it.
+		/*
+		 * Set the size of the tabbed pane to the preferred size - the size of
+		 * the main application frame depends on it.
+		 */
 		keyStoreTabbedPane.setPreferredSize(new Dimension(DEFAULT_FRAME_WIDTH,
 				DEFAULT_FRAME_HEIGHT));
 
 		JPanel globalButtons = new JPanel(new FlowLayout(FlowLayout.RIGHT));
 		JButton resetJavaAuthCache = new JButton("Clear HTTP authentication");
 		resetJavaAuthCache.addActionListener(new ActionListener() {
+			@Override
 			public void actionPerformed(ActionEvent e) {
 				clearAuthenticationCache();
 			}
@@ -212,6 +228,7 @@
 		JButton changeMasterPasswordButton = new JButton(
 				"Change master password");
 		changeMasterPasswordButton.addActionListener(new ActionListener() {
+			@Override
 			public void actionPerformed(ActionEvent e) {
 				changeMasterPassword();
 			}
@@ -219,17 +236,18 @@
 		globalButtons.add(changeMasterPasswordButton);
 
 		// Add change master password to the main application frame
-		getContentPane().add(globalButtons, BorderLayout.NORTH);
+		getContentPane().add(globalButtons, NORTH);
 		// Add tabbed pane to the main application frame
-		getContentPane().add(keyStoreTabbedPane, BorderLayout.CENTER);
+		getContentPane().add(keyStoreTabbedPane, CENTER);
 
 		// Handle application close
 		addWindowListener(new WindowAdapter() {
+			@Override
 			public void windowClosing(WindowEvent evt) {
 				closeFrame();
 			}
 		});
-		setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
+		setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
 
 		pack();
 
@@ -247,51 +265,46 @@
 	}
 
 	protected void clearAuthenticationCache() {
-		if (! credManager.resetAuthCache()) {
-			JOptionPane
-					.showMessageDialog(
-							this,
-							"Java's internal HTTP authentication cache could not be cleared. \n\n" +
-							"Taverna can only clear the cache using an undocumented Java API \n" +
-							"that might not work if you are using a Java VM other than \n" +
-							"Java 6 from Sun. You can restarting Taverna to clear the cache.",
-							"Could not clear authentication cache",
-							JOptionPane.ERROR_MESSAGE);
-		} else {
-			JOptionPane.showMessageDialog(this,
+		if (!credManager.resetAuthCache())
+			showMessageDialog(
+					this,
+					"Java's internal HTTP authentication cache could not be cleared. \n\n"
+							+ "Taverna can only clear the cache using an undocumented Java API \n"
+							+ "that might not work if you are using a Java VM other than \n"
+							+ "Java 6 from Sun. You can restarting Taverna to clear the cache.",
+					"Could not clear authentication cache", ERROR_MESSAGE);
+		else
+			showMessageDialog(
+					this,
 					"Java's internal HTTP authentication cache has been cleared. \n\n"
 							+ "You might also need to edit or delete individual \n"
 							+ "password entries in the credential manager \n"
 							+ "if a relevant password has previously been saved.",
-					"Cleared authentication cache", JOptionPane.INFORMATION_MESSAGE);
-		}
+					"Cleared authentication cache", INFORMATION_MESSAGE);
 	}
 
 	protected void changeMasterPassword() {
-
 		ChangeMasterPasswordDialog changePasswordDialog = new ChangeMasterPasswordDialog(
 				this, "Change master password", true,
 				"Change master password for Credential Manager", credManager);
 		changePasswordDialog.setLocationRelativeTo(null);
 		changePasswordDialog.setVisible(true);
 		String password = changePasswordDialog.getPassword();
-		if (password == null) { // user cancelled
+		if (password == null) // user cancelled
 			return; // do nothing
-		} else {
-			try {
-				credManager.changeMasterPassword(password);
-				JOptionPane.showMessageDialog(this,
-						"Master password changed sucessfully",
-						"Credential Manager Error",
-						JOptionPane.INFORMATION_MESSAGE);
-			} catch (CMException cme) {
-				// Failed to change the master password for Credential Manager -
-				// warn the user
-				String exMessage = "Failed to change master password for Credential Manager";
-				logger.error(exMessage);
-				JOptionPane.showMessageDialog(this, exMessage,
-						"Credential Manager Error", JOptionPane.ERROR_MESSAGE);
-			}
+
+		try {
+			credManager.changeMasterPassword(password);
+			showMessageDialog(this, "Master password changed sucessfully",
+					ALERT_TITLE, INFORMATION_MESSAGE);
+		} catch (CMException cme) {
+			/*
+			 * Failed to change the master password for Credential Manager -
+			 * warn the user
+			 */
+			String exMessage = "Failed to change master password for Credential Manager";
+			logger.error(exMessage);
+			showMessageDialog(this, exMessage, ERROR_TITLE, ERROR_MESSAGE);
 		}
 	}
 
@@ -299,20 +312,21 @@
 	 * Initialise the tabs and tables with the content from the Keystore and Truststore.
 	 */
 	private JTable initTable(String tableType, JPanel tab) {
-
 		JTable table = null;
 
 		if (tableType.equals(PASSWORDS)) { // Passwords table
-
 			// The Passwords table's data model
 			PasswordsTableModel passwordsTableModel = new PasswordsTableModel(credManager);
 			// The table itself
 			table = new JTable(passwordsTableModel);
 
-			// Set the password and alias columns of the Passwords table to be
-			// invisible by removing them from the column model (they will still
-			// present in the table model)
-			// Remove the last column first
+			/*
+			 * Set the password and alias columns of the Passwords table to be
+			 * invisible by removing them from the column model (they will still
+			 * present in the table model)
+			 * 
+			 * Remove the last column first
+			 */
 			TableColumn aliasColumn = table.getColumnModel().getColumn(5);
 			table.getColumnModel().removeColumn(aliasColumn);
 			TableColumn passwordColumn = table.getColumnModel().getColumn(4);
@@ -323,6 +337,7 @@
 			// Buttons
 			JButton newPasswordButton = new JButton("New");
 			newPasswordButton.addActionListener(new ActionListener() {
+				@Override
 				public void actionPerformed(ActionEvent e) {
 					newPassword();
 				}
@@ -330,6 +345,7 @@
 
 			final JButton viewPasswordButton = new JButton("Details");
 			viewPasswordButton.addActionListener(new ActionListener() {
+				@Override
 				public void actionPerformed(ActionEvent e) {
 					viewPassword();
 				}
@@ -338,6 +354,7 @@
 
 			final JButton editPasswordButton = new JButton("Edit");
 			editPasswordButton.addActionListener(new ActionListener() {
+				@Override
 				public void actionPerformed(ActionEvent e) {
 					editPassword();
 				}
@@ -346,35 +363,36 @@
 
 			final JButton deletePasswordButton = new JButton("Delete");
 			deletePasswordButton.addActionListener(new ActionListener() {
+				@Override
 				public void actionPerformed(ActionEvent e) {
 					deletePassword();
 				}
 			});
 			deletePasswordButton.setEnabled(false);
 
-			// Selection listener for passwords table to enable/disable action buttons accordingly
-			class PasswordsTableSelectionListner implements ListSelectionListener{
+			/*
+			 * Selection listener for passwords table to enable/disable action
+			 * buttons accordingly
+			 */
+			class PasswordsTableSelectionListner implements
+					ListSelectionListener {
 				@Override
 				public void valueChanged(ListSelectionEvent e) {
-					if (e.getSource() == passwordsTable.getSelectionModel()){
-						if (passwordsTable.getSelectedRow() == -1){ // nothing is selected
-							viewPasswordButton.setEnabled(false);
-							editPasswordButton.setEnabled(false);
-							deletePasswordButton.setEnabled(false);
-						}
-						else{
-							if (!viewPasswordButton.isEnabled()){
-								viewPasswordButton.setEnabled(true);
-							}
-							if(!editPasswordButton.isEnabled()){
-								editPasswordButton.setEnabled(true);
-							}
-							if (!deletePasswordButton.isEnabled()){
-								deletePasswordButton.setEnabled(true);
-							}
-						}
+					if (e.getSource() != passwordsTable.getSelectionModel())
+						return;
+					if (passwordsTable.getSelectedRow() == -1) {
+						// nothing is selected
+						viewPasswordButton.setEnabled(false);
+						editPasswordButton.setEnabled(false);
+						deletePasswordButton.setEnabled(false);
+					} else {
+						if (!viewPasswordButton.isEnabled())
+							viewPasswordButton.setEnabled(true);
+						if (!editPasswordButton.isEnabled())
+							editPasswordButton.setEnabled(true);
+						if (!deletePasswordButton.isEnabled())
+							deletePasswordButton.setEnabled(true);
 					}
-
 				}
 			}
 			table.getSelectionModel().addListSelectionListener(new PasswordsTableSelectionListner());
@@ -387,19 +405,21 @@
 			bp.add(deletePasswordButton);
 
 			// Add button panel to the tab
-			tab.add(bp, BorderLayout.PAGE_END);
+			tab.add(bp, PAGE_END);
 
 		} else if (tableType.equals(KEYPAIRS)) { // Key Pairs tab
-
 			// The Key Pairs table's data model
 			KeyPairsTableModel keyPairsTableModel = new KeyPairsTableModel(credManager);
 			// The table itself
 			table = new JTable(keyPairsTableModel);
 
-			// Set the alias and service URIs columns of the KayPairs table to
-			// be invisible by removing them from the column model (they will still
-			// present in the table model)
-			// Remove the last column first
+			/*
+			 * Set the alias and service URIs columns of the KayPairs table to
+			 * be invisible by removing them from the column model (they will
+			 * still present in the table model)
+			 * 
+			 * Remove the last column first
+			 */
 			TableColumn aliasColumn = table.getColumnModel().getColumn(6);
 			table.getColumnModel().removeColumn(aliasColumn);
 			TableColumn serviceURIsColumn = table.getColumnModel().getColumn(5);
@@ -410,6 +430,7 @@
 			// Buttons
 			final JButton viewKeyPairButton = new JButton("Details");
 			viewKeyPairButton.addActionListener(new ActionListener() {
+				@Override
 				public void actionPerformed(ActionEvent e) {
 					viewCertificate();
 				}
@@ -418,6 +439,7 @@
 
 			JButton importKeyPairButton = new JButton("Import");
 			importKeyPairButton.addActionListener(new ActionListener() {
+				@Override
 				public void actionPerformed(ActionEvent e) {
 					importKeyPair();
 				}
@@ -425,6 +447,7 @@
 
 			final JButton exportKeyPairButton = new JButton("Export");
 			exportKeyPairButton.addActionListener(new ActionListener() {
+				@Override
 				public void actionPerformed(ActionEvent e) {
 					exportKeyPair();
 				}
@@ -433,38 +456,40 @@
 
 			final JButton deleteKeyPairButton = new JButton("Delete");
 			deleteKeyPairButton.addActionListener(new ActionListener() {
+				@Override
 				public void actionPerformed(ActionEvent e) {
 					deleteKeyPair();
 				}
 			});
 			deleteKeyPairButton.setEnabled(false);
 
-			// Selection listener for key pairs table to enable/disable action buttons accordingly
-			class KeyPairsTableSelectionListner implements ListSelectionListener{
+			/*
+			 * Selection listener for key pairs table to enable/disable action
+			 * buttons accordingly
+			 */
+			class KeyPairsTableSelectionListner implements
+					ListSelectionListener {
 				@Override
 				public void valueChanged(ListSelectionEvent e) {
-					if (e.getSource() == keyPairsTable.getSelectionModel()){
-						if (keyPairsTable.getSelectedRow() == -1){ // nothing is selected
-							viewKeyPairButton.setEnabled(false);
-							exportKeyPairButton.setEnabled(false);
-							deleteKeyPairButton.setEnabled(false);
-						}
-						else{
-							if (!viewKeyPairButton.isEnabled()){
-								viewKeyPairButton.setEnabled(true);
-							}
-							if(!exportKeyPairButton.isEnabled()){
-								exportKeyPairButton.setEnabled(true);
-							}
-							if (!deleteKeyPairButton.isEnabled()){
-								deleteKeyPairButton.setEnabled(true);
-							}
-						}
+					if (e.getSource() != keyPairsTable.getSelectionModel())
+						return;
+					if (keyPairsTable.getSelectedRow() == -1) {
+						// nothing is selected
+						viewKeyPairButton.setEnabled(false);
+						exportKeyPairButton.setEnabled(false);
+						deleteKeyPairButton.setEnabled(false);
+					} else {
+						if (!viewKeyPairButton.isEnabled())
+							viewKeyPairButton.setEnabled(true);
+						if (!exportKeyPairButton.isEnabled())
+							exportKeyPairButton.setEnabled(true);
+						if (!deleteKeyPairButton.isEnabled())
+							deleteKeyPairButton.setEnabled(true);
 					}
-
 				}
 			}
-			table.getSelectionModel().addListSelectionListener(new KeyPairsTableSelectionListner());
+			table.getSelectionModel().addListSelectionListener(
+					new KeyPairsTableSelectionListner());
 
 			// Panel to hold the buttons
 			JPanel bp = new JPanel();
@@ -474,19 +499,21 @@
 			bp.add(deleteKeyPairButton);
 
 			// Add button panel to the tab
-			tab.add(bp, BorderLayout.PAGE_END);
-		}
-		else if (tableType.equals(TRUSTED_CERTIFICATES)) { // Certificates tab
+			tab.add(bp, PAGE_END);
+		} else if (tableType.equals(TRUSTED_CERTIFICATES)) { // Certificates tab
 
 			// The Trusted Certificate table's data model
 			TrustedCertsTableModel trustedCertificatesTableModel = new TrustedCertsTableModel(credManager);
 			// The table itself
 			table = new JTable(trustedCertificatesTableModel);
 
-			// Set the alias columns of the Trusted Certs table to be invisible
-			// by removing them from the column model (they will still be present in the
-			// table model)
-			// Remove the last column first
+			/*
+			 * Set the alias columns of the Trusted Certs table to be invisible
+			 * by removing them from the column model (they will still be
+			 * present in the table model)
+			 * 
+			 * Remove the last column first
+			 */
 			TableColumn aliasColumn = table.getColumnModel().getColumn(5);
 			table.getColumnModel().removeColumn(aliasColumn);
 			TableColumn lastModifiedDateColumn = table.getColumnModel().getColumn(4);
@@ -496,6 +523,7 @@
 			final JButton viewTrustedCertificateButton = new JButton("Details");
 			viewTrustedCertificateButton
 					.addActionListener(new ActionListener() {
+						@Override
 						public void actionPerformed(ActionEvent e) {
 							viewCertificate();
 						}
@@ -505,6 +533,7 @@
 			JButton importTrustedCertificateButton = new JButton("Import");
 			importTrustedCertificateButton
 					.addActionListener(new ActionListener() {
+						@Override
 						public void actionPerformed(ActionEvent e) {
 							importTrustedCertificate();
 						}
@@ -513,6 +542,7 @@
 			final JButton exportTrustedCertificateButton = new JButton("Export");
 			exportTrustedCertificateButton
 					.addActionListener(new ActionListener() {
+						@Override
 						public void actionPerformed(ActionEvent e) {
 							exportTrustedCertificate();
 						}
@@ -522,6 +552,7 @@
 			final JButton deleteTrustedCertificateButton = new JButton("Delete");
 			deleteTrustedCertificateButton
 					.addActionListener(new ActionListener() {
+						@Override
 						public void actionPerformed(ActionEvent e) {
 							deleteTrustedCertificate();
 						}
@@ -529,31 +560,29 @@
 			deleteTrustedCertificateButton.setEnabled(false);
 
 			// Selection listener for trusted certs table to enable/disable action buttons accordingly
-			class TrustedCertsTableSelectionListner implements ListSelectionListener{
+			class TrustedCertsTableSelectionListener implements
+					ListSelectionListener {
 				@Override
 				public void valueChanged(ListSelectionEvent e) {
-					if (e.getSource() == trustedCertsTable.getSelectionModel()){
-						if (trustedCertsTable.getSelectedRow() == -1){ // nothing is selected
-							viewTrustedCertificateButton.setEnabled(false);
-							exportTrustedCertificateButton.setEnabled(false);
-							deleteTrustedCertificateButton.setEnabled(false);
-						}
-						else{
-							if (!viewTrustedCertificateButton.isEnabled()){
-								viewTrustedCertificateButton.setEnabled(true);
-							}
-							if (!exportTrustedCertificateButton.isEnabled()){
-								exportTrustedCertificateButton.setEnabled(true);
-							}
-							if (!deleteTrustedCertificateButton.isEnabled()){
-								deleteTrustedCertificateButton.setEnabled(true);
-							}
-						}
+					if (e.getSource() != trustedCertsTable.getSelectionModel())
+						return;
+					if (trustedCertsTable.getSelectedRow() == -1) {
+						// nothing is selected
+						viewTrustedCertificateButton.setEnabled(false);
+						exportTrustedCertificateButton.setEnabled(false);
+						deleteTrustedCertificateButton.setEnabled(false);
+					} else {
+						if (!viewTrustedCertificateButton.isEnabled())
+							viewTrustedCertificateButton.setEnabled(true);
+						if (!exportTrustedCertificateButton.isEnabled())
+							exportTrustedCertificateButton.setEnabled(true);
+						if (!deleteTrustedCertificateButton.isEnabled())
+							deleteTrustedCertificateButton.setEnabled(true);
 					}
-
 				}
 			}
-			table.getSelectionModel().addListSelectionListener(new TrustedCertsTableSelectionListner());
+			table.getSelectionModel().addListSelectionListener(
+					new TrustedCertsTableSelectionListener());
 
 			// Panel to hold the buttons
 			JPanel bp = new JPanel();
@@ -563,7 +592,7 @@
 			bp.add(deleteTrustedCertificateButton);
 
 			// Add button panel to the tab
-			tab.add(bp, BorderLayout.PAGE_END);
+			tab.add(bp, PAGE_END);
 		} else {
 			throw new RuntimeException("Unknown table type " + tableType);
 		}
@@ -572,7 +601,7 @@
 		table.setRowMargin(0);
 		table.getColumnModel().setColumnMargin(0);
 		table.getTableHeader().setReorderingAllowed(false);
-		table.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
+		table.setAutoResizeMode(AUTO_RESIZE_ALL_COLUMNS);
 		// Top accommodates entry icons with 2 pixels spare space (images are
 		// 16x16 pixels)
 		table.setRowHeight(18);
@@ -603,17 +632,19 @@
 
 		// Put the table into a scroll pane
 		JScrollPane jspTableScrollPane = new JScrollPane(table,
-				JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
-				JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
+				VERTICAL_SCROLLBAR_AS_NEEDED, HORIZONTAL_SCROLLBAR_AS_NEEDED);
 		jspTableScrollPane.getViewport().setBackground(table.getBackground());
 
 		// Put the scroll pane on the tab panel
-		tab.add(jspTableScrollPane, BorderLayout.CENTER);
+		tab.add(jspTableScrollPane, CENTER);
 		jspTableScrollPane.setBorder(new EmptyBorder(3, 3, 3, 3));
 
-		// Add mouse listeners to show an entry's details if it is
-		// double-clicked
+		/*
+		 * Add mouse listeners to show an entry's details if it is
+		 * double-clicked
+		 */
 		table.addMouseListener(new MouseAdapter() {
+			@Override
 			public void mouseClicked(MouseEvent evt) {
 				tableDoubleClick(evt);
 			}
@@ -632,17 +663,18 @@
 	private void viewPassword() {
 		// Which username/password pair entry has been selected, if any?
 		int iRow = passwordsTable.getSelectedRow();
-		if (iRow == -1) { // no row currently selected
+		if (iRow == -1) // no row currently selected
 			return;
-		}
 
 		// Get current values for service URI, username and password
 		String serviceURI = (String) passwordsTable.getValueAt(iRow, 1); // current entry's service URI
 
 		String username = (String) passwordsTable.getValueAt(iRow, 2); // current entry's username
 
-		// Because the password column is not visible we call
-		// the getValueAt method on the table model rather than at the JTable
+		/*
+		 * Because the password column is not visible we call the getValueAt
+		 * method on the table model rather than at the JTable
+		 */
 		String password = (String) passwordsTable.getModel()
 				.getValueAt(iRow, 4); // current entry's password value
 
@@ -659,16 +691,16 @@
 	 * Keystore.
 	 */
 	private void newPassword() {
-
 		URI serviceURI = null; // service URI
 		String username = null; // username
 		String password = null; // password
 
 		// Loop until the user cancels or enters everything correctly
 		while (true) {
-
-			// Let the user insert a new password entry (by specifying service
-			// URI, username and password)
+			/*
+			 * Let the user insert a new password entry (by specifying service
+			 * URI, username and password)
+			 */
 			NewEditPasswordEntryDialog newPasswordDialog = new NewEditPasswordEntryDialog(
 					this, "New username and password for a service", true,
 					serviceURI, username, password, credManager);
@@ -685,64 +717,67 @@
 				return;
 			}
 
-			// Check if a password entry with the given service URI
-			// already exists in the Keystore.
-			// We ask this here as the user may wish to overwrite the
-			// existing password entry.
-			// Checking for key pair entries' URIs is done in the
-			// NewEditPasswordEntry dialog.
+			/*
+			 * Check if a password entry with the given service URI already
+			 * exists in the Keystore. We ask this here as the user may wish to
+			 * overwrite the existing password entry. Checking for key pair
+			 * entries' URIs is done in the NewEditPasswordEntry dialog.
+			 */
 
-			// Get list of service URIs for all the password entries in the
-			// Keystore
+			/*
+			 * Get list of service URIs for all the password entries in the
+			 * Keystore
+			 */
 			List<URI> serviceURIs = null;
 			try {
 				serviceURIs = credManager
 						.getServiceURIsForAllUsernameAndPasswordPairs();
 			} catch (CMException cme) {
-				String exMessage = "Failed to get service URIs for all username and password pairs to check if the entered service URI already exists";
-				JOptionPane.showMessageDialog(this, exMessage,
-						"Credential Manager Error", JOptionPane.ERROR_MESSAGE);
+				showMessageDialog(this, "Failed to get service URIs for all username and password pairs "
+						+ "to check if the entered service URI already exists",
+						ERROR_TITLE, ERROR_MESSAGE);
 				return;
 			}
 			if (serviceURIs.contains(serviceURI)) { // if such a URI already
 				// exists
 				// Ask if the user wants to overwrite it
-				int answer = JOptionPane
-						.showConfirmDialog(
+				int answer = showConfirmDialog(
 								this,
 								"Credential Manager already contains a password entry with the same service URI.\n"
 										+ "Do you want to overwrite it?",
-								"Credential Manager Alert",
-								JOptionPane.YES_NO_OPTION);
+								ALERT_TITLE,
+								YES_NO_OPTION);
 
 				// Add the new password entry in the Keystore
-				if (answer == JOptionPane.YES_OPTION) {
-					try {
-						credManager.addUsernameAndPasswordForService(new UsernamePassword(username,
-								password), serviceURI);
+				try {
+					if (answer == YES_OPTION) {
+						credManager.addUsernameAndPasswordForService(
+								new UsernamePassword(username, password),
+								serviceURI);
 						break;
-					} catch (CMException cme) {
-						String exMessage = "Credential Manager failed to insert a new username and password pair";
-						JOptionPane.showMessageDialog(this, exMessage,
-								"Credential Manager Error",
-								JOptionPane.ERROR_MESSAGE);
 					}
+				} catch (CMException cme) {
+					showMessageDialog(
+							this,
+							"Credential Manager failed to insert a new username and password pair",
+							ERROR_TITLE, ERROR_MESSAGE);
 				}
-				// Otherwise show the same window with the entered service
-				// URI, username and password values
-			} else {
+				/*
+				 * Otherwise show the same window with the entered service URI,
+				 * username and password values
+				 */
+			} else
 				// Add the new password entry in the Keystore
 				try {
 					credManager.addUsernameAndPasswordForService(new UsernamePassword(username,
 							password), serviceURI);
 					break;
 				} catch (CMException cme) {
-					String exMessage = "Credential Manager failed to insert a new username and password pair";
-					JOptionPane.showMessageDialog(this, exMessage,
-							"Credential Manager Error",
-							JOptionPane.ERROR_MESSAGE);
+					showMessageDialog(
+							this,
+							"Credential Manager failed to insert a new username and password pair",
+							ERROR_TITLE, ERROR_MESSAGE);
 				}
-			}
 		}
 	}
 
@@ -751,15 +786,15 @@
 	 * to the Keystore.
 	 */
 	public void newPasswordForService(URI serviceURI) {
-
-		// As this method can be called from outside of Credential Manager UI,
-		// e.g. from wsdl-activity-ui or rshell-activity-ui to pop up a dialog to
-		// ask the user for username and password, we also want to make sure the
-		// main Credential Manager UI Dialog is visible as it may be clearer to the
-		// user what is going on
-		if (!this.isVisible() || this.getState()==Frame.ICONIFIED){
-			this.setVisible(true);
-		}
+		/*
+		 * As this method can be called from outside of Credential Manager UI,
+		 * e.g. from wsdl-activity-ui or rshell-activity-ui to pop up a dialog
+		 * to ask the user for username and password, we also want to make sure
+		 * the main Credential Manager UI Dialog is visible as it may be clearer
+		 * to the user what is going on
+		 */
+		if (!isVisible() || getState() == ICONIFIED)
+			setVisible(true);
 
 		// Make sure password tab is selected as this method may
 		// be called from outside of Credential Manager UI.
@@ -787,18 +822,17 @@
 			username = newPasswordDialog.getUsername(); // get username
 			password = newPasswordDialog.getPassword(); // get password
 
-			if (password == null) { // user cancelled - any of the above three
+			if (password == null) // user cancelled - any of the above three
 				// fields is null
 				// do nothing
 				return;
-			}
 
-			// Check if a password entry with the given service URI
-			// already exists in the Keystore.
-			// We ask this here as the user may wish to overwrite the
-			// existing password entry.
-			// Checking for key pair entries' URIs is done in the
-			// NewEditPasswordEntry dialog.
+			/*
+			 * Check if a password entry with the given service URI already
+			 * exists in the Keystore. We ask this here as the user may wish to
+			 * overwrite the existing password entry. Checking for key pair
+			 * entries' URIs is done in the NewEditPasswordEntry dialog.
+			 */
 
 			// Get list of service URIs for all the password entries in the
 			// Keystore
@@ -807,50 +841,46 @@
 				serviceURIs = credManager
 						.getServiceURIsForAllUsernameAndPasswordPairs();
 			} catch (CMException cme) {
-				String exMessage = "Failed to get service URIs for all username and password pairs to check if the entered service URI already exists";
-				JOptionPane.showMessageDialog(this, exMessage,
-						"Credential Manager Error", JOptionPane.ERROR_MESSAGE);
+				showMessageDialog(this, "Failed to get service URIs for all username and password pairs "
+						+ "to check if the entered service URI already exists",
+						ERROR_TITLE, ERROR_MESSAGE);
 				return;
 			}
 			if (serviceURIs.contains(serviceURI)) { // if such a URI already
 				// exists
 				// Ask if the user wants to overwrite it
-				int answer = JOptionPane
-						.showConfirmDialog(
-								this,
-								"Credential Manager already contains a password entry with the same service URI.\n"
-										+ "Do you want to overwrite it?",
-								"Credential Manager Alert",
-								JOptionPane.YES_NO_OPTION);
+				int answer = showConfirmDialog(
+						this,
+						"Credential Manager already contains a password entry with the same service URI.\n"
+								+ "Do you want to overwrite it?", ALERT_TITLE,
+						YES_NO_OPTION);
 
 				// Add the new password entry in the Keystore
-				if (answer == JOptionPane.YES_OPTION) {
-					try {
-						credManager.addUsernameAndPasswordForService(new UsernamePassword(username,
-								password), serviceURI);
+				try {
+					if (answer == YES_OPTION) {
+						credManager.addUsernameAndPasswordForService(
+								new UsernamePassword(username, password),
+								serviceURI);
 						break;
-					} catch (CMException cme) {
-						String exMessage = "Credential Manager failed to insert a new username and password pair";
-						JOptionPane.showMessageDialog(this, exMessage,
-								"Credential Manager Error",
-								JOptionPane.ERROR_MESSAGE);
 					}
+				} catch (CMException cme) {
+					String exMessage = "Credential Manager failed to insert a new username and password pair";
+					showMessageDialog(this, exMessage, ERROR_TITLE,
+							ERROR_MESSAGE);
 				}
 				// Otherwise show the same window with the entered service
 				// URI, username and password values
-			} else {
+			} else
 				// Add the new password entry in the Keystore
 				try {
 					credManager.addUsernameAndPasswordForService(new UsernamePassword(username,
 							password), serviceURI);
 					break;
 				} catch (CMException cme) {
-					String exMessage = "Credential Manager failed to insert a new username and password pair";
-					JOptionPane.showMessageDialog(this, exMessage,
-							"Credential Manager Error",
-							JOptionPane.ERROR_MESSAGE);
+					showMessageDialog(this, "Credential Manager failed to insert a new username and password pair",
+							ERROR_TITLE,
+							ERROR_MESSAGE);
 				}
-			}
 		}
 	}
 
@@ -859,7 +889,6 @@
 	 * URI to the Keystore.
 	 */
 	private void editPassword() {
-
 		// Which password entry has been selected?
 		int iRow = passwordsTable.getSelectedRow();
 		if (iRow == -1) { // no row currently selected
@@ -871,8 +900,10 @@
 
 		String username = (String) passwordsTable.getValueAt(iRow, 2); // current entry's username
 
-		// Because the password column is not visible we call
-		// the getValueAt method on the table model rather than at the JTable
+		/*
+		 * Because the password column is not visible we call the getValueAt
+		 * method on the table model rather than at the JTable
+		 */
 		String password = (String) passwordsTable.getModel()
 				.getValueAt(iRow, 4); // current entry's password value
 
@@ -890,22 +921,22 @@
 			String newUsername = editPasswordDialog.getUsername(); // get new username
 			String newPassword = editPasswordDialog.getPassword(); // get new password
 
-			if (newPassword == null) { // user cancelled - any of the above three
+			if (newPassword == null) // user cancelled - any of the above three
 				// fields is null
 				// do nothing
 				return;
-			}
 
 			// Is anything actually modified?
-			boolean isModified = (!serviceURI.equals(newServiceURI)
-					|| !username.equals(newUsername) || !password
-					.equals(newPassword));
+			boolean isModified = !serviceURI.equals(newServiceURI)
+					|| !username.equals(newUsername)
+					|| !password.equals(newPassword);
 
 			if (isModified) {
-				// Check if a different password entry with the new URI
-				// (i.e. alias) already exists in the Keystore
-				// We ask this here as the user may wish to overwrite that
-				// other password entry.
+				/*
+				 * Check if a different password entry with the new URI (i.e.
+				 * alias) already exists in the Keystore We ask this here as the
+				 * user may wish to overwrite that other password entry.
+				 */
 
 				// Get list of URIs for all passwords in the Keystore
 				List<URI> serviceURIs = null;
@@ -913,66 +944,62 @@
 					serviceURIs = credManager
 							.getServiceURIsForAllUsernameAndPasswordPairs();
 				} catch (CMException cme) {
-					String exMessage = "Failed to get service URIs for all username and password pairs to check if the modified entry already exists";
-					JOptionPane.showMessageDialog(this, exMessage,
-							"Credential Manager Error",
-							JOptionPane.ERROR_MESSAGE);
+					showMessageDialog(this, "Failed to get service URIs for all username and password pairs "
+							+ "to check if the modified entry already exists",
+							ERROR_TITLE,
+							ERROR_MESSAGE);
 					return;
 				}
 
 				// If the modified service URI already exists and is not the
 				// currently selected one
-				if ((!newServiceURI.equals(serviceURI))
+				if (!newServiceURI.equals(serviceURI)
 						&& serviceURIs.contains(newServiceURI)) {
+					int answer = showConfirmDialog(
+							this,
+							"The Keystore already contains username and password pair for the entered service URI.\n"
+									+ "Do you want to overwrite it?",
+							ALERT_TITLE, YES_NO_OPTION);
 
-					int answer = JOptionPane
-							.showConfirmDialog(
-									this,
-									"The Keystore already contains username and password pair for the entered service URI.\n"
-											+ "Do you want to overwrite it?",
-									"Credential Manager Alert",
-									JOptionPane.YES_NO_OPTION);
-
-					if (answer == JOptionPane.YES_OPTION) {
-
-						// Overwrite that other entry entry and save the new
-						// one in its place.
-						// Also remove the current one that we are editing -
-						// as it is replacing the other entry.
-						try {
+					try {
+						if (answer == YES_OPTION) {
+							/*
+							 * Overwrite that other entry entry and save the new
+							 * one in its place. Also remove the current one
+							 * that we are editing - as it is replacing the
+							 * other entry.
+							 */
 							credManager
 									.deleteUsernameAndPasswordForService(serviceURI);
 							credManager.addUsernameAndPasswordForService(
-									new UsernamePassword(newUsername, newPassword), newServiceURI);
+									new UsernamePassword(newUsername,
+											newPassword), newServiceURI);
 							break;
-						} catch (CMException cme) {
-							String exMessage = "Failed to update the username and password pair in the Keystore";
-							JOptionPane.showMessageDialog(this, exMessage,
-									"Credential Manager Error",
-									JOptionPane.ERROR_MESSAGE);
 						}
+					} catch (CMException cme) {
+						showMessageDialog(
+								this,
+								"Failed to update the username and password pair in the Keystore",
+								ERROR_TITLE, ERROR_MESSAGE);
 					}
 					// Otherwise show the same window with the entered
 					// service URI, username and password values
-				} else {
+				} else
 					try {
-						if (!newServiceURI.equals(serviceURI)) {
+						if (!newServiceURI.equals(serviceURI))
 							credManager
 									.deleteUsernameAndPasswordForService(serviceURI);
-						}
 						credManager.addUsernameAndPasswordForService(
 								new UsernamePassword(newUsername, newPassword), newServiceURI);
 						break;
 					} catch (CMException cme) {
-						String exMessage = "Failed to update the username and password pair in the Keystore";
-						JOptionPane.showMessageDialog(this, exMessage,
-								"Credential Manager Error",
-								JOptionPane.ERROR_MESSAGE);
+						showMessageDialog(
+								this,
+								"Failed to update the username and password pair in the Keystore",
+								ERROR_TITLE, ERROR_MESSAGE);
 					}
-				}
-			} else { // nothing actually modified
+			} else // nothing actually modified
 				break;
-			}
 		}
 	}
 
@@ -981,46 +1008,38 @@
 	 * Keystore.
 	 */
 	private void deletePassword() {
-
 		// Which entries have been selected?
 		int[] selectedRows = passwordsTable.getSelectedRows();
-		if (selectedRows.length == 0) { // no password entry selected
+		if (selectedRows.length == 0) // no password entry selected
 			return;
-		}
 
 		// Ask user to confirm the deletion
-		int answer = JOptionPane
-				.showConfirmDialog(
-						null,
-						"Are you sure you want to delete the selected username and password entries?",
-						"Credential Manager Alert", JOptionPane.YES_NO_OPTION);
-
-		if (answer != JOptionPane.YES_OPTION) {
+		if (showConfirmDialog(
+				null,
+				"Are you sure you want to delete the selected username and password entries?",
+				ALERT_TITLE, YES_NO_OPTION) != YES_OPTION)
 			return;
-		}
 
+		String exMessage = null;
 		for (int i = selectedRows.length - 1; i >= 0; i--) { // delete from backwards
 			// Get service URI for the current entry
-			URI serviceURI = URI.create((String) passwordsTable.getValueAt(selectedRows[i], 1)); // current
-			// entry's
-			// service
-			// URI
+			URI serviceURI = URI.create((String) passwordsTable.getValueAt(selectedRows[i], 1));
+			// current entry's service URI
 			try {
 				// Delete the password entry from the Keystore
 				credManager.deleteUsernameAndPasswordForService(serviceURI);
 			} catch (CMException cme) {
-				String exMessage = "Failed to delete the username and password pair from the Keystore";
-				JOptionPane.showMessageDialog(this, exMessage,
-						"Credential Manager Error", JOptionPane.ERROR_MESSAGE);
+				exMessage = "Failed to delete the username and password pair from the Keystore";
 			}
 		}
+		if (exMessage != null)
+			showMessageDialog(this, exMessage, ERROR_TITLE, ERROR_MESSAGE);
 	}
 
 	/**
 	 * Shows the contents of a (user or trusted) certificate.
 	 */
 	private void viewCertificate() {
-
 		int selectedRow = -1;
 		String alias = null;
 		X509Certificate certToView = null;
@@ -1029,33 +1048,34 @@
 
 		// Are we showing user's public key certificate?
 		if (keyPairsTab.isShowing()) {
-			keystoreType = KeystoreType.KEYSTORE;
+			keystoreType = KEYSTORE;
 			selectedRow = keyPairsTable.getSelectedRow();
 
-			if (selectedRow != -1) {
-				// Because the alias column is not visible we call the
-				// getValueAt method on the table model rather than at the
-				// JTable
+			if (selectedRow != -1)
+				/*
+				 * Because the alias column is not visible we call the
+				 * getValueAt method on the table model rather than at the
+				 * JTable
+				 */
 				alias = (String) keyPairsTable.getModel().getValueAt(selectedRow, 6); // current entry's Keystore alias
-			}
 		}
 		// Are we showing trusted certificate?
 		else if (trustedCertificatesTab.isShowing()) {
-			keystoreType = KeystoreType.TRUSTSTORE;
+			keystoreType = TRUSTSTORE;
 			selectedRow = trustedCertsTable.getSelectedRow();
 
-			if (selectedRow != -1) {
-
-				// Get the selected trusted certificate entry's Truststore alias
-				// Alias column is invisible so we get the value from the table
-				// model
-				alias = (String) trustedCertsTable.getModel().getValueAt(selectedRow,
-						5);
-			}
+			if (selectedRow != -1)
+				/*
+				 * Get the selected trusted certificate entry's Truststore alias
+				 * Alias column is invisible so we get the value from the table
+				 * model
+				 */
+				alias = (String) trustedCertsTable.getModel().getValueAt(
+						selectedRow, 5);
 		}
 
-		if (selectedRow != -1) { // something has been selected
-			try {
+		try {
+			if (selectedRow != -1) { // something has been selected
 				// Get the entry's certificate
 				certToView = dnParser.convertCertificate(credManager
 						.getCertificate(keystoreType, alias));
@@ -1066,12 +1086,11 @@
 						serviceURIs, dnParser);
 				viewCertDetailsDialog.setLocationRelativeTo(this);
 				viewCertDetailsDialog.setVisible(true);
-			} catch (CMException cme) {
-				String exMessage = "Failed to get certificate details to display to the user";
-				logger.error(exMessage);
-				JOptionPane.showMessageDialog(this, exMessage,
-						"Credential Manager Error", JOptionPane.ERROR_MESSAGE);
 			}
+		} catch (CMException cme) {
+			String exMessage = "Failed to get certificate details to display to the user";
+			logger.error(exMessage, cme);
+			showMessageDialog(this, exMessage, ERROR_TITLE, ERROR_MESSAGE);
 		}
 	}
 
@@ -1080,9 +1099,10 @@
 	 * Keystore.
 	 */
 	private void importKeyPair() {
-
-		// Let the user choose a PKCS #12 file (keystore) containing a public
-		// and private key pair to import
+		/*
+		 * Let the user choose a PKCS #12 file (keystore) containing a public
+		 * and private key pair to import
+		 */
 		File importFile = selectImportExportFile(
 				"PKCS #12 file to import from", // title
 				new String[] { ".p12", ".pfx" }, // array of file extensions
@@ -1091,14 +1111,13 @@
 				"Import", // text for the file chooser's approve button
 				"keyPairDir"); // preference string for saving the last chosen directory
 
-		if (importFile == null) {
+		if (importFile == null)
 			return;
-		}
 
 		// The PKCS #12 keystore is not a file
 		if (!importFile.isFile()) {
-			JOptionPane.showMessageDialog(this, "Your selection is not a file",
-					"Credential Manager Alert", JOptionPane.WARNING_MESSAGE);
+			showMessageDialog(this, "Your selection is not a file",
+					ALERT_TITLE, WARNING_MESSAGE);
 			return;
 		}
 
@@ -1112,13 +1131,11 @@
 
 		String pkcs12Password = getPasswordDialog.getPassword();
 
-		if (pkcs12Password == null) { // user cancelled
+		if (pkcs12Password == null) // user cancelled
 			return;
-		} else if (pkcs12Password.length() == 0) { // empty password
-			// FIXME: Maybe user did not have the password set for the private
-			// key???
+		else if (pkcs12Password.isEmpty()) // empty password
+			// FIXME: Maybe user did not have the password set for the private key???
 			return;
-		}
 
 		try {
 			// Load the PKCS #12 keystore from the file
@@ -1126,9 +1143,12 @@
 			KeyStore pkcs12Keystore = credManager.loadPKCS12Keystore(importFile,
 					pkcs12Password);
 
-			// Display the import key pair dialog supplying all the private keys
-			// stored in the PKCS #12 file (normally there will be only one private
-			// key inside, but could be more as this is a keystore after all).
+			/*
+			 * Display the import key pair dialog supplying all the private keys
+			 * stored in the PKCS #12 file (normally there will be only one
+			 * private key inside, but could be more as this is a keystore after
+			 * all).
+			 */
 			NewKeyPairEntryDialog importKeyPairDialog = new NewKeyPairEntryDialog(
 					this, "Credential Manager", true, pkcs12Keystore, dnParser);
 			importKeyPairDialog.setLocationRelativeTo(this);
@@ -1138,40 +1158,32 @@
 			Key privateKey = importKeyPairDialog.getPrivateKey();
 			Certificate[] certChain = importKeyPairDialog.getCertificateChain();
 
-			if (privateKey == null || certChain == null) {
+			if (privateKey == null || certChain == null)
 				// User did not select a key pair for import or cancelled
 				return;
-			}
 
-			// Check if a key pair entry with the same alias already exists in
-			// the Keystore
-			if (credManager.hasKeyPair(privateKey, certChain)) {
-				int answer = JOptionPane
-						.showConfirmDialog(
-								this,
-								"The keystore already contains the key pair entry with the same private key.\nDo you want to overwrite it?",
-								"Credential Manager Alert",
-								JOptionPane.YES_NO_OPTION);
-
-				if (answer != JOptionPane.YES_OPTION) {
-					return;
-				}
-			}
+			/*
+			 * Check if a key pair entry with the same alias already exists in
+			 * the Keystore
+			 */
+			if (credManager.hasKeyPair(privateKey, certChain)
+					&& showConfirmDialog(this,
+							"The keystore already contains the key pair entry with the same private key.\n"
+									+ "Do you want to overwrite it?",
+							ALERT_TITLE, YES_NO_OPTION) != YES_OPTION)
+				return;
 
 			// Place the private key and certificate chain into the Keystore
 			credManager.addKeyPair(privateKey, certChain);
 
 			// Display success message
-			JOptionPane
-					.showMessageDialog(this, "Key pair import successful",
-							"Credential Manager Alert",
-							JOptionPane.INFORMATION_MESSAGE);
+			showMessageDialog(this, "Key pair import successful", ALERT_TITLE,
+					INFORMATION_MESSAGE);
 		} catch (Exception ex) { // too many exceptions to catch separately
 			String exMessage = "Failed to import the key pair entry to the Keystore. "
 					+ ex.getMessage();
 			logger.error(exMessage, ex);
-			JOptionPane.showMessageDialog(this, exMessage,
-					"Credential Manager Error", JOptionPane.ERROR_MESSAGE);
+			showMessageDialog(this, exMessage, ERROR_TITLE, ERROR_MESSAGE);
 		}
 	}
 
@@ -1180,12 +1192,10 @@
 	 * keystore file.
 	 */
 	private void exportKeyPair() {
-
 		// Which key pair entry has been selected?
 		int selectedRow = keyPairsTable.getSelectedRow();
-		if (selectedRow == -1) { // no row currently selected
+		if (selectedRow == -1) // no row currently selected
 			return;
-		}
 
 		// Get the key pair entry's Keystore alias
 		String alias = (String) keyPairsTable.getModel().getValueAt(selectedRow, 6);
@@ -1199,23 +1209,16 @@
 				"Export", // text for the file chooser's approve button
 				"keyPairDir"); // preference string for saving the last chosen directory
 
-		if (exportFile == null) {
+		if (exportFile == null)
 			return;
-		}
 
 		// If file already exist - ask the user if he wants to overwrite it
-		if (exportFile.isFile()) {
-			int answer = JOptionPane
-					.showConfirmDialog(
-							this,
-							"The file with the given name already exists.\nDo you want to overwrite it?",
-							"Credential Manager Alert",
-							JOptionPane.YES_NO_OPTION);
-
-			if (answer == JOptionPane.NO_OPTION) {
-				return;
-			}
-		}
+		if (exportFile.isFile()
+				&& showConfirmDialog(this,
+						"The file with the given name already exists.\n"
+								+ "Do you want to overwrite it?", ALERT_TITLE,
+						YES_NO_OPTION) == NO_OPTION)
+			return;
 
 		// Get the user to enter the password for the PKCS #12 keystore file
 		GetPasswordDialog getPasswordDialog = new GetPasswordDialog(this,
@@ -1228,25 +1231,21 @@
 
 		if (pkcs12Password == null) { // user cancelled or empty password
 			// Warn the user
-			JOptionPane
-					.showMessageDialog(
-							this,
-							"You must supply a password for protecting the exported key pair.",
-							"Credential Manager Alert",
-							JOptionPane.INFORMATION_MESSAGE);
+			showMessageDialog(
+					this,
+					"You must supply a password for protecting the exported key pair.",
+					ALERT_TITLE, INFORMATION_MESSAGE);
 			return;
 		}
 
 		// Export the key pair
 		try {
 			credManager.exportKeyPair(alias, exportFile, pkcs12Password);
-			JOptionPane
-					.showMessageDialog(this, "Key pair export successful",
-							"Credential Manager Alert",
-							JOptionPane.INFORMATION_MESSAGE);
+			showMessageDialog(this, "Key pair export successful", ALERT_TITLE,
+					INFORMATION_MESSAGE);
 		} catch (CMException cme) {
-			JOptionPane.showMessageDialog(this, cme.getMessage(),
-					"Credential Manager Error", JOptionPane.ERROR_MESSAGE);
+			showMessageDialog(this, cme.getMessage(), ERROR_TITLE,
+					ERROR_MESSAGE);
 		}
 	}
 
@@ -1254,22 +1253,18 @@
 	 * Lets a user delete selected key pair entries from the Keystore.
 	 */
 	private void deleteKeyPair() {
-
 		// Which entries have been selected?
 		int[] selectedRows = keyPairsTable.getSelectedRows();
-		if (selectedRows.length == 0) { // no key pair entry selected
+		if (selectedRows.length == 0) // no key pair entry selected
 			return;
-		}
 
 		// Ask user to confirm the deletion
-		int answer = JOptionPane.showConfirmDialog(null,
+		if (showConfirmDialog(null,
 				"Are you sure you want to delete the selected key pairs?",
-				"Credential Manager Alert", JOptionPane.YES_NO_OPTION);
-
-		if (answer != JOptionPane.YES_OPTION) {
+				ALERT_TITLE, YES_NO_OPTION) != YES_OPTION)
 			return;
-		}
 
+		String exMessage = null;
 		for (int i = selectedRows.length - 1; i >= 0; i--) { // delete from backwards
 			// Get the alias for the current entry
 			String alias = (String) keyPairsTable.getModel().getValueAt(
@@ -1278,11 +1273,12 @@
 				// Delete the key pair entry from the Keystore
 				credManager.deleteKeyPair(alias);
 			} catch (CMException cme) {
-				String exMessage = "Failed to delete the key pair(s) from the Keystore";
-				JOptionPane.showMessageDialog(this, exMessage,
-						"Credential Manager Error", JOptionPane.ERROR_MESSAGE);
+				logger.warn("failed to delete " + alias, cme);
+				exMessage = "Failed to delete the key pair(s) from the Keystore";
 			}
 		}
+		if (exMessage != null)
+			showMessageDialog(this, exMessage, ERROR_TITLE, ERROR_MESSAGE);
 	}
 
 	/**
@@ -1298,67 +1294,53 @@
 				"Certificate Files (*.pem, *.crt, , *.cer, *.der, *.p7, *.p7c)", // filter descriptions
 				"Import", // text for the file chooser's approve button
 				"trustedCertDir"); // preference string for saving the last chosen directory
-
-		if (certFile == null) {
+		if (certFile == null)
 			return;
-		}
 
 		// Load the certificate(s) from the file
-		ArrayList<X509Certificate> trustCertsList = new ArrayList<X509Certificate>();
-		FileInputStream fis = null;
-
+		ArrayList<X509Certificate> trustCertsList = new ArrayList<>();
+		CertificateFactory cf;
 		try {
-			fis = new FileInputStream(certFile);
-			CertificateFactory cf = CertificateFactory.getInstance("X.509");
-			Collection<? extends Certificate> c = cf.generateCertificates(fis);
-			Iterator<? extends Certificate> i = c.iterator();
-			while (i.hasNext()) {
-				trustCertsList.add((X509Certificate) i.next());
-			}
-		} catch (Exception cex) {
-			// Do nothing
-		} finally {
-			try {
-				fis.close();
-			} catch (Exception ex) {
-				// ignore
-			}
+			cf = CertificateFactory.getInstance("X.509");
+		} catch (Exception e) {
+			// Nothing we can do! Things are badly misconfigured
+			cf = null;
 		}
 
-		if (trustCertsList.size() == 0) { // Could not load certificates as
-			// any of the above types
-			try {
-				// Try as openssl PEM format - which sligtly differs from the
-				// one supported by JCE
-				fis = new FileInputStream(certFile);
-				CertificateFactory cf = CertificateFactory.getInstance("X.509");
-				PEMReader pr = new PEMReader(new InputStreamReader(fis), null,
-						cf.getProvider().getName());
-				Object cert;
-				while ((cert = pr.readObject()) != null) {
-					if (cert instanceof X509Certificate) {
-						trustCertsList.add((X509Certificate) cert);
-					}
-				}
+		if (cf != null) {
+			try (FileInputStream fis = new FileInputStream(certFile)) {
+				for (Certificate cert : cf.generateCertificates(fis))
+					trustCertsList.add((X509Certificate) cert);
 			} catch (Exception cex) {
-				// do nothing
-			} finally {
-				try {
-					fis.close();
-				} catch (Exception ex) {
-					// ignore
+				// Do nothing
+			}
+
+			if (trustCertsList.size() == 0) {
+				// Could not load certificates as any of the above types
+				try (FileInputStream fis = new FileInputStream(certFile);
+						PEMReader pr = new PEMReader(
+								new InputStreamReader(fis), null, cf
+										.getProvider().getName())) {
+					/*
+					 * Try as openssl PEM format - which sligtly differs from
+					 * the one supported by JCE
+					 */
+					Object cert;
+					while ((cert = pr.readObject()) != null)
+						if (cert instanceof X509Certificate)
+							trustCertsList.add((X509Certificate) cert);
+				} catch (Exception cex) {
+					// do nothing
 				}
 			}
 		}
 
-		if (trustCertsList.size() == 0) { // Failed to load certifcate(s)
-			// using any of the known encodings
-			JOptionPane
-					.showMessageDialog(
-							this,
-							"Failed to load certificate(s) using any of the known encodings -\nfile format not recognised.",
-							"Credential Manager Error",
-							JOptionPane.ERROR_MESSAGE);
+		if (trustCertsList.size() == 0) {
+			/* Failed to load certifcate(s) using any of the known encodings */
+			showMessageDialog(this,
+					"Failed to load certificate(s) using any of the known encodings -\n"
+							+ "file format not recognised.", ERROR_TITLE,
+					ERROR_MESSAGE);
 			return;
 		}
 
@@ -1369,31 +1351,25 @@
 
 		importTrustCertsDialog.setLocationRelativeTo(this);
 		importTrustCertsDialog.setVisible(true);
-		ArrayList<X509Certificate> selectedTrustCerts = importTrustCertsDialog
+		List<X509Certificate> selectedTrustCerts = importTrustCertsDialog
 				.getTrustedCertificates(); // user-selected trusted certs to import
 
 		// If user cancelled or did not select any cert to import
-		if ((selectedTrustCerts) == null || (selectedTrustCerts.size() == 0)) {
+		if (selectedTrustCerts == null || selectedTrustCerts.isEmpty())
 			return;
-		}
 
 		try {
-			for (int i = selectedTrustCerts.size() - 1; i >= 0; i--) {
+			for (X509Certificate cert : selectedTrustCerts)
 				// Import the selected trusted certificates
-				credManager.addTrustedCertificate(selectedTrustCerts.get(i));
-			}
+				credManager.addTrustedCertificate(cert);
 
 			// Display success message
-			JOptionPane
-					.showMessageDialog(this,
-							"Trusted certificate(s) import successful",
-							"Credential Manager Alert",
-							JOptionPane.INFORMATION_MESSAGE);
+			showMessageDialog(this, "Trusted certificate(s) import successful",
+					ALERT_TITLE, INFORMATION_MESSAGE);
 		} catch (CMException cme) {
 			String exMessage = "Failed to import trusted certificate(s) to the Truststore";
-			logger.error(exMessage);
-			JOptionPane.showMessageDialog(this, exMessage,
-					"Credential Manager Error", JOptionPane.ERROR_MESSAGE);
+			logger.error(exMessage, cme);
+			showMessageDialog(this, exMessage, ERROR_TITLE, ERROR_MESSAGE);
 		}
 	}
 
@@ -1402,12 +1378,10 @@
 	 * certificate entries to a PEM-encoded file.
 	 */
 	private boolean exportTrustedCertificate() {
-
 		// Which trusted certificate has been selected?
 		int selectedRow = trustedCertsTable.getSelectedRow();
-		if (selectedRow == -1) { // no row currently selected
+		if (selectedRow == -1) // no row currently selected
 			return false;
-		}
 
 		// Get the trusted certificate entry's Keystore alias
 		String alias = (String) trustedCertsTable.getModel()
@@ -1422,56 +1396,30 @@
 				"Certificate Files (*.pem)", // description of the filter
 				"Export", // text for the file chooser's approve button
 				"trustedCertDir"); // preference string for saving the last chosen directory
-
-		if (exportFile == null) {
+		if (exportFile == null)
 			return false;
-		}
 
 		// If file already exist - ask the user if he wants to overwrite it
-		if (exportFile.isFile()) {
-			int answer = JOptionPane
-					.showConfirmDialog(
-							this,
-							"The file with the given name already exists.\nDo you want to overwrite it?",
-							"Credential Manager Alert",
-							JOptionPane.YES_NO_OPTION);
-
-			if (answer == JOptionPane.NO_OPTION) {
-				return false;
-			}
-		}
+		if (exportFile.isFile()
+				&& showConfirmDialog(this,
+						"The file with the given name already exists.\n"
+								+ "Do you want to overwrite it?", ALERT_TITLE,
+						YES_NO_OPTION) == NO_OPTION)
+			return false;
 
 		// Export the trusted certificate
-		PEMWriter pw = null;
-		try {
+		try (PEMWriter pw = new PEMWriter(new FileWriter(exportFile))) {
 			// Get the trusted certificate
-			Certificate certToExport = credManager.getCertificate(
-					KeystoreType.TRUSTSTORE, alias);
-			pw = new PEMWriter(new FileWriter(exportFile));
-			pw.writeObject(certToExport);
-
-			JOptionPane
-					.showMessageDialog(this,
-							"Trusted certificate export successful",
-							"Credential Manager Alert",
-							JOptionPane.INFORMATION_MESSAGE);
-
-			return true;
+			pw.writeObject(credManager.getCertificate(TRUSTSTORE, alias));
 		} catch (Exception ex) {
 			String exMessage = "Failed to export the trusted certificate from the Truststore.";
-			logger.error(exMessage);
-			JOptionPane.showMessageDialog(this, exMessage,
-					"Credential Manager Error", JOptionPane.ERROR_MESSAGE);
+			logger.error(exMessage, ex);
+			showMessageDialog(this, exMessage, ERROR_TITLE, ERROR_MESSAGE);
 			return false;
-		} finally {
-			if (pw != null) {
-				try {
-					pw.close();
-				} catch (IOException ex) {
-					// ignore
-				}
-			}
 		}
+		showMessageDialog(this, "Trusted certificate export successful",
+				ALERT_TITLE, INFORMATION_MESSAGE);
+		return true;
 	}
 
 	/**
@@ -1479,24 +1427,19 @@
 	 * Truststore.
 	 */
 	private void deleteTrustedCertificate() {
-
 		// Which entries have been selected?
 		int[] selectedRows = trustedCertsTable.getSelectedRows();
-		if (selectedRows.length == 0) { // no trusted cert entry selected
+		if (selectedRows.length == 0) // no trusted cert entry selected
 			return;
-		}
 
 		// Ask user to confirm the deletion
-		int answer = JOptionPane
-				.showConfirmDialog(
-						null,
-						"Are you sure you want to delete the selected trusted certificate(s)?",
-						"Credential Manager Alert", JOptionPane.YES_NO_OPTION);
-
-		if (answer != JOptionPane.YES_OPTION) {
+		if (showConfirmDialog(
+				null,
+				"Are you sure you want to delete the selected trusted certificate(s)?",
+				ALERT_TITLE, YES_NO_OPTION) != YES_OPTION)
 			return;
-		}
 
+		String exMessage = null;
 		for (int i = selectedRows.length - 1; i >= 0; i--) { // delete from backwards
 			// Get the alias for the current entry
 			String alias = (String) trustedCertsTable.getModel().getValueAt(
@@ -1505,12 +1448,12 @@
 				// Delete the trusted certificate entry from the Truststore
 				credManager.deleteTrustedCertificate(alias);
 			} catch (CMException cme) {
-				String exMessage = "Failed to delete the trusted certificate(s) from the Truststore";
-				logger.error(exMessage);
-				JOptionPane.showMessageDialog(this, exMessage,
-						"Credential Manager Error", JOptionPane.ERROR_MESSAGE);
+				exMessage = "Failed to delete the trusted certificate(s) from the Truststore";
+				logger.error(exMessage, cme);
 			}
 		}
+		if (exMessage != null)
+			showMessageDialog(this, exMessage, ERROR_TITLE, ERROR_MESSAGE);
 	}
 
 	/**
@@ -1519,22 +1462,21 @@
 	 */
 	private void tableDoubleClick(MouseEvent evt) {
 		if (evt.getClickCount() > 1) { // is it a double click?
-
 			// Which row was clicked on (if any)?
 			Point point = new Point(evt.getX(), evt.getY());
 			int row = ((JTable) evt.getSource()).rowAtPoint(point);
-			if (row == -1) {
+			if (row == -1)
 				return;
-			}
 			// Which table the click occured on?
-			if (((JTable) evt.getSource()).getModel() instanceof PasswordsTableModel) { // Passwords
-				// table
+			if (((JTable) evt.getSource()).getModel() instanceof PasswordsTableModel)
+				// Passwords table
 				viewPassword();
-			} else if (((JTable) evt.getSource()).getModel() instanceof KeyPairsTableModel) { // Key pairs table
+			else if (((JTable) evt.getSource()).getModel() instanceof KeyPairsTableModel)
+				// Key pairs table
 				viewCertificate();
-			} else { // Trusted certificates table
+			else
+				// Trusted certificates table
 				viewCertificate();
-			}
 		}
 	}
 
@@ -1544,25 +1486,23 @@
 	 */
 	private File selectImportExportFile(String title, String[] filter,
 			String description, String approveButtonText, String prefString) {
-
-		Preferences prefs = Preferences.userNodeForPackage(CredentialManagerUI.class);
-		String keyPairDir = prefs
-				.get(prefString, System.getProperty("user.home"));
+		Preferences prefs = Preferences
+				.userNodeForPackage(CredentialManagerUI.class);
+		String keyPairDir = prefs.get(prefString,
+				System.getProperty("user.home"));
 		JFileChooser fileChooser = new JFileChooser();
 		fileChooser.addChoosableFileFilter(new CryptoFileFilter(filter,
-						description));
+				description));
 		fileChooser.setDialogTitle(title);
 		fileChooser.setMultiSelectionEnabled(false);
 		fileChooser.setCurrentDirectory(new File(keyPairDir));
 
-		int rtnValue = fileChooser.showDialog(this, approveButtonText);
-		if (rtnValue == JFileChooser.APPROVE_OPTION) {
-			File selectedFile = fileChooser.getSelectedFile();
-			prefs.put(prefString, fileChooser.getCurrentDirectory()
-					.toString());
-			return selectedFile;
-		}
-		return null;
+		if (fileChooser.showDialog(this, approveButtonText) != APPROVE_OPTION)
+			return null;
+
+		File selectedFile = fileChooser.getSelectedFile();
+		prefs.put(prefString, fileChooser.getCurrentDirectory().toString());
+		return selectedFile;
 	}
 
 	private void closeFrame() {
@@ -1570,4 +1510,3 @@
 		dispose();
 	}
 }
-
diff --git a/credential-manager-ui/src/main/java/net/sf/taverna/t2/workbench/ui/credentialmanager/CredentialManagerUILauncher.java b/credential-manager-ui/src/main/java/net/sf/taverna/t2/workbench/ui/credentialmanager/CredentialManagerUILauncher.java
index 2611a07..cdcabb7 100644
--- a/credential-manager-ui/src/main/java/net/sf/taverna/t2/workbench/ui/credentialmanager/CredentialManagerUILauncher.java
+++ b/credential-manager-ui/src/main/java/net/sf/taverna/t2/workbench/ui/credentialmanager/CredentialManagerUILauncher.java
@@ -20,7 +20,9 @@
  ******************************************************************************/
 package net.sf.taverna.t2.workbench.ui.credentialmanager;
 
-import java.awt.BorderLayout;
+import static java.awt.BorderLayout.CENTER;
+import static javax.swing.SwingUtilities.invokeLater;
+
 import java.awt.Dimension;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
@@ -30,91 +32,65 @@
 import javax.swing.JFrame;
 import javax.swing.JLabel;
 import javax.swing.JPanel;
-import javax.swing.SwingUtilities;
-import javax.swing.WindowConstants;
-
-import net.sf.taverna.t2.security.credentialmanager.CMException;
 
 /**
- *
  * Test launcher for Credential Manager GUI (so it does not have to be
  * launched from Taverna).
  *
  * @author Alexandra Nenadic
- *
  */
 public class CredentialManagerUILauncher extends JFrame {
-
 	private static final long serialVersionUID = 2079805060170251148L;
 
-	private final ImageIcon launchCMIcon = new ImageIcon(CredentialManagerUILauncher.class.getResource(
-	"/images/cred_manager.png"));
+	private final ImageIcon launchCMIcon = new ImageIcon(
+			CredentialManagerUILauncher.class
+					.getResource("/images/cred_manager.png"));
 
-	public CredentialManagerUILauncher(){
-
+	public CredentialManagerUILauncher() {
 		JPanel jpLaunch = new JPanel();
-		jpLaunch.setPreferredSize(new Dimension (300, 120));
+		jpLaunch.setPreferredSize(new Dimension(300, 120));
 
 		JLabel jlLaunch = new JLabel("T2: Launch Credential Manager GUI");
 
 		JButton jbLaunch = new JButton();
 		jbLaunch.setIcon(launchCMIcon);
 		jbLaunch.setToolTipText("Launches Credential Manager");
-		jbLaunch.addActionListener(new ActionListener(){
-
+		jbLaunch.addActionListener(new ActionListener() {
+			@Override
 			public void actionPerformed(ActionEvent e) {
 				CredentialManagerUI cmGUI = new CredentialManagerUI(null, null);
-				if (cmGUI != null){
+				if (cmGUI != null)
 					cmGUI.setVisible(true);
-				}
 			}
 		});
 
 		jpLaunch.add(jlLaunch);
 		jpLaunch.add(jbLaunch);
 
-		getContentPane().add(jpLaunch,BorderLayout.CENTER);
+		getContentPane().add(jpLaunch, CENTER);
 
-        // Handle application close
-        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
+		// Handle application close
+		setDefaultCloseOperation(EXIT_ON_CLOSE);
 
 		pack();
 
         // Centre the frame in the centre of the desktop
         setLocationRelativeTo(null);
-
         // Set the frame's title
         setTitle("Credential Manager GUI Launcher");
-
         setVisible(true);
-
 	}
 
-
-    /**
-     * Runnable to create and show the Credential Manager Launcher's GUI.
-     */
-    private static class CreateAndShowGui
-        implements Runnable
-    {
-
-        /**
-         * Create and show the launcher GUI.
-         */
-        public void run()
-        {
-            new CredentialManagerUILauncher();
-        }
-    }
-
-
-    /**
-     * Launcher for the Credential Manager GUI.
-     */
-    public static void main(String[] args)
-    {
+	/**
+	 * Launcher for the Credential Manager GUI.
+	 */
+	public static void main(String[] args) {
         // Create and show GUI on the event handler thread
-        SwingUtilities.invokeLater(new CreateAndShowGui());
+        invokeLater(new Runnable(){
+        	@Override
+        	public void run() {
+        		new CredentialManagerUILauncher();
+        	}
+        });
     }
-
 }
diff --git a/credential-manager-ui/src/main/java/net/sf/taverna/t2/workbench/ui/credentialmanager/CryptoFileFilter.java b/credential-manager-ui/src/main/java/net/sf/taverna/t2/workbench/ui/credentialmanager/CryptoFileFilter.java
index af43a03..d58aa8a 100644
--- a/credential-manager-ui/src/main/java/net/sf/taverna/t2/workbench/ui/credentialmanager/CryptoFileFilter.java
+++ b/credential-manager-ui/src/main/java/net/sf/taverna/t2/workbench/ui/credentialmanager/CryptoFileFilter.java
@@ -21,9 +21,7 @@
 package net.sf.taverna.t2.workbench.ui.credentialmanager;
 
 import java.io.File;
-import java.util.ArrayList;
 import java.util.Arrays;
-import java.util.Iterator;
 import java.util.List;
 
 import javax.swing.filechooser.FileFilter;
@@ -41,30 +39,26 @@
  * encoded as binary DER or as ASCII PEM. .p7 and .p7c are PKCS #7 certificate
  * chain files (i.e. SignedData structure without data, just certificate(s)).
  */
-public class CryptoFileFilter extends FileFilter 
-{
+public class CryptoFileFilter extends FileFilter {
 	// Description of the filter
 	private String description;
-	
+
 	// Array of file extensions to filter against
-	private List<String> exts = new ArrayList<String>();
+	private List<String> exts;
 
-    public CryptoFileFilter(String [] extList, String desc)
-    {
-    	exts = Arrays.asList(extList);
-        this.description = desc;
-    }
+	public CryptoFileFilter(String[] extList, String desc) {
+		exts = Arrays.asList(extList);
+		this.description = desc;
+	}
 
+	@Override
 	public boolean accept(File file) {
-		if (file.isDirectory()) {
+		if (file.isDirectory())
 			return true;
-		} else if (file.isFile()) {
-			Iterator<String> it = exts.iterator();
-			while (it.hasNext()) {
-				if (file.getName().toLowerCase().endsWith((String) it.next()))
+		if (file.isFile())
+			for (String ext : exts)
+				if (file.getName().toLowerCase().endsWith(ext))
 					return true;
-			}
-		}
 		return false;
 	}
 
@@ -72,6 +66,7 @@
 		this.description = desc;
 	}
 
+	@Override
 	public String getDescription() {
 		return this.description;
 	}
diff --git a/credential-manager-ui/src/main/java/net/sf/taverna/t2/workbench/ui/credentialmanager/GetMasterPasswordDialog.java b/credential-manager-ui/src/main/java/net/sf/taverna/t2/workbench/ui/credentialmanager/GetMasterPasswordDialog.java
index 8448673..b6f623e 100644
--- a/credential-manager-ui/src/main/java/net/sf/taverna/t2/workbench/ui/credentialmanager/GetMasterPasswordDialog.java
+++ b/credential-manager-ui/src/main/java/net/sf/taverna/t2/workbench/ui/credentialmanager/GetMasterPasswordDialog.java
@@ -20,9 +20,16 @@
  ******************************************************************************/
 package net.sf.taverna.t2.workbench.ui.credentialmanager;
 
+import static java.awt.BorderLayout.CENTER;
+import static java.awt.BorderLayout.NORTH;
+import static java.awt.BorderLayout.SOUTH;
+import static javax.swing.BoxLayout.Y_AXIS;
+import static javax.swing.JOptionPane.WARNING_MESSAGE;
+import static javax.swing.JOptionPane.showMessageDialog;
+import static net.sf.taverna.t2.workbench.ui.credentialmanager.CMStrings.WARN_TITLE;
+
 import java.awt.BorderLayout;
 import java.awt.FlowLayout;
-import java.awt.Font;
 import java.awt.Frame;
 import java.awt.GridLayout;
 import java.awt.event.ActionEvent;
@@ -33,7 +40,6 @@
 import javax.swing.BoxLayout;
 import javax.swing.JButton;
 import javax.swing.JLabel;
-import javax.swing.JOptionPane;
 import javax.swing.JPanel;
 import javax.swing.JPasswordField;
 import javax.swing.border.EmptyBorder;
@@ -41,21 +47,18 @@
 import net.sf.taverna.t2.workbench.helper.NonBlockedHelpEnabledDialog;
 
 /**
- * Dialog used for getting a master password for Credential Manager
- * from the users.
- *
+ * Dialog used for getting a master password for Credential Manager from the
+ * users.
+ * 
  * @author Alex Nenadic
  */
 @SuppressWarnings("serial")
 public class GetMasterPasswordDialog extends NonBlockedHelpEnabledDialog {
-
-	// Password entry field
+	/** Password entry field */
 	private JPasswordField passwordField;
-
-	// The entered password
+	/** The entered password */
 	private String password = null;
-
-	// Text giving user the instructions what to do in the dialog
+	/** Text giving user the instructions what to do in the dialog */
 	private String instructions;
 
 	public GetMasterPasswordDialog(String instructions) {
@@ -68,10 +71,10 @@
 		getContentPane().setLayout(new BorderLayout());
 
 		JLabel instructionsLabel = new JLabel(instructions);
-//		instructionsLabel.setFont(new Font(null, Font.PLAIN, 11));
+		// instructionsLabel.setFont(new Font(null, Font.PLAIN, 11));
 
 		JPanel instructionsPanel = new JPanel();
-		instructionsPanel.setLayout(new BoxLayout(instructionsPanel, BoxLayout.Y_AXIS));
+		instructionsPanel.setLayout(new BoxLayout(instructionsPanel, Y_AXIS));
 		instructionsPanel.add(instructionsLabel);
 		instructionsPanel.setBorder(new EmptyBorder(10, 5, 10, 0));
 
@@ -85,11 +88,12 @@
 
 		JPanel mainPanel = new JPanel(new BorderLayout());
 		mainPanel.setBorder(new EmptyBorder(10, 10, 10, 10));
-		mainPanel.add(instructionsPanel, BorderLayout.NORTH);
-		mainPanel.add(passwordPanel, BorderLayout.CENTER);
+		mainPanel.add(instructionsPanel, NORTH);
+		mainPanel.add(passwordPanel, CENTER);
 
 		JButton okButton = new JButton("OK");
 		okButton.addActionListener(new ActionListener() {
+			@Override
 			public void actionPerformed(ActionEvent evt) {
 				okPressed();
 			}
@@ -97,6 +101,7 @@
 
 		JButton cancelButton = new JButton("Cancel");
 		cancelButton.addActionListener(new ActionListener() {
+			@Override
 			public void actionPerformed(ActionEvent evt) {
 				cancelPressed();
 			}
@@ -105,19 +110,18 @@
 		buttonsPanel.add(okButton);
 		buttonsPanel.add(cancelButton);
 
-		getContentPane().add(mainPanel, BorderLayout.CENTER);
-		getContentPane().add(buttonsPanel, BorderLayout.SOUTH);
+		getContentPane().add(mainPanel, CENTER);
+		getContentPane().add(buttonsPanel, SOUTH);
 
 		addWindowListener(new WindowAdapter() {
+			@Override
 			public void windowClosing(WindowEvent evt) {
 				closeDialog();
 			}
 		});
 
 		setResizable(false);
-
 		getRootPane().setDefaultButton(okButton);
-
 		pack();
 	}
 
@@ -129,29 +133,31 @@
 	}
 
 	/**
-	 * Check that the entered password is not empty and store the entered password.
+	 * Check that the entered password is not empty and store the entered
+	 * password.
 	 */
 	private boolean checkPassword() {
 		password = new String(passwordField.getPassword());
 
-		if (password.length() == 0) { // password is empty
-			JOptionPane.showMessageDialog(this, "The password cannot be empty",
-					"Credential Manager Warning", JOptionPane.WARNING_MESSAGE);
+		if (password.isEmpty()) {
+			showMessageDialog(this, "The password cannot be empty",
+					WARN_TITLE, WARNING_MESSAGE);
 			return false;
-		} else { // password is not empty
-			return true;
 		}
+
+		return true;
 	}
 
 	private void okPressed() {
-		if (checkPassword()) {
+		if (checkPassword())
 			closeDialog();
-		}
 	}
 
 	private void cancelPressed() {
-		// Set the password to null as it might have changed in the meantime
-		// if user entered something then cancelled.
+		/*
+		 * Set the password to null as it might have changed in the meantime if
+		 * user entered something then cancelled.
+		 */
 		password = null;
 		closeDialog();
 	}
diff --git a/credential-manager-ui/src/main/java/net/sf/taverna/t2/workbench/ui/credentialmanager/GetPasswordDialog.java b/credential-manager-ui/src/main/java/net/sf/taverna/t2/workbench/ui/credentialmanager/GetPasswordDialog.java
index 30011fc..45a0f88 100644
--- a/credential-manager-ui/src/main/java/net/sf/taverna/t2/workbench/ui/credentialmanager/GetPasswordDialog.java
+++ b/credential-manager-ui/src/main/java/net/sf/taverna/t2/workbench/ui/credentialmanager/GetPasswordDialog.java
@@ -20,6 +20,14 @@
  ******************************************************************************/
 package net.sf.taverna.t2.workbench.ui.credentialmanager;
 
+import static java.awt.BorderLayout.CENTER;
+import static java.awt.BorderLayout.NORTH;
+import static java.awt.BorderLayout.SOUTH;
+import static java.awt.Font.PLAIN;
+import static javax.swing.JOptionPane.WARNING_MESSAGE;
+import static javax.swing.JOptionPane.showMessageDialog;
+import static net.sf.taverna.t2.workbench.ui.credentialmanager.CMStrings.WARN_TITLE;
+
 import java.awt.BorderLayout;
 import java.awt.FlowLayout;
 import java.awt.Font;
@@ -32,7 +40,6 @@
 import javax.swing.JDialog;
 import javax.swing.JFrame;
 import javax.swing.JLabel;
-import javax.swing.JOptionPane;
 import javax.swing.JPanel;
 import javax.swing.JPasswordField;
 import javax.swing.border.EmptyBorder;
@@ -46,63 +53,56 @@
  */
 @SuppressWarnings("serial")
 public class GetPasswordDialog extends NonBlockedHelpEnabledDialog {
-
-	// Instructions for user explaining the purpose of the password 
+	/** Instructions for user explaining the purpose of the password */
 	private String instructions = null;
-	
-    // Password entry password field 
-    private JPasswordField passwordField;
+	/* Password entry password field */
+	private JPasswordField passwordField;
+	/* Stores the password entered */
+	private String password = null;
 
-    // Stores the password entered 
-    private String password = null;
+	public GetPasswordDialog(JFrame parent, String title, boolean modal,
+			String instr) {
+		super(parent, title, modal);
+		instructions = instr;
+		initComponents();
+	}
 
-    public GetPasswordDialog(JFrame parent, String title, boolean modal, String instr)
-    {
-        super(parent, title, modal);
-        instructions = instr;
-        initComponents();
-    }
+	public GetPasswordDialog(JDialog parent, String title, boolean modal,
+			String instr) {
+		super(parent, title, modal);
+		instructions = instr;
+		initComponents();
+	}
 
-    public GetPasswordDialog(JDialog parent, String title, boolean modal, String instr)
-    {
-        super(parent, title, modal);
-        instructions = instr;
-        initComponents();
-    }
+	private void initComponents() {
+		getContentPane().setLayout(new BorderLayout());
 
-    private void initComponents()
-    {
-        getContentPane().setLayout(new BorderLayout());
-               	
-        JLabel passwordLabel = new JLabel("Password");
-        passwordField = new JPasswordField(15);
+		JLabel passwordLabel = new JLabel("Password");
+		passwordField = new JPasswordField(15);
 
-        JButton okButton = new JButton("OK");
-        okButton.addActionListener(new ActionListener()
-        {
-            public void actionPerformed(ActionEvent evt)
-            {
-                okPressed();
-            }
-        });
+		JButton okButton = new JButton("OK");
+		okButton.addActionListener(new ActionListener() {
+			@Override
+			public void actionPerformed(ActionEvent evt) {
+				okPressed();
+			}
+		});
 
-        JButton cancelButton = new JButton("Cancel");
-        cancelButton.addActionListener(new ActionListener()
-        {
-            public void actionPerformed(ActionEvent evt)
-            {
-                cancelPressed();
-            }
-        });
+		JButton cancelButton = new JButton("Cancel");
+		cancelButton.addActionListener(new ActionListener() {
+			@Override
+			public void actionPerformed(ActionEvent evt) {
+				cancelPressed();
+			}
+		});
 
-             
-        JLabel instructionsLabel; // Instructions
-        if (instructions != null){
-        	instructionsLabel = new JLabel (instructions);
-        	instructionsLabel.setFont(new Font(null, Font.PLAIN, 11));
-        	instructionsLabel.setBorder(new EmptyBorder(5,5,5,5));
-        	getContentPane().add(instructionsLabel, BorderLayout.NORTH);
-        }
+		JLabel instructionsLabel; // Instructions
+		if (instructions != null) {
+			instructionsLabel = new JLabel(instructions);
+			instructionsLabel.setFont(new Font(null, PLAIN, 11));
+			instructionsLabel.setBorder(new EmptyBorder(5, 5, 5, 5));
+			getContentPane().add(instructionsLabel, NORTH);
+		}
         
         JPanel passwordPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
         passwordPanel.add(passwordLabel);
@@ -113,72 +113,56 @@
         buttonsPanel.add(okButton);
         buttonsPanel.add(cancelButton);
 
-        getContentPane().add(passwordPanel, BorderLayout.CENTER);
-        getContentPane().add(buttonsPanel, BorderLayout.SOUTH);
+        getContentPane().add(passwordPanel, CENTER);
+        getContentPane().add(buttonsPanel, SOUTH);
 
-        addWindowListener(new WindowAdapter()
-        {
-            public void windowClosing(WindowEvent evt)
-            {
-                closeDialog();
-            }
-        });
+		addWindowListener(new WindowAdapter() {
+			@Override
+			public void windowClosing(WindowEvent evt) {
+				closeDialog();
+			}
+		});
 
         setResizable(false);
-
         getRootPane().setDefaultButton(okButton);
-
         pack();
-    }
+	}
 
+	/**
+	 * Get the password entered in the dialog.
+	 */
+	public String getPassword() {
+		return password;
+	}
 
-    /**
-     * Get the password entered in the dialog.
-     */
-    public String getPassword()
-    {
-    	return password;
-    }
-    
-    /**
-     * Check that the password entered is not empty and 
-     * store the entered password.
-     */
-    private boolean checkPassword()
-    {
-        password = new String(passwordField.getPassword());
+	/**
+	 * Check that the password entered is not empty and store the entered
+	 * password.
+	 */
+	private boolean checkPassword() {
+		password = new String(passwordField.getPassword());
 
-        
-        if (password.length() == 0) { //password is empty          
-            JOptionPane.showMessageDialog(this,
-                    "The password cannot be empty", 
-                    "Credential Manager Warning",
-                    JOptionPane.WARNING_MESSAGE);
-            return false;
-        }
-        else { //password is not empty
-        	return true;
-        }
+		if (password.isEmpty()) {
+			showMessageDialog(this, "The password cannot be empty",
+					WARN_TITLE, WARNING_MESSAGE);
+			return false;
+		}
 
-    }
-    
-    private void okPressed()
-    {
-        if (checkPassword()) {
+		return true;
+	}
+
+	private void okPressed() {
+        if (checkPassword())
             closeDialog();
-        }
     }
 
-    private void cancelPressed()
-    {
-    	password = null;
-        closeDialog();
-    }
+	private void cancelPressed() {
+		password = null;
+		closeDialog();
+	}
 
-    private void closeDialog()
-    {
-        setVisible(false);
-        dispose();
-    }
+	private void closeDialog() {
+		setVisible(false);
+		dispose();
+	}
 }
-
diff --git a/credential-manager-ui/src/main/java/net/sf/taverna/t2/workbench/ui/credentialmanager/KeyPairsTableModel.java b/credential-manager-ui/src/main/java/net/sf/taverna/t2/workbench/ui/credentialmanager/KeyPairsTableModel.java
index 44c8423..712cdf6 100644
--- a/credential-manager-ui/src/main/java/net/sf/taverna/t2/workbench/ui/credentialmanager/KeyPairsTableModel.java
+++ b/credential-manager-ui/src/main/java/net/sf/taverna/t2/workbench/ui/credentialmanager/KeyPairsTableModel.java
@@ -20,21 +20,25 @@
  ******************************************************************************/
 package net.sf.taverna.t2.workbench.ui.credentialmanager;
 
-import java.util.ArrayList;
+import static javax.swing.JOptionPane.ERROR_MESSAGE;
+import static javax.swing.JOptionPane.showMessageDialog;
+import static net.sf.taverna.t2.security.credentialmanager.CredentialManager.KeystoreType.KEYSTORE;
+import static net.sf.taverna.t2.workbench.ui.credentialmanager.CMStrings.ERROR_TITLE;
+import static net.sf.taverna.t2.workbench.ui.credentialmanager.CredentialManagerUI.KEY_PAIR_ENTRY_TYPE;
+
 import java.util.TreeMap;
 
 import javax.swing.JFrame;
-import javax.swing.JOptionPane;
 import javax.swing.table.AbstractTableModel;
 
-import org.apache.log4j.Logger;
-
 import net.sf.taverna.t2.lang.observer.Observable;
 import net.sf.taverna.t2.lang.observer.Observer;
 import net.sf.taverna.t2.security.credentialmanager.CMException;
 import net.sf.taverna.t2.security.credentialmanager.CredentialManager;
 import net.sf.taverna.t2.security.credentialmanager.KeystoreChangedEvent;
 
+import org.apache.log4j.Logger;
+
 /**
  * The table model used to display the Keystore's key pair entries.
  *
@@ -42,28 +46,25 @@
  */
 @SuppressWarnings("serial")
 public class KeyPairsTableModel extends AbstractTableModel implements Observer<KeystoreChangedEvent> {
+	private static final Logger logger = Logger.getLogger(KeyPairsTableModel.class);
 
-	// Column names
+	/** Column names*/
     private String[] columnNames;
-
-    // Table data
+    /** Table data*/
     private Object[][] data;
-
 	private CredentialManager credManager;
 
-	private Logger logger = Logger.getLogger(KeyPairsTableModel.class);
-
     public KeyPairsTableModel(CredentialManager credentialManager) {
         credManager = credentialManager;
 
-        if (credManager == null) {
-			// Failed to instantiate Credential Manager - warn the user and exit
+		if (credManager == null) {
+			/* Failed to instantiate Credential Manager - warn the user and exit */
 			String sMessage = "Failed to instantiate Credential Manager. ";
-			logger.error("CM GUI: "+ sMessage);
-			JOptionPane.showMessageDialog(new JFrame(), sMessage,
-					"Credential Manager Error", JOptionPane.ERROR_MESSAGE);
+			logger.error("CM GUI: " + sMessage);
+			showMessageDialog(new JFrame(), sMessage,
+					ERROR_TITLE, ERROR_MESSAGE);
 			return;
-        }
+		}
 
        	data = new Object[0][0];
         columnNames = new String[] {
@@ -74,15 +75,15 @@
         	"Last Modified", // last modified date of the entry
             "URLs", // the invisible column holding the list of URLs associated with this entry
             "Alias" // the invisible column holding the actual alias in the Keystore
-        	};
+        };
 
-        try {
+		try {
 			load();
 		} catch (CMException cme) {
 			String sMessage = "Failed to load key pairs";
-			logger.error(sMessage);
-			JOptionPane.showMessageDialog(new JFrame(), sMessage,
-					"Credential Manager Error", JOptionPane.ERROR_MESSAGE);
+			logger.error(sMessage, cme);
+			showMessageDialog(new JFrame(), sMessage,
+					ERROR_TITLE, ERROR_MESSAGE);
 			return;
 		}
 
@@ -94,124 +95,119 @@
      * Load the table model with the key pair entries from the Keystore.
      */
     public void load() throws CMException {
+    	// Place key pair entries' aliases in a tree map to sort them
+    	TreeMap<String, String> sortedAliases = new TreeMap<>();
 
-        try{
-            // Place key pair entries' aliases in a tree map to sort them
-            TreeMap<String, String> sortedAliases = new TreeMap<String, String>();
+		for (String alias: credManager.getAliases(KEYSTORE))
+			/*
+			 * We are only interested in key pair entries here.
+			 * 
+			 * Alias for such entries is constructed as
+			 * "keypair#<CERT_SERIAL_NUMBER>#<CERT_COMMON_NAME>" where
+			 */
+			if (alias.startsWith("keypair#"))
+				sortedAliases.put(alias, alias);
 
-            ArrayList<String> aliases = credManager.getAliases(CredentialManager.KeystoreType.KEYSTORE);
+		// Create one table row for each key pair entry
+		data = new Object[sortedAliases.size()][7];
 
-           	for (String alias: aliases){
-        		// We are only interested in key pair entries here.
-        		// Alias for such entries is constructed as "keypair#<CERT_SERIAL_NUMBER>#<CERT_COMMON_NAME>" where
-        		if (alias.startsWith("keypair#")){
-        			sortedAliases.put(alias, alias);
-        		}
-        	}
+		/*
+		 * Iterate through the sorted aliases (if any), retrieving the key pair
+		 * entries and populating the table model
+		 */
+		int iCnt = 0;
+		for (String alias : sortedAliases.values()) {
+			/*
+			 * Populate the type column - it is set with an integer but a custom
+			 * cell renderer will cause a suitable icon to be displayed
+			 */
+			data[iCnt][0] = KEY_PAIR_ENTRY_TYPE;
 
-            // Create one table row for each key pair entry
-            data = new Object[sortedAliases.size()][7];
+			/*
+			 * Split the alias string to extract owner, issuer and serial number
+			 * alias =
+			 * "keypair#"<SUBJECT_COMMON_NAME>"#"<ISSUER_COMMON_NAME>"#"<SERIAL_NUMBER>
+			 */
+			String[] aliasComponents = alias.split("#");
 
-            // Iterate through the sorted aliases (if any), retrieving the key pair
-            // entries and populating the table model
-            int iCnt = 0;
-            for (String alias : sortedAliases.values())
-            {
+			// Populate the owner column extracted from the alias
+			data[iCnt][1] = aliasComponents[1];
 
-                // Populate the type column - it is set with an integer
-                // but a custom cell renderer will cause a suitable icon
-                // to be displayed
-                data[iCnt][0] = CredentialManagerUI.KEY_PAIR_ENTRY_TYPE;
+			// Populate the issuer column extracted from the alias
+			data[iCnt][2] = aliasComponents[2];
 
-                // Split the alias string to extract owner, issuer and serial number
-                // alias = "keypair#"<CERT_SUBJECT_COMMON_NAME>"#"<CERT_ISSUER_COMMON_NAME>"#"<CERT_SERIAL_NUMBER>
-                String[] aliasComponents = alias.split("#");
+			// Populate the serial number column extracted from the alias
+			data[iCnt][3] = aliasComponents[3];
 
-                // Populate the owner column extracted from the alias
-                data[iCnt][1] = aliasComponents[1];
+			// Populate the modified date column ("UBER" keystore type supports creation date)
+			//data[iCnt][4] = credManager.getEntryCreationDate(CredentialManager.KEYSTORE, alias);
 
-                // Populate the issuer column extracted from the alias
-                data[iCnt][2] = aliasComponents[2];
+			// Populate the invisible URLs list column
+			//data[iCnt][5] = credManager.getServiceURLsForKeyPair(alias);
 
-                // Populate the serial number column extracted from the alias
-                data[iCnt][3] = aliasComponents[3];
+			// Populate the invisible alias column
+			data[iCnt][6] = alias;
 
-                // Populate the modified date column ("UBER" keystore type supports creation date)
-               	//data[iCnt][4] = credManager.getEntryCreationDate(CredentialManager.KEYSTORE, alias);
-
-                // Populate the invisible URLs list column
-                //data[iCnt][5] = credManager.getServiceURLsForKeyPair(alias);
-
-                // Populate the invisible alias column
-                data[iCnt][6] = alias;
-
-                iCnt++;
-            }
-        }
-        catch (CMException cme){
-            throw (cme);
-        }
-
-        fireTableDataChanged();
-    }
-
-    /**
-     * Get the number of columns in the table.
-     */
-    public int getColumnCount()
-    {
-        return columnNames.length;
-    }
-
-    /**
-     * Get the number of rows in the table.
-     */
-    public int getRowCount()
-    {
-        return data.length;
-    }
-
-    /**
-     * Get the name of the column at the given position.
-     */
-    public String getColumnName(int iCol)
-    {
-        return columnNames[iCol];
-    }
-
-    /**
-     * Get the cell value at the given row and column position.
-     */
-    public Object getValueAt(int iRow, int iCol)
-    {
-        return data[iRow][iCol];
-    }
-
-    /**
-     * Get the class at of the cells at the given column position.
-     */
-    public Class<? extends Object> getColumnClass(int iCol)
-    {
-        return getValueAt(0, iCol).getClass();
-    }
-
-    /**
-     * Is the cell at the given row and column position editable?
-     */
-    public boolean isCellEditable(int iRow, int iCol)
-    {
-        // The table is always read-only
-        return false;
-    }
-
-	public void notify(Observable<KeystoreChangedEvent> sender,
-			KeystoreChangedEvent message) throws Exception {
-
-		// reload the table
-		if (message.keystoreType.equals(CredentialManager.KeystoreType.KEYSTORE)){
-			load();
+			iCnt++;
 		}
+
+		fireTableDataChanged();
+    }
+
+	/**
+	 * Get the number of columns in the table.
+	 */
+	@Override
+	public int getColumnCount() {
+		return columnNames.length;
 	}
 
-}
+	/**
+	 * Get the number of rows in the table.
+	 */
+	@Override
+	public int getRowCount() {
+		return data.length;
+	}
 
+	/**
+	 * Get the name of the column at the given position.
+	 */
+	@Override
+	public String getColumnName(int iCol) {
+		return columnNames[iCol];
+	}
+
+	/**
+	 * Get the cell value at the given row and column position.
+	 */
+	@Override
+	public Object getValueAt(int iRow, int iCol) {
+		return data[iRow][iCol];
+	}
+
+	/**
+	 * Get the class at of the cells at the given column position.
+	 */
+	@Override
+	public Class<? extends Object> getColumnClass(int iCol) {
+		return getValueAt(0, iCol).getClass();
+	}
+
+	/**
+	 * Is the cell at the given row and column position editable?
+	 */
+	@Override
+	public boolean isCellEditable(int iRow, int iCol) {
+		// The table is always read-only
+		return false;
+	}
+
+	@Override
+	public void notify(Observable<KeystoreChangedEvent> sender,
+			KeystoreChangedEvent message) throws Exception {
+		// reload the table
+		if (message.keystoreType.equals(KEYSTORE))
+			load();
+	}
+}
diff --git a/credential-manager-ui/src/main/java/net/sf/taverna/t2/workbench/ui/credentialmanager/NewEditPasswordEntryDialog.java b/credential-manager-ui/src/main/java/net/sf/taverna/t2/workbench/ui/credentialmanager/NewEditPasswordEntryDialog.java
index a1bef03..bd150e6 100644
--- a/credential-manager-ui/src/main/java/net/sf/taverna/t2/workbench/ui/credentialmanager/NewEditPasswordEntryDialog.java
+++ b/credential-manager-ui/src/main/java/net/sf/taverna/t2/workbench/ui/credentialmanager/NewEditPasswordEntryDialog.java
@@ -20,6 +20,18 @@
  ******************************************************************************/
 package net.sf.taverna.t2.workbench.ui.credentialmanager;
 
+import static java.awt.BorderLayout.CENTER;
+import static java.awt.BorderLayout.SOUTH;
+import static java.awt.GridBagConstraints.HORIZONTAL;
+import static java.awt.GridBagConstraints.NONE;
+import static java.awt.GridBagConstraints.WEST;
+import static javax.swing.JOptionPane.ERROR_MESSAGE;
+import static javax.swing.JOptionPane.WARNING_MESSAGE;
+import static javax.swing.JOptionPane.showMessageDialog;
+import static net.sf.taverna.t2.workbench.ui.credentialmanager.CMStrings.ALERT_TITLE;
+import static net.sf.taverna.t2.workbench.ui.credentialmanager.CMStrings.ERROR_TITLE;
+import static net.sf.taverna.t2.workbench.ui.credentialmanager.CMStrings.WARN_TITLE;
+
 import java.awt.BorderLayout;
 import java.awt.FlowLayout;
 import java.awt.GridBagConstraints;
@@ -60,83 +72,74 @@
 @SuppressWarnings("serial")
 public class NewEditPasswordEntryDialog extends NonBlockedHelpEnabledDialog
 {
-	// 'Edit' mode constant - the dialog is in the 'edit' entry mode
+	private static final Logger logger = Logger
+			.getLogger(NewEditPasswordEntryDialog.class);
+	/** 'Edit' mode constant - the dialog is in the 'edit' entry mode */
 	private static final String EDIT_MODE = "EDIT";
-
-	// 'New' mode constant - the dialog is in the 'new' entry mode
+	/** 'New' mode constant - the dialog is in the 'new' entry mode */
 	private static final String NEW_MODE = "NEW";
 
-	// Mode of this dialog - NEW_MODE for entering new password entry and EDIT_MODE for editting an existing password entry */
+	/**
+	 * Mode of this dialog - {@link #NEW_MODE} for entering new password entry
+	 * and {@link #EDIT_MODE} for editting an existing password entry
+	 */
 	String mode;
-
-    // Service URI field
-    private JTextField serviceURIField;
-
-    // Username field
-    private JTextField usernameField;
-
-    // First password entry field
-    private JPasswordField passwordField;
-
-    // Password confirmation entry field
-    private JPasswordField passwordConfirmField;
-
-    // Stores service URI entered
-    private URI serviceURI;
-    // Stores previous service URI for EDIT_MODE
-    private URI serviceURIOld;
-
-    // Stores username entered
-    private String username;
-
-    // Stores password entered
+	/** Service URI field */
+	private JTextField serviceURIField;
+	/** Username field */
+	private JTextField usernameField;
+	/** First password entry field */
+	private JPasswordField passwordField;
+	/** Password confirmation entry field */
+	private JPasswordField passwordConfirmField;
+	/** Stores service URI entered */
+	private URI serviceURI;
+	/** Stores previous service URI for {@link #EDIT_MODE} */
+	private URI serviceURIOld;
+	/** Stores username entered */
+	private String username;
+    /** Stores password entered*/
     private String password;
-
-    private Logger logger = Logger.getLogger(NewEditPasswordEntryDialog.class);
-
     private CredentialManager credentialManager;
 
-    public NewEditPasswordEntryDialog(JFrame parent, String title,
+	public NewEditPasswordEntryDialog(JFrame parent, String title,
 			boolean modal, URI currentURI, String currentUsername,
-			String currentPassword, CredentialManager credentialManager)
-    {
-        super(parent, title, modal);
-        serviceURI = currentURI;
-        username = currentUsername;
-        password = currentPassword;
+			String currentPassword, CredentialManager credentialManager) {
+		super(parent, title, modal);
+		serviceURI = currentURI;
+		username = currentUsername;
+		password = currentPassword;
 		this.credentialManager = credentialManager;
-        if (serviceURI == null && username == null && password == null) // if passed values are all null
-        {
+		if (serviceURI == null && username == null && password == null) {
+			// if passed values are all null
         	mode = NEW_MODE; // dialog is for entering a new password entry
-        }
-        else{
+		} else {
             mode = EDIT_MODE; // dialog is for editing an existing entry
             serviceURIOld = currentURI;
         }
         initComponents();
     }
 
-    public NewEditPasswordEntryDialog(JDialog parent, String title, boolean modal, URI currentURI, String currentUsername, String currentPassword, CredentialManager credentialManager)
-    {
-        super(parent, title, modal);
+	public NewEditPasswordEntryDialog(JDialog parent, String title,
+			boolean modal, URI currentURI, String currentUsername,
+			String currentPassword, CredentialManager credentialManager) {
+		super(parent, title, modal);
         serviceURI = currentURI;
         username = currentUsername;
         password = currentPassword;
 		this.credentialManager = credentialManager;
-       if (serviceURI == null && username == null && password == null) // if passed values are all null
-        {
+		if (serviceURI == null && username == null && password == null) {
+			// if passed values are all null
         	mode = NEW_MODE; // dialog is for entering new password entry
-        }
-        else{
+		} else {
             mode = EDIT_MODE; // dialog is for editing existing entry
             serviceURIOld = currentURI;
         }
         initComponents();
     }
 
-    private void initComponents()
-    {
-        getContentPane().setLayout(new BorderLayout());
+	private void initComponents() {
+		getContentPane().setLayout(new BorderLayout());
 
         JLabel serviceURILabel = new JLabel("Service URI");
         serviceURILabel.setBorder(new EmptyBorder(0,5,0,0));
@@ -163,32 +166,30 @@
         //jpfConfirmPassword.setBorder(new EmptyBorder(0,0,0,5));
 
         //If in EDIT_MODE - populate the fields with current values
-        if (mode.equals(EDIT_MODE)){
-            serviceURIField.setText(serviceURI.toASCIIString());
-            usernameField.setText(username);
-            passwordField.setText(password);
-            passwordConfirmField.setText(password);
-        }
+		if (mode.equals(EDIT_MODE)) {
+			serviceURIField.setText(serviceURI.toASCIIString());
+			usernameField.setText(username);
+			passwordField.setText(password);
+			passwordConfirmField.setText(password);
+		}
 
-        JButton okButton = new JButton("OK");
-        okButton.addActionListener(new ActionListener()
-        {
-            public void actionPerformed(ActionEvent evt)
-            {
-                okPressed();
-            }
-        });
+		JButton okButton = new JButton("OK");
+		okButton.addActionListener(new ActionListener() {
+			@Override
+			public void actionPerformed(ActionEvent evt) {
+				okPressed();
+			}
+		});
 
-        JButton cancelButton = new JButton("Cancel");
-        cancelButton.addActionListener(new ActionListener()
-        {
-            public void actionPerformed(ActionEvent evt)
-            {
-                cancelPressed();
-            }
-        });
+		JButton cancelButton = new JButton("Cancel");
+		cancelButton.addActionListener(new ActionListener() {
+			@Override
+			public void actionPerformed(ActionEvent evt) {
+				cancelPressed();
+			}
+		});
 
-        JPanel passwordPanel = new JPanel(new GridBagLayout());
+		JPanel passwordPanel = new JPanel(new GridBagLayout());
 
 		GridBagConstraints gbc = new GridBagConstraints();
 		gbc.weighty = 0.0;
@@ -196,176 +197,155 @@
 		gbc.weightx = 0.0;
 		gbc.gridx = 0;
 		gbc.gridy = 0;
-		gbc.fill = GridBagConstraints.NONE;
-		gbc.anchor = GridBagConstraints.WEST;
+		gbc.fill = NONE;
+		gbc.anchor = WEST;
 		gbc.insets = new Insets(5, 10, 0, 0);
         passwordPanel.add(serviceURILabel, gbc);
 
 		gbc.weightx = 1.0;
 		gbc.gridx = 1;
 		gbc.gridy = 0;
-		gbc.fill = GridBagConstraints.HORIZONTAL;
-		gbc.anchor = GridBagConstraints.WEST;
+		gbc.fill = HORIZONTAL;
+		gbc.anchor = WEST;
 		gbc.insets = new Insets(5, 10, 0, 5);
         passwordPanel.add(serviceURIField, gbc);
 
 		gbc.weightx = 0.0;
 		gbc.gridx = 0;
 		gbc.gridy = 1;
-		gbc.fill = GridBagConstraints.NONE;
-		gbc.anchor = GridBagConstraints.WEST;
+		gbc.fill = NONE;
+		gbc.anchor = WEST;
 		gbc.insets = new Insets(5, 10, 0, 0);
         passwordPanel.add(usernameLabel, gbc);
 
 		gbc.weightx = 1.0;
 		gbc.gridx = 1;
 		gbc.gridy = 1;
-		gbc.fill = GridBagConstraints.HORIZONTAL;
-		gbc.anchor = GridBagConstraints.WEST;
+		gbc.fill = HORIZONTAL;
+		gbc.anchor = WEST;
 		gbc.insets = new Insets(5, 10, 0, 5);
         passwordPanel.add(usernameField, gbc);
 
 		gbc.weightx = 0.0;
 		gbc.gridx = 0;
 		gbc.gridy = 2;
-		gbc.fill = GridBagConstraints.NONE;
-		gbc.anchor = GridBagConstraints.WEST;
+		gbc.fill = NONE;
+		gbc.anchor = WEST;
 		gbc.insets = new Insets(5, 10, 0, 0);
         passwordPanel.add(passwordLabel, gbc);
 
 		gbc.weightx = 1.0;
 		gbc.gridx = 1;
 		gbc.gridy = 2;
-		gbc.fill = GridBagConstraints.HORIZONTAL;
-		gbc.anchor = GridBagConstraints.WEST;
+		gbc.fill = HORIZONTAL;
+		gbc.anchor = WEST;
 		gbc.insets = new Insets(5, 10, 0, 5);
         passwordPanel.add(passwordField, gbc);
 
 		gbc.weightx = 0.0;
 		gbc.gridx = 0;
 		gbc.gridy = 3;
-		gbc.fill = GridBagConstraints.NONE;
-		gbc.anchor = GridBagConstraints.WEST;
+		gbc.fill = NONE;
+		gbc.anchor = WEST;
 		gbc.insets = new Insets(5, 10, 0, 0);
         passwordPanel.add(passwordConfirmLabel, gbc);
 
 		gbc.weightx = 1.0;
 		gbc.gridx = 1;
 		gbc.gridy = 3;
-		gbc.fill = GridBagConstraints.HORIZONTAL;
-		gbc.anchor = GridBagConstraints.WEST;
+		gbc.fill = HORIZONTAL;
+		gbc.anchor = WEST;
 		gbc.insets = new Insets(5, 10, 0, 5);
-        passwordPanel.add(passwordConfirmField, gbc);
+		passwordPanel.add(passwordConfirmField, gbc);
 
-        passwordPanel.setBorder(new CompoundBorder(
-                new EmptyBorder(10, 10, 10, 10), new EtchedBorder()));
+		passwordPanel.setBorder(new CompoundBorder(new EmptyBorder(10, 10, 10,
+				10), new EtchedBorder()));
 
-        JPanel buttonsPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
-        buttonsPanel.add(okButton);
-        buttonsPanel.add(cancelButton);
+		JPanel buttonsPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
+		buttonsPanel.add(okButton);
+		buttonsPanel.add(cancelButton);
 
-        getContentPane().add(passwordPanel, BorderLayout.CENTER);
-        getContentPane().add(buttonsPanel, BorderLayout.SOUTH);
+		getContentPane().add(passwordPanel, CENTER);
+		getContentPane().add(buttonsPanel, SOUTH);
 
-        addWindowListener(new WindowAdapter()
-        {
-            public void windowClosing(WindowEvent evt)
-            {
-                closeDialog();
-            }
-        });
+		addWindowListener(new WindowAdapter() {
+			@Override
+			public void windowClosing(WindowEvent evt) {
+				closeDialog();
+			}
+		});
 
         //setResizable(false);
-
         getRootPane().setDefaultButton(okButton);
-
         pack();
     }
 
-    /**
-     * Get the username entered in the dialog.
-     */
-    public String getUsername()
-    {
-        return username;
-    }
+	/**
+	 * Get the username entered in the dialog.
+	 */
+	public String getUsername() {
+		return username;
+	}
 
-    /**
-     * Get the service URI entered in the dialog.
-     */
-    public URI getServiceURI()
-    {
-        return serviceURI;
-    }
+	/**
+	 * Get the service URI entered in the dialog.
+	 */
+	public URI getServiceURI() {
+		return serviceURI;
+	}
 
-    /**
-     * Get the password entered in the dialog.
-     */
-    public String getPassword()
-    {
-    	return password;
-    }
+	/**
+	 * Get the password entered in the dialog.
+	 */
+	public String getPassword() {
+		return password;
+	}
 
-    /**
-     * Checks that the user has entered a non-empty service URI, a non-empty username,
-     * a non-empty password and that an entry with the same URI already does not already
-     * exist in the Keystore. Store the new password.
-     */
-    private boolean checkControls()
-    {
-    	String serviceURIString = new String(serviceURIField.getText());
-    	if (serviceURIString.length() == 0) {
-            JOptionPane.showMessageDialog(this,
-                "Service URI cannot be empty",
-                "Credential Manager Warning",
-                JOptionPane.WARNING_MESSAGE);
-
-            return false;
-    	}
+	/**
+	 * Checks that the user has entered a non-empty service URI, a non-empty
+	 * username, a non-empty password and that an entry with the same URI
+	 * already does not already exist in the Keystore. Store the new password.
+	 */
+	private boolean checkControls() {
+		String serviceURIString = new String(serviceURIField.getText());
+		if (serviceURIString.isEmpty()) {
+			showMessageDialog(this, "Service URI cannot be empty",
+					WARN_TITLE, WARNING_MESSAGE);
+			return false;
+		}
     	try {
 			serviceURI = new URI(serviceURIString);
 		} catch (URISyntaxException e) {
-            JOptionPane.showMessageDialog(this,
-                    "Service URI is not a valid URI",
-                    "Credential Manager Warning",
-                    JOptionPane.WARNING_MESSAGE);
-
-                return false;
+			showMessageDialog(this, "Service URI is not a valid URI",
+					WARN_TITLE, WARNING_MESSAGE);
+			return false;
 		}
 
-    	username = new String(usernameField.getText());
-    	if (username.length() == 0){
-            JOptionPane.showMessageDialog(this,
-                "Username cannot be empty",
-                "Credential Manager Warning",
-                JOptionPane.WARNING_MESSAGE);
+		username = new String(usernameField.getText());
+		if (username.isEmpty()) {
+			showMessageDialog(this, "Username cannot be empty", WARN_TITLE,
+					WARNING_MESSAGE);
+			return false;
+		}
 
-            return false;
-    	}
+		String firstPassword = new String(passwordField.getPassword());
+		String confirmPassword = new String(passwordConfirmField.getPassword());
 
-    	String firstPassword = new String(passwordField.getPassword());
-        String confirmPassword = new String(passwordConfirmField.getPassword());
+		if (!firstPassword.equals(confirmPassword)) {
+			// passwords do not match
+			showMessageDialog(this, "Passwords do not match", WARN_TITLE,
+					WARNING_MESSAGE);
+			return false;
+		}
+		if (firstPassword.isEmpty()) {
+			// passwords match but are empty
+			showMessageDialog(this, "Password cannot be empty", WARN_TITLE,
+					WARNING_MESSAGE);
+			return false;
+		}
 
-    	if ((firstPassword.length() > 0) && (firstPassword.equals(confirmPassword))) { // passwords the same and non-empty
-    		password = firstPassword;
-        }
-        else if ((firstPassword.length() == 0) && (firstPassword.equals(confirmPassword))){ // passwords match but are empty
-
-            JOptionPane.showMessageDialog(this,
-                "Password cannot be empty",
-                "Credential Manager Warning",
-                JOptionPane.WARNING_MESSAGE);
-
-            return false;
-        }
-        else{ // passwords do not match
-            JOptionPane.showMessageDialog(this,
-                "Passwords do not match",
-                "Credential Manager Warning",
-                JOptionPane.WARNING_MESSAGE);
-
-            return false;
-        }
+		// passwords the same and non-empty
+		password = firstPassword;
 
 		// Check if the entered service URL is already associated with another password entry in the Keystore
     	List<URI> uriList = null;
@@ -375,51 +355,44 @@
 			// Failed to instantiate Credential Manager - warn the user and exit
 			String exMessage = "Failed to instantiate Credential Manager to check for duplicate service URIs.";
 			logger.error(exMessage, cme);
-			JOptionPane.showMessageDialog(new JFrame(), exMessage,
-					"Credential Manager Error", JOptionPane.ERROR_MESSAGE);
+			showMessageDialog(new JFrame(), exMessage, ERROR_TITLE,
+					ERROR_MESSAGE);
 			return false;
 		}
 
-       	if (uriList != null){ // should not be null really (although can be empty). Check anyway.
-       		if (mode.equals(EDIT_MODE)){ // edit mode
+       	if (uriList != null) { // should not be null really (although can be empty). Check anyway.
+       		if (mode.equals(EDIT_MODE)) // edit mode
             	// Remove the current entry's service URI from the list
                 uriList.remove(serviceURIOld);
-       		}
 
-   			if (uriList.contains(serviceURI)){ // found another entry for this service URI
+   			if (uriList.contains(serviceURI)) { // found another entry for this service URI
         		// Warn the user and exit
-            	JOptionPane.showMessageDialog(
-                		this,
-                		"The entered service URI is already associated with another password entry",
-            			"Credential Manager Alert",
-            			JOptionPane.WARNING_MESSAGE);
-            	return false;
+				showMessageDialog(
+						this,
+						"The entered service URI is already associated with another password entry",
+						ALERT_TITLE, WARNING_MESSAGE);
+				return false;
 			}
-       	}
+		}
 
-    	return true;
-    }
+		return true;
+	}
 
-    private void okPressed()
-    {
-        if (checkControls()) {
-            closeDialog();
-        }
-    }
+	private void okPressed() {
+		if (checkControls())
+			closeDialog();
+	}
 
-    private void cancelPressed()
-    {
+	private void cancelPressed() {
     	// Set all fields to null to indicate that cancel button was pressed
-    	serviceURI = null;
-    	username = null;
-    	password = null;
-        closeDialog();
-    }
+		serviceURI = null;
+		username = null;
+		password = null;
+		closeDialog();
+	}
 
-    private void closeDialog()
-    {
-        setVisible(false);
-        dispose();
-    }
+	private void closeDialog() {
+		setVisible(false);
+		dispose();
+	}
 }
-