Added text hover
diff --git a/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jdt/internal/ui/examples/jspeditor/JspSourceViewerConfiguration.java b/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jdt/internal/ui/examples/jspeditor/JspSourceViewerConfiguration.java
index 2790569..a437298 100644
--- a/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jdt/internal/ui/examples/jspeditor/JspSourceViewerConfiguration.java
+++ b/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jdt/internal/ui/examples/jspeditor/JspSourceViewerConfiguration.java
@@ -13,9 +13,11 @@
import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.jface.text.ITextHover;
import org.eclipse.jface.text.reconciler.IReconciler;
import org.eclipse.jface.text.reconciler.IReconcilingStrategy;
import org.eclipse.jface.text.reconciler.MonoReconciler;
+import org.eclipse.jface.text.source.AnnotationTextHover;
import org.eclipse.jface.text.source.DefaultAnnotationHover;
import org.eclipse.jface.text.source.IAnnotationHover;
import org.eclipse.jface.text.source.ISourceViewer;
@@ -58,4 +60,11 @@
public IAnnotationHover getAnnotationHover(ISourceViewer sourceViewer) {
return new DefaultAnnotationHover();
}
+
+ /*
+ * @see SourceViewerConfiguration#getTextHover(ISourceViewer, String)
+ */
+ public ITextHover getTextHover(ISourceViewer sourceViewer, String contentType) {
+ return new AnnotationTextHover(fTextEditor.getDocumentProvider().getAnnotationModel(fTextEditor.getEditorInput()));
+ }
}
diff --git a/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jface/text/source/AnnotationTextHover.java b/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jface/text/source/AnnotationTextHover.java
new file mode 100644
index 0000000..c9632d9
--- /dev/null
+++ b/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jface/text/source/AnnotationTextHover.java
@@ -0,0 +1,70 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2003 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.jface.text.source;
+
+import java.util.Iterator;
+
+import org.eclipse.jface.text.Assert;
+import org.eclipse.jface.text.IRegion;
+import org.eclipse.jface.text.ITextHover;
+import org.eclipse.jface.text.ITextViewer;
+import org.eclipse.jface.text.Position;
+import org.eclipse.jface.text.Region;
+
+/**
+ * A simple text hover to show annotation information.
+ *
+ * @since 3.0
+ */
+public class AnnotationTextHover implements ITextHover {
+
+ /** This hover's annotation model */
+ private IAnnotationModel fModel;
+
+ /**
+ * Creates a new annotation hover.
+ *
+ * @param model this hover's annotation model
+ */
+ public AnnotationTextHover(IAnnotationModel model) {
+ Assert.isNotNull(model);
+ fModel= model;
+ }
+
+ /*
+ * @see org.eclipse.jface.text.ITextHover#getHoverInfo(org.eclipse.jface.text.ITextViewer, org.eclipse.jface.text.IRegion)
+ */
+ public String getHoverInfo(ITextViewer textViewer, IRegion hoverRegion) {
+
+ Iterator e= fModel.getAnnotationIterator();
+ while (e.hasNext()) {
+ Annotation a= (Annotation) e.next();
+ Position p= fModel.getPosition(a);
+ if (p.overlapsWith(hoverRegion.getOffset(), hoverRegion.getLength())) {
+ if (a instanceof IAnnotationExtension) {
+ String msg= ((IAnnotationExtension) a).getMessage();
+ if (msg != null && msg.trim().length() > 0)
+ return msg;
+ }
+ }
+ }
+
+ return null;
+ }
+
+ /*
+ * @see org.eclipse.jface.text.ITextHover#getHoverRegion(org.eclipse.jface.text.ITextViewer, int)
+ */
+ public IRegion getHoverRegion(ITextViewer textViewer, int offset) {
+ return new Region(offset, 0);
+ }
+}
diff --git a/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jface/text/source/DefaultAnnotationHover.java b/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jface/text/source/DefaultAnnotationHover.java
index d503f21..9c2cab6 100644
--- a/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jface/text/source/DefaultAnnotationHover.java
+++ b/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jface/text/source/DefaultAnnotationHover.java
@@ -20,15 +20,11 @@
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.Position;
-import org.eclipse.jface.text.source.Annotation;
-import org.eclipse.jface.text.source.IAnnotationHover;
-import org.eclipse.jface.text.source.IAnnotationModel;
-import org.eclipse.jface.text.source.ISourceViewer;
/**
- * Determines all annotations for the given line and collects, concatenates, and formats
- * their messages.
+ * Determines all annotations for the given line, collects,
+ * concatenates, and formats their messages.
*
* @since 3.0
*/
@@ -79,8 +75,11 @@
HashMap messagesAtPosition= new HashMap();
while (e.hasNext()) {
Object o= e.next();
+
if (o instanceof IAnnotationExtension) {
+
IAnnotationExtension a= (IAnnotationExtension)o;
+
Position position= model.getPosition((Annotation)a);
if (position == null)
continue;
@@ -163,16 +162,10 @@
return null;
}
- /*
- * Formats a message as HTML text.
- */
private String formatSingleMessage(String message) {
return message;
}
- /*
- * Formats several message as HTML text.
- */
private String formatMultipleMessages(List messages) {
StringBuffer buffer= new StringBuffer();
Iterator e= messages.iterator();
diff --git a/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jface/text/source/TemporaryAnnotation.java b/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jface/text/source/TemporaryAnnotation.java
index bbefc99..22e6e5c 100644
--- a/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jface/text/source/TemporaryAnnotation.java
+++ b/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jface/text/source/TemporaryAnnotation.java
@@ -137,14 +137,7 @@
public boolean isError() {
return fSeverity == ERROR;
}
-
- /*
- * @see IJavaAnnotation#isRelevant()
- */
- public boolean isRelevant() {
- return true;
- }
-
+
/*
* @see IAnnotationExtension#getMessage()
*/