Search in sources :

Example 26 with TaskJobExecutor

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

the class ManagerLogViewAction method run.

/**
	 * Open the log editor and show log conent
	 */
public void run() {
    final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (window == null) {
        return;
    }
    if (cubridNode == null) {
        Object[] obj = this.getSelectedObj();
        if (!isSupported(obj[0])) {
            setEnabled(false);
            return;
        }
        cubridNode = (ICubridNode) obj[0];
    }
    final GetManagerLogListTask task = new GetManagerLogListTask(cubridNode.getServer().getServerInfo());
    TaskJobExecutor taskJobExecutor = new TaskJobExecutor() {

        public IStatus exec(IProgressMonitor monitor) {
            if (monitor.isCanceled()) {
                cubridNode = null;
                return Status.CANCEL_STATUS;
            }
            for (ITask t : taskList) {
                t.execute();
                final String msg = t.getErrorMsg();
                if (monitor.isCanceled()) {
                    cubridNode = null;
                    return Status.CANCEL_STATUS;
                }
                if (msg != null && msg.length() > 0 && !monitor.isCanceled()) {
                    cubridNode = null;
                    return new Status(IStatus.ERROR, CubridManagerUIPlugin.PLUGIN_ID, msg);
                } else {
                    Display.getDefault().syncExec(new Runnable() {

                        public void run() {
                            ManagerLogInfos managerLogInfos = (ManagerLogInfos) task.getLogContent();
                            IEditorPart editorPart = LayoutUtil.getEditorPart(cubridNode, LogEditorPart.ID);
                            if (editorPart != null) {
                                window.getActivePage().closeEditor(editorPart, false);
                            }
                            try {
                                IEditorPart editor = window.getActivePage().openEditor(cubridNode, LogEditorPart.ID);
                                ((LogEditorPart) editor).setManagerLogInfo(managerLogInfos, true);
                            } catch (PartInitException e) {
                                LOGGER.error(e.getMessage(), e);
                            }
                        }
                    });
                }
                if (monitor.isCanceled()) {
                    cubridNode = null;
                    return Status.CANCEL_STATUS;
                }
            }
            cubridNode = null;
            return Status.OK_STATUS;
        }
    };
    taskJobExecutor.addTask(task);
    String jobName = Messages.viewLogJobName + " - " + cubridNode.getName() + "@" + cubridNode.getServer().getName();
    taskJobExecutor.schedule(jobName, null, false, Job.SHORT);
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) TaskJobExecutor(com.cubrid.common.ui.spi.progress.TaskJobExecutor) ITask(com.cubrid.common.core.task.ITask) ManagerLogInfos(com.cubrid.cubridmanager.core.logs.model.ManagerLogInfos) IEditorPart(org.eclipse.ui.IEditorPart) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) GetManagerLogListTask(com.cubrid.cubridmanager.core.logs.task.GetManagerLogListTask) PartInitException(org.eclipse.ui.PartInitException)

Example 27 with TaskJobExecutor

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

the class CopyDatabaseDialog method okPressed.

/**
	 * When ok button press,call this method
	 */
protected void okPressed() {
    if (!verify()) {
        return;
    }
    destDbName = destinationDBNameText.getText();
    if (!CommonUITool.openConfirmBox(parentComp.getShell(), Messages.warnYesNoCopyDb)) {
        return;
    }
    SocketTask checkTask = getCheckDirsTask();
    SocketTask copyTask = getCopyDbTask();
    TaskJobExecutor taskExec = new CommonTaskJobExec(this);
    taskExec.addTask(checkTask);
    taskExec.addTask(copyTask);
    JobFamily jobFamily = new JobFamily();
    String serverName = database.getServer().getName();
    String dbName = database.getName();
    jobFamily.setServerName(serverName);
    jobFamily.setDbName(dbName);
    jobName = Messages.msgCopyDbRearJobName + " - " + dbName + "@" + serverName;
    taskExec.schedule(jobName, jobFamily, true, Job.SHORT);
}
Also used : TaskJobExecutor(com.cubrid.common.ui.spi.progress.TaskJobExecutor) CommonTaskJobExec(com.cubrid.common.ui.spi.progress.CommonTaskJobExec) SocketTask(com.cubrid.cubridmanager.core.common.socket.SocketTask) JobFamily(com.cubrid.common.ui.spi.progress.JobFamily)

Example 28 with TaskJobExecutor

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

the class UserEditor method loadData.

/**
	 * 
	 * Load data
	 * 
	 * @return <code>true</code> if it is successfully;<code>false</code>
	 *         otherwise
	 */
public boolean loadData() {
    final CommonQueryTask<DbUserInfoList> userTask = new CommonQueryTask<DbUserInfoList>(database.getServer().getServerInfo(), CommonSendMsg.getCommonDatabaseSendMsg(), new DbUserInfoList(), database.getDatabaseInfo().getCharSet());
    userTask.setDbName(database.getName());
    final GetAllClassListTask classInfoTask = new GetAllClassListTask(database.getDatabaseInfo());
    final GetAllPartitionClassTask partitionTask = new GetAllPartitionClassTask(database.getDatabaseInfo());
    TaskJobExecutor taskJobExecutor = new TaskJobExecutor() {

        @SuppressWarnings("unchecked")
        @Override
        public IStatus exec(IProgressMonitor monitor) {
            if (monitor.isCanceled()) {
                return Status.CANCEL_STATUS;
            }
            for (ITask t : taskList) {
                if (t instanceof GetAllClassListTask) {
                    allClassInfoList = ((GetAllClassListTask) t).getAllClassInfoList();
                } else {
                    t.execute();
                }
                if (t instanceof CommonQueryTask) {
                    userListInfo = ((CommonQueryTask<DbUserInfoList>) t).getResultModel();
                }
                if (t instanceof GetAllPartitionClassTask) {
                    partitionClassMap = ((GetAllPartitionClassTask) t).getPartitionClassMap();
                }
                final String msg = t.getErrorMsg();
                if (monitor.isCanceled()) {
                    return Status.CANCEL_STATUS;
                }
                if (msg != null && msg.length() > 0 && !monitor.isCanceled()) {
                    return new Status(IStatus.ERROR, CubridManagerUIPlugin.PLUGIN_ID, msg);
                }
                if (monitor.isCanceled()) {
                    return Status.CANCEL_STATUS;
                }
            }
            Display.getDefault().syncExec(new Runnable() {

                public void run() {
                    initial();
                }
            });
            return Status.OK_STATUS;
        }
    };
    taskJobExecutor.addTask(userTask);
    taskJobExecutor.addTask(classInfoTask);
    taskJobExecutor.addTask(partitionTask);
    String jobName = Messages.viewUserInfoJobName + " - " + userName + "@" + database.getName() + "@" + database.getServer().getName();
    taskJobExecutor.schedule(jobName, null, false, Job.SHORT);
    return true;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) TaskJobExecutor(com.cubrid.common.ui.spi.progress.TaskJobExecutor) GetAllClassListTask(com.cubrid.cubridmanager.core.cubrid.table.task.GetAllClassListTask) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ITask(com.cubrid.common.core.task.ITask) CommonQueryTask(com.cubrid.cubridmanager.core.common.task.CommonQueryTask) DbUserInfoList(com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfoList) GetAllPartitionClassTask(com.cubrid.cubridmanager.core.cubrid.table.task.GetAllPartitionClassTask)

Example 29 with TaskJobExecutor

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

the class ServiceDashboardEditor method loadServerBrokerInfo.

/**
	 * Load Server Broker Info
	 */
private void loadServerBrokerInfo(final ServerInfo serverInfo, final String key) {
    final CommonQueryTask<BrokerInfos> task = new CommonQueryTask<BrokerInfos>(serverInfo, CommonSendMsg.getCommonSimpleSendMsg(), new BrokerInfos());
    TaskJobExecutor taskJobExec = new CommonTaskJobExec(new ITaskExecutorInterceptor() {

        public void completeAll() {
            Object input = serviceTreeViewer.getInput();
            ServiceDashboardInfo sDashInfo = getSelectedDashInfo(input, serverInfo.getServerName(), key);
            BrokerInfos brokerInfos = task.getResultModel();
            setBrokerData(sDashInfo, brokerInfos);
            serviceTreeViewer.refresh(input);
        }

        public IStatus postTaskFinished(ITask task) {
            return Status.OK_STATUS;
        }
    });
    taskJobExec.addTask(task);
    executeTask(taskJobExec, serverInfo.getServerName(), Messages.taskGetServerBrokerInfo);
}
Also used : TaskJobExecutor(com.cubrid.common.ui.spi.progress.TaskJobExecutor) ITaskExecutorInterceptor(com.cubrid.common.ui.spi.progress.ITaskExecutorInterceptor) ITask(com.cubrid.common.core.task.ITask) IStatus(org.eclipse.core.runtime.IStatus) CommonTaskJobExec(com.cubrid.common.ui.spi.progress.CommonTaskJobExec) BrokerInfos(com.cubrid.cubridmanager.core.broker.model.BrokerInfos) CommonQueryTask(com.cubrid.cubridmanager.core.common.task.CommonQueryTask)

Example 30 with TaskJobExecutor

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

the class LoadDatabaseDialog method loadDb.

/**
	 * Execute task and load database
	 * 
	 * @param buttonId the button id
	 */
private void loadDb(final int buttonId) {
    TaskJobExecutor taskExcutor = new LoadDbTaskExecutor(buttonId);
    LoadDbTask loadDbTask1 = new LoadDbTask(database.getServer().getServerInfo());
    LoadDbTask loadDbTask2 = new LoadDbTask(database.getServer().getServerInfo());
    loadDbTask1.setDbName(databaseNameText.getText());
    loadDbTask2.setDbName(databaseNameText.getText());
    loadDbTask1.setDbUser(userNameText.getText());
    loadDbTask2.setDbUser(userNameText.getText());
    if (checkSyntaxButton.getSelection()) {
        loadDbTask1.setCheckOption("both");
        loadDbTask2.setCheckOption("both");
    } else {
        loadDbTask1.setCheckOption("load");
        loadDbTask2.setCheckOption("load");
    }
    if (commitPeriodButton.getSelection()) {
        loadDbTask1.setUsedPeriod(true, commitPeriodText.getText());
        loadDbTask2.setUsedPeriod(true, commitPeriodText.getText());
    } else {
        loadDbTask1.setUsedPeriod(false, "");
        loadDbTask2.setUsedPeriod(false, "");
    }
    if (estimatedSizeButton.getSelection()) {
        loadDbTask1.setUsedEstimatedSize(true, estimatedSizeText.getText());
        loadDbTask2.setUsedEstimatedSize(true, estimatedSizeText.getText());
    } else {
        loadDbTask1.setUsedEstimatedSize(false, "");
        loadDbTask2.setUsedEstimatedSize(false, "");
    }
    if (useErrorControlFileButton.getSelection()) {
        loadDbTask1.setUsedErrorContorlFile(true, errorControlFileText.getText());
        loadDbTask2.setUsedErrorContorlFile(true, errorControlFileText.getText());
    } else {
        loadDbTask1.setUsedErrorContorlFile(false, "");
        loadDbTask2.setUsedErrorContorlFile(false, "");
    }
    if (ignoreClassFileButton.getSelection()) {
        loadDbTask1.setUsedIgnoredClassFile(true, ignoredClassFileText.getText());
        loadDbTask2.setUsedIgnoredClassFile(true, ignoredClassFileText.getText());
    } else {
        loadDbTask1.setUsedIgnoredClassFile(false, "");
        loadDbTask2.setUsedIgnoredClassFile(false, "");
    }
    loadDbTask1.setNoUsedOid(oidButton.getSelection());
    loadDbTask2.setNoUsedOid(oidButton.getSelection());
    if (noStatisButton != null) {
        loadDbTask1.setNoUsedStatistics(noStatisButton.getSelection());
        loadDbTask2.setNoUsedStatistics(noStatisButton.getSelection());
    }
    loadDbTask1.setNoUsedLog(false);
    loadDbTask2.setNoUsedLog(false);
    if (selectLoadFileFromListButton.getSelection()) {
        String schemaPath = "";
        String objectPath = "";
        String indexPath = "";
        String triggerPath = "";
        for (int i = 0, n = unloadInfoTable.getItemCount(); i < n; i++) {
            if (unloadInfoTable.getItem(i).getChecked()) {
                String type = unloadInfoTable.getItem(i).getText(0);
                String path = unloadInfoTable.getItem(i).getText(1);
                if (type != null && type.trim().equals("schema")) {
                    schemaPath = path;
                }
                if (type != null && type.trim().equals("object")) {
                    objectPath = path;
                }
                if (type != null && type.trim().equals("index")) {
                    indexPath = path;
                }
                if (type != null && type.trim().equals("trigger")) {
                    triggerPath = path;
                }
            }
        }
        boolean isAddTask1 = false;
        if (schemaPath != null && schemaPath.trim().length() > 0) {
            loadDbTask1.setSchemaPath(schemaPath);
            isAddTask1 = true;
        } else {
            loadDbTask1.setSchemaPath("none");
        }
        if (objectPath != null && objectPath.trim().length() > 0) {
            loadDbTask1.setObjectPath(objectPath);
            isAddTask1 = true;
        } else {
            loadDbTask1.setObjectPath("none");
        }
        if (indexPath != null && indexPath.trim().length() > 0) {
            loadDbTask1.setIndexPath(indexPath);
            isAddTask1 = true;
        } else {
            loadDbTask1.setIndexPath("none");
        }
        boolean isAddTask2 = false;
        if (triggerPath != null && triggerPath.trim().length() > 0) {
            loadDbTask2.setSchemaPath(triggerPath);
            isAddTask2 = true;
        }
        if (isAddTask1) {
            taskExcutor.addTask(loadDbTask1);
        }
        if (isAddTask2) {
            taskExcutor.addTask(loadDbTask2);
        }
    } else if (selectUnloadFileFromSysButton.getSelection()) {
        boolean isAddTask1 = false;
        if (loadSchemaButton.getSelection()) {
            String schemaPath = loadSchemaText.getText();
            loadDbTask1.setSchemaPath(schemaPath);
            isAddTask1 = true;
        } else {
            loadDbTask1.setSchemaPath("none");
        }
        if (loadObjButton.getSelection()) {
            String objPath = loadObjText.getText();
            loadDbTask1.setObjectPath(objPath);
            isAddTask1 = true;
        } else {
            loadDbTask1.setObjectPath("none");
        }
        if (loadIndexButton.getSelection()) {
            String indexPath = loadIndexText.getText();
            loadDbTask1.setIndexPath(indexPath);
            isAddTask1 = true;
        } else {
            loadDbTask1.setIndexPath("none");
        }
        boolean isAddTask2 = false;
        if (loadTriggerButton.getSelection()) {
            String triggerPath = loadTriggerText.getText();
            loadDbTask2.setSchemaPath(triggerPath);
            isAddTask2 = true;
        }
        if (isAddTask1) {
            taskExcutor.addTask(loadDbTask1);
        }
        if (isAddTask2) {
            taskExcutor.addTask(loadDbTask2);
        }
    }
    JobFamily jobFamily = new JobFamily();
    String serverName = database.getServer().getName();
    String dbName = database.getName();
    jobFamily.setServerName(serverName);
    jobFamily.setDbName(dbName);
    String jobName = Messages.msgLoadDBRearJobName + " - " + dbName + "@" + serverName;
    taskExcutor.schedule(jobName, jobFamily, true, Job.SHORT);
}
Also used : TaskJobExecutor(com.cubrid.common.ui.spi.progress.TaskJobExecutor) LoadDbTask(com.cubrid.cubridmanager.core.cubrid.database.task.LoadDbTask) JobFamily(com.cubrid.common.ui.spi.progress.JobFamily)

Aggregations

TaskJobExecutor (com.cubrid.common.ui.spi.progress.TaskJobExecutor)41 IStatus (org.eclipse.core.runtime.IStatus)29 ITask (com.cubrid.common.core.task.ITask)28 CommonTaskJobExec (com.cubrid.common.ui.spi.progress.CommonTaskJobExec)24 JobFamily (com.cubrid.common.ui.spi.progress.JobFamily)24 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)18 Status (org.eclipse.core.runtime.Status)15 ITaskExecutorInterceptor (com.cubrid.common.ui.spi.progress.ITaskExecutorInterceptor)12 ArrayList (java.util.ArrayList)12 CommonQueryTask (com.cubrid.cubridmanager.core.common.task.CommonQueryTask)11 DbSpaceInfoList (com.cubrid.cubridmanager.core.cubrid.dbspace.model.DbSpaceInfoList)10 List (java.util.List)8 CheckDirTask (com.cubrid.cubridmanager.core.cubrid.database.task.CheckDirTask)6 CheckFileTask (com.cubrid.cubridmanager.core.cubrid.database.task.CheckFileTask)6 IJobChangeEvent (org.eclipse.core.runtime.jobs.IJobChangeEvent)6 BrokerInfoList (com.cubrid.cubridmanager.core.broker.model.BrokerInfoList)4 IEditorPart (org.eclipse.ui.IEditorPart)4 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)4 PartInitException (org.eclipse.ui.PartInitException)4 CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)3