Search in sources :

Example 86 with CommonTaskExec

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

the class DeleteUserAction method doRun.

public void doRun(ISchemaNode node) {
    // FIXME move this logic to core module
    CubridDatabase database = node.getDatabase();
    if (database == null || node == null) {
        CommonUITool.openErrorBox(getShell(), Messages.msgSelectDB);
        return;
    }
    String childId = database.getId() + ICubridNodeLoader.NODE_SEPARATOR + CubridNodeLoader.USERS_FOLDER_ID;
    ICubridNode folderNode = database.getChild(childId);
    if (folderNode == null || !folderNode.getLoader().isLoaded()) {
        return;
    }
    //		if (database.getDatabaseInfo().isHAMode()) {
    //			CommonUITool.openErrorBox(com.cubrid.cubridmanager.ui.common.Messages.errNoSupportInHA);
    //			return;
    //		}
    TaskExecutor taskExecutor = new CommonTaskExec(CommonTaskName.DELETE_USER_TASK_NAME);
    DropUserTask task = new DropUserTask(database.getDatabaseInfo(), node.getName());
    taskExecutor.addTask(task);
    new ExecTaskWithProgress(taskExecutor).busyCursorWhile();
    if (taskExecutor.isSuccess()) {
        CubridNavigatorView navigatorView = CubridNavigatorView.findNavigationView();
        if (navigatorView != null) {
            TreeViewer treeViewer = navigatorView.getViewer();
            if (treeViewer != null) {
                //refresh user folder count label
                CubridNodeChangedEvent event = new CubridNodeChangedEvent(folderNode, CubridNodeChangedEventType.NODE_REFRESH);
                CubridNodeManager.getInstance().fireCubridNodeChanged(event);
                CommonUITool.updateFolderNodeLabelIncludingChildrenCount(treeViewer, node.getParent());
                CommonUITool.openInformationBox(com.cubrid.common.ui.common.Messages.titleSuccess, Messages.msgDeleteUserSuccess);
            }
        }
    }
}
Also used : CommonTaskExec(com.cubrid.common.ui.spi.progress.CommonTaskExec) TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) CubridNavigatorView(com.cubrid.common.ui.common.navigator.CubridNavigatorView) TreeViewer(org.eclipse.jface.viewers.TreeViewer) DropUserTask(com.cubrid.cubridmanager.core.cubrid.user.task.DropUserTask) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) CubridNodeChangedEvent(com.cubrid.common.ui.spi.event.CubridNodeChangedEvent) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase)

Example 87 with CommonTaskExec

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

the class CreateTriggerDialog method executeBySocket.

/**
	 *
	 * Execute to add or alter trigger by socket
	 *
	 * @param buttonId int
	 */
