use of com.cubrid.common.core.task.ITask in project cubrid-manager by CUBRID.
the class EditUserDialog method execTask.
public boolean execTask(final int buttonId, final ITask[] tasks, Shell shell) {
final Display display = Display.getCurrent();
TaskExecutor taskExecutor = new TaskExecutor() {
public boolean exec(IProgressMonitor monitor) {
for (ITask task : tasks) {
if (task instanceof GetAllClassListTask) {
setAllClassInfoList(((GetAllClassListTask) task).getAllClassInfoList());
} else {
task.execute();
}
if (openErrorBox(null, task.getErrorMsg(), monitor)) {
return false;
}
if (monitor.isCanceled()) {
return false;
}
}
if (!monitor.isCanceled()) {
display.syncExec(new Runnable() {
public void run() {
if (buttonId > 0) {
setReturnCode(buttonId);
close();
}
}
});
}
return true;
}
};
for (ITask task : tasks) {
taskExecutor.addTask(task);
}
new ExecTaskWithProgress(taskExecutor).busyCursorWhile();
return taskExecutor.isSuccess();
}
use of com.cubrid.common.core.task.ITask in project cubrid-manager by CUBRID.
the class CreateTriggerDialog method executeBySocket.
/**
*
* Execute to add or alter trigger by socket
*
* @param buttonId int
*/
private void executeBySocket(int buttonId) {
// FIXME remove
String taskName = null;
String message = null;
ITask executedTask = null;
if (buttonId == IDialogConstants.OK_ID) {
String eventType = getEventType();
String triggerEventTargetTable = triggerTargetTableCombo.getText().trim();
String triggerEventTargetColumn = triggerTargetColumnCombo.getText().trim();
AddTriggerTask task = new AddTriggerTask(database.getServer().getServerInfo());
task.setDbName(database.getName());
task.setTriggerName("\"" + triggerName + "\"");
String eventTime = getEventTime();
task.setConditionTime(TriggerConditionTime.eval(eventTime));
task.setEventType(TriggerEvent.eval(eventType));
String triggerActionType = getActionType();
String triggerAction = triggerActionText.getText().trim();
String crChar = "\r";
String nlChar = "\n";
triggerAction = triggerAction.replaceAll(crChar, "");
triggerAction = triggerAction.replaceAll(nlChar, " ");
task.setAction(Trigger.TriggerAction.eval(triggerActionType), triggerAction);
if (triggerEventTargetTable.length() > 0) {
if (triggerEventTargetColumn.length() > 0) {
task.setEventTarget("\"" + triggerEventTargetTable + "\"(\"" + triggerEventTargetColumn + "\")");
} else {
task.setEventTarget("\"" + triggerEventTargetTable + "\"");
}
}
String actionTime = getActionTime();
if (!actionTime.equals(Messages.actionTimeDefault)) {
// action time selected
task.setActionTime(TriggerActionTime.eval(actionTime));
}
String triggerCondition = triggerConditionText.getText().trim();
triggerCondition = triggerCondition.replaceAll(crChar, "");
triggerCondition = triggerCondition.replaceAll(nlChar, " ");
task.setCondition(triggerCondition);
String triggerStatus = this.getStatus();
task.setStatus(TriggerStatus.eval(triggerStatus));
String strPriority = triggerPriorityText.getText();
task.setPriority(strPriority);
taskName = Messages.bind(Messages.addTriggerTaskName, triggerName);
message = Messages.newTriggerSuccess;
executedTask = task;
} else if (buttonId == ALTER_TRIGGER_OK_ID) {
AlterTriggerTask task = new AlterTriggerTask(database.getServer().getServerInfo());
task.setDbName(database.getName());
task.setTriggerName(trigger.getName());
String triggerStatus = this.getStatus();
task.setStatus(TriggerStatus.eval(triggerStatus));
String strPriority = triggerPriorityText.getText();
task.setPriority(strPriority);
taskName = Messages.bind(Messages.alterTriggerTaskName, trigger.getName());
message = Messages.alterTriggerSuccess;
executedTask = task;
}
TaskExecutor taskExecutor = new CommonTaskExec(taskName);
taskExecutor.addTask(executedTask);
new ExecTaskWithProgress(taskExecutor).busyCursorWhile();
if (taskExecutor.isSuccess()) {
setReturnCode(buttonId);
close();
CommonUITool.openInformationBox(Messages.msgInformation, message);
}
}
use of com.cubrid.common.core.task.ITask in project cubrid-manager by CUBRID.
the class TruncateTableAction method run.
/**
* @see org.eclipse.jface.action.Action#run()
*/
public void run() {
Object[] obj = this.getSelectedObj();
if (!isSupported(obj)) {
setEnabled(false);
return;
}
StringBuilder sb = new StringBuilder();
int len = obj.length;
final List<String> tableList = new ArrayList<String>();
CubridDatabase database = null;
for (int i = 0; i < len; i++) {
ISchemaNode table = (ISchemaNode) obj[i];
database = table.getDatabase();
final String tableName = table.getName();
tableList.add(tableName);
if (i < 100) {
if (sb.length() > 0) {
sb.append(", ");
}
sb.append(tableName);
}
}
if (len > 100) {
sb.append("...");
}
String message = Messages.bind(Messages.confirmTableDeleteWarn, sb.toString());
if (!CommonUITool.openConfirmBox(message)) {
return;
}
final TruncateTableTask task = new TruncateTableTask(database.getDatabaseInfo());
TaskJobExecutor taskExec = new CommonTaskJobExec(new ITaskExecutorInterceptor() {
public void completeAll() {
CommonUITool.openInformationBox(Messages.msg_information, Messages.resultTableDeleteInformantion);
}
public IStatus postTaskFinished(ITask task) {
return Status.OK_STATUS;
}
});
String[] tableNames = new String[tableList.size()];
tableNames = tableList.toArray(tableNames);
task.setTableName(tableNames);
taskExec.addTask(task);
JobFamily jobFamily = new JobFamily();
String serverName = database.getServer().getName();
String dbName = database.getName();
jobFamily.setServerName(serverName);
jobFamily.setDbName(dbName);
String jobName = Messages.msgTruncateTableJobName + " - " + tableList.toString() + "@" + dbName + "@" + serverName;
taskExec.schedule(jobName, jobFamily, false, Job.SHORT);
}
use of com.cubrid.common.core.task.ITask in project cubrid-manager by CUBRID.
the class ExportERwinDataController 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[] { "*.xml" });
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() {
@Override
public boolean exec(IProgressMonitor monitor) {
for (ITask task : taskList) {
if (task instanceof ExportSchemaTask) {
ExportSchemaTask eTask = (ExportSchemaTask) task;
try {
eTask.initMarshaller();
} catch (JAXBException e) {
e.printStackTrace();
eTask.cancel();
return false;
}
monitor.setTaskName(Messages.msgGenerateInfo);
monitor.worked(50);
eTask.execute();
monitor.setTaskName(Messages.msgFinished);
monitor.worked(100);
monitor.done();
}
}
return true;
}
};
ExportSchemaTask task = new ExportSchemaTask(getERSchema().getAllSchemaInfo(), fileFullName);
List<ERTable> tables = getERSchema().getTables();
Map<String, String> tablePLMap = new HashMap<String, String>();
Map<String, Map<String, List>> tablesPhysicalLogicalMap = new HashMap<String, Map<String, List>>();
for (ERTable table : tables) {
tablePLMap.put(table.getName(true), table.getName(false));
Map<String, List> columnsPLMap = new HashMap<String, List>();
tablesPhysicalLogicalMap.put(table.getName(true), columnsPLMap);
List<ERTableColumn> columns = table.getColumns();
for (ERTableColumn column : columns) {
List<String> logicalNameAndType = new LinkedList<String>();
columnsPLMap.put(column.getName(true), logicalNameAndType);
logicalNameAndType.add(column.getName(false));
logicalNameAndType.add(column.getShowType(false));
}
}
task.setTablePLMap(tablePLMap);
task.setTablesPhysicalLogicalMap(tablesPhysicalLogicalMap);
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 ExportImportGsonDataController 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[] { "*.erd" });
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 ExportGsonDataTask) {
ExportGsonDataTask eTask = (ExportGsonDataTask) task;
monitor.setTaskName(Messages.msgGenerateInfo);
monitor.worked(50);
eTask.execute();
monitor.setTaskName(Messages.msgFinished);
monitor.worked(100);
monitor.done();
}
}
return true;
}
};
ExportGsonDataTask task = new ExportGsonDataTask(getERSchema(), 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();
}
Aggregations