use of org.eclipse.ui.IEditorPart 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 org.eclipse.ui.IEditorPart 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 org.eclipse.ui.IEditorPart 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 org.eclipse.ui.IEditorPart in project translationstudio8 by heartsome.
the class MergeNextHandler method execute.
public Object execute(ExecutionEvent event) throws ExecutionException {
IEditorPart editor = HandlerUtil.getActiveEditor(event);
if (!(editor instanceof XLIFFEditorImplWithNatTable)) {
return null;
}
XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) editor;
List<String> selectedRowIds = xliffEditor.getSelectedRowIds();
if (selectedRowIds.size() < 1) {
return null;
}
String rowId = selectedRowIds.get(selectedRowIds.size() - 1);
XLFHandler handler = xliffEditor.getXLFHandler();
int rowIndex = handler.getRowIndex(rowId);
IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
if (rowIndex == handler.countEditableTransUnit() - 1) {
// 是最后一行
MessageDialog.openWarning(window.getShell(), "", "不存在下一文本段,不能合并。");
return null;
}
String rowId2 = handler.getRowId(rowIndex + 1);
if (handler.isApproved(rowId) || handler.isApproved(rowId2)) {
MessageDialog.openWarning(window.getShell(), "", "已批准文本段,不能合并。");
return null;
}
String fileName1 = RowIdUtil.getFileNameByRowId(rowId);
String fileName2 = RowIdUtil.getFileNameByRowId(rowId2);
if (fileName1 == null || fileName2 == null || !fileName1.equals(fileName2)) {
MessageDialog.openWarning(window.getShell(), "", "文本段不在同一个文件内,不能合并。");
return null;
}
return null;
}
use of org.eclipse.ui.IEditorPart in project translationstudio8 by heartsome.
the class MergePreviousHandler method execute.
public Object execute(ExecutionEvent event) throws ExecutionException {
IEditorPart editor = HandlerUtil.getActiveEditor(event);
if (!(editor instanceof XLIFFEditorImplWithNatTable)) {
return null;
}
XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) editor;
List<String> selectedRowIds = xliffEditor.getSelectedRowIds();
if (selectedRowIds.size() < 1) {
return null;
}
String rowId = selectedRowIds.get(0);
XLFHandler handler = xliffEditor.getXLFHandler();
int rowIndex = handler.getRowIndex(rowId);
IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
if (rowIndex == 0) {
// 是第一行
MessageDialog.openWarning(window.getShell(), "", "不存在上一文本段,不能合并。");
return null;
}
String rowId2 = handler.getRowId(rowIndex - 1);
if (handler.isApproved(rowId) || handler.isApproved(rowId2)) {
MessageDialog.openWarning(window.getShell(), "", "已批准文本段,不能合并。");
return null;
}
String fileName1 = RowIdUtil.getFileNameByRowId(rowId);
String fileName2 = RowIdUtil.getFileNameByRowId(rowId2);
if (fileName1 == null || fileName2 == null || !fileName1.equals(fileName2)) {
MessageDialog.openWarning(window.getShell(), "", "文本段不在同一个文件内,不能合并。");
return null;
}
// IOperationHistory operationHistory = OperationHistoryFactory.getOperationHistory();
// try {
// operationHistory.execute(new MergeSegmentOperation("Merge Segment", xliffEditor, handler,
// rowIndex - 1), null, null);
// } catch (ExecutionException e) {
// e.printStackTrace();
// }
// 选中上一行
SelectionLayer selectionLayer = LayerUtil.getLayer(xliffEditor.getTable(), SelectionLayer.class);
selectionLayer.selectRow(0, rowIndex - 1, false, false);
return null;
}
Aggregations