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;
31 * Caution: this implementation is a layer breaker and contains some "shortcuts"
33 public class BestMatchHover extends AbstractJavaEditorTextHover implements ITextHoverExtension, IInformationProviderExtension2 {
35 private List fTextHoverSpecifications;
36 private List fInstantiatedTextHovers;
37 private ITextHover fBestHover;
39 public BestMatchHover() {
43 public BestMatchHover(IEditorPart editor) {
49 * Installs all text hovers.
51 private void installTextHovers() {
53 // initialize lists - indicates that the initialization happened
54 fTextHoverSpecifications= new ArrayList(2);
55 fInstantiatedTextHovers= new ArrayList(2);
58 JavaEditorTextHoverDescriptor[] hoverDescs= PHPeclipsePlugin.getDefault().getJavaEditorTextHoverDescriptors();
59 for (int i= 0; i < hoverDescs.length; i++) {
60 // ensure that we don't add ourselves to the list
61 if (!PreferenceConstants.ID_BESTMATCH_HOVER.equals(hoverDescs[i].getId()))
62 fTextHoverSpecifications.add(hoverDescs[i]);
66 private void checkTextHovers() {
67 if (fTextHoverSpecifications.size() == 0)
70 for (Iterator iterator= new ArrayList(fTextHoverSpecifications).iterator(); iterator.hasNext(); ) {
71 JavaEditorTextHoverDescriptor spec= (JavaEditorTextHoverDescriptor) iterator.next();
73 IJavaEditorTextHover hover= spec.createTextHover();
75 hover.setEditor(getEditor());
77 fTextHoverSpecifications.remove(spec);
82 protected void addTextHover(ITextHover hover) {
83 if (!fInstantiatedTextHovers.contains(hover))
84 fInstantiatedTextHovers.add(hover);
88 * @see ITextHover#getHoverInfo(ITextViewer, IRegion)
90 public String getHoverInfo(ITextViewer textViewer, IRegion hoverRegion) {
95 if (fInstantiatedTextHovers == null)
98 for (Iterator iterator= fInstantiatedTextHovers.iterator(); iterator.hasNext(); ) {
99 ITextHover hover= (ITextHover)iterator.next();
101 String s= hover.getHoverInfo(textViewer, hoverRegion);
102 if (s != null && s.trim().length() > 0) {
112 * @see org.eclipse.jface.text.ITextHoverExtension#getInformationControlCreator()
115 public IInformationControlCreator getInformationControlCreator() {
116 if (fBestHover instanceof ITextHoverExtension)
117 return ((ITextHoverExtension)fBestHover).getInformationControlCreator();
123 * @see org.eclipse.jface.text.information.IInformationProviderExtension2#getInformationPresenterControlCreator()
126 public IInformationControlCreator getInformationPresenterControlCreator() {
127 if (fBestHover instanceof IInformationProviderExtension2)
128 return ((IInformationProviderExtension2)fBestHover).getInformationPresenterControlCreator();