Project

General

Profile

Download (3.81 KB) Statistics
| Branch: | Tag: | Revision:
1
// $Id$
2
/**
3
* Copyright (C) 2007 EDIT
4
* European Distributed Institute of Taxonomy 
5
* http://www.e-taxonomy.eu
6
* 
7
* The contents of this file are subject to the Mozilla Public License Version 1.1
8
* See LICENSE.TXT at the top of this package for the full license terms.
9
*/
10
package eu.etaxonomy.taxeditor.annotatedlineeditor;
11

    
12
import java.util.Iterator;
13

    
14
import org.apache.log4j.Logger;
15
import org.eclipse.jface.text.DefaultInformationControl;
16
import org.eclipse.jface.text.DefaultTextHover;
17
import org.eclipse.jface.text.IInformationControl;
18
import org.eclipse.jface.text.IInformationControlCreator;
19
import org.eclipse.jface.text.IRegion;
20
import org.eclipse.jface.text.ITextHover;
21
import org.eclipse.jface.text.ITextHoverExtension;
22
import org.eclipse.jface.text.ITextViewer;
23
import org.eclipse.jface.text.Position;
24
import org.eclipse.jface.text.reconciler.IReconciler;
25
import org.eclipse.jface.text.reconciler.IReconcilingStrategy;
26
import org.eclipse.jface.text.reconciler.MonoReconciler;
27
import org.eclipse.jface.text.source.Annotation;
28
import org.eclipse.jface.text.source.IAnnotationModel;
29
import org.eclipse.jface.text.source.ISourceViewer;
30
import org.eclipse.jface.text.source.SourceViewerConfiguration;
31
import org.eclipse.swt.widgets.Shell;
32
import org.eclipse.ui.editors.text.EditorsUI;
33

    
34

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

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

    
75
		private ISourceViewer sourceViewer;
76

    
77
		public TextHover(ISourceViewer sourceViewer) {
78
			super(sourceViewer);
79
			
80
			this.sourceViewer = sourceViewer;
81
		}
82
		
83
		/* (non-Javadoc)
84
		 * @see org.eclipse.jface.text.DefaultTextHover#getHoverInfo(org.eclipse.jface.text.ITextViewer, org.eclipse.jface.text.IRegion)
85
		 */
86
		@Override
87
		public String getHoverInfo(ITextViewer textViewer, IRegion hoverRegion) {
88
			
89
			IAnnotationModel model= sourceViewer.getAnnotationModel();
90
			Iterator e= model.getAnnotationIterator();
91
			while (e.hasNext()) {
92
				Annotation annotation= (Annotation) e.next();
93
				if (isIncluded(annotation)) {
94
					Position p= model.getPosition(annotation);
95
					if (p != null && p.overlapsWith(hoverRegion.getOffset(), hoverRegion.getLength())) {
96
						return ((LineAnnotation) annotation).getHoverText();
97
					}
98
				}
99
			}
100
			return null;
101
		}
102
		
103
		/* (non-Javadoc)
104
		 * @see org.eclipse.jface.text.ITextHoverExtension#getHoverControlCreator()
105
		 */
106
		public IInformationControlCreator getHoverControlCreator() {
107
			return new IInformationControlCreator() {
108
				public IInformationControl createInformationControl(Shell parent) {
109
					return new DefaultInformationControl(parent, EditorsUI.getTooltipAffordanceString());
110
				}
111
			};
112
		}
113
	}
114
}
(5-5/16)