Java Code Examples for org.eclipse.xtext.ui.editor.XtextEditor#getSelectionProvider()
The following examples show how to use
org.eclipse.xtext.ui.editor.XtextEditor#getSelectionProvider() .
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: MarkOccurrencesTest.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
@Test public void testMarkOccurrencesCrossFile() throws Exception { String model1 = "Zonk { Bar(Foo) {} Baz(Foo Bar) {} }"; String model2 = "Foo {}"; IFile modelFile1 = IResourcesSetupUtil.createFile("MarkOccurrencesTest/src/Test1.outlinetestlanguage", model1); IResourcesSetupUtil.createFile("MarkOccurrencesTest/src/Test2.outlinetestlanguage", model2); IResourcesSetupUtil.waitForBuild(); XtextEditor editor = openEditor(modelFile1); ISelectionProvider selectionProvider = editor.getSelectionProvider(); selectionProvider.setSelection(new TextSelection(model1.indexOf("Foo"), 1)); IAnnotationModel annotationModel = editor.getDocumentProvider().getAnnotationModel(editor.getEditorInput()); ExpectationBuilder listener = new ExpectationBuilder(editor, annotationModel) .added(OCCURRENCE_ANNOTATION_TYPE, model1.indexOf("Foo", 3), 3) .added(OCCURRENCE_ANNOTATION_TYPE, model1.lastIndexOf("Foo"), 3); listener.start(); annotationModel.addAnnotationModelListener(listener); setMarkOccurrences(true); listener.verify(TIMEOUT); }
Example 2
Source File: MarkOccurrencesTest.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
@Test public void testMarkOccurrences() throws Exception { String model = "Foo { Bar(Foo) {} Baz(Foo Bar) {} }"; IFile modelFile = IResourcesSetupUtil.createFile("MarkOccurrencesTest/src/Test.outlinetestlanguage", model); XtextEditor editor = openEditor(modelFile); ISelectionProvider selectionProvider = editor.getSelectionProvider(); selectionProvider.setSelection(new TextSelection(0, 1)); IAnnotationModel annotationModel = editor.getDocumentProvider().getAnnotationModel(editor.getEditorInput()); ExpectationBuilder listener = new ExpectationBuilder(editor, annotationModel).added(DECLARATION_ANNOTATION_TYPE, 0, 3) .added(OCCURRENCE_ANNOTATION_TYPE, model.indexOf("Foo", 3), 3) .added(OCCURRENCE_ANNOTATION_TYPE, model.lastIndexOf("Foo"), 3); listener.start(); annotationModel.addAnnotationModelListener(listener); setMarkOccurrences(true); listener.verify(TIMEOUT); listener.start(); listener.removed(DECLARATION_ANNOTATION_TYPE, 0, 3) .removed(OCCURRENCE_ANNOTATION_TYPE, model.indexOf("Foo", 3), 3) .removed(OCCURRENCE_ANNOTATION_TYPE, model.lastIndexOf("Foo"), 3) .added(DECLARATION_ANNOTATION_TYPE, model.indexOf("Bar"), 3) .added(OCCURRENCE_ANNOTATION_TYPE, model.lastIndexOf("Bar"), 3); selectionProvider.setSelection(new TextSelection(model.lastIndexOf("Bar"), 1)); listener.verify(TIMEOUT); listener.start(); listener.removed(DECLARATION_ANNOTATION_TYPE, model.indexOf("Bar"), 3).removed(OCCURRENCE_ANNOTATION_TYPE, model.lastIndexOf("Bar"), 3); setMarkOccurrences(false); listener.verify(TIMEOUT); }
Example 3
Source File: RailroadSelectionLinker.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
public void setXtextEditor(XtextEditor xtextEditor) { if (currentEditor != null) { removeTextSelectionListener(currentEditor); } if (XTEXT_LANGUAGE_NAME.equals(xtextEditor.getLanguageName())) { currentEditor = xtextEditor; ISelectionProvider selectionProvider = xtextEditor.getSelectionProvider(); if (selectionProvider instanceof IPostSelectionProvider) ((IPostSelectionProvider) selectionProvider) .addPostSelectionChangedListener(textSelectionChangeListener); else selectionProvider.addSelectionChangedListener(textSelectionChangeListener); } }
Example 4
Source File: RailroadSelectionLinker.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
protected void removeTextSelectionListener(XtextEditor editor) { ISelectionProvider selectionProvider = editor.getSelectionProvider(); if (selectionProvider != null) { if (selectionProvider instanceof IPostSelectionProvider) ((IPostSelectionProvider) selectionProvider) .removePostSelectionChangedListener(textSelectionChangeListener); else selectionProvider.removeSelectionChangedListener(textSelectionChangeListener); } }