Search in sources :

Example 66 with ITask

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

the class ExportPictureController method exportData.

public boolean exportData(Shell parentShell, boolean isDirectSave) {
    String fileFullName;
    if (!isDirectSave || latestFileFullName == null) {
        FileDialog dialog = new FileDialog(parentShell, SWT.SAVE | SWT.APPLICATION_MODAL);
        dialog.setFilterExtensions(new String[] { "*.jpg", "*.bmp", "*.png", "*.tif" });
        fileFullName = dialog.open();
    } else {
        fileFullName = latestFileFullName;
    }
    if (fileFullName == null) {
        return false;
    }
    if (fileFullName.trim().length() == 0) {
        CommonUITool.openErrorBox(Messages.errFileNameIsEmpty);
        return false;
    }
    TaskExecutor executor = new TaskExecutor() {

        public boolean exec(IProgressMonitor monitor) {
            for (ITask task : taskList) {
                if (task instanceof ExportPictureTask) {
                    ExportPictureTask eTask = (ExportPictureTask) task;
                    monitor.setTaskName(Messages.msgGenerateInfo);
                    monitor.worked(50);
                    eTask.execute();
                    monitor.setTaskName(Messages.msgFinished);
                    monitor.worked(100);
                    monitor.done();
                }
            }
            return true;
        }
    };
    ExportPictureTask task = new ExportPictureTask(erSchemaEditor, fileFullName);
    executor.addTask(task);
    new ExecTaskWithProgress(executor).busyCursorWhile();
    if (executor.isSuccess()) {
        latestFileFullName = fileFullName;
        CommonUITool.openInformationBox(com.cubrid.common.ui.er.Messages.titleExport, Messages.bind(com.cubrid.common.ui.er.Messages.msgExportSuccess, fileFullName));
    }
    return executor.isSuccess();
}
Also used : TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ITask(com.cubrid.common.core.task.ITask) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) FileDialog(org.eclipse.swt.widgets.FileDialog)

Example 67 with ITask

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

the class ExportSQLDataController method exportData.

public boolean exportData(Shell parentShell, boolean isDirectSave) {
    String fileFullName;
    if (!isDirectSave || latestFileFullName == null) {
        FileDialog dialog = new FileDialog(parentShell, SWT.SAVE | SWT.APPLICATION_MODAL);
        dialog.setFilterExtensions(new String[] { "*.sql" });
        fileFullName = dialog.open();
    } else {
        fileFullName = latestFileFullName;
    }
    if (fileFullName == null) {
        return false;
    }
    if (fileFullName.trim().length() == 0) {
        CommonUITool.openErrorBox(Messages.errFileNameIsEmpty);
        return false;
    }
    TaskExecutor executor = new TaskExecutor() {

        public boolean exec(IProgressMonitor monitor) {
            for (ITask task : taskList) {
                if (task instanceof ExportSQLDataTask) {
                    ExportSQLDataTask eTask = (ExportSQLDataTask) task;
                    monitor.setTaskName(Messages.msgGenerateInfo);
                    monitor.worked(50);
                    eTask.execute();
                    monitor.setTaskName(Messages.msgFinished);
                    monitor.worked(100);
                    monitor.done();
                }
            }
            return true;
        }
    };
    ExportSQLDataTask task = new ExportSQLDataTask(erSchemaEditor.getERSchema(), fileFullName, "UTF-8", true);
    executor.addTask(task);
    new ExecTaskWithProgress(executor).busyCursorWhile();
    if (executor.isSuccess()) {
        latestFileFullName = fileFullName;
        CommonUITool.openInformationBox(com.cubrid.common.ui.er.Messages.titleExport, Messages.bind(com.cubrid.common.ui.er.Messages.msgExportSuccess, fileFullName));
    }
    return executor.isSuccess();
}
Also used : TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ITask(com.cubrid.common.core.task.ITask) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) FileDialog(org.eclipse.swt.widgets.FileDialog)

Example 68 with ITask

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

the class RenameDatabaseDialog method renameDb.

/**
	 * Execute task and rename database
	 */
private void renameDb() {
    newDBName = databaseNameText.getText();
    isCanFinished = true;
    TaskJobExecutor taskExec = new TaskJobExecutor() {

        public IStatus exec(final IProgressMonitor monitor) {
            Display.getDefault().syncExec(new Runnable() {

                public void run() {
                    getShell().setVisible(false);
                }
            });
            if (monitor.isCanceled()) {
                cancel();
                Display.getDefault().syncExec(new Runnable() {

                    public void run() {
                        close();
                    }
                });
                return Status.CANCEL_STATUS;
            }
            List<String> cubridConfContentList = null;
            for (ITask task : taskList) {
                if (task instanceof SetCubridConfParameterTask) {
                    if (cubridConfContentList == null) {
                        LOGGER.warn("cubridConfContentList is null. Skip SetCubridConfParameterTask.");
                        continue;
                    }
                    SetCubridConfParameterTask setParaTask = (SetCubridConfParameterTask) task;
                    setParaTask.setConfContents(cubridConfContentList);
                }
                task.execute();
                final String msg = task.getErrorMsg();
                if (msg != null && msg.length() > 0 && !monitor.isCanceled() && !isCanceled()) {
                    Display.getDefault().syncExec(new Runnable() {

                        public void run() {
                            getShell().setVisible(true);
                        }
                    });
                    return new Status(IStatus.ERROR, CubridManagerUIPlugin.PLUGIN_ID, msg);
                }
                if (isCanceled()) {
                    return Status.CANCEL_STATUS;
                }
                if (task instanceof CheckDirTask) {
                    CheckDirTask checkDirTask = (CheckDirTask) task;
                    final String[] dirs = checkDirTask.getNoExistDirectory();
                    if (dirs != null && dirs.length > 0) {
                        Display.getDefault().syncExec(new Runnable() {

                            public void run() {
                                CreateDirDialog dialog = new CreateDirDialog(getShell());
                                dialog.setDirs(dirs);
                                if (dialog.open() != IDialogConstants.OK_ID) {
                                    isCanFinished = false;
                                }
                            }
                        });
                    }
                } else if (task instanceof GetCubridConfParameterTask) {
                    GetCubridConfParameterTask getCubridConfParameterTask = (GetCubridConfParameterTask) task;
                    cubridConfContentList = CoreUtils.renameDatabaseFromServiceServer(getCubridConfParameterTask, cubridConfContentList, database.getName(), newDBName);
                }
                if (!isCanFinished || monitor.isCanceled()) {
                    cancel();
                    Display.getDefault().syncExec(new Runnable() {

                        public void run() {
                            close();
                        }
                    });
                    return Status.CANCEL_STATUS;
                }
            }
            return Status.OK_STATUS;
        }

        public void done(IJobChangeEvent event) {
            if (event.getResult() == Status.OK_STATUS) {
                Display.getDefault().syncExec(new Runnable() {

                    public void run() {
                        iUpdateUIWithJob.completeAll();
                        close();
                    }
                });
            }
        }
    };
    CheckDirTask checkDirTask = new CheckDirTask(database.getServer().getServerInfo());
    RenameDbTask renameDbTask = new RenameDbTask(database.getServer().getServerInfo());
    renameDbTask.setDbName(database.getLabel());
    renameDbTask.setNewDbName(newDBName);
    if (exVolumePathButton.getSelection()) {
        checkDirTask.setDirectory(new String[] { exVolumePathText.getText() });
        renameDbTask.setExVolumePath(exVolumePathText.getText());
        renameDbTask.setAdvanced(false);
    } else if (renameVolumeButton.getSelection()) {
        List<String> pathList = new ArrayList<String>();
        List<String> volumeChangedList = new ArrayList<String>();
        for (int i = 0; spaceInfoList != null && i < spaceInfoList.size(); i++) {
            Map<String, String> map = spaceInfoList.get(i);
            String oldName = map.get("0");
            String newName = map.get("1");
            String oldPath = map.get("2");
            String newPath = map.get("3");
            addVolumePath(pathList, newPath);
            oldPath = oldPath.replaceAll(":", "|");
            newPath = newPath.replaceAll(":", "|");
            volumeChangedList.add(oldPath + "/" + oldName + ":" + newPath + "/" + newName);
        }
        String[] checkedDirs = new String[pathList.size()];
        pathList.toArray(checkedDirs);
        checkDirTask.setDirectory(checkedDirs);
        renameDbTask.setAdvanced(true);
        renameDbTask.setIndividualVolume(volumeChangedList);
    }
    if (forceDelBackupVolumeButton.getSelection()) {
        renameDbTask.setForceDel(true);
    } else {
        renameDbTask.setForceDel(false);
    }
    taskExec.addTask(renameDbTask);
    GetCubridConfParameterTask getCubridConfParameterTask = new GetCubridConfParameterTask(database.getServer().getServerInfo());
    taskExec.addTask(getCubridConfParameterTask);
    SetCubridConfParameterTask setCubridConfParameterTask = new SetCubridConfParameterTask(database.getServer().getServerInfo());
    taskExec.addTask(setCubridConfParameterTask);
    JobFamily jobFamily = new JobFamily();
    String serverName = database.getServer().getName();
    String dbName = database.getName();
    jobFamily.setServerName(serverName);
    jobFamily.setDbName(dbName);
    String jobName = Messages.msgRenameDBRearJobName + " - " + dbName + "@" + serverName;
    taskExec.schedule(jobName, jobFamily, true, Job.SHORT);
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) TaskJobExecutor(com.cubrid.common.ui.spi.progress.TaskJobExecutor) ITask(com.cubrid.common.core.task.ITask) SetCubridConfParameterTask(com.cubrid.cubridmanager.core.common.task.SetCubridConfParameterTask) RenameDbTask(com.cubrid.cubridmanager.core.cubrid.database.task.RenameDbTask) GetCubridConfParameterTask(com.cubrid.cubridmanager.core.common.task.GetCubridConfParameterTask) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) JobFamily(com.cubrid.common.ui.spi.progress.JobFamily) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) List(java.util.List) ArrayList(java.util.ArrayList) DbSpaceInfoList(com.cubrid.cubridmanager.core.cubrid.dbspace.model.DbSpaceInfoList) CheckDirTask(com.cubrid.cubridmanager.core.cubrid.database.task.CheckDirTask) Map(java.util.Map) HashMap(java.util.HashMap)

Example 69 with ITask

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

the class DeleteDatabaseDialog method deleteDatabase.

/**
	 * 
	 * Delete the database
	 * 
	 * @return <code>true</code> if successful;<code>false</code> otherwise
	 */
private boolean deleteDatabase() {
    TaskExecutor taskExcutor = new TaskExecutor() {

        public boolean exec(final IProgressMonitor monitor) {
            if (monitor.isCanceled()) {
                return false;
            }
            String taskName = Messages.bind(Messages.delDbTaskName, database.getName());
            monitor.beginTask(taskName, IProgressMonitor.UNKNOWN);
            boolean isActiveReplServer = false;
            boolean isActiveReplAgent = false;
            List<String> cubridConfContentList = null;
            for (ITask task : taskList) {
                if (task instanceof GetReplServerStatusTask) {
                    GetReplServerStatusTask getReplServerStatusTask = (GetReplServerStatusTask) task;
                    getReplServerStatusTask.execute();
                    isActiveReplServer = getReplServerStatusTask.isActive();
                } else if (task instanceof StopReplServerTask) {
                    if (isActiveReplServer) {
                        task.execute();
                    }
                } else if (task instanceof GetReplAgentStatusTask) {
                    GetReplAgentStatusTask getReplAgentStatusTask = (GetReplAgentStatusTask) task;
                    getReplAgentStatusTask.execute();
                    isActiveReplAgent = getReplAgentStatusTask.isActive();
                } else if (task instanceof StopReplicationAgentTask) {
                    if (isActiveReplAgent) {
                        task.execute();
                    }
                } else if (task instanceof SetCubridConfParameterTask) {
                    if (cubridConfContentList == null) {
                        continue;
                    } else {
                        SetCubridConfParameterTask setParaTask = (SetCubridConfParameterTask) task;
                        setParaTask.setConfContents(cubridConfContentList);
                        setParaTask.execute();
                    }
                } else {
                    task.execute();
                }
                final String msg = task.getErrorMsg();
                if (openErrorBox(getShell(), msg, monitor)) {
                    return false;
                }
                if (monitor.isCanceled()) {
                    return false;
                }
                if (task instanceof GetCubridConfParameterTask) {
                    GetCubridConfParameterTask getCubridConfParameterTask = (GetCubridConfParameterTask) task;
                    cubridConfContentList = CoreUtils.deleteDatabaseFromServiceServer(getCubridConfParameterTask, cubridConfContentList, database.getName());
                }
            }
            return true;
        }
    };
    ServerInfo serverInfo = database.getServer().getServerInfo();
    //check the replication server and agent
    if (serverInfo.isSupportReplication() == 0) {
        if (database.isDistributorDb()) {
            GetReplAgentStatusTask getReplAgentStatusTask = new GetReplAgentStatusTask(serverInfo);
            getReplAgentStatusTask.setDbName(database.getLabel());
            taskExcutor.addTask(getReplAgentStatusTask);
            StopReplicationAgentTask stopReplAgentTask = new StopReplicationAgentTask(serverInfo);
            stopReplAgentTask.setDbName(database.getLabel());
            taskExcutor.addTask(stopReplAgentTask);
        } else {
            GetReplServerStatusTask getReplServerStatusTask = new GetReplServerStatusTask(serverInfo);
            getReplServerStatusTask.setDbName(database.getLabel());
            taskExcutor.addTask(getReplServerStatusTask);
            StopReplServerTask stopReplServerTask = new StopReplServerTask(serverInfo);
            stopReplServerTask.setDbName(database.getLabel());
            taskExcutor.addTask(stopReplServerTask);
        }
    }
    CommonUpdateTask deleteDbtask = new CommonUpdateTask(CommonTaskName.DELETE_DATABASE_TASK_NAME, serverInfo, CommonSendMsg.getDeletedbSendMsg());
    deleteDbtask.setDbName(database.getName());
    if (deleteBackupVolumesButton.getSelection()) {
        deleteDbtask.setDelbackup(YesNoType.Y);
    } else {
        deleteDbtask.setDelbackup(YesNoType.N);
    }
    taskExcutor.addTask(deleteDbtask);
    GetCubridConfParameterTask getCubridConfParameterTask = new GetCubridConfParameterTask(serverInfo);
    taskExcutor.addTask(getCubridConfParameterTask);
    SetCubridConfParameterTask setCubridConfParameterTask = new SetCubridConfParameterTask(serverInfo);
    taskExcutor.addTask(setCubridConfParameterTask);
    new ExecTaskWithProgress(taskExcutor).exec(true, false);
    if (taskExcutor.isSuccess()) {
        setReturnCode(DELETE_ID);
        close();
        return true;
    } else {
        return false;
    }
}
Also used : ITask(com.cubrid.common.core.task.ITask) GetReplAgentStatusTask(com.cubrid.cubridmanager.core.replication.task.GetReplAgentStatusTask) ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo) StopReplicationAgentTask(com.cubrid.cubridmanager.core.replication.task.StopReplicationAgentTask) SetCubridConfParameterTask(com.cubrid.cubridmanager.core.common.task.SetCubridConfParameterTask) GetCubridConfParameterTask(com.cubrid.cubridmanager.core.common.task.GetCubridConfParameterTask) TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) GetReplServerStatusTask(com.cubrid.cubridmanager.core.replication.task.GetReplServerStatusTask) StopReplServerTask(com.cubrid.cubridmanager.core.replication.task.StopReplServerTask) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) CommonUpdateTask(com.cubrid.cubridmanager.core.common.task.CommonUpdateTask)

Example 70 with ITask

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

the class StopDatabaseAction method run.

public void run() {
    Object[] objArr = this.getSelectedObj();
    if (objArr == null || objArr.length <= 0) {
        setEnabled(false);
        return;
    }
    Set<CubridDatabase> databaseSet = new HashSet<CubridDatabase>();
    for (int i = 0; objArr != null && i < objArr.length; i++) {
        if (!isSupported(objArr[i])) {
            setEnabled(false);
            return;
        }
        ISchemaNode schemaNode = (ISchemaNode) objArr[i];
        CubridDatabase database = schemaNode.getDatabase();
        databaseSet.add(database);
    }
    StringBuffer dbNames = new StringBuffer();
    Iterator<CubridDatabase> it = databaseSet.iterator();
    while (it.hasNext()) {
        CubridDatabase database = it.next();
        dbNames.append(database.getLabel()).append(",");
    }
    dbNames = new StringBuffer(dbNames.substring(0, dbNames.length() - 1));
    boolean isStop = CommonUITool.openConfirmBox(getShell(), Messages.bind(Messages.msgConfirmStopDatabase, dbNames.toString()));
    if (!isStop) {
        return;
    }
    Iterator<CubridDatabase> iter = databaseSet.iterator();
    while (iter.hasNext()) {
        CubridDatabase database = iter.next();
        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.msgStopDbWithJob, dbName));
            databaseSet.remove(database);
            continue;
        }
    }
    final Object[] dbObjectArr = new Object[databaseSet.size()];
    databaseSet.toArray(dbObjectArr);
    ISelectionProvider provider = getSelectionProvider();
    final Shell shell = getShell();
    if (provider instanceof TreeViewer && dbObjectArr.length > 0) {
        final TreeViewer viewer = (TreeViewer) provider;
        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++) {
                    ISchemaNode node = (ISchemaNode) dbObjectArr[i];
                    final CubridDatabase database = node.getDatabase();
                    if (!isSupported(database)) {
                        continue;
                    }
                    monitor.subTask(Messages.bind(Messages.stopDbTaskName, database.getName()));
                    ITask task = taskList.get(i);
                    task.execute();
                    final String msg = task.getErrorMsg();
                    if (openErrorBox(shell, msg, monitor)) {
                        return false;
                    }
                    if (monitor.isCanceled()) {
                        return false;
                    }
                    database.removeAllChild();
                    if (database.getLoader() != null) {
                        database.getLoader().setLoaded(false);
                    }
                    database.setRunningType(DbRunningType.STANDALONE);
                    display.syncExec(new Runnable() {

                        public void run() {
                            viewer.refresh(database, true);
                        }
                    });
                    if (monitor.isCanceled()) {
                        return false;
                    }
                }
                return true;
            }
        };
        boolean isContinue = true;
        for (int i = 0; i < dbObjectArr.length; i++) {
            ISchemaNode node = (ISchemaNode) dbObjectArr[i];
            CubridDatabase database = node.getDatabase();
            if (!isSupported(database)) {
                setEnabled(false);
                return;
            }
            if (!LayoutUtil.checkAllQueryEditor(database)) {
                isContinue = false;
                break;
            }
            CommonUpdateTask task = new CommonUpdateTask(CommonTaskName.STOP_DB_TASK_NAME, database.getServer().getServerInfo(), CommonSendMsg.getCommonDatabaseSendMsg());
            task.setDbName(database.getLabel());
            taskExcutor.addTask(task);
        }
        if (!isContinue) {
            return;
        }
        new ExecTaskWithProgress(taskExcutor).busyCursorWhile();
        ActionManager.getInstance().fireSelectionChanged(getSelection());
        for (int i = 0; i < dbObjectArr.length; i++) {
            CubridDatabase database = (CubridDatabase) dbObjectArr[i];
            CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent(database, CubridNodeChangedEventType.DATABASE_STOP));
        }
    }
}
Also used : ITask(com.cubrid.common.core.task.ITask) TreeViewer(org.eclipse.jface.viewers.TreeViewer) CubridNodeChangedEvent(com.cubrid.common.ui.spi.event.CubridNodeChangedEvent) Shell(org.eclipse.swt.widgets.Shell) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) CommonUpdateTask(com.cubrid.cubridmanager.core.common.task.CommonUpdateTask) Job(org.eclipse.core.runtime.jobs.Job) HashSet(java.util.HashSet) ISchemaNode(com.cubrid.common.ui.spi.model.ISchemaNode) JobFamily(com.cubrid.common.ui.spi.progress.JobFamily) TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) Display(org.eclipse.swt.widgets.Display)

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