Search in sources :

Example 21 with ITask

use of com.cubrid.common.core.task.ITask in project cubrid-manager by CUBRID.

the class StartDatabaseAction method doRun.

public void doRun(ISchemaNode[] schemaArray) {
    if (schemaArray == null || schemaArray.length == 0) {
        return;
    }
    List<ISchemaNode> startList = new ArrayList<ISchemaNode>();
    /*Judge start job is running*/
    for (ISchemaNode node : schemaArray) {
        if (!isSupported(node)) {
            setEnabled(false);
            return;
        }
        CubridDatabase database = node.getDatabase();
        final JobFamily jobFamily = new JobFamily();
        String serverName = database.getServer().getName();
        String dbName = database.getName();
        jobFamily.setServerName(serverName);
        jobFamily.setDbName(dbName);
        Job[] jobs = Job.getJobManager().find(jobFamily);
        if (jobs.length > 0) {
            CommonUITool.openWarningBox(Messages.bind(Messages.msgStartDbWithJob, dbName));
            continue;
        }
        startList.add(database);
    }
    CubridNavigatorView navigationView = CubridNavigatorView.findNavigationView();
    if (navigationView != null && startList.size() > 0) {
        final TreeViewer treeViewer = navigationView.getViewer();
        TaskExecutor taskExcutor = new TaskExecutor() {

            public boolean exec(final IProgressMonitor monitor) {
                Display display = Display.getDefault();
                if (monitor.isCanceled()) {
                    return false;
                }
                for (int i = 0; i < taskList.size(); i++) {
                    ITask task = taskList.get(i);
                    final CubridDatabase database = (CubridDatabase) task.getData("dbName");
                    if (!isSupported(database)) {
                        continue;
                    }
                    monitor.subTask(Messages.bind(Messages.startDbTaskName, database.getName()));
                    task.execute();
                    if (openErrorBox(shell, task.getErrorMsg(), monitor) || monitor.isCanceled()) {
                        return false;
                    }
                    openWarningBox(shell, task.getWarningMsg(), monitor);
                    if (monitor.isCanceled()) {
                        return false;
                    }
                    database.removeAllChild();
                    if (database.getLoader() != null) {
                        database.getLoader().setLoaded(false);
                    }
                    database.setRunningType(DbRunningType.CS);
                    display.syncExec(new Runnable() {

                        public void run() {
                            treeViewer.refresh(database, true);
                        }
                    });
                    if (monitor.isCanceled()) {
                        return false;
                    }
                }
                return true;
            }
        };
        for (ISchemaNode schemaNode : startList) {
            CubridDatabase database = schemaNode.getDatabase();
            if (!isSupported(database)) {
                setEnabled(false);
                return;
            }
            ServerInfo serverInfo = database.getServer().getServerInfo();
            CommonUpdateTask task = new CommonUpdateTask(CommonTaskName.START_DB_TASK_NAME, serverInfo, CommonSendMsg.getCommonDatabaseSendMsg());
            task.setDbName(database.getLabel());
            task.putData("dbName", database);
            taskExcutor.addTask(task);
        }
        new ExecTaskWithProgress(taskExcutor).busyCursorWhile();
        ActionManager.getInstance().fireSelectionChanged(getSelection());
    }
}
Also used : ITask(com.cubrid.common.core.task.ITask) ISchemaNode(com.cubrid.common.ui.spi.model.ISchemaNode) TreeViewer(org.eclipse.jface.viewers.TreeViewer) ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo) ArrayList(java.util.ArrayList) JobFamily(com.cubrid.common.ui.spi.progress.JobFamily) CubridNavigatorView(com.cubrid.common.ui.common.navigator.CubridNavigatorView) TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) CommonUpdateTask(com.cubrid.cubridmanager.core.common.task.CommonUpdateTask) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) Job(org.eclipse.core.runtime.jobs.Job) Display(org.eclipse.swt.widgets.Display)

Example 22 with ITask

use of com.cubrid.common.core.task.ITask in project cubrid-manager by CUBRID.

the class UnloadDatabaseAction method run.

