Search in sources :

Example 6 with ViewportLayer

use of net.sourceforge.nattable.viewport.ViewportLayer in project translationstudio8 by heartsome.

the class XLIFFEditorImplWithNatTable method jumpToRow.

/**
	 * 跳转到指定行的文本段
	 * @param rowPosition
	 *            行号,从0开始 ;
	 */
public void jumpToRow(int rowPosition) {
    if (rowPosition < 0) {
        return;
    }
    int[] selectedRows = getSelectedRows();
    if (selectedRows.length == 1 && selectedRows[0] == rowPosition) {
        // 如果已经选中此行
        return;
    }
    // TODO 已在 target 内容修改的时候判断并将 state 属性值做修改,此处理论上无需再做处理。
    // updateCurrentSegmentTranslateProp(); // 若当前目标文本段内容不为空,则自动将其 state 属性值设为“translated”
    int maxRowNum = handler.countEditableTransUnit() - 1;
    rowPosition = rowPosition > maxRowNum ? maxRowNum : rowPosition;
    if (!isHorizontalLayout) {
        // 处理垂直布局下的行号
        rowPosition = rowPosition * VerticalNatTableConfig.ROW_SPAN;
    }
    ViewportLayer viewportLayer = bodyLayer.getViewportLayer();
    // 先记录下可见区域的范围
    HsMultiActiveCellEditor.commit(true);
    viewportLayer.doCommand(new SelectCellCommand(bodyLayer.getSelectionLayer(), getTgtColumnIndex(), rowPosition, false, false));
    HsMultiCellEditorControl.activeSourceAndTargetCell(this);
}
Also used : SelectCellCommand(net.sourceforge.nattable.selection.command.SelectCellCommand) HorizontalViewportLayer(net.heartsome.cat.ts.ui.xliffeditor.nattable.layer.HorizontalViewportLayer) ViewportLayer(net.sourceforge.nattable.viewport.ViewportLayer) VerticalViewportLayer(net.heartsome.cat.ts.ui.xliffeditor.nattable.layer.VerticalViewportLayer) Point(org.eclipse.swt.graphics.Point)

Example 7 with ViewportLayer

use of net.sourceforge.nattable.viewport.ViewportLayer in project translationstudio8 by heartsome.

the class LayerUtil method getUpperLayerRowPosition.

public static <T extends ILayer> int getUpperLayerRowPosition(NatTable table, int sourceRowPosition, Class<T> sourceLayerClass) {
    ViewportLayer viewportLayer = getLayer(table, ViewportLayer.class);
    int originRowPosition = viewportLayer.getOriginRowPosition();
    T t = getLayer(table, sourceLayerClass);
    sourceRowPosition = convertRowPosition(t, sourceRowPosition, viewportLayer);
    sourceRowPosition += originRowPosition + 1;
    return sourceRowPosition;
}
Also used : ViewportLayer(net.sourceforge.nattable.viewport.ViewportLayer)

Example 8 with ViewportLayer

use of net.sourceforge.nattable.viewport.ViewportLayer in project translationstudio8 by heartsome.

the class KeyEditAction method run.

