use of org.eclipse.core.commands.operations.IOperationHistory in project che by eclipse.
the class RefactoringCorePlugin method getUndoContext.
public static IUndoContext getUndoContext() {
if (fRefactoringUndoContext == null) {
fRefactoringUndoContext = new RefactoringUndoContext();
IUndoContext workspaceContext = (IUndoContext) ResourcesPlugin.getWorkspace().getAdapter(IUndoContext.class);
if (workspaceContext instanceof ObjectUndoContext) {
((ObjectUndoContext) workspaceContext).addMatch(fRefactoringUndoContext);
}
IOperationHistory operationHistory = OperationHistoryFactory.getOperationHistory();
operationHistory.setLimit(fRefactoringUndoContext, 5);
}
return fRefactoringUndoContext;
}
use of org.eclipse.core.commands.operations.IOperationHistory in project translationstudio8 by heartsome.
the class NattableUtil method mergeSegment.
/**
* 合并文本段 ;
*/
public void mergeSegment() {
XLFHandler handler = xliffEditor.getXLFHandler();
List<String> lstRowId = xliffEditor.getSelectedRowIds();
List<String> lstAllRowId = xliffEditor.getXLFHandler().getAllRowIds();
Shell shell = xliffEditor.getSite().getShell();
if (lstRowId.size() < 2) {
MessageDialog.openInformation(shell, Messages.getString("utils.NattableUtil.mergeSegment.msgTitle"), Messages.getString("utils.NattableUtil.mergeSegment.msg1"));
return;
}
Collections.sort(lstRowId, new SortRowIdComparator());
Collections.sort(lstAllRowId, new SortRowIdComparator());
String rowId1 = lstRowId.get(0);
String fileName = RowIdUtil.getFileNameByRowId(rowId1);
if (fileName == null) {
return;
}
if (handler.isLocked(rowId1)) {
MessageDialog.openInformation(shell, Messages.getString("utils.NattableUtil.mergeSegment.msgTitle"), Messages.getString("utils.NattableUtil.mergeSegment.msg3"));
return;
}
for (int i = 1; i < lstRowId.size(); i++) {
String rowId = lstRowId.get(i);
if (handler.isLocked(rowId)) {
MessageDialog.openInformation(shell, Messages.getString("utils.NattableUtil.mergeSegment.msgTitle"), Messages.getString("utils.NattableUtil.mergeSegment.msg3"));
return;
}
String fileName2 = RowIdUtil.getFileNameByRowId(rowId);
// 数组集合必须在一个文件中才能合并
if (fileName2 == null || !fileName.equals(fileName2)) {
MessageDialog.openInformation(shell, Messages.getString("utils.NattableUtil.mergeSegment.msgTitle"), Messages.getString("utils.NattableUtil.mergeSegment.msg4"));
return;
}
// 判断所选文本段是否连续
String strCurTuId = RowIdUtil.getTUIdByRowId(rowId);
String strPreTuId = RowIdUtil.getTUIdByRowId(lstRowId.get(i - 1));
if (strCurTuId == null || strPreTuId == null) {
return;
}
if ((lstAllRowId.indexOf(rowId) - lstAllRowId.indexOf(lstRowId.get(i - 1))) != 1) {
MessageDialog.openInformation(shell, Messages.getString("utils.NattableUtil.mergeSegment.msgTitle"), Messages.getString("utils.NattableUtil.mergeSegment.msg5"));
return;
} else {
String curOriginal = RowIdUtil.getOriginalByRowId(rowId);
String preOriginal = RowIdUtil.getOriginalByRowId(lstRowId.get(i - 1));
if (!curOriginal.equals(preOriginal)) {
MessageDialog.openInformation(shell, Messages.getString("utils.NattableUtil.mergeSegment.msgTitle"), Messages.getString("utils.NattableUtil.mergeSegment.msg5"));
return;
}
}
}
// Bug #2373:选择全部文本段合并后,无显示内容
if (lstRowId.size() == xliffEditor.getXLFHandler().getRowIds().size()) {
xliffEditor.jumpToRow(0);
}
MergeSegmentOperation mergeOper = new MergeSegmentOperation("merge segment", xliffEditor, handler, lstRowId);
IOperationHistory operationHistory = OperationHistoryFactory.getOperationHistory();
try {
operationHistory.execute(mergeOper, null, null);
} catch (Exception e) {
LOGGER.error("", e);
}
}
use of org.eclipse.core.commands.operations.IOperationHistory 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;
}
use of org.eclipse.core.commands.operations.IOperationHistory in project translationstudio8 by heartsome.
the class UpdateDataAndAutoResizeCommandHandler method doCommand.
@Override
protected boolean doCommand(UpdateDataAndAutoResizeCommand command) {
try {
// int columnPosition = command.getColumnPosition();
// int rowPosition = command.getRowPosition();
// dataLayer.getDataProvider().setDataValue(columnPosition, rowPosition, command.getNewValue());
// dataLayer.fireLayerEvent(new CellVisualChangeEvent(dataLayer, columnPosition, rowPosition));
//
// int currentRow = command.getRowPosition() + 1; // 修改行在当前一屏显示的几行中的相对位置
// table.doCommand(new AutoResizeCurrentRowsCommand(table, new int[] { currentRow },
// table.getConfigRegistry(), new GC(table)));
IOperationHistory operationHistory = OperationHistoryFactory.getOperationHistory();
operationHistory.execute(new UpdateDataOperation(table, dataLayer, command), null, null);
return true;
} catch (UnsupportedOperationException e) {
LOGGER.error(MessageFormat.format(Messages.getString("handler.UpdateDataAndAutoResizeCommandHandler.logger1"), command.getNewValue()), e);
e.printStackTrace(System.err);
System.err.println("Failed to update value to: " + command.getNewValue());
} catch (ExecutionException e) {
LOGGER.error("", e);
e.printStackTrace();
}
return false;
}
use of org.eclipse.core.commands.operations.IOperationHistory in project translationstudio8 by heartsome.
the class NattableUtil method changeTgtState.
/**
* 改变Target的状态
* @param state
* 状态值("new", "final", "translated", "signed-off", "needs-adaptation", "needs-review-adaptation",
* "needs-l10n", "needs-review-l10n", "needs-translation", "needs-review-translation");
*/
public void changeTgtState(final List<String> selectedRowIds, final String state, IProgressMonitor monitor) {
if (monitor == null) {
monitor = new NullProgressMonitor();
}
monitor.beginTask(Messages.getString("utils.NattableUtil.task4"), 1);
monitor.worked(1);
final IOperationHistory operationHistory = OperationHistoryFactory.getOperationHistory();
final IProgressMonitor monitor2 = monitor;
Display.getDefault().syncExec(new Runnable() {
public void run() {
try {
operationHistory.execute(new StateOperation("State", xliffEditor.getTable(), selectedRowIds, xliffEditor.getXLFHandler(), state), monitor2, null);
} catch (ExecutionException e) {
LOGGER.error("", e);
MessageDialog.openError(xliffEditor.getSite().getShell(), Messages.getString("utils.NattableUtil.msgTitle2"), e.getMessage());
e.printStackTrace();
}
}
});
monitor.done();
}
Aggregations