KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > text > java > hover > JavaEditorTextHoverProxy


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11
12 package org.eclipse.jdt.internal.ui.text.java.hover;
13
14 import org.eclipse.jface.text.IInformationControlCreator;
15 import org.eclipse.jface.text.IRegion;
16 import org.eclipse.jface.text.ITextHoverExtension;
17 import org.eclipse.jface.text.ITextViewer;
18 import org.eclipse.jface.text.information.IInformationProviderExtension2;
19
20 import org.eclipse.ui.IEditorPart;
21
22 import org.eclipse.jdt.ui.text.java.hover.IJavaEditorTextHover;
23
24
25 /**
26  * Proxy for JavaEditorTextHovers.
27  *
28  * @since 2.1
29  */

30 public class JavaEditorTextHoverProxy extends AbstractJavaEditorTextHover implements ITextHoverExtension, IInformationProviderExtension2 {
31
32     private JavaEditorTextHoverDescriptor fHoverDescriptor;
33     private IJavaEditorTextHover fHover;
34
35     public JavaEditorTextHoverProxy(JavaEditorTextHoverDescriptor descriptor, IEditorPart editor) {
36         fHoverDescriptor= descriptor;
37         setEditor(editor);
38     }
39
40     /*
41      * @see IJavaEditorTextHover#setEditor(IEditorPart)
42      */

43     public void setEditor(IEditorPart editor) {
44         super.setEditor(editor);
45
46         if (fHover != null)
47             fHover.setEditor(getEditor());
48     }
49
50     public boolean isEnabled() {
51         return true;
52     }
53
54     /*
55      * @see ITextHover#getHoverRegion(ITextViewer, int)
56      */

57     public IRegion getHoverRegion(ITextViewer textViewer, int offset) {
58         if (ensureHoverCreated())
59             return fHover.getHoverRegion(textViewer, offset);
60
61         return null;
62     }
63
64     /*
65      * @see ITextHover#getHoverInfo(ITextViewer, IRegion)
66      */

67     public String JavaDoc getHoverInfo(ITextViewer textViewer, IRegion hoverRegion) {
68         if (ensureHoverCreated())
69             return fHover.getHoverInfo(textViewer, hoverRegion);
70
71         return null;
72     }
73
74     private boolean ensureHoverCreated() {
75         if (!isEnabled() || fHoverDescriptor == null)
76             return false;
77         return isCreated() || createHover();
78     }
79
80     private boolean isCreated() {
81         return fHover != null;
82     }
83
84     private boolean createHover() {
85         fHover= fHoverDescriptor.createTextHover();
86         if (fHover != null)
87             fHover.setEditor(getEditor());
88         return isCreated();
89     }
90
91     /*
92      * @see org.eclipse.jface.text.ITextHoverExtension#getHoverControlCreator()
93      * @since 3.0
94      */

95     public IInformationControlCreator getHoverControlCreator() {
96         if (ensureHoverCreated() && (fHover instanceof ITextHoverExtension))
97             return ((ITextHoverExtension)fHover).getHoverControlCreator();
98
99         return null;
100     }
101
102     /*
103      * @see org.eclipse.jface.text.information.IInformationProviderExtension2#getInformationPresenterControlCreator()
104      */

105     public IInformationControlCreator getInformationPresenterControlCreator() {
106         if (ensureHoverCreated() && (fHover instanceof IInformationProviderExtension2))
107             return ((IInformationProviderExtension2)fHover).getInformationPresenterControlCreator();
108
109         return null;
110     }
111 }
112
Popular Tags