Search in sources :

Example 36 with TaskJobExecutor

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

the class UnloadDatabaseDialog method unloadDatabase.

/**
	 * 
	 * Execute task and unload database
	 * 
	 * @param buttonId the button id
	 */
private void unloadDatabase(final int buttonId) {
    isCanFinished = true;
    TaskJobExecutor taskExcutor = new TaskJobExecutor() {

        private List<String> unloadResultList = null;

        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() {
                        setReturnCode(buttonId);
                        close();
                    }
                });
                isCanFinished = true;
                return Status.CANCEL_STATUS;
            }
            for (ITask task : taskList) {
                task.execute();
                final String msg = task.getErrorMsg();
                if (monitor.isCanceled()) {
                    cancel();
                    Display.getDefault().syncExec(new Runnable() {

                        public void run() {
                            setReturnCode(buttonId);
                            close();
                        }
                    });
                    isCanFinished = true;
                    return Status.CANCEL_STATUS;
                }
                if (msg != null && msg.length() > 0 && !monitor.isCanceled() && !isCanceled()) {
                    Display.getDefault().syncExec(new Runnable() {

                        public void run() {
                            getShell().setVisible(true);
                        }
                    });
                    isCanFinished = false;
                    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;
                                    getShell().setVisible(true);
                                }
                            }
                        });
                    }
                } else if (task instanceof CheckFileTask) {
                    CheckFileTask checkFileTask = (CheckFileTask) task;
                    final String[] files = checkFileTask.getExistFiles();
                    if (files != null && files.length > 0) {
                        Display.getDefault().syncExec(new Runnable() {

                            public void run() {
                                OverrideFileDialog dialog = new OverrideFileDialog(getShell());
                                dialog.setFiles(files);
                                if (dialog.open() != IDialogConstants.OK_ID) {
                                    isCanFinished = false;
                                    getShell().setVisible(true);
                                }
                            }
                        });
                    }
                } else if (task instanceof UnloadDatabaseTask) {
                    UnloadDatabaseTask unloadDatabaseTask = (UnloadDatabaseTask) task;
                    if (!isSchemaOnly) {
                        unloadResultList = unloadDatabaseTask.getUnloadDbResult();
                    }
                }
                if (!isCanFinished) {
                    return Status.CANCEL_STATUS;
                }
                if (monitor.isCanceled()) {
                    Display.getDefault().syncExec(new Runnable() {

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

        /**
			 * Notification that a job has completed execution,
			 * 
			 * @param event the event details
			 */
        public void done(IJobChangeEvent event) {
            if (event.getResult() == Status.OK_STATUS) {
                if (isSchemaOnly) {
                    Display.getDefault().syncExec(new Runnable() {

                        public void run() {
                            CommonUITool.openInformationBox(getShell(), Messages.titleSuccess, Messages.msgSuccessUnload);
                            setReturnCode(buttonId);
                            close();
                        }
                    });
                } else {
                    Display.getDefault().syncExec(new Runnable() {

                        public void run() {
                            UnloadDatabaseResultDialog dialog = new UnloadDatabaseResultDialog(getShell());
                            dialog.setUnloadResulList(unloadResultList);
                            dialog.open();
                            setReturnCode(buttonId);
                            close();
                        }
                    });
                }
            }
        }
    };
    CheckDirTask checkDirTask = new CheckDirTask(database.getServer().getServerInfo());
    CheckFileTask checkFileTask = new CheckFileTask(database.getServer().getServerInfo());
    final UnloadDatabaseTask unloadDatabaseTask = new UnloadDatabaseTask(database.getServer().getServerInfo(), database.getDatabaseInfo().getCharSet());
    fillTask(taskExcutor, checkDirTask, checkFileTask, unloadDatabaseTask);
    String serverName = database.getServer().getName();
    String dbName = database.getName();
    String jobName = Messages.msgUnloadDbRearJobName + " - " + dbName + "@" + serverName;
    JobFamily jobFamily = new JobFamily();
    jobFamily.setServerName(serverName);
    jobFamily.setDbName(dbName);
    taskExcutor.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) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) JobFamily(com.cubrid.common.ui.spi.progress.JobFamily) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ArrayList(java.util.ArrayList) List(java.util.List) CheckDirTask(com.cubrid.cubridmanager.core.cubrid.database.task.CheckDirTask) CheckFileTask(com.cubrid.cubridmanager.core.cubrid.database.task.CheckFileTask) UnloadDatabaseTask(com.cubrid.cubridmanager.core.cubrid.database.task.UnloadDatabaseTask)

Example 37 with TaskJobExecutor

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

the class OptimizeDialog method exec.

/**
	 *
	 * Execute to optimize the table
	 *
	 * @param buttonId the button id
	 * @param task the task
	 * @param cancelable whether it is cancelable
	 * @param shell the shell
	 */
public void exec(final int buttonId, final SocketTask task, boolean cancelable, Shell shell) {
    TaskJobExecutor taskJobExecutor = new TaskJobExecutor() {

        @Override
        public IStatus exec(IProgressMonitor monitor) {
            if (monitor.isCanceled()) {
                return Status.CANCEL_STATUS;
            }
            for (final ITask t : taskList) {
                t.execute();
                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);
                } else {
                    Display.getDefault().syncExec(new Runnable() {

                        public void run() {
                            TableItem item = new TableItem(volumeTable, SWT.NONE);
                            if (t.getErrorMsg() == null) {
                                item.setText(Messages.bind(Messages.errOptimizeSuccess, className.getText()));
                            } else {
                                CommonUITool.openInformationBox(getShell(), Messages.titleFailure, Messages.bind(Messages.errOptimizeFail, className.getText(), task.getErrorMsg()));
                                item.setText(Messages.errOptimizeFail + className.getText() + "-" + task.getErrorMsg());
                            }
                            volumeTable.getColumn(0).pack();
                        }
                    });
                }
                if (monitor.isCanceled()) {
                    return Status.CANCEL_STATUS;
                }
            }
            return Status.OK_STATUS;
        }
    };
    taskJobExecutor.addTask(task);
    String serverName = database.getServer().getName();
    String dbName = database.getName();
    String jobName = Messages.titleOptimizeDbDialog + " - " + dbName + "@" + serverName;
    taskJobExecutor.schedule(jobName, null, false, Job.SHORT);
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) TaskJobExecutor(com.cubrid.common.ui.spi.progress.TaskJobExecutor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ITask(com.cubrid.common.core.task.ITask) TableItem(org.eclipse.swt.widgets.TableItem)

Example 38 with TaskJobExecutor

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

the class ParamDumpDialog method buttonPressed.

/**
	 * When press button in button bar,call this method
	 * 
	 * @param buttonId the button id
	 */
protected void buttonPressed(int buttonId) {
    if (buttonId == IDialogConstants.OK_ID) {
        if (!verify()) {
            return;
        }
        task = new ParamDumpTask(database.getServer().getServerInfo());
        task.setDbName(database.getName());
        task.setBoth(repairButton.getSelection() ? YesNoType.Y : YesNoType.N);
        String serverName = database.getServer().getName();
        String dbName = database.getName();
        jobName = Messages.titleParamDumpDialog + " - " + dbName + "@" + serverName;
        TaskJobExecutor taskExec = new CommonTaskJobExec(this);
        taskExec.addTask(task);
        JobFamily jobFamily = new JobFamily();
        jobFamily.setServerName(serverName);
        jobFamily.setDbName(dbName);
        taskExec.schedule(jobName, jobFamily, true, Job.SHORT);
        return;
    }
    super.buttonPressed(buttonId);
}
Also used : TaskJobExecutor(com.cubrid.common.ui.spi.progress.TaskJobExecutor) CommonTaskJobExec(com.cubrid.common.ui.spi.progress.CommonTaskJobExec) JobFamily(com.cubrid.common.ui.spi.progress.JobFamily) ParamDumpTask(com.cubrid.cubridmanager.core.cubrid.database.task.ParamDumpTask)

Example 39 with TaskJobExecutor

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

the class ViewReplicationErrorLogAction method run.

/**
	 * view replication error log
	 */
public void run() {
    final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (window == null) {
        return;
    }
    Object[] obj = this.getSelectedObj();
    if (!isSupported(obj[0])) {
        setEnabled(false);
        return;
    }
    final ISchemaNode schemaNode = (ISchemaNode) obj[0];
    cubridNode = schemaNode;
    ReplicationInfo replInfo = (ReplicationInfo) schemaNode.getAdapter(ReplicationInfo.class);
    final GetLogListTask task = new GetLogListTask(schemaNode.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() {
                            LogContentInfo logContentInfo = (LogContentInfo) 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).setTableInfo(logContentInfo, true);
                            } catch (PartInitException e) {
                                LOGGER.error(e.getMessage(), e);
                            }
                        }
                    });
                }
                if (monitor.isCanceled()) {
                    cubridNode = null;
                    return Status.CANCEL_STATUS;
                }
            }
            cubridNode = null;
            return Status.OK_STATUS;
        }
    };
    String errPath = replInfo.getDistInfo().getCopyLogPath().substring(0, replInfo.getDistInfo().getCopyLogPath().indexOf(replInfo.getDistInfo().getDistDbName())) + replInfo.getDistInfo().getDistDbName() + schemaNode.getServer().getServerInfo().getPathSeparator() + replInfo.getDistInfo().getDistDbName() + ".err";
    task.setPath(errPath);
    task.setStart("1");
    task.setEnd("100");
    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) ISchemaNode(com.cubrid.common.ui.spi.model.ISchemaNode) IEditorPart(org.eclipse.ui.IEditorPart) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) LogContentInfo(com.cubrid.cubridmanager.core.logs.model.LogContentInfo) GetLogListTask(com.cubrid.cubridmanager.core.logs.task.GetLogListTask) ReplicationInfo(com.cubrid.cubridmanager.core.replication.model.ReplicationInfo) PartInitException(org.eclipse.ui.PartInitException)

Example 40 with TaskJobExecutor

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

the class ChangeReplTablesWizard method performFinish.

/**
	 * Called when user clicks Finish
	 *
	 * @return boolean
	 */
public boolean performFinish() {
    String mdbName = setDatabaseInfoPage.getMasterDbName();
    String distdbName = setDatabaseInfoPage.getDistributorDbName();
    String distdbPassword = setDatabaseInfoPage.getDistdbPassword();
    boolean isReplAllTables = changeTablesPage.isReplAllTables();
    List<String> replTableList = changeTablesPage.getReplTableList();
    TaskJobExecutor taskExcutor = new TaskJobExecutor() {

        public void closeUI() {
            Display.getDefault().syncExec(new Runnable() {

                public void run() {
                    dialog.close();
                }
            });
        }

        public void setVisible(final boolean isVisible) {
            Display display = Display.getDefault();
            display.syncExec(new Runnable() {

                public void run() {
                    dialog.getShell().setVisible(isVisible);
                }
            });
        }

        public IStatus exec(final IProgressMonitor monitor) {
            setVisible(false);
            for (ITask task : taskList) {
                task.execute();
                if (monitor.isCanceled()) {
                    closeUI();
                    return Status.CANCEL_STATUS;
                }
                final String msg = task.getErrorMsg();
                if (msg != null && msg.length() > 0 && !monitor.isCanceled()) {
                    return new Status(IStatus.ERROR, CubridManagerUIPlugin.PLUGIN_ID, msg);
                }
            }
            closeUI();
            return Status.OK_STATUS;
        }
    };
    ServerInfo serverInfo = replicationNode.getServer().getServerInfo();
    ChangeReplTablesTask task = new ChangeReplTablesTask(serverInfo);
    task.setMdbName(mdbName);
    task.setDistdbName(distdbName);
    task.setDistdbPassword(distdbPassword);
    task.setReplAllClasses(isReplAllTables);
    task.setReplicatedClasses(replTableList);
    taskExcutor.addTask(task);
    JobFamily jobFamily = new JobFamily();
    String serverName = replicationNode.getServer().getName();
    jobFamily.setServerName(serverName);
    jobFamily.setDbName(distdbName);
    String jobName = Messages.bind(Messages.changeReplicationSchemaJobName, new String[] { distdbName, serverName });
    taskExcutor.schedule(jobName, jobFamily, true, Job.SHORT);
    return false;
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) ChangeReplTablesTask(com.cubrid.cubridmanager.core.replication.task.ChangeReplTablesTask) TaskJobExecutor(com.cubrid.common.ui.spi.progress.TaskJobExecutor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ITask(com.cubrid.common.core.task.ITask) ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo) JobFamily(com.cubrid.common.ui.spi.progress.JobFamily) Display(org.eclipse.swt.widgets.Display)

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