use of com.cubrid.common.ui.cubrid.database.erwin.task.ExportSchemaTask in project cubrid-manager by CUBRID.
the class ExportERwinAction method run.
public void run() {
// FIXME logic code move to core module
int selected = 0;
int logined = 0;
Object[] objects = getSelectedObj();
if (objects instanceof Object[]) {
for (Object object : objects) {
if (object instanceof CubridDatabase) {
selected++;
CubridDatabase database = (CubridDatabase) object;
if (database.isLogined()) {
logined++;
}
}
}
}
if (selected > 1) {
CommonUITool.openWarningBox(com.cubrid.common.ui.cubrid.database.erwin.Messages.errERwinSelectLeastOneDb);
return;
}
if (selected <= 0) {
CommonUITool.openWarningBox(com.cubrid.common.ui.cubrid.database.erwin.Messages.errERwinSelectExportDb);
return;
}
if (logined <= 0) {
CommonUITool.openWarningBox(com.cubrid.common.ui.cubrid.database.erwin.Messages.errERwinSelectLoginedDb);
return;
}
FileDialog dialog = new FileDialog(getShell(), SWT.SAVE | SWT.APPLICATION_MODAL);
dialog.setFilterExtensions(new String[] { "*.xml" });
String filename = dialog.open();
if (filename == null) {
return;
}
if (filename.trim().equals("")) {
CommonUITool.openErrorBox(Messages.errFileNameIsEmpty);
return;
}
for (Object obj : objects) {
if (!(obj instanceof CubridDatabase)) {
continue;
}
CubridDatabase database = (CubridDatabase) obj;
final Map<String, SchemaInfo> allSchemaInfos = new HashMap<String, SchemaInfo>();
TaskExecutor executor = new TaskExecutor() {
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();
} else if (task instanceof GetAllSchemaTask) {
monitor.beginTask(Messages.msgGenerateInfo, 100);
GetAllSchemaTask gTask = (GetAllSchemaTask) task;
gTask.execute();
if (task.getErrorMsg() == null) {
allSchemaInfos.putAll(gTask.getSchemas());
}
if (allSchemaInfos.size() == 0) {
continue;
}
}
}
return true;
}
};
ExportSchemaTask task = new ExportSchemaTask(allSchemaInfos, filename);
GetAllSchemaTask schemaTask = new GetAllSchemaTask(database.getDatabaseInfo());
executor.addTask(schemaTask);
executor.addTask(task);
new ExecTaskWithProgress(executor).busyCursorWhile();
if (executor.isSuccess()) {
CommonUITool.openInformationBox(Messages.titleExportSchema, Messages.msgExportSuccess);
}
}
}
use of com.cubrid.common.ui.cubrid.database.erwin.task.ExportSchemaTask 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();
}
Aggregations