Integrated first version of new SWT Browser (MSIE under Windows; Mozilla under Linux)
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpeclipse / phpeditor / PHPDocumentProvider.java
index 5751336..a79460d 100644 (file)
@@ -54,9 +54,11 @@ import org.eclipse.jface.text.ILineTracker;
 import org.eclipse.jface.text.Position;
 import org.eclipse.jface.text.source.Annotation;
 import org.eclipse.jface.text.source.AnnotationModelEvent;
+import org.eclipse.jface.text.source.IAnnotationAccessExtension;
 import org.eclipse.jface.text.source.IAnnotationModel;
 import org.eclipse.jface.text.source.IAnnotationModelListener;
 import org.eclipse.jface.text.source.IAnnotationModelListenerExtension;
+import org.eclipse.jface.text.source.IAnnotationPresentation;
 import org.eclipse.jface.util.IPropertyChangeListener;
 import org.eclipse.jface.util.ListenerList;
 import org.eclipse.jface.util.PropertyChangeEvent;
@@ -68,11 +70,12 @@ import org.eclipse.swt.widgets.Canvas;
 import org.eclipse.swt.widgets.Display;
 import org.eclipse.ui.IEditorInput;
 import org.eclipse.ui.IFileEditorInput;
+import org.eclipse.ui.editors.text.EditorsUI;
 import org.eclipse.ui.editors.text.FileDocumentProvider;
 import org.eclipse.ui.part.FileEditorInput;
 import org.eclipse.ui.texteditor.AbstractMarkerAnnotationModel;
-import org.eclipse.ui.texteditor.DefaultAnnotation;
-import org.eclipse.ui.texteditor.IAnnotationExtension;
+import org.eclipse.ui.texteditor.AnnotationPreference;
+import org.eclipse.ui.texteditor.AnnotationPreferenceLookup;
 import org.eclipse.ui.texteditor.MarkerAnnotation;
 import org.eclipse.ui.texteditor.ResourceMarkerAnnotationModel;
 
