use of net.heartsome.cat.ts.core.file.XLFHandler in project translationstudio8 by heartsome.
the class XlfEditor method getRowIds.
/**
* @return List<String> 当前所有可见文本段的 RowID,合并、分割文本段后应重新获取
*/
public ArrayList<String> getRowIds() {
WorkbenchContentsFinder finder = new WorkbenchContentsFinder();
IEditorPart activateEditor = finder.activeWorkbenchWindow().getActivePage().getActiveEditor();
IXliffEditor xliffEditor = (IXliffEditor) activateEditor;
XLFHandler handler = xliffEditor.getXLFHandler();
return handler.getRowIds();
}
use of net.heartsome.cat.ts.core.file.XLFHandler in project translationstudio8 by heartsome.
the class PreTransUitls method executeTranslation.
public static void executeTranslation(List<IFile> list, final Shell shell) {
HsMultiActiveCellEditor.commit(true);
try {
if (list.size() == 0) {
MessageDialog.openInformation(shell, Messages.getString("pretranslation.PreTransUitls.msgTitle"), Messages.getString("pretranslation.PreTransUitls.msg1"));
return;
}
List<IFile> lstFiles = new ArrayList<IFile>();
XLFValidator.resetFlag();
for (IFile iFile : list) {
if (!XLFValidator.validateXliffFile(iFile)) {
lstFiles.add(iFile);
}
}
XLFValidator.resetFlag();
list = new ArrayList<IFile>(list);
list.removeAll(lstFiles);
if (list.size() == 0) {
return;
}
final IProject project = list.get(0).getProject();
final List<String> filesWithOsPath = ResourceUtils.IFilesToOsPath(list);
final XLFHandler xlfHandler = new XLFHandler();
Map<String, Object> resultMap = xlfHandler.openFiles(filesWithOsPath);
if (resultMap == null || Constant.RETURNVALUE_RESULT_SUCCESSFUL != (Integer) resultMap.get(Constant.RETURNVALUE_RESULT)) {
// 打开文件失败。
MessageDialog.openInformation(shell, Messages.getString("pretranslation.PreTransUitls.msgTitle"), Messages.getString("pretranslation.PreTransUitls.msg2"));
return;
}
Map<String, List<XliffBean>> map = xlfHandler.getXliffInfo();
final PreTransParameters parameters = new PreTransParameters();
PreTranslationDialog dialog = new PreTranslationDialog(shell, map, parameters);
if (dialog.open() == Window.OK) {
if (project == null) {
MessageDialog.openInformation(shell, Messages.getString("pretranslation.PreTransUitls.msgTitle"), Messages.getString("pretranslation.PreTransUitls.msg3"));
return;
}
if (filesWithOsPath == null || filesWithOsPath.size() == 0) {
MessageDialog.openInformation(shell, Messages.getString("pretranslation.PreTransUitls.msgTitle"), Messages.getString("pretranslation.PreTransUitls.msg4"));
return;
}
final List<IFile> lstFile = list;
IRunnableWithProgress runnable = new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
PreTranslation pt = new PreTranslation(xlfHandler, filesWithOsPath, project, parameters);
try {
final List<PreTranslationCounter> result = pt.executeTranslation(monitor);
Display.getDefault().syncExec(new Runnable() {
public void run() {
PreTranslationResultDialog dialog = new PreTranslationResultDialog(shell, result);
dialog.open();
}
});
project.refreshLocal(IResource.DEPTH_INFINITE, null);
result.clear();
} catch (InterruptedException e) {
e.printStackTrace();
} catch (CoreException e) {
logger.error("", e);
e.printStackTrace();
} finally {
pt.clearResources();
}
Display.getDefault().syncExec(new Runnable() {
public void run() {
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
for (IFile file : lstFile) {
FileEditorInput editorInput = new FileEditorInput(file);
IEditorPart editorPart = page.findEditor(editorInput);
// 选择所有语言
XLFHandler handler = null;
if (editorPart != null && editorPart instanceof IXliffEditor) {
// xliff 文件已用 XLIFF 编辑器打开
IXliffEditor xliffEditor = (IXliffEditor) editorPart;
handler = xliffEditor.getXLFHandler();
handler.resetCache();
VTDGen vg = new VTDGen();
String path = ResourceUtils.iFileToOSPath(file);
if (vg.parseFile(path, true)) {
handler.getVnMap().put(path, vg.getNav());
xliffEditor.refresh();
}
}
}
}
});
}
};
try {
new ProgressMonitorDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell()).run(true, true, runnable);
} catch (InvocationTargetException e) {
logger.error(Messages.getString("pretranslation.PreTransUitls.logger1"), e);
} catch (InterruptedException e) {
logger.error(Messages.getString("pretranslation.PreTransUitls.logger1"), e);
}
}
} finally {
HsMultiCellEditorControl.activeSourceAndTargetCell(XLIFFEditorImplWithNatTable.getCurrent());
}
}
use of net.heartsome.cat.ts.core.file.XLFHandler in project translationstudio8 by heartsome.
the class JumpToNextHandler method execute.
public Object execute(ExecutionEvent event) throws ExecutionException {
IEditorPart editor = HandlerUtil.getActiveEditor(event);
if (editor instanceof XLIFFEditorImplWithNatTable) {
String jumpToNext = event.getParameter("JumpNextSegment");
if (jumpToNext == null) {
return null;
}
XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) editor;
int[] selectedRows = xliffEditor.getSelectedRows();
if (selectedRows.length < 1) {
return null;
}
Arrays.sort(selectedRows);
int lastSelectRow = selectedRows[selectedRows.length - 1];
XLFHandler handler = xliffEditor.getXLFHandler();
int nextRow = -1;
Shell shell = HandlerUtil.getActiveShell(event);
if (jumpToNext.equalsIgnoreCase("JumpNextNonTranslation")) {
// 下一未翻译文本段
nextRow = handler.getNextUntranslatedSegmentIndex(lastSelectRow);
if (nextRow == -1) {
MessageDialog.openInformation(shell, Messages.getString("handler.JumpToNextHandler.msgTitle"), Messages.getString("handler.JumpToNextHandler.msg1"));
return null;
}
} else if (jumpToNext.equalsIgnoreCase("JumpNextQuestion")) {
// 下一带疑问文本段
nextRow = handler.getNextQuestionSegmentIndex(lastSelectRow);
if (nextRow == -1) {
MessageDialog.openInformation(shell, Messages.getString("handler.JumpToNextHandler.msgTitle"), Messages.getString("handler.JumpToNextHandler.msg2"));
return null;
}
} else if (jumpToNext.equalsIgnoreCase("JumpNextNote")) {
// 下一带标注文本段
nextRow = handler.getNextNoteSegmentIndex(lastSelectRow);
if (nextRow == -1) {
MessageDialog.openInformation(shell, Messages.getString("handler.JumpToNextHandler.msgTitle"), Messages.getString("handler.JumpToNextHandler.msg3"));
return null;
}
}
xliffEditor.jumpToRow(nextRow);
}
return null;
}
use of net.heartsome.cat.ts.core.file.XLFHandler in project translationstudio8 by heartsome.
the class LockRepeatedSegmentHandler method lockInnerRepeatedSegment.
/**
* 锁定内部重复文本段
* @param iFile
* @param monitor
* @return ;
*/
private Map<String, int[]> lockInnerRepeatedSegment(List<IFile> iFileList, IProgressMonitor monitor, boolean checkTM) {
Map<String, int[]> repeatedMap = new HashMap<String, int[]>();
final XLFHandler handler = new XLFHandler();
Map<String, Integer> lockedSizeMap = new HashMap<String, Integer>();
monitor.beginTask(Messages.getString("translation.LockRepeatedSegmentHandler.task3"), iFileList.size() * 3);
List<IFile> removeiFileList = new ArrayList<IFile>();
for (final IFile iFile : iFileList) {
File file = iFile.getLocation().toFile();
try {
Map<String, Object> resultMap = handler.openFile(file);
if (resultMap == null || Constant.RETURNVALUE_RESULT_SUCCESSFUL != (Integer) resultMap.get(Constant.RETURNVALUE_RESULT)) {
// 打开文件失败。
Display.getDefault().syncExec(new Runnable() {
public void run() {
MessageDialog.openInformation(shell, Messages.getString("translation.LockRepeatedSegmentHandler.msgTitle"), MessageFormat.format(Messages.getString("translation.LockRepeatedSegmentHandler.msg2"), iFile.getLocation().toOSString()));
}
});
removeiFileList.add(iFile);
repeatedMap.put(file.getPath(), new int[] { 0, 0 });
}
} catch (Exception e) {
LOGGER.error("", e);
e.printStackTrace();
}
lockedSizeMap.put(iFile.getLocation().toOSString(), 0);
if (!monitorWork(monitor, 1)) {
return null;
}
}
Map<String, ArrayList<String>> languages = handler.getLanguages();
for (Entry<String, ArrayList<String>> entry : languages.entrySet()) {
String srcLanguage = entry.getKey();
for (String tgtLanguage : entry.getValue()) {
ArrayList<String> rowIds = handler.getRepeatedSegmentExceptFirstOne(srcLanguage, tgtLanguage);
// 将所有的RowId进行按文件名排序
Map<String, List<String>> lockedRowidsMap = RowIdUtil.groupRowIdByFileName(rowIds);
// 将锁定的文件本个数添加到map中
for (String rowId : rowIds) {
String fileLC = RowIdUtil.getFileNameByRowId(rowId);
lockedSizeMap.put(fileLC, lockedSizeMap.get(fileLC) + 1);
}
if (!monitorWork(monitor, iFileList.size())) {
isCancel = true;
return null;
}
lockTU(handler, lockedRowidsMap);
}
}
// 如果没有进行外部匹配,那么就必须获取每个文件的TU节点数量
for (IFile iFile : iFileList) {
if (removeiFileList.indexOf(iFile) >= 0) {
continue;
}
String iFileLc = iFile.getLocation().toOSString();
repeatedMap.put(iFileLc, new int[] { checkTM ? -1 : handler.countTransUnit(iFileLc), lockedSizeMap.get(iFileLc) });
if (!monitorWork(monitor, 1)) {
isCancel = true;
return null;
}
}
monitor.done();
return repeatedMap;
}
use of net.heartsome.cat.ts.core.file.XLFHandler in project translationstudio8 by heartsome.
the class MatchViewPart method reLoadMatches.
public void reLoadMatches(IXliffEditor editor, int rowIndex) {
// 修复 Bug #3064 编辑匹配--更换记忆库后再编辑原记忆库匹配,出现异常.刷新问题
// handler.getTransUnit(rowId);
TransUnitBean transUnit = editor.getRowTransUnitBean(rowIndex);
if (transUnit == null) {
return;
}
XLFHandler handler = editor.getXLFHandler();
if (handler == null) {
return;
}
IProject prj = null;
if (editor instanceof IEditorPart) {
IEditorPart p = (IEditorPart) editor;
FileEditorInput input = (FileEditorInput) p.getEditorInput();
prj = input.getFile().getProject();
}
if (prj == null) {
return;
}
String rowId = handler.getRowId(rowIndex);
TransUnitInfo2TranslationBean tuInfoBean = getTuInfoBean(transUnit, handler, rowId);
executeMatch(editor, rowId, transUnit, tuInfoBean, prj);
}
Aggregations