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
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 package net.sourceforge.phpdt.internal.ui.text.java.hover;
13 import java.util.ArrayList;
14 import java.util.Iterator;
15 import java.util.List;
17 import net.sourceforge.phpdt.ui.PreferenceConstants;
18 import net.sourceforge.phpdt.ui.text.java.hover.IJavaEditorTextHover;
19 import net.sourceforge.phpeclipse.ui.WebUI;
20 //import net.sourceforge.phpeclipse.PHPeclipsePlugin;
22 import org.eclipse.jface.text.IInformationControlCreator;
23 import org.eclipse.jface.text.IRegion;
24 import org.eclipse.jface.text.ITextHover;
25 import org.eclipse.jface.text.ITextHoverExtension;
26 import org.eclipse.jface.text.ITextViewer;
27 import org.eclipse.jface.text.information.IInformationProviderExtension2;
28 //import org.eclipse.ui.IEditorPart;
31 * Caution: this implementation is a layer breaker and contains some "shortcuts"
33 public class BestMatchHover extends AbstractJavaEditorTextHover implements
34 ITextHoverExtension, IInformationProviderExtension2 {
36 private List fTextHoverSpecifications;
38 private List fInstantiatedTextHovers;
40 private ITextHover fBestHover;
42 public BestMatchHover() {
46 // public BestMatchHover(IEditorPart editor) {
52 * Installs all text hovers.
54 private void installTextHovers() {
56 // initialize lists - indicates that the initialization happened
57 fTextHoverSpecifications = new ArrayList(2);
58 fInstantiatedTextHovers = new ArrayList(2);
61 JavaEditorTextHoverDescriptor[] hoverDescs = WebUI
62 .getDefault().getJavaEditorTextHoverDescriptors();
63 for (int i = 0; i < hoverDescs.length; i++) {
64 // ensure that we don't add ourselves to the list
65 if (!PreferenceConstants.ID_BESTMATCH_HOVER.equals(hoverDescs[i]
67 fTextHoverSpecifications.add(hoverDescs[i]);
71 private void checkTextHovers() {
72 if (fTextHoverSpecifications.size() == 0)
75 for (Iterator iterator = new ArrayList(fTextHoverSpecifications)
76 .iterator(); iterator.hasNext();) {
77 JavaEditorTextHoverDescriptor spec = (JavaEditorTextHoverDescriptor) iterator
80 IJavaEditorTextHover hover = spec.createTextHover();
82 hover.setEditor(getEditor());
84 fTextHoverSpecifications.remove(spec);
89 protected void addTextHover(ITextHover hover) {
90 if (!fInstantiatedTextHovers.contains(hover))
91 fInstantiatedTextHovers.add(hover);
95 * @see ITextHover#getHoverInfo(ITextViewer, IRegion)
97 public String getHoverInfo(ITextViewer textViewer, IRegion hoverRegion) {
102 if (fInstantiatedTextHovers == null)
105 for (Iterator iterator = fInstantiatedTextHovers.iterator(); iterator
107 ITextHover hover = (ITextHover) iterator.next();
109 String s = hover.getHoverInfo(textViewer, hoverRegion);
110 if (s != null && s.trim().length() > 0) {
120 * @see org.eclipse.jface.text.ITextHoverExtension#getHoverControlCreator()
123 public IInformationControlCreator getHoverControlCreator() {
124 if (fBestHover instanceof ITextHoverExtension)
125 return ((ITextHoverExtension) fBestHover).getHoverControlCreator();
131 * @see org.eclipse.jface.text.information.IInformationProviderExtension2#getInformationPresenterControlCreator()
134 public IInformationControlCreator getInformationPresenterControlCreator() {
135 if (fBestHover instanceof IInformationProviderExtension2)
136 return ((IInformationProviderExtension2) fBestHover)
137 .getInformationPresenterControlCreator();