use of org.eclipse.core.runtime.IProgressMonitor in project translationstudio8 by heartsome.
the class TmDbManagerImportWizard method performFinish.
@Override
public boolean performFinish() {
final String tmxFile = tmxPage.getTMXFile();
if (tmxFile == null || tmxFile.equals("")) {
tmxPage.setErrorMessage(Messages.getString("wizard.TmDbManagerImportWizard.msg"));
return false;
}
tmxPage.setErrorMessage(null);
tmxPage.setMessage(null);
IRunnableWithProgress runnable = new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
tmxPage.executeImport(tmxFile, monitor);
}
};
try {
getContainer().run(true, true, runnable);
} catch (InvocationTargetException e) {
e.printStackTrace();
return false;
} catch (InterruptedException e) {
e.printStackTrace();
return false;
}
return true;
}
use of org.eclipse.core.runtime.IProgressMonitor in project translationstudio8 by heartsome.
the class UpdateTMWizard method performFinish.
public boolean performFinish() {
final IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
final boolean isDraft = page.isDraft();
final boolean isApproved = page.isApproved();
final boolean isSignedOff = page.isSignedOff();
final boolean isTranslated = page.isTranslated();
final boolean isLocked = page.isLocked();
if (!isDraft && !isApproved && !isSignedOff && !isTranslated && !isLocked) {
MessageDialog.openInformation(getShell(), Messages.getString("wizard.UpdateTMWizard.msgTitle"), Messages.getString("wizard.UpdateTMWizard.msg"));
return false;
}
IPreferenceStore ps = Activator.getDefault().getPreferenceStore();
final int contextSize = ps.getInt(TMPreferenceConstants.CONTEXT_MATCH);
final int tmxImportStrategy = ps.getInt(TMPreferenceConstants.TM_UPDATE);
IRunnableWithProgress progress = new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) {
monitor.setTaskName(Messages.getString("dialog.UpdateTMDialog.jobTask1"));
monitor.beginTask(Messages.getString("dialog.UpdateTMDialog.jobTask1"), lstXLIFF.size() * 2);
for (final IFile xliffFile : lstXLIFF) {
ProjectConfiger projectConfig = ProjectConfigerFactory.getProjectConfiger(xliffFile.getProject());
DatabaseModelBean modelBean = projectConfig.getDefaultTMDb();
FileEditorInput editorInput = new FileEditorInput(xliffFile);
IEditorPart editorPart = activePage.findEditor(editorInput);
// 选择所有语言
XLFHandler handler = null;
if (editorPart != null && editorPart instanceof IXliffEditor) {
// xliff 文件已用 XLIFF 编辑器打开
IXliffEditor xliffEditor = (IXliffEditor) editorPart;
handler = xliffEditor.getXLFHandler();
} else {
// xliff 文件未打开
handler = new XLFHandler();
}
monitor.subTask(Messages.getString("dialog.UpdateTMDialog.jobTask2"));
// 修改获取系统用户方式/*System.getProperty("user.name");*/
String systemUser = PlatformUI.getPreferenceStore().getString(IPreferenceConstants.SYSTEM_USER);
String[] arrTempTMX = handler.generateTMXToUpdateTM(xliffFile, isApproved, isSignedOff, isTranslated, isDraft, isLocked, contextSize, systemUser);
monitor.worked(1);
if (arrTempTMX != null) {
monitor.subTask(Messages.getString("dialog.UpdateTMDialog.jobTask3"));
// }
try {
DatabaseService.importTmxWithString(modelBean.toDbMetaData(), arrTempTMX[1], new SubProgressMonitor(monitor, 1), tmxImportStrategy, false, arrTempTMX[0]);
} catch (ImportException e) {
final String msg = e.getMessage();
Display.getDefault().syncExec(new Runnable() {
public void run() {
MessageDialog.openInformation(getShell(), Messages.getString("dialog.UpdateTMDialog.job.msgTitle"), msg);
}
});
canFinish = false;
return;
}
}
}
monitor.done();
// 刷新项目
ResourceUtils.refreshCurentSelectProject();
canFinish = true;
}
};
try {
getContainer().run(true, true, progress);
} catch (InvocationTargetException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
return canFinish;
}
use of org.eclipse.core.runtime.IProgressMonitor in project translationstudio8 by heartsome.
the class ImportProjectWizardPage2 method updateProjectsList.
public void updateProjectsList(final String path) {
if (path == null || path.length() == 0) {
setMessage(Messages.getString("wizard.ImportProjectWizardPage.desc"));
selectedProjects = new ProjectRecord[0];
setPageComplete(selectElementTree.getCheckedElements().length > 0);
lastPath = path;
return;
}
final File directory = new File(path);
long modified = directory.lastModified();
if (path.equals(lastPath) && lastModified == modified && lastCopyFiles == copyFiles) {
// change, no refreshing is required
return;
}
lastPath = path;
lastModified = modified;
lastCopyFiles = copyFiles;
// We can't access the radio button from the inner class so get the
// status beforehand
final boolean dirSelected = false;
try {
getContainer().run(true, true, new IRunnableWithProgress() {
@SuppressWarnings({ "rawtypes", "restriction" })
public void run(IProgressMonitor monitor) {
monitor.beginTask(Messages.getString("importProjectWizardPage.searchingMessage"), 100);
selectedProjects = new ProjectRecord[0];
Collection files = new ArrayList();
monitor.worked(10);
if (!dirSelected && ArchiveFileManipulations.isTarFile(path)) {
TarFile sourceTarFile = getSpecifiedTarSourceFile(path);
if (sourceTarFile == null) {
return;
}
structureProvider = new TarLeveledStructureProvider(sourceTarFile);
Object child = structureProvider.getRoot();
if (!collectProjectFilesFromProvider(files, child, 0, monitor)) {
return;
}
Iterator filesIterator = files.iterator();
selectedProjects = new ProjectRecord[files.size()];
int index = 0;
monitor.worked(50);
monitor.subTask(Messages.getString("importProjectWizardPage.processingMessage"));
while (filesIterator.hasNext()) {
selectedProjects[index++] = (ProjectRecord) filesIterator.next();
}
} else if (!dirSelected && ArchiveFileManipulations.isZipFile(path)) {
ZipFile sourceFile = getSpecifiedZipSourceFile(path);
if (sourceFile == null) {
return;
}
structureProvider = new ZipLeveledStructureProvider(sourceFile);
Object child = structureProvider.getRoot();
if (!collectProjectFilesFromProvider(files, child, 0, monitor)) {
return;
}
Iterator filesIterator = files.iterator();
selectedProjects = new ProjectRecord[files.size()];
int index = 0;
monitor.worked(50);
monitor.subTask(Messages.getString("importProjectWizardPage.processingMessage"));
while (filesIterator.hasNext()) {
selectedProjects[index++] = (ProjectRecord) filesIterator.next();
}
} else {
monitor.worked(60);
}
monitor.done();
}
});
} catch (InvocationTargetException e) {
LOGGER.error(e.getMessage(), e);
} catch (InterruptedException e) {
LOGGER.error(e.getMessage(), e);
}
// 开始处理导入项目中的项目名称不合法的情况
String projectName = "";
StringBuffer errorProjectNameSB = new StringBuffer();
StringBuffer errorCharSB = new StringBuffer();
List<ProjectRecord> tempList = new ArrayList<ProjectRecord>();
boolean isError = false;
for (int i = 0; i < selectedProjects.length; i++) {
projectName = selectedProjects[i].getProjectName();
isError = false;
for (int j = 0; j < Constant.RESOURCE_ERRORCHAR.length; j++) {
if (projectName.indexOf(Constant.RESOURCE_ERRORCHAR[j]) != -1) {
errorCharSB.append(Constant.RESOURCE_ERRORCHAR[j]);
errorProjectNameSB.append(projectName + ", ");
isError = true;
}
}
if (!isError) {
tempList.add(selectedProjects[i]);
}
}
if (errorProjectNameSB.length() > 0) {
final String errorTip = MessageFormat.format(Messages.getString("importProjectWizardPage.projectError"), new Object[] { errorProjectNameSB.toString().substring(0, errorProjectNameSB.toString().length() - 2), errorCharSB.toString() });
Display.getDefault().asyncExec(new Runnable() {
public void run() {
MessageDialog.openWarning(getShell(), Messages.getString("importProject.all.dialog.warning"), errorTip);
}
});
}
selectedProjects = tempList.toArray(new ProjectRecord[tempList.size()]);
setPageComplete(selectElementTree.getCheckedElements().length > 0);
selectElementTree.refresh(true);
}
use of org.eclipse.core.runtime.IProgressMonitor in project translationstudio8 by heartsome.
the class PreTranslation method executeTranslation.
/**
* 根据构建参数执行预翻译 ;
* @throws InterruptedException
*/
public List<PreTranslationCounter> executeTranslation(IProgressMonitor monitor) throws InterruptedException {
if (monitor == null) {
monitor = new NullProgressMonitor();
}
monitor.beginTask("", this.xlfFiles.size());
monitor.setTaskName(Messages.getString("pretranslation.PreTranslation.task1"));
try {
for (String xlfPath : xlfFiles) {
if (monitor != null && monitor.isCanceled()) {
throw new InterruptedException();
}
currentCounter = new PreTranslationCounter(xlfPath);
this.transCounters.add(currentCounter);
VTDNav vn = xlfHandler.getVnMap().get(xlfPath);
VTDUtils vu = new VTDUtils(vn);
AutoPilot ap = new AutoPilot(vu.getVTDNav());
int tuNumber = xlfHandler.getNodeCount(xlfPath, "/xliff/file//descendant::trans-unit[(source/text()!='' or source/*)]");
currentCounter.setTuNumber(tuNumber);
ap.selectXPath("/xliff/file");
String srcLang = "";
String tgtLang = "";
XMLModifier xm = new XMLModifier(vn);
IProgressMonitor monitor2 = new SubProgressMonitor(monitor, 1);
monitor2.beginTask(Messages.getString("pretranslation.PreTranslation.task2"), tuNumber);
while (ap.evalXPath() != -1) {
// 循环 file 节点
String _srcLang = vu.getCurrentElementAttribut("source-language", "");
String _tgtLang = vu.getCurrentElementAttribut("target-language", "");
if (!_srcLang.equals("")) {
srcLang = _srcLang;
}
if (!_tgtLang.equals("")) {
tgtLang = _tgtLang;
}
if (srcLang.equals("") || tgtLang.equals("")) {
continue;
}
if (updateStrategy == PreTransParameters.KEEP_OLD_TARGET) {
keepCurrentMatchs(vu, _srcLang, _tgtLang, xm, monitor2);
} else if (updateStrategy == PreTransParameters.KEEP_BEST_MATCH_TARGET) {
keepHigherMatchs(vu, _srcLang, _tgtLang, xm, monitor2);
} else if (updateStrategy == PreTransParameters.KEEP_NEW_TARGET) {
overwriteMatchs(vu, srcLang, tgtLang, xm, monitor2);
}
}
monitor2.done();
FileOutputStream fos = new FileOutputStream(xlfPath);
BufferedOutputStream bos = new BufferedOutputStream(fos);
// 写入文件
xm.output(bos);
bos.close();
fos.close();
}
} catch (XPathParseException e) {
logger.error("", e);
e.printStackTrace();
} catch (NavException e) {
logger.error("", e);
e.printStackTrace();
} catch (ModifyException e) {
logger.error("", e);
e.printStackTrace();
} catch (XPathEvalException e) {
logger.error("", e);
e.printStackTrace();
} catch (UnsupportedEncodingException e) {
logger.error("", e);
e.printStackTrace();
} catch (FileNotFoundException e) {
logger.error("", e);
e.printStackTrace();
} catch (TranscodeException e) {
logger.error("", e);
e.printStackTrace();
} catch (IOException e) {
logger.error("", e);
e.printStackTrace();
}
monitor.done();
return this.transCounters;
}
use of org.eclipse.core.runtime.IProgressMonitor in project translationstudio8 by heartsome.
the class ExportDocxDialog method beginExport.
/**
* 开始导出功能
*/
private void beginExport(IProgressMonitor monitor, final String docxPath, boolean exportComment, boolean exportStatus, String expandXpath) throws Exception {
if (monitor == null) {
monitor = new NullProgressMonitor();
}
VTDGen vg = new VTDGen();
if (!vg.parseFile(strXliffFullPath, true)) {
final String parseErrorTip = MessageFormat.format(Messages.getString("ExportDocxDialog.parseError"), ResourceUtils.fileToIFile(docxPath).getFullPath().toOSString());
Display.getDefault().syncExec(new Runnable() {
@Override
public void run() {
MessageDialog.openError(getShell(), Messages.getString("all.dialog.warning"), parseErrorTip);
}
});
throw new Exception(parseErrorTip);
}
monitor.worked(1);
VTDNav vn = vg.getNav();
VTDUtils vu = new VTDUtils(vn);
AutoPilot ap = new AutoPilot(vn);
ap.declareXPathNameSpace("hs", "http://www.heartsome.net.cn/2008/XLFExtension");
otherAP = new AutoPilot(vn);
otherAP.declareXPathNameSpace("hs", "http://www.heartsome.net.cn/2008/XLFExtension");
AutoPilot childAP = new AutoPilot(vn);
childAP.declareXPathNameSpace("hs", "http://www.heartsome.net.cn/2008/XLFExtension");
String srcLang = "";
String tgtLang = "";
// 备注:目前只支持处理一种目标语言的情况
ap.selectXPath("/xliff//file[1]");
if (ap.evalXPath() != -1) {
srcLang = vu.getCurrentElementAttribut("source-language", "");
tgtLang = vu.getCurrentElementAttribut("target-language", "");
}
if ("".equals(srcLang)) {
Display.getDefault().syncExec(new Runnable() {
@Override
public void run() {
MessageDialog.openWarning(getShell(), Messages.getString("all.dialog.warning"), Messages.getString("ExportDocxDialog.ok.msg1"));
}
});
LOGGER.error(Messages.getString("ExportDocxDialog.ok.msg1"));
}
if ("".equals(tgtLang)) {
Display.getDefault().syncExec(new Runnable() {
@Override
public void run() {
MessageDialog.openWarning(getShell(), Messages.getString("all.dialog.warning"), Messages.getString("ExportDocxDialog.ok.msg2"));
}
});
LOGGER.error(Messages.getString("ExportDocxDialog.ok.msg2"));
}
String xpath = "/xliff/file[@source-language='" + srcLang + "' and @target-language='" + tgtLang + "']/body/descendant::trans-unit[(source/text()!='' or source/*)" + expandXpath + "]";
ap.selectXPath(xpath);
List<TUBean> tuDataList = new ArrayList<TUBean>();
String rowId = "";
int status = DocxConstant.STATUS_unstrans;
boolean approved = false;
boolean isLocked = false;
boolean isNotSendToTm = false;
boolean needsReview = false;
int index = -1;
while (ap.evalXPath() != -1) {
status = DocxConstant.STATUS_unstrans;
approved = false;
isLocked = false;
isNotSendToTm = false;
needsReview = false;
TUBean bean = new TUBean();
rowId = RowIdUtil.getSpecialRowId(vn);
bean.setRowId(rowId);
// 是否批准
if ((index = vn.getAttrVal("approved")) != -1) {
if ("yes".equals(vn.toString(index))) {
approved = true;
}
}
// 是否锁定
if ((index = vn.getAttrVal("translate")) != -1) {
if ("no".equals(vn.toString(index))) {
isLocked = true;
}
}
// 是否不发送数据库
if ((index = vn.getAttrVal("hs:send-to-tm")) != -1) {
if ("no".equals(vn.toString(index))) {
isNotSendToTm = true;
}
}
// 是否是疑问文本段
if ((index = vn.getAttrVal("hs:needs-review")) != -1) {
if ("yes".equals(vn.toString(index))) {
needsReview = true;
}
}
vn.push();
childAP.selectXPath("./source");
if (childAP.evalXPath() != -1) {
bean.setSrcText(vu.getElementContent());
}
vn.pop();
vn.push();
childAP.selectXPath("./target");
if (childAP.evalXPath() != -1) {
if ((index = vn.getAttrVal("state")) != -1) {
String stateStr = vn.toString(index);
if ("new".equals(stateStr)) {
// 草稿
status = DocxConstant.STATUS_draft;
} else if ("translated".equals(stateStr)) {
if (approved) {
// 批准翻译
status = DocxConstant.STATUS_approved;
} else {
// 完成翻译
status = DocxConstant.STATUS_translated;
}
} else if ("signed-off".equals(stateStr) && approved) {
// 签发
status = DocxConstant.STATUS_signedOff;
}
}
bean.setTgtText(vu.getElementContent());
} else {
status = DocxConstant.STATUS_unstrans;
}
vn.pop();
// 这里参照界面上状态的写法,分三个部份,第一个为(草稿,已翻译,完成翻译,批注,签发,锁定), 第二部份为不送至库,第三部份为疑问。
String beanStatus = "";
if (isLocked) {
beanStatus += Messages.getString("ExportDocxDialog.ok.status.locked");
} else {
switch(status) {
case DocxConstant.STATUS_unstrans:
beanStatus += Messages.getString("ExportDocxDialog.ok.status.unstrans");
break;
case DocxConstant.STATUS_draft:
beanStatus += Messages.getString("ExportDocxDialog.ok.status.draft");
break;
case DocxConstant.STATUS_translated:
beanStatus += Messages.getString("ExportDocxDialog.ok.status.translated");
break;
case DocxConstant.STATUS_approved:
beanStatus += Messages.getString("ExportDocxDialog.ok.status.approved");
break;
case DocxConstant.STATUS_signedOff:
beanStatus += Messages.getString("ExportDocxDialog.ok.status.signedOff");
break;
default:
break;
}
}
if (isNotSendToTm) {
beanStatus += "、";
beanStatus += Messages.getString("ExportDocxDialog.ok.status.NotSendToTm");
}
if (needsReview) {
beanStatus += "、";
beanStatus += Messages.getString("ExportDocxDialog.ok.status.Review");
}
bean.setStatus(beanStatus);
getComments(vn, vu, bean);
bean.setIndex("" + (tuDataList.size() + 1));
tuDataList.add(bean);
}
monitor.worked(1);
// 开始导出操作。规划出 subMonitor
IProgressMonitor subMonitor = new SubProgressMonitor(monitor, 18, SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK);
ExportDocx wordOutput = new ExportDocx(srcLang, tgtLang, docxPath, getShell(), exportComment, exportStatus);
wordOutput.output(tuDataList, subMonitor);
subMonitor.done();
}
Aggregations