Search in sources :

Example 1 with IMatchViewPart

use of net.heartsome.cat.ts.ui.view.IMatchViewPart in project translationstudio8 by heartsome.

the class AcceptMatch1 method execute.

/** (non-Javadoc)
	 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
	 */
public Object execute(ExecutionEvent event) throws ExecutionException {
    IViewPart viewPart = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView("net.heartsome.cat.ts.ui.translation.view.matchview");
    if (viewPart != null && viewPart instanceof IMatchViewPart) {
        IMatchViewPart matchView = (IMatchViewPart) viewPart;
        matchView.acceptMatchByIndex(0);
    }
    return null;
}
Also used : IViewPart(org.eclipse.ui.IViewPart) IMatchViewPart(net.heartsome.cat.ts.ui.view.IMatchViewPart)

Example 2 with IMatchViewPart

use of net.heartsome.cat.ts.ui.view.IMatchViewPart in project translationstudio8 by heartsome.

the class ColorConfigLoader method loadColor.

private void loadColor() {
    Device device = Activator.getDefault().getWorkbench().getDisplay();
    if (pfStore == null) {
        pfStore = Activator.getDefault().getPreferenceStore();
        pfStore.addPropertyChangeListener(this);
    }
    colorConfigBean.release();
    colorConfigBean.setPtColor(getColor(device, IColorPreferenceConstant.PT_COLOR));
    colorConfigBean.setQtColor(getColor(device, IColorPreferenceConstant.QT_COLOR));
    colorConfigBean.setMtColor(getColor(device, IColorPreferenceConstant.MT_COLOR));
    colorConfigBean.setTm101Color(getColor(device, IColorPreferenceConstant.TM_MATCH101_COLOR));
    colorConfigBean.setTm100Color(getColor(device, IColorPreferenceConstant.TM_MATCH100_COLOR));
    colorConfigBean.setTm90Color(getColor(device, IColorPreferenceConstant.TM_MATCH90_COLOR));
    colorConfigBean.setTm80Color(getColor(device, IColorPreferenceConstant.TM_MATCH80_COLOR));
    colorConfigBean.setTm70Color(getColor(device, IColorPreferenceConstant.TM_MATCH70_COLOR));
    colorConfigBean.setTm0Color(getColor(device, IColorPreferenceConstant.TM_MATCH0_COLOR));
    colorConfigBean.setSrcDiffFgColor(getColor(device, IColorPreferenceConstant.DIFFERENCE_FG_COLOR));
    colorConfigBean.setSrcDiffBgColor(getColor(device, IColorPreferenceConstant.DIFFERENCE_BG_COLOR));
    colorConfigBean.setTagFgColor(getColor(device, IColorPreferenceConstant.TAG_FG_COLOR));
    colorConfigBean.setTagBgColor(getColor(device, IColorPreferenceConstant.TAG_BG_COLOR));
    colorConfigBean.setWrongTagColor(getColor(device, IColorPreferenceConstant.WRONG_TAG_COLOR));
    colorConfigBean.setErrorWordColor(getColor(device, IColorPreferenceConstant.WRONG_TAG_COLOR));
    String strColor = colorConfigBean.toString();
    IXliffEditor xliffEditor = null;
    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (window != null) {
        IWorkbenchPage page = window.getActivePage();
        if (page != null) {
            IEditorPart editor = page.getActiveEditor();
            if (editor != null && editor instanceof IXliffEditor) {
                xliffEditor = (IXliffEditor) editor;
            }
        }
    }
    if (strCurColor != null && !strCurColor.equals(strColor)) {
        // 更改颜色设置后刷新界面
        if (xliffEditor != null) {
            xliffEditor.autoResize();
            xliffEditor.refresh();
        }
        if (window != null) {
            IWorkbenchPage page = window.getActivePage();
            if (page != null) {
                IViewPart viewPart = page.findView("net.heartsome.cat.ts.ui.translation.view.matchview");
                if (viewPart != null) {
                    IMatchViewPart part = (IMatchViewPart) viewPart;
                    part.refreshTable();
                }
            }
        }
        strCurColor = strColor;
    }
    Color highlightedTermColor = colorConfigBean.getHighlightedTermColor();
    RGB newRgb = StringConverter.asRGB(pfStore.getString(IColorPreferenceConstant.HIGHLIGHTED_TERM_COLOR));
    if (highlightedTermColor == null || highlightedTermColor.isDisposed()) {
        highlightedTermColor = new Color(device, newRgb);
    } else if (!highlightedTermColor.getRGB().equals(newRgb)) {
        highlightedTermColor.dispose();
        highlightedTermColor = new Color(device, newRgb);
        // had changed
        if (xliffEditor != null) {
            // 刷新
            xliffEditor.highlightedTerms(0, null);
        }
    }
    colorConfigBean.setHighlightedTermColor(highlightedTermColor);
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IViewPart(org.eclipse.ui.IViewPart) Device(org.eclipse.swt.graphics.Device) Color(org.eclipse.swt.graphics.Color) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IEditorPart(org.eclipse.ui.IEditorPart) RGB(org.eclipse.swt.graphics.RGB) IXliffEditor(net.heartsome.cat.ts.ui.editors.IXliffEditor) IMatchViewPart(net.heartsome.cat.ts.ui.view.IMatchViewPart)

Example 3 with IMatchViewPart

use of net.heartsome.cat.ts.ui.view.IMatchViewPart 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 4 with IMatchViewPart

use of net.heartsome.cat.ts.ui.view.IMatchViewPart 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();
// }
}
Also used : IViewPart(org.eclipse.ui.IViewPart) IProject(org.eclipse.core.resources.IProject) ImportException(net.heartsome.cat.common.core.exception.ImportException) AutomaticQATrigger(net.heartsome.cat.ts.ui.xliffeditor.nattable.qa.AutomaticQATrigger) Entry(java.util.Map.Entry) List(java.util.List) ArrayList(java.util.ArrayList) XLFHandler(net.heartsome.cat.ts.core.file.XLFHandler) IMatchViewPart(net.heartsome.cat.ts.ui.view.IMatchViewPart)

