new version with WorkingCopy Management
[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 /**
22  * Proxy for JavaEditorTextHovers.
23  * 
24  * @since 2.1
25  */
26 public class JavaEditorTextHoverProxy extends AbstractJavaEditorTextHover {
27
28         private JavaEditorTextHoverDescriptor fHoverDescriptor;
29         private IJavaEditorTextHover fHover;
30
31         public JavaEditorTextHoverProxy(JavaEditorTextHoverDescriptor descriptor, IEditorPart editor) {
32                 fHoverDescriptor= descriptor;
33                 setEditor(editor);
34         }
35
36         /*
37          * @see IJavaEditorTextHover#setEditor(IEditorPart)
38          */
39         public void setEditor(IEditorPart editor) {
40                 super.setEditor(editor);
41
42                 if (fHover != null)
43                         fHover.setEditor(getEditor());
44         }
45
46         public boolean isEnabled() {
47                 return true;
48         }
49
50         /*
51          * @see ITextHover#getHoverRegion(ITextViewer, int)
52          */
53         public IRegion getHoverRegion(ITextViewer textViewer, int offset) {
54                 if (!isEnabled() || fHoverDescriptor == null)
55                         return null;
56
57                 if (isCreated() || createHover())
58                         return fHover.getHoverRegion(textViewer, offset);
59                 else
60                         return null;
61         }
62         
63         /*
64          * @see ITextHover#getHoverInfo(ITextViewer, IRegion)
65          */
66         public String getHoverInfo(ITextViewer textViewer, IRegion hoverRegion) {
67                 if (!isEnabled() || fHoverDescriptor == null)
68                         return null;
69
70                 if (isCreated() || createHover())
71                         return fHover.getHoverInfo(textViewer, hoverRegion);
72                 else
73                         return null;
74         }
75
76         private boolean isCreated() {
77                 return fHover != null;
78         }
79
80         private boolean createHover() {
81                 fHover= fHoverDescriptor.createTextHover();
82                 if (fHover != null)
83                         fHover.setEditor(getEditor());
84                 return isCreated();
85         }
86 }