private void executeBySocket(int buttonId) {
    // FIXME remove
    String taskName = null;
    String message = null;
    ITask executedTask = null;
    if (buttonId == IDialogConstants.OK_ID) {
        String eventType = getEventType();
        String triggerEventTargetTable = triggerTargetTableCombo.getText().trim();
        String triggerEventTargetColumn = triggerTargetColumnCombo.getText().trim();
        AddTriggerTask task = new AddTriggerTask(database.getServer().getServerInfo());
        task.setDbName(database.getName());
        task.setTriggerName("\"" + triggerName + "\"");
        String eventTime = getEventTime();
        task.setConditionTime(TriggerConditionTime.eval(eventTime));
        task.setEventType(TriggerEvent.eval(eventType));
        String triggerActionType = getActionType();
        String triggerAction = triggerActionText.getText().trim();
        String crChar = "\r";
        String nlChar = "\n";
        triggerAction = triggerAction.replaceAll(crChar, "");
        triggerAction = triggerAction.replaceAll(nlChar, " ");
        task.setAction(Trigger.TriggerAction.eval(triggerActionType), triggerAction);
        if (triggerEventTargetTable.length() > 0) {
            if (triggerEventTargetColumn.length() > 0) {
                task.setEventTarget("\"" + triggerEventTargetTable + "\"(\"" + triggerEventTargetColumn + "\")");
            } else {
                task.setEventTarget("\"" + triggerEventTargetTable + "\"");
            }
        }
        String actionTime = getActionTime();
        if (!actionTime.equals(Messages.actionTimeDefault)) {
            // action time selected
            task.setActionTime(TriggerActionTime.eval(actionTime));
        }
        String triggerCondition = triggerConditionText.getText().trim();
        triggerCondition = triggerCondition.replaceAll(crChar, "");
        triggerCondition = triggerCondition.replaceAll(nlChar, " ");
        task.setCondition(triggerCondition);
        String triggerStatus = this.getStatus();
        task.setStatus(TriggerStatus.eval(triggerStatus));
        String strPriority = triggerPriorityText.getText();
        task.setPriority(strPriority);
        taskName = Messages.bind(Messages.addTriggerTaskName, triggerName);
        message = Messages.newTriggerSuccess;
        executedTask = task;
    } else if (buttonId == ALTER_TRIGGER_OK_ID) {
        AlterTriggerTask task = new AlterTriggerTask(database.getServer().getServerInfo());
        task.setDbName(database.getName());
        task.setTriggerName(trigger.getName());
        String triggerStatus = this.getStatus();
        task.setStatus(TriggerStatus.eval(triggerStatus));
        String strPriority = triggerPriorityText.getText();
        task.setPriority(strPriority);
        taskName = Messages.bind(Messages.alterTriggerTaskName, trigger.getName());
        message = Messages.alterTriggerSuccess;
        executedTask = task;
    }
    TaskExecutor taskExecutor = new CommonTaskExec(taskName);
    taskExecutor.addTask(executedTask);
    new ExecTaskWithProgress(taskExecutor).busyCursorWhile();
    if (taskExecutor.isSuccess()) {
        setReturnCode(buttonId);
        close();
        CommonUITool.openInformationBox(Messages.msgInformation, message);
    }
}
Also used : CommonTaskExec(com.cubrid.common.ui.spi.progress.CommonTaskExec) ITask(com.cubrid.common.core.task.ITask) TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) AddTriggerTask(com.cubrid.cubridmanager.core.cubrid.trigger.task.AddTriggerTask) AlterTriggerTask(com.cubrid.cubridmanager.core.cubrid.trigger.task.AlterTriggerTask)

Example 88 with CommonTaskExec

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

the class DropTableAction method doRun.

/**
	 * Do run
	 * @param obj
	 */
private void doRun(Object[] obj) {
    int len = obj.length;
    StringBuilder sb = new StringBuilder();
    ISchemaNode table = (ISchemaNode) obj[0];
    // FIXME move this logic to core module
    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);
        }
        //TODO -KK
        TreeViewer treeViewer = CubridNavigatorView.findNavigationView().getViewer();
        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]);
        }
        treeViewer.remove(parent, obj);
        treeViewer.setSelection(new StructuredSelection(parent), true);
        //refresh user folder count label
        CommonUITool.updateFolderNodeLabelIncludingChildrenCount(treeViewer, 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 : CommonTaskExec(com.cubrid.common.ui.spi.progress.CommonTaskExec) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) ISchemaNode(com.cubrid.common.ui.spi.model.ISchemaNode) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) SQLException(java.sql.SQLException) TreeViewer(org.eclipse.jface.viewers.TreeViewer) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) TableEditorInput(com.cubrid.common.ui.cubrid.table.editor.TableEditorInput) 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) IEditorReference(org.eclipse.ui.IEditorReference) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) DropTableOrViewTask(com.cubrid.cubridmanager.core.cubrid.table.task.DropTableOrViewTask)

Example 89 with CommonTaskExec

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

the class DropViewAction method run.