Example 5 with IMatchViewPart

use of net.heartsome.cat.ts.ui.view.IMatchViewPart in project translationstudio8 by heartsome.

the class AcceptMatch2 method execute.

/** (non-Javadoc)
	 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
	 */
public Object execute(ExecutionEvent event) throws ExecutionException {
    IViewPart viewPart = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView("net.heartsome.cat.ts.ui.translation.view.matchview");
    if (viewPart != null && viewPart instanceof IMatchViewPart) {
        IMatchViewPart matchView = (IMatchViewPart) viewPart;
        matchView.acceptMatchByIndex(1);
    }
    return null;
}
Also used : IViewPart(org.eclipse.ui.IViewPart) IMatchViewPart(net.heartsome.cat.ts.ui.view.IMatchViewPart)

Aggregations

IMatchViewPart (net.heartsome.cat.ts.ui.view.IMatchViewPart)6 IViewPart (org.eclipse.ui.IViewPart)6 XLFHandler (net.heartsome.cat.ts.core.file.XLFHandler)2 IEditorPart (org.eclipse.ui.IEditorPart)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Entry (java.util.Map.Entry)1 ImportException (net.heartsome.cat.common.core.exception.ImportException)1 IXliffEditor (net.heartsome.cat.ts.ui.editors.IXliffEditor)1 XLIFFEditorImplWithNatTable (net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable)1 AutomaticQATrigger (net.heartsome.cat.ts.ui.xliffeditor.nattable.qa.AutomaticQATrigger)1 NattableUtil (net.heartsome.cat.ts.ui.xliffeditor.nattable.utils.NattableUtil)1 IProject (org.eclipse.core.resources.IProject)1 Color (org.eclipse.swt.graphics.Color)1 Device (org.eclipse.swt.graphics.Device)1 RGB (org.eclipse.swt.graphics.RGB)1 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)1 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)1