Java Code Examples for org.eclipse.core.commands.operations.OperationHistoryFactory#getOperationHistory()

The following examples show how to use org.eclipse.core.commands.operations.OperationHistoryFactory#getOperationHistory() . 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: 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 2
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 3
Source File: DeleteTuHandler.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
	TmxEditorViewer viewer = TmxEditorViewer.getInstance();
	if (viewer == null) {
		return null;
	}
	TmxEditor editor = viewer.getTmxEditor();
	if (editor == null) {
		return null;
	}
	if (editor.getTmxDataAccess().getDisplayTuCount() == 0
			|| editor.getTmxEditorImpWithNattable().getSelectedRows().length == 0) {
		OpenMessageUtils.openMessage(IStatus.INFO, Messages.getString("tmxeditor.deleteTuHandler.noSelectedMsg"));
		return null;
	}
	boolean confirm = MessageDialog.openConfirm(HandlerUtil.getActiveShell(event),
			Messages.getString("tmxeditor.deleteTuHandler.warn.msg"),
			Messages.getString("tmxeditor.deleteTuHandler.warn.desc"));
	if (!confirm) {
		return null;
	}
	editor.deleteSelectedTu();
	IOperationHistory histor = OperationHistoryFactory.getOperationHistory();
	histor.dispose(PlatformUI.getWorkbench().getOperationSupport().getUndoContext(), true, true, true);
	return null;
}
 
Example 4
Source File: TestEditor.java    From ermasterr with Apache License 2.0 5 votes vote down vote up
/**
 * The <code>AbstractTextEditor</code> implementation of this
 * <code>IWorkbenchPart</code> method may be extended by subclasses.
 * Subclasses must call <code>super.dispose()</code>.
 * <p>
 * Note that many methods may return <code>null</code> after the editor is
 * disposed.
 * </p>
 */
@Override
public void dispose() {

    if (fTitleImage != null) {
        fTitleImage.dispose();
        fTitleImage = null;
    }

    disposeDocumentProvider();

    if (fSourceViewer != null) {
        fSourceViewer = null;
    }

    if (fConfiguration != null)
        fConfiguration = null;

    final IOperationHistory history = OperationHistoryFactory.getOperationHistory();
    if (history != null) {
        if (fNonLocalOperationApprover != null)
            history.removeOperationApprover(fNonLocalOperationApprover);
        if (fLinearUndoViolationApprover != null)
            history.removeOperationApprover(fLinearUndoViolationApprover);
    }
    fNonLocalOperationApprover = null;
    fLinearUndoViolationApprover = null;

    super.dispose();
}
 
Example 5
Source File: CellEditorGlobalActionHanlder.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
public void runWithEvent(Event event) {
	TeActiveCellEditor.commit();
	IOperationHistory history = OperationHistoryFactory.getOperationHistory();
	IUndoContext context = PlatformUI.getWorkbench().getOperationSupport().getUndoContext();
	if (history.canRedo(context)) {
		try {
			history.redo(context, null, null);
			updateActionsEnableState();
		} catch (ExecutionException e) {
			e.printStackTrace();
		}
	}
}
 
Example 6
Source File: CellEditorGlobalActionHanlder.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Update the state.
 */
public void updateEnabledState() {
	IOperationHistory opHisotry = OperationHistoryFactory.getOperationHistory();
	IUndoContext context = PlatformUI.getWorkbench().getOperationSupport().getUndoContext();
	if (opHisotry.canUndo(context)) {
		setEnabled(true);
		return;
	}
	if (viewer != null && !viewer.getTextWidget().isDisposed()) {
		setEnabled(viewer.canDoOperation(ITextOperationTarget.UNDO));
		return;
	}
	setEnabled(false);
}
 
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: CellEditorGlobalActionHanlder.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Update the state.
 */
public void updateEnabledState() {
	IOperationHistory opHisotry = OperationHistoryFactory.getOperationHistory();
	IUndoContext context = PlatformUI.getWorkbench().getOperationSupport().getUndoContext();
	if (opHisotry.canRedo(context)) {
		setEnabled(true);
		return;
	}
	if (viewer != null && !viewer.getTextWidget().isDisposed()) {
		setEnabled(viewer.canDoOperation(ITextOperationTarget.REDO));
		return;
	}
	setEnabled(false);
}
 
Example 9
Source File: XLIFFEditorActionHandler.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void runWithEvent(Event event) {
	if (viewer != null && !viewer.getTextWidget().isDisposed()) {
		XLIFFEditorImplWithNatTable xliffEditor = XLIFFEditorImplWithNatTable.getCurrent();
		// 先保存在撤销,除非以后取消两种模式,否则不要删除此判断
		if (viewer.canDoOperation(ITextOperationTarget.UNDO)) {
			HsMultiActiveCellEditor.commit(true);
		}
		IOperationHistory history = OperationHistoryFactory.getOperationHistory();
		IUndoContext undoContext = (IUndoContext) xliffEditor.getTable().getData(IUndoContext.class.getName());
		if (history.canUndo(undoContext)) {
			try {
				history.undo(undoContext, null, null);
				undoBean.setCrosseStep(undoBean.getCrosseStep() + 1);
			} catch (ExecutionException e) {
				e.printStackTrace();
			}
		}
		XLIFFEditorImplWithNatTable.getCurrent().redraw();
		updateActionsEnableState();
		return;
	}
	if (undoAction != null) {
		undoAction.runWithEvent(event);
		return;
	}
}
 
Example 10
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 11
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 12
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 13
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 14
Source File: TestEditor.java    From ermaster-b with Apache License 2.0 5 votes vote down vote up
/**
 * The <code>AbstractTextEditor</code> implementation of this
 * <code>IWorkbenchPart</code> method may be extended by subclasses.
 * Subclasses must call <code>super.dispose()</code>.
 * <p>
 * Note that many methods may return <code>null</code> after the editor is
 * disposed.
 * </p>
 */
@Override
public void dispose() {

	if (fTitleImage != null) {
		fTitleImage.dispose();
		fTitleImage = null;
	}

	disposeDocumentProvider();

	if (fSourceViewer != null) {
		fSourceViewer = null;
	}

	if (fConfiguration != null)
		fConfiguration = null;

	IOperationHistory history = OperationHistoryFactory
			.getOperationHistory();
	if (history != null) {
		if (fNonLocalOperationApprover != null)
			history.removeOperationApprover(fNonLocalOperationApprover);
		if (fLinearUndoViolationApprover != null)
			history.removeOperationApprover(fLinearUndoViolationApprover);
	}
	fNonLocalOperationApprover = null;
	fLinearUndoViolationApprover = null;

	super.dispose();
}
 
Example 15
Source File: LinkedEditingUndoSupport.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
public void startRecording(XtextEditor editor) {
	this.editor = editor;
	ISourceViewer viewer = editor.getInternalSourceViewer();
	if (viewer instanceof ITextViewerExtension6) {
		IUndoManager undoManager = ((ITextViewerExtension6) viewer).getUndoManager();
		if (undoManager instanceof IUndoManagerExtension) {
			IUndoManagerExtension undoManagerExtension = (IUndoManagerExtension) undoManager;
			IUndoContext undoContext = undoManagerExtension.getUndoContext();
			IOperationHistory operationHistory = OperationHistoryFactory.getOperationHistory();
			startingUndoOperation = operationHistory.getUndoOperation(undoContext);
		}
	}
}
 
Example 16
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 17
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 18
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 19
Source File: RenameLinkedMode.java    From typescript.java with MIT License 4 votes vote down vote up
public void start() {
	if (getActiveLinkedMode() != null) {
		// for safety; should already be handled in RenameJavaElementAction
		fgActiveLinkedMode.startFullDialog();
		return;
	}

	ISourceViewer viewer = fEditor.getViewer();
	IDocument document = viewer.getDocument();

	ITypeScriptFile tsFile = fEditor.getTypeScriptFile();
	tsFile.setDisableChanged(true);
	fOriginalSelection = viewer.getSelectedRange();
	int offset = fOriginalSelection.x;

	try {
		fLinkedPositionGroup = new LinkedPositionGroup();
		if (viewer instanceof ITextViewerExtension6) {
			IUndoManager undoManager = ((ITextViewerExtension6) viewer).getUndoManager();
			if (undoManager instanceof IUndoManagerExtension) {
				IUndoManagerExtension undoManagerExtension = (IUndoManagerExtension) undoManager;
				IUndoContext undoContext = undoManagerExtension.getUndoContext();
				IOperationHistory operationHistory = OperationHistoryFactory.getOperationHistory();
				fStartingUndoOperation = operationHistory.getUndoOperation(undoContext);
			}
		}

		// Find occurrences
		List<OccurrencesResponseItem> occurrences = tsFile.occurrences(offset).get(1000, TimeUnit.MILLISECONDS);

		// Create Eclipse linked position from the occurrences list.
		int start, length;
		for (int i = 0; i < occurrences.size(); i++) {
			OccurrencesResponseItem item = occurrences.get(i);
			start = tsFile.getPosition(item.getStart());
			length = tsFile.getPosition(item.getEnd()) - start;
			LinkedPosition linkedPosition = new LinkedPosition(document, start, length, i);
			if (i == 0) {
				fOriginalName = document.get(start, length);
				fNamePosition = linkedPosition;
			}
			fLinkedPositionGroup.addPosition(linkedPosition);
		}

		fLinkedModeModel = new LinkedModeModel();
		fLinkedModeModel.addGroup(fLinkedPositionGroup);
		fLinkedModeModel.forceInstall();
		fLinkedModeModel.addLinkingListener(new EditorHighlightingSynchronizer(fEditor));
		fLinkedModeModel.addLinkingListener(new EditorSynchronizer());

		LinkedModeUI ui = new EditorLinkedModeUI(fLinkedModeModel, viewer);
		ui.setExitPosition(viewer, offset, 0, Integer.MAX_VALUE);
		ui.setExitPolicy(new ExitPolicy(document));
		ui.enter();

		viewer.setSelectedRange(fOriginalSelection.x, fOriginalSelection.y); // by
																				// default,
																				// full
																				// word
																				// is
																				// selected;
																				// restore
																				// original
																				// selection

		if (viewer instanceof IEditingSupportRegistry) {
			IEditingSupportRegistry registry = (IEditingSupportRegistry) viewer;
			registry.register(fFocusEditingSupport);
		}

		openSecondaryPopup();
		// startAnimation();
		fgActiveLinkedMode = this;

	} catch (Exception e) {
		JSDTTypeScriptUIPlugin.log(e);
	}
}
 
Example 20
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;
}