use of com.cubrid.common.core.task.AbstractUITask in project cubrid-manager by CUBRID.
the class ERSchemaEditor method compareTableSchemas.
public void compareTableSchemas(final String modelName, final Map<String, TableSchema> tableSchema, final Map<String, SchemaInfo> schemaInfos) {
final List<TableSchemaCompareModelInputLazy> input = new ArrayList<TableSchemaCompareModelInputLazy>();
ITask reportBugTask = new AbstractUITask() {
private boolean success = false;
public void cancel() {
}
public void finish() {
}
public boolean isCancel() {
return false;
}
public boolean isSuccess() {
return success;
}
public void execute(IProgressMonitor monitor) {
CubridDatabase database = erSchema.getCubridDatabase();
List<TableDetailInfo> leftDbTableInfoList = TableSchemaCompareUtil.getTableInfoList(database);
final CubridDatabase virtualDb = new CubridDatabase(modelName, modelName);
virtualDb.setVirtual(true);
DatabaseInfo info = database.getDatabaseInfo();
virtualDb.setDatabaseInfo(info);
WrappedDatabaseInfo wrappedDatabaseInfo = new WrappedDatabaseInfo(info);
wrappedDatabaseInfo.addSchemaInfos(schemaInfos);
wrappedDatabaseInfo.addTableSchemas(tableSchema);
ERXmlDatabaseInfoMapper.addWrappedDatabaseInfo(info, wrappedDatabaseInfo);
TableSchemaModel leftModel = TableSchemaCompareUtil.createTableSchemaModel(leftDbTableInfoList);
TableSchemaModel rightModel = new TableSchemaModel();
rightModel.getTableSchemaMap().putAll(tableSchema);
TableSchemaComparator comparator = new TableSchemaComparator(database, virtualDb);
TableSchemaCompareModel model = comparator.compare(leftModel, rightModel);
model.setSourceDB(database);
model.setTargetDB(virtualDb);
input.add(new TableSchemaCompareModelInputLazy(model));
success = true;
}
};
TaskExecutor taskExecutor = new CommonTaskExec(com.cubrid.common.ui.common.Messages.titleSchemaComparison);
taskExecutor.addTask(reportBugTask);
new ExecTaskWithProgress(taskExecutor).exec();
if (taskExecutor.isSuccess()) {
try {
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().openEditor(input.get(0), TableSchemaCompareInfoPart.ID);
} catch (Exception e) {
}
}
}
use of com.cubrid.common.core.task.AbstractUITask in project cubrid-manager by CUBRID.
the class SchemaCompareDialog method buttonPressed.
/**
* Call this method when the button in button bar is pressed
*
* @param buttonId
* the button id
*/
protected void buttonPressed(int buttonId) {
isCanceled = false;
if (buttonId == COMPARE_ID) {
if (!isSelectedAllSideDatabases()) {
CommonUITool.openWarningBox(com.cubrid.common.ui.compare.Messages.errNeedSelectCompareDb);
return;
}
if (isSelectedSameDatabases()) {
CommonUITool.openWarningBox(com.cubrid.common.ui.compare.Messages.errSelectSameCompareDb);
return;
}
final List<String> origDbLabel = new ArrayList<String>();
for (int i = 0; i < selections.size(); i++) {
origDbLabel.add(leftCombo.getItem(i));
}
final int leftIndex = leftCombo.getSelectionIndex();
final int rightIndex = rightCombo.getSelectionIndex();
final List<String> rightDbLabel = new ArrayList<String>();
final List<CubridDatabase> sourceDBList = new ArrayList<CubridDatabase>();
final List<CubridDatabase> targetDBList = new ArrayList<CubridDatabase>();
final List<TableSchemaCompareEditorInput> editorInput = new ArrayList<TableSchemaCompareEditorInput>();
ITask reportBugTask = new AbstractUITask() {
public void cancel() {
isCanceled = true;
}
public void finish() {
}
public boolean isCancel() {
return isCanceled;
}
public boolean isSuccess() {
return true;
}
public void execute(IProgressMonitor monitor) {
// FIXME logic code move to core module
CubridDatabase leftDb = (CubridDatabase) selections.get(leftIndex);
sourceDBList.add(leftDb);
List<TableDetailInfo> leftDbTableInfoList = TableSchemaCompareUtil.getTableInfoList(leftDb);
TableSchemaCompareRunner thread = null;
CubridDatabase rightDb = (CubridDatabase) selections.get(rightIndex);
targetDBList.add(rightDb);
rightDbLabel.add(origDbLabel.get(rightIndex));
thread = new TableSchemaCompareRunner(SchemaCompareDialog.this, leftDb, rightDb, leftDbTableInfoList);
thread.start();
try {
thread.join();
} catch (InterruptedException e) {
LOGGER.error(e.getMessage(), e);
}
TableSchemaCompareEditorInput input = thread.getInput();
editorInput.add(input);
}
};
TaskExecutor taskExecutor = new CommonTaskExec(Messages.titleSchemaComparison);
taskExecutor.addTask(reportBugTask);
new ExecTaskWithProgress(taskExecutor).exec();
if (taskExecutor.isSuccess()) {
for (int i = 0; i < rightDbLabel.size(); i++) {
if (isCanceled) {
return;
}
showSchemaCompareEditor(editorInput.get(i));
}
if (isCanceled) {
return;
}
super.buttonPressed(IDialogConstants.OK_ID);
}
}
super.buttonPressed(buttonId);
}
use of com.cubrid.common.core.task.AbstractUITask in project cubrid-manager by CUBRID.
the class RowDetailDialog method exportData.
/**
* Export data
*
* @param filePath String
*/
private void exportData(final String filePath) {
final String oidStr = dataItem.getText(1);
final String value = columnValueText.getText();
final String fileCharset = fileCharsetCombo.getText();
AbstractUITask task = new AbstractUITask() {
boolean isSuccess = false;
public void execute(final IProgressMonitor monitor) {
try {
export(filePath, oidStr, value, fileCharset);
isSuccess = true;
} catch (IOException e) {
errorMsg = e.getMessage();
} catch (SQLException e) {
errorMsg = e.getMessage();
}
}
public void cancel() {
//empty
}
public void finish() {
//empty
}
public boolean isCancel() {
return false;
}
public boolean isSuccess() {
return isSuccess;
}
};
TaskExecutor taskExecutor = new CommonTaskExec(Messages.exportDataTaskName);
taskExecutor.addTask(task);
new ExecTaskWithProgress(taskExecutor).exec();
if (taskExecutor.isSuccess()) {
CommonUITool.openInformationBox(getShell(), com.cubrid.common.ui.common.Messages.titleSuccess, Messages.msgExportData);
}
}
use of com.cubrid.common.core.task.AbstractUITask in project cubrid-manager by CUBRID.
the class RowDetailDialog method updateData.
/**
* Update data
*/
private void updateData() {
if (!validate()) {
return;
}
final String columnValue = columnValueText.getText();
final String fileCharset = fileCharsetCombo.getText();
final String oid = dataItem.getText(1);
final boolean updateDB = !QueryExecuter.isNewInsertedRecordItem(dataItem);
AbstractUITask task = new AbstractUITask() {
boolean isSuccess = false;
public void execute(IProgressMonitor monitor) {
errorMsg = update(columnValue, fileCharset, oid, updateDB);
isSuccess = errorMsg == null;
}
public void cancel() {
//empty
}
public void finish() {
//empty
}
public boolean isCancel() {
return false;
}
public boolean isSuccess() {
return isSuccess;
}
};
TaskExecutor taskExecutor = new CommonTaskExec(Messages.updateDataTaskName);
taskExecutor.addTask(task);
new ExecTaskWithProgress(taskExecutor).exec();
}
use of com.cubrid.common.core.task.AbstractUITask in project cubrid-manager by CUBRID.
the class LongTextCellPopupDialog method exportData.
/**
*
* Export data to file
*
* @param filePath String
*/
private void exportData(final String filePath) {
final String charsetName = fileCharsetCombo.getText();
final String content = columnValueText.getText();
AbstractUITask task = new AbstractUITask() {
boolean isSuccess = false;
public void execute(final IProgressMonitor monitor) {
BufferedWriter writer = null;
try {
writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(filePath), charsetName));
writer.write(content);
writer.flush();
isSuccess = true;
} catch (IOException e) {
errorMsg = e.getMessage();
} finally {
if (writer != null) {
try {
writer.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()) {
CommonUITool.openInformationBox(getShell(), Messages.titleSuccess, Messages.msgExportSuccess);
}
}
Aggregations