public void run(ISchemaNode[] nodeArray) {
    if (nodeArray == null || nodeArray.length == 0) {
        return;
    }
    int selectedCount = nodeArray.length;
    ISchemaNode table = nodeArray[0];
    String type = table.getType();
    String message = null;
    if (NodeType.USER_VIEW.equals(type)) {
        message = Messages.bind(Messages.dropView, selectedCount);
    }
    boolean ret = CommonUITool.openConfirmBox(message);
    if (!ret) {
        canceledTask = true;
        return;
    }
    String taskName = Messages.bind(Messages.dropTableTaskName, selectedCount);
    TaskExecutor taskExecutor = new CommonTaskExec(taskName);
    DropTableOrViewTask task = new DropTableOrViewTask(table.getDatabase().getDatabaseInfo());
    List<String> viewNameList = new ArrayList<String>();
    for (int i = 0; i < selectedCount; i++) {
        table = (DefaultSchemaNode) nodeArray[i];
        type = table.getType();
        if (NodeType.USER_VIEW.equals(type)) {
            viewNameList.add(table.getName());
        }
    }
    String[] viewNames = new String[viewNameList.size()];
    viewNames = viewNameList.toArray(viewNames);
    task.setViewName(viewNames);
    taskExecutor.addTask(task);
    new ExecTaskWithProgress(taskExecutor).exec();
    if (taskExecutor.isSuccess()) {
        ISelectionProvider provider = this.getSelectionProvider();
        final TreeViewer viewer = (TreeViewer) provider;
        ICubridNode parent = table.getParent();
        table.getDatabase().getDatabaseInfo().removeSchema(table.getName());
        for (int i = 0; i < selectedCount; i++) {
            parent.removeChild(nodeArray[i]);
            /*Broadcast the view changed*/
            QueryEditorUtil.fireSchemaNodeChanged(nodeArray[i]);
        }
        viewer.remove(parent, nodeArray);
        viewer.setSelection(new StructuredSelection(parent), true);
        CommonUITool.updateFolderNodeLabelIncludingChildrenCount(viewer, parent);
    }
}
Also used : CommonTaskExec(com.cubrid.common.ui.spi.progress.CommonTaskExec) ISchemaNode(com.cubrid.common.ui.spi.model.ISchemaNode) TreeViewer(org.eclipse.jface.viewers.TreeViewer) ArrayList(java.util.ArrayList) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) DropTableOrViewTask(com.cubrid.cubridmanager.core.cubrid.table.task.DropTableOrViewTask)

Example 90 with CommonTaskExec

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

the class NewTableAction method doRun.

private void doRun(ISchemaNode node) {
    CubridDatabase database = node.getDatabase();
    TaskExecutor taskExcutor = new CommonTaskExec(null);
    DatabaseInfo databaseInfo = database.getDatabaseInfo();
    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;
    }
    TableEditorInput input = new TableEditorInput(database, true, null, null, EditTableAction.MODE_TABLE_EDIT);
    List<String> dbUserList = allUserTask.getDbUserList();
    input.setDbUserList(dbUserList);
    if (supportCharset) {
        List<Collation> collations = collationTask.getCollations();
        input.setCollationList(collations);
    }
    try {
        IWorkbench workbench = PlatformUI.getWorkbench();
        IWorkbenchWindow workbenchWindow = workbench.getActiveWorkbenchWindow();
        workbenchWindow.getActivePage().openEditor(input, TableEditorPart.ID);
    } catch (Exception ignore) {
    }
}
Also used : CommonTaskExec(com.cubrid.common.ui.spi.progress.CommonTaskExec) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) TableEditorInput(com.cubrid.common.ui.cubrid.table.editor.TableEditorInput) JDBCGetAllDbUserTask(com.cubrid.cubridmanager.core.cubrid.user.task.JDBCGetAllDbUserTask) 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) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase)

Aggregations

CommonTaskExec (com.cubrid.common.ui.spi.progress.CommonTaskExec)106 ExecTaskWithProgress (com.cubrid.common.ui.spi.progress.ExecTaskWithProgress)106 TaskExecutor (com.cubrid.common.ui.spi.progress.TaskExecutor)81 TreeViewer (org.eclipse.jface.viewers.TreeViewer)31 ServerInfo (com.cubrid.cubridmanager.core.common.model.ServerInfo)24 ArrayList (java.util.ArrayList)24 ICubridNode (com.cubrid.common.ui.spi.model.ICubridNode)23 CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)18 DatabaseInfo (com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo)14 ISchemaNode (com.cubrid.common.ui.spi.model.ISchemaNode)13 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)13 DefaultCubridNode (com.cubrid.common.ui.spi.model.DefaultCubridNode)12 LogInfo (com.cubrid.cubridmanager.core.logs.model.LogInfo)11 IEditorPart (org.eclipse.ui.IEditorPart)11 DefaultSchemaNode (com.cubrid.common.ui.spi.model.DefaultSchemaNode)9 HashMap (java.util.HashMap)9 AbstractUITask (com.cubrid.common.core.task.AbstractUITask)8 Map (java.util.Map)8 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)8 ISelectionProvider (org.eclipse.jface.viewers.ISelectionProvider)8