Search in sources :

Example 1 with UpdateDataBean

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

the class XliffEditorDataProvider method setTgtValue.

protected void setTgtValue(int rowIndex, Object newValue) {
    UpdateDataBean bean = (UpdateDataBean) newValue;
    handler.changeTgtTextValue(handler.getRowId(rowIndex), bean.getText(), bean.getMatchType(), bean.getQuality());
}
Also used : UpdateDataBean(net.heartsome.cat.ts.ui.xliffeditor.nattable.UpdateDataBean)

Example 2 with UpdateDataBean

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

the class NattableUtil method propagateTranslations.

// /**
// * 获得记忆库更新策略
// * @return ;
// */
// public int getTmxImportStrategy() {
// IPreferenceStore ps = Activator.getDefault().getPreferenceStore();
// return ps.getInt(PreferenceConstants.TM_UPDATE);
// }
/**
	 * 繁殖翻译 robert
	 * @param rowIdsMap
	 * @param monitor
	 * @return
	 */
public IStatus propagateTranslations(Map<String, List<String>> rowIdsMap, IProgressMonitor monitor) {
    if (monitor == null) {
        monitor = new NullProgressMonitor();
    }
    IProgressMonitor subMonitor = new SubProgressMonitor(monitor, 9, SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK);
    subMonitor.beginTask(Messages.getString("utils.NattableUtil.task7"), rowIdsMap.keySet().size());
    Iterator<Entry<String, List<String>>> it = rowIdsMap.entrySet().iterator();
    final XLFHandler handler = xliffEditor.getXLFHandler();
    while (it.hasNext()) {
        Entry<String, List<String>> entry = it.next();
        // 这是源文本,也就是繁殖翻译中的父
        String rootRowId = entry.getKey();
        // 这是要被繁殖的所有rowIds,其源文与rootRowId的源文一致
        final List<String> rowIds = entry.getValue();
        // TransUnitBean tu = handler.getTransUnit(rootRowId);
        // String tgtContent = tu.getTgtContent();
        final String rootTgtPureText = handler.getTUPureTextByRowId(rootRowId, false);
        String rootSrcFullText = handler.getTUFullTextByRowId(rootRowId, true);
        String rootTgtFullText = handler.getTUFullTextByRowId(rootRowId, false);
        for (String rowId : rowIds) {
            String temp = rootTgtPureText;
            String srcFullText = handler.getTUFullTextByRowId(rowId, true);
            if (srcFullText.trim().equals(rootSrcFullText.trim())) {
                temp = rootTgtFullText;
            } else {
                temp = IntelligentTagPrcessor.intelligentAppendTag(srcFullText, rootTgtFullText);
            }
            handler.changeTgtTextValue(rowId, temp, null, null);
        }
        // 下面这是处理处于获得焦点状态的文本段。无法繁殖翻译的情况
        Display.getDefault().syncExec(new Runnable() {

            public void run() {
                int focusRowIndex = HsMultiActiveCellEditor.sourceRowIndex;
                if (focusRowIndex == -1) {
                    return;
                }
                if (!XLIFFEditorImplWithNatTable.getCurrent().isHorizontalLayout()) {
                    focusRowIndex = VerticalNatTableConfig.getRealRowIndex(focusRowIndex);
                }
                String focusRowId = handler.getRowId(focusRowIndex);
                if (rowIds.contains(focusRowId)) {
                    HsMultiActiveCellEditor.getTargetStyledEditor().setCanonicalValue(new UpdateDataBean(rootTgtPureText, null, null));
                }
            }
        });
        if (subMonitor.isCanceled()) {
            return Status.OK_STATUS;
        }
        subMonitor.worked(1);
    }
    subMonitor.done();
    return Status.OK_STATUS;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Entry(java.util.Map.Entry) List(java.util.List) ArrayList(java.util.ArrayList) UpdateDataBean(net.heartsome.cat.ts.ui.xliffeditor.nattable.UpdateDataBean) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) XLFHandler(net.heartsome.cat.ts.core.file.XLFHandler)

Example 3 with UpdateDataBean

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

the class XLIFFEditorImplWithNatTable method updateCellEditor.

/**
	 * 修改单元格编辑器中的文本。
	 * @param columnIndex
	 *            列索引
	 * @param newValue
	 *            新值
	 * @return ;
	 */
private boolean updateCellEditor(int columnIndex, String newValue, String matchType, String quality) {
    StyledTextCellEditor cellEditor = HsMultiActiveCellEditor.getFocusCellEditor();
    if (cellEditor == null) {
        return false;
    }
    // 如果当前的文本是锁定状态,不改变值
    String tgt = handler.getCaseTgtContent(handler.getRowId(cellEditor.getRowIndex()));
    if (null != tgt) {
        if (tgt.equals("no")) {
            return true;
        }
    }
    int rowIndex = cellEditor.getRowIndex();
    int activeCellEditorColumnIndex = cellEditor.getColumnIndex();
    if (rowIndex == -1) {
        return false;
    }
    if (activeCellEditorColumnIndex == -1) {
        return false;
    }
    if (!isHorizontalLayout) {
        // 垂直布局
        int[] selecteds = getSelectedRows();
        int seled = getSelectedRows()[selecteds.length - 1];
        if ((seled * 2) + 1 != rowIndex) {
            return false;
        }
    } else {
        if (activeCellEditorColumnIndex != columnIndex) {
            return false;
        }
    }
    /** burke 修改复制来源到目标中,当光标在src单元格中,点击复制来源到目标应该不起作用 修改代码 添加合并判断条件 !isHorizontalLayout */
    if (activeCellEditorColumnIndex == -1 || (activeCellEditorColumnIndex != columnIndex && !isHorizontalLayout)) {
        return false;
    }
    UpdateDataBean bean = new UpdateDataBean(newValue, matchType, quality);
    cellEditor.setCanonicalValue(bean);
    return true;
}
Also used : UpdateDataBean(net.heartsome.cat.ts.ui.xliffeditor.nattable.UpdateDataBean) Point(org.eclipse.swt.graphics.Point)

Example 4 with UpdateDataBean

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

the class XLIFFEditorImplWithNatTable method affterFuzzyMatchApplayTarget.

/**
	 * (non-Javadoc)
	 * @see net.heartsome.cat.ts.ui.editors.IXliffEditor#affterFuzzyMatchApplayTarget(int, String, String, String)
	 */
public void affterFuzzyMatchApplayTarget(int rowIndex, String targetContent, String matchType, String quality) {
    StyledTextCellEditor cellEditor = HsMultiActiveCellEditor.getTargetStyledEditor();
    if (cellEditor != null && cellEditor.getRowIndex() == rowIndex) {
        String currentText = cellEditor.getSegmentViewer().getText();
        if (currentText == null || currentText.trim().equals("")) {
            UpdateDataBean bean = new UpdateDataBean(targetContent, matchType, quality);
            cellEditor.setCanonicalValue(bean);
        }
    }
}
Also used : UpdateDataBean(net.heartsome.cat.ts.ui.xliffeditor.nattable.UpdateDataBean)

Example 5 with UpdateDataBean

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

the class StyledTextCellEditor method activateCell.

protected Control activateCell(final Composite parent, HsMultiCellEditor hsCellEditor) {
    this.hsCellEditor = hsCellEditor;
    StyledText text = createTextControl(parent);
    text.setBounds(hsCellEditor.getEditorBounds());
    // analyzeCellType(); // 分析单元格类型。
    this.cellType = hsCellEditor.getType();
    if (cellType == NatTableConstant.TARGET) {
        this.source = HsMultiActiveCellEditor.getSourceEditor().getOriginalCanonicalValue().toString();
        // 设置原文本,用来解析内部标记
        viewer.setSource(source);
    }
    // 判断“可编辑”状态;
    editableManager.judgeEditable();
    // If we have an initial value, then
    Object originalCanonicalValue = this.hsCellEditor.getOriginalCanonicalValue();
    if (originalCanonicalValue != null) {
        setCanonicalValue(new UpdateDataBean(originalCanonicalValue.toString(), null, null));
    } else {
        setCanonicalValue(new UpdateDataBean());
    }
    // 改变关闭状态标识
    close = false;
    xliffEditor.getTable().addDisposeListener(this);
    // text.forceFocus();
    // 初始化撤销/重做管理器,设置步长为 50。
    viewer.initUndoManager(50);
    // 绑定全局 Edit 菜单
    actionHandler.addTextViewer(viewer);
    text.addKeyListener(movedKeyListener);
    // 移除向上和向下键默认事件处理,将此部分实现放到upAndDownKeyListener监听中
    text.setKeyBinding(SWT.ARROW_DOWN, SWT.NULL);
    text.setKeyBinding(SWT.ARROW_UP, SWT.NULL);
    addMouselistener(text);
    return text;
}
Also used : StyledText(org.eclipse.swt.custom.StyledText) UpdateDataBean(net.heartsome.cat.ts.ui.xliffeditor.nattable.UpdateDataBean)

Aggregations

UpdateDataBean (net.heartsome.cat.ts.ui.xliffeditor.nattable.UpdateDataBean)7 AutoResizeCurrentRowsCommand (net.heartsome.cat.ts.ui.xliffeditor.nattable.handler.AutoResizeCurrentRowsCommand)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Entry (java.util.Map.Entry)1 XLFHandler (net.heartsome.cat.ts.core.file.XLFHandler)1 ISegmentViewer (net.heartsome.cat.ts.ui.innertag.ISegmentViewer)1 StyledTextCellEditor (net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.StyledTextCellEditor)1 CellVisualChangeEvent (net.sourceforge.nattable.layer.event.CellVisualChangeEvent)1 SelectCellCommand (net.sourceforge.nattable.selection.command.SelectCellCommand)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)1 StyledText (org.eclipse.swt.custom.StyledText)1 Point (org.eclipse.swt.graphics.Point)1