use of net.sourceforge.sqlexplorer.dialogs.PasswordConnDlg in project tdq-studio-se by Talend.
the class ConnectionJob method promptForPassword.
/**
* Prompts the user for a new username/password to attempt login with; if the dialog is
* cancelled then this.user is set to null.
* @param message
*/
private void promptForPassword(final String message) {
final Shell shell = SQLExplorerPlugin.getDefault().getSite().getShell();
// Switch to the UI thread to run the password dialog, but run it synchronously so we
// wait for it to complete
shell.getDisplay().syncExec(new Runnable() {
public void run() {
if (message != null) {
String title = Messages.getString("Progress.Connection.Title") + ' ' + alias.getName();
if (user != null && !alias.hasNoUserName())
title += '/' + user.getUserName();
if (alias.hasNoUserName()) {
MessageDialog dlg = new MessageDialog(shell, title, null, Messages.getString("Progress.Connection.ErrorMessage_Part1") + "\n\n" + message, MessageDialog.ERROR, new String[] { IDialogConstants.OK_LABEL }, 0);
dlg.open();
cancelled = true;
return;
} else {
MessageDialog dlg = new MessageDialog(shell, title, null, Messages.getString("Progress.Connection.ErrorMessage_Part1") + "\n\n" + message + "\n\n" + Messages.getString("Progress.Connection.ErrorMessage_Part2"), MessageDialog.ERROR, new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 0);
boolean retry = dlg.open() == 0;
if (!retry) {
cancelled = true;
return;
}
}
}
Shell shell = Display.getCurrent().getActiveShell();
PasswordConnDlg dlg = new PasswordConnDlg(shell, user.getAlias(), user);
if (dlg.open() != Window.OK) {
cancelled = true;
return;
}
// Create a new user and add it to the alias
User userTmp = new User(dlg.getUserName(), dlg.getPassword());
userTmp.setAutoCommit(dlg.getAutoCommit());
userTmp.setCommitOnClose(dlg.getCommitOnClose());
user = alias.addUser(userTmp);
}
});
}
Aggregations