org.eclipse.xtext.ui.editor.XtextSourceViewer Java Examples

The following examples show how to use org.eclipse.xtext.ui.editor.XtextSourceViewer. 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: DirtyStateEditorSupportIntegrationTest.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=354123
 */
@Test
public void testUndoRedo() throws Exception {
	pushKey('a', 0);
	Assert.assertEquals(1, events.size());
	Assert.assertEquals("fooa", getFirstExportedObjectInLastEventDelta()
			.getQualifiedName().getLastSegment());
	IUndoManager undoManager = ((XtextSourceViewer) editor.getInternalSourceViewer()).getUndoManager();
	undoManager.undo();
	syncUtil.yieldToQueuedDisplayJobs(new NullProgressMonitor());
	syncUtil.waitForReconciler(editor);
	Assert.assertEquals(2, events.size());
	Assert.assertNull(Iterables.getLast(events).getDeltas().get(0).getNew());
	undoManager.redo();
	syncUtil.yieldToQueuedDisplayJobs(new NullProgressMonitor());
	syncUtil.waitForReconciler(editor);
	Assert.assertEquals(3, events.size());
	Assert.assertEquals("fooa", getFirstExportedObjectInLastEventDelta()
			.getQualifiedName().getLastSegment());
	Iterables.getLast(events);
}
 
Example #2
Source File: XtextStyledTextHighlightingHelper.java    From statecharts with Eclipse Public License 1.0 6 votes vote down vote up
public void install(StyledTextXtextAdapter styledTextXtextAdapter,
		XtextSourceViewer sourceViewer) {
	this.styledTextXtextAdapter = styledTextXtextAdapter;
	fSourceViewer = sourceViewer;
	if (styledTextXtextAdapter != null) {
		fConfiguration = styledTextXtextAdapter
				.getXtextSourceViewerConfiguration();
		fPresentationReconciler = (XtextPresentationReconciler) fConfiguration
				.getPresentationReconciler(sourceViewer);
	} else {
		fConfiguration = null;
		fPresentationReconciler = null;
	}
	preferenceStore = getPreferenceStoreAccessor().getPreferenceStore();
	preferenceStore.addPropertyChangeListener(this);
	enable();
}
 
Example #3
Source File: FixedHighlightingReconciler.java    From dsl-devkit with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Install this reconciler on the given editor and presenter.
 *
 * @param editor
 *          the editor
 * @param sourceViewer
 *          the source viewer
 * @param presenter
 *          the highlighting presenter
 */
@Override
public void install(final XtextEditor editor, final XtextSourceViewer sourceViewer, final HighlightingPresenter presenter) {
  synchronized (fReconcileLock) {
    cleanUpAfterReconciliation = false; // prevents a potentially already running reconciliation process to clean up after itself
  }
  this.presenter = presenter;
  this.editor = editor;
  this.sourceViewer = sourceViewer;
  if (oldCalculator != null || newCalculator != null) {
    if (editor == null) {
      ((IXtextDocument) sourceViewer.getDocument()).addModelListener(this);
    } else if (editor.getDocument() != null) {
      editor.getDocument().addModelListener(this);
    }

    sourceViewer.addTextInputListener(this);
  }
  refresh();
}
 
Example #4
Source File: XtextDocumentUtil.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * @deprecated Inject an instance of {@link XtextDocumentUtil} instead and use {@code getXtextDocument(..)}
 * instead. This allows to override the lookup of documents.
 */
@Deprecated
public static IXtextDocument get(Object ctx) {
	if (ctx instanceof IXtextDocument)
		return (IXtextDocument) ctx;
	if (ctx instanceof ProjectionDocument)
		return get(((ProjectionDocument) ctx).getMasterDocument());
	if (ctx instanceof XtextSourceViewer)
		return ((XtextSourceViewer) ctx).getXtextDocument();
	if (ctx instanceof ITextViewer)
		return get(((ITextViewer) ctx).getDocument());
	if (ctx instanceof XtextEditor)
		return ((XtextEditor) ctx).getDocument();
	if (ctx instanceof IFile) {
		IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
		return get(activePage.findEditor(new FileEditorInput((IFile) ctx)));
	}
	return null;
}
 
