Search in sources :

Example 91 with OperationCanceledException

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

the class DocumentPart method reverseConvert.

// ------------------------------------------  下面是逆转换的代码 ------------------------------------------------
@Override
public void reverseConvert() throws Exception {
    // 处理的单元为 w:p
    String xpath = "/w:document/w:body/descendant::w:p";
    int allPSum = getNodeCount(xpath);
    initWorkInterval(allPSum);
    IProgressMonitor subMonitor = new SubProgressMonitor(monitor, 12, SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK);
    subMonitor.beginTask("", allPSum % workInterval == 0 ? (allPSum / workInterval) : (allPSum / workInterval) + 1);
    subMonitor.setTaskName(Messages.getString("xlf2Docx.task5"));
    ap.selectXPath(xpath);
    int traverPIdx = 0;
    while (ap.evalXPath() != -1) {
        traverPIdx++;
        analysisReversePnode();
        monitorWork(subMonitor, traverPIdx, false);
    }
    xm.output(partPath);
    monitorWork(subMonitor, traverPIdx, true);
    subMonitor.done();
    //再处理可翻译属性
    xpath = "/w:document/w:body/descendant::w:p/w:r/w:pict/v:shape/@alt";
    reverseTranslateAttributes(xpath);
    monitor.worked(1);
    if (monitor.isCanceled()) {
        throw new OperationCanceledException(Messages.getString("docxConvert.task3"));
    }
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor)

Example 92 with OperationCanceledException

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

the class PreloadingRepositoryHandler method doExecuteAndLoad.

void doExecuteAndLoad() {
    if (preloadRepositories()) {
        // cancel any load that is already running
        final IStatus[] checkStatus = new IStatus[1];
        Job.getJobManager().cancel(LoadMetadataRepositoryJob.LOAD_FAMILY);
        final LoadMetadataRepositoryJob loadJob = new LoadMetadataRepositoryJob(getProvisioningUI()) {

            public IStatus runModal(IProgressMonitor monitor) {
                SubMonitor sub = SubMonitor.convert(monitor, getProgressTaskName(), 1000);
                IStatus status = super.runModal(sub.newChild(500));
                if (status.getSeverity() == IStatus.CANCEL)
                    return status;
                if (status.getSeverity() != IStatus.OK) {
                    // 记录检查错误
                    checkStatus[0] = status;
                    return Status.OK_STATUS;
                }
                try {
                    doPostLoadBackgroundWork(sub.newChild(500));
                } catch (OperationCanceledException e) {
                    return Status.CANCEL_STATUS;
                }
                return status;
            }
        };
        setLoadJobProperties(loadJob);
        loadJob.setName(P2UpdateUtil.CHECK_UPDATE_JOB_NAME);
        if (waitForPreload()) {
            loadJob.addJobChangeListener(new JobChangeAdapter() {

                public void done(IJobChangeEvent event) {
                    if (PlatformUI.isWorkbenchRunning())
                        if (event.getResult().isOK()) {
                            PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {

                                public void run() {
                                    if (checkStatus[0] != null) {
                                        // 提示连接异常
                                        P2UpdateUtil.openConnectErrorInfoDialog(getShell(), P2UpdateUtil.INFO_TYPE_CHECK);
                                        return;
                                    }
                                    doExecute(loadJob);
                                }
                            });
                        }
                }
            });
            loadJob.setUser(true);
            loadJob.schedule();
        } else {
            loadJob.setSystem(true);
            loadJob.setUser(false);
            loadJob.schedule();
            doExecute(null);
        }
    } else {
        doExecute(null);
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) SubMonitor(org.eclipse.core.runtime.SubMonitor) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) LoadMetadataRepositoryJob(org.eclipse.equinox.p2.ui.LoadMetadataRepositoryJob)

Example 93 with OperationCanceledException

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

the class XLFHandler method generateTMXFileContent.

/**
	 * 根据同一个 XLIFF 文件中的 rowId 生成 TMX 文件, 对于不添加到库中的文本段将被忽略
	 * @param list
	 *            rowId
	 * @param srcLang
	 *            源语言
	 * @param monitor
	 *            进度条
	 * @return TMX 文件
	 */