public void run(NatTable natTable, KeyEvent event) {
    Character character = null;
    if (LetterOrDigitKeyEventMatcher.isLetterOrDigit(event.character) || event.character == ' ') {
        character = Character.valueOf(event.character);
    }
    if (character != null) {
        int[] selectedRowIndexs = XLIFFEditorImplWithNatTable.getCurrent().getSelectedRows();
        if (selectedRowIndexs.length == 0) {
            return;
        }
        Arrays.sort(selectedRowIndexs);
        int rowIndex = selectedRowIndexs[selectedRowIndexs.length - 1];
        ViewportLayer viewportLayer = LayerUtil.getLayer(natTable, ViewportLayer.class);
        SelectionLayer selectionLayer = LayerUtil.getLayer(natTable, SelectionLayer.class);
        // 先记录下可见区域的范围
        int originRowPosition = viewportLayer.getOriginRowPosition();
        // 总行数
        int rowCount = viewportLayer.getRowCount();
        XLIFFEditorImplWithNatTable editor = XLIFFEditorImplWithNatTable.getCurrent();
        if (!editor.isHorizontalLayout()) {
            rowIndex = rowIndex * 2;
        }
        if (rowIndex < originRowPosition || rowIndex > originRowPosition + rowCount || HsMultiActiveCellEditor.getTargetEditor() == null) {
            HsMultiActiveCellEditor.commit(true);
            PositionCoordinate p = selectionLayer.getLastSelectedCellPosition();
            if (!editor.isHorizontalLayout()) {
                natTable.doCommand(new SelectCellCommand(selectionLayer, editor.getTgtColumnIndex(), p.rowPosition / 2 * 2, false, false));
            } else {
                if (p.columnPosition != editor.getSrcColumnIndex() && p.columnPosition != editor.getTgtColumnIndex()) {
                    p.columnPosition = editor.getTgtColumnIndex();
                }
                natTable.doCommand(new SelectCellCommand(selectionLayer, p.columnPosition, p.rowPosition, false, false));
            }
            HsMultiCellEditorControl.activeSourceAndTargetCell(editor);
            StyledTextCellEditor cellEditor = HsMultiActiveCellEditor.getFocusCellEditor();
            if (cellEditor != null && cellEditor.getCellType().equals(NatTableConstant.TARGET)) {
                cellEditor.insertCanonicalValue(character);
            }
        }
    } else if ((event.character == SWT.CR) && event.stateMask == SWT.NONE) {
        HsMultiActiveCellEditor.commit(true);
        SelectionLayer selectionLayer = LayerUtil.getLayer(natTable, SelectionLayer.class);
        PositionCoordinate p = selectionLayer.getLastSelectedCellPosition();
        XLIFFEditorImplWithNatTable editor = XLIFFEditorImplWithNatTable.getCurrent();
        if (!editor.isHorizontalLayout()) {
            natTable.doCommand(new SelectCellCommand(selectionLayer, editor.getTgtColumnIndex(), p.rowPosition / 2 * 2, false, false));
        } else {
            if (p.columnPosition != editor.getSrcColumnIndex() && p.columnPosition != editor.getTgtColumnIndex()) {
                p.columnPosition = editor.getTgtColumnIndex();
            }
            natTable.doCommand(new SelectCellCommand(selectionLayer, p.columnPosition, p.rowPosition, false, false));
        }
        HsMultiCellEditorControl.activeSourceAndTargetCell(editor);
    }
}
Also used : XLIFFEditorImplWithNatTable(net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable) SelectionLayer(net.sourceforge.nattable.selection.SelectionLayer) SelectCellCommand(net.sourceforge.nattable.selection.command.SelectCellCommand) PositionCoordinate(net.sourceforge.nattable.coordinate.PositionCoordinate) ViewportLayer(net.sourceforge.nattable.viewport.ViewportLayer) StyledTextCellEditor(net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.StyledTextCellEditor)

Example 9 with ViewportLayer

use of net.sourceforge.nattable.viewport.ViewportLayer in project translationstudio8 by heartsome.

the class HsMultiActiveCellEditor method recalculateCellsBounds.

public static void recalculateCellsBounds() {
    if (parent == null) {
        return;
    }
    ViewportLayer vLayer = LayerUtil.getLayer(parent, ViewportLayer.class);
    if (vLayer == null) {
        return;
    }
    StyledTextCellEditor fc = getFocusCellEditor();
    if (sourceEditor != null && sourceEditor.isValid()) {
        int rowPosition = vLayer.getRowPositionByIndex(sourceEditor.getRowIndex());
        int columnPosition = vLayer.getColumnPositionByIndex(sourceEditor.getColumnIndex());
        rowPosition += 1;
        if (rowPosition < 1) {
            return;
        }
        LayerCell cell = parent.getCellByPosition(columnPosition, rowPosition);
        if (cell == null) {
            return;
        }
        Rectangle cellBounds = cell.getBounds();
        if (cellBounds != null) {
            Rectangle adjustedCellBounds = parent.getLayerPainter().adjustCellBounds(cellBounds);
            sourceEditor.setEditorBounds(adjustedCellBounds, true);
            sourceEditor.setColumnPosition(columnPosition);
            sourceEditor.setRowPosition(rowPosition);
            if (fc == sourceEditor.getCellEditor()) {
                sourceEditor.forceFocus();
            }
        }
    }
    if (targetEditor != null && targetEditor.isValid()) {
        int rowPosition = vLayer.getRowPositionByIndex(targetEditor.getRowIndex());
        int columnPosition = vLayer.getColumnPositionByIndex(targetEditor.getColumnIndex());
        rowPosition += 1;
        if (rowPosition < 1) {
            return;
        }
        LayerCell cell = parent.getCellByPosition(columnPosition, rowPosition);
        if (cell == null) {
            return;
        }
        Rectangle cellBounds = cell.getBounds();
        if (cellBounds != null) {
            Rectangle adjustedCellBounds = parent.getLayerPainter().adjustCellBounds(cellBounds);
            targetEditor.setEditorBounds(adjustedCellBounds, true);
            targetEditor.setColumnPosition(columnPosition);
            targetEditor.setRowPosition(rowPosition);
            if (fc == targetEditor.getCellEditor()) {
                targetEditor.forceFocus();
            }
        }
    }
}
Also used : LayerCell(net.sourceforge.nattable.layer.cell.LayerCell) Rectangle(org.eclipse.swt.graphics.Rectangle) ViewportLayer(net.sourceforge.nattable.viewport.ViewportLayer)

Example 10 with ViewportLayer

use of net.sourceforge.nattable.viewport.ViewportLayer in project translationstudio8 by heartsome.

the class HsMultiCellEditorControl method activeSourceAndTargetCell.

