1 /*******************************************************************************
2 * Copyright (c) 2000, 2006 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 package net.sourceforge.phpdt.internal.ui.text.java.hover;
13 import java.util.ArrayList;
14 import java.util.HashMap;
15 import java.util.Iterator;
16 import java.util.List;
18 import net.sourceforge.phpdt.internal.ui.PHPUiImages;
19 import net.sourceforge.phpdt.internal.ui.text.java.hover.AnnotationExpansionControl.AnnotationHoverInput;
20 import net.sourceforge.phpdt.ui.PreferenceConstants;
21 //import net.sourceforge.phpeclipse.PHPeclipsePlugin;
22 import net.sourceforge.phpeclipse.phpeditor.IJavaAnnotation;
23 import net.sourceforge.phpeclipse.phpeditor.JavaMarkerAnnotation;
24 import net.sourceforge.phpeclipse.phpeditor.PHPDocumentProvider.ProblemAnnotation;
25 import net.sourceforge.phpeclipse.ui.WebUI;
27 import org.eclipse.jface.preference.IPreferenceStore;
28 import org.eclipse.jface.text.IDocument;
29 import org.eclipse.jface.text.IInformationControlExtension2;
30 import org.eclipse.jface.text.Position;
31 import org.eclipse.jface.text.source.Annotation;
32 import org.eclipse.jface.text.source.CompositeRuler;
33 import org.eclipse.jface.text.source.IAnnotationAccess;
34 import org.eclipse.jface.text.source.IAnnotationAccessExtension;
35 import org.eclipse.jface.text.source.IAnnotationModel;
36 import org.eclipse.jface.text.source.IAnnotationPresentation;
37 import org.eclipse.jface.text.source.ISourceViewer;
38 import org.eclipse.jface.text.source.ImageUtilities;
39 import org.eclipse.jface.viewers.IDoubleClickListener;
40 import org.eclipse.swt.SWT;
41 import org.eclipse.swt.graphics.GC;
42 import org.eclipse.swt.graphics.Image;
43 import org.eclipse.swt.graphics.Rectangle;
44 import org.eclipse.swt.widgets.Canvas;
45 import org.eclipse.ui.texteditor.AnnotationPreference;
46 import org.eclipse.ui.texteditor.AnnotationPreferenceLookup;
53 public class JavaExpandHover extends AnnotationExpandHover {
55 /** Id of the no breakpoint fake annotation */
56 public static final String NO_BREAKPOINT_ANNOTATION = "net.sourceforge.phpdt.internal.ui.NoBreakpointAnnotation"; //$NON-NLS-1$
58 private static class NoBreakpointAnnotation extends Annotation implements
59 IAnnotationPresentation {
61 public NoBreakpointAnnotation() {
62 super(NO_BREAKPOINT_ANNOTATION, false, JavaHoverMessages
63 .getString("NoBreakpointAnnotation.addBreakpoint"));
67 * @see org.eclipse.jface.text.source.IAnnotationPresentation#paint(org.eclipse.swt.graphics.GC,
68 * org.eclipse.swt.widgets.Canvas,
69 * org.eclipse.swt.graphics.Rectangle)
71 public void paint(GC gc, Canvas canvas, Rectangle bounds) {
72 // draw affordance so the user know she can click here to get a
74 Image fImage = PHPUiImages.get(PHPUiImages.IMG_FIELD_PUBLIC);
75 ImageUtilities.drawImage(fImage, gc, canvas, bounds, SWT.CENTER);
79 * @see org.eclipse.jface.text.source.IAnnotationPresentation#getLayer()
81 public int getLayer() {
82 return IAnnotationPresentation.DEFAULT_LAYER;
86 private AnnotationPreferenceLookup fLookup = new AnnotationPreferenceLookup();
88 private IPreferenceStore fStore = WebUI.getDefault()
89 .getCombinedPreferenceStore();
91 public JavaExpandHover(CompositeRuler ruler, IAnnotationAccess access,
92 IDoubleClickListener doubleClickListener) {
93 super(ruler, access, doubleClickListener);
97 * @see org.eclipse.ui.internal.texteditor.AnnotationExpandHover#getHoverInfoForLine(org.eclipse.jface.text.source.ISourceViewer,
100 protected Object getHoverInfoForLine(final ISourceViewer viewer,
102 final boolean showTemporaryProblems = PreferenceConstants
103 .getPreferenceStore().getBoolean(
104 PreferenceConstants.EDITOR_CORRECTION_INDICATION);
105 IAnnotationModel model = viewer.getAnnotationModel();
106 IDocument document = viewer.getDocument();
111 List exact = new ArrayList();
112 HashMap messagesAtPosition = new HashMap();
114 Iterator e = model.getAnnotationIterator();
115 while (e.hasNext()) {
116 Annotation annotation = (Annotation) e.next();
118 if (fAnnotationAccess instanceof IAnnotationAccessExtension)
119 if (!((IAnnotationAccessExtension) fAnnotationAccess)
120 .isPaintable(annotation))
123 if (annotation instanceof IJavaAnnotation
124 && !isIncluded((IJavaAnnotation) annotation,
125 showTemporaryProblems))
128 AnnotationPreference pref = fLookup
129 .getAnnotationPreference(annotation);
131 String key = pref.getVerticalRulerPreferenceKey();
132 if (key != null && !fStore.getBoolean(key))
136 Position position = model.getPosition(annotation);
137 if (position == null)
140 if (compareRulerLine(position, document, line) == 1) {
142 if (isDuplicateMessage(messagesAtPosition, position, annotation
146 exact.add(annotation);
152 if (exact.size() > 0)
153 setLastRulerMouseLocation(viewer, line);
155 if (exact.size() > 0) {
156 Annotation first = (Annotation) exact.get(0);
157 if (!isBreakpointAnnotation(first))
158 exact.add(0, new NoBreakpointAnnotation());
161 if (exact.size() <= 1)
164 AnnotationHoverInput input = new AnnotationHoverInput();
165 input.fAnnotations = (Annotation[]) exact.toArray(new Annotation[0]);
166 input.fViewer = viewer;
167 input.fRulerInfo = fCompositeRuler;
168 input.fAnnotationListener = fgListener;
169 input.fDoubleClickListener = fDblClickListener;
170 input.redoAction = new AnnotationExpansionControl.ICallback() {
172 public void run(IInformationControlExtension2 control) {
173 control.setInput(getHoverInfoForLine(viewer, line));
182 private boolean isIncluded(IJavaAnnotation annotation,
183 boolean showTemporaryProblems) {
185 // XXX: see https://bugs.eclipse.org/bugs/show_bug.cgi?id=138601
186 if (annotation instanceof ProblemAnnotation
187 && JavaMarkerAnnotation.TASK_ANNOTATION_TYPE.equals(annotation
191 if (!annotation.isProblem())
194 if (annotation.isMarkedDeleted() && !annotation.hasOverlay())
197 if (annotation.hasOverlay() && !annotation.isMarkedDeleted())
200 if (annotation.hasOverlay())
201 return (!isIncluded(annotation.getOverlay(), showTemporaryProblems));
203 return showTemporaryProblems; // &&
204 // JavaCorrectionProcessor.hasCorrections((Annotation)annotation);
208 * @see org.eclipse.ui.internal.texteditor.AnnotationExpandHover#getOrder(org.eclipse.jface.text.source.Annotation)
210 protected int getOrder(Annotation annotation) {
211 if (isBreakpointAnnotation(annotation))
214 return super.getOrder(annotation);
217 private boolean isBreakpointAnnotation(Annotation a) {
218 if (a instanceof JavaMarkerAnnotation) {
219 JavaMarkerAnnotation jma = (JavaMarkerAnnotation) a;
220 // HACK to get breakpoints to show up first
221 return jma.getType().equals("org.eclipse.debug.core.breakpoint"); //$NON-NLS-1$