Search in sources :

Example 1 with ISegmentViewer

use of net.heartsome.cat.ts.ui.innertag.ISegmentViewer in project translationstudio8 by heartsome.

the class AbstractInsertTagHandler method execute.

public Object execute(ExecutionEvent event) throws ExecutionException {
    this.event = event;
    IEditorPart editor = HandlerUtil.getActiveEditor(event);
    if (!(editor instanceof XLIFFEditorImplWithNatTable)) {
        // 不是针对 XLIFFEditorImplWithNatTable 编辑器中的操作,则退出
        return null;
    }
    cellEditor = HsMultiActiveCellEditor.getFocusCellEditor();
    if (cellEditor == null) {
        return null;
    }
    //		cellEditor = (StyledTextCellEditor) iCellEditor;
    if (!cellEditor.isEditable()) {
        // 显示不可编辑提示信息。
        cellEditor.showUneditableMessage();
        // 不可编辑,则退出
        return null;
    }
    ISegmentViewer segmentViewer = cellEditor.getSegmentViewer();
    // 插入位置
    int caretOffset = segmentViewer.getTextWidget().getCaretOffset();
    if (caretOffset < 0) {
        // 文本框已经关闭,则退出
        return null;
    }
    // source 内部标记中的最大索引
    sourceMaxTagIndex = segmentViewer.getSourceMaxTagIndex();
    if (sourceMaxTagIndex <= 0) {
        // source 无内部标记。
        return null;
    }
    int num = getTagNum();
    if (num < 0 || num > sourceMaxTagIndex) {
        return null;
    }
    cellEditor.getSegmentViewer().insertInnerTag(num, caretOffset);
    return null;
}
Also used : XLIFFEditorImplWithNatTable(net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable) ISegmentViewer(net.heartsome.cat.ts.ui.innertag.ISegmentViewer) IEditorPart(org.eclipse.ui.IEditorPart)

Example 2 with ISegmentViewer

use of net.heartsome.cat.ts.ui.innertag.ISegmentViewer in project translationstudio8 by heartsome.

the class UpdateDataOperation method refreshNatTable.

/**
	 * 更新 NatTable 的 UI
	 * @param value
	 *            单元格保存的值
	 * @param move
	 *            是否移动单元格到指定区域;
	 */
private IStatus refreshNatTable(Object value, boolean move) {
    if (table == null || table.isDisposed()) {
        return Status.CANCEL_STATUS;
    }
    int rowIndex = command.getRowPosition();
    int columnIndex = command.getColumnPosition();
    int columnPosition = viewportLayer.getColumnPositionByIndex(columnIndex);
    int rowPosition = viewportLayer.getRowPositionByIndex(rowIndex);
    // 实质上 DataLayer 层的 index 和 position 是一致的,此方法可以对范围判断
    if (rowIndex == -1 || columnIndex == -1) {
        return Status.CANCEL_STATUS;
    }
    // 修改值并刷新 UI。
    dataLayer.getDataProvider().setDataValue(columnIndex, rowIndex, value);
    dataLayer.fireLayerEvent(new CellVisualChangeEvent(dataLayer, columnPosition, rowPosition));
    // 修改行在当前一屏显示的几行中的相对位置
    int currentRow = rowPosition + 1;
    table.doCommand(new AutoResizeCurrentRowsCommand(table, new int[] { currentRow }, table.getConfigRegistry()));
    int selectedRow = XLIFFEditorImplWithNatTable.getCurrent().getSelectedRows()[0];
    if (value instanceof UpdateDataBean & rowIndex == selectedRow) {
        UpdateDataBean bean = (UpdateDataBean) value;
        StyledTextCellEditor sourceCellEditor = HsMultiActiveCellEditor.getSourceStyledEditor();
        StyledTextCellEditor targetCellEditor = HsMultiActiveCellEditor.getTargetStyledEditor();
        if (sourceCellEditor != null && sourceCellEditor.getRowIndex() == rowIndex && sourceCellEditor.getColumnIndex() == columnIndex) {
            ISegmentViewer segviewer = sourceCellEditor.getSegmentViewer();
            if (segviewer != null) {
                segviewer.setText(bean.getText());
            }
        } else if (targetCellEditor != null && targetCellEditor.getRowIndex() == rowIndex && targetCellEditor.getColumnIndex() == columnIndex) {
            ISegmentViewer segviewer = targetCellEditor.getSegmentViewer();
            if (segviewer != null) {
                segviewer.setText(bean.getText());
            }
        }
    }
    // 先记录下可见区域的范围
    int originRowPosition = viewportLayer.getOriginRowPosition();
    // 总行数
    int rowCount = viewportLayer.getRowCount();
    int row = LayerUtil.convertRowPosition(dataLayer, rowPosition, viewportLayer);
    if (move) {
        // 定位到屏幕第三行的位置
        if (rowPosition < originRowPosition || rowPosition > originRowPosition + rowCount) {
            HsMultiActiveCellEditor.commit(true);
            viewportLayer.doCommand(new SelectCellCommand(viewportLayer, columnPosition, row, false, false));
            HsMultiCellEditorControl.activeSourceAndTargetCell(XLIFFEditorImplWithNatTable.getCurrent());
        } else {
            XLIFFEditorImplWithNatTable.getCurrent().jumpToRow(rowIndex);
        }
    }
    return Status.OK_STATUS;
}
Also used : AutoResizeCurrentRowsCommand(net.heartsome.cat.ts.ui.xliffeditor.nattable.handler.AutoResizeCurrentRowsCommand) SelectCellCommand(net.sourceforge.nattable.selection.command.SelectCellCommand) ISegmentViewer(net.heartsome.cat.ts.ui.innertag.ISegmentViewer) UpdateDataBean(net.heartsome.cat.ts.ui.xliffeditor.nattable.UpdateDataBean) StyledTextCellEditor(net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.StyledTextCellEditor) CellVisualChangeEvent(net.sourceforge.nattable.layer.event.CellVisualChangeEvent)

Aggregations

ISegmentViewer (net.heartsome.cat.ts.ui.innertag.ISegmentViewer)2 UpdateDataBean (net.heartsome.cat.ts.ui.xliffeditor.nattable.UpdateDataBean)1 StyledTextCellEditor (net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.StyledTextCellEditor)1 XLIFFEditorImplWithNatTable (net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable)1 AutoResizeCurrentRowsCommand (net.heartsome.cat.ts.ui.xliffeditor.nattable.handler.AutoResizeCurrentRowsCommand)1 CellVisualChangeEvent (net.sourceforge.nattable.layer.event.CellVisualChangeEvent)1 SelectCellCommand (net.sourceforge.nattable.selection.command.SelectCellCommand)1 IEditorPart (org.eclipse.ui.IEditorPart)1