2 * Copyright (c) 2003-2004 Christopher Lenz and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Common Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/cpl-v10.html
9 * Christopher Lenz - initial API and implementation
11 * $Id: XMLTextHover.java,v 1.2 2006-10-21 23:14:13 pombredanne Exp $
13 package net.sourceforge.phpeclipse.xml.ui.internal.text;
15 import java.util.Iterator;
17 import org.eclipse.jface.text.IRegion;
18 import org.eclipse.jface.text.ITextHover;
19 import org.eclipse.jface.text.ITextViewer;
20 import org.eclipse.jface.text.Position;
21 import org.eclipse.jface.text.source.Annotation;
22 import org.eclipse.jface.text.source.IAnnotationModel;
25 * Implements simple annotation hover to show the associated messages.
27 public class XMLTextHover implements ITextHover {
29 * This hovers annotation model.
31 private IAnnotationModel model;
34 * Creates a new annotation hover.
37 * this hover's annotation model
39 public XMLTextHover(IAnnotationModel model) {
44 * @see ITextHover#getHoverInfo(ITextViewer, IRegion)
46 public String getHoverInfo(ITextViewer textViewer, IRegion region) {
47 Iterator e = new XMLAnnotationIterator(model, true);
49 Annotation a = (Annotation) e.next();
51 Position p = model.getPosition(a);
52 if (p.overlapsWith(region.getOffset(), region.getLength())) {
53 String text = a.getText();
54 if ((text != null) && (text.trim().length() > 0)) {
64 * @see ITextHover#getHoverRegion(ITextViewer, int)
66 public IRegion getHoverRegion(ITextViewer textViewer, int offset) {
67 return XMLWordFinder.findWord(textViewer.getDocument(), offset);