try {
if (!canConnect()) {
return false;
} else {
setErrorMessage(null);
IDialogSettings section = getDialogSettings().getSection(PREVIOUS_CONNECTIONS);
if (section == null) {
section = getDialogSettings().addNewSection(PREVIOUS_CONNECTIONS);
}
IDialogSettings[] allSections = section.getSections();
IDialogSettings match = findMatchForCurrent(allSections);
if (match != null) {
if( savePassword.getSelection() ){
String storedPass = match.get(PASSWORD);
if( !password.getText().equals(storedPass) ){
if( storedPass==null || storedPass.length()==0 ){
match.put(PASSWORD, password.getText());
}else {
boolean choice = MessageDialog.openConfirm(getShell(), localization.password, localization.changePasswordQuery);
if( choice ){
match.put(PASSWORD, password.getText());
}
}
}
}else{
match.put(PASSWORD, ""); //$NON-NLS-1$
}
match.put(SAVE_PASSWORD, savePassword.getSelection());
match.put(TIMESTAMP, System.currentTimeMillis());
} else {
IDialogSettings params = section.addNewSection(allSections.length + 1 + ""); //$NON-NLS-1$
params.put(HOST, host.getText());
params.put(PORT, port.getText());
params.put(USERNAME, username.getText());
params.put(TIMESTAMP, System.currentTimeMillis());
params.put(SAVE_PASSWORD, savePassword.getSelection());
if ( savePassword.getSelection() ){
params.put(PASSWORD, password.getText());
}
}
return true;
}