Search in sources :

Example 1 with AnnotationBag

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

the class DefaultMarkerAnnotationAccess method getImage.

/**
 * Returns the image for the given annotation and the given annotation preferences or
 * <code>null</code> if there is no such image.
 *
 * @param annotation the annotation
 * @param preference the annotation preference
 * @param annotationType the annotation type
 * @return the image or <code>null</code>
 * @since 3.0
 */
private Image getImage(Annotation annotation, AnnotationPreference preference, String annotationType) {
    if (annotation instanceof AnnotationBag) {
        AnnotationBag bag = (AnnotationBag) annotation;
        if (!bag.isEmpty())
            annotation = bag.iterator().next();
    }
    ImageRegistry registry = EditorsPlugin.getDefault().getImageRegistry();
    IAnnotationImageProvider annotationImageProvider = preference.getAnnotationImageProvider();
    if (annotationImageProvider != null) {
        Image image = annotationImageProvider.getManagedImage(annotation);
        if (image != null)
            return image;
        String id = annotationImageProvider.getImageDescriptorId(annotation);
        if (id != null) {
            image = registry.get(id);
            if (image == null) {
                ImageDescriptor descriptor = annotationImageProvider.getImageDescriptor(id);
                registry.put(id, descriptor);
                image = registry.get(id);
            }
            return image;
        }
    }
    if (annotationType == null)
        return null;
    if (hasQuickFix(annotation)) {
        ImageDescriptor quickFixImageDesc = preference.getQuickFixImageDescriptor();
        if (quickFixImageDesc != null) {
            Image image = registry.get(quickFixImageDesc.toString());
            if (image == null) {
                registry.put(quickFixImageDesc.toString(), quickFixImageDesc);
                image = registry.get(quickFixImageDesc.toString());
            }
            if (image != null)
                return image;
        }
    }
    Image image = registry.get(annotationType);
    if (image == null) {
        ImageDescriptor descriptor = preference.getImageDescriptor();
        if (descriptor != null) {
            registry.put(annotationType, descriptor);
            image = registry.get(annotationType);
        } else {
            String symbolicImageName = preference.getSymbolicImageName();
            if (symbolicImageName != null) {
                String key = getSharedImageName(preference.getSymbolicImageName());
                if (key != null) {
                    ISharedImages sharedImages = PlatformUI.getWorkbench().getSharedImages();
                    image = sharedImages.getImage(key);
                }
            }
        }
    }
    return image;
}
Also used : AnnotationBag(org.eclipse.jface.text.source.projection.AnnotationBag) ImageRegistry(org.eclipse.jface.resource.ImageRegistry) ISharedImages(org.eclipse.ui.ISharedImages) ImageDescriptor(org.eclipse.jface.resource.ImageDescriptor) Image(org.eclipse.swt.graphics.Image)

Example 2 with AnnotationBag

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

the class DefaultAnnotationHover method getAnnotationsForLine.

private List<Annotation> getAnnotationsForLine(ISourceViewer viewer, int line) {
    IAnnotationModel model = getAnnotationModel(viewer);
    if (model == null)
        return null;
    IDocument document = viewer.getDocument();
    List<Annotation> javaAnnotations = new ArrayList<>();
    HashMap<Position, Object> messagesAtPosition = new HashMap<>();
    Iterator<Annotation> iterator = model.getAnnotationIterator();
    while (iterator.hasNext()) {
        Annotation annotation = iterator.next();
        Position position = model.getPosition(annotation);
        if (position == null)
            continue;
        if (!isRulerLine(position, document, line))
            continue;
        if (annotation instanceof AnnotationBag) {
            AnnotationBag bag = (AnnotationBag) annotation;
            Iterator<Annotation> e = bag.iterator();
            while (e.hasNext()) {
                annotation = e.next();
                position = model.getPosition(annotation);
                if (position != null && includeAnnotation(annotation, position, messagesAtPosition))
                    javaAnnotations.add(annotation);
            }
            continue;
        }
        if (includeAnnotation(annotation, position, messagesAtPosition))
            javaAnnotations.add(annotation);
    }
    return javaAnnotations;
}
Also used : AnnotationBag(org.eclipse.jface.text.source.projection.AnnotationBag) Position(org.eclipse.jface.text.Position) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IDocument(org.eclipse.jface.text.IDocument)

Aggregations

AnnotationBag (org.eclipse.jface.text.source.projection.AnnotationBag)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 ImageDescriptor (org.eclipse.jface.resource.ImageDescriptor)1 ImageRegistry (org.eclipse.jface.resource.ImageRegistry)1 IDocument (org.eclipse.jface.text.IDocument)1 Position (org.eclipse.jface.text.Position)1 Image (org.eclipse.swt.graphics.Image)1 ISharedImages (org.eclipse.ui.ISharedImages)1