use of net.heartsome.cat.ts.core.file.XLFHandler in project translationstudio8 by heartsome.
the class ShowLastSegmentHandler method execute.
public Object execute(ExecutionEvent event) throws ExecutionException {
IEditorPart editor = HandlerUtil.getActiveEditor(event);
if (!(editor instanceof XLIFFEditorImplWithNatTable)) {
return null;
}
XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) editor;
XLFHandler handler = xliffEditor.getXLFHandler();
int lastRow = handler.countEditableTransUnit() - 1;
xliffEditor.jumpToRow(lastRow);
return null;
}
use of net.heartsome.cat.ts.core.file.XLFHandler in project translationstudio8 by heartsome.
the class ShowNextFuzzyHandler method execute.
public Object execute(ExecutionEvent event) throws ExecutionException {
IEditorPart editor = HandlerUtil.getActiveEditor(event);
if (!(editor instanceof XLIFFEditorImplWithNatTable)) {
return null;
}
XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) editor;
int[] selectedRows = xliffEditor.getSelectedRows();
if (selectedRows.length < 1) {
return null;
}
Arrays.sort(selectedRows);
int lastSelectedRow = selectedRows[selectedRows.length - 1];
XLFHandler handler = xliffEditor.getXLFHandler();
int row = handler.getNextFuzzySegmentIndex(lastSelectedRow);
if (row != -1) {
xliffEditor.jumpToRow(row);
} else {
IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
MessageDialog.openWarning(window.getShell(), "", "不存在下一模糊匹配文本段。");
}
return null;
}
use of net.heartsome.cat.ts.core.file.XLFHandler in project translationstudio8 by heartsome.
the class ShowPreviousNoteHandler method execute.
public Object execute(ExecutionEvent event) throws ExecutionException {
IEditorPart editor = HandlerUtil.getActiveEditor(event);
if (!(editor instanceof XLIFFEditorImplWithNatTable)) {
return null;
}
XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) editor;
int[] selectedRows = xliffEditor.getSelectedRows();
if (selectedRows.length < 1) {
return null;
}
Arrays.sort(selectedRows);
int firstSelectedRow = selectedRows[0];
XLFHandler handler = xliffEditor.getXLFHandler();
int row = handler.getPreviousNoteSegmentIndex(firstSelectedRow);
if (row != -1) {
xliffEditor.jumpToRow(row);
} else {
IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
MessageDialog.openWarning(window.getShell(), "", "不存在上一个带批注的文本段。");
}
return null;
}
use of net.heartsome.cat.ts.core.file.XLFHandler in project translationstudio8 by heartsome.
the class SetSplitPointByWordNumHandler method execute.
public Object execute(ExecutionEvent event) throws ExecutionException {
final String navegatorID = "net.heartsome.cat.common.ui.navigator.view";
final String XLIFF_EDITOR_ID = "net.heartsome.cat.ts.ui.xliffeditor.nattable.editor";
IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
final Shell shell = window.getShell();
IFile selectFile = null;
XLIFFEditorImplWithNatTable xliffEditor = null;
IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
// 如果是导航视图,那么就获取导航视图中选中的文件
if (activePart instanceof IViewPart) {
if (navegatorID.equals(activePart.getSite().getId())) {
IViewPart viewPart = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView(navegatorID);
ISelection currentSelection = (StructuredSelection) viewPart.getSite().getSelectionProvider().getSelection();
if (currentSelection != null && !currentSelection.isEmpty() && currentSelection instanceof IStructuredSelection) {
IStructuredSelection structuredSelection = (IStructuredSelection) currentSelection;
Object object = structuredSelection.getFirstElement();
if (object instanceof IFile) {
selectFile = (IFile) object;
String fileExtension = selectFile.getFileExtension();
// 如果后缀名不是xlf,那么就退出操作
if (fileExtension == null || !CommonFunction.validXlfExtension(fileExtension)) {
MessageDialog.openInformation(shell, Messages.getString("handler.SplitXliffHandler.msgTitle"), Messages.getString("handler.SplitXliffHandler.msg1"));
return null;
}
FileEditorInput fileInput = new FileEditorInput(selectFile);
IEditorReference[] editorRefer = window.getActivePage().findEditors(fileInput, XLIFF_EDITOR_ID, IWorkbenchPage.MATCH_INPUT | IWorkbenchPage.MATCH_ID);
IEditorPart editorPart = null;
if (editorRefer.length >= 1) {
editorPart = editorRefer[0].getEditor(true);
xliffEditor = (XLIFFEditorImplWithNatTable) editorPart;
if (window.getActivePage().getActiveEditor() != editorPart) {
window.getActivePage().activate(editorPart);
}
} else {
try {
xliffEditor = (XLIFFEditorImplWithNatTable) window.getActivePage().openEditor(fileInput, XLIFF_EDITOR_ID, true, IWorkbenchPage.MATCH_INPUT | IWorkbenchPage.MATCH_ID);
} catch (PartInitException e) {
LOGGER.error("", e);
e.printStackTrace();
}
}
} else {
MessageDialog.openInformation(shell, Messages.getString("all.dialog.info"), Messages.getString("SetSplitPointHandler.cantSetPointToNotXlf"));
return null;
}
}
}
} else if (activePart instanceof IEditorPart) {
if (XLIFF_EDITOR_ID.equals(activePart.getSite().getId())) {
xliffEditor = (XLIFFEditorImplWithNatTable) activePart;
if (xliffEditor.isMultiFile()) {
MessageDialog.openInformation(shell, Messages.getString("all.dialog.info"), Messages.getString("SetSplitPointByWOrdNumHandler.cantSetForMulty"));
return null;
}
selectFile = ((FileEditorInput) xliffEditor.getEditorInput()).getFile();
}
}
if (selectFile == null) {
return null;
}
XLIFFEditorImplWithNatTable nattable = XLIFFEditorImplWithNatTable.getCurrent();
final XLFHandler xlfHander = nattable.getXLFHandler();
Map<String, Integer> rowWordNumMap = xlfHander.getSplitFileInfoForPointSetting(selectFile.getLocation().toOSString());
if (rowWordNumMap.size() <= 1) {
MessageDialog.openInformation(shell, Messages.getString("all.dialog.info"), Messages.getString("SetSplitPointHandler.cantSetPointForTuNum"));
return null;
}
List<String> splitPointList = nattable.getSplitXliffPoints();
// 排序之前先过滤重复
HashSet<String> set = new HashSet<String>(splitPointList);
splitPointList.clear();
splitPointList.addAll(set);
// 先对 splitPointList 进行排序
Collections.sort(splitPointList, new Comparator<String>() {
public int compare(String rowId1, String rowId2) {
int rowIndex1 = xlfHander.getRowIndex(rowId1);
int rowIndex2 = xlfHander.getRowIndex(rowId2);
return rowIndex1 > rowIndex2 ? 1 : -1;
}
});
List<SegPointBean> segPointList = new ArrayList<SegPointBean>();
if (splitPointList.size() > 0) {
int segWordNum = 0;
int i = 0;
String pointRowId = splitPointList.get(i);
for (Entry<String, Integer> entry : rowWordNumMap.entrySet()) {
segWordNum += entry.getValue();
if (pointRowId.equals(entry.getKey())) {
segPointList.add(new SegPointBean(segWordNum));
segWordNum = 0;
i++;
if (i < splitPointList.size()) {
pointRowId = splitPointList.get(i);
}
}
}
if (splitPointList.size() + 1 > segPointList.size()) {
segPointList.add(new SegPointBean(segWordNum));
}
}
SetSplitPointByWordNumDialog dialog = new SetSplitPointByWordNumDialog(shell, xlfHander, selectFile.getLocation().toOSString(), rowWordNumMap, segPointList);
int openResult = dialog.open();
if (openResult == IDialogConstants.OK_ID) {
// 如果选择确定,那么在界面上生成分割点
nattable.getSplitXliffPoints().clear();
for (SegPointBean bean : segPointList) {
if (bean.getRowId() != null && !bean.getRowId().isEmpty()) {
nattable.getSplitXliffPoints().add(bean.getRowId());
}
}
nattable.refresh();
}
return null;
}
use of net.heartsome.cat.ts.core.file.XLFHandler in project translationstudio8 by heartsome.
the class ExecuteFuzzyTranslationHandler method execute.
public Object execute(ExecutionEvent event) throws ExecutionException {
IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event);
IEditorPart editor = window.getActivePage().getActiveEditor();
if (!XLIFF_EDITOR_ID.equals(editor.getSite().getId())) {
return null;
}
final XLIFFEditorImplWithNatTable nattable = (XLIFFEditorImplWithNatTable) editor;
final NattableUtil util = NattableUtil.getInstance(nattable);
IRunnableWithProgress runnable = new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
// monitor.beginTask(Messages.getString("translation.ExecuteFuzzyTranslationHandler.task1"), 8);
// 首选获取有译文的trans-unit
monitor.beginTask(Messages.getString("translation.ExecuteFuzzyTranslationHandler.task2"), 10);
XLFHandler handler = nattable.getXLFHandler();
Map<String, List<String>> rowIdMap = new HashMap<String, List<String>>();
rowIdMap = RepeatRowSearcher.getRepeateRowsForFuzzy(handler);
monitor.worked(1);
util.propagateTranslations(rowIdMap, monitor);
monitor.done();
}
};
try {
new ProgressMonitorDialog(nattable.getEditorSite().getShell()).run(true, true, runnable);
} catch (InvocationTargetException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
nattable.autoResize();
return null;
}
Aggregations