Example #5
Source File: AbstractMultiQuickfixTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected ICompletionProposal[] computeQuickAssistProposals(XtextEditor editor, int offset) {
	IResourcesSetupUtil.waitForBuild();
	XtextSourceViewer sourceViewer = (XtextSourceViewer) editor.getInternalSourceViewer();
	QuickAssistAssistant quickAssistAssistant = (QuickAssistAssistant) sourceViewer.getQuickAssistAssistant();
	IQuickAssistProcessor quickAssistProcessor = quickAssistAssistant.getQuickAssistProcessor();
	ICompletionProposal[] quickAssistProposals = quickAssistProcessor
			.computeQuickAssistProposals(new TextInvocationContext(sourceViewer, offset, -1));
	return quickAssistProposals;
}
 
Example #6
Source File: SARLSourceViewer.java    From sarl with Apache License 2.0 5 votes vote down vote up
@Override
public XtextSourceViewer createSourceViewer(Composite parent, IVerticalRuler ruler,
		IOverviewRuler overviewRuler, boolean showsAnnotationOverview, int styles) {
	final SARLSourceViewer result = new SARLSourceViewer(parent, ruler, overviewRuler, showsAnnotationOverview, styles);
	try {
		final Field field = RichStringAwareSourceViewer.class.getDeclaredField("merger"); //$NON-NLS-1$
		field.setAccessible(true);
		field.set(result, this.merger);
	} catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException exception) {
		Exceptions.sneakyThrow(exception);
	}
	this.memberInjector.injectMembers(result);
	return result;
}
 
Example #7
Source File: XtextStyledTextHighlightingReconciler.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Install this reconciler on the given editor and presenter.
 * 
 * @param editor
 *            the editor
 * @param sourceViewer
 *            the source viewer
 * @param presenter
 *            the highlighting presenter
 */
public void install(StyledTextXtextAdapter xtextStyledText, XtextSourceViewer sourceViewer,
		HighlightingPresenter presenter) {
	this.presenter = presenter;
	this.styledTextXtextAdapter = xtextStyledText;
	this.sourceViewer = sourceViewer;
	if (calculator != null) {
		if (styledTextXtextAdapter.getXtextDocument() != null)
			styledTextXtextAdapter.getXtextDocument().addModelListener(this);

		sourceViewer.addTextInputListener(this);
	}
	refresh();
}
 
Example #8
Source File: StyledTextXtextAdapter.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
protected XtextSourceViewer createXtextSourceViewer() {
	final XtextSourceViewer result = new XtextSourceViewerEx(getStyledText(),
			getPreferenceStoreAccess().getPreferenceStore());
	result.configure(getXtextSourceViewerConfiguration());
	result.setDocument(getXtextDocument(), new AnnotationModel());
	return result;
}
 
Example #9
Source File: RichStringAwareSourceViewer.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public XtextSourceViewer createSourceViewer(Composite parent, IVerticalRuler ruler,
		IOverviewRuler overviewRuler, boolean showsAnnotationOverview, int styles) {
	RichStringAwareSourceViewer result = new RichStringAwareSourceViewer(parent, ruler, overviewRuler, showsAnnotationOverview, styles);
	result.merger = merger;
	return result;
}
 
Example #10
Source File: DotProposalProviderDelegator.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
private ISourceViewer getSourceViewer(Shell shell,
		final IXtextDocument xtextDocument,
		XtextSourceViewerConfiguration configuration) {
	XtextSourceViewer.Factory factory = get(
			XtextSourceViewer.Factory.class);
	ISourceViewer sourceViewer = factory.createSourceViewer(shell, null,
			null, false, 0);
	sourceViewer.configure(configuration);
	sourceViewer.setDocument(xtextDocument);
	return sourceViewer;
}
 
Example #11
Source File: ContentAssistProcessorTestBuilder.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected ISourceViewer getSourceViewer(Shell shell, final IXtextDocument xtextDocument,
		XtextSourceViewerConfiguration configuration) {
	XtextSourceViewer.Factory factory = get(XtextSourceViewer.Factory.class);
	ISourceViewer sourceViewer = factory.createSourceViewer(shell, null, null, false, 0);
	sourceViewer.configure(configuration);
	sourceViewer.setDocument(xtextDocument);
	return sourceViewer;
}
 
