1 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 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 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 57 public IRegion getHoverRegion(ITextViewer textViewer, int offset) { 58 if (ensureHoverCreated()) 59 return fHover.getHoverRegion(textViewer, offset); 60 61 return null; 62 } 63 64 67 public String 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 95 public IInformationControlCreator getHoverControlCreator() { 96 if (ensureHoverCreated() && (fHover instanceof ITextHoverExtension)) 97 return ((ITextHoverExtension)fHover).getHoverControlCreator(); 98 99 return null; 100 } 101 102 105 public IInformationControlCreator getInformationPresenterControlCreator() { 106 if (ensureHoverCreated() && (fHover instanceof IInformationProviderExtension2)) 107 return ((IInformationProviderExtension2)fHover).getInformationPresenterControlCreator(); 108 109 return null; 110 } 111 } 112 | Popular Tags |