Search in sources :

Example 1 with ISourceViewerAware

use of org.eclipse.xtext.ui.editor.ISourceViewerAware in project xtext-eclipse by eclipse.

the class XtextReconciler method install.

@Override
public void install(ITextViewer textViewer) {
    if (!isInstalled) {
        this.textViewer = textViewer;
        textInputListener = new TextInputListener();
        textViewer.addTextInputListener(textInputListener);
        handleInputDocumentChanged(null, textViewer.getDocument());
        if (textViewer instanceof ISourceViewerExtension4) {
            ContentAssistantFacade facade = ((ISourceViewerExtension4) textViewer).getContentAssistantFacade();
            if (facade == null) {
                shouldInstallCompletionListener = true;
            } else {
                facade.addCompletionListener(documentListener);
            }
            if (strategy instanceof ISourceViewerAware) {
                ((ISourceViewerAware) strategy).setSourceViewer((ISourceViewer) textViewer);
            }
        }
        isInstalled = true;
    }
}
Also used : ISourceViewerAware(org.eclipse.xtext.ui.editor.ISourceViewerAware) ContentAssistantFacade(org.eclipse.jface.text.source.ContentAssistantFacade) ITextInputListener(org.eclipse.jface.text.ITextInputListener) ISourceViewerExtension4(org.eclipse.jface.text.source.ISourceViewerExtension4)

Example 2 with ISourceViewerAware

use of org.eclipse.xtext.ui.editor.ISourceViewerAware in project n4js by eclipse.

the class N4JSHyperlinkDetector method detectHyperlinks.

/**
 * Method copied from super class with only a minor change: call to "readOnly" changed to "tryReadOnly".
 */
@Override
public IHyperlink[] detectHyperlinks(final ITextViewer textViewer, final IRegion region, final boolean canShowMultipleHyperlinks) {
    final IDocument xtextDocument = textViewer.getDocument();
    if (!(xtextDocument instanceof N4JSDocument)) {
        return super.detectHyperlinks(textViewer, region, canShowMultipleHyperlinks);
    }
    final IHyperlinkHelper helper = getHelper();
    return ((N4JSDocument) xtextDocument).tryReadOnly(new IUnitOfWork<IHyperlink[], XtextResource>() {

        @Override
        public IHyperlink[] exec(XtextResource resource) throws Exception {
            if (resource == null) {
                return null;
            }
            if (helper instanceof ISourceViewerAware && textViewer instanceof ISourceViewer) {
                ((ISourceViewerAware) helper).setSourceViewer((ISourceViewer) textViewer);
            }
            return helper.createHyperlinksByOffset(resource, region.getOffset(), canShowMultipleHyperlinks);
        }
    }, null);
}
Also used : IHyperlinkHelper(org.eclipse.xtext.ui.editor.hyperlinking.IHyperlinkHelper) ISourceViewerAware(org.eclipse.xtext.ui.editor.ISourceViewerAware) XtextResource(org.eclipse.xtext.resource.XtextResource) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) IDocument(org.eclipse.jface.text.IDocument)

Aggregations

ISourceViewerAware (org.eclipse.xtext.ui.editor.ISourceViewerAware)2 IDocument (org.eclipse.jface.text.IDocument)1 ITextInputListener (org.eclipse.jface.text.ITextInputListener)1 ContentAssistantFacade (org.eclipse.jface.text.source.ContentAssistantFacade)1 ISourceViewer (org.eclipse.jface.text.source.ISourceViewer)1 ISourceViewerExtension4 (org.eclipse.jface.text.source.ISourceViewerExtension4)1 XtextResource (org.eclipse.xtext.resource.XtextResource)1 IHyperlinkHelper (org.eclipse.xtext.ui.editor.hyperlinking.IHyperlinkHelper)1