Search in sources :

Example 1 with ISourceViewerExtension5

use of org.eclipse.jface.text.source.ISourceViewerExtension5 in project eclipse.platform.text by eclipse.

the class SourceViewerDecorationSupport method showAnnotations.

/**
 * Enables annotations in the source viewer for the given annotation type.
 *
 * @param annotationType the annotation type
 * @param updatePainter if <code>true</code> update the annotation painter
 * @since 3.0
 */
private void showAnnotations(Object annotationType, boolean updatePainter) {
    if (fSourceViewer instanceof ITextViewerExtension2) {
        if (fAnnotationPainter == null) {
            fAnnotationPainter = createAnnotationPainter();
            if (fSourceViewer instanceof ITextViewerExtension4)
                ((ITextViewerExtension4) fSourceViewer).addTextPresentationListener(fAnnotationPainter);
            ITextViewerExtension2 extension = (ITextViewerExtension2) fSourceViewer;
            extension.addPainter(fAnnotationPainter);
            if (fSourceViewer instanceof ISourceViewerExtension5)
                ((ISourceViewerExtension5) fSourceViewer).setCodeMiningAnnotationPainter(fAnnotationPainter);
        }
        fAnnotationPainter.setAnnotationTypeColor(annotationType, getAnnotationTypeColor(annotationType));
        Object decorationType = getAnnotationDecorationType(annotationType);
        if (decorationType != null)
            fAnnotationPainter.addAnnotationType(annotationType, decorationType);
        else
            fAnnotationPainter.addHighlightAnnotationType(annotationType);
        if (updatePainter)
            updateAnnotationPainter();
    }
}
Also used : ITextViewerExtension2(org.eclipse.jface.text.ITextViewerExtension2) ITextViewerExtension4(org.eclipse.jface.text.ITextViewerExtension4) ISourceViewerExtension5(org.eclipse.jface.text.source.ISourceViewerExtension5)

Example 2 with ISourceViewerExtension5

use of org.eclipse.jface.text.source.ISourceViewerExtension5 in project eclipse.platform.text by eclipse.

the class CodeMiningDemo method main.

public static void main(String[] args) throws Exception {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setLayout(new FillLayout());
    shell.setText("Code Mining demo");
    ISourceViewer sourceViewer = new SourceViewer(shell, null, SWT.V_SCROLL | SWT.BORDER);
    sourceViewer.setDocument(new Document("// Type class & new keyword and see references CodeMining\n" + "// Name class with a number N to emulate Nms before resolving the references CodeMining \n\n" + "class A\n" + "new A\n" + "new A\n\n" + "class 5\n" + "new 5\n" + "new 5\n" + "new 5"), new AnnotationModel());
    // Add AnnotationPainter (required by CodeMining)
    addAnnotationPainter(sourceViewer);
    // Initialize codemining providers
    ((ISourceViewerExtension5) sourceViewer).setCodeMiningProviders(new ICodeMiningProvider[] { new ClassReferenceCodeMiningProvider(), new ClassImplementationsCodeMiningProvider() });
    // Execute codemining in a reconciler
    MonoReconciler reconciler = new MonoReconciler(new IReconcilingStrategy() {

        @Override
        public void setDocument(IDocument document) {
            ((ISourceViewerExtension5) sourceViewer).updateCodeMinings();
        }

        @Override
        public void reconcile(DirtyRegion dirtyRegion, IRegion subRegion) {
        }

        @Override
        public void reconcile(IRegion partition) {
            ((ISourceViewerExtension5) sourceViewer).updateCodeMinings();
        }
    }, false);
    reconciler.install(sourceViewer);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}
Also used : ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) SourceViewer(org.eclipse.jface.text.source.SourceViewer) ISourceViewerExtension5(org.eclipse.jface.text.source.ISourceViewerExtension5) FillLayout(org.eclipse.swt.layout.FillLayout) Document(org.eclipse.jface.text.Document) IDocument(org.eclipse.jface.text.IDocument) MonoReconciler(org.eclipse.jface.text.reconciler.MonoReconciler) IRegion(org.eclipse.jface.text.IRegion) Shell(org.eclipse.swt.widgets.Shell) IReconcilingStrategy(org.eclipse.jface.text.reconciler.IReconcilingStrategy) AnnotationModel(org.eclipse.jface.text.source.AnnotationModel) DirtyRegion(org.eclipse.jface.text.reconciler.DirtyRegion) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) IDocument(org.eclipse.jface.text.IDocument) Display(org.eclipse.swt.widgets.Display)

Example 3 with ISourceViewerExtension5

use of org.eclipse.jface.text.source.ISourceViewerExtension5 in project eclipse.platform.text by eclipse.

the class AbstractTextEditor method initializeSourceViewer.

/**
 * Initializes the editor's source viewer based on the given editor input.
 *
 * @param input the editor input to be used to initialize the source viewer
 */
