Search in sources :

Example 1 with NattableUtil

use of net.heartsome.cat.ts.ui.xliffeditor.nattable.utils.NattableUtil in project translationstudio8 by heartsome.

the class NotSendToTMHandler method execute.

public Object execute(ExecutionEvent event) throws ExecutionException {
    IEditorPart editor = HandlerUtil.getActiveEditor(event);
    if (editor instanceof XLIFFEditorImplWithNatTable) {
        XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) editor;
        List<String> selectedRowIds = xliffEditor.getSelectedRowIds();
        if (selectedRowIds != null && selectedRowIds.size() > 0) {
            boolean isSendtoTm = true;
            XLFHandler handler = xliffEditor.getXLFHandler();
            for (String rowId : selectedRowIds) {
                if (!handler.isSendToTM(rowId) && isSendtoTm) {
                    isSendtoTm = false;
                    break;
                }
            }
            NattableUtil util = NattableUtil.getInstance(xliffEditor);
            util.changeSendToTmState(selectedRowIds, isSendtoTm ? "yes" : "no");
        }
    }
    return null;
}
Also used : XLIFFEditorImplWithNatTable(net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable) NattableUtil(net.heartsome.cat.ts.ui.xliffeditor.nattable.utils.NattableUtil) IEditorPart(org.eclipse.ui.IEditorPart) XLFHandler(net.heartsome.cat.ts.core.file.XLFHandler)

Example 2 with NattableUtil

use of net.heartsome.cat.ts.ui.xliffeditor.nattable.utils.NattableUtil in project translationstudio8 by heartsome.

the class AddSegmentToTMHandler method execute.

public Object execute(ExecutionEvent event) throws ExecutionException {
    IEditorPart editor = HandlerUtil.getActiveEditor(event);
    if (!(editor instanceof XLIFFEditorImplWithNatTable)) {
        return null;
    }
    XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) editor;
    String addSegmentToTM = event.getParameter("addSegmentToTM");
    if (addSegmentToTM == null) {
        return null;
    }
    NattableUtil util = NattableUtil.getInstance(xliffEditor);
    HsMultiActiveCellEditor.commit(true);
    boolean state = util.addSelectSegmentToTM();
    if (!state) {
        return null;
    }
    // 刷新项目
    ResourceUtils.refreshCurentSelectProject();
    if (addSegmentToTM.equals("addToTMAndJumpNext")) {
        // 添加到记忆库并跳转到下一文本段
        int[] selectedRows = xliffEditor.getSelectedRows();
        if (selectedRows.length < 1) {
            return null;
        }
        Arrays.sort(selectedRows);
        int lastSelectedRow = selectedRows[selectedRows.length - 1];
        // 假如当前选择了第1,3行,则跳转到下一文本段时是跳转到第2行
        for (int rowNum = 0; rowNum < selectedRows.length - 1; rowNum++) {
            if (selectedRows[rowNum + 1] != (selectedRows[rowNum] + 1)) {
                lastSelectedRow = rowNum;
                break;
            }
        }
        XLFHandler handler = xliffEditor.getXLFHandler();
        int lastRow = handler.countEditableTransUnit() - 1;
        if (lastSelectedRow == lastRow) {
            lastSelectedRow = lastRow - 1;
        }
        xliffEditor.jumpToRow(lastSelectedRow + 1);
    } else if (addSegmentToTM.equals("addToTMAndJumpNextNotCompleteMatch")) {
        // 添加到记忆库并跳转到下一非完全匹配
        int[] selectedRows = xliffEditor.getSelectedRows();
        if (selectedRows.length < 1) {
            return null;
        }
        Arrays.sort(selectedRows);
        int lastSelectedRow = selectedRows[selectedRows.length - 1];
        // 假如当前选择了第1,3行,则跳转到下一非完全匹配文本段时要从第2行开始检查
        for (int rowNum = 0; rowNum < selectedRows.length - 1; rowNum++) {
            if (selectedRows[rowNum + 1] != (selectedRows[rowNum] + 1)) {
                lastSelectedRow = rowNum;
                break;
            }
        }
        XLFHandler handler = xliffEditor.getXLFHandler();
        int row = handler.getNextFuzzySegmentIndex(lastSelectedRow);
        if (row != -1) {
            xliffEditor.jumpToRow(row);
        } else {
            MessageDialog.openInformation(HandlerUtil.getActiveShell(event), Messages.getString("translation.AddSegmentToTMHandler.msgTitle"), Messages.getString("translation.AddSegmentToTMHandler.msg"));
        }
    } 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);
    }
    return null;
}
Also used : XLIFFEditorImplWithNatTable(net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable) IViewPart(org.eclipse.ui.IViewPart) NattableUtil(net.heartsome.cat.ts.ui.xliffeditor.nattable.utils.NattableUtil) IEditorPart(org.eclipse.ui.IEditorPart) XLFHandler(net.heartsome.cat.ts.core.file.XLFHandler) IMatchViewPart(net.heartsome.cat.ts.ui.view.IMatchViewPart)

Example 3 with NattableUtil

use of net.heartsome.cat.ts.ui.xliffeditor.nattable.utils.NattableUtil in project translationstudio8 by heartsome.

the class ApproveSegmentHandler method execute.

