use of com.cubrid.common.ui.spi.progress.CommonTaskExec in project cubrid-manager by CUBRID.
the class DropTableAction method run.
/**
* @see org.eclipse.jface.action.Action#run()
*/
public void run() {
Object[] obj = this.getSelectedObj();
if (!isSupported(obj)) {
setEnabled(false);
return;
}
// FIXME move this logic to core module
int len = obj.length;
StringBuilder sb = new StringBuilder();
ISchemaNode table = (ISchemaNode) obj[0];
String type = table.getType();
for (int i = 0; i < len && i < 100; i++) {
table = (DefaultSchemaNode) obj[i];
if (sb.length() > 0) {
sb.append(", ");
}
sb.append(table.getName());
}
if (len > 100) {
sb.append("...");
}
String message = null;
if (NodeType.USER_TABLE.equals(type) || NodeType.USER_PARTITIONED_TABLE_FOLDER.equals(type)) {
message = Messages.bind(Messages.dropTable, sb.toString());
}
boolean ret = CommonUITool.openConfirmBox(message);
if (!ret) {
return;
}
String taskName = Messages.bind(Messages.dropTableTaskName, sb.toString());
TaskExecutor taskExecutor = new CommonTaskExec(taskName);
DropTableOrViewTask task = new DropTableOrViewTask(table.getDatabase().getDatabaseInfo());
List<String> tableNameList = new ArrayList<String>();
for (int i = 0; i < len; i++) {
table = (DefaultSchemaNode) obj[i];
tableNameList.add(table.getName());
}
String[] tableNames = new String[tableNameList.size()];
tableNames = tableNameList.toArray(tableNames);
task.setTableName(tableNames);
taskExecutor.addTask(task);
new ExecTaskWithProgress(taskExecutor).exec();
if (taskExecutor.isSuccess()) {
// delete table/column descriptions which is dropping table.
DatabaseInfo dbInfo = table.getDatabase().getDatabaseInfo();
Connection conn = null;
try {
conn = JDBCConnectionManager.getConnection(dbInfo, false);
IDatabaseSpec dbSpec = table.getDatabase().getDatabaseInfo();
boolean isSupportTableComment = SchemaCommentHandler.isInstalledMetaTable(dbSpec, conn);
if (isSupportTableComment) {
for (int i = 0; i < len; i++) {
table = (DefaultSchemaNode) obj[i];
SchemaCommentHandler.deleteDescription(dbInfo, conn, table.getName());
}
}
} catch (SQLException e) {
LOGGER.error(e.getMessage(), e);
} finally {
QueryUtil.freeQuery(conn);
}
ISelectionProvider provider = this.getSelectionProvider();
final TreeViewer viewer = (TreeViewer) provider;
ICubridNode parent = table.getParent();
table.getDatabase().getDatabaseInfo().removeSchema(table.getName());
for (int i = 0; i < len; i++) {
parent.removeChild((ISchemaNode) obj[i]);
/*Broadcast the view changed*/
QueryEditorUtil.fireSchemaNodeChanged((ISchemaNode) obj[i]);
}
viewer.remove(parent, obj);
viewer.setSelection(new StructuredSelection(parent), true);
//refresh user folder count label
CommonUITool.updateFolderNodeLabelIncludingChildrenCount(viewer, parent);
/*For bug TOOLS-3118: close opened TableEditorPart about dropped table*/
IWorkbench workbench = PlatformUI.getWorkbench();
IWorkbenchWindow workbenchWindow = workbench.getActiveWorkbenchWindow();
for (IEditorReference editorRef : workbenchWindow.getActivePage().getEditorReferences()) {
IEditorPart editor = editorRef.getEditor(true);
if (editor.getEditorInput() instanceof TableEditorInput) {
TableEditorInput input = (TableEditorInput) editor.getEditorInput();
ISchemaNode tableOfEditor = input.getEditedTableNode();
for (int i = 0; i < len; i++) {
if (tableOfEditor.equals((ISchemaNode) obj[i])) {
workbenchWindow.getActivePage().closeEditor(editor, false);
break;
}
}
}
}
}
}
use of com.cubrid.common.ui.spi.progress.CommonTaskExec in project cubrid-manager by CUBRID.
the class UpdateStatisticsAction method run.
public void run() {
Object[] obj = this.getSelectedObj();
if (!isSupported(obj)) {
setEnabled(false);
return;
}
// FIXME move this logic to core module
List<String> sqlList = new ArrayList<String>();
StringBuilder buffer = new StringBuilder();
for (int i = 0; i < obj.length; i++) {
ISchemaNode schemaNode = (ISchemaNode) obj[i];
String tableName = schemaNode.getParent().getName();
int partitionNameLoc = schemaNode.getName().lastIndexOf("__p__");
if (partitionNameLoc == -1) {
continue;
}
partitionNameLoc += 5;
String partitionName = schemaNode.getName().substring(partitionNameLoc);
String sql = "ALTER TABLE " + QuerySyntax.escapeKeyword(tableName) + " ANALYZE PARTITION " + QuerySyntax.escapeKeyword(partitionName);
sqlList.add(sql);
buffer.append(",");
buffer.append(schemaNode.getName());
}
String str = buffer.toString().replaceFirst(",", "");
if (CommonUITool.openConfirmBox(Messages.bind(Messages.msgConfirmUpdateStatis, str))) {
DefaultSchemaNode node = (DefaultSchemaNode) obj[0];
String taskName = Messages.bind(Messages.updateStatisTaskName, node.getName());
TaskExecutor executor = new CommonTaskExec(taskName);
UpdateStatisticsTask task = new UpdateStatisticsTask(node.getDatabase().getDatabaseInfo());
task.setSqlList(sqlList);
executor.addTask(task);
new ExecTaskWithProgress(executor).exec();
if (executor.isSuccess()) {
CommonUITool.openInformationBox(Messages.titleSuccess, Messages.msgSuccessUpdateStatis);
}
}
}
use of com.cubrid.common.ui.spi.progress.CommonTaskExec in project cubrid-manager by CUBRID.
the class RenameTableAction method doRun.
/**
* Perform rename Table
*
* @param cubridDatabase
* @param table
*/
private void doRun(CubridDatabase cubridDatabase, ISchemaNode table) {
boolean isTable = false;
String type = table.getType();
if (NodeType.USER_TABLE.equals(type) || NodeType.USER_PARTITIONED_TABLE_FOLDER.equals(type)) {
isTable = true;
} else if (NodeType.USER_VIEW.equals(type)) {
isTable = false;
}
String tableName = table.getName();
CubridDatabase db = table.getDatabase();
DatabaseInfo dbInfo = db.getDatabaseInfo();
GetTablesTask getTableTask = new GetTablesTask(dbInfo);
List<String> tableList = getTableTask.getAllTableAndViews();
RenameTableDialog dlg = new RenameTableDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), tableName, isTable, tableList, true);
int ret = dlg.open();
if (ret == IDialogConstants.OK_ID) {
String newName = dlg.getNewName();
RenameTableOrViewTask task = new RenameTableOrViewTask(dbInfo);
task.setOldClassName(tableName);
task.setNewClassName(newName);
task.setTable(isTable);
String taskName = Messages.bind(com.cubrid.common.ui.cubrid.table.Messages.renameTableTaskName, new String[] { tableName, newName });
TaskExecutor taskExecutor = new CommonTaskExec(taskName);
taskExecutor.addTask(task);
new ExecTaskWithProgress(taskExecutor).exec();
if (taskExecutor.isSuccess()) {
ISelectionProvider provider = this.getSelectionProvider();
final TreeViewer viewer = (TreeViewer) provider;
//remove the old table schema information
table.getDatabase().getDatabaseInfo().removeSchema(tableName);
DefaultSchemaNode cloneTable = null;
try {
cloneTable = ((DefaultSchemaNode) table).clone();
CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent(cloneTable, CubridNodeChangedEventType.NODE_REMOVE));
} catch (CloneNotSupportedException ex) {
LOGGER.error(ex.getMessage());
}
ClassInfo classInfo = (ClassInfo) table.getAdapter(ClassInfo.class);
classInfo.setClassName(newName);
table.setId(table.getParent().getId() + ICubridNodeLoader.NODE_SEPARATOR + newName);
table.setLabel(newName);
viewer.refresh(table, true);
LayoutManager.getInstance().getWorkbenchContrItem().reopenEditorOrView(table);
CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent(table, CubridNodeChangedEventType.NODE_ADD));
ActionManager.getInstance().fireSelectionChanged(getSelection());
/*Broadcast the view changed*/
QueryEditorUtil.fireSchemaNodeChanged(table);
/*For bug TOOLS-3118: close opened TableEditorPart about dropped table*/
IWorkbench workbench = PlatformUI.getWorkbench();
IWorkbenchWindow workbenchWindow = workbench.getActiveWorkbenchWindow();
for (IEditorReference editorRef : workbenchWindow.getActivePage().getEditorReferences()) {
IEditorPart editor = editorRef.getEditor(true);
if (editor.getEditorInput() instanceof TableEditorInput) {
TableEditorInput input = (TableEditorInput) editor.getEditorInput();
ISchemaNode tableOfEditor = input.getEditedTableNode();
if (tableOfEditor.equals(table)) {
workbenchWindow.getActivePage().closeEditor(editor, false);
break;
}
}
}
}
}
}
use of com.cubrid.common.ui.spi.progress.CommonTaskExec in project cubrid-manager by CUBRID.
the class CreateLikeTableDialog method createTable.
/**
*
* Execute task to create table
*
*/
private void createTable() {
newTableName = newTableNameText.getText();
String taskName = Messages.bind(Messages.createLikeTableTaskName, newTableName);
TaskExecutor executor = new CommonTaskExec(taskName);
CreateLikeTableTask task = new CreateLikeTableTask(getDatabase().getDatabaseInfo());
likeTableName = likeTableNameText.getText();
task.setTableName(newTableName);
task.setLikeTableName(likeTableName);
executor.addTask(task);
new ExecTaskWithProgress(executor).exec();
if (task.isSuccess()) {
super.buttonPressed(IDialogConstants.OK_ID);
}
}
use of com.cubrid.common.ui.spi.progress.CommonTaskExec 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) {
}
}
}
Aggregations