private void initializeSourceViewer(IEditorInput input) {
    IDocumentProvider documentProvider = getDocumentProvider();
    IAnnotationModel model = documentProvider.getAnnotationModel(input);
    IDocument document = documentProvider.getDocument(input);
    if (document != null) {
        fSourceViewer.setDocument(document, model);
        fSourceViewer.setEditable(isEditable());
        fSourceViewer.showAnnotations(model != null);
    }
    if (fElementStateListener instanceof IElementStateListenerExtension) {
        boolean isStateValidated = false;
        if (documentProvider instanceof IDocumentProviderExtension)
            isStateValidated = ((IDocumentProviderExtension) documentProvider).isStateValidated(input);
        IElementStateListenerExtension extension = (IElementStateListenerExtension) fElementStateListener;
        extension.elementStateValidationChanged(input, isStateValidated);
    }
    if (fInitialCaret == null)
        fInitialCaret = fSourceViewer.getTextWidget().getCaret();
    if (fIsOverwriting)
        fSourceViewer.getTextWidget().invokeAction(ST.TOGGLE_OVERWRITE);
    handleInsertModeChanged();
    if (isTabsToSpacesConversionEnabled())
        installTabsToSpacesConverter();
    if (fSourceViewer instanceof ITextViewerExtension8) {
        IPreferenceStore store = getPreferenceStore();
        EnrichMode mode = store != null ? convertEnrichModePreference(store.getInt(PREFERENCE_HOVER_ENRICH_MODE)) : EnrichMode.AFTER_DELAY;
        ((ITextViewerExtension8) fSourceViewer).setHoverEnrichMode(mode);
    }
    if (fSourceViewer instanceof ISourceViewerExtension5)
        installCodeMiningProviders();
}
Also used : ITextViewerExtension8(org.eclipse.jface.text.ITextViewerExtension8) ISourceViewerExtension5(org.eclipse.jface.text.source.ISourceViewerExtension5) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) EnrichMode(org.eclipse.jface.text.ITextViewerExtension8.EnrichMode) IDocument(org.eclipse.jface.text.IDocument)

Example 4 with ISourceViewerExtension5

use of org.eclipse.jface.text.source.ISourceViewerExtension5 in project eclipse.platform.text by eclipse.

the class CodeMiningDemo method addAnnotationPainter.

private static void addAnnotationPainter(ISourceViewer viewer) {
    IAnnotationAccess annotationAccess = new IAnnotationAccess() {

        @Override
        public Object getType(Annotation annotation) {
            return annotation.getType();
        }

        @Override
        public boolean isMultiLine(Annotation annotation) {
            return true;
        }

        @Override
        public boolean isTemporary(Annotation annotation) {
            return true;
        }
    };
    AnnotationPainter painter = new AnnotationPainter(viewer, annotationAccess);
    ((ITextViewerExtension2) viewer).addPainter(painter);
    // Register this annotation painter as CodeMining annotation painter.
    ((ISourceViewerExtension5) viewer).setCodeMiningAnnotationPainter(painter);
}
Also used : ITextViewerExtension2(org.eclipse.jface.text.ITextViewerExtension2) IAnnotationAccess(org.eclipse.jface.text.source.IAnnotationAccess) ISourceViewerExtension5(org.eclipse.jface.text.source.ISourceViewerExtension5) AnnotationPainter(org.eclipse.jface.text.source.AnnotationPainter) Annotation(org.eclipse.jface.text.source.Annotation)

Aggregations

ISourceViewerExtension5 (org.eclipse.jface.text.source.ISourceViewerExtension5)4 IDocument (org.eclipse.jface.text.IDocument)2 ITextViewerExtension2 (org.eclipse.jface.text.ITextViewerExtension2)2 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)1 Document (org.eclipse.jface.text.Document)1 IRegion (org.eclipse.jface.text.IRegion)1 ITextViewerExtension4 (org.eclipse.jface.text.ITextViewerExtension4)1 ITextViewerExtension8 (org.eclipse.jface.text.ITextViewerExtension8)1 EnrichMode (org.eclipse.jface.text.ITextViewerExtension8.EnrichMode)1 DirtyRegion (org.eclipse.jface.text.reconciler.DirtyRegion)1 IReconcilingStrategy (org.eclipse.jface.text.reconciler.IReconcilingStrategy)1 MonoReconciler (org.eclipse.jface.text.reconciler.MonoReconciler)1 Annotation (org.eclipse.jface.text.source.Annotation)1 AnnotationModel (org.eclipse.jface.text.source.AnnotationModel)1 AnnotationPainter (org.eclipse.jface.text.source.AnnotationPainter)1 IAnnotationAccess (org.eclipse.jface.text.source.IAnnotationAccess)1 IAnnotationModel (org.eclipse.jface.text.source.IAnnotationModel)1 ISourceViewer (org.eclipse.jface.text.source.ISourceViewer)1 SourceViewer (org.eclipse.jface.text.source.SourceViewer)1 FillLayout (org.eclipse.swt.layout.FillLayout)1