Fixed: 1760857 - Avoid refreshing the preview when phpeditor got focus.
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpeclipse / phpeditor / JavaAnnotationImageProvider.java
index 6ec9b9b..ae92cf6 100644 (file)
  *******************************************************************************/
 package net.sourceforge.phpeclipse.phpeditor;
 
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.widgets.Display;
+import net.sourceforge.phpdt.internal.ui.PHPUiImages;
+import net.sourceforge.phpdt.ui.PreferenceConstants;
 
 import org.eclipse.jface.resource.ImageDescriptor;
 import org.eclipse.jface.resource.ImageRegistry;
-
 import org.eclipse.jface.text.source.Annotation;
-
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.Display;
 import org.eclipse.ui.ISharedImages;
 import org.eclipse.ui.PlatformUI;
 import org.eclipse.ui.texteditor.IAnnotationImageProvider;
 
-import net.sourceforge.phpdt.ui.PreferenceConstants;
-
-import net.sourceforge.phpdt.internal.ui.PHPUiImages;
-//import net.sourceforge.phpdt.internal.ui.text.correction.JavaCorrectionProcessor;
-
 /**
  * Image provider for annotations based on Java problem markers.
  * 
  * @since 3.0
  */
 public class JavaAnnotationImageProvider implements IAnnotationImageProvider {
-       
-       private final static int NO_IMAGE= 0;
-       private final static int GRAY_IMAGE= 1;
-       private final static int OVERLAY_IMAGE= 2;
-       private final static int QUICKFIX_IMAGE= 3;
-       private final static int QUICKFIX_ERROR_IMAGE= 4;
-       
-       
+
+       private final static int NO_IMAGE = 0;
+
+       private final static int GRAY_IMAGE = 1;
+
+       private final static int OVERLAY_IMAGE = 2;
+
+       private final static int QUICKFIX_IMAGE = 3;
+
+       private final static int QUICKFIX_ERROR_IMAGE = 4;
+
        private static Image fgQuickFixImage;
+
        private static Image fgQuickFixErrorImage;
+
        private static ImageRegistry fgImageRegistry;
-       
+
        private boolean fShowQuickFixIcon;
+
        private int fCachedImageType;
+
        private Image fCachedImage;
-       
-       
+
        public JavaAnnotationImageProvider() {
-               fShowQuickFixIcon= PreferenceConstants.getPreferenceStore().getBoolean(PreferenceConstants.EDITOR_CORRECTION_INDICATION);
+               fShowQuickFixIcon = PreferenceConstants.getPreferenceStore()
+                               .getBoolean(PreferenceConstants.EDITOR_CORRECTION_INDICATION);
        }
-       
+
        /*
         * @see org.eclipse.jface.text.source.IAnnotationImageProvider#getManagedImage(org.eclipse.jface.text.source.Annotation)
         */
        public Image getManagedImage(Annotation annotation) {
                if (annotation instanceof IJavaAnnotation) {
-                       IJavaAnnotation javaAnnotation= (IJavaAnnotation) annotation;
-                       int imageType= getImageType(javaAnnotation);
+                       IJavaAnnotation javaAnnotation = (IJavaAnnotation) annotation;
+                       int imageType = getImageType(javaAnnotation);
                        return getImage(javaAnnotation, imageType, Display.getCurrent());
                }
                return null;
        }
-       
+
        /*
         * @see org.eclipse.jface.text.source.IAnnotationImageProvider#getImageDescriptorId(org.eclipse.jface.text.source.Annotation)
         */
@@ -82,86 +84,95 @@ public class JavaAnnotationImageProvider implements IAnnotationImageProvider {
                // unmanaged images are not supported
                return null;
        }
-       
-       
+
        private boolean showQuickFix(IJavaAnnotation annotation) {
-       //      return fShowQuickFixIcon && annotation.isProblem() && JavaCorrectionProcessor.hasCorrections(annotation);
-         return false;
+               // return fShowQuickFixIcon && annotation.isProblem() &&
+               // JavaCorrectionProcessor.hasCorrections(annotation);
+               return false;
        }
-       
+
        private Image getQuickFixImage() {
                if (fgQuickFixImage == null)
-                       fgQuickFixImage= PHPUiImages.get(PHPUiImages.IMG_OBJS_FIXABLE_PROBLEM);
+                       fgQuickFixImage = PHPUiImages
+                                       .get(PHPUiImages.IMG_OBJS_FIXABLE_PROBLEM);
                return fgQuickFixImage;
        }
 
        private Image getQuickFixErrorImage() {
                if (fgQuickFixErrorImage == null)
-                       fgQuickFixErrorImage= PHPUiImages.get(PHPUiImages.IMG_OBJS_FIXABLE_ERROR);
+                       fgQuickFixErrorImage = PHPUiImages
+                                       .get(PHPUiImages.IMG_OBJS_FIXABLE_ERROR);
                return fgQuickFixErrorImage;
        }
-       
+
        private ImageRegistry getImageRegistry(Display display) {
                if (fgImageRegistry == null)
-                       fgImageRegistry= new ImageRegistry(display);
+                       fgImageRegistry = new ImageRegistry(display);
                return fgImageRegistry;
        }
-       
+
        private int getImageType(IJavaAnnotation annotation) {
-               int imageType= NO_IMAGE;
+               int imageType = NO_IMAGE;
                if (annotation.hasOverlay())
-                       imageType= OVERLAY_IMAGE;
+                       imageType = OVERLAY_IMAGE;
                else if (!annotation.isMarkedDeleted()) {
                        if (showQuickFix(annotation))
-                               imageType= JavaMarkerAnnotation.ERROR_ANNOTATION_TYPE.equals(annotation.getType()) ? QUICKFIX_ERROR_IMAGE : QUICKFIX_IMAGE; 
+                               imageType = JavaMarkerAnnotation.ERROR_ANNOTATION_TYPE
+                                               .equals(annotation.getType()) ? QUICKFIX_ERROR_IMAGE
+                                               : QUICKFIX_IMAGE;
                } else {
-                       imageType= GRAY_IMAGE;
+                       imageType = GRAY_IMAGE;
                }
                return imageType;
        }
 
-       private Image getImage(IJavaAnnotation annotation, int imageType, Display display) {
+       private Image getImage(IJavaAnnotation annotation, int imageType,
+                       Display display) {
                if (fCachedImageType == imageType)
                        return fCachedImage;
-               
-               Image image= null;
+
+               Image image = null;
                switch (imageType) {
-                       case OVERLAY_IMAGE:
-                               IJavaAnnotation overlay= annotation.getOverlay();
-                               image= overlay.getImage(display);
-                               break;
-                       case QUICKFIX_IMAGE:
-                               image= getQuickFixImage();
-                               break;
-                       case QUICKFIX_ERROR_IMAGE:
-                               image= getQuickFixErrorImage();
-                               break;
-                       case GRAY_IMAGE: {
-                               ISharedImages sharedImages= PlatformUI.getWorkbench().getSharedImages();
-                               String annotationType= annotation.getType();
-                               if (JavaMarkerAnnotation.ERROR_ANNOTATION_TYPE.equals(annotationType)) {
-                                       image= sharedImages.getImage(ISharedImages.IMG_OBJS_ERROR_TSK);
-                               } else if (JavaMarkerAnnotation.WARNING_ANNOTATION_TYPE.equals(annotationType)) {
-                                       image= sharedImages.getImage(ISharedImages.IMG_OBJS_WARN_TSK);
-                               } else if (JavaMarkerAnnotation.INFO_ANNOTATION_TYPE.equals(annotationType)) {
-                                       image= sharedImages.getImage(ISharedImages.IMG_OBJS_INFO_TSK);
-                               }
-                               if (image != null) {
-                                       ImageRegistry registry= getImageRegistry(display);
-                                       String key= Integer.toString(image.hashCode());
-                                       Image grayImage= registry.get(key);
-                                       if (grayImage == null) {
-                                               grayImage= new Image(display, image, SWT.IMAGE_GRAY);
-                                               registry.put(key, grayImage);
-                                       }
-                                       image= grayImage;
+               case OVERLAY_IMAGE:
+                       IJavaAnnotation overlay = annotation.getOverlay();
+                       image = overlay.getImage(display);
+                       break;
+               case QUICKFIX_IMAGE:
+                       image = getQuickFixImage();
+                       break;
+               case QUICKFIX_ERROR_IMAGE:
+                       image = getQuickFixErrorImage();
+                       break;
+               case GRAY_IMAGE: {
+                       ISharedImages sharedImages = PlatformUI.getWorkbench()
+                                       .getSharedImages();
+                       String annotationType = annotation.getType();
+                       if (JavaMarkerAnnotation.ERROR_ANNOTATION_TYPE
+                                       .equals(annotationType)) {
+                               image = sharedImages.getImage(ISharedImages.IMG_OBJS_ERROR_TSK);
+                       } else if (JavaMarkerAnnotation.WARNING_ANNOTATION_TYPE
+                                       .equals(annotationType)) {
+                               image = sharedImages.getImage(ISharedImages.IMG_OBJS_WARN_TSK);
+                       } else if (JavaMarkerAnnotation.INFO_ANNOTATION_TYPE
+                                       .equals(annotationType)) {
+                               image = sharedImages.getImage(ISharedImages.IMG_OBJS_INFO_TSK);
+                       }
+                       if (image != null) {
+                               ImageRegistry registry = getImageRegistry(display);
+                               String key = Integer.toString(image.hashCode());
+                               Image grayImage = registry.get(key);
+                               if (grayImage == null) {
+                                       grayImage = new Image(display, image, SWT.IMAGE_GRAY);
+                                       registry.put(key, grayImage);
                                }
-                               break;
+                               image = grayImage;
                        }
+                       break;
                }
-               
-               fCachedImageType= imageType;
-               fCachedImage= image;
+               }
+
+               fCachedImageType = imageType;
+               fCachedImage = image;
                return fCachedImage;
        }
 }