Search in sources :

Example 41 with TaskExecutor

use of com.cubrid.common.ui.spi.progress.TaskExecutor 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;
                    }
                }
            }
        }
    }
}
Also used : DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) SQLException(java.sql.SQLException) TreeViewer(org.eclipse.jface.viewers.TreeViewer) ArrayList(java.util.ArrayList) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) TableEditorInput(com.cubrid.common.ui.cubrid.table.editor.TableEditorInput) IEditorReference(org.eclipse.ui.IEditorReference) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) CommonTaskExec(com.cubrid.common.ui.spi.progress.CommonTaskExec) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) ISchemaNode(com.cubrid.common.ui.spi.model.ISchemaNode) Connection(java.sql.Connection) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) IEditorPart(org.eclipse.ui.IEditorPart) IWorkbench(org.eclipse.ui.IWorkbench) TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) IDatabaseSpec(com.cubrid.common.core.common.model.IDatabaseSpec) DropTableOrViewTask(com.cubrid.cubridmanager.core.cubrid.table.task.DropTableOrViewTask)

Example 42 with TaskExecutor

use of com.cubrid.common.ui.spi.progress.TaskExecutor 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);
        }
    }
}
Also used : CommonTaskExec(com.cubrid.common.ui.spi.progress.CommonTaskExec) ISchemaNode(com.cubrid.common.ui.spi.model.ISchemaNode) ArrayList(java.util.ArrayList) DefaultSchemaNode(com.cubrid.common.ui.spi.model.DefaultSchemaNode) UpdateStatisticsTask(com.cubrid.cubridmanager.core.cubrid.table.task.UpdateStatisticsTask) TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress)

Example 43 with TaskExecutor

use of com.cubrid.common.ui.spi.progress.TaskExecutor 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;
                    }
                }
            }
        }
    }
}
Also used : CommonTaskExec(com.cubrid.common.ui.spi.progress.CommonTaskExec) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) ISchemaNode(com.cubrid.common.ui.spi.model.ISchemaNode) TreeViewer(org.eclipse.jface.viewers.TreeViewer) TableEditorInput(com.cubrid.common.ui.cubrid.table.editor.TableEditorInput) RenameTableOrViewTask(com.cubrid.cubridmanager.core.cubrid.table.task.RenameTableOrViewTask) CubridNodeChangedEvent(com.cubrid.common.ui.spi.event.CubridNodeChangedEvent) IEditorPart(org.eclipse.ui.IEditorPart) DefaultSchemaNode(com.cubrid.common.ui.spi.model.DefaultSchemaNode) IWorkbench(org.eclipse.ui.IWorkbench) RenameTableDialog(com.cubrid.common.ui.cubrid.table.dialog.RenameTableDialog) TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) IEditorReference(org.eclipse.ui.IEditorReference) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) GetTablesTask(com.cubrid.cubridmanager.core.cubrid.table.task.GetTablesTask) ClassInfo(com.cubrid.cubridmanager.core.cubrid.table.model.ClassInfo)

Example 44 with TaskExecutor

use of com.cubrid.common.ui.spi.progress.TaskExecutor in project cubrid-manager by CUBRID.

the class EditTableAction method doRun.

