use of com.cubrid.common.core.task.AbstractUITask in project cubrid-manager by CUBRID.
the class TableSchemaCompareInfoPart method showTopButtons.
private void showTopButtons() {
final Composite buttonsComposite = new Composite(topSash, SWT.NONE);
buttonsComposite.setLayout(new GridLayout(5, false));
buttonsComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
if (compareRealDatabase) {
showTopButtonsForRealDatabase(buttonsComposite);
}
final Button viewComparisonBtn = new Button(buttonsComposite, SWT.NONE);
viewComparisonBtn.setText(Messages.viewEntireSchemaComparison);
viewComparisonBtn.setToolTipText(Messages.aboutViewEntireSchemaComparison);
viewComparisonBtn.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(final SelectionEvent event) {
final List<String> sourceDBSchema = new ArrayList<String>();
final List<String> targetDBSchema = new ArrayList<String>();
viewComparisonBtn.setEnabled(false);
ITask reportBugTask = new AbstractUITask() {
public void cancel() {
}
public void finish() {
}
public boolean isCancel() {
return false;
}
public boolean isSuccess() {
return true;
}
public void execute(IProgressMonitor monitor) {
Map<String, SchemaInfo> source = compareModel.getSourceSchemas();
Map<String, SchemaInfo> target = compareModel.getTargetSchemas();
List<SchemaInfo> commonTables = new LinkedList<SchemaInfo>();
for (SchemaInfo sourceTable : source.values()) {
if (target.containsKey(sourceTable.getClassname())) {
commonTables.add(sourceTable);
}
}
Collections.sort(commonTables);
String s_schema = getDBSchema(sourceDB, source, commonTables);
sourceDBSchema.add(s_schema);
String t_schema = getDBSchema(targetDB, target, commonTables);
targetDBSchema.add(t_schema);
}
};
TaskExecutor taskExecutor = new CommonTaskExec(Messages.loadEntireSchemaComparison);
taskExecutor.addTask(reportBugTask);
new ExecTaskWithProgress(taskExecutor).exec();
if (taskExecutor.isSuccess()) {
String targetDbName = "";
if (targetDB.isVirtual()) {
targetDbName = Messages.targetDatabase;
if (StringUtil.isNotEmpty(targetDB.getName())) {
targetDbName += " : " + targetDB.getName();
}
} else {
targetDbName = Messages.targetDatabase + ": " + targetDB.getDatabaseInfo().getBrokerIP() + "@" + targetDB.getName();
}
String sourceBrokerIp = sourceDB.getDatabaseInfo().getBrokerIP();
String sourceDbName = sourceDB.getName();
showEntireSchemaCompareEditor(Messages.sourceDatabase + ": " + sourceBrokerIp + "@" + sourceDbName, Messages.targetDatabase + ": " + targetDbName, sourceDBSchema.get(0), targetDBSchema.get(0));
}
viewComparisonBtn.setEnabled(true);
}
});
Button copyAlterFromSourceBtn = new Button(buttonsComposite, SWT.NONE);
copyAlterFromSourceBtn.setText(Messages.copyWholeSchemaAlter + "[" + Messages.fromSourceToTargetLabel + "]");
copyAlterFromSourceBtn.setToolTipText(Messages.aboutCopyAlterSource);
copyAlterFromSourceBtn.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(final SelectionEvent event) {
copyTableAlterDDL(sourceDB, targetDB, true);
}
});
Button copyAlterFromTargetBtn = new Button(buttonsComposite, SWT.NONE);
copyAlterFromTargetBtn.setText(Messages.copyWholeSchemaAlter + "[" + Messages.fromTargetToSourceLabel + "]");
copyAlterFromTargetBtn.setToolTipText(Messages.aboutCopyAlterTarget);
copyAlterFromTargetBtn.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(final SelectionEvent event) {
copyTableAlterDDL(targetDB, sourceDB, false);
}
});
}
use of com.cubrid.common.core.task.AbstractUITask in project cubrid-manager by CUBRID.
the class ImportERwinAction method createCompareModel.
/**
*
* @param tableSchema
* @param schemaInfos
*/
private void createCompareModel(final String modelName, final Map<String, TableSchema> tableSchema, final Map<String, ERWinSchemaInfo> 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) {
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);
Map<String, SchemaInfo> dbSchemaInfos = new HashMap<String, SchemaInfo>();
Collection<ERWinSchemaInfo> erwinSchemas = schemaInfos.values();
for (ERWinSchemaInfo erwinSchema : erwinSchemas) {
SchemaInfo schemaInfo = (SchemaInfo) erwinSchema;
dbSchemaInfos.put(schemaInfo.getClassname(), schemaInfo);
}
wrappedDatabaseInfo.addSchemaInfos(dbSchemaInfos);
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);
// TODO rename class to ErwinCompareModelInput
input.add(new TableSchemaCompareModelInputLazy(model));
success = true;
}
};
TaskExecutor taskExecutor = new CommonTaskExec(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 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.core.task.AbstractUITask in project cubrid-manager by CUBRID.
the class CommonTaskExec method exec.
/**
* Execute the task
*
* @param monitor the monitor
* @return <code>true</code>if success;<code>false</code> otherwise
*/
public boolean exec(final IProgressMonitor monitor) {
if (monitor.isCanceled()) {
return false;
}
if (taskName != null) {
monitor.beginTask(taskName, IProgressMonitor.UNKNOWN);
}
for (final ITask task : taskList) {
if (task instanceof AbstractUITask) {
((AbstractUITask) task).execute(monitor);
} else {
task.execute();
}
String errorMsg = task.getErrorMsg();
if (messageHandler != null) {
errorMsg = messageHandler.translate(task.getErrorMsg());
}
if (openErrorBox(null, errorMsg, monitor)) {
return false;
}
// });
if (taskExeStatus != null && taskExeStatus == Status.CANCEL_STATUS) {
return false;
}
if (taskExeStatus != null && taskExeStatus != Status.OK_STATUS) {
errorMsg = taskExeStatus.getMessage();
if (messageHandler != null) {
errorMsg = messageHandler.translate(taskExeStatus.getMessage());
}
openErrorBox(null, errorMsg, monitor);
return false;
}
if (monitor.isCanceled()) {
return false;
}
}
// });
return true;
}
use of com.cubrid.common.core.task.AbstractUITask in project cubrid-manager by CUBRID.
the class CommonTaskJobExec method exec.
/**
* Execute the task
*
* @param monitor the monitor
* @return <code>true</code>if success;<code>false</code> otherwise
*/
public IStatus exec(IProgressMonitor monitor) {
Display.getDefault().syncExec(new Runnable() {
public void run() {
setDialogVisible(false);
}
});
if (monitor.isCanceled()) {
cancel();
Display.getDefault().syncExec(new Runnable() {
public void run() {
closeDialog();
}
});
return Status.CANCEL_STATUS;
}
for (final ITask task : taskList) {
if (task instanceof AbstractUITask) {
((AbstractUITask) task).execute(monitor);
} else {
task.execute();
}
final String msg = task.getErrorMsg();
if (msg != null && msg.length() > 0 && !monitor.isCanceled() && !isCanceled()) {
Display.getDefault().syncExec(new Runnable() {
public void run() {
setDialogVisible(true);
}
});
return new Status(IStatus.ERROR, CommonUIPlugin.PLUGIN_ID, msg);
} else {
Display.getDefault().syncExec(new Runnable() {
public void run() {
taskExeStatus = refresh(task);
}
});
}
if (taskExeStatus != Status.OK_STATUS) {
Display.getDefault().syncExec(new Runnable() {
public void run() {
setDialogVisible(true);
}
});
return taskExeStatus;
}
if (monitor.isCanceled()) {
cancel();
Display.getDefault().syncExec(new Runnable() {
public void run() {
closeDialog();
}
});
return Status.CANCEL_STATUS;
}
}
return Status.OK_STATUS;
}
Aggregations