use of net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.StyledTextCellEditor 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.editor.StyledTextCellEditor 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;
}
use of net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.StyledTextCellEditor in project translationstudio8 by heartsome.
the class FindReplaceCommandHandler method doCommand.
public boolean doCommand(ILayer targetLayer, FindReplaceCommand findReplaceCommand) {
findReplaceCommand.convertToTargetLayer(targetLayer);
ISearchStrategy searchStrategy = findReplaceCommand.getSearchStrategy();
if (findReplaceCommand.getSearchEventListener() != null) {
selectionLayer.addLayerListener(findReplaceCommand.getSearchEventListener());
}
PositionCoordinate anchor = selectionLayer.getSelectionAnchor();
if (anchor.columnPosition < 0 || anchor.rowPosition < 0) {
anchor = new PositionCoordinate(selectionLayer, 0, 0);
}
searchStrategy.setContextLayer(targetLayer);
Object dataValueToFind = null;
if ((dataValueToFind = findReplaceCommand.getSearchText()) == null) {
dataValueToFind = selectionLayer.getDataValueByPosition(anchor.columnPosition, anchor.rowPosition);
}
ICellSearchStrategy cellSearchStrategy = findReplaceCommand.getCellSearchStrategy();
searchStrategy.setCellSearchStrategy(cellSearchStrategy);
DefaultCellSearchStrategy defaultCellSearchStrategy = null;
if (cellSearchStrategy instanceof DefaultCellSearchStrategy) {
defaultCellSearchStrategy = (DefaultCellSearchStrategy) cellSearchStrategy;
}
searchResultCellRegion = searchStrategy.executeSearch(dataValueToFind);
if (searchResultCellRegion != null) {
PositionCoordinate searchResultCellCoordinate = searchResultCellRegion.getPositionCoordinate();
int rowPosition = searchResultCellCoordinate.rowPosition;
XLIFFEditorImplWithNatTable editor = XLIFFEditorImplWithNatTable.getCurrent();
ViewportLayer viewportLayer = LayerUtil.getLayer(editor.getTable(), ViewportLayer.class);
HsMultiActiveCellEditor.commit(true);
if (!editor.isHorizontalLayout()) {
viewportLayer.doCommand(new SelectCellCommand(selectionLayer, searchResultCellCoordinate.columnPosition, rowPosition / 2 * 2, false, false));
} else {
viewportLayer.doCommand(new SelectCellCommand(selectionLayer, searchResultCellCoordinate.columnPosition, rowPosition, false, false));
}
HsMultiCellEditorControl.activeSourceAndTargetCell(editor);
HsMultiActiveCellEditor.setCellEditorForceFocusByIndex(searchResultCellCoordinate.columnPosition, rowPosition);
StyledTextCellEditor cellEditor = HsMultiActiveCellEditor.getFocusCellEditor();
if (cellEditor != null) {
String dataValue = cellEditor.getSegmentViewer().getDocument().get();
if (dataValue != null) {
int startOffset = -1;
if (defaultCellSearchStrategy != null) {
startOffset = defaultCellSearchStrategy.getStartOffset();
}
defaultCellSearchStrategy.setStartOffset(startOffset);
String findString = dataValueToFind.toString();
if (XliffEditorParameter.getInstance().isShowNonpirnttingCharacter()) {
findString = findString.replaceAll("\\n", Constants.LINE_SEPARATOR_CHARACTER + "\n");
findString = findString.replaceAll("\\t", Constants.TAB_CHARACTER + "");
findString = findString.replaceAll(" ", Constants.SPACE_CHARACTER + "");
}
IRegion region = defaultCellSearchStrategy.executeSearch(findString, dataValue);
if (region != null) {
HsMultiActiveCellEditor.setSelectionText(cellEditor, region.getOffset(), region.getLength());
}
defaultCellSearchStrategy.setStartOffset(-1);
}
}
}
selectionLayer.fireLayerEvent(new FindReplaceEvent(searchResultCellRegion));
if (findReplaceCommand.getSearchEventListener() != null) {
selectionLayer.removeLayerListener(findReplaceCommand.getSearchEventListener());
}
return true;
}
use of net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.StyledTextCellEditor in project translationstudio8 by heartsome.
the class DeleteAllTagsHandler method execute.
public Object execute(ExecutionEvent event) throws ExecutionException {
IEditorPart editor = HandlerUtil.getActiveEditor(event);
if (editor instanceof XLIFFEditorImplWithNatTable) {
XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) editor;
int[] rows = xliffEditor.getSelectedRows();
if (rows.length == 0) {
return null;
}
HsMultiCellEditor targetCellEditor = HsMultiActiveCellEditor.getTargetEditor();
StyledTextCellEditor cellEditor = targetCellEditor.getCellEditor();
if (cellEditor == null || cellEditor.isClosed()) {
return null;
}
if (rows.length == 1) {
// 清除内部标记
cellEditor.clearTags();
return null;
} else {
int activeEditRowIndex = targetCellEditor.getRowIndex();
// 清除内部标记
cellEditor.clearTags();
if (!xliffEditor.isHorizontalLayout()) {
activeEditRowIndex = activeEditRowIndex / 2;
}
// non active row
int[] nonActiveRows = new int[rows.length - 1];
int i = 0;
for (int row : rows) {
if (row == activeEditRowIndex) {
continue;
}
nonActiveRows[i++] = row;
}
List<String> rowIdList = new ArrayList<String>(xliffEditor.getXLFHandler().getRowIds(rows));
xliffEditor.getXLFHandler().removeAllTags(rowIdList);
xliffEditor.refresh();
}
}
return null;
}
use of net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.StyledTextCellEditor in project translationstudio8 by heartsome.
the class CopySourceHandler method execute.
public Object execute(ExecutionEvent event) throws ExecutionException {
IEditorPart editor = HandlerUtil.getActiveEditor(event);
if (editor instanceof XLIFFEditorImplWithNatTable) {
XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) editor;
XLFHandler handler = xliffEditor.getXLFHandler();
List<String> rowIds = xliffEditor.getSelectedRowIds();
boolean locked = false;
Map<String, String> map = new HashMap<String, String>();
for (int i = 0; i < rowIds.size(); i++) {
String rowId = rowIds.get(i);
if (handler.isLocked(rowId)) {
// 已经批准或者已锁定,则不进行修改。
locked = true;
continue;
}
String srcContent = handler.getSrcContent(rowId);
String newValue = srcContent == null ? "" : srcContent;
map.put(rowId, newValue);
}
if (locked) {
if (!MessageDialog.openConfirm(xliffEditor.getSite().getShell(), Messages.getString("handler.CopySourceHandler.msgTitle"), Messages.getString("handler.CopySourceHandler.msg"))) {
return null;
}
}
StyledTextCellEditor cellEditor = HsMultiActiveCellEditor.getTargetStyledEditor();
if (cellEditor != null) {
HsMultiActiveCellEditor.setCellEditorForceFocus(cellEditor.getColumnPosition(), cellEditor.getRowPosition());
}
xliffEditor.updateSegments(map, xliffEditor.getTgtColumnIndex(), null, null);
}
return null;
}
Aggregations