use of net.heartsome.cat.ts.ui.xliffeditor.nattable.search.coordinate.CellRegion in project translationstudio8 by heartsome.
the class FindReplaceDialog method doReplace.
/**
* 替换 ;
*/
private void doReplace() {
CellRegion activeCellRegion = ActiveCellRegion.getActiveCellRegion();
if (activeCellRegion == null) {
return;
}
StyledTextCellEditor cellEditor = HsMultiActiveCellEditor.getTargetStyledEditor();
if (cellEditor != null) {
StyledText text = cellEditor.getSegmentViewer().getTextWidget();
String sleText = text.getSelectionText();
String findStr = cmbFind.getText();
if (XliffEditorParameter.getInstance().isShowNonpirnttingCharacter()) {
findStr = findStr.replaceAll("\\n", Constants.LINE_SEPARATOR_CHARACTER + "\n");
findStr = findStr.replaceAll("\\t", Constants.TAB_CHARACTER + "");
findStr = findStr.replaceAll(" ", Constants.SPACE_CHARACTER + "");
}
if (sleText != null && sleText.toLowerCase().equals(findStr.toLowerCase())) {
Point p = text.getSelection();
text.replaceTextRange(p.x, p.y - p.x, cmbReplace.getText());
}
}
}
use of net.heartsome.cat.ts.ui.xliffeditor.nattable.search.coordinate.CellRegion in project translationstudio8 by heartsome.
the class FindReplaceDialog method doFindNext.
/**
* 查找下一个 ;
* @return
*/
private boolean doFindNext() {
XLIFFEditorImplWithNatTable editor = XLIFFEditorImplWithNatTable.getCurrent();
if (editor == null) {
return false;
}
int[] selectedRows = editor.getSelectedRows();
int startingRowPosition;
if (selectedRows.length > 0) {
Arrays.sort(selectedRows);
if (forwardButton.getSelection()) {
// 从当前选中行中最大的行开始找。
startingRowPosition = selectedRows[selectedRows.length - 1];
} else {
// 从当前选中行中最大的行开始找。
startingRowPosition = selectedRows[0];
}
if (!editor.isHorizontalLayout()) {
startingRowPosition *= VerticalNatTableConfig.ROW_SPAN;
if (!sourceButton.getSelection()) {
startingRowPosition++;
}
}
int startOffset;
CellRegion cellRegion = ActiveCellRegion.getActiveCellRegion();
if (cellRegion == null || cellRegion.getPositionCoordinate().getRowPosition() != startingRowPosition) {
// 起始行不一致
if (forwardButton.getSelection()) {
startOffset = 0;
} else {
startOffset = -1;
}
} else {
PositionCoordinate coordinate = cellRegion.getPositionCoordinate();
// 得到上次查找的列
int columnIndex = coordinate.getLayer().getColumnIndexByPosition(coordinate.getColumnPosition());
if (columnIndex != (sourceButton.getSelection() ? editor.getSrcColumnIndex() : editor.getTgtColumnIndex())) {
// 如果所查找的列改变了,赋为初始值
if (forwardButton.getSelection()) {
startOffset = 0;
} else {
startOffset = -1;
}
} else {
if (forwardButton.getSelection()) {
startOffset = cellRegion.getRegion().getOffset() + cellRegion.getRegion().getLength();
} else {
startOffset = cellRegion.getRegion().getOffset() - 1;
if (startOffset == -1) {
// 解决在垂直布局时,选择向后查找在查找到某一行后会返回到最后一行继续查找的问题。
if (editor.isHorizontalLayout()) {
startingRowPosition--;
} else {
startingRowPosition -= 2;
}
}
}
}
}
cellRegion = find(startingRowPosition, startOffset);
replaceButton.setEnabled(!sourceButton.getSelection() && cellRegion != null);
if (cellRegion == null) {
refreshMsgAndTable();
}
return cellRegion != null;
} else {
return doFind();
}
}
use of net.heartsome.cat.ts.ui.xliffeditor.nattable.search.coordinate.CellRegion in project translationstudio8 by heartsome.
the class FindReplaceDialog method doReplaceAll.
/**
* 替换全部 ;
*/
private void doReplaceAll() {
XLIFFEditorImplWithNatTable editor = XLIFFEditorImplWithNatTable.getCurrent();
if (editor == null) {
return;
}
CellRegion cellRegion = null;
if (editor.isHorizontalLayout()) {
cellRegion = find(0, 0);
} else {
cellRegion = find(1, 0);
}
if (cellRegion == null) {
// 无查找结果
return;
}
boolean forward = forwardButton.getSelection();
if (!forward) {
forwardButton.setSelection(true);
}
int firstRowPosition = cellRegion.getPositionCoordinate().getRowPosition();
HashMap<String, String> segments = new HashMap<String, String>();
int count = 0;
String findStr = cmbFind.getText();
String replaceStr = cmbReplace.getText();
do {
PositionCoordinate coordinate = cellRegion.getPositionCoordinate();
int rowPosition = coordinate.rowPosition;
int columnPosition = coordinate.columnPosition;
int rowIndex = coordinate.getLayer().getRowIndexByPosition(rowPosition);
if (!editor.isHorizontalLayout()) {
rowIndex = rowIndex / VerticalNatTableConfig.ROW_SPAN;
}
// 判断锁定
TransUnitBean transUnit = editor.getRowTransUnitBean(rowIndex);
String translate = transUnit.getTuProps().get("translate");
if (translate != null && "no".equalsIgnoreCase(translate)) {
rowPosition++;
cellRegion = find(rowPosition, 0);
continue;
}
String cellValue = (String) coordinate.getLayer().getDataValueByPosition(columnPosition, rowPosition);
StringBuffer cellValueBf = new StringBuffer(cellValue);
int start = cellValue.toUpperCase().indexOf(findStr.toUpperCase());
while (start != -1) {
cellValueBf.replace(start, start + findStr.length(), replaceStr);
start = cellValueBf.indexOf(findStr, start);
count++;
}
segments.put(editor.getXLFHandler().getRowId(rowIndex), cellValueBf.toString());
rowPosition++;
if (!editor.isHorizontalLayout()) {
rowPosition++;
}
cellRegion = find(rowPosition, 0);
} while (cellRegion.getPositionCoordinate().getRowPosition() != firstRowPosition);
if (!forward) {
forwardButton.setSelection(false);
backwardButton.setSelection(true);
}
int columnIndex = 0;
if (sourceButton.getSelection()) {
columnIndex = editor.getSrcColumnIndex();
} else {
columnIndex = editor.getTgtColumnIndex();
}
try {
editor.updateSegments(segments, columnIndex, null, null);
} catch (ExecutionException e) {
LOGGER.error(Messages.getString("dialog.FindReplaceDialog.logger1"), e);
}
String msg = Messages.getString("dialog.FindReplaceDialog.status3");
statusLabel.setText(MessageFormat.format(msg, count));
ActiveCellRegion.setActiveCellRegion(null);
}
use of net.heartsome.cat.ts.ui.xliffeditor.nattable.search.coordinate.CellRegion in project translationstudio8 by heartsome.
the class CellDisplayValueSearchUtil method findCell.
static CellRegion findCell(final ILayer layer, final IConfigRegistry configRegistry, final PositionCoordinate[] cellsToSearch, final Object valueToMatch, final ICellSearchStrategy cellSearchStrategy) {
final List<PositionCoordinate> cellCoordinates = Arrays.asList(cellsToSearch);
// Find cell
CellRegion targetCoordinate = null;
String stringValue = valueToMatch.toString();
final IDisplayConverter displayConverter = configRegistry.getConfigAttribute(CellConfigAttributes.DISPLAY_CONVERTER, DisplayMode.NORMAL, XLIFFEditorImplWithNatTable.SOURCE_EDIT_CELL_LABEL);
for (int cellIndex = 0; cellIndex < cellCoordinates.size(); cellIndex++) {
final PositionCoordinate cellCoordinate = cellCoordinates.get(cellIndex);
final int columnPosition = cellCoordinate.columnPosition;
final int rowPosition = cellCoordinate.rowPosition;
// Convert cell's data
if (displayConverter instanceof TagDisplayConverter) {
LayerCell cell = new LayerCell(cellCoordinate.getLayer(), cellCoordinate.getColumnPosition(), cellCoordinate.getRowPosition());
((TagDisplayConverter) displayConverter).setCell(cell);
}
final Object dataValue = displayConverter.canonicalToDisplayValue(layer.getDataValueByPosition(columnPosition, rowPosition));
// Compare with valueToMatch
if (dataValue instanceof String) {
String dataValueString = dataValue.toString();
IRegion region;
if ((region = cellSearchStrategy.executeSearch(stringValue, dataValueString)) != null) {
targetCoordinate = new CellRegion(cellCoordinate, region);
break;
}
((DefaultCellSearchStrategy) cellSearchStrategy).setStartOffset(-1);
}
}
return targetCoordinate;
}
use of net.heartsome.cat.ts.ui.xliffeditor.nattable.search.coordinate.CellRegion in project translationstudio8 by heartsome.
the class FindReplaceDialog method doFind.
private boolean doFind() {
CellRegion cellRegion;
XLIFFEditorImplWithNatTable editor = XLIFFEditorImplWithNatTable.getCurrent();
if (editor == null) {
return false;
}
if (forwardButton.getSelection()) {
if (editor.isHorizontalLayout()) {
cellRegion = find(0, 0);
} else {
// 解决在垂直布局查找 Source 时,如果 Source 没有匹配而 Target 有匹配,会找到 Target 中的匹配文本
if (sourceButton.getSelection()) {
cellRegion = find(0, 0);
} else {
cellRegion = find(1, 0);
}
}
} else {
NatTable natTable = editor.getTable();
int sourceRowPosition = natTable.getRowCount() - 1;
int row = LayerUtil.getLowerLayerRowPosition(natTable, sourceRowPosition, SelectionLayer.class);
if (!editor.isHorizontalLayout()) {
row *= VerticalNatTableConfig.ROW_SPAN;
if (!sourceButton.getSelection()) {
row++;
}
}
cellRegion = find(row, -1);
}
replaceButton.setEnabled(!sourceButton.getSelection() && cellRegion != null);
if (cellRegion == null) {
refreshMsgAndTable();
}
return cellRegion != null;
}
Aggregations