public static void activeSourceAndTargetCell(XLIFFEditorImplWithNatTable xliffEditor) {
    if (xliffEditor == null) {
        return;
    }
    int[] selectedRowIndexs = xliffEditor.getSelectedRows();
    if (selectedRowIndexs.length == 0) {
        return;
    }
    Arrays.sort(selectedRowIndexs);
    int rowIndex = selectedRowIndexs[selectedRowIndexs.length - 1];
    if (!xliffEditor.isHorizontalLayout()) {
        // source index
        rowIndex = rowIndex * 2;
    }
    NatTable natTable = xliffEditor.getTable();
    IConfigRegistry configRegistry = natTable.getConfigRegistry();
    ViewportLayer vLayer = LayerUtil.getLayer(natTable, ViewportLayer.class);
    int rowPosition = vLayer.getRowPositionByIndex(rowIndex);
    rowPosition += 1;
    if (rowPosition < 1) {
        return;
    }
    int columnIndex = xliffEditor.getSrcColumnIndex();
    HsMultiCellEditor srcCellEditor = activeCell(vLayer, xliffEditor, configRegistry, columnIndex, rowIndex, rowPosition, NatTableConstant.SOURCE);
    if (srcCellEditor == null) {
        return;
    }
    if (!xliffEditor.isHorizontalLayout()) {
        // target
        rowIndex = rowIndex + 1;
        rowPosition = vLayer.getRowPositionByIndex(rowIndex);
        rowPosition += 1;
        if (rowPosition < 1) {
            return;
        }
    }
    columnIndex = xliffEditor.getTgtColumnIndex();
    HsMultiCellEditor tgtCellEditor = activeCell(vLayer, xliffEditor, configRegistry, columnIndex, rowIndex, rowPosition, NatTableConstant.TARGET);
    if (tgtCellEditor == null) {
        return;
    }
    HsMultiActiveCellEditor.activateCellEditors(srcCellEditor, tgtCellEditor, natTable);
    // 目标文本段一进入焦点就进行一次拼写检查 robert 2013-01-22
    // UNDO 这里错误单词提示并没有修改颜色。
    String tgtLang = xliffEditor.getTgtColumnName();
    spellTrigger = RealTimeSpellCheckTrigger.getInstance();
    if (spellTrigger != null && spellTrigger.checkSpellAvailable(tgtLang)) {
        tgtTextFirstRealTimeSpellCheck(tgtLang, tgtCellEditor);
        tgtTextRealTimeSpellCheck(tgtLang, tgtCellEditor);
    }
    List<String> terms = xliffEditor.getTermsCache().get(selectedRowIndexs[0]);
    if (terms != null && terms.size() > 0) {
        srcCellEditor.highlightedTerms(terms);
    }
}
Also used : IConfigRegistry(net.sourceforge.nattable.config.IConfigRegistry) NatTable(net.sourceforge.nattable.NatTable) ViewportLayer(net.sourceforge.nattable.viewport.ViewportLayer)

Aggregations

ViewportLayer (net.sourceforge.nattable.viewport.ViewportLayer)10 HorizontalViewportLayer (net.heartsome.cat.ts.ui.xliffeditor.nattable.layer.HorizontalViewportLayer)3 VerticalViewportLayer (net.heartsome.cat.ts.ui.xliffeditor.nattable.layer.VerticalViewportLayer)3 PositionCoordinate (net.sourceforge.nattable.coordinate.PositionCoordinate)3 SelectCellCommand (net.sourceforge.nattable.selection.command.SelectCellCommand)3 StyledTextCellEditor (net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.StyledTextCellEditor)2 XLIFFEditorImplWithNatTable (net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable)2 SelectionLayer (net.sourceforge.nattable.selection.SelectionLayer)2 Point (org.eclipse.swt.graphics.Point)2 MessageFormat (java.text.MessageFormat)1 FindReplaceEvent (net.heartsome.cat.ts.ui.xliffeditor.nattable.search.event.FindReplaceEvent)1 DefaultCellSearchStrategy (net.heartsome.cat.ts.ui.xliffeditor.nattable.search.strategy.DefaultCellSearchStrategy)1 ICellSearchStrategy (net.heartsome.cat.ts.ui.xliffeditor.nattable.search.strategy.ICellSearchStrategy)1 ISearchStrategy (net.heartsome.cat.ts.ui.xliffeditor.nattable.search.strategy.ISearchStrategy)1 NatTable (net.sourceforge.nattable.NatTable)1 IConfigRegistry (net.sourceforge.nattable.config.IConfigRegistry)1 ClientAreaResizeCommand (net.sourceforge.nattable.grid.command.ClientAreaResizeCommand)1 IUniqueIndexLayer (net.sourceforge.nattable.layer.IUniqueIndexLayer)1 LayerCell (net.sourceforge.nattable.layer.cell.LayerCell)1 IRegion (org.eclipse.jface.text.IRegion)1