public StringBuffer generateTMXFileContent(String systemUser, List<String> list, String srcLang, String tgtLang, IProgressMonitor monitor, int contextSize, IProject project) {
    if (list == null || list.size() == 0) {
        return null;
    }
    // long start = System.currentTimeMillis();
    if (monitor == null) {
        monitor = new NullProgressMonitor();
    }
    monitor.setTaskName(Messages.getString("file.XLFHandler.task4"));
    monitor.beginTask(Messages.getString("file.XLFHandler.task4"), list.size());
    if (monitor.isCanceled()) {
        monitor.setTaskName(Messages.getString("file.XLFHandler.task5"));
        throw new OperationCanceledException();
    }
    StringBuffer re = new StringBuffer();
    re.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
    re.append("<tmx version=\"1.4b\">");
    re.append("<header creationtool=\"" + Constants.TMX_CREATIONTOOL + "\" creationtoolversion=\"" + Constants.TMX_CREATIONTOOLVERSION + "\" srclang=\"" + srcLang + "\" adminlang=\"en\" datatype=\"xml\" o-tmf=\"XLIFF\" segtype=\"paragraph\">");
    re.append("</header>");
    re.append("<body>");
    VTDNav vn = getVTDNavByRowId(list.get(0)).duplicateNav();
    AutoPilot ap = new AutoPilot(vn);
    VTDUtils vu = null;
    try {
        vu = new VTDUtils(vn);
    } catch (NavException e) {
        LOGGER.error(Messages.getString("file.XLFHandler.logger15"), e);
    }
    String strChangeBy = systemUser;
    String strProp = getProjectProp(project);
    boolean isNull = true;
    AutoPilot ap2 = new AutoPilot(vn);
    ap2.declareXPathNameSpace(hsNSPrefix, hsR7NSUrl);
    for (String rowId : list) {
        if (monitor.isCanceled()) {
            re = null;
            monitor.setTaskName(Messages.getString("file.XLFHandler.task5"));
            throw new OperationCanceledException();
        }
        String tgtText = getTgtContent(rowId);
        String srcText = getSrcContent(rowId);
        if (srcText == null || srcText.trim().equals("") || tgtText == null || tgtText.trim().equals("")) {
            monitor.worked(1);
            continue;
        }
        if (isSendToTM(rowId)) {
            monitor.worked(1);
            continue;
        }
        String tuXPath = RowIdUtil.parseRowIdToXPath(rowId);
        try {
            ap.selectXPath(tuXPath);
            ap.evalXPath();
        } catch (XPathParseException e) {
            LOGGER.error(Messages.getString("file.XLFHandler.logger16"), e);
            monitor.done();
        } catch (XPathEvalException e) {
            LOGGER.error(Messages.getString("file.XLFHandler.logger16"), e);
            monitor.done();
        } catch (NavException e) {
            LOGGER.error(Messages.getString("file.XLFHandler.logger16"), e);
            monitor.done();
        }
        re.append("<tu ");
        // 添加tu的属性
        String id = vu.getValue("./@id");
        String creationDate = CommonFunction.retTMXDate();
        String changeDate = creationDate;
        re.append("tuid=\"" + genTuId(rowId, id) + "\" ");
        re.append("changedate=\"" + changeDate + "\" changeid=\"" + strChangeBy + "\" ");
        re.append("creationdate=\"" + creationDate + "\" creationid=\"" + strChangeBy + "\" >\n");
        try {
            // Fixed Bug #2290 入库时未添加批注信息 by Jason
            Vector<NoteBean> notes = getNotes(rowId);
            if (notes != null) {
                for (NoteBean bean : notes) {
                    String lang = bean.getLang();
                    if (lang != null && !lang.equals("")) {
                        re.append("<note xml:lang='" + lang + "'>" + bean.getNoteText() + "</note>");
                    } else {
                        re.append("<note>" + bean.getNoteText() + "</note>");
                    }
                }
            }
        } catch (NavException e1) {
            LOGGER.error("", e1);
            e1.printStackTrace();
        } catch (XPathParseException e1) {
            LOGGER.error("", e1);
            e1.printStackTrace();
        } catch (XPathEvalException e1) {
            LOGGER.error("", e1);
            e1.printStackTrace();
        }
        // 添加上下文prop
        re.append("<prop type=\"x-preContext\">");
        vn.push();
        try {
            ap2.selectXPath(tuXPath);
        } catch (XPathParseException e) {
            LOGGER.error("XPathParseException", e);
            e.printStackTrace();
        }
        re.append(getContext(vu, ap2, contextSize, true));
        re.append("</prop>");
        vn.pop();
        vn.push();
        re.append("<prop type=\"x-nextContext\">");
        ap2.resetXPath();
        re.append(getContext(vu, ap2, contextSize, false));
        re.append("</prop>");
        vn.pop();
        // 添加自定义属性
        re.append(strProp);
        re.append("<tuv xml:lang=\"" + srcLang + "\">\n");
        // String sourceTextXp = "./source/text()";
        // re.append("<seg>").append(vu.getValue(ap, sourceTextXp)).append("</seg>");
        re.append("<seg>").append(srcText.trim()).append("</seg>\n");
        re.append("</tuv>\n");
        // 添加tuv(target)
        re.append("<tuv xml:lang=\"" + tgtLang + "\">\n");
        // String targetTextXp = "./target/text()";
        // re.append("<seg>").append(vu.getValue(ap, targetTextXp)).append("</seg>");
        re.append("<seg>").append(tgtText.trim()).append("</seg>\n");
        re.append("</tuv>\n");
        re.append("</tu>\n");
        monitor.worked(1);
        isNull = false;
    }
    re.append("</body>");
    re.append("</tmx>");
    monitor.done();
    if (isNull) {
        return null;
    } else {
        return re;
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) NavException(com.ximpleware.NavException) XPathEvalException(com.ximpleware.XPathEvalException) XPathParseException(com.ximpleware.XPathParseException) NoteBean(net.heartsome.cat.ts.core.bean.NoteBean) VTDUtils(net.heartsome.xml.vtdimpl.VTDUtils) AutoPilot(com.ximpleware.AutoPilot) VTDNav(com.ximpleware.VTDNav)

Example 94 with OperationCanceledException

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

the class CheckUpdateHandler method doPostLoadBackgroundWork.

@Override
protected void doPostLoadBackgroundWork(IProgressMonitor monitor) throws OperationCanceledException {
    operation = getProvisioningUI().getUpdateOperation(null, null);
    // check for updates
    IStatus resolveStatus = operation.resolveModal(monitor);
    if (resolveStatus.getSeverity() == IStatus.CANCEL)
        throw new OperationCanceledException();
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException)

Example 95 with OperationCanceledException

use of org.eclipse.core.runtime.OperationCanceledException in project che by eclipse.

the class ASTProvider method createAST.

/**
     * Creates a new compilation unit AST.
     *
     * @param input the Java element for which to create the AST
     * @param progressMonitor the progress monitor
     * @return AST
     */
public static CompilationUnit createAST(final ITypeRoot input, final IProgressMonitor progressMonitor) {
    if (!hasSource(input))
        return null;
    if (progressMonitor != null && progressMonitor.isCanceled())
        return null;
    final ASTParser parser = ASTParser.newParser(SHARED_AST_LEVEL);
    parser.setResolveBindings(true);
    parser.setStatementsRecovery(SHARED_AST_STATEMENT_RECOVERY);
    parser.setBindingsRecovery(SHARED_BINDING_RECOVERY);
    parser.setSource(input);
    if (progressMonitor != null && progressMonitor.isCanceled())
        return null;
    final CompilationUnit[] root = new CompilationUnit[1];
    SafeRunner.run(new ISafeRunnable() {

        public void run() {
            try {
                if (progressMonitor != null && progressMonitor.isCanceled())
                    return;
                if (DEBUG)
                    System.err.println(getThreadName() + " - " + DEBUG_PREFIX + "creating AST for: " + //$NON-NLS-1$ //$NON-NLS-2$
                    input.getElementName());
                root[0] = (CompilationUnit) parser.createAST(progressMonitor);
                //mark as unmodifiable
                ASTNodes.setFlagsToAST(root[0], ASTNode.PROTECT);
            } catch (OperationCanceledException ex) {
                return;
            }
        }

        public void handleException(Throwable ex) {
            LOG.error(ex.getMessage(), ex);
        }
    });
    return root[0];
}
Also used : CompilationUnit(org.eclipse.jdt.core.dom.CompilationUnit) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) ISafeRunnable(org.eclipse.core.runtime.ISafeRunnable) ASTParser(org.eclipse.jdt.core.dom.ASTParser)

Aggregations

OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)134 CoreException (org.eclipse.core.runtime.CoreException)38 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)37 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)34 ArrayList (java.util.ArrayList)25 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)24 IOException (java.io.IOException)21 IFile (org.eclipse.core.resources.IFile)21 IStatus (org.eclipse.core.runtime.IStatus)21 InvocationTargetException (java.lang.reflect.InvocationTargetException)20 Status (org.eclipse.core.runtime.Status)16 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)16 RefactoringStatus (org.eclipse.ltk.core.refactoring.RefactoringStatus)16 File (java.io.File)15 SubMonitor (org.eclipse.core.runtime.SubMonitor)10 Job (org.eclipse.core.runtime.jobs.Job)9 CompilationUnit (org.eclipse.jdt.core.dom.CompilationUnit)9 IProject (org.eclipse.core.resources.IProject)8 HashSet (java.util.HashSet)7 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)7