2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
9 package eu
.etaxonomy
.taxeditor
.annotatedlineeditor
;
11 import java
.util
.Iterator
;
13 import org
.apache
.log4j
.Logger
;
14 import org
.eclipse
.jface
.text
.DefaultInformationControl
;
15 import org
.eclipse
.jface
.text
.DefaultTextHover
;
16 import org
.eclipse
.jface
.text
.IInformationControl
;
17 import org
.eclipse
.jface
.text
.IInformationControlCreator
;
18 import org
.eclipse
.jface
.text
.IRegion
;
19 import org
.eclipse
.jface
.text
.ITextHover
;
20 import org
.eclipse
.jface
.text
.ITextHoverExtension
;
21 import org
.eclipse
.jface
.text
.ITextViewer
;
22 import org
.eclipse
.jface
.text
.Position
;
23 import org
.eclipse
.jface
.text
.reconciler
.IReconciler
;
24 import org
.eclipse
.jface
.text
.reconciler
.IReconcilingStrategy
;
25 import org
.eclipse
.jface
.text
.reconciler
.MonoReconciler
;
26 import org
.eclipse
.jface
.text
.source
.Annotation
;
27 import org
.eclipse
.jface
.text
.source
.IAnnotationModel
;
28 import org
.eclipse
.jface
.text
.source
.ISourceViewer
;
29 import org
.eclipse
.jface
.text
.source
.SourceViewerConfiguration
;
30 import org
.eclipse
.swt
.widgets
.Shell
;
31 import org
.eclipse
.ui
.editors
.text
.EditorsUI
;
35 * <p>AnnotatedLineEditorSourceViewerConfiguration class.</p>
41 public class AnnotatedLineEditorSourceViewerConfiguration
extends
42 SourceViewerConfiguration
{
43 @SuppressWarnings("unused")
44 private static final Logger logger
= Logger
.getLogger(AnnotatedLineEditorSourceViewerConfiguration
.class);
47 * @see org.eclipse.jface.text.source.SourceViewerConfiguration#getReconciler(org.eclipse.jface.text.source.ISourceViewer)
50 public IReconciler
getReconciler(ISourceViewer sourceViewer
) {
52 IReconcilingStrategy strategy
= new AnnotatedLineEditorReconcilingStrategy(sourceViewer
);
53 IReconciler reconciler
= new MonoReconciler(strategy
, true);
59 * @see org.eclipse.jface.text.source.SourceViewerConfiguration#getTextHover(org.eclipse.jface.text.source.ISourceViewer, java.lang.String, int)
63 public ITextHover
getTextHover(ISourceViewer sourceViewer
, String contentType
) {
65 * http://dev.eclipse.org/newslists/news.eclipse.platform/msg76821.html
67 * The Javadoc hover is shown in a Browser widget
69 return new TextHover(sourceViewer
);
72 private final class TextHover
extends DefaultTextHover
implements ITextHoverExtension
{
74 private ISourceViewer sourceViewer
;
76 public TextHover(ISourceViewer sourceViewer
) {
79 this.sourceViewer
= sourceViewer
;
83 * @see org.eclipse.jface.text.DefaultTextHover#getHoverInfo(org.eclipse.jface.text.ITextViewer, org.eclipse.jface.text.IRegion)
86 public String
getHoverInfo(ITextViewer textViewer
, IRegion hoverRegion
) {
88 IAnnotationModel model
= sourceViewer
.getAnnotationModel();
89 Iterator e
= model
.getAnnotationIterator();
91 Annotation annotation
= (Annotation
) e
.next();
92 if (isIncluded(annotation
)) {
93 Position p
= model
.getPosition(annotation
);
94 if (p
!= null && p
.overlapsWith(hoverRegion
.getOffset(), hoverRegion
.getLength())) {
95 return ((LineAnnotation
) annotation
).getHoverText();
103 * @see org.eclipse.jface.text.ITextHoverExtension#getHoverControlCreator()
105 public IInformationControlCreator
getHoverControlCreator() {
106 return new IInformationControlCreator() {
107 public IInformationControl
createInformationControl(Shell parent
) {
108 return new DefaultInformationControl(parent
, EditorsUI
.getTooltipAffordanceString());