Search in sources :

Example 6 with ExecTaskWithProgress

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

the class DeleteSerialAction method run.

/**
	 * Delete the selected serials
	 */
public void run(ISchemaNode[] nodeArray) {
    if (nodeArray == null) {
        LOGGER.error("The nodeArray parameter is a null.");
        return;
    }
    final List<String> serialNameList = new ArrayList<String>();
    final StringBuffer serialNames = new StringBuffer();
    for (int i = 0; nodeArray != null && i < nodeArray.length; i++) {
        if (!isSupported(nodeArray[i])) {
            setEnabled(false);
            return;
        }
        ISchemaNode schemaNode = (ISchemaNode) nodeArray[i];
        if (i == 0) {
            serialNames.append(schemaNode.getLabel());
        }
        serialNameList.add(schemaNode.getLabel());
    }
    if (nodeArray.length > 1) {
        serialNames.append(", ...");
    }
    String cfmMsg = Messages.bind(Messages.msgConfirmDelSerial, serialNames.toString(), nodeArray.length);
    boolean isDelete = CommonUITool.openConfirmBox(getShell(), cfmMsg);
    if (!isDelete) {
        return;
    }
    final Shell shell = getShell();
    TaskExecutor taskExcutor = new TaskExecutor() {

        public boolean exec(final IProgressMonitor monitor) {
            if (monitor.isCanceled()) {
                return false;
            }
            String taskName = Messages.bind(Messages.delSerialTaskName, serialNames.toString());
            monitor.beginTask(taskName, IProgressMonitor.UNKNOWN);
            for (ITask task : taskList) {
                if (task instanceof DeleteSerialTask) {
                    DeleteSerialTask deleteSerialTask = (DeleteSerialTask) task;
                    String[] serialNames = new String[serialNameList.size()];
                    deleteSerialTask.deleteSerial(serialNameList.toArray(serialNames));
                }
                final String msg = task.getErrorMsg();
                if (openErrorBox(shell, msg, monitor)) {
                    return false;
                }
                if (monitor.isCanceled()) {
                    return false;
                }
            }
            return true;
        }
    };
    ISchemaNode schemaNode = (ISchemaNode) nodeArray[0];
    CubridDatabase database = schemaNode.getDatabase();
    DatabaseInfo databaseInfo = database.getDatabaseInfo();
    DeleteSerialTask deleteSerialTask = new DeleteSerialTask(databaseInfo);
    taskExcutor.addTask(deleteSerialTask);
    new ExecTaskWithProgress(taskExcutor).busyCursorWhile();
    if (!taskExcutor.isSuccess()) {
        return;
    }
    ISelectionProvider provider = this.getSelectionProvider();
    ICubridNode parent = schemaNode.getParent();
    if (provider instanceof TreeViewer) {
        TreeViewer viewer = (TreeViewer) provider;
        for (int i = 0; nodeArray != null && i < nodeArray.length; i++) {
            parent.removeChild((ICubridNode) nodeArray[i]);
        }
        viewer.remove(parent, nodeArray);
        viewer.setSelection(new StructuredSelection(parent), true);
        CommonUITool.updateFolderNodeLabelIncludingChildrenCount(viewer, parent);
    }
}
Also used : ITask(com.cubrid.common.core.task.ITask) ISchemaNode(com.cubrid.common.ui.spi.model.ISchemaNode) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) TreeViewer(org.eclipse.jface.viewers.TreeViewer) ArrayList(java.util.ArrayList) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) DeleteSerialTask(com.cubrid.cubridmanager.core.cubrid.serial.task.DeleteSerialTask) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) Shell(org.eclipse.swt.widgets.Shell) TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase)

Example 7 with ExecTaskWithProgress

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

the class EditSerialAction method run.

/**
	 * Open the editSerial dialog and edit serial
	 */
