use of com.cubrid.cubridmanager.core.cubrid.user.task.CreateUserTask in project cubrid-manager by CUBRID.
the class EditUserDialog method buttonPressed.
/**
* When press button,call it
*
* @param buttonId the button id
*/
protected void buttonPressed(int buttonId) {
if (buttonId == IDialogConstants.OK_ID) {
if (!valid()) {
return;
}
boolean isChangePassword = false;
if (newFlag) {
isChangePassword = true;
} else if (changePwdBtn.getSelection()) {
isChangePassword = true;
}
String password = null;
if (isChangePassword) {
password = pwdText.getText();
if (password == null) {
password = "";
}
}
this.inputtedPassword = password;
boolean isNoDbaAuthUser = database.getDatabaseInfo().getAuthLoginedDbUserInfo().getName().equalsIgnoreCase(userName) && !database.getDatabaseInfo().getAuthLoginedDbUserInfo().isDbaAuthority();
String taskName = Messages.bind(Messages.addOrUpdateUserTaskName, userNameText.getText());
TaskExecutor taskExecutor = new CommonTaskExec(taskName);
ITask task = null;
boolean isDropAndCreateUser = false;
if (isNoDbaAuthUser) {
if (isChangePassword) {
task = new ChangeDbUserPwdTask(database.getDatabaseInfo());
ChangeDbUserPwdTask changeDbUserPwdTask = (ChangeDbUserPwdTask) task;
changeDbUserPwdTask.setDbUserName(userName);
changeDbUserPwdTask.setNewPwd(password);
taskExecutor.addTask(changeDbUserPwdTask);
} else {
super.buttonPressed(IDialogConstants.CANCEL_ID);
return;
}
} else {
if (newFlag) {
List<String> groupList = new ArrayList<String>();
for (int i = 0; i < userGroupTable.getItemCount(); i++) {
groupList.add(userGroupTable.getItem(i).getText(0));
}
List<String> memberList = new ArrayList<String>();
for (Map<String, String> map : memberListData) {
memberList.add(map.get("0").toLowerCase(Locale.getDefault()));
}
task = new CreateUserTask(database.getDatabaseInfo(), userNameText.getText(), pwdText.getText(), groupList, memberList);
taskExecutor.addTask(task);
} else {
if (!groupChange()) {
task = new DropUserTask(database.getDatabaseInfo(), userName);
taskExecutor.addTask(task);
List<String> groupList = new ArrayList<String>();
for (int i = 0; i < userGroupTable.getItemCount(); i++) {
groupList.add(userGroupTable.getItem(i).getText(0));
}
List<String> memberList = new ArrayList<String>();
for (Map<String, String> map : memberListData) {
memberList.add(map.get("0").toLowerCase(Locale.getDefault()));
}
task = new CreateUserTask(database.getDatabaseInfo(), userNameText.getText(), pwdText.getText(), groupList, memberList);
taskExecutor.addTask(task);
isDropAndCreateUser = true;
} else if (isChangePassword) {
task = new ChangeDbUserPwdTask(database.getDatabaseInfo());
ChangeDbUserPwdTask changeDbUserPwdTask = (ChangeDbUserPwdTask) task;
changeDbUserPwdTask.setDbUserName(userName);
changeDbUserPwdTask.setNewPwd(password);
taskExecutor.addTask(task);
}
}
}
task = new UpdateAddUserJdbcTask(database.getDatabaseInfo(), userNameText.getText(), classGrantMap, authListData, authListDataOld, isDBAGroup(), isDropAndCreateUser);
taskExecutor.addTask(task);
new ExecTaskWithProgress(taskExecutor).busyCursorWhile();
if (taskExecutor.isSuccess() && isChangePassword && database.getDatabaseInfo().getAuthLoginedDbUserInfo().getName().equalsIgnoreCase(userName)) {
database.getDatabaseInfo().getAuthLoginedDbUserInfo().setNoEncryptPassword(password);
}
if (taskExecutor.isSuccess()) {
String message = null;
if (newFlag) {
message = Messages.msgAddUserSuccess;
} else {
message = Messages.msgModifyUserSuccess;
}
CommonUITool.openInformationBox(Messages.msgInformation, message);
} else {
return;
}
}
super.buttonPressed(buttonId);
}
Aggregations