Example #12
Source File: JSDocContentAssistProcessor.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int offset) {
	if (viewer instanceof XtextSourceViewer) {
		IXtextDocument document = (IXtextDocument) viewer.getDocument();
		return document.priorityReadOnly(createCompletionProposalComputer(viewer, offset));
	}

	return new ICompletionProposal[0];
}
 
Example #13
Source File: ContentAssistProcessorTestBuilder.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected ISourceViewer getSourceViewer(Shell shell, final IXtextDocument xtextDocument,
		XtextSourceViewerConfiguration configuration) {
	XtextSourceViewer.Factory factory = get(XtextSourceViewer.Factory.class);
	ISourceViewer sourceViewer = factory.createSourceViewer(shell, null, null, false, 0);
	sourceViewer.configure(configuration);
	sourceViewer.setDocument(xtextDocument);
	return sourceViewer;
}
 
Example #14
Source File: HighlightingReconciler.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Refreshes the highlighting.
 */
public void refresh() {
	if (oldCalculator != null || newCalculator != null) {
		new Job("calculating highlighting") {
			@Override
			protected IStatus run(IProgressMonitor monitor) {
				XtextSourceViewer mySourceViewer = sourceViewer;
				if (mySourceViewer != null) {
					IXtextDocument document = mySourceViewer.getXtextDocument();
					if (document != null) {
						document.tryReadOnly(new CancelableUnitOfWork<Void,XtextResource>() {
							@Override
							public java.lang.Void exec(XtextResource state, CancelIndicator cancelIndicator)
									throws Exception {
								beforeRefresh(state, cancelIndicator);
								modelChanged(state, cancelIndicator);
								return null;
							}
						});
					}
				}
				return Status.OK_STATUS;
			}
		}.schedule();
	} else {
		Display display = getDisplay();
		display.asyncExec(presenter.createSimpleUpdateRunnable());
	}
}
 
Example #15
Source File: HighlightingHelper.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @since 2.3
 */
public void install(XtextSourceViewerConfiguration configuration, XtextSourceViewer sourceViewer) {
	fSourceViewer= sourceViewer;
	fConfiguration= configuration;
	if(sourceViewer != null && configuration != null){
		fPresentationReconciler= (XtextPresentationReconciler) fConfiguration.getPresentationReconciler(sourceViewer);
	} else {
		fPresentationReconciler = null;
		fConfiguration = null;
	}
	preferenceStore = getPreferenceStoreAccessor().getPreferenceStore();
	preferenceStore.addPropertyChangeListener(this);
	enable();
}
 
Example #16
Source File: HighlightingHelper.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void install(XtextEditor editor, XtextSourceViewer sourceViewer) {
	fEditor= editor;
	if (fEditor != null) {
		install(editor.getXtextSourceViewerConfiguration(), sourceViewer) ;
	}
}
 
Example #17
Source File: XtextDocumentUtil.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @since 2.19
 */
public IXtextDocument getXtextDocument(ITextViewer viewer) {
	if (viewer instanceof XtextSourceViewer) {
		return ((XtextSourceViewer) viewer).getXtextDocument();
	}
	return getXtextDocument(viewer.getDocument());
}
 
Example #18
Source File: InvalidatingHighlightingHelper.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void propertyChange(PropertyChangeEvent event) {
	super.propertyChange(event);
	XtextEditor editor = myEditor;
	XtextSourceViewer sourceViewer = mySourceViewer;
	if (editor instanceof N4JSEditor && sourceViewer != null
			&& event.getProperty().contains(".syntaxColorer.tokenStyles")) {
		((N4JSEditor) editor).initializeViewerColors(sourceViewer);
		sourceViewer.invalidateTextPresentation();
	}
}
 
Example #19
Source File: SpellingQuickfixTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected ICompletionProposal[] computeQuickAssistProposals(int offset) {
	XtextSourceViewer sourceViewer = getSourceViewer();
	XtextReconciler reconciler = (XtextReconciler) sourceViewer.getAdapter(IReconciler.class);
	IReconcilingStrategyExtension reconcilingStrategyExtension = (IReconcilingStrategyExtension) reconciler.getReconcilingStrategy("");
	reconcilingStrategyExtension.initialReconcile();
	QuickAssistAssistant quickAssistAssistant = (QuickAssistAssistant) sourceViewer.getQuickAssistAssistant();
	IQuickAssistProcessor quickAssistProcessor = quickAssistAssistant.getQuickAssistProcessor();
	ICompletionProposal[] quickAssistProposals = quickAssistProcessor
			.computeQuickAssistProposals(new TextInvocationContext(sourceViewer, offset, -1));
	return quickAssistProposals;
}
 
