use of com.cubrid.common.core.task.ITask in project cubrid-manager by CUBRID.
the class ExportPictureController method exportData.
public boolean exportData(Shell parentShell, boolean isDirectSave) {
String fileFullName;
if (!isDirectSave || latestFileFullName == null) {
FileDialog dialog = new FileDialog(parentShell, SWT.SAVE | SWT.APPLICATION_MODAL);
dialog.setFilterExtensions(new String[] { "*.jpg", "*.bmp", "*.png", "*.tif" });
fileFullName = dialog.open();
} else {
fileFullName = latestFileFullName;
}
if (fileFullName == null) {
return false;
}
if (fileFullName.trim().length() == 0) {
CommonUITool.openErrorBox(Messages.errFileNameIsEmpty);
return false;
}
TaskExecutor executor = new TaskExecutor() {
public boolean exec(IProgressMonitor monitor) {
for (ITask task : taskList) {
if (task instanceof ExportPictureTask) {
ExportPictureTask eTask = (ExportPictureTask) task;
monitor.setTaskName(Messages.msgGenerateInfo);
monitor.worked(50);
eTask.execute();
monitor.setTaskName(Messages.msgFinished);
monitor.worked(100);
monitor.done();
}
}
return true;
}
};
ExportPictureTask task = new ExportPictureTask(erSchemaEditor, fileFullName);
executor.addTask(task);
new ExecTaskWithProgress(executor).busyCursorWhile();
if (executor.isSuccess()) {
latestFileFullName = fileFullName;
CommonUITool.openInformationBox(com.cubrid.common.ui.er.Messages.titleExport, Messages.bind(com.cubrid.common.ui.er.Messages.msgExportSuccess, fileFullName));
}
return executor.isSuccess();
}
use of com.cubrid.common.core.task.ITask in project cubrid-manager by CUBRID.
the class ExportSQLDataController method exportData.
public boolean exportData(Shell parentShell, boolean isDirectSave) {
String fileFullName;
if (!isDirectSave || latestFileFullName == null) {
FileDialog dialog = new FileDialog(parentShell, SWT.SAVE | SWT.APPLICATION_MODAL);
dialog.setFilterExtensions(new String[] { "*.sql" });
fileFullName = dialog.open();
} else {
fileFullName = latestFileFullName;
}
if (fileFullName == null) {
return false;
}
if (fileFullName.trim().length() == 0) {
CommonUITool.openErrorBox(Messages.errFileNameIsEmpty);
return false;
}
TaskExecutor executor = new TaskExecutor() {
public boolean exec(IProgressMonitor monitor) {
for (ITask task : taskList) {
if (task instanceof ExportSQLDataTask) {
ExportSQLDataTask eTask = (ExportSQLDataTask) task;
monitor.setTaskName(Messages.msgGenerateInfo);
monitor.worked(50);
eTask.execute();
monitor.setTaskName(Messages.msgFinished);
monitor.worked(100);
monitor.done();
}
}
return true;
}
};
ExportSQLDataTask task = new ExportSQLDataTask(erSchemaEditor.getERSchema(), fileFullName, "UTF-8", true);
executor.addTask(task);
new ExecTaskWithProgress(executor).busyCursorWhile();
if (executor.isSuccess()) {
latestFileFullName = fileFullName;
CommonUITool.openInformationBox(com.cubrid.common.ui.er.Messages.titleExport, Messages.bind(com.cubrid.common.ui.er.Messages.msgExportSuccess, fileFullName));
}
return executor.isSuccess();
}
use of com.cubrid.common.core.task.ITask in project cubrid-manager by CUBRID.
the class RenameDatabaseDialog method renameDb.
/**
* Execute task and rename database
*/
private void renameDb() {
newDBName = databaseNameText.getText();
isCanFinished = true;
TaskJobExecutor taskExec = new TaskJobExecutor() {
public IStatus exec(final IProgressMonitor monitor) {
Display.getDefault().syncExec(new Runnable() {
public void run() {
getShell().setVisible(false);
}
});
if (monitor.isCanceled()) {
cancel();
Display.getDefault().syncExec(new Runnable() {
public void run() {
close();
}
});
return Status.CANCEL_STATUS;
}
List<String> cubridConfContentList = null;
for (ITask task : taskList) {
if (task instanceof SetCubridConfParameterTask) {
if (cubridConfContentList == null) {
LOGGER.warn("cubridConfContentList is null. Skip SetCubridConfParameterTask.");
continue;
}
SetCubridConfParameterTask setParaTask = (SetCubridConfParameterTask) task;
setParaTask.setConfContents(cubridConfContentList);
}
task.execute();
final String msg = task.getErrorMsg();
if (msg != null && msg.length() > 0 && !monitor.isCanceled() && !isCanceled()) {
Display.getDefault().syncExec(new Runnable() {
public void run() {
getShell().setVisible(true);
}
});
return new Status(IStatus.ERROR, CubridManagerUIPlugin.PLUGIN_ID, msg);
}
if (isCanceled()) {
return Status.CANCEL_STATUS;
}
if (task instanceof CheckDirTask) {
CheckDirTask checkDirTask = (CheckDirTask) task;
final String[] dirs = checkDirTask.getNoExistDirectory();
if (dirs != null && dirs.length > 0) {
Display.getDefault().syncExec(new Runnable() {
public void run() {
CreateDirDialog dialog = new CreateDirDialog(getShell());
dialog.setDirs(dirs);
if (dialog.open() != IDialogConstants.OK_ID) {
isCanFinished = false;
}
}
});
}
} else if (task instanceof GetCubridConfParameterTask) {
GetCubridConfParameterTask getCubridConfParameterTask = (GetCubridConfParameterTask) task;
cubridConfContentList = CoreUtils.renameDatabaseFromServiceServer(getCubridConfParameterTask, cubridConfContentList, database.getName(), newDBName);
}
if (!isCanFinished || monitor.isCanceled()) {
cancel();
Display.getDefault().syncExec(new Runnable() {
public void run() {
close();
}
});
return Status.CANCEL_STATUS;
}
}
return Status.OK_STATUS;
}
public void done(IJobChangeEvent event) {
if (event.getResult() == Status.OK_STATUS) {
Display.getDefault().syncExec(new Runnable() {
public void run() {
iUpdateUIWithJob.completeAll();
close();
}
});
}
}
};
CheckDirTask checkDirTask = new CheckDirTask(database.getServer().getServerInfo());
RenameDbTask renameDbTask = new RenameDbTask(database.getServer().getServerInfo());
renameDbTask.setDbName(database.getLabel());
renameDbTask.setNewDbName(newDBName);
if (exVolumePathButton.getSelection()) {
checkDirTask.setDirectory(new String[] { exVolumePathText.getText() });
renameDbTask.setExVolumePath(exVolumePathText.getText());
renameDbTask.setAdvanced(false);
} else if (renameVolumeButton.getSelection()) {
List<String> pathList = new ArrayList<String>();
List<String> volumeChangedList = new ArrayList<String>();
for (int i = 0; spaceInfoList != null && i < spaceInfoList.size(); i++) {
Map<String, String> map = spaceInfoList.get(i);
String oldName = map.get("0");
String newName = map.get("1");
String oldPath = map.get("2");
String newPath = map.get("3");
addVolumePath(pathList, newPath);
oldPath = oldPath.replaceAll(":", "|");
newPath = newPath.replaceAll(":", "|");
volumeChangedList.add(oldPath + "/" + oldName + ":" + newPath + "/" + newName);
}
String[] checkedDirs = new String[pathList.size()];
pathList.toArray(checkedDirs);
checkDirTask.setDirectory(checkedDirs);
renameDbTask.setAdvanced(true);
renameDbTask.setIndividualVolume(volumeChangedList);
}
if (forceDelBackupVolumeButton.getSelection()) {
renameDbTask.setForceDel(true);
} else {
renameDbTask.setForceDel(false);
}
taskExec.addTask(renameDbTask);
GetCubridConfParameterTask getCubridConfParameterTask = new GetCubridConfParameterTask(database.getServer().getServerInfo());
taskExec.addTask(getCubridConfParameterTask);
SetCubridConfParameterTask setCubridConfParameterTask = new SetCubridConfParameterTask(database.getServer().getServerInfo());
taskExec.addTask(setCubridConfParameterTask);
JobFamily jobFamily = new JobFamily();
String serverName = database.getServer().getName();
String dbName = database.getName();
jobFamily.setServerName(serverName);
jobFamily.setDbName(dbName);
String jobName = Messages.msgRenameDBRearJobName + " - " + dbName + "@" + serverName;
taskExec.schedule(jobName, jobFamily, true, Job.SHORT);
}
use of com.cubrid.common.core.task.ITask in project cubrid-manager by CUBRID.
the class DeleteDatabaseDialog method deleteDatabase.
/**
*
* Delete the database
*
* @return <code>true</code> if successful;<code>false</code> otherwise
*/
private boolean deleteDatabase() {
TaskExecutor taskExcutor = new TaskExecutor() {
public boolean exec(final IProgressMonitor monitor) {
if (monitor.isCanceled()) {
return false;
}
String taskName = Messages.bind(Messages.delDbTaskName, database.getName());
monitor.beginTask(taskName, IProgressMonitor.UNKNOWN);
boolean isActiveReplServer = false;
boolean isActiveReplAgent = false;
List<String> cubridConfContentList = null;
for (ITask task : taskList) {
if (task instanceof GetReplServerStatusTask) {
GetReplServerStatusTask getReplServerStatusTask = (GetReplServerStatusTask) task;
getReplServerStatusTask.execute();
isActiveReplServer = getReplServerStatusTask.isActive();
} else if (task instanceof StopReplServerTask) {
if (isActiveReplServer) {
task.execute();
}
} else if (task instanceof GetReplAgentStatusTask) {
GetReplAgentStatusTask getReplAgentStatusTask = (GetReplAgentStatusTask) task;
getReplAgentStatusTask.execute();
isActiveReplAgent = getReplAgentStatusTask.isActive();
} else if (task instanceof StopReplicationAgentTask) {
if (isActiveReplAgent) {
task.execute();
}
} else if (task instanceof SetCubridConfParameterTask) {
if (cubridConfContentList == null) {
continue;
} else {
SetCubridConfParameterTask setParaTask = (SetCubridConfParameterTask) task;
setParaTask.setConfContents(cubridConfContentList);
setParaTask.execute();
}
} else {
task.execute();
}
final String msg = task.getErrorMsg();
if (openErrorBox(getShell(), msg, monitor)) {
return false;
}
if (monitor.isCanceled()) {
return false;
}
if (task instanceof GetCubridConfParameterTask) {
GetCubridConfParameterTask getCubridConfParameterTask = (GetCubridConfParameterTask) task;
cubridConfContentList = CoreUtils.deleteDatabaseFromServiceServer(getCubridConfParameterTask, cubridConfContentList, database.getName());
}
}
return true;
}
};
ServerInfo serverInfo = database.getServer().getServerInfo();
//check the replication server and agent
if (serverInfo.isSupportReplication() == 0) {
if (database.isDistributorDb()) {
GetReplAgentStatusTask getReplAgentStatusTask = new GetReplAgentStatusTask(serverInfo);
getReplAgentStatusTask.setDbName(database.getLabel());
taskExcutor.addTask(getReplAgentStatusTask);
StopReplicationAgentTask stopReplAgentTask = new StopReplicationAgentTask(serverInfo);
stopReplAgentTask.setDbName(database.getLabel());
taskExcutor.addTask(stopReplAgentTask);
} else {
GetReplServerStatusTask getReplServerStatusTask = new GetReplServerStatusTask(serverInfo);
getReplServerStatusTask.setDbName(database.getLabel());
taskExcutor.addTask(getReplServerStatusTask);
StopReplServerTask stopReplServerTask = new StopReplServerTask(serverInfo);
stopReplServerTask.setDbName(database.getLabel());
taskExcutor.addTask(stopReplServerTask);
}
}
CommonUpdateTask deleteDbtask = new CommonUpdateTask(CommonTaskName.DELETE_DATABASE_TASK_NAME, serverInfo, CommonSendMsg.getDeletedbSendMsg());
deleteDbtask.setDbName(database.getName());
if (deleteBackupVolumesButton.getSelection()) {
deleteDbtask.setDelbackup(YesNoType.Y);
} else {
deleteDbtask.setDelbackup(YesNoType.N);
}
taskExcutor.addTask(deleteDbtask);
GetCubridConfParameterTask getCubridConfParameterTask = new GetCubridConfParameterTask(serverInfo);
taskExcutor.addTask(getCubridConfParameterTask);
SetCubridConfParameterTask setCubridConfParameterTask = new SetCubridConfParameterTask(serverInfo);
taskExcutor.addTask(setCubridConfParameterTask);
new ExecTaskWithProgress(taskExcutor).exec(true, false);
if (taskExcutor.isSuccess()) {
setReturnCode(DELETE_ID);
close();
return true;
} else {
return false;
}
}
use of com.cubrid.common.core.task.ITask in project cubrid-manager by CUBRID.
the class StopDatabaseAction method run.
public void run() {
Object[] objArr = this.getSelectedObj();
if (objArr == null || objArr.length <= 0) {
setEnabled(false);
return;
}
Set<CubridDatabase> databaseSet = new HashSet<CubridDatabase>();
for (int i = 0; objArr != null && i < objArr.length; i++) {
if (!isSupported(objArr[i])) {
setEnabled(false);
return;
}
ISchemaNode schemaNode = (ISchemaNode) objArr[i];
CubridDatabase database = schemaNode.getDatabase();
databaseSet.add(database);
}
StringBuffer dbNames = new StringBuffer();
Iterator<CubridDatabase> it = databaseSet.iterator();
while (it.hasNext()) {
CubridDatabase database = it.next();
dbNames.append(database.getLabel()).append(",");
}
dbNames = new StringBuffer(dbNames.substring(0, dbNames.length() - 1));
boolean isStop = CommonUITool.openConfirmBox(getShell(), Messages.bind(Messages.msgConfirmStopDatabase, dbNames.toString()));
if (!isStop) {
return;
}
Iterator<CubridDatabase> iter = databaseSet.iterator();
while (iter.hasNext()) {
CubridDatabase database = iter.next();
final JobFamily jobFamily = new JobFamily();
String serverName = database.getServer().getName();
String dbName = database.getName();
jobFamily.setServerName(serverName);
jobFamily.setDbName(dbName);
Job[] jobs = Job.getJobManager().find(jobFamily);
if (jobs.length > 0) {
CommonUITool.openWarningBox(Messages.bind(Messages.msgStopDbWithJob, dbName));
databaseSet.remove(database);
continue;
}
}
final Object[] dbObjectArr = new Object[databaseSet.size()];
databaseSet.toArray(dbObjectArr);
ISelectionProvider provider = getSelectionProvider();
final Shell shell = getShell();
if (provider instanceof TreeViewer && dbObjectArr.length > 0) {
final TreeViewer viewer = (TreeViewer) provider;
TaskExecutor taskExcutor = new TaskExecutor() {
public boolean exec(final IProgressMonitor monitor) {
Display display = Display.getDefault();
if (monitor.isCanceled()) {
return false;
}
for (int i = 0; i < taskList.size(); i++) {
ISchemaNode node = (ISchemaNode) dbObjectArr[i];
final CubridDatabase database = node.getDatabase();
if (!isSupported(database)) {
continue;
}
monitor.subTask(Messages.bind(Messages.stopDbTaskName, database.getName()));
ITask task = taskList.get(i);
task.execute();
final String msg = task.getErrorMsg();
if (openErrorBox(shell, msg, monitor)) {
return false;
}
if (monitor.isCanceled()) {
return false;
}
database.removeAllChild();
if (database.getLoader() != null) {
database.getLoader().setLoaded(false);
}
database.setRunningType(DbRunningType.STANDALONE);
display.syncExec(new Runnable() {
public void run() {
viewer.refresh(database, true);
}
});
if (monitor.isCanceled()) {
return false;
}
}
return true;
}
};
boolean isContinue = true;
for (int i = 0; i < dbObjectArr.length; i++) {
ISchemaNode node = (ISchemaNode) dbObjectArr[i];
CubridDatabase database = node.getDatabase();
if (!isSupported(database)) {
setEnabled(false);
return;
}
if (!LayoutUtil.checkAllQueryEditor(database)) {
isContinue = false;
break;
}
CommonUpdateTask task = new CommonUpdateTask(CommonTaskName.STOP_DB_TASK_NAME, database.getServer().getServerInfo(), CommonSendMsg.getCommonDatabaseSendMsg());
task.setDbName(database.getLabel());
taskExcutor.addTask(task);
}
if (!isContinue) {
return;
}
new ExecTaskWithProgress(taskExcutor).busyCursorWhile();
ActionManager.getInstance().fireSelectionChanged(getSelection());
for (int i = 0; i < dbObjectArr.length; i++) {
CubridDatabase database = (CubridDatabase) dbObjectArr[i];
CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent(database, CubridNodeChangedEventType.DATABASE_STOP));
}
}
}
Aggregations