use of com.cubrid.common.ui.spi.progress.CommonTaskExec in project cubrid-manager by CUBRID.
the class RemoveAllErrorLogAction method run.
/**
* Remove all error logs
*/
public void run() {
if (!CommonUITool.openConfirmBox(Messages.warningRemoveLog)) {
return;
}
Object[] selected = this.getSelectedObj();
DelAllLogTask delAllLogTask = new DelAllLogTask(((DefaultCubridNode) selected[0]).getServer().getServerInfo());
String[] path = new String[((DefaultCubridNode) selected[0]).getChildren().size()];
for (int i = 0, len = path.length; i < len; i++) {
path[i] = ((LogInfo) (((DefaultCubridNode) selected[0]).getChildren().get(i).getAdapter(LogInfo.class))).getPath();
}
delAllLogTask.setPath(path);
TaskExecutor taskExecutor = new CommonTaskExec(Messages.removeLogTaskName);
taskExecutor.addTask(delAllLogTask);
new ExecTaskWithProgress(taskExecutor).busyCursorWhile();
if (taskExecutor.isSuccess()) {
TreeViewer treeViewer = (TreeViewer) this.getSelectionProvider();
DefaultCubridNode delNode = ((DefaultCubridNode) selected[0]);
ICubridNode parentNode = delNode.getParent().getParent();
parentNode.removeChild(delNode);
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
IWorkbenchPage activePage = window.getActivePage();
for (int i = 0, len = path.length; i < len; i++) {
IEditorPart editor = activePage.findEditor(((DefaultCubridNode) selected[0]).getChildren().get(i));
treeViewer.remove(((DefaultCubridNode) selected[0]).getChildren().get(i));
if (null != editor) {
activePage.closeEditor(editor, true);
}
}
}
}
use of com.cubrid.common.ui.spi.progress.CommonTaskExec in project cubrid-manager by CUBRID.
the class DeleteProcedureAction method run.
public void run() {
// FIXME logic code move to core module
Object[] objects = this.getSelectedObj();
if (objects == null || !isSupported(objects)) {
this.setEnabled(false);
return;
}
Shell shell = getShell();
CubridDatabase database = null;
ISchemaNode node = null;
if (objects[0] instanceof ISchemaNode && NodeType.STORED_PROCEDURE_PROCEDURE.equals(((ISchemaNode) objects[0]).getType())) {
node = (ISchemaNode) objects[0];
database = node.getDatabase();
}
if (database == null || node == null) {
CommonUITool.openErrorBox(shell, Messages.errSelectProcedure);
return;
}
if (!CommonUITool.openConfirmBox(shell, Messages.msgSureDropProcedure)) {
return;
}
CommonSQLExcuterTask task = new CommonSQLExcuterTask(database.getDatabaseInfo());
String sql = " DROP PROCEDURE " + QuerySyntax.escapeKeyword(node.getName());
task.addSqls(sql);
TaskExecutor taskExcutor = new CommonTaskExec(null);
taskExcutor.addTask(task);
new ExecTaskWithProgress(taskExcutor).busyCursorWhile();
if (!taskExcutor.isSuccess()) {
return;
}
ISelectionProvider provider = this.getSelectionProvider();
ICubridNode parent = node.getParent();
if (provider instanceof TreeViewer) {
TreeViewer viewer = (TreeViewer) provider;
for (int i = 0; objects != null && i < objects.length; i++) {
parent.removeChild((ISchemaNode) objects[i]);
}
viewer.remove(parent, objects);
viewer.setSelection(new StructuredSelection(parent), true);
}
}
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;
}
}
}
}
}
}
Aggregations