public int run(CubridDatabase database, final ISchemaNode node) {
    final Shell shell = getShell();
    TaskExecutor taskExcutor = new TaskExecutor() {

        public boolean exec(final IProgressMonitor monitor) {
            if (monitor.isCanceled()) {
                return false;
            }
            monitor.beginTask(Messages.loadSerialTaskName, IProgressMonitor.UNKNOWN);
            for (ITask task : taskList) {
                SerialInfo serialInfo = null;
                if (task instanceof GetSerialInfoTask) {
                    GetSerialInfoTask getSerialInfoTask = (GetSerialInfoTask) task;
                    serialInfo = getSerialInfoTask.getSerialInfo(node.getLabel());
                }
                final String msg = task.getErrorMsg();
                if (openErrorBox(shell, msg, monitor)) {
                    return false;
                }
                if (monitor.isCanceled()) {
                    return false;
                }
                if (serialInfo == null) {
                    openErrorBox(shell, Messages.errNameNotExist, monitor);
                    return false;
                }
                node.setModelObj(serialInfo);
            }
            return true;
        }
    };
    DatabaseInfo databaseInfo = database.getDatabaseInfo();
    GetSerialInfoTask task = new GetSerialInfoTask(databaseInfo);
    taskExcutor.addTask(task);
    new ExecTaskWithProgress(taskExcutor).busyCursorWhile();
    if (!taskExcutor.isSuccess()) {
        return IDialogConstants.CANCEL_ID;
    }
    boolean isEditorAble = ActionSupportUtil.isSupportSinSelCheckDbUser(node, NodeType.SERIAL);
    CreateOrEditSerialDialog dialog = new CreateOrEditSerialDialog(getShell(), isEditorAble);
    dialog.setEditedNode(node);
    dialog.setDatabase(database);
    if (dialog.open() == IDialogConstants.OK_ID) {
        CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent(node, CubridNodeChangedEventType.NODE_REFRESH));
        ActionManager.getInstance().fireSelectionChanged(getSelection());
        return IDialogConstants.OK_ID;
    }
    return IDialogConstants.CANCEL_ID;
}
Also used : CreateOrEditSerialDialog(com.cubrid.common.ui.cubrid.serial.dialog.CreateOrEditSerialDialog) Shell(org.eclipse.swt.widgets.Shell) TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ITask(com.cubrid.common.core.task.ITask) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) CubridNodeChangedEvent(com.cubrid.common.ui.spi.event.CubridNodeChangedEvent) SerialInfo(com.cubrid.common.core.common.model.SerialInfo) GetSerialInfoTask(com.cubrid.cubridmanager.core.cubrid.serial.task.GetSerialInfoTask)

Example 8 with ExecTaskWithProgress

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

the class EditUserDialog method buttonPressed.

/**
	 * When press button,call it
	 * 
	 * @param buttonId the button id
	 */
protected void buttonPressed(int buttonId) {
    if (buttonId == IDialogConstants.OK_ID) {
        if (!valid()) {
            return;
        }
        boolean isChangePassword = false;
        if (newFlag) {
            isChangePassword = true;
        } else if (changePwdBtn.getSelection()) {
            isChangePassword = true;
        }
        String password = null;
        if (isChangePassword) {
            password = pwdText.getText();
            if (password == null) {
                password = "";
            }
        }
        this.inputtedPassword = password;
        boolean isNoDbaAuthUser = database.getDatabaseInfo().getAuthLoginedDbUserInfo().getName().equalsIgnoreCase(userName) && !database.getDatabaseInfo().getAuthLoginedDbUserInfo().isDbaAuthority();
        String taskName = Messages.bind(Messages.addOrUpdateUserTaskName, userNameText.getText());
        TaskExecutor taskExecutor = new CommonTaskExec(taskName);
        ITask task = null;
        boolean isDropAndCreateUser = false;
        if (isNoDbaAuthUser) {
            if (isChangePassword) {
                task = new ChangeDbUserPwdTask(database.getDatabaseInfo());
                ChangeDbUserPwdTask changeDbUserPwdTask = (ChangeDbUserPwdTask) task;
                changeDbUserPwdTask.setDbUserName(userName);
                changeDbUserPwdTask.setNewPwd(password);
                taskExecutor.addTask(changeDbUserPwdTask);
            } else {
                super.buttonPressed(IDialogConstants.CANCEL_ID);
                return;
            }
        } else {
            if (newFlag) {
                List<String> groupList = new ArrayList<String>();
                for (int i = 0; i < userGroupTable.getItemCount(); i++) {
                    groupList.add(userGroupTable.getItem(i).getText(0));
                }
                List<String> memberList = new ArrayList<String>();
                for (Map<String, String> map : memberListData) {
                    memberList.add(map.get("0").toLowerCase(Locale.getDefault()));
                }
                task = new CreateUserTask(database.getDatabaseInfo(), userNameText.getText(), pwdText.getText(), groupList, memberList);
                taskExecutor.addTask(task);
            } else {
                if (!groupChange()) {
                    task = new DropUserTask(database.getDatabaseInfo(), userName);
                    taskExecutor.addTask(task);
                    List<String> groupList = new ArrayList<String>();
                    for (int i = 0; i < userGroupTable.getItemCount(); i++) {
                        groupList.add(userGroupTable.getItem(i).getText(0));
                    }
                    List<String> memberList = new ArrayList<String>();
                    for (Map<String, String> map : memberListData) {
                        memberList.add(map.get("0").toLowerCase(Locale.getDefault()));
                    }
                    task = new CreateUserTask(database.getDatabaseInfo(), userNameText.getText(), pwdText.getText(), groupList, memberList);
                    taskExecutor.addTask(task);
                    isDropAndCreateUser = true;
                } else if (isChangePassword) {
                    task = new ChangeDbUserPwdTask(database.getDatabaseInfo());
                    ChangeDbUserPwdTask changeDbUserPwdTask = (ChangeDbUserPwdTask) task;
                    changeDbUserPwdTask.setDbUserName(userName);
                    changeDbUserPwdTask.setNewPwd(password);
                    taskExecutor.addTask(task);
                }
            }
        }
        task = new UpdateAddUserJdbcTask(database.getDatabaseInfo(), userNameText.getText(), classGrantMap, authListData, authListDataOld, isDBAGroup(), isDropAndCreateUser);
        taskExecutor.addTask(task);
        new ExecTaskWithProgress(taskExecutor).busyCursorWhile();
        if (taskExecutor.isSuccess() && isChangePassword && database.getDatabaseInfo().getAuthLoginedDbUserInfo().getName().equalsIgnoreCase(userName)) {
            database.getDatabaseInfo().getAuthLoginedDbUserInfo().setNoEncryptPassword(password);
        }
        if (taskExecutor.isSuccess()) {
            String message = null;
            if (newFlag) {
                message = Messages.msgAddUserSuccess;
            } else {
                message = Messages.msgModifyUserSuccess;
            }
            CommonUITool.openInformationBox(Messages.msgInformation, message);
        } else {
            return;
        }
    }
    super.buttonPressed(buttonId);
}
Also used : CommonTaskExec(com.cubrid.common.ui.spi.progress.CommonTaskExec) ITask(com.cubrid.common.core.task.ITask) ArrayList(java.util.ArrayList) CreateUserTask(com.cubrid.cubridmanager.core.cubrid.user.task.CreateUserTask) TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) ChangeDbUserPwdTask(com.cubrid.cubridmanager.core.cubrid.user.task.ChangeDbUserPwdTask) DropUserTask(com.cubrid.cubridmanager.core.cubrid.user.task.DropUserTask) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) UpdateAddUserJdbcTask(com.cubrid.cubridmanager.core.cubrid.user.task.UpdateAddUserJdbcTask)

Example 9 with ExecTaskWithProgress

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

the class AlterTriggerAction method run.

/**
	 * edit trigger
	 * @param database
	 * @param node
	 * @return
	 */
public int run(final CubridDatabase database, final ISchemaNode node) {
    // FIXME move this logic to core module
    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;
                }
                Trigger trigger = null;
                if (task instanceof GetTriggerListTask) {
                    GetTriggerListTask getTriggerListTask = (GetTriggerListTask) task;
                    List<Trigger> triggerList = getTriggerListTask.getTriggerInfoList();
                    for (int i = 0; triggerList != null && i < triggerList.size(); i++) {
                        Trigger trig = triggerList.get(i);
                        if (node.getName().equals(trig.getName())) {
                            trigger = trig;
                            break;
                        }
                    }
                } else if (task instanceof JDBCGetTriggerInfoTask) {
                    JDBCGetTriggerInfoTask getTriggerInfoTask = (JDBCGetTriggerInfoTask) task;
                    trigger = getTriggerInfoTask.getTriggerInfo(node.getLabel());
                }
                if (trigger == null) {
                    openErrorBox(shell, Messages.errNameNoExist, monitor);
                    return false;
                }
                // getting comment for version after 10.0
                if (CompatibleUtil.isCommentSupports(database.getDatabaseInfo())) {
                    try {
                        SchemaComment schemaComment = SchemaCommentHandler.loadObjectDescription(database.getDatabaseInfo(), JDBCConnectionManager.getConnection(database.getDatabaseInfo(), true), trigger.getName(), CommentType.TRIGGER);
                        trigger.setDescription(schemaComment.getDescription());
                    } catch (SQLException e) {
                        CommonUITool.openErrorBox(e.getMessage());
                    }
                }
                node.setModelObj(trigger);
            }
            return true;
        }
    };
    ITask task = null;
    if (ApplicationType.CUBRID_MANAGER.equals(PerspectiveManager.getInstance().getCurrentMode())) {
        task = new GetTriggerListTask(database.getServer().getServerInfo());
        ((GetTriggerListTask) task).setDbName(database.getName());
    } else {
        task = new JDBCGetTriggerInfoTask(database.getDatabaseInfo());
    }
    taskExcutor.addTask(task);
    new ExecTaskWithProgress(taskExcutor).busyCursorWhile();
    if (!taskExcutor.isSuccess()) {
        return IDialogConstants.CANCEL_ID;
    }
    CreateTriggerDialog dialog = new CreateTriggerDialog(getShell(), node.getDatabase(), (Trigger) node.getAdapter(Trigger.class));
    if (dialog.open() != IDialogConstants.CANCEL_ID) {
        CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent(node, CubridNodeChangedEventType.NODE_REFRESH));
        ActionManager.getInstance().fireSelectionChanged(getSelection());
        return IDialogConstants.OK_ID;
    }
    return IDialogConstants.CANCEL_ID;
}
Also used : ITask(com.cubrid.common.core.task.ITask) JDBCGetTriggerInfoTask(com.cubrid.cubridmanager.core.cubrid.trigger.task.JDBCGetTriggerInfoTask) SQLException(java.sql.SQLException) CubridNodeChangedEvent(com.cubrid.common.ui.spi.event.CubridNodeChangedEvent) TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Trigger(com.cubrid.common.core.common.model.Trigger) GetTriggerListTask(com.cubrid.cubridmanager.core.cubrid.trigger.task.GetTriggerListTask) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) CreateTriggerDialog(com.cubrid.common.ui.cubrid.trigger.dialog.CreateTriggerDialog) SchemaComment(com.cubrid.common.core.schemacomment.model.SchemaComment)

Example 10 with ExecTaskWithProgress

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

the class DropTriggerAction method run.

public void run(ISchemaNode[] nodeArray) {
    // FIXME move this logic to core module
    if (nodeArray == null) {
        LOGGER.error("The nodeArray is a null.");
        return;
    }
    List<String> triggerNameList = new ArrayList<String>();
    StringBuffer bf = new StringBuffer();
    for (int i = 0; nodeArray != null && i < nodeArray.length; i++) {
        DefaultSchemaNode trigger = (DefaultSchemaNode) nodeArray[i];
        triggerNameList.add(trigger.getName());
        if (i == 0) {
            bf.append(trigger.getName());
        }
    }
    if (nodeArray.length > 1) {
        bf.append(", ...");
    }
    String cfmMsg = Messages.bind(Messages.dropTriggerWarnMSG1, nodeArray.length, bf.toString());
    boolean ret = CommonUITool.openConfirmBox(cfmMsg);
    if (!ret) {
        return;
    }
    ISchemaNode triggerNode = (ISchemaNode) nodeArray[0];
    CommonSQLExcuterTask task = new CommonSQLExcuterTask(triggerNode.getDatabase().getDatabaseInfo());
    for (String triggerName : triggerNameList) {
        String sql = "DROP TRIGGER " + QuerySyntax.escapeKeyword(triggerName);
        task.addSqls(sql);
    }
    String taskName = Messages.bind(Messages.dropTriggerTaskName, bf.toString());
    TaskExecutor taskExecutor = new CommonTaskExec(taskName);
    taskExecutor.addTask(task);
    new ExecTaskWithProgress(taskExecutor).busyCursorWhile();
    if (!taskExecutor.isSuccess()) {
        return;
    }
    String title = com.cubrid.common.ui.common.Messages.titleSuccess;
    String msg = Messages.dropTriggerSuccessMsg;
    CommonUITool.openInformationBox(title, msg);
    ISelectionProvider provider = this.getSelectionProvider();
    ICubridNode parent = triggerNode.getParent();
    if (provider instanceof TreeViewer) {
        TreeViewer viewer = (TreeViewer) provider;
        for (int i = 0; nodeArray != null && i < nodeArray.length; i++) {
            parent.removeChild((ISchemaNode) 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) CommonSQLExcuterTask(com.cubrid.cubridmanager.core.common.task.CommonSQLExcuterTask) ArrayList(java.util.ArrayList) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) DefaultSchemaNode(com.cubrid.common.ui.spi.model.DefaultSchemaNode) TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress)

Aggregations

ExecTaskWithProgress (com.cubrid.common.ui.spi.progress.ExecTaskWithProgress)155 TaskExecutor (com.cubrid.common.ui.spi.progress.TaskExecutor)124 CommonTaskExec (com.cubrid.common.ui.spi.progress.CommonTaskExec)106 ServerInfo (com.cubrid.cubridmanager.core.common.model.ServerInfo)40 TreeViewer (org.eclipse.jface.viewers.TreeViewer)39 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)37 ITask (com.cubrid.common.core.task.ITask)35 CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)30 ArrayList (java.util.ArrayList)29 ICubridNode (com.cubrid.common.ui.spi.model.ICubridNode)26 DatabaseInfo (com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo)25 ISchemaNode (com.cubrid.common.ui.spi.model.ISchemaNode)23 Shell (org.eclipse.swt.widgets.Shell)15 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)14 HashMap (java.util.HashMap)13 Map (java.util.Map)13 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