Java Code Examples for org.eclipse.core.commands.operations.IOperationHistory#execute()

The following examples show how to use org.eclipse.core.commands.operations.IOperationHistory#execute() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ProblemHoverTest.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Test public void testBug357516_bookmark() throws Exception {
	IResource resource = editor.getResource();
	HashMap<String, Object> attributes = new HashMap<String, Object>();
	attributes.put(IMarker.MESSAGE, CUSTOM_MARKER_TEST_MESSAGE);
	attributes.put(IMarker.LINE_NUMBER, 1);
	attributes.put(IMarker.LOCATION, resource.getFullPath().toPortableString());
	IUndoableOperation operation= new CreateMarkersOperation(IMarker.BOOKMARK, attributes, resource, CUSTOM_MARKER_TEST_MESSAGE);
	IOperationHistory operationHistory= PlatformUI.getWorkbench().getOperationSupport().getOperationHistory();
	try {
		operationHistory.execute(operation, null, null);
	} catch (ExecutionException x) {
		fail(x.getMessage());
	}
	String hoverInfo = hover.getHoverInfo(editor.getInternalSourceViewer(), 0);
	assertNotNull(hoverInfo);
	assertTrue(hoverInfo.contains(CUSTOM_MARKER_TEST_MESSAGE));
}
 
Example 2
Source File: CreateSubdiagramCommand.java    From statecharts with Eclipse Public License 1.0 6 votes vote down vote up
protected void executeCommand(AbstractTransactionalCommand operation) {
	IOperationHistory history = OperationHistoryFactory.getOperationHistory();
	try {
		history.execute(operation, new NullProgressMonitor(), null);
	} catch (ExecutionException e) {
		e.printStackTrace();
	}
}
 
Example 3
Source File: SetEntryKindCommand.java    From statecharts with Eclipse Public License 1.0 6 votes vote down vote up
public Object execute(ExecutionEvent event) throws ExecutionException {
	entry = unwrap(HandlerUtil.getCurrentSelection(event));
	
	if (entry == null)
		return null;
	SetValueCommand setCommand = new SetValueCommand(new SetRequest(entry,
			SGraphPackage.Literals.ENTRY__KIND, getEntryKind()));
	IOperationHistory history = OperationHistoryFactory
			.getOperationHistory();
	try {
		history.execute(setCommand, new NullProgressMonitor(), null);
	} catch (ExecutionException e) {
		e.printStackTrace();
	}
	
	return null;
}
 
Example 4
Source File: AbstractSemanticModification.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
protected void executeCommand(IUndoableOperation command, Resource resource) {
	IOperationHistory history = OperationHistoryFactory.getOperationHistory();
	try {
		history.execute(command, new NullProgressMonitor(), null);
	} catch (ExecutionException e) {
		e.printStackTrace();
	}
}
 
Example 5
Source File: NattableUtil.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 添加或者取消疑问
 * @param selectedRowIds
 * @param state
 *            ;
 */
public void changIsQuestionState(List<String> selectedRowIds, String state) {
	IOperationHistory operationHistory = OperationHistoryFactory.getOperationHistory();
	try {
		operationHistory.execute(new NeedsReviewOperation("need-review", xliffEditor.getTable(), selectedRowIds,
				xliffEditor.getXLFHandler(), state), null, null);
	} catch (ExecutionException e) {
		LOGGER.error("", e);
		MessageDialog.openError(xliffEditor.getSite().getShell(),
				Messages.getString("utils.NattableUtil.msgTitle2"), e.getMessage());
		e.printStackTrace();
	}
}
 
Example 6
Source File: NattableUtil.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 设置是否添加到记忆库
 * @param selectedRowIds
 * @param state
 *            "yes" or "no";
 */
public void changeSendToTmState(List<String> selectedRowIds, String state) {
	IOperationHistory operationHistory = OperationHistoryFactory.getOperationHistory();
	try {
		operationHistory.execute(new SendTOTmOperation("send-to-tm", xliffEditor.getTable(), selectedRowIds,
				xliffEditor.getXLFHandler(), state), null, null);
	} catch (ExecutionException e) {
		LOGGER.error("", e);
		MessageDialog.openError(xliffEditor.getSite().getShell(),
				Messages.getString("utils.NattableUtil.msgTitle2"), e.getMessage());
		e.printStackTrace();
	}
}
 
Example 7
Source File: UpdateDataCommandHandler.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected boolean doCommand(UpdateDataCommand command) {
	IOperationHistory operationHistory = OperationHistoryFactory.getOperationHistory();
	try {
		UpdateDataOperation op = new UpdateDataOperation(table, bodyLayerStack, command);
		op.addContext(PlatformUI.getWorkbench().getOperationSupport().getUndoContext());
		operationHistory.execute(op, null, null);
	} catch (ExecutionException e) {
		e.printStackTrace();
	}
	return true;
}
 
Example 8
Source File: NattableUtil.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 添加或者取消疑问
 * @param selectedRowIds
 * @param state
 *            ;
 */
public void changIsQuestionState(List<String> selectedRowIds, String state) {
	IOperationHistory operationHistory = OperationHistoryFactory.getOperationHistory();
	try {
		operationHistory.execute(new NeedsReviewOperation("need-review", xliffEditor.getTable(), selectedRowIds,
				xliffEditor.getXLFHandler(), state), null, null);
	} catch (ExecutionException e) {
		LOGGER.error("", e);
		MessageDialog.openError(xliffEditor.getSite().getShell(),
				Messages.getString("utils.NattableUtil.msgTitle2"), e.getMessage());
		e.printStackTrace();
	}
}
 
Example 9
Source File: NattableUtil.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 设置是否添加到记忆库
 * @param selectedRowIds
 * @param state
 *            "yes" or "no";
 */
public void changeSendToTmState(List<String> selectedRowIds, String state) {
	IOperationHistory operationHistory = OperationHistoryFactory.getOperationHistory();
	try {
		operationHistory.execute(new SendTOTmOperation("send-to-tm", xliffEditor.getTable(), selectedRowIds,
				xliffEditor.getXLFHandler(), state), null, null);
	} catch (ExecutionException e) {
		LOGGER.error("", e);
		MessageDialog.openError(xliffEditor.getSite().getShell(),
				Messages.getString("utils.NattableUtil.msgTitle2"), e.getMessage());
		e.printStackTrace();
	}
}
 
Example 10
Source File: CommandUtil.java    From statecharts with Eclipse Public License 1.0 4 votes vote down vote up
public static IStatus executeUndoableOperation(IUndoableOperation undoableOperation)
		throws ExecutionException {
	IOperationHistory history = PlatformUI.getWorkbench().getOperationSupport().getOperationHistory();
	return history.execute(undoableOperation, new NullProgressMonitor(), null);
}
 
Example 11
Source File: NattableUtil.java    From translationstudio8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 合并文本段 ;
 */
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);
	}

}
 
Example 12
Source File: SplitSegmentHandler.java    From translationstudio8 with GNU General Public License v2.0 4 votes vote down vote up
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 添加代码 终 */

	cellEditor.close(); // 关闭Editor
	IOperationHistory operationHistory = OperationHistoryFactory.getOperationHistory();
	try {
		operationHistory.execute(new SplitSegmentOperation("Split Segment", xliffEditor, handler, rowIndex,
				caretOffset), null, null);
	} catch (ExecutionException e) {
		e.printStackTrace();
	}
	return null;
}
 
Example 13
Source File: NattableUtil.java    From tmxeditor8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 合并文本段 ;
 */
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);
	}
	
}
 
Example 14
Source File: SplitSegmentHandler.java    From tmxeditor8 with GNU General Public License v2.0 4 votes vote down vote up
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 添加代码 终 */

	cellEditor.close(); // 关闭Editor
	IOperationHistory operationHistory = OperationHistoryFactory.getOperationHistory();
	try {
		operationHistory.execute(new SplitSegmentOperation("Split Segment", xliffEditor, handler, rowIndex,
				caretOffset), null, null);
	} catch (ExecutionException e) {
		e.printStackTrace();
	}
	return null;
}