use of net.sourceforge.nattable.coordinate.PositionCoordinate in project translationstudio8 by heartsome.
the class XLIFFEditorImplWithNatTable method updateStatusLine.
/**
* 在状态栏上显示被编辑文件的信息。
*/
public void updateStatusLine() {
if (table == null || table.isDisposed()) {
return;
}
SelectionLayer selectionLayer = bodyLayer.getSelectionLayer();
ViewportLayer viewportLayer = bodyLayer.getViewportLayer();
PositionCoordinate cellPosition = selectionLayer.getLastSelectedCellPosition();
if (cellPosition == null) {
return;
}
// int order = LayerUtil.convertRowPosition(selectionLayer, cellPosition.rowPosition, viewportLayer);
// Bug #2317:选中文本段后排序,不会刷新状态栏中的序号
int[] selectedRowPostions = selectionLayer.getFullySelectedRowPositions();
if (selectedRowPostions.length <= 0) {
return;
}
// 刷新选中行的术语,使其排序后保持高亮显示
// if (!isHorizontalLayout()) {
// int rowPosition = selectedRowPostions[0];
// rowPosition *= VerticalNatTableConfig.ROW_SPAN;
// cellPosition.set(rowPosition, cellPosition.getColumnPosition());
// } else {
// cellPosition.set(selectedRowPostions[0], cellPosition.getColumnPosition());
// }
// if (!FindReplaceDialog.isOpen) {
// CellRegion cellRegion = new CellRegion(cellPosition, new Region(0, selectionLayer.getWidth()));
// ActiveCellRegion.setActiveCellRegion(cellRegion);
// }
int order = LayerUtil.convertRowPosition(selectionLayer, selectedRowPostions[0], viewportLayer);
order += viewportLayer.getOriginRowPosition() + 1;
// 垂直布局时order需要进行两行递增的处理
if (!isHorizontalLayout) {
order = (int) Math.ceil(order / 2.0);
}
MessageFormat messageFormat = null;
if (order > 0) {
/* 一个Xliff文件,可能有多个File节点,这里使用File结点的original属性 */
/* 当前文件:{0} | 顺序号:{1} | 可见文本段数:{2} | 文本段总数:{3} | 当前用户名" */
messageFormat = new MessageFormat(Messages.getString("editor.XLIFFEditorImplWithNatTable.messageFormat1"));
} else {
messageFormat = new MessageFormat(Messages.getString("editor.XLIFFEditorImplWithNatTable.messageFormat2"));
}
String fileName = "";
// 添加 Project Name
IEditorInput editorInput = getEditorInput();
String filePath = "";
if (isMultiFile()) {
if (getSelectedRowIds().size() > 0) {
filePath = RowIdUtil.getFileNameByRowId(getSelectedRowIds().get(0));
fileName = ResourceUtils.toWorkspacePath(filePath);
}
} else {
fileName = getEditorInput().getName();
if (editorInput instanceof FileEditorInput) {
FileEditorInput fileEditorInput = (FileEditorInput) editorInput;
filePath = fileEditorInput.getFile().getLocation().toOSString();
fileName = fileEditorInput.getFile().getFullPath().toOSString();
}
}
String systemUser = Activator.getDefault().getPreferenceStore().getString(IPreferenceConstants.SYSTEM_USER);
int editableTuSum = handler.countEditableTransUnit();
int tuSum = handler.countTransUnit();
// int translatedSum1 = handler
// .getNodeCount(filePath,
// "/xliff/file/body/trans-unit[@approved = 'yes' and target/@state != 'translated' and target/@state != 'signed-off']");
// int translatedSum2 = handler.getNodeCount(filePath,
// "/xliff/file/body/trans-unit/target[@state = 'translated' or @state = 'signed-off']");
// int approveSum1 = handler.getNodeCount(filePath,
// "/xliff/file/body/trans-unit[not(@approved='yes') and target/@state='signed-off']");
// int approveSum2 = handler.getNodeCount(filePath, "/xliff/file/body/trans-unit[@approved = 'yes']");
int translatedSum = handler.getTranslatedCount();
int approveedSum = handler.getApprovedCount();
int approveP = (int) Math.floor(approveedSum / (double) tuSum * 100.00);
int translatedP = (int) Math.floor(translatedSum / (double) tuSum * 100.00);
translationItem.setProgressValue(translatedP);
approveItem.setProgressValue(approveP);
// 将信息显示在状态栏
String message = messageFormat.format(new String[] { fileName, String.valueOf(order), String.valueOf(editableTuSum), String.valueOf(tuSum), systemUser });
statusLineManager.setMessage(statusLineImage, message);
}
use of net.sourceforge.nattable.coordinate.PositionCoordinate 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.sourceforge.nattable.coordinate.PositionCoordinate 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.sourceforge.nattable.coordinate.PositionCoordinate in project translationstudio8 by heartsome.
the class CellDisplayValueSearchUtil method getCellCoordinates.
static List<PositionCoordinate> getCellCoordinates(ILayer contextLayer, int startingColumnPosition, int startingRowPosition, int width, int height, boolean isHorizontalLayout) {
if (!isHorizontalLayout) {
height = (int) Math.ceil(height * 1.0 / VerticalNatTableConfig.ROW_SPAN);
}
List<PositionCoordinate> coordinates = new ArrayList<PositionCoordinate>();
for (int columnPosition = 0; columnPosition < width; columnPosition++) {
for (int rowPosition = 0; rowPosition < height; rowPosition++) {
PositionCoordinate coordinate = new PositionCoordinate(contextLayer, startingColumnPosition, startingRowPosition);
coordinates.add(coordinate);
startingRowPosition += isHorizontalLayout ? 1 : VerticalNatTableConfig.ROW_SPAN;
}
startingColumnPosition++;
}
return coordinates;
}
use of net.sourceforge.nattable.coordinate.PositionCoordinate 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;
}
Aggregations