Skip to content

Commit

Permalink
update InlinedAnnotationDemo to get rid off depricated methods
Browse files Browse the repository at this point in the history
Signed-off-by: Oleksandr Krutko <[email protected]>
  • Loading branch information
arsenalzp authored and mickaelistria committed Jan 29, 2024
1 parent ce26ac0 commit 09d20e2
Showing 1 changed file with 57 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.eclipse.jface.text.source.AnnotationModel;
import org.eclipse.jface.text.source.AnnotationPainter;
import org.eclipse.jface.text.source.IAnnotationAccess;
import org.eclipse.jface.text.source.IAnnotationAccessExtension;
import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.jface.text.source.SourceViewer;
import org.eclipse.jface.text.source.inlined.AbstractInlinedAnnotation;
Expand All @@ -41,7 +42,10 @@
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Device;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

Expand Down Expand Up @@ -105,6 +109,58 @@ public void reconcile(DirtyRegion dirtyRegion, IRegion subRegion) {
display.dispose();
}

/**
* Create annotation access by implementing annotation access extension.
*
* @return annotation access.
*/
private static class AnnotationAccessExtension implements IAnnotationAccess, IAnnotationAccessExtension {

@Override
public String getTypeLabel(Annotation annotation) {
return annotation.getText();
}

@Override
public int getLayer(Annotation annotation) {
return IAnnotationAccessExtension.DEFAULT_LAYER;
}

@Override
public void paint(Annotation annotation, GC gc, Canvas canvas, Rectangle bounds) {
}

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

@Override
public boolean isSubtype(Object annotationType, Object potentialSupertype) {
return false;
}

@Override
public Object[] getSupertypes(Object annotationType) {
return null;
}

@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;
}

}
/**
* Create annotation painter.
*
Expand All @@ -113,24 +169,7 @@ public void reconcile(DirtyRegion dirtyRegion, IRegion subRegion) {
* @return annotation painter.
*/
private static AnnotationPainter createAnnotationPainter(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);
AnnotationPainter painter = new AnnotationPainter(viewer, new AnnotationAccessExtension());
((ITextViewerExtension2) viewer).addPainter(painter);
return painter;
}
Expand Down

0 comments on commit 09d20e2

Please sign in to comment.