@@ -533,225 +536,211 @@ public class PHPDocumentProvider extends FileDocumentProvider {
   }
 
   /**
-                * Annotation representating an <code>IProblem</code>.
-                */
-  static protected class ProblemAnnotation extends Annotation implements IJavaAnnotation, IAnnotationExtension{
-
-    private static final String TASK_ANNOTATION_TYPE= "org.eclipse.ui.workbench.texteditor.task"; //$NON-NLS-1$
-    private static final String ERROR_ANNOTATION_TYPE= "org.eclipse.ui.workbench.texteditor.error"; //$NON-NLS-1$
-    private static final String WARNING_ANNOTATION_TYPE= "org.eclipse.ui.workbench.texteditor.warning"; //$NON-NLS-1$
-    private static final String INFO_ANNOTATION_TYPE= "org.eclipse.ui.workbench.texteditor.info"; //$NON-NLS-1$
-    
-    //    private static Image fgQuickFixImage;
-    //    private static Image fgQuickFixErrorImage;
-    //    private static boolean fgQuickFixImagesInitialized = false;
-
-    private ICompilationUnit fCompilationUnit;
-    private List fOverlaids;
-    private IProblem fProblem;
-    private Image fImage;
-    //    private boolean fQuickFixImagesInitialized = false;
-//    private AnnotationType fType;
-    private String fType;
-
-    public ProblemAnnotation(IProblem problem, ICompilationUnit cu) {
-      fProblem= problem;
-      fCompilationUnit= cu;
-      
-      if (IProblem.Task == fProblem.getID()) {
-        fType= TASK_ANNOTATION_TYPE;
-        setLayer(DefaultAnnotation.TASK_LAYER + 1);
-      } else if (fProblem.isWarning()) {
-        fType= WARNING_ANNOTATION_TYPE;
-        setLayer(DefaultAnnotation.WARNING_LAYER + 1);
-      } else if (fProblem.isError()) {
-        fType= ERROR_ANNOTATION_TYPE;
-        setLayer(DefaultAnnotation.ERROR_LAYER + 1);
-      } else {
-        fType= INFO_ANNOTATION_TYPE;
-        setLayer(DefaultAnnotation.INFO_LAYER + 1);
-      }
-    }
-//    public ProblemAnnotation(IProblem problem) {
-//
-//      fProblem = problem;
-//      setLayer(MarkerAnnotation.PROBLEM_LAYER + 1);
-//
-//      if (IProblem.Task == fProblem.getID())
-//        fType = AnnotationType.TASK;
-//      else if (fProblem.isWarning())
-//        fType = AnnotationType.WARNING;
-//      else
-//        fType = AnnotationType.ERROR;
-//    }
-
-    private void initializeImages() {
-      // http://bugs.eclipse.org/bugs/show_bug.cgi?id=18936
-      //      if (!fQuickFixImagesInitialized) {
-      //        if (indicateQuixFixableProblems() && JavaCorrectionProcessor.hasCorrections(fProblem.getID())) {
-      //          if (!fgQuickFixImagesInitialized) {
-      //            fgQuickFixImage = JavaPluginImages.get(JavaPluginImages.IMG_OBJS_FIXABLE_PROBLEM);
-      //            fgQuickFixErrorImage = JavaPluginImages.get(JavaPluginImages.IMG_OBJS_FIXABLE_ERROR);
-      //            fgQuickFixImagesInitialized = true;
-      //          }
-      //          if (fType == AnnotationType.ERROR)
-      //            fImage = fgQuickFixErrorImage;
-      //          else
-      //            fImage = fgQuickFixImage;
-      //        }
-      //        fQuickFixImagesInitialized = true;
-      //      }
-    }
-
-    private boolean indicateQuixFixableProblems() {
-      return PreferenceConstants.getPreferenceStore().getBoolean(PreferenceConstants.EDITOR_CORRECTION_INDICATION);
-    }
-
-    /*
-     * @see Annotation#paint
-     */
-    public void paint(GC gc, Canvas canvas, Rectangle r) {
-      initializeImages();
-      if (fImage != null)
-        drawImage(fImage, gc, canvas, r, SWT.CENTER, SWT.TOP);
-    }
-
-    /*
-     * @see IJavaAnnotation#getImage(Display)
-     */
-    public Image getImage(Display display) {
-      initializeImages();
-      return fImage;
-    }
-
-    /*
-     * @see IJavaAnnotation#getMessage()
-     */
-    public String getMessage() {
-      return fProblem.getMessage();
-    }
-
-    /*
-     * @see IJavaAnnotation#isTemporary()
-     */
-    public boolean isTemporary() {
-      return true;
-    }
-
-    /*
-     * @see IJavaAnnotation#getArguments()
-     */
-    public String[] getArguments() {
-      return isProblem() ? fProblem.getArguments() : null;
-    }
-
-    /*
-     * @see IJavaAnnotation#getId()
-     */
-    public int getId() {
-      return isProblem() ? fProblem.getID() : -1;
-    }
-
-//    /*
-//     * @see IJavaAnnotation#isProblem()
-//     */
-//    public boolean isProblem() {
-//      return fType == AnnotationType.WARNING || fType == AnnotationType.ERROR;
-//    }
-    /*
-     * @see IJavaAnnotation#isProblem()
-     */
-    public boolean isProblem() {
-      return  WARNING_ANNOTATION_TYPE.equals(fType)  || ERROR_ANNOTATION_TYPE.equals(fType);
-    }
-
-    /*
-     * @see IJavaAnnotation#isRelevant()
-     */
-    public boolean isRelevant() {
-      return true;
-    }
-
-    /*
-     * @see IJavaAnnotation#hasOverlay()
-     */
-    public boolean hasOverlay() {
-      return false;
-    }
-
-    /*
-     * @see IJavaAnnotation#addOverlaid(IJavaAnnotation)
-     */
-    public void addOverlaid(IJavaAnnotation annotation) {
-      if (fOverlaids == null)
-        fOverlaids = new ArrayList(1);
-      fOverlaids.add(annotation);
-    }
-
-    /*
-     * @see IJavaAnnotation#removeOverlaid(IJavaAnnotation)
-     */
-    public void removeOverlaid(IJavaAnnotation annotation) {
-      if (fOverlaids != null) {
-        fOverlaids.remove(annotation);
-        if (fOverlaids.size() == 0)
-          fOverlaids = null;
-      }
-    }
-
-    /*
-     * @see IJavaAnnotation#getOverlaidIterator()
-     */
-    public Iterator getOverlaidIterator() {
-      if (fOverlaids != null)
-        return fOverlaids.iterator();
-      return null;
-    }
-
-    
-    public AnnotationType getAnnotationType() {
-      if (ERROR_ANNOTATION_TYPE.equals(fType)) {
-        return AnnotationType.ERROR;
-      }
-      if (WARNING_ANNOTATION_TYPE.equals(fType)) {
-        return AnnotationType.WARNING;
-      }
-      if (TASK_ANNOTATION_TYPE.equals(fType)) {
-        return AnnotationType.TASK;
-      }
-//      if (INFO_ANNOTATION_TYPE.equals(fType)) {
-//        return AnnotationType.INFO;
-//      }
-      return AnnotationType.UNKNOWN;
-    }
-    
-    /*
-     * @see IAnnotationExtension#getMarkerType()
-     */
-    public String getMarkerType() {
-      if (isProblem() || INFO_ANNOTATION_TYPE.equals(fType))
-        return IMarker.PROBLEM;
-      else
-        return IMarker.TASK;
-    }
-    /*
-     * @see IAnnotationExtension#getSeverity()
-     */
-    public int getSeverity() {
-      if (ERROR_ANNOTATION_TYPE.equals(fType))
-        return IMarker.SEVERITY_ERROR;
-      if (WARNING_ANNOTATION_TYPE.equals(fType))
-        return IMarker.SEVERITY_WARNING;
-      return IMarker.SEVERITY_INFO;
-    }
-
-    /*
-     * @see org.eclipse.jdt.internal.ui.javaeditor.IJavaAnnotation#getCompilationUnit()
-     */
-    public ICompilationUnit getCompilationUnit() {
-      return fCompilationUnit;
-    }
-  };
+        * Annotation representating an <code>IProblem</code>.
+        */
+       static protected class ProblemAnnotation extends Annotation implements IJavaAnnotation, IAnnotationPresentation {
+               
+               private static final String SPELLING_ANNOTATION_TYPE= "org.eclipse.ui.workbench.texteditor.spelling";
+
+               //XXX: To be fully correct these constants should be non-static
+               /** 
+                * The layer in which task problem annotations are located.
+                */
+               private static final int TASK_LAYER;
+               /** 
+                * The layer in which info problem annotations are located.
+                */
+               private static final int INFO_LAYER;
+               /** 
+                * The layer in which warning problem annotations representing are located.
+                */
+               private static final int WARNING_LAYER;
+               /** 
+                * The layer in which error problem annotations representing are located.
+                */
+               private static final int ERROR_LAYER;
+               
+               static {
+                       AnnotationPreferenceLookup lookup= EditorsUI.getAnnotationPreferenceLookup();
+                       TASK_LAYER= computeLayer("org.eclipse.ui.workbench.texteditor.task", lookup); //$NON-NLS-1$
+                       INFO_LAYER= computeLayer("net.sourceforge.phpdt.ui.info", lookup); //$NON-NLS-1$
+                       WARNING_LAYER= computeLayer("net.sourceforge.phpdt.ui.warning", lookup); //$NON-NLS-1$
+                       ERROR_LAYER= computeLayer("net.sourceforge.phpdt.ui.error", lookup); //$NON-NLS-1$
+               }
+               
+               private static int computeLayer(String annotationType, AnnotationPreferenceLookup lookup) {
+                       Annotation annotation= new Annotation(annotationType, false, null);
+                       AnnotationPreference preference= lookup.getAnnotationPreference(annotation);
+                       if (preference != null)
+                               return preference.getPresentationLayer() + 1;
+                       else
+                               return IAnnotationAccessExtension.DEFAULT_LAYER + 1;
+               }
+
+//             private static Image fgQuickFixImage;
+//             private static Image fgQuickFixErrorImage;
+//             private static boolean fgQuickFixImagesInitialized= false;
+               
+               private ICompilationUnit fCompilationUnit;
+               private List fOverlaids;
+               private IProblem fProblem;
+               private Image fImage;
+               private boolean fQuickFixImagesInitialized= false;
+               private int fLayer= IAnnotationAccessExtension.DEFAULT_LAYER;
+               
+               public ProblemAnnotation(IProblem problem, ICompilationUnit cu) {
+                       
+                       fProblem= problem;
+                       fCompilationUnit= cu;
+                       
+//                     if (SpellProblem.Spelling == fProblem.getID()) {
+//                             setType(SPELLING_ANNOTATION_TYPE);
+//                             fLayer= WARNING_LAYER;
+//                     } else 
+                   if (IProblem.Task == fProblem.getID()) {
+                               setType(JavaMarkerAnnotation.TASK_ANNOTATION_TYPE);
+                               fLayer= TASK_LAYER;
+                       } else if (fProblem.isWarning()) {
+                               setType(JavaMarkerAnnotation.WARNING_ANNOTATION_TYPE);
+                               fLayer= WARNING_LAYER;
+                       } else if (fProblem.isError()) {
+                               setType(JavaMarkerAnnotation.ERROR_ANNOTATION_TYPE);
+                               fLayer= ERROR_LAYER;
+                       } else {
+                               setType(JavaMarkerAnnotation.INFO_ANNOTATION_TYPE);
+                               fLayer= INFO_LAYER;
+                       }
+               }
+               
+               /*
+                * @see org.eclipse.jface.text.source.IAnnotationPresentation#getLayer()
+                */
+               public int getLayer() {
+                       return fLayer;
+               }
+               
+               private void initializeImages() {
+                       // http://bugs.eclipse.org/bugs/show_bug.cgi?id=18936
+//                     if (!fQuickFixImagesInitialized) {
+//                             if (isProblem() && indicateQuixFixableProblems() && JavaCorrectionProcessor.hasCorrections(this)) { // no light bulb for tasks
+//                                     if (!fgQuickFixImagesInitialized) {
+//                                             fgQuickFixImage= JavaPluginImages.get(JavaPluginImages.IMG_OBJS_FIXABLE_PROBLEM);
+//                                             fgQuickFixErrorImage= JavaPluginImages.get(JavaPluginImages.IMG_OBJS_FIXABLE_ERROR);
+//                                             fgQuickFixImagesInitialized= true;
+//                                     }
+//                                     if (JavaMarkerAnnotation.ERROR_ANNOTATION_TYPE.equals(getType()))
+//                                             fImage= fgQuickFixErrorImage;
+//                                     else
+//                                             fImage= fgQuickFixImage;
+//                             }
+//                             fQuickFixImagesInitialized= true;
+//                     }
+               }
+
+               private boolean indicateQuixFixableProblems() {
+                       return PreferenceConstants.getPreferenceStore().getBoolean(PreferenceConstants.EDITOR_CORRECTION_INDICATION);
+               }
+                                       
+               /*
+                * @see Annotation#paint
+                */
+               public void paint(GC gc, Canvas canvas, Rectangle r) {
+                       initializeImages();
+                       if (fImage != null)
+                               drawImage(fImage, gc, canvas, r, SWT.CENTER, SWT.TOP);
+               }
+               
+               /*
+                * @see IJavaAnnotation#getImage(Display)
+                */
+               public Image getImage(Display display) {
+                       initializeImages();
+                       return fImage;
+               }
+               
+               /*
+                * @see IJavaAnnotation#getMessage()
+                */
+               public String getText() {
+                       return fProblem.getMessage();
+               }
+               
+               /*
+                * @see IJavaAnnotation#getArguments()
+                */
+               public String[] getArguments() {
+                       return isProblem() ? fProblem.getArguments() : null;
+               }
+
+               /*
+                * @see IJavaAnnotation#getId()
+                */
+               public int getId() {
+                       return fProblem.getID();
+               }
+
+               /*
+                * @see IJavaAnnotation#isProblem()
+                */
+               public boolean isProblem() {
+                       String type= getType();
+                       return  JavaMarkerAnnotation.WARNING_ANNOTATION_TYPE.equals(type)  || 
+                                               JavaMarkerAnnotation.ERROR_ANNOTATION_TYPE.equals(type) ||
+                                               SPELLING_ANNOTATION_TYPE.equals(type);
+               }
+               
+               /*
+                * @see IJavaAnnotation#hasOverlay()
+                */
+               public boolean hasOverlay() {
+                       return false;
+               }
+               
+               /*
+                * @see org.eclipse.jdt.internal.ui.javaeditor.IJavaAnnotation#getOverlay()
+                */
+               public IJavaAnnotation getOverlay() {
+                       return null;
+               }
+               
+               /*
+                * @see IJavaAnnotation#addOverlaid(IJavaAnnotation)
+                */
+               public void addOverlaid(IJavaAnnotation annotation) {
+                       if (fOverlaids == null)
+                               fOverlaids= new ArrayList(1);
+                       fOverlaids.add(annotation);
+               }
+
+               /*
+                * @see IJavaAnnotation#removeOverlaid(IJavaAnnotation)
+                */
+               public void removeOverlaid(IJavaAnnotation annotation) {
+                       if (fOverlaids != null) {
+                               fOverlaids.remove(annotation);
+                               if (fOverlaids.size() == 0)
+                                       fOverlaids= null;
+                       }
+               }
+               
+               /*
+                * @see IJavaAnnotation#getOverlaidIterator()
+                */
+               public Iterator getOverlaidIterator() {
+                       if (fOverlaids != null)
+                               return fOverlaids.iterator();
+                       return null;
+               }
+               
+               /*
+                * @see org.eclipse.jdt.internal.ui.javaeditor.IJavaAnnotation#getCompilationUnit()
+                */
+               public ICompilationUnit getCompilationUnit() {
+                       return fCompilationUnit;
+               }
+       }
+       
   /**
                 * Internal structure for mapping positions to some value. 
                 * The reason for this specific structure is that positions can