A massive organize imports and formatting of the sources using default Eclipse code...
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / ui / text / java / hover / JavaEditorTextHoverProxy.java
1 /*******************************************************************************
2  * Copyright (c) 2000, 2003 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials 
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  * 
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  *******************************************************************************/
11
12 package net.sourceforge.phpdt.internal.ui.text.java.hover;
13
14 import net.sourceforge.phpdt.ui.text.java.hover.IJavaEditorTextHover;
15
16 import org.eclipse.jface.text.IRegion;
17 import org.eclipse.jface.text.ITextViewer;
18 import org.eclipse.ui.IEditorPart;
19
20 /**
21  * Proxy for JavaEditorTextHovers.
22  * 
23  * @since 2.1
24  */
25 public class JavaEditorTextHoverProxy extends AbstractJavaEditorTextHover {
26
27         private JavaEditorTextHoverDescriptor fHoverDescriptor;
28
29         private IJavaEditorTextHover fHover;
30
31         public JavaEditorTextHoverProxy(JavaEditorTextHoverDescriptor descriptor,
32                         IEditorPart editor) {
33                 fHoverDescriptor = descriptor;
34                 setEditor(editor);
35         }
36
37         /*
38          * @see IJavaEditorTextHover#setEditor(IEditorPart)
39          */
40         public void setEditor(IEditorPart editor) {
41                 super.setEditor(editor);
42
43                 if (fHover != null)
44                         fHover.setEditor(getEditor());
45         }
46
47         public boolean isEnabled() {
48                 return true;
49         }
50
51         /*
52          * @see ITextHover#getHoverRegion(ITextViewer, int)
53          */
54         public IRegion getHoverRegion(ITextViewer textViewer, int offset) {
55                 if (!isEnabled() || fHoverDescriptor == null)
56                         return null;
57
58                 if (isCreated() || createHover())
59                         return fHover.getHoverRegion(textViewer, offset);
60                 else
61                         return null;
62         }
63
64         /*
65          * @see ITextHover#getHoverInfo(ITextViewer, IRegion)
66          */
67         public String getHoverInfo(ITextViewer textViewer, IRegion hoverRegion) {
68                 if (!isEnabled() || fHoverDescriptor == null)
69                         return null;
70
71                 if (isCreated() || createHover())
72                         return fHover.getHoverInfo(textViewer, hoverRegion);
73                 else
74                         return null;
75         }
76
77         private boolean isCreated() {
78                 return fHover != null;
79         }
80
81         private boolean createHover() {
82                 fHover = fHoverDescriptor.createTextHover();
83                 if (fHover != null)
84                         fHover.setEditor(getEditor());
85                 return isCreated();
86         }
87 }