Search in sources :

Example 91 with Job

use of org.eclipse.core.runtime.jobs.Job in project translationstudio8 by heartsome.

the class ExportTmxDialog method okPressed.

@Override
protected void okPressed() {
    String encoding = "UTF-8";
    if (hasChangedCodingCbtn.getSelection()) {
        encoding = this.encodingComboViewer.getCombo().getText();
    }
    String exportPath = this.tmxFileText.getText();
    boolean isTopLevelTmx = this.isTopLevelTmxCbtn.getSelection();
    boolean isTagLevelTmx = this.isTagCbtn.getSelection();
    ExportFilterBean filterBean = null;
    if (this.hasfilterCbtn.getSelection()) {
        IStructuredSelection sel = (IStructuredSelection) filterComboViewer.getSelection();
        filterBean = (ExportFilterBean) sel.getFirstElement();
        if (filterBean.equals(filterList.get(0))) {
            filterBean = null;
        }
    }
    if (this.dbList.size() == 0) {
        MessageDialog.openInformation(getShell(), Messages.getString("dialog.ExportTmxDialog.msgTitle"), Messages.getString("dialog.ExportTmxDialog.msg3"));
        return;
    }
    for (Iterator<ExportDatabaseBean> iterator = dbList.iterator(); iterator.hasNext(); ) {
        ExportDatabaseBean dbBean = iterator.next();
        String dbType = dbBean.getDbBean().getDbType();
        String name = dbBean.getDbBean().getDatabaseName();
        if (dbBean.getHasSelectedLangs().size() < 2) {
            MessageDialog.openInformation(getShell(), Messages.getString("dialog.ExportTmxDialog.msgTitle"), MessageFormat.format(Messages.getString("dialog.ExportTmxDialog.msg4"), dbType, name));
            return;
        }
        if (dbBean.getSrcLang().equals("")) {
            MessageDialog.openInformation(getShell(), Messages.getString("dialog.ExportTmxDialog.msgTitle"), MessageFormat.format(Messages.getString("dialog.ExportTmxDialog.msg5"), dbType, name));
            return;
        }
    }
    if (exportPath == null || exportPath.equals("")) {
        MessageDialog.openInformation(getShell(), Messages.getString("dialog.ExportTmxDialog.msgTitle"), Messages.getString("dialog.ExportTmxDialog.msg6"));
        return;
    }
    if (this.dbList.size() > 1) {
        File f = new File(exportPath);
        if (!f.isDirectory()) {
            MessageDialog.openInformation(getShell(), Messages.getString("dialog.ExportTmxDialog.msgTitle"), Messages.getString("dialog.ExportTmxDialog.msg8"));
            return;
        }
    }
    if (this.dbList.size() == 1) {
        File f = new File(exportPath);
        if (f.isDirectory()) {
            MessageDialog.openInformation(getShell(), Messages.getString("dialog.ExportTmxDialog.msgTitle"), Messages.getString("dialog.ExportTmxDialog.msg9"));
            return;
        }
    }
    if (this.dbList.size() == 1) {
        dbList.get(0).setExportFilePath(exportPath);
        File file = new File(exportPath);
        if (file.exists()) {
            if (!MessageDialog.openConfirm(getShell(), Messages.getString("dialog.ExportTmxDialog.msgTitle"), MessageFormat.format(Messages.getString("dialog.ExportTmxDialog.msg7"), exportPath))) {
                return;
            }
        }
    } else {
        for (Iterator<ExportDatabaseBean> iterator = dbList.iterator(); iterator.hasNext(); ) {
            ExportDatabaseBean db = iterator.next();
            String databaseName = db.getDbBean().getDatabaseName();
            String path = exportPath + System.getProperty("file.separator") + databaseName + db.getDbBean().getDbType() + ".tmx";
            File file = new File(path);
            if (file.exists()) {
                if (!MessageDialog.openConfirm(getShell(), Messages.getString("dialog.ExportTmxDialog.msgTitle"), MessageFormat.format(Messages.getString("dialog.ExportTmxDialog.msg7"), path))) {
                    return;
                }
            }
            db.setExportFilePath(path);
        }
    }
    final ExportAbstract tmxExport = new ExportTmxImpl(this.dbList, filterBean, encoding, isTopLevelTmx, isTagLevelTmx);
    Job job = new Job(Messages.getString("dialog.ExportTmxDialog.job")) {

        @Override
        protected IStatus run(IProgressMonitor monitor) {
            final String result = DatabaseService.executeExport(tmxExport, monitor);
            Display.getDefault().syncExec(new Runnable() {

                public void run() {
                    MessageDialog.openInformation(getShell(), Messages.getString("dialog.ExportTmxDialog.msgTitle"), result);
                }
            });
            return Status.OK_STATUS;
        }
    };
    // 当程序退出时,检测当前 job 是否正常关闭
    CommonFunction.jobCantCancelTip(job);
    job.addJobChangeListener(new JobChangeAdapter() {

        @Override
        public void running(IJobChangeEvent event) {
            ProgressIndicatorManager.displayProgressIndicator();
            super.running(event);
        }

        @Override
        public void done(IJobChangeEvent event) {
            ProgressIndicatorManager.hideProgressIndicator();
            super.done(event);
        }
    });
    job.setUser(true);
    job.schedule();
    super.okPressed();
}
Also used : JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) ExportFilterBean(net.heartsome.cat.database.bean.ExportFilterBean) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) ExportTmxImpl(net.heartsome.cat.document.ExportTmxImpl) ExportDatabaseBean(net.heartsome.cat.database.bean.ExportDatabaseBean) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ExportAbstract(net.heartsome.cat.document.ExportAbstract) Job(org.eclipse.core.runtime.jobs.Job) File(java.io.File)

Example 92 with Job

use of org.eclipse.core.runtime.jobs.Job in project translationstudio8 by heartsome.

the class ExportDocxDialog method okPressed.

@Override
protected void okPressed() {
    if (xliffPathTxt.getText() == null || xliffPathTxt.getText().trim().equals("")) {
        MessageDialog.openInformation(getShell(), Messages.getString("all.dialog.ok.title"), Messages.getString("ExportDocxDialog.ok.msg0"));
        return;
    }
    String docxPath = docxPathTxt.getText().trim();
    if (docxPath == null || docxPath.length() <= 0) {
        MessageDialog.openInformation(getShell(), Messages.getString("all.dialog.ok.title"), Messages.getString("ExportDocxDialog.ok.msg3"));
        return;
    }
    IDialogSettings dialogSettings = Activator.getDefault().getDialogSettings();
    dialogSettings.put(STORE_DOCX_PATH, docxPath);
    XLFValidator.resetFlag();
    if (!XLFValidator.validateXliffFile(strXliffFullPath)) {
        return;
    }
    XLFValidator.resetFlag();
    // 补全 docx 路径
    docxPath = docxPath + File.separator + new File(strXliffFullPath).getName() + ".docx";
    if (new File(docxPath).exists()) {
        boolean confirm = MessageDialog.openConfirm(getShell(), Messages.getString("all.dialog.confirm"), MessageFormat.format(Messages.getString("ExportDocxDialog.ok.msg5"), "DOCX", docxPath));
        if (confirm) {
            new File(docxPath).delete();
        } else {
            return;
        }
    }
    final boolean commentSelection = commentBtn.getSelection();
    final boolean statusSelection = statusBtn.getSelection();
    // 设置查询每个 tu 的条件,比如排除或者 仅导出
    String expandXpath = "";
    if (excludeBtn.getSelection()) {
        if (excludeLockedBtn.getSelection()) {
            expandXpath += " and not(@translate='no')";
        }
        if (exclude101Btn.getSelection()) {
            expandXpath += " and not(target[@hs:quality='101'])";
        }
        if (exclude100Btn.getSelection()) {
            expandXpath += " and not(target[@hs:quality='100'])";
        }
    } else if (onlyExportBtn.getSelection()) {
        if (onlyExportNoteBtn.getSelection()) {
            expandXpath += " and note/text()!=''";
        } else if (onlyExportReviewBtn.getSelection()) {
            expandXpath += " and @hs:needs-review='yes'";
        }
    }
    final String finalExpandXpath = expandXpath;
    // 这里开始调用导出的方法
    final String finalDocxPath = docxPath;
    Job job = new Job(Messages.getString("ExportDocxDialog.ok.monitor.title")) {

        protected IStatus run(final IProgressMonitor monitor) {
            try {
                // 解析文件花一格。读取 xliff 数据花 1 格,导出花 18 格。
                monitor.beginTask(Messages.getString("ExportDocxDialog.ok.monitor.msg0"), 20);
                beginExport(monitor, finalDocxPath, commentSelection, statusSelection, finalExpandXpath);
                Display.getDefault().syncExec(new Runnable() {

                    @Override
                    public void run() {
                        MessageDialog.openInformation(getShell(), Messages.getString("all.dialog.ok.title"), Messages.getString("ExportDocxDialog.ok.msg4"));
                    }
                });
                monitor.done();
            } catch (OperationCanceledException e) {
            // do nothing
            } catch (final Exception e) {
                Display.getDefault().syncExec(new Runnable() {

                    @Override
                    public void run() {
                        MessageDialog.openError(getShell(), Messages.getString("all.dialog.error"), Messages.getString("ExportDocxDialog.ok.exportError") + "\n" + e.getMessage());
                    }
                });
                LOGGER.error("Export xliff to MS WORD error\n" + e.getMessage(), e);
            }
            return Status.OK_STATUS;
        }
    };
    // 当程序退出时,检测当前 job 是否正常关闭
    CommonFunction.jobCantCancelTip(job);
    job.addJobChangeListener(new JobChangeAdapter() {

        @Override
        public void running(IJobChangeEvent event) {
            ProgressIndicatorManager.displayProgressIndicator();
            super.running(event);
        }

        @Override
        public void done(IJobChangeEvent event) {
            ProgressIndicatorManager.hideProgressIndicator();
            super.done(event);
        }
    });
    job.setUser(true);
    job.schedule();
    close();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IDialogSettings(org.eclipse.jface.dialogs.IDialogSettings) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) Job(org.eclipse.core.runtime.jobs.Job) LocalFile(org.eclipse.core.internal.filesystem.local.LocalFile) IFile(org.eclipse.core.resources.IFile) File(java.io.File) CoreException(org.eclipse.core.runtime.CoreException) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException)

Example 93 with Job

use of org.eclipse.core.runtime.jobs.Job in project translationstudio8 by heartsome.

the class FileAnalysisHandler method analysisFile.

/**
	 * 准备分析文件
	 */
public void analysisFile(String title) {
    final QAXmlHandler handler = new QAXmlHandler();
    Job job = new Job(title) {

        @Override
        protected IStatus run(IProgressMonitor monitor) {
            // 要分析的文件的个数
            int fileNum = model.getAnalysisIFileList().size();
            model.setSubFileNum(fileNum);
            // 定义的进度条总共四格,其中,解析文件一格,分析文件三格
            monitor.beginTask("", fileNum * 4);
            // 解析文件,如果解析不成功,退出程序, 解析要分析的文件,用掉fileNum*1个格子
            if (!openXliff(handler, monitor)) {
                monitor.done();
                return Status.CANCEL_STATUS;
            }
            if (model.getAnalysisIFileList().size() == 0) {
                MessageDialog.openInformation(shell, Messages.getString("qa.all.dialog.info"), Messages.getString("qa.handlers.FileAnalysisHandler.tip4"));
                return Status.CANCEL_STATUS;
            }
            // 填充要分析文件的所有trans-unit节点个数的总和
            model.setAllTuSize(allTUSize);
            FileAnalysis fileAnalysis = getClassInstance(faItemId);
            // 分析文件用去fileNum*3个格子
            IProgressMonitor subMonitor = new SubProgressMonitor(monitor, fileNum * 3, SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK);
            int analysisResult = fileAnalysis.beginAnalysis(model, subMonitor, handler);
            if (analysisResult == -1 || analysisResult == QAConstant.QA_ZERO) {
                return Status.CANCEL_STATUS;
            }
            subMonitor.done();
            monitor.done();
            return Status.OK_STATUS;
        }
    };
    // 当程序退出时,检测当前 job 是否正常关闭
    CommonFunction.jobCantCancelTip(job);
    job.addJobChangeListener(new JobChangeAdapter() {

        @Override
        public void running(IJobChangeEvent event) {
            ProgressIndicatorManager.displayProgressIndicator();
            super.running(event);
        }

        @Override
        public void done(IJobChangeEvent event) {
            ProgressIndicatorManager.hideProgressIndicator();
            super.done(event);
        }
    });
    job.setUser(true);
    job.schedule();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) QAXmlHandler(net.heartsome.cat.ts.core.qa.QAXmlHandler) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) Job(org.eclipse.core.runtime.jobs.Job) FileAnalysis(net.heartsome.cat.ts.core.qa.FileAnalysis) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor)

Example 94 with Job

use of org.eclipse.core.runtime.jobs.Job in project translationstudio8 by heartsome.

the class NumberOrTagConsisQAHandler method beginQA.

private void beginQA(final ArrayList<IFile> selectIFiles, final QAModel model, final boolean isNumberQA, final QAResult qaResult) {
    final String titile = isNumberQA ? Messages.getString("qa.NumberOrTagConsisQAHandler.jobTitle1") : Messages.getString("qa.NumberOrTagConsisQAHandler.jobTitle2");
    Job job = new Job(titile) {

        @Override
        protected IStatus run(IProgressMonitor monitor) {
            // 解析一格,其余九格
            monitor.beginTask(titile, 10 * selectIFiles.size());
            xmlHandler = new QAXmlHandler();
            // 首先解析文件,如果为false,则退出
            if (!openFile(selectIFiles, monitor)) {
                return Status.OK_STATUS;
            }
            int allTUSize = 0;
            for (IFile iFile : selectIFiles) {
                allTUSize += xmlHandler.getTuSizeMap().get(iFile.getLocation().toOSString());
            }
            initWorkInterval(allTUSize);
            // 开始进行数据处理
            IProgressMonitor subMonitor = new SubProgressMonitor(monitor, 9, SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK);
            subMonitor.beginTask(titile + "...", allTUSize % workInterval == 0 ? (allTUSize / workInterval) : (allTUSize / workInterval) + 1);
            Map<String, ArrayList<String>> languageList = xmlHandler.getLanguages();
            int lineNumber = 0;
            int traversalTuIndex = 0;
            IFile iFile;
            for (Entry<String, ArrayList<String>> langEntry : languageList.entrySet()) {
                String srcLang = langEntry.getKey();
                for (String tgtLang : langEntry.getValue()) {
                    List<String> rowIdsList = xmlHandler.getAllRowIdsByLanguages(srcLang.toUpperCase(), tgtLang.toUpperCase());
                    model.setRowIdsList(rowIdsList);
                    // 开始针对每一个文本段进行检查
                    for (String rowId : rowIdsList) {
                        traversalTuIndex++;
                        // 行号
                        lineNumber = rowIdsList.indexOf(rowId) + 1;
                        String filePath = RowIdUtil.getFileNameByRowId(rowId);
                        iFile = ResourceUtils.fileToIFile(filePath);
                        String langPair = srcLang + Hyphen + tgtLang;
                        QATUDataBean tuDataBean = xmlHandler.getFilteredTUText(filePath, RowIdUtil.parseRowIdToXPath(rowId), model.getNotInclude());
                        if (tuDataBean == null) {
                            if (!xmlHandler.monitorWork(subMonitor, traversalTuIndex, workInterval, false)) {
                                return Status.CANCEL_STATUS;
                            }
                            continue;
                        }
                        if (!tuDataBean.isPassFilter()) {
                            if (!xmlHandler.monitorWork(subMonitor, traversalTuIndex, workInterval, false)) {
                                return Status.CANCEL_STATUS;
                            }
                            continue;
                        } else if (tuDataBean.getTgtContent() == null || "".equals(tuDataBean.getTgtContent())) {
                            // 因为文本段完整性检查要判断译文是否为空的情况,所以,如果译文为空,只有文本段完整性要进行检查,其他检查项都跳过。
                            continue;
                        }
                        tuDataBean.setLineNumber(lineNumber + "");
                        tuDataBean.setFileName(iFile.getName());
                        tuDataBean.setSrcLang(srcLang);
                        tuDataBean.setTgtLang(tgtLang);
                        if (isNumberQA) {
                            NumberConsistenceQA numberQA = new NumberConsistenceQA();
                            qaResult.setMultiOper(model.getMultiOper());
                            numberQA.setQaResult(qaResult);
                            numberQA.startQA(model, subMonitor, iFile, xmlHandler, tuDataBean);
                        } else {
                            TagConsistenceQA tagQA = new TagConsistenceQA();
                            qaResult.setMultiOper(model.getMultiOper());
                            tagQA.setQaResult(qaResult);
                            tagQA.startQA(model, subMonitor, iFile, xmlHandler, tuDataBean);
                        }
                        qaResult.sendDataToViewer(null);
                        if (!xmlHandler.monitorWork(subMonitor, traversalTuIndex, workInterval, false)) {
                            return Status.CANCEL_STATUS;
                        }
                    }
                }
                if (!xmlHandler.monitorWork(subMonitor, traversalTuIndex, workInterval, false)) {
                    return Status.CANCEL_STATUS;
                }
            }
            qaResult.informQAEndFlag();
            subMonitor.done();
            monitor.done();
            return Status.OK_STATUS;
        }
    };
    // 当程序退出时,检测当前 job 是否正常关闭
    CommonFunction.jobCantCancelTip(job);
    job.addJobChangeListener(new JobChangeAdapter() {

        @Override
        public void running(IJobChangeEvent event) {
            ProgressIndicatorManager.displayProgressIndicator();
            super.running(event);
        }

        @Override
        public void done(IJobChangeEvent event) {
            ProgressIndicatorManager.hideProgressIndicator();
            super.done(event);
        }
    });
    job.setUser(true);
    job.schedule();
}
Also used : NumberConsistenceQA(net.heartsome.cat.ts.ui.qa.NumberConsistenceQA) IFile(org.eclipse.core.resources.IFile) QATUDataBean(net.heartsome.cat.ts.core.qa.QATUDataBean) JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) QAXmlHandler(net.heartsome.cat.ts.core.qa.QAXmlHandler) ArrayList(java.util.ArrayList) TagConsistenceQA(net.heartsome.cat.ts.ui.qa.TagConsistenceQA) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Job(org.eclipse.core.runtime.jobs.Job)

Example 95 with Job

use of org.eclipse.core.runtime.jobs.Job in project translationstudio8 by heartsome.

the class QualityAssurance method beginQA.

//------------------下面是优化品质检查的试用代码
public void beginQA(final QAResult qaResult) {
    this.qaResult = qaResult;
    handler = new QAXmlHandler();
    Job job = new Job(Messages.getString("qa.all.qa")) {

        @Override
        protected IStatus run(IProgressMonitor monitor) {
            long time1 = System.currentTimeMillis();
            // 品质检查项的总数
            int fileNum = model.getQaXlfList().size();
            // 定义的进度条总共五格,其中,解析文件一格,进行检查四格
            monitor.beginTask(Messages.getString("qa.QualityAssurance.tip1"), fileNum * 5);
            //先将所有的文件进行解析
            if (!openFile(monitor)) {
                monitor.done();
                return Status.CANCEL_STATUS;
            }
            if (model.getQaXlfList().size() == 0) {
                MessageDialog.openInformation(shell, _INFO, Messages.getString("qa.QualityAssurance.tip2"));
                return Status.CANCEL_STATUS;
            }
            initWorkInterval();
            QARealization realization = null;
            //先遍历每个文件
            for (int fileIndex = 0; fileIndex < model.getQaXlfList().size(); fileIndex++) {
                final IFile iFile = model.getQaXlfList().get(fileIndex);
                String xlfPath = iFile.getLocation().toOSString();
                String iFileFullPath = iFile.getFullPath().toOSString();
                IProgressMonitor subMonitor = new SubProgressMonitor(monitor, 4, SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK);
                int allTuSum = handler.getNodeCount(xlfPath, "/xliff/file/body//trans-unit");
                subMonitor.beginTask("", allTuSum % workInterval == 0 ? (allTuSum / workInterval) : (allTuSum / workInterval) + 1);
                subMonitor.setTaskName(MessageFormat.format(Messages.getString("qa.QualityAssurance.tip3"), new Object[] { Messages.getString("qa.all.qa"), iFileFullPath }));
                int fileNodeSum = handler.getNodeCount(xlfPath, "/xliff/file");
                //行号
                int lineNumber = 0;
                //遍历tu节点的序列号
                int traversalTuIndex = 0;
                for (int fileNodeIdx = QAConstant.QA_FIRST; fileNodeIdx <= fileNodeSum; fileNodeIdx++) {
                    //获取语言对
                    String srcLang = handler.getNodeAttribute(xlfPath, "/xliff/file[" + fileNodeIdx + "]", "source-language");
                    String tgtLang = handler.getNodeAttribute(xlfPath, "/xliff/file[" + fileNodeIdx + "]", "target-language");
                    String langPair = srcLang + Hyphen + tgtLang;
                    int curFileTUNodeSum = handler.getNodeCount(xlfPath, "/xliff/file[" + fileNodeIdx + "]/body//trans-unit");
                    for (int tuIndex = QAConstant.QA_FIRST; tuIndex <= curFileTUNodeSum; tuIndex++) {
                        traversalTuIndex++;
                        String tuXpath = "/xliff/file[" + fileNodeIdx + "]/body/descendant::trans-unit[" + tuIndex + "]";
                        QATUDataBean dataBean = handler.getFilteredTUText(xlfPath, tuXpath, model.getNotInclude());
                        //如果返回的map为null,则进行下一循环,行号也不加自加,这样可以保持这里的行号与界面上的行号一致性,方便定位,出现这种情况的可能很小,因为 rowID 的过滤已经处理过了。
                        if (dataBean == null) {
                            if (!monitorWork(subMonitor, traversalTuIndex, false)) {
                                closeDB();
                                return Status.CANCEL_STATUS;
                            }
                            continue;
                        }
                        lineNumber++;
                        if (lineNumber == 73) {
                            System.out.println("开始处理。。。。");
                        }
                        // 未通过 过滤器过滤的情况,
                        if (!dataBean.isPassFilter()) {
                            if (!monitorWork(subMonitor, traversalTuIndex, false)) {
                                closeDB();
                                return Status.CANCEL_STATUS;
                            }
                            continue;
                        }
                        dataBean.setLineNumber(lineNumber + "");
                        dataBean.setFileName(iFile.getName());
                        dataBean.setSrcLang(srcLang);
                        dataBean.setTgtLang(tgtLang);
                        dataBean.setXlfPath(xlfPath);
                        for (int i = 0; i < model.getBatchQAItemIdList().size(); i++) {
                            final String qaItemId = model.getBatchQAItemIdList().get(i);
                            realization = getClassInstance(qaItemId);
                            // 若没有该项检查的实例,提示出错
                            if (realization == null) {
                                Display.getDefault().asyncExec(new Runnable() {

                                    public void run() {
                                        MessageDialog.openError(shell, _ERROR, MessageFormat.format(Messages.getString("qa.QualityAssurance.tip4"), new Object[] { model.getQaItemId_Name_Class().get(qaItemId).get(QAConstant.QA_ITEM_NAME) }));
                                    }
                                });
                                closeDB();
                                return Status.CANCEL_STATUS;
                            }
                            // 开始进行该项文件的该项检查
                            final String result = realization.startQA(model, subMonitor, iFile, handler, dataBean);
                            // 当未设置术语库、拼写检查词典配置 错误时才会返回 null,所以这时可以直接删。
                            if (result == null) {
                                model.getBatchQAItemIdList().remove(qaItemId);
                                i--;
                            }
                            if (monitor.isCanceled()) {
                                return Status.CANCEL_STATUS;
                            }
                        }
                        // UNDO 发现这里很耗时,需要处理。
                        qaResult.sendDataToViewer(null);
                        if (!monitorWork(subMonitor, traversalTuIndex, false)) {
                            closeDB();
                            return Status.CANCEL_STATUS;
                        }
                    }
                    if (!monitorWork(subMonitor, traversalTuIndex, true)) {
                        closeDB();
                        return Status.CANCEL_STATUS;
                    }
                }
                subMonitor.done();
            }
            closeDB();
            qaResult.informQAEndFlag();
            monitor.done();
            System.out.println("所用时间为" + (System.currentTimeMillis() - time1));
            return Status.OK_STATUS;
        }
    };
    // 当程序退出时,检测当前 job 是否正常关闭
    CommonFunction.jobCantCancelTip(job);
    job.addJobChangeListener(new JobChangeAdapter() {

        @Override
        public void running(IJobChangeEvent event) {
            ProgressIndicatorManager.displayProgressIndicator();
            super.running(event);
        }

        @Override
        public void done(IJobChangeEvent event) {
            ProgressIndicatorManager.hideProgressIndicator();
            super.done(event);
        }
    });
    job.setUser(true);
    job.schedule();
}
Also used : IFile(org.eclipse.core.resources.IFile) QATUDataBean(net.heartsome.cat.ts.core.qa.QATUDataBean) JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) QAXmlHandler(net.heartsome.cat.ts.core.qa.QAXmlHandler) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Job(org.eclipse.core.runtime.jobs.Job)

Aggregations

Job (org.eclipse.core.runtime.jobs.Job)177 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)134 IStatus (org.eclipse.core.runtime.IStatus)33 IOException (java.io.IOException)27 File (java.io.File)20 Status (org.eclipse.core.runtime.Status)20 IJobChangeEvent (org.eclipse.core.runtime.jobs.IJobChangeEvent)20 JobChangeAdapter (org.eclipse.core.runtime.jobs.JobChangeAdapter)20 CoreException (org.eclipse.core.runtime.CoreException)17 IDockerConnection (org.eclipse.linuxtools.docker.core.IDockerConnection)17 JobFamily (com.cubrid.common.ui.spi.progress.JobFamily)14 DockerException (org.eclipse.linuxtools.docker.core.DockerException)14 IFile (org.eclipse.core.resources.IFile)13 URL (java.net.URL)11 ArrayList (java.util.ArrayList)11 IPath (org.eclipse.core.runtime.IPath)10 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)9 IWorkbenchPart (org.eclipse.ui.IWorkbenchPart)9 DockerConnection (org.eclipse.linuxtools.internal.docker.core.DockerConnection)8 Display (org.eclipse.swt.widgets.Display)8