use of net.heartsome.cat.ts.core.file.XLFHandler in project translationstudio8 by heartsome.
the class LockRepeatedSegmentHandler method lockTMSegment.
private LockTMSegment lockTMSegment(final List<IFile> iFileList, boolean isLockTM100Segment, boolean isLockTM101Segment, IProgressMonitor monitor) {
SubProgressMonitor subMonitor = new SubProgressMonitor(monitor, iFileList.size(), SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK);
subMonitor.beginTask("", 10);
subMonitor.setTaskName(Messages.getString("translation.LockRepeatedSegmentHandler.task2"));
XLFHandler xlfHandler = null;
singleNattable = null;
Display.getDefault().syncExec(new Runnable() {
public void run() {
IEditorReference[] editorRefer = window.getActivePage().findEditors(new FileEditorInput(iFileList.get(0)), XLIFF_EDITOR_ID, IWorkbenchPage.MATCH_INPUT | IWorkbenchPage.MATCH_ID);
if (editorRefer.length > 0) {
singleNattable = ((XLIFFEditorImplWithNatTable) editorRefer[0].getEditor(true));
}
}
});
if (singleNattable != null) {
xlfHandler = singleNattable.getXLFHandler();
}
if (xlfHandler == null) {
xlfHandler = new XLFHandler();
for (final IFile iFile : iFileList) {
File file = iFile.getLocation().toFile();
try {
Map<String, Object> resultMap = xlfHandler.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()));
}
});
list.remove(iFile);
return null;
}
} catch (Exception e) {
LOGGER.error("", e);
e.printStackTrace();
}
if (!monitorWork(monitor, 1)) {
return null;
}
}
} else {
subMonitor.worked(1);
}
List<String> filesPath = ResourceUtils.IFilesToOsPath(iFileList);
LockTMSegment lts = new LockTMSegment(xlfHandler, tmMatcher, filesPath, curProject);
lts.setLockedContextMatch(isLockTM101Segment);
lts.setLockedFullMatch(isLockTM100Segment);
// 查记忆库并锁定,占剩下的 9/10。
SubProgressMonitor subSubMonitor = new SubProgressMonitor(subMonitor, 9, SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK);
if (!lts.executeTranslation(subSubMonitor)) {
isCancel = true;
subSubMonitor.done();
subMonitor.done();
return null;
}
subSubMonitor.done();
subMonitor.done();
if (singleNattable != null) {
Display.getDefault().syncExec(new Runnable() {
public void run() {
singleNattable.getTable().redraw();
}
});
}
Map<String, List<String>> needLockRowIdMap = lts.getNeedLockRowIdMap();
if (needLockRowIdMap.size() > 0) {
lockTU(xlfHandler, needLockRowIdMap);
}
return lts;
}
use of net.heartsome.cat.ts.core.file.XLFHandler in project translationstudio8 by heartsome.
the class LockRepeatedSegmentHandler method lockTMSegmentOFEditor.
/**
* 专门处理以 nattble 形式打开的文件
* @param iFileList
* @param isLockTM100Segment
* @param isLockTM101Segment
* @param monitor
* @return ;
*/
private LockTMSegment lockTMSegmentOFEditor(List<IFile> iFileList, boolean isLockTM100Segment, boolean isLockTM101Segment, IProgressMonitor monitor) {
XLFHandler xlfHandler = nattable.getXLFHandler();
SubProgressMonitor subMonitor = new SubProgressMonitor(monitor, iFileList.size(), SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK);
subMonitor.beginTask("", 10);
subMonitor.setTaskName(Messages.getString("translation.LockRepeatedSegmentHandler.task2"));
// 解析文件,占 1/10,这里是直接获取编辑器的XLFHandler,故不需解析
if (!monitorWork(subMonitor, 1)) {
return null;
}
List<String> filesPath = ResourceUtils.IFilesToOsPath(iFileList);
LockTMSegment lts = new LockTMSegment(xlfHandler, tmMatcher, filesPath, curProject);
lts.setLockedContextMatch(isLockTM101Segment);
lts.setLockedFullMatch(isLockTM100Segment);
// 查记忆库并锁定,占剩下的 9/10。
IProgressMonitor subSubMonitor = new SubProgressMonitor(monitor, 9, SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK);
if (!lts.executeTranslation(subSubMonitor)) {
subSubMonitor.done();
subMonitor.done();
isCancel = true;
return null;
}
subSubMonitor.done();
subMonitor.done();
if (nattable != null) {
Display.getDefault().syncExec(new Runnable() {
public void run() {
nattable.getTable().redraw();
}
});
}
Map<String, List<String>> needLockRowIdMap = lts.getNeedLockRowIdMap();
if (needLockRowIdMap.size() > 0) {
lockTU(xlfHandler, needLockRowIdMap);
}
return lts;
}
use of net.heartsome.cat.ts.core.file.XLFHandler in project translationstudio8 by heartsome.
the class NattableUtil method addSelectSegmentToTM.
/**
* 添加选中文本段到记忆库
* @param modelBean
* 数据库元数据
* @return boolean true : 完成入库 false 不完成入库
*/
public boolean addSelectSegmentToTM() {
List<String> selectedRowIds = xliffEditor.getSelectedRowIds();
if (selectedRowIds.size() == 0) {
return false;
}
final Map<String, List<String>> tmpGroup = RowIdUtil.groupRowIdByFileName(selectedRowIds);
boolean hasEmpty = false;
XLFHandler handler = xliffEditor.getXLFHandler();
for (Entry<String, List<String>> entry : tmpGroup.entrySet()) {
// 目标文本为空不添加到记忆库
List<String> rowIds = entry.getValue();
int size = rowIds.size();
handler.removeNullTgtContentRowId(rowIds);
if (rowIds.size() != size) {
hasEmpty = true;
}
handler.removeLockedRowIds(rowIds);
}
// 入库前进行品质检查 --robert
final AutomaticQATrigger auto = new AutomaticQATrigger(xliffEditor.getXLFHandler());
int i = 0;
for (Entry<String, List<String>> entry : tmpGroup.entrySet()) {
List<String> rowIdList = tmpGroup.get(entry.getKey());
for (Iterator<String> it = rowIdList.iterator(); it.hasNext(); ) {
String rowId = it.next();
String result = auto.beginAutoQa(true, rowId, i == 0 ? true : false);
if (result == null) {
return false;
}
if (result.length() > 1) {
boolean respons = MessageDialog.openConfirm(xliffEditor.getTable().getShell(), Messages.getString("utils.NattableUtil.msgTitle3"), result);
// 若选择ok,则继续操作
if (!respons) {
auto.bringQAResultViewerToTop();
it.remove();
selectedRowIds.remove(rowId);
}
}
i++;
}
}
auto.informQAEndFlag();
if (selectedRowIds.size() <= 0) {
return false;
}
String message = null;
if (hasEmpty) {
message = Messages.getString("utils.NattableUtil.msg1");
}
if (message != null) {
if (!MessageDialog.openConfirm(xliffEditor.getTable().getShell(), Messages.getString("utils.NattableUtil.msgTitle"), message)) {
return false;
}
}
final ArrayList<String> lstRowId = new ArrayList<String>();
final IProject project = ((FileEditorInput) (xliffEditor.getEditorInput())).getFile().getProject();
this.importer.setProject(project);
final int contextSize = importer.getContextSize();
// IRunnableWithProgress runnable = new IRunnableWithProgress() {
// public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
BusyIndicator.showWhile(xliffEditor.getSite().getShell().getDisplay(), new Runnable() {
public void run() {
// monitor.beginTask(Messages.getString("utils.NattableUtil.task5"), 2);
if (!CommonFunction.checkEdition("L")) {
if (!importer.checkImporter() && ProjectConfigerFactory.getProjectConfiger(project).getDefaultTMDb() != null) {
final boolean[] state = new boolean[] { true };
Display.getDefault().syncExec(new Runnable() {
public void run() {
state[0] = MessageDialog.openConfirm(Display.getDefault().getActiveShell(), Messages.getString("utils.NattableUtil.msgTitle2"), Messages.getString("utils.NattableUtil.msg.cantConnDefaultDb"));
}
});
if (!state[0]) {
return;
}
}
}
for (Entry<String, List<String>> entry : tmpGroup.entrySet()) {
List<String> rowIdList = tmpGroup.get(entry.getKey());
if (importer.checkImporter()) {
String systemUser = Activator.getDefault().getPreferenceStore().getString(IPreferenceConstants.SYSTEM_USER);
StringBuffer fileContent = xliffEditor.getXLFHandler().generateTMXFileContent(systemUser, rowIdList, xliffEditor.getSrcColumnName(), xliffEditor.getTgtColumnName(), /* new SubProgressMonitor(monitor, 1) */
null, contextSize, project);
// }
if (fileContent != null) {
int state = -1;
try {
state = importer.executeImport(fileContent.toString(), xliffEditor.getSrcColumnName(), /* monitor */
null);
} catch (ImportException e) {
final String msg = e.getMessage();
Display.getDefault().syncExec(new Runnable() {
public void run() {
MessageDialog.openInformation(Display.getDefault().getActiveShell(), Messages.getString("utils.NattableUtil.msgTitle"), msg);
}
});
return;
}
if (state == ITmImporter.IMPORT_STATE_FAILED) {
Display.getDefault().syncExec(new Runnable() {
public void run() {
MessageDialog.openInformation(xliffEditor.getTable().getShell(), Messages.getString("utils.NattableUtil.msgTitle"), Messages.getString("utils.NattableUtil.msg6"));
}
});
return;
} else if (state == ITmImporter.IMPORT_STATE_NODB) {
Display.getDefault().syncExec(new Runnable() {
public void run() {
MessageDialog.openInformation(xliffEditor.getTable().getShell(), Messages.getString("utils.NattableUtil.msgTitle"), Messages.getString("utils.NattableUtil.msg7"));
}
});
}
}
}
// Bug #2306:文本段添加不入库标记后不能改变为完成翻译状态
lstRowId.addAll(rowIdList);
}
Display.getDefault().asyncExec(new Runnable() {
public void run() {
changeTgtState(lstRowId, "translated");
// xliffEditor.updateStatusLine();
}
});
// monitor.done();
}
});
// }
return true;
}
use of net.heartsome.cat.ts.core.file.XLFHandler in project translationstudio8 by heartsome.
the class NattableUtil method approveTransUnits.
/**
* 批准或取消批准文本段
* @param selectedRowIds1
* 选中行的rowId集合
* @param approve
* true:批准;false:取消批准;
*/
public void approveTransUnits(boolean isJumpNext) {
List<String> selectedRowIds = xliffEditor.getSelectedRowIds();
if (selectedRowIds.size() == 0) {
return;
}
final Map<String, List<String>> tmpGroup = RowIdUtil.groupRowIdByFileName(selectedRowIds);
boolean hasEmpty = false;
XLFHandler handler = xliffEditor.getXLFHandler();
for (Entry<String, List<String>> entry : tmpGroup.entrySet()) {
// 目标文本为空不能执行批准,将要跳过
List<String> rowIds = entry.getValue();
int size = rowIds.size();
handler.removeNullTgtContentRowId(rowIds);
if (rowIds.size() != size) {
hasEmpty = true;
}
handler.removeLockedRowIds(rowIds);
}
// 入库前进行品质检查 --robert
int i = 0;
final AutomaticQATrigger auto = new AutomaticQATrigger(xliffEditor.getXLFHandler());
for (Entry<String, List<String>> entry : tmpGroup.entrySet()) {
List<String> rowIdList = tmpGroup.get(entry.getKey());
for (Iterator<String> it = rowIdList.iterator(); it.hasNext(); ) {
String rowId = it.next();
String result = auto.beginAutoQa(false, rowId, i == 0 ? true : false);
if (result == null) {
return;
}
if (result.length() > 1) {
boolean respons = MessageDialog.openConfirm(xliffEditor.getSite().getShell(), Messages.getString("translation.ApproveSegmentHandler.msgTitle"), result);
// 若选择ok,则继续操作
if (!respons) {
auto.bringQAResultViewerToTop();
it.remove();
selectedRowIds.remove(rowId);
}
}
i++;
}
}
auto.informQAEndFlag();
String message = null;
if (hasEmpty) {
message = Messages.getString("utils.NattableUtil.msg1");
}
if (message != null) {
if (!MessageDialog.openConfirm(xliffEditor.getTable().getShell(), Messages.getString("utils.NattableUtil.msgTitle"), message)) {
return;
}
}
if (selectedRowIds.size() == 0) {
return;
}
HsMultiActiveCellEditor.commit(true);
// 将选中的文本段添加记忆库,在生成TMX的过程中会过滤掉标记不添加到记忆库的文本段
final IProject project = ((FileEditorInput) (xliffEditor.getEditorInput())).getFile().getProject();
this.importer.setProject(project);
final int contextSize = importer.getContextSize();
BusyIndicator.showWhile(xliffEditor.getSite().getShell().getDisplay(), new Runnable() {
public void run() {
// monitor.beginTask(Messages.getString("utils.NattableUtil.task1"), 8);
if (!CommonFunction.checkEdition("L")) {
if (!importer.checkImporter() && ProjectConfigerFactory.getProjectConfiger(project).getDefaultTMDb() != null) {
final boolean[] state = new boolean[] { true };
Display.getDefault().syncExec(new Runnable() {
public void run() {
state[0] = MessageDialog.openConfirm(Display.getDefault().getActiveShell(), Messages.getString("utils.NattableUtil.msgTitle2"), Messages.getString("utils.NattableUtil.msg.cantConnDefaultDb"));
}
});
if (!state[0]) {
return;
}
}
}
final List<String> addToTmResultRowIds = new ArrayList<String>();
for (Entry<String, List<String>> entry : tmpGroup.entrySet()) {
List<String> rowIdList = tmpGroup.get(entry.getKey());
if (importer.checkImporter()) {
String systemUser = Activator.getDefault().getPreferenceStore().getString(IPreferenceConstants.SYSTEM_USER);
StringBuffer fileContent = xliffEditor.getXLFHandler().generateTMXFileContent(systemUser, rowIdList, xliffEditor.getSrcColumnName(), xliffEditor.getTgtColumnName(), /* new SubProgressMonitor(monitor, 3) */
null, contextSize, project);
// }
if (fileContent != null) {
int state = -1;
try {
state = importer.executeImport(fileContent.toString(), xliffEditor.getSrcColumnName(), /* monitor */
null);
} catch (ImportException e) {
final String msg = e.getMessage();
Display.getDefault().syncExec(new Runnable() {
public void run() {
MessageDialog.openInformation(Display.getDefault().getActiveShell(), Messages.getString("utils.NattableUtil.msgTitle"), msg);
}
});
return;
}
if (state == ITmImporter.IMPORT_STATE_FAILED) {
Display.getDefault().syncExec(new Runnable() {
public void run() {
MessageDialog.openInformation(Display.getDefault().getActiveShell(), Messages.getString("utils.NattableUtil.msgTitle"), Messages.getString("utils.NattableUtil.msg2"));
}
});
return;
} else if (state == ITmImporter.IMPORT_STATE_NODB) {
Display.getDefault().syncExec(new Runnable() {
public void run() {
MessageDialog.openInformation(Display.getCurrent().getActiveShell(), Messages.getString("utils.NattableUtil.msgTitle"), Messages.getString("utils.NattableUtil.msg3"));
}
});
}
}
}
addToTmResultRowIds.addAll(rowIdList);
}
// monitor.setTaskName(Messages.getString("utils.NattableUtil.task2"));
Display.getDefault().syncExec(new Runnable() {
public void run() {
// 修改文本段状态,目前没有取消批准的功能,所以直接传入true,即所有的操作都是批准
List<String> rowIds = xliffEditor.getXLFHandler().approveTransUnits(addToTmResultRowIds, true);
if (rowIds.size() > 0) {
String message;
if (addToTmResultRowIds != null && addToTmResultRowIds.size() == 1) {
message = Messages.getString("utils.NattableUtil.msg4");
} else {
message = MessageFormat.format(Messages.getString("utils.NattableUtil.msg5"), rowIds.size());
}
boolean res = MessageDialog.openQuestion(xliffEditor.getTable().getShell(), null, message);
if (res) {
xliffEditor.getXLFHandler().approveTransUnits(rowIds, true, false);
}
}
xliffEditor.updateStatusLine();
xliffEditor.getTable().redraw();
}
});
// monitor.worked(2);
// if (monitor.isCanceled()) {
// return;
// }
//
// // 批准时需要进行繁殖翻译
// // propagateTranslations(addToTmResultRowIds, new
// // SubProgressMonitor(monitor, 2));
// monitor.done();
}
});
// runnable);
if (isJumpNext) {
int[] selectedRows = xliffEditor.getSelectedRows();
Arrays.sort(selectedRows);
xliffEditor.jumpToRow(selectedRows[selectedRows.length - 1] + 1);
} else {
IViewPart viewPart = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView("net.heartsome.cat.ts.ui.translation.view.matchview");
int[] selected = xliffEditor.getSelectedRows();
if (viewPart != null && viewPart instanceof IMatchViewPart && selected.length != 0) {
((IMatchViewPart) viewPart).reLoadMatches(xliffEditor, selected[selected.length - 1]);
}
HsMultiCellEditorControl.activeSourceAndTargetCell(xliffEditor);
}
// } catch (InvocationTargetException e) {
// e.printStackTrace();
// } catch (InterruptedException e) {
// e.printStackTrace();
// }
}
use of net.heartsome.cat.ts.core.file.XLFHandler in project translationstudio8 by heartsome.
the class XlfEditor method getAllRowIds.
/**
* @return List<String> 当前文件中所有文本段的 RowID,合并、分割文本段后应重新获取 (每个 RowID 由 XLIFF 文件路径、源文件路径、trans-unit ID 组成)
*/
public List<String> getAllRowIds() {
WorkbenchContentsFinder finder = new WorkbenchContentsFinder();
IEditorPart activateEditor = finder.activeWorkbenchWindow().getActivePage().getActiveEditor();
IXliffEditor xliffEditor = (IXliffEditor) activateEditor;
XLFHandler handler = xliffEditor.getXLFHandler();
return handler.getAllRowIds();
}
Aggregations