Project

General

Profile

Download (3.8 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2007 EDIT
3
* European Distributed Institute of Taxonomy 
4
* http://www.e-taxonomy.eu
5
* 
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.
8
*/
9
package eu.etaxonomy.taxeditor.annotatedlineeditor;
10

    
11
import java.util.Iterator;
12

    
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;
32

    
33

    
34
/**
35
 * <p>AnnotatedLineEditorSourceViewerConfiguration class.</p>
36
 *
37
 * @author p.ciardelli
38
 * @created 25.06.2009
39
 * @version 1.0
40
 */
41
public class AnnotatedLineEditorSourceViewerConfiguration extends
42
		SourceViewerConfiguration {
43
	@SuppressWarnings("unused")
44
	private static final Logger logger = Logger.getLogger(AnnotatedLineEditorSourceViewerConfiguration.class);
45
	
46
	/* (non-Javadoc)
47
	 * @see org.eclipse.jface.text.source.SourceViewerConfiguration#getReconciler(org.eclipse.jface.text.source.ISourceViewer)
48
	 */
49
	/** {@inheritDoc} */
50
	public IReconciler getReconciler(ISourceViewer sourceViewer) {
51
		
52
		IReconcilingStrategy strategy = new AnnotatedLineEditorReconcilingStrategy(sourceViewer);
53
		IReconciler reconciler = new MonoReconciler(strategy, true);
54

    
55
		return reconciler;
56
	}
57
	
58
	/* (non-Javadoc)
59
	 * @see org.eclipse.jface.text.source.SourceViewerConfiguration#getTextHover(org.eclipse.jface.text.source.ISourceViewer, java.lang.String, int)
60
	 */
61
	/** {@inheritDoc} */
62
	@Override
63
	public ITextHover getTextHover(ISourceViewer sourceViewer, String contentType) {
64
		/**
65
		 * http://dev.eclipse.org/newslists/news.eclipse.platform/msg76821.html
66
		 * 
67
		 * The Javadoc hover is shown in a Browser widget
68
		 */
69
		return new TextHover(sourceViewer);
70
	}
71
	
72
	private final class TextHover extends DefaultTextHover implements ITextHoverExtension {
73

    
74
		private ISourceViewer sourceViewer;
75

    
76
		public TextHover(ISourceViewer sourceViewer) {
77
			super(sourceViewer);
78
			
79
			this.sourceViewer = sourceViewer;
80
		}
81
		
82
		/* (non-Javadoc)
83
		 * @see org.eclipse.jface.text.DefaultTextHover#getHoverInfo(org.eclipse.jface.text.ITextViewer, org.eclipse.jface.text.IRegion)
84
		 */
85
		@Override
86
		public String getHoverInfo(ITextViewer textViewer, IRegion hoverRegion) {
87
			
88
			IAnnotationModel model= sourceViewer.getAnnotationModel();
89
			Iterator e= model.getAnnotationIterator();
90
			while (e.hasNext()) {
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();
96
					}
97
				}
98
			}
99
			return null;
100
		}
101
		
102
		/* (non-Javadoc)
103
		 * @see org.eclipse.jface.text.ITextHoverExtension#getHoverControlCreator()
104
		 */
105
		public IInformationControlCreator getHoverControlCreator() {
106
			return new IInformationControlCreator() {
107
				public IInformationControl createInformationControl(Shell parent) {
108
					return new DefaultInformationControl(parent, EditorsUI.getTooltipAffordanceString());
109
				}
110
			};
111
		}
112
	}
113
}
(5-5/16)