Project

General

Profile

« Previous | Next » 

Revision 3be6ef3e

Added by Niels Hoffmann over 13 years ago

performed javacscript:fix and worked on documentation

View differences:

taxeditor-bulkeditor/src/main/java/eu/etaxonomy/taxeditor/annotatedlineeditor/AnnotatedLineEditorSourceViewerConfiguration.java
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
 * @author p.ciardelli
37
 * @created 25.06.2009
38
 * @version 1.0
39
 */
40
public class AnnotatedLineEditorSourceViewerConfiguration extends
41
		SourceViewerConfiguration {
42
	@SuppressWarnings("unused")
43
	private static final Logger logger = Logger.getLogger(AnnotatedLineEditorSourceViewerConfiguration.class);
44
	
45
	/* (non-Javadoc)
46
	 * @see org.eclipse.jface.text.source.SourceViewerConfiguration#getReconciler(org.eclipse.jface.text.source.ISourceViewer)
47
	 */
48
	public IReconciler getReconciler(ISourceViewer sourceViewer) {
49
		
50
		IReconcilingStrategy strategy = new AnnotatedLineEditorReconcilingStrategy(sourceViewer);
51
		IReconciler reconciler = new MonoReconciler(strategy, true);
52

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

  
71
		private ISourceViewer sourceViewer;
72

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

Also available in: Unified diff