Example #20
Source File: HighlightingReconciler.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Install this reconciler on the given editor and presenter.
 * 
 * @param editor
 *            the editor
 * @param sourceViewer
 *            the source viewer
 * @param presenter
 *            the highlighting presenter
 */
public void install(XtextEditor editor, XtextSourceViewer sourceViewer, HighlightingPresenter presenter) {
	this.presenter = presenter;
	this.editor = editor;
	this.sourceViewer = sourceViewer;
	if (oldCalculator != null || newCalculator != null) {
		if(editor == null){
			sourceViewer.getXtextDocument().addModelListener(this);
		} else if (editor.getDocument() != null)
			editor.getDocument().addModelListener(this);

		sourceViewer.addTextInputListener(this);
	}
	refresh();
}
 
Example #21
Source File: EmbeddedEditor.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
public EmbeddedEditor(XtextDocument document, XtextSourceViewer viewer, XtextSourceViewerConfiguration configuration, IEditedResourceProvider resourceProvider, Runnable afterSetDocumet) {
	this.document = document;
	this.viewer = viewer;
	this.configuration = configuration;
	this.resourceProvider = resourceProvider;
	this.afterSetDocument = afterSetDocumet;
}
 
Example #22
Source File: FixedXtextSourceViewer.java    From dsl-devkit with Eclipse Public License 1.0 4 votes vote down vote up
/** {@inheritDoc} */
@Override
public XtextSourceViewer createSourceViewer(final Composite parent, final IVerticalRuler ruler, final IOverviewRuler overviewRuler, final boolean showsAnnotationOverview, final int styles) {
  return new FixedXtextSourceViewer(parent, ruler, overviewRuler, showsAnnotationOverview, styles);
}
 
Example #23
Source File: InvalidatingHighlightingHelper.java    From n4js with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public void install(XtextEditor editor, XtextSourceViewer sourceViewer) {
	this.myEditor = editor;
	this.mySourceViewer = sourceViewer;
	super.install(editor, sourceViewer);
}
 
Example #24
Source File: AbstractSARLUiModule.java    From sarl with Apache License 2.0 4 votes vote down vote up
public Class<? extends XtextSourceViewer.Factory> bindXtextSourceViewer$Factory() {
	return SARLSourceViewer.Factory.class;
}
 
Example #25
Source File: GamaSourceViewerFactory.java    From gama with GNU General Public License v3.0 4 votes vote down vote up
/**
 * @see org.eclipse.xtext.ui.editor.XtextSourceViewer.Factory#createSourceViewer(org.eclipse.swt.widgets.Composite,
 *      org.eclipse.jface.text.source.IVerticalRuler,
 *      org.eclipse.jface.text.source.IOverviewRuler, boolean, int)
 */
@Override
public XtextSourceViewer createSourceViewer(final Composite parent, final IVerticalRuler ruler,
		final IOverviewRuler overviewRuler, final boolean showsAnnotationOverview, final int styles) {
	return new GamaSourceViewer(parent, ruler, overviewRuler, showsAnnotationOverview, styles);
}
 
Example #26
Source File: GamlUiModule.java    From gama with GNU General Public License v3.0 4 votes vote down vote up
public Class<? extends XtextSourceViewer.Factory> bindSourceViewerFactory() {
	return GamaSourceViewerFactory.class;
}
 
Example #27
Source File: StyledTextXtextAdapter.java    From statecharts with Eclipse Public License 1.0 4 votes vote down vote up
protected XtextSourceViewer getXtextSourceviewer() {
	return this.sourceviewer;
}
 
Example #28
Source File: SpellingQuickfixTest.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
protected XtextSourceViewer getSourceViewer() {
	XtextSourceViewer sourceViewer = (XtextSourceViewer) xtextEditor.getInternalSourceViewer();
	return sourceViewer;
}
 
Example #29
Source File: XtendFormatterPreview.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
public XtextSourceViewer getEditorViewer() {
	checkEditorHandleIsSet();
	return editorHandle.getViewer();
}
 
Example #30
Source File: EmbeddedEditor.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
public XtextSourceViewer getViewer() {
	return this.viewer;
}