private void doRun(ISchemaNode table, int type) {
    final DatabaseInfo databaseInfo = NodeUtil.findDatabaseInfo(table);
    if (databaseInfo == null) {
        return;
    }
    final String tableName = table.getName();
    TaskExecutor taskExcutor = new TaskExecutor() {

        public boolean exec(final IProgressMonitor monitor) {
            if (monitor.isCanceled()) {
                return false;
            }
            for (ITask task : taskList) {
                task.execute();
                final String msg = task.getErrorMsg();
                if (openErrorBox(shell, msg, monitor)) {
                    return false;
                }
                if (monitor.isCanceled()) {
                    return false;
                }
            }
            databaseInfo.removeSchema(tableName);
            SchemaInfo schemaInfo = databaseInfo.getSchemaInfo(tableName);
            if (schemaInfo == null) {
                openErrorBox(shell, databaseInfo.getErrorMessage(), monitor);
                return false;
            }
            return true;
        }
    };
    boolean supportCharset = CompatibleUtil.isSupportCreateDBByCharset(databaseInfo);
    JDBCGetAllDbUserTask allUserTask = new JDBCGetAllDbUserTask(databaseInfo);
    taskExcutor.addTask(allUserTask);
    GetCollations collationTask = null;
    if (supportCharset) {
        collationTask = new GetCollations(databaseInfo);
        taskExcutor.addTask(collationTask);
    }
    new ExecTaskWithProgress(taskExcutor).busyCursorWhile();
    if (!taskExcutor.isSuccess()) {
        return;
    }
    List<String> dbUserList = allUserTask.getDbUserList();
    SchemaInfo schemaInfo = databaseInfo.getSchemaInfo(tableName);
    TableEditorInput input = new TableEditorInput(table.getDatabase(), false, schemaInfo, table, type);
    input.setDbUserList(dbUserList);
    if (supportCharset) {
        List<Collation> collations = collationTask.getCollations();
        input.setCollationList(collations);
    }
    try {
        IWorkbench workbench = PlatformUI.getWorkbench();
        IWorkbenchWindow workbenchWindow = workbench.getActiveWorkbenchWindow();
        //If true, active opened editor of it and return, else open new editor.
        for (IEditorReference editorRef : workbenchWindow.getActivePage().getEditorReferences()) {
            IEditorPart oldEditor = editorRef.getEditor(true);
            if (oldEditor.getEditorInput() instanceof TableEditorInput) {
                TableEditorInput oldInput = (TableEditorInput) oldEditor.getEditorInput();
                ISchemaNode oldTable = oldInput.getEditedTableNode();
                if (oldTable != null && oldTable.equals(table)) {
                    workbenchWindow.getActivePage().activate(oldEditor);
                    return;
                }
            }
        }
        workbenchWindow.getActivePage().openEditor(input, TableEditorPart.ID);
    } catch (Exception ignore) {
    }
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) ITask(com.cubrid.common.core.task.ITask) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) ISchemaNode(com.cubrid.common.ui.spi.model.ISchemaNode) TableEditorInput(com.cubrid.common.ui.cubrid.table.editor.TableEditorInput) JDBCGetAllDbUserTask(com.cubrid.cubridmanager.core.cubrid.user.task.JDBCGetAllDbUserTask) IEditorPart(org.eclipse.ui.IEditorPart) GetCollations(com.cubrid.cubridmanager.core.cubrid.table.task.GetCollations) Collation(com.cubrid.cubridmanager.core.cubrid.database.model.Collation) IWorkbench(org.eclipse.ui.IWorkbench) TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IEditorReference(org.eclipse.ui.IEditorReference) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) SchemaInfo(com.cubrid.common.core.common.model.SchemaInfo)

Example 45 with TaskExecutor

use of com.cubrid.common.ui.spi.progress.TaskExecutor 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);
    }
}
Also used : CommonTaskExec(com.cubrid.common.ui.spi.progress.CommonTaskExec) TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) CreateLikeTableTask(com.cubrid.cubridmanager.core.cubrid.table.task.CreateLikeTableTask) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress)

Aggregations

ExecTaskWithProgress (com.cubrid.common.ui.spi.progress.ExecTaskWithProgress)124 TaskExecutor (com.cubrid.common.ui.spi.progress.TaskExecutor)124 CommonTaskExec (com.cubrid.common.ui.spi.progress.CommonTaskExec)81 TreeViewer (org.eclipse.jface.viewers.TreeViewer)38 ServerInfo (com.cubrid.cubridmanager.core.common.model.ServerInfo)37 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)37 ITask (com.cubrid.common.core.task.ITask)35 CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)29 ICubridNode (com.cubrid.common.ui.spi.model.ICubridNode)25 DatabaseInfo (com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo)24 ISchemaNode (com.cubrid.common.ui.spi.model.ISchemaNode)23 ArrayList (java.util.ArrayList)23 Shell (org.eclipse.swt.widgets.Shell)15 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)14 ISelectionProvider (org.eclipse.jface.viewers.ISelectionProvider)13 DefaultCubridNode (com.cubrid.common.ui.spi.model.DefaultCubridNode)12 IEditorPart (org.eclipse.ui.IEditorPart)12 LogInfo (com.cubrid.cubridmanager.core.logs.model.LogInfo)11 CubridNodeChangedEvent (com.cubrid.common.ui.spi.event.CubridNodeChangedEvent)10 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)9