public Object execute(ExecutionEvent event) {
    IEditorPart editor = HandlerUtil.getActiveEditor(event);
    if (editor instanceof XLIFFEditorImplWithNatTable) {
        final XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) editor;
        List<String> rowIds = xliffEditor.getSelectedRowIds();
        if (rowIds.size() == 0) {
            return null;
        }
        String parameter = event.getParameter("approveSegment");
        if (parameter != null) {
            HsMultiActiveCellEditor.commit(true);
            NattableUtil util = NattableUtil.getInstance(xliffEditor);
            // 执行批准
            util.approveTransUnits(parameter.equalsIgnoreCase("approveAndJumpNext"));
        }
    }
    return null;
}
Also used : XLIFFEditorImplWithNatTable(net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable) NattableUtil(net.heartsome.cat.ts.ui.xliffeditor.nattable.utils.NattableUtil) IEditorPart(org.eclipse.ui.IEditorPart)

Example 4 with NattableUtil

use of net.heartsome.cat.ts.ui.xliffeditor.nattable.utils.NattableUtil in project translationstudio8 by heartsome.

the class DraftSegmentHandler method execute.

public Object execute(ExecutionEvent event) throws ExecutionException {
    IEditorPart editor = HandlerUtil.getActiveEditor(event);
    if (editor instanceof XLIFFEditorImplWithNatTable) {
        XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) editor;
        NattableUtil util = NattableUtil.getInstance(xliffEditor);
        List<String> selectedRowIds = util.getRowIdsNoEmptyTranslate(false);
        if (selectedRowIds != null && selectedRowIds.size() > 0) {
            util.changeTgtState(selectedRowIds, "new");
        }
    }
    return null;
}
Also used : XLIFFEditorImplWithNatTable(net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable) NattableUtil(net.heartsome.cat.ts.ui.xliffeditor.nattable.utils.NattableUtil) IEditorPart(org.eclipse.ui.IEditorPart)

Example 5 with NattableUtil

use of net.heartsome.cat.ts.ui.xliffeditor.nattable.utils.NattableUtil in project translationstudio8 by heartsome.

the class LockSegmentHandler method execute.

public Object execute(ExecutionEvent event) throws ExecutionException {
    // 这是之前的实现方式,这是锁定文本段。锁定全部文本段,锁定可编辑文本段的共同 handler,--robert 2012-05-02
    // String lockSegment = event.getParameter("lockSegment");
    // if (lockSegment == null) {
    // return null;
    // }
    // State state = event.getCommand().getState(RegistryToggleState.STATE_ID);
    // boolean isSelect = (Boolean) (state.getValue());
    // state.setValue(!isSelect);
    // IEditorPart editor = HandlerUtil.getActiveEditor(event);
    // if (editor instanceof XLIFFEditorImplWithNatTable) {
    // XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) editor;
    //
    // // 批准可编辑文本段时要初始化 rowIds ,批准所有文本段则不需要
    // if (lockSegment.equals("lockDuplicateSegment")) {
    // // TODO 解决如何高效获取重复文本段后再做
    //
    // } else {
    // ArrayList<String> rowIds = null;
    // if (lockSegment.equals("lockEditableSegment")) {
    // rowIds = xliffEditor.getXLFHandler().getRowIds();
    // } else if (lockSegment.equals("lockAllSegment")) {
    // rowIds = null;
    // }
    // NattableUtil util = new NattableUtil(xliffEditor);
    // util.lockTransUnits(rowIds, !isSelect);
    // // 改变单元格编辑器模式为“只读”
    // util.changeCellEditorMode(rowIds, null);
    // // TODO 入库
    //
    // }
    //
    // }
    IEditorPart editor = HandlerUtil.getActiveEditor(event);
    if (editor instanceof XLIFFEditorImplWithNatTable) {
        XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) editor;
        XLFHandler handler = xliffEditor.getXLFHandler();
        ArrayList<String> rowIds = (ArrayList<String>) xliffEditor.getSelectedRowIds();
        ArrayList<String> needLockRowIds = new ArrayList<String>();
        // 先判断所有的选择文本段的是否锁定状态
        for (String rowId : rowIds) {
            if (!handler.isLocked(rowId)) {
                needLockRowIds.add(rowId);
            }
        }
        NattableUtil util = NattableUtil.getInstance(xliffEditor);
        // 如果都是锁定状态的,那么把它们都变成未锁定
        if (needLockRowIds.size() <= 0) {
            util.lockTransUnits(rowIds, false);
        } else {
            util.lockTransUnits(needLockRowIds, true);
        // 改变单元格编辑器模式为“只读”
        // util.changeCellEditorMode(rowIds, null);
        }
        HsMultiActiveCellEditor.refrushCellsEditAbility();
    }
    return null;
}
Also used : XLIFFEditorImplWithNatTable(net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable) NattableUtil(net.heartsome.cat.ts.ui.xliffeditor.nattable.utils.NattableUtil) ArrayList(java.util.ArrayList) IEditorPart(org.eclipse.ui.IEditorPart) XLFHandler(net.heartsome.cat.ts.core.file.XLFHandler)

Aggregations

XLIFFEditorImplWithNatTable (net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable)8 NattableUtil (net.heartsome.cat.ts.ui.xliffeditor.nattable.utils.NattableUtil)8 IEditorPart (org.eclipse.ui.IEditorPart)8 XLFHandler (net.heartsome.cat.ts.core.file.XLFHandler)5 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 IMatchViewPart (net.heartsome.cat.ts.ui.view.IMatchViewPart)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 ProgressMonitorDialog (org.eclipse.jface.dialogs.ProgressMonitorDialog)1 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)1 IViewPart (org.eclipse.ui.IViewPart)1 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)1