Search in sources :

Example 46 with XLFHandler

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;
}
Also used : XLIFFEditorImplWithNatTable(net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable) IEditorPart(org.eclipse.ui.IEditorPart) XLFHandler(net.heartsome.cat.ts.core.file.XLFHandler)

Example 47 with XLFHandler

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;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) XLIFFEditorImplWithNatTable(net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable) IEditorPart(org.eclipse.ui.IEditorPart) XLFHandler(net.heartsome.cat.ts.core.file.XLFHandler)

Example 48 with XLFHandler

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;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) XLIFFEditorImplWithNatTable(net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable) IEditorPart(org.eclipse.ui.IEditorPart) XLFHandler(net.heartsome.cat.ts.core.file.XLFHandler)

Example 49 with XLFHandler

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;
}
Also used : XLIFFEditorImplWithNatTable(net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable) IViewPart(org.eclipse.ui.IViewPart) IFile(org.eclipse.core.resources.IFile) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ArrayList(java.util.ArrayList) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Shell(org.eclipse.swt.widgets.Shell) IEditorReference(org.eclipse.ui.IEditorReference) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) ISelection(org.eclipse.jface.viewers.ISelection) PartInitException(org.eclipse.ui.PartInitException) SetSplitPointByWordNumDialog(net.heartsome.cat.ts.handlexlf.dialog.SetSplitPointByWordNumDialog) HashSet(java.util.HashSet) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) SegPointBean(net.heartsome.cat.ts.core.bean.SegPointBean) IEditorPart(org.eclipse.ui.IEditorPart) FileEditorInput(org.eclipse.ui.part.FileEditorInput) XLFHandler(net.heartsome.cat.ts.core.file.XLFHandler)

Example 50 with XLFHandler

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;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) XLIFFEditorImplWithNatTable(net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable) HashMap(java.util.HashMap) NattableUtil(net.heartsome.cat.ts.ui.xliffeditor.nattable.utils.NattableUtil) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) IEditorPart(org.eclipse.ui.IEditorPart) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) List(java.util.List) XLFHandler(net.heartsome.cat.ts.core.file.XLFHandler)

Aggregations

XLFHandler (net.heartsome.cat.ts.core.file.XLFHandler)63 IEditorPart (org.eclipse.ui.IEditorPart)45 XLIFFEditorImplWithNatTable (net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable)36 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)24 ArrayList (java.util.ArrayList)21 IFile (org.eclipse.core.resources.IFile)16 FileEditorInput (org.eclipse.ui.part.FileEditorInput)16 List (java.util.List)14 IProject (org.eclipse.core.resources.IProject)13 ExecutionException (org.eclipse.core.commands.ExecutionException)11 InvocationTargetException (java.lang.reflect.InvocationTargetException)10 CoreException (org.eclipse.core.runtime.CoreException)9 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)8 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)8 Shell (org.eclipse.swt.widgets.Shell)8 IViewPart (org.eclipse.ui.IViewPart)8 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)8 IXliffEditor (net.heartsome.cat.ts.ui.editors.IXliffEditor)7 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)6 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)6