use of net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.StyledTextCellEditor in project translationstudio8 by heartsome.
the class DeleteAllSegmentTranslationsHandler method execute.
public Object execute(ExecutionEvent event) throws ExecutionException {
IEditorPart editor = HandlerUtil.getActiveEditor(event);
if (!(editor instanceof XLIFFEditorImplWithNatTable)) {
return null;
}
IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
boolean res = MessageDialog.openConfirm(window.getShell(), Messages.getString("handler.DeleteSelectionSegmentTranslationsHandler.msgTitle1"), Messages.getString("handler.DeleteSelectionSegmentTranslationsHandler.msg3"));
if (res) {
XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) editor;
try {
XLFHandler handler = xliffEditor.getXLFHandler();
int count = xliffEditor.getAllRowCount();
int[] selectedRows = new int[count];
for (int i = 0; i < count; i++) {
selectedRows[i] = i;
}
List<Integer> rows = new ArrayList<Integer>();
boolean exitFlag = false;
for (int i = 0; i < selectedRows.length; i++) {
String tgt = handler.getCaseTgtContent(handler.getRowId(selectedRows[i]));
if (null != tgt) {
if (tgt.equals("no")) {
exitFlag = true;
continue;
}
}
rows.add(selectedRows[i]);
}
if (rows.size() != 0) {
int columnIndex = xliffEditor.getTgtColumnIndex();
StyledTextCellEditor cellEditor = HsMultiActiveCellEditor.getTargetStyledEditor();
if (cellEditor != null && cellEditor.getColumnIndex() == columnIndex) {
cellEditor.getSegmentViewer().getTextWidget().forceFocus();
}
int[] updateRows = new int[rows.size()];
for (int i = 0; i < rows.size(); i++) {
int ri = rows.get(i);
updateRows[i] = ri;
}
xliffEditor.updateCells(updateRows, columnIndex, "");
if (exitFlag) {
MessageDialog.openInformation(xliffEditor.getSite().getShell(), Messages.getString("handler.DeleteSelectionSegmentTranslationsHandler.msgTitle2"), Messages.getString("handler.DeleteSelectionSegmentTranslationsHandler.msg2"));
}
}
} catch (Exception e) {
LOGGER.error("", e);
e.printStackTrace();
}
}
return null;
}
use of net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.StyledTextCellEditor in project translationstudio8 by heartsome.
the class DeleteSelectionSegmentTranslationsHandler method execute.
public Object execute(ExecutionEvent event) throws ExecutionException {
IEditorPart editor = HandlerUtil.getActiveEditor(event);
if (!(editor instanceof XLIFFEditorImplWithNatTable)) {
return null;
}
IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
boolean res = MessageDialog.openConfirm(window.getShell(), Messages.getString("handler.DeleteSelectionSegmentTranslationsHandler.msgTitle1"), Messages.getString("handler.DeleteSelectionSegmentTranslationsHandler.msg1"));
if (res) {
XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) editor;
try {
XLFHandler handler = xliffEditor.getXLFHandler();
int[] selectedRows = xliffEditor.getSelectedRows();
List<Integer> rows = new ArrayList<Integer>();
boolean exitFlag = false;
for (int i = 0; i < selectedRows.length; i++) {
String tgt = handler.getCaseTgtContent(handler.getRowId(selectedRows[i]));
if (null != tgt) {
if (tgt.equals("no")) {
exitFlag = true;
continue;
}
}
rows.add(selectedRows[i]);
}
if (rows.size() != 0) {
int columnIndex = xliffEditor.getTgtColumnIndex();
StyledTextCellEditor cellEditor = HsMultiActiveCellEditor.getTargetStyledEditor();
if (cellEditor != null && cellEditor.getColumnIndex() == columnIndex) {
cellEditor.getSegmentViewer().getTextWidget().forceFocus();
}
int[] updateRows = new int[rows.size()];
for (int i = 0; i < rows.size(); i++) {
int ri = rows.get(i);
updateRows[i] = ri;
}
xliffEditor.updateCells(updateRows, columnIndex, "");
if (exitFlag) {
MessageDialog.openInformation(xliffEditor.getSite().getShell(), Messages.getString("handler.DeleteSelectionSegmentTranslationsHandler.msgTitle2"), Messages.getString("handler.DeleteSelectionSegmentTranslationsHandler.msg2"));
}
}
} catch (Exception e) {
LOGGER.error("", e);
e.printStackTrace();
}
}
return null;
}
use of net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.StyledTextCellEditor in project translationstudio8 by heartsome.
the class DeleteToEndOrToTagHandler method execute.
public Object execute(ExecutionEvent event) throws ExecutionException {
IEditorPart editor = HandlerUtil.getActiveEditor(event);
if (editor instanceof XLIFFEditorImplWithNatTable) {
XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) editor;
String deleteType = event.getParameter("DeleteContent");
if (deleteType == null) {
return null;
}
StyledTextCellEditor cellEditor = HsMultiActiveCellEditor.getFocusCellEditor();
if (cellEditor == null || !cellEditor.getCellType().equals(NatTableConstant.TARGET)) {
return null;
}
if (!cellEditor.isEditable()) {
// cellEditor.showUneditableMessage();
MessageDialog.openInformation(HandlerUtil.getActiveShell(event), Messages.getString("handler.DeleteToEndOrToTagHandler.msgTitle"), cellEditor.getEditableManager().getUneditableMessage());
return null;
}
StyledText styledText = cellEditor.getSegmentViewer().getTextWidget();
int offset = styledText.getCaretOffset();
Point p = styledText.getSelection();
if (p != null) {
int len = styledText.getText().length();
String preText = "";
String nextText = "";
SegmentViewer viewer = (SegmentViewer) cellEditor.getSegmentViewer();
if (offset > 0) {
preText = styledText.getText(0, offset - 1);
preText = viewer.convertDisplayTextToOriginalText(preText);
}
// 删除标记前所有内容
if (deleteType.equals("DeleteToTag") && offset < len) {
nextText = styledText.getText(offset, len - 1);
Matcher matcher = PATTERN.matcher(nextText);
if (matcher.find()) {
int index = matcher.start();
nextText = nextText.substring(index);
} else {
// 选择删除标记前所有内容时,如果当前光标之后没有标记,则删除光标之后的所有内容
nextText = "";
}
}
nextText = viewer.convertDisplayTextToOriginalText(nextText);
String newText = preText + nextText;
Hashtable<String, String> map = new Hashtable<String, String>();
// Fix Bug #2883 删除光标后内容--同时选择多个文本段进行操作时,界面出错 By Jason
// for (String rowId : xliffEditor.getSelectedRowIds()) {
// map.put(rowId, newText);
// }
int index = cellEditor.getRowIndex();
String rowId = xliffEditor.getXLFHandler().getRowId(index);
map.put(rowId, newText);
xliffEditor.updateSegments(map, xliffEditor.getTgtColumnIndex(), null, null);
// 定位光标
styledText.setCaretOffset(offset);
}
}
return null;
}
use of net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.StyledTextCellEditor in project translationstudio8 by heartsome.
the class ChangeSourceEditableHandler method execute.
public Object execute(ExecutionEvent event) throws ExecutionException {
IEditorPart editor = HandlerUtil.getActiveEditor(event);
if (editor != null && editor instanceof XLIFFEditorImplWithNatTable) {
XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) editor;
ICellEditor cellEditor = xliffEditor.getTable().getConfigRegistry().getConfigAttribute(EditConfigAttributes.CELL_EDITOR, DisplayMode.EDIT, XLIFFEditorImplWithNatTable.SOURCE_EDIT_CELL_LABEL);
if (cellEditor == null || !(cellEditor instanceof StyledTextCellEditor)) {
return null;
}
HsMultiActiveCellEditor.commit(false);
StyledTextCellEditor sce = (StyledTextCellEditor) cellEditor;
EditableManager editableManager = sce.getEditableManager();
// SourceEditMode nextMode = editableManager.getSourceEditMode().getNextMode();
SourceEditMode nextMode = getSourceEditMode(editableManager);
editableManager.setSourceEditMode(nextMode);
// element.setIcon(Activator.getImageDescriptor(nextMode.getImagePath()));
if (!sce.isClosed()) {
editableManager.judgeEditable();
// 更新全局 Action 的可用状态,主要是更新编辑-删除功能的可用状态。
sce.getActionHandler().updateActionsEnableState();
}
sce.addClosingListener(listener);
}
return null;
}
use of net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.StyledTextCellEditor in project translationstudio8 by heartsome.
the class SplitSegmentHandler method execute.
public Object execute(ExecutionEvent event) throws ExecutionException {
IEditorPart editor = HandlerUtil.getActiveEditor(event);
if (!(editor instanceof XLIFFEditorImplWithNatTable)) {
return null;
}
XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) editor;
StyledTextCellEditor cellEditor = HsMultiActiveCellEditor.getFocusCellEditor();
if (cellEditor == null) {
return null;
}
if (!cellEditor.getCellType().equals(NatTableConstant.SOURCE)) {
showInformation(event, Messages.getString("handler.SplitSegmentHandler.msg1"));
return null;
}
int rowIndex = cellEditor.getRowIndex();
// 如果是垂直布局,那么 rowIndex 要除以2 --robert
if (!xliffEditor.isHorizontalLayout()) {
rowIndex = rowIndex / 2;
}
int caretOffset = cellEditor.getRealSplitOffset();
if (caretOffset < 0) {
// 文本框已经关闭时
showInformation(event, Messages.getString("handler.SplitSegmentHandler.msg1"));
return null;
}
// 不能选择多个字符进行分割
String selText = cellEditor.getSegmentViewer().getTextWidget().getSelectionText();
if (selText.length() != 0) {
showInformation(event, Messages.getString("handler.SplitSegmentHandler.msg1"));
return null;
}
XLFHandler handler = xliffEditor.getXLFHandler();
String rowId = handler.getRowId(rowIndex);
/* burke 修改锁定文本段不能被分割和光标在文本段段首或者段末时,不能进行分割的BUG 添加代码 起 */
String tgt = handler.getCaseTgtContent(rowId);
if (null != tgt) {
if (tgt.equals("no")) {
showInformation(event, Messages.getString("handler.SplitSegmentHandler.msg2"));
return null;
}
}
int cellTextLength = ((UpdateDataBean) cellEditor.getCanonicalValue()).getText().length();
if (caretOffset <= 0 || caretOffset >= cellTextLength) {
showInformation(event, Messages.getString("handler.SplitSegmentHandler.msg3"));
return null;
}
/* burke 修改锁定文本段不能被分割和光标在文本段段首或者段末时,不能进行分割的BUG 添加代码 终 */
// 关闭Editor
cellEditor.close();
IOperationHistory operationHistory = OperationHistoryFactory.getOperationHistory();
try {
operationHistory.execute(new SplitSegmentOperation("Split Segment", xliffEditor, handler, rowIndex, caretOffset), null, null);
} catch (ExecutionException e) {
e.printStackTrace();
}
return null;
}
Aggregations