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);
}
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;
}
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);
}
}
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();
}
}
}
}
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);
}
}
Aggregations