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();
}
}
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();
}
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();
}
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);
}
Aggregations