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.PHPeclipsePlugin;
21 import org.eclipse.jface.text.IInformationControlCreator;
22 import org.eclipse.jface.text.IRegion;
23 import org.eclipse.jface.text.ITextHover;
24 import org.eclipse.jface.text.ITextHoverExtension;
25 import org.eclipse.jface.text.ITextViewer;
26 import org.eclipse.jface.text.information.IInformationProviderExtension2;
27 import org.eclipse.ui.IEditorPart;
30 * Caution: this implementation is a layer breaker and contains some "shortcuts"
32 public class BestMatchHover extends AbstractJavaEditorTextHover implements
33 ITextHoverExtension, IInformationProviderExtension2 {
35 private List fTextHoverSpecifications;
37 private List fInstantiatedTextHovers;
39 private ITextHover fBestHover;
41 public BestMatchHover() {
45 public BestMatchHover(IEditorPart editor) {
51 * Installs all text hovers.
53 private void installTextHovers() {
55 // initialize lists - indicates that the initialization happened
56 fTextHoverSpecifications = new ArrayList(2);
57 fInstantiatedTextHovers = new ArrayList(2);
60 JavaEditorTextHoverDescriptor[] hoverDescs = PHPeclipsePlugin
61 .getDefault().getJavaEditorTextHoverDescriptors();
62 for (int i = 0; i < hoverDescs.length; i++) {
63 // ensure that we don't add ourselves to the list
64 if (!PreferenceConstants.ID_BESTMATCH_HOVER.equals(hoverDescs[i]
66 fTextHoverSpecifications.add(hoverDescs[i]);
70 private void checkTextHovers() {
71 if (fTextHoverSpecifications.size() == 0)
74 for (Iterator iterator = new ArrayList(fTextHoverSpecifications)
75 .iterator(); iterator.hasNext();) {
76 JavaEditorTextHoverDescriptor spec = (JavaEditorTextHoverDescriptor) iterator
79 IJavaEditorTextHover hover = spec.createTextHover();
81 hover.setEditor(getEditor());
83 fTextHoverSpecifications.remove(spec);
88 protected void addTextHover(ITextHover hover) {
89 if (!fInstantiatedTextHovers.contains(hover))
90 fInstantiatedTextHovers.add(hover);
94 * @see ITextHover#getHoverInfo(ITextViewer, IRegion)
96 public String getHoverInfo(ITextViewer textViewer, IRegion hoverRegion) {
101 if (fInstantiatedTextHovers == null)
104 for (Iterator iterator = fInstantiatedTextHovers.iterator(); iterator
106 ITextHover hover = (ITextHover) iterator.next();
108 String s = hover.getHoverInfo(textViewer, hoverRegion);
109 if (s != null && s.trim().length() > 0) {
119 * @see org.eclipse.jface.text.ITextHoverExtension#getHoverControlCreator()
122 public IInformationControlCreator getHoverControlCreator() {
123 if (fBestHover instanceof ITextHoverExtension)
124 return ((ITextHoverExtension) fBestHover).getHoverControlCreator();
130 * @see org.eclipse.jface.text.information.IInformationProviderExtension2#getInformationPresenterControlCreator()
133 public IInformationControlCreator getInformationPresenterControlCreator() {
134 if (fBestHover instanceof IInformationProviderExtension2)
135 return ((IInformationProviderExtension2) fBestHover)
136 .getInformationPresenterControlCreator();