public void run() {
    Object[] obj = this.getSelectedObj();
    if (!isSupported(obj[0])) {
        setEnabled(false);
        return;
    }
    ISchemaNode node = (ISchemaNode) obj[0];
    final CubridDatabase database = node.getDatabase();
    final UnloadDatabaseDialog dialog = new UnloadDatabaseDialog(getShell());
    dialog.setDatabase(database);
    final Shell shell = getShell();
    TaskExecutor taskExcutor = new TaskExecutor() {

        public boolean exec(final IProgressMonitor monitor) {
            if (monitor.isCanceled()) {
                return false;
            }
            monitor.beginTask(Messages.loadAllClassTaskName, IProgressMonitor.UNKNOWN);
            for (ITask task : taskList) {
                task.execute();
                final String msg = task.getErrorMsg();
                if (openErrorBox(shell, msg, monitor)) {
                    return false;
                }
                if (monitor.isCanceled()) {
                    return false;
                }
                if (task instanceof GetClassListTask) {
                    GetClassListTask getClassListTask = (GetClassListTask) task;
                    List<String> allUserClassList = new ArrayList<String>();
                    DBClasses dbClasses = getClassListTask.getDbClassInfo();
                    List<ClassItem> userClassList = dbClasses == null ? null : dbClasses.getUserClassList().getClassList();
                    if (userClassList != null && !userClassList.isEmpty()) {
                        for (ClassItem userClass : userClassList) {
                            allUserClassList.add(userClass.getClassname());
                        }
                    }
                    Collections.sort(allUserClassList);
                    dialog.setUserClassList(allUserClassList);
                }
            }
            return true;
        }
    };
    ServerInfo serverInfo = database.getServer().getServerInfo();
    GetClassListTask task = new GetClassListTask(serverInfo, database.getDatabaseInfo().getCharSet());
    task.setDbName(database.getLabel());
    task.setDbStatus(OnOffType.OFF);
    taskExcutor.addTask(task);
    new ExecTaskWithProgress(taskExcutor).busyCursorWhile();
    if (taskExcutor.isSuccess()) {
        dialog.open();
    }
}
Also used : ITask(com.cubrid.common.core.task.ITask) ISchemaNode(com.cubrid.common.ui.spi.model.ISchemaNode) ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo) ArrayList(java.util.ArrayList) Shell(org.eclipse.swt.widgets.Shell) TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ClassItem(com.cubrid.cubridmanager.core.cubrid.table.model.ClassItem) GetClassListTask(com.cubrid.cubridmanager.core.cubrid.table.task.GetClassListTask) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) UnloadDatabaseDialog(com.cubrid.cubridmanager.ui.cubrid.database.dialog.UnloadDatabaseDialog) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) DBClasses(com.cubrid.cubridmanager.core.cubrid.table.model.DBClasses)

Example 23 with ITask

use of com.cubrid.common.core.task.ITask in project cubrid-manager by CUBRID.

the class UserManagementTableViewerSorter method deleteUser.

/**
	 * 
	 * Execute task and delete user
	 * 
	 * @param userInfoMapArr the user info map
	 */
@SuppressWarnings("rawtypes")
private void deleteUser(final Map[] userInfoMapArr) {
    TaskExecutor taskExcutor = new TaskExecutor() {

        public boolean exec(final IProgressMonitor monitor) {
            if (monitor.isCanceled()) {
                return false;
            }
            monitor.beginTask(Messages.delUserTaskName, IProgressMonitor.UNKNOWN);
            for (ITask task : taskList) {
                task.execute();
                final String msg = task.getErrorMsg();
                if (openErrorBox(getShell(), msg, monitor)) {
                    return false;
                }
                if (monitor.isCanceled()) {
                    return false;
                }
                if (task instanceof DeleteCMUserTask) {
                    DeleteCMUserTask deleteCMUserTask = (DeleteCMUserTask) task;
                    String userId = deleteCMUserTask.getUserId();
                    for (int i = 0; i < userInfoMapArr.length; i++) {
                        String id = (String) userInfoMapArr[i].get("0");
                        if (userId.equals(id)) {
                            serverUserInfoTableList.remove(userInfoMapArr[i]);
                            ServerType serverType = server.getServerInfo().getServerType();
                            if (serverType == ServerType.BOTH) {
                                serverUserInfoList.remove(userInfoMapArr[i].get("4"));
                            } else {
                                serverUserInfoList.remove(userInfoMapArr[i].get("3"));
                            }
                            break;
                        }
                    }
                }
            }
            return true;
        }
    };
    for (int i = 0; userInfoMapArr != null && i < userInfoMapArr.length; i++) {
        DeleteCMUserTask deleteTask = new DeleteCMUserTask(server.getServerInfo());
        Map map = userInfoMapArr[i];
        deleteTask.setUserId((String) map.get("0"));
        taskExcutor.addTask(deleteTask);
    }
    new ExecTaskWithProgress(taskExcutor).exec(true, true);
}
Also used : ServerType(com.cubrid.cubridmanager.core.common.model.ServerType) TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ITask(com.cubrid.common.core.task.ITask) DeleteCMUserTask(com.cubrid.cubridmanager.core.common.task.DeleteCMUserTask) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) HashMap(java.util.HashMap) Map(java.util.Map)

Example 24 with ITask

use of com.cubrid.common.core.task.ITask in project cubrid-manager by CUBRID.

the class LoadDatabaseAction method run.

public void run() {
    Object[] obj = this.getSelectedObj();
    if (!isSupported(obj[0])) {
        setEnabled(false);
        return;
    }
    ISchemaNode node = (ISchemaNode) obj[0];
    final CubridDatabase database = node.getDatabase();
    final LoadDatabaseDialog dialog = new LoadDatabaseDialog(getShell());
    dialog.setDatabase(database);
    final Shell shell = getShell();
    TaskExecutor taskExcutor = new TaskExecutor() {

        public boolean exec(final IProgressMonitor monitor) {
            if (monitor.isCanceled()) {
                return false;
            }
            monitor.beginTask(Messages.loadDbUnloadInfoTaskName, IProgressMonitor.UNKNOWN);
            for (ITask task : taskList) {
                task.execute();
                final String msg = task.getErrorMsg();
                if (openErrorBox(shell, msg, monitor)) {
                    return false;
                }
                if (monitor.isCanceled()) {
                    return false;
                }
                if (task instanceof GetDbUnloadInfoTask) {
                    GetDbUnloadInfoTask getDbUnloadInfoTask = (GetDbUnloadInfoTask) task;
                    List<DbUnloadInfo> dbUnloadInfoList = getDbUnloadInfoTask.getDbUnloadInfoList();
                    dialog.setDbUnloadInfoList(dbUnloadInfoList);
                }
            }
            return true;
        }
    };
    ServerInfo serverInfo = database.getServer().getServerInfo();
    GetDbUnloadInfoTask task = new GetDbUnloadInfoTask(serverInfo);
    taskExcutor.addTask(task);
    new ExecTaskWithProgress(taskExcutor).busyCursorWhile();
    if (taskExcutor.isSuccess()) {
        dialog.open();
    }
}
Also used : ITask(com.cubrid.common.core.task.ITask) LoadDatabaseDialog(com.cubrid.cubridmanager.ui.cubrid.database.dialog.LoadDatabaseDialog) ISchemaNode(com.cubrid.common.ui.spi.model.ISchemaNode) ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo) DbUnloadInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DbUnloadInfo) GetDbUnloadInfoTask(com.cubrid.cubridmanager.core.cubrid.database.task.GetDbUnloadInfoTask) Shell(org.eclipse.swt.widgets.Shell) TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase)

Example 25 with ITask

use of com.cubrid.common.core.task.ITask in project cubrid-manager by CUBRID.

the class RenameDatabaseAction method run.

public void run() {
    Object[] obj = this.getSelectedObj();
    if (!isSupported(obj[0])) {
        setEnabled(false);
        return;
    }
    final CubridDatabase database = (CubridDatabase) obj[0];
    ISelectionProvider provider = this.getSelectionProvider();
    final TreeViewer viewer = (TreeViewer) provider;
    String serverName = database.getServer().getName();
    String dbName = database.getName();
    final String jobName = serverName + "-" + dbName + "-" + Messages.msgRenameDBRearJobName;
    final RenameDatabaseDialog dialog = new RenameDatabaseDialog(getShell(), new ITaskExecutorInterceptor() {

        public void completeAll() {
            QueryOptions.removePref(database.getDatabaseInfo());
            CommonUITool.openInformationBox(Messages.titleSuccess, Messages.bind(Messages.msgRenameDBComplete, jobName));
            CommonUITool.refreshNavigatorTree(viewer, database.getParent());
        }

        public IStatus postTaskFinished(ITask task) {
            return Status.OK_STATUS;
        }
    });
    dialog.setDatabase(database);
    final Shell shell = getShell();
    TaskExecutor taskExcutor = new TaskExecutor() {

        @SuppressWarnings("unchecked")
        public boolean exec(final IProgressMonitor monitor) {
            if (monitor.isCanceled()) {
                return false;
            }
            monitor.beginTask(Messages.getDbSpaceInfoTaskName, IProgressMonitor.UNKNOWN);
            for (ITask task : taskList) {
                task.execute();
                final String msg = task.getErrorMsg();
                if (openErrorBox(shell, msg, monitor)) {
                    return false;
                }
                if (monitor.isCanceled()) {
                    return false;
                }
                if (task instanceof CommonQueryTask) {
                    dbSpaceInfo = ((CommonQueryTask<DbSpaceInfoList>) task).getResultModel();
                }
            }
            return true;
        }
    };
    dbSpaceInfo = new DbSpaceInfoList();
    CommonQueryTask<DbSpaceInfoList> task = new CommonQueryTask<DbSpaceInfoList>(database.getServer().getServerInfo(), CommonSendMsg.getCommonDatabaseSendMsg(), dbSpaceInfo);
    task.setDbName(database.getLabel());
    taskExcutor.addTask(task);
    new ExecTaskWithProgress(taskExcutor).busyCursorWhile();
    if (taskExcutor.isSuccess()) {
        dialog.setDbSpaceInfoList(dbSpaceInfo);
        dialog.open();
    }
}
Also used : ITaskExecutorInterceptor(com.cubrid.common.ui.spi.progress.ITaskExecutorInterceptor) ITask(com.cubrid.common.core.task.ITask) IStatus(org.eclipse.core.runtime.IStatus) RenameDatabaseDialog(com.cubrid.cubridmanager.ui.cubrid.database.dialog.RenameDatabaseDialog) TreeViewer(org.eclipse.jface.viewers.TreeViewer) 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) DbSpaceInfoList(com.cubrid.cubridmanager.core.cubrid.dbspace.model.DbSpaceInfoList) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) CommonQueryTask(com.cubrid.cubridmanager.core.common.task.CommonQueryTask) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase)

Aggregations

ITask (com.cubrid.common.core.task.ITask)85 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)49 IStatus (org.eclipse.core.runtime.IStatus)37 ExecTaskWithProgress (com.cubrid.common.ui.spi.progress.ExecTaskWithProgress)35 TaskExecutor (com.cubrid.common.ui.spi.progress.TaskExecutor)35 TaskJobExecutor (com.cubrid.common.ui.spi.progress.TaskJobExecutor)28 ArrayList (java.util.ArrayList)27 Status (org.eclipse.core.runtime.Status)23 DatabaseInfo (com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo)20 CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)17 ServerInfo (com.cubrid.cubridmanager.core.common.model.ServerInfo)15 Map (java.util.Map)15 Display (org.eclipse.swt.widgets.Display)15 JobFamily (com.cubrid.common.ui.spi.progress.JobFamily)14 CommonQueryTask (com.cubrid.cubridmanager.core.common.task.CommonQueryTask)14 List (java.util.List)14 ISchemaNode (com.cubrid.common.ui.spi.model.ISchemaNode)13 ITaskExecutorInterceptor (com.cubrid.common.ui.spi.progress.ITaskExecutorInterceptor)13 CommonTaskJobExec (com.cubrid.common.ui.spi.progress.CommonTaskJobExec)12 MonitoringTask (com.cubrid.cubridmanager.core.common.task.MonitoringTask)11