Java Code Examples for org.eclipse.xtext.ui.editor.XtextEditor#selectAndReveal()

The following examples show how to use org.eclipse.xtext.ui.editor.XtextEditor#selectAndReveal() . 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: ToSaveOrNotToSaveTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected void renameFooToFooBar(final XtextEditor contextEditor) throws Exception {
		contextEditor.getEditorSite().getPage().activate(contextEditor);
		waitForDisplay();
		IXtextDocument document = contextEditor.getDocument();
		final int offset = document.get().indexOf("foo");
		contextEditor.selectAndReveal(offset, 3);
		
		EvaluationContext evaluationContext = new EvaluationContext(null, new Object());
		evaluationContext.addVariable(ISources.ACTIVE_EDITOR_NAME, contextEditor);
		ExecutionEvent executionEvent = new ExecutionEvent(null, newHashMap(), null, evaluationContext);
		renameElementHandler.execute(executionEvent);
//		syncUtil.totalSync(refactoringPreferences.isSaveAllBeforeRefactoring());
//		IRenameElementContext context = document.readOnly(new IUnitOfWork<IRenameElementContext, XtextResource>() {
//			public IRenameElementContext exec(XtextResource state) throws Exception {
//				EObject target = eObjectAtOffsetHelper.resolveElementAt(state, offset);
//				return renameContextFactory.createRenameElementContext(target, contextEditor, new TextSelection(offset,
//						3), state);
//			}
//		});
//		controller.initialize(context);
//		waitForDisplay();
//		controller.startRefactoring(RefactoringType.LINKED_EDITING);
//		waitForDisplay();
		pressKeys(contextEditor, "fooBar\n");
		waitForDisplay();
		waitForReconciler(fooEditor);
		waitForReconciler(barEditor);
		waitForDisplay();
	}
 
Example 2
Source File: LinkedModelCalculatorIntegrationTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected void selectElementInEditor(EObject targetElement, final URI targetElementURI, final XtextEditor editor,
		XtextResource editorResource) {
	if (targetElementURI != null && targetElementURI.trimFragment().equals(editorResource.getURI())) {
		ITextRegion region = locationInFileProvider.getSignificantTextRegion(targetElement);
		editor.selectAndReveal(region.getOffset(), region.getLength());
	}
}
 
Example 3
Source File: ExtractVariableHandler.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
	try {
		syncUtil.totalSync(false);
		final XtextEditor editor = EditorUtils.getActiveXtextEditor(event);
		if (editor != null) {
			final ITextSelection selection = (ITextSelection) editor.getSelectionProvider().getSelection();
			final IXtextDocument document = editor.getDocument();
			XtextResource resource = document.priorityReadOnly(new IUnitOfWork<XtextResource, XtextResource>() {
				@Override
				public XtextResource exec(XtextResource state) throws Exception {
					return resourceCopier.loadIntoNewResourceSet(state);
				}
			});
			XExpression expression = expressionUtil.findSelectedExpression(resource, selection);
			if(expression != null) {
				ExtractVariableRefactoring introduceVariableRefactoring = refactoringProvider.get();
				if(introduceVariableRefactoring.initialize(editor, expression)) {
					ITextRegion region = locationInFileProvider.getFullTextRegion(expression);
					editor.selectAndReveal(region.getOffset(), region.getLength());
					ExtractVariableWizard wizard = new ExtractVariableWizard(introduceVariableRefactoring);
					RefactoringWizardOpenOperation_NonForking openOperation = new RefactoringWizardOpenOperation_NonForking(
							wizard);
					openOperation.run(editor.getSite().getShell(), "Extract Local Variable");
				}
			}
		}
	} catch (InterruptedException e) {
		return null;
	} catch (Exception exc) {
		LOG.error("Error during refactoring", exc);
		MessageDialog.openError(Display.getCurrent().getActiveShell(), "Error during refactoring", exc.getMessage()
				+ "\nSee log for details");
	}
	return null;
}
 
Example 4
Source File: TypeChooser.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected void revealInEditor(XtextEditor activeXtextEditor, Iterable<TypeUsage> usages, final XtextResource resource) {
	boolean isRevealUsages = activeXtextEditor.getDocument().priorityReadOnly(new IUnitOfWork<Boolean, XtextResource>() {
		@Override
		public Boolean exec(XtextResource state) throws Exception {
			return state.getURI().equals(resource.getURI());
		}
	});
	if(isRevealUsages) {
		originalSelection = activeXtextEditor.getSelectionProvider().getSelection();
		ITextRegion firstOccurrence = usages.iterator().next().getTextRegion();
		activeXtextEditor.selectAndReveal(firstOccurrence.getOffset(), firstOccurrence.getLength());
	}
}
 
Example 5
Source File: ExtractMethodHandler.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
protected void updateSelection(final XtextEditor editor, List<XExpression> expressions) {
	ICompositeNode firstNode = NodeModelUtils.getNode(expressions.get(0));
	ICompositeNode lastNode = NodeModelUtils.getNode(expressions.get(expressions.size() - 1));
	if (firstNode != null && lastNode != null) {
		int correctedSelectionOffset = firstNode.getOffset();
		int correctedSelectionLength = lastNode.getEndOffset() - correctedSelectionOffset;
		editor.selectAndReveal(correctedSelectionOffset, correctedSelectionLength);
	}
}
 
Example 6
Source File: ExternalEditorTest.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
private void clickAtHyperlinkAt(XtextEditor editor, int offset) {
	editor.selectAndReveal(offset, 0);
	IHyperlink[] hyperlinks = detector.detectHyperlinks(editor.getInternalSourceViewer(),
			new Region(((ITextSelection) editor.getSelectionProvider().getSelection()).getOffset(), 0), false);
	hyperlinks[0].open();
}