use of com.cubrid.common.ui.spi.progress.TaskJobExecutor in project cubrid-manager by CUBRID.
the class UnloadDatabaseDialog method unloadDatabase.
/**
*
* Execute task and unload database
*
* @param buttonId the button id
*/
private void unloadDatabase(final int buttonId) {
isCanFinished = true;
TaskJobExecutor taskExcutor = new TaskJobExecutor() {
private List<String> unloadResultList = null;
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() {
setReturnCode(buttonId);
close();
}
});
isCanFinished = true;
return Status.CANCEL_STATUS;
}
for (ITask task : taskList) {
task.execute();
final String msg = task.getErrorMsg();
if (monitor.isCanceled()) {
cancel();
Display.getDefault().syncExec(new Runnable() {
public void run() {
setReturnCode(buttonId);
close();
}
});
isCanFinished = true;
return Status.CANCEL_STATUS;
}
if (msg != null && msg.length() > 0 && !monitor.isCanceled() && !isCanceled()) {
Display.getDefault().syncExec(new Runnable() {
public void run() {
getShell().setVisible(true);
}
});
isCanFinished = false;
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;
getShell().setVisible(true);
}
}
});
}
} else if (task instanceof CheckFileTask) {
CheckFileTask checkFileTask = (CheckFileTask) task;
final String[] files = checkFileTask.getExistFiles();
if (files != null && files.length > 0) {
Display.getDefault().syncExec(new Runnable() {
public void run() {
OverrideFileDialog dialog = new OverrideFileDialog(getShell());
dialog.setFiles(files);
if (dialog.open() != IDialogConstants.OK_ID) {
isCanFinished = false;
getShell().setVisible(true);
}
}
});
}
} else if (task instanceof UnloadDatabaseTask) {
UnloadDatabaseTask unloadDatabaseTask = (UnloadDatabaseTask) task;
if (!isSchemaOnly) {
unloadResultList = unloadDatabaseTask.getUnloadDbResult();
}
}
if (!isCanFinished) {
return Status.CANCEL_STATUS;
}
if (monitor.isCanceled()) {
Display.getDefault().syncExec(new Runnable() {
public void run() {
setReturnCode(buttonId);
close();
}
});
return Status.CANCEL_STATUS;
}
}
return Status.OK_STATUS;
}
/**
* Notification that a job has completed execution,
*
* @param event the event details
*/
public void done(IJobChangeEvent event) {
if (event.getResult() == Status.OK_STATUS) {
if (isSchemaOnly) {
Display.getDefault().syncExec(new Runnable() {
public void run() {
CommonUITool.openInformationBox(getShell(), Messages.titleSuccess, Messages.msgSuccessUnload);
setReturnCode(buttonId);
close();
}
});
} else {
Display.getDefault().syncExec(new Runnable() {
public void run() {
UnloadDatabaseResultDialog dialog = new UnloadDatabaseResultDialog(getShell());
dialog.setUnloadResulList(unloadResultList);
dialog.open();
setReturnCode(buttonId);
close();
}
});
}
}
}
};
CheckDirTask checkDirTask = new CheckDirTask(database.getServer().getServerInfo());
CheckFileTask checkFileTask = new CheckFileTask(database.getServer().getServerInfo());
final UnloadDatabaseTask unloadDatabaseTask = new UnloadDatabaseTask(database.getServer().getServerInfo(), database.getDatabaseInfo().getCharSet());
fillTask(taskExcutor, checkDirTask, checkFileTask, unloadDatabaseTask);
String serverName = database.getServer().getName();
String dbName = database.getName();
String jobName = Messages.msgUnloadDbRearJobName + " - " + dbName + "@" + serverName;
JobFamily jobFamily = new JobFamily();
jobFamily.setServerName(serverName);
jobFamily.setDbName(dbName);
taskExcutor.schedule(jobName, jobFamily, true, Job.SHORT);
}
use of com.cubrid.common.ui.spi.progress.TaskJobExecutor in project cubrid-manager by CUBRID.
the class OptimizeDialog method exec.
/**
*
* Execute to optimize the table
*
* @param buttonId the button id
* @param task the task
* @param cancelable whether it is cancelable
* @param shell the shell
*/
public void exec(final int buttonId, final SocketTask task, boolean cancelable, Shell shell) {
TaskJobExecutor taskJobExecutor = new TaskJobExecutor() {
@Override
public IStatus exec(IProgressMonitor monitor) {
if (monitor.isCanceled()) {
return Status.CANCEL_STATUS;
}
for (final ITask t : taskList) {
t.execute();
final String msg = t.getErrorMsg();
if (monitor.isCanceled()) {
return Status.CANCEL_STATUS;
}
if (msg != null && msg.length() > 0 && !monitor.isCanceled()) {
return new Status(IStatus.ERROR, CubridManagerUIPlugin.PLUGIN_ID, msg);
} else {
Display.getDefault().syncExec(new Runnable() {
public void run() {
TableItem item = new TableItem(volumeTable, SWT.NONE);
if (t.getErrorMsg() == null) {
item.setText(Messages.bind(Messages.errOptimizeSuccess, className.getText()));
} else {
CommonUITool.openInformationBox(getShell(), Messages.titleFailure, Messages.bind(Messages.errOptimizeFail, className.getText(), task.getErrorMsg()));
item.setText(Messages.errOptimizeFail + className.getText() + "-" + task.getErrorMsg());
}
volumeTable.getColumn(0).pack();
}
});
}
if (monitor.isCanceled()) {
return Status.CANCEL_STATUS;
}
}
return Status.OK_STATUS;
}
};
taskJobExecutor.addTask(task);
String serverName = database.getServer().getName();
String dbName = database.getName();
String jobName = Messages.titleOptimizeDbDialog + " - " + dbName + "@" + serverName;
taskJobExecutor.schedule(jobName, null, false, Job.SHORT);
}
use of com.cubrid.common.ui.spi.progress.TaskJobExecutor in project cubrid-manager by CUBRID.
the class ParamDumpDialog method buttonPressed.
/**
* When press button in button bar,call this method
*
* @param buttonId the button id
*/
protected void buttonPressed(int buttonId) {
if (buttonId == IDialogConstants.OK_ID) {
if (!verify()) {
return;
}
task = new ParamDumpTask(database.getServer().getServerInfo());
task.setDbName(database.getName());
task.setBoth(repairButton.getSelection() ? YesNoType.Y : YesNoType.N);
String serverName = database.getServer().getName();
String dbName = database.getName();
jobName = Messages.titleParamDumpDialog + " - " + dbName + "@" + serverName;
TaskJobExecutor taskExec = new CommonTaskJobExec(this);
taskExec.addTask(task);
JobFamily jobFamily = new JobFamily();
jobFamily.setServerName(serverName);
jobFamily.setDbName(dbName);
taskExec.schedule(jobName, jobFamily, true, Job.SHORT);
return;
}
super.buttonPressed(buttonId);
}
use of com.cubrid.common.ui.spi.progress.TaskJobExecutor in project cubrid-manager by CUBRID.
the class ViewReplicationErrorLogAction method run.
/**
* view replication error log
*/
public void run() {
final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (window == null) {
return;
}
Object[] obj = this.getSelectedObj();
if (!isSupported(obj[0])) {
setEnabled(false);
return;
}
final ISchemaNode schemaNode = (ISchemaNode) obj[0];
cubridNode = schemaNode;
ReplicationInfo replInfo = (ReplicationInfo) schemaNode.getAdapter(ReplicationInfo.class);
final GetLogListTask task = new GetLogListTask(schemaNode.getServer().getServerInfo());
TaskJobExecutor taskJobExecutor = new TaskJobExecutor() {
public IStatus exec(IProgressMonitor monitor) {
if (monitor.isCanceled()) {
cubridNode = null;
return Status.CANCEL_STATUS;
}
for (ITask t : taskList) {
t.execute();
final String msg = t.getErrorMsg();
if (monitor.isCanceled()) {
cubridNode = null;
return Status.CANCEL_STATUS;
}
if (msg != null && msg.length() > 0 && !monitor.isCanceled()) {
cubridNode = null;
return new Status(IStatus.ERROR, CubridManagerUIPlugin.PLUGIN_ID, msg);
} else {
Display.getDefault().syncExec(new Runnable() {
public void run() {
LogContentInfo logContentInfo = (LogContentInfo) task.getLogContent();
IEditorPart editorPart = LayoutUtil.getEditorPart(cubridNode, LogEditorPart.ID);
if (editorPart != null) {
window.getActivePage().closeEditor(editorPart, false);
}
try {
IEditorPart editor = window.getActivePage().openEditor(cubridNode, LogEditorPart.ID);
((LogEditorPart) editor).setTableInfo(logContentInfo, true);
} catch (PartInitException e) {
LOGGER.error(e.getMessage(), e);
}
}
});
}
if (monitor.isCanceled()) {
cubridNode = null;
return Status.CANCEL_STATUS;
}
}
cubridNode = null;
return Status.OK_STATUS;
}
};
String errPath = replInfo.getDistInfo().getCopyLogPath().substring(0, replInfo.getDistInfo().getCopyLogPath().indexOf(replInfo.getDistInfo().getDistDbName())) + replInfo.getDistInfo().getDistDbName() + schemaNode.getServer().getServerInfo().getPathSeparator() + replInfo.getDistInfo().getDistDbName() + ".err";
task.setPath(errPath);
task.setStart("1");
task.setEnd("100");
taskJobExecutor.addTask(task);
String jobName = Messages.viewLogJobName + " - " + cubridNode.getName() + "@" + cubridNode.getServer().getName();
taskJobExecutor.schedule(jobName, null, false, Job.SHORT);
}
use of com.cubrid.common.ui.spi.progress.TaskJobExecutor in project cubrid-manager by CUBRID.
the class ChangeReplTablesWizard method performFinish.
/**
* Called when user clicks Finish
*
* @return boolean
*/
public boolean performFinish() {
String mdbName = setDatabaseInfoPage.getMasterDbName();
String distdbName = setDatabaseInfoPage.getDistributorDbName();
String distdbPassword = setDatabaseInfoPage.getDistdbPassword();
boolean isReplAllTables = changeTablesPage.isReplAllTables();
List<String> replTableList = changeTablesPage.getReplTableList();
TaskJobExecutor taskExcutor = new TaskJobExecutor() {
public void closeUI() {
Display.getDefault().syncExec(new Runnable() {
public void run() {
dialog.close();
}
});
}
public void setVisible(final boolean isVisible) {
Display display = Display.getDefault();
display.syncExec(new Runnable() {
public void run() {
dialog.getShell().setVisible(isVisible);
}
});
}
public IStatus exec(final IProgressMonitor monitor) {
setVisible(false);
for (ITask task : taskList) {
task.execute();
if (monitor.isCanceled()) {
closeUI();
return Status.CANCEL_STATUS;
}
final String msg = task.getErrorMsg();
if (msg != null && msg.length() > 0 && !monitor.isCanceled()) {
return new Status(IStatus.ERROR, CubridManagerUIPlugin.PLUGIN_ID, msg);
}
}
closeUI();
return Status.OK_STATUS;
}
};
ServerInfo serverInfo = replicationNode.getServer().getServerInfo();
ChangeReplTablesTask task = new ChangeReplTablesTask(serverInfo);
task.setMdbName(mdbName);
task.setDistdbName(distdbName);
task.setDistdbPassword(distdbPassword);
task.setReplAllClasses(isReplAllTables);
task.setReplicatedClasses(replTableList);
taskExcutor.addTask(task);
JobFamily jobFamily = new JobFamily();
String serverName = replicationNode.getServer().getName();
jobFamily.setServerName(serverName);
jobFamily.setDbName(distdbName);
String jobName = Messages.bind(Messages.changeReplicationSchemaJobName, new String[] { distdbName, serverName });
taskExcutor.schedule(jobName, jobFamily, true, Job.SHORT);
return false;
}
Aggregations