Search in sources :

Example 1 with FileAnalysis

use of net.heartsome.cat.ts.core.qa.FileAnalysis 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)

Aggregations

FileAnalysis (net.heartsome.cat.ts.core.qa.FileAnalysis)1 QAXmlHandler (net.heartsome.cat.ts.core.qa.QAXmlHandler)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)1 IJobChangeEvent (org.eclipse.core.runtime.jobs.IJobChangeEvent)1 Job (org.eclipse.core.runtime.jobs.Job)1 JobChangeAdapter (org.eclipse.core.runtime.jobs.JobChangeAdapter)1