use of com.cubrid.common.ui.spi.progress.CommonTaskExec 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);
}
use of com.cubrid.common.ui.spi.progress.CommonTaskExec in project cubrid-manager by CUBRID.
the class DropTriggerAction method run.
public void run(ISchemaNode[] nodeArray) {
// FIXME move this logic to core module
if (nodeArray == null) {
LOGGER.error("The nodeArray is a null.");
return;
}
List<String> triggerNameList = new ArrayList<String>();
StringBuffer bf = new StringBuffer();
for (int i = 0; nodeArray != null && i < nodeArray.length; i++) {
DefaultSchemaNode trigger = (DefaultSchemaNode) nodeArray[i];
triggerNameList.add(trigger.getName());
if (i == 0) {
bf.append(trigger.getName());
}
}
if (nodeArray.length > 1) {
bf.append(", ...");
}
String cfmMsg = Messages.bind(Messages.dropTriggerWarnMSG1, nodeArray.length, bf.toString());
boolean ret = CommonUITool.openConfirmBox(cfmMsg);
if (!ret) {
return;
}
ISchemaNode triggerNode = (ISchemaNode) nodeArray[0];
CommonSQLExcuterTask task = new CommonSQLExcuterTask(triggerNode.getDatabase().getDatabaseInfo());
for (String triggerName : triggerNameList) {
String sql = "DROP TRIGGER " + QuerySyntax.escapeKeyword(triggerName);
task.addSqls(sql);
}
String taskName = Messages.bind(Messages.dropTriggerTaskName, bf.toString());
TaskExecutor taskExecutor = new CommonTaskExec(taskName);
taskExecutor.addTask(task);
new ExecTaskWithProgress(taskExecutor).busyCursorWhile();
if (!taskExecutor.isSuccess()) {
return;
}
String title = com.cubrid.common.ui.common.Messages.titleSuccess;
String msg = Messages.dropTriggerSuccessMsg;
CommonUITool.openInformationBox(title, msg);
ISelectionProvider provider = this.getSelectionProvider();
ICubridNode parent = triggerNode.getParent();
if (provider instanceof TreeViewer) {
TreeViewer viewer = (TreeViewer) provider;
for (int i = 0; nodeArray != null && i < nodeArray.length; i++) {
parent.removeChild((ISchemaNode) nodeArray[i]);
}
viewer.remove(parent, nodeArray);
viewer.setSelection(new StructuredSelection(parent), true);
CommonUITool.updateFolderNodeLabelIncludingChildrenCount(viewer, parent);
}
}
use of com.cubrid.common.ui.spi.progress.CommonTaskExec in project cubrid-manager by CUBRID.
the class CreateTriggerDialog method executeByJDBC.
/**
*
* Execute to add or alter trigger by JDBC
*
* @param buttonId int
*/
private void executeByJDBC(int buttonId) {
// FIXME move this logic to core module
String createSQL = generateSqlText().toString();
if (StringUtil.isEmpty(createSQL)) {
return;
}
String taskName = null;
String message = null;
if (buttonId == IDialogConstants.OK_ID) {
taskName = Messages.bind(Messages.addTriggerTaskName, triggerName);
message = Messages.newTriggerSuccess;
} else if (buttonId == ALTER_TRIGGER_OK_ID) {
createSQL = createSQL.substring(createSQL.indexOf("ALTER TRIGGER "));
message = Messages.alterTriggerSuccess;
taskName = Messages.bind(Messages.alterTriggerTaskName, triggerName);
}
// add or alter triggers by JDBC
JDBCSqlExecuteTask jdbcTask = new JDBCSqlExecuteTask(taskName, database.getDatabaseInfo(), createSQL);
TaskExecutor taskExecutor = new CommonTaskExec(taskName);
taskExecutor.addTask(jdbcTask);
new ExecTaskWithProgress(taskExecutor).busyCursorWhile();
if (taskExecutor.isSuccess()) {
triggerName = triggerNameText.getText();
setReturnCode(buttonId);
close();
CommonUITool.openInformationBox(Messages.msgInformation, message);
}
}
use of com.cubrid.common.ui.spi.progress.CommonTaskExec in project cubrid-manager by CUBRID.
the class BLOBCellPopupDialog method exportData.
/**
*
* Export data to file
*
* @param isOpenProgram boolean
* @param filePath String
*/
private boolean exportData(final String filePath, final boolean isOpenProgram) {
final String charsetName = fileCharsetCombo.getText();
if (currValue instanceof String) {
try {
"".getBytes(charsetName);
} catch (UnsupportedEncodingException e) {
CommonUITool.openErrorBox(Messages.errCharset);
return false;
}
}
AbstractUITask task = new AbstractUITask() {
boolean isSuccess = false;
public void execute(final IProgressMonitor monitor) {
BufferedWriter writer = null;
FileOutputStream out = null;
InputStream in = null;
try {
if (currValue instanceof String) {
String content = (String) currValue;
if (DBAttrTypeFormatter.isBinaryString(content)) {
content = DBAttrTypeFormatter.getInnerString(content);
byte[] bytes = DBAttrTypeFormatter.getBytes(content, 2);
content = new String(bytes, charsetName);
} else if (DBAttrTypeFormatter.isHexString(content)) {
content = DBAttrTypeFormatter.getInnerString(content);
byte[] bytes = DBAttrTypeFormatter.getBytes(content, 16);
content = new String(bytes, charsetName);
}
writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(filePath), charsetName));
writer.write(content);
writer.flush();
} else if (currValue instanceof File) {
out = new FileOutputStream(filePath);
in = new FileInputStream((File) currValue);
byte[] bytes = new byte[1024];
int len = 0;
while ((len = in.read(bytes)) != -1) {
out.write(bytes, 0, len);
}
out.flush();
} else if (currValue instanceof byte[]) {
out = new FileOutputStream(filePath);
byte[] bytes = (byte[]) currValue;
out.write(bytes, 0, bytes.length);
out.flush();
}
isSuccess = true;
} catch (Exception e) {
errorMsg = e.getMessage();
} finally {
if (writer != null) {
try {
writer.close();
} catch (IOException e) {
// ignore
}
}
if (out != null) {
try {
out.close();
} catch (IOException e) {
// ignore
}
}
if (in != null) {
try {
in.close();
} catch (IOException e) {
// ignore
}
}
}
}
public void cancel() {
//empty
}
public void finish() {
//empty
}
public boolean isCancel() {
return false;
}
public boolean isSuccess() {
return isSuccess;
}
};
TaskExecutor taskExecutor = new CommonTaskExec(Messages.msgExportFieldData);
taskExecutor.addTask(task);
new ExecTaskWithProgress(taskExecutor).exec();
if (taskExecutor.isSuccess()) {
if (isOpenProgram) {
return true;
}
CommonUITool.openInformationBox(getShell(), Messages.titleSuccess, Messages.msgExportSuccess);
return true;
}
return false;
}
use of com.cubrid.common.ui.spi.progress.CommonTaskExec in project cubrid-manager by CUBRID.
the class BrokerParameterPropertyPage method performOk.
/**
* Save the page content
*
* @return <code>true</code> if it saved successfully;<code>false</code>
* otherwise
*/
public boolean performOk() {
// execute set parameter task
String[][] brokerParameters = ConfConstants.getBrokerParameters(serverInfo);
if (isTableChange()) {
Map<String, String> paraMap = confParaMap.get(node.getLabel());
//compare the default value, if equal default value and delete it from map
for (String[] brokerPara : brokerParameters) {
if (brokerPara[0].equals(ConfConstants.APPL_SERVER_PORT)) {
String serverPort = paraMap.get(ConfConstants.APPL_SERVER_PORT);
if (null != serverPort) {
int serverPortValue = Integer.parseInt(paraMap.get(ConfConstants.BROKER_PORT)) + 1;
if (serverPort.equalsIgnoreCase(Integer.toString(serverPortValue))) {
paraMap.remove(ConfConstants.APPL_SERVER_PORT);
}
}
} else if (brokerPara[0].equals(ConfConstants.LONG_QUERY_TIME)) {
if (isQueryOrTransTimeUseMs) {
int intValue = Integer.parseInt(brokerPara[2]) * 1000;
if (Integer.toString(intValue).equals(paraMap.get(ConfConstants.LONG_QUERY_TIME))) {
paraMap.remove(ConfConstants.LONG_QUERY_TIME);
} else {
String sVal = paraMap.get(ConfConstants.LONG_QUERY_TIME);
double dVal = Double.parseDouble(sVal) / 1000;
paraMap.put(ConfConstants.LONG_QUERY_TIME, String.valueOf(dVal));
}
} else {
if (brokerPara[2].equals(paraMap.get(ConfConstants.LONG_QUERY_TIME))) {
paraMap.remove(ConfConstants.LONG_QUERY_TIME);
}
}
} else if (brokerPara[0].equals(ConfConstants.LONG_TRANSACTION_TIME)) {
if (isQueryOrTransTimeUseMs) {
int intValue = Integer.parseInt(brokerPara[2]) * 1000;
if (Integer.toString(intValue).equals(paraMap.get(ConfConstants.LONG_TRANSACTION_TIME))) {
paraMap.remove(ConfConstants.LONG_TRANSACTION_TIME);
} else {
String sVal = paraMap.get(ConfConstants.LONG_TRANSACTION_TIME);
double dVal = Double.parseDouble(sVal) / 1000;
paraMap.put(ConfConstants.LONG_TRANSACTION_TIME, String.valueOf(dVal));
}
} else {
if (brokerPara[2].equals(paraMap.get(ConfConstants.LONG_TRANSACTION_TIME))) {
paraMap.remove(ConfConstants.LONG_TRANSACTION_TIME);
}
}
} else if (brokerPara[2].equals(paraMap.get(brokerPara[0]))) {
paraMap.remove(brokerPara[0]);
}
}
SetBrokerConfParameterTask setBrokerConfParameterTask = new SetBrokerConfParameterTask(serverInfo);
setBrokerConfParameterTask.setConfParameters(confParaMap);
String taskName = Messages.bind(Messages.setBrokerConfParameterTaskName, this.node.getName());
CommonTaskExec taskExec = new CommonTaskExec(taskName);
taskExec.addTask(setBrokerConfParameterTask);
new ExecTaskWithProgress(taskExec).exec();
if (taskExec.isSuccess()) {
CommonUITool.openInformationBox(com.cubrid.cubridmanager.ui.common.Messages.titleSuccess, Messages.restartBrokerMsg);
} else {
return true;
}
}
// refresh tap
if (isSettingChange()) {
boolean isOn = refreshBtn.getSelection();
String interval = intervalTxt.getText();
String serverName = node.getServer().getLabel();
String nodeName = node.getLabel();
BrokerIntervalSetting newSetting = new BrokerIntervalSetting(serverName, nodeName, interval, isOn);
BrokerIntervalSettingManager manager = BrokerIntervalSettingManager.getInstance();
manager.removeBrokerIntervalSetting(serverName, brokerName);
manager.setBrokerInterval(newSetting);
}
return true;
}
Aggregations