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;
12 import java.util.ArrayList;
13 import java.util.Iterator;
14 import java.util.List;
16 import net.sourceforge.phpdt.ui.PreferenceConstants;
17 import net.sourceforge.phpdt.ui.text.java.hover.IJavaEditorTextHover;
18 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
20 import org.eclipse.jface.text.IInformationControlCreator;
21 import org.eclipse.jface.text.IRegion;
22 import org.eclipse.jface.text.ITextHover;
23 import org.eclipse.jface.text.ITextHoverExtension;
24 import org.eclipse.jface.text.ITextViewer;
25 import org.eclipse.jface.text.information.IInformationProviderExtension2;
26 import org.eclipse.ui.IEditorPart;
30 * Caution: this implementation is a layer breaker and contains some "shortcuts"
32 public class BestMatchHover extends AbstractJavaEditorTextHover implements ITextHoverExtension, IInformationProviderExtension2 {
34 private List fTextHoverSpecifications;
35 private List fInstantiatedTextHovers;
36 private ITextHover fBestHover;
38 public BestMatchHover() {
42 public BestMatchHover(IEditorPart editor) {
48 * Installs all text hovers.
50 private void installTextHovers() {
52 // initialize lists - indicates that the initialization happened
53 fTextHoverSpecifications= new ArrayList(2);
54 fInstantiatedTextHovers= new ArrayList(2);
57 JavaEditorTextHoverDescriptor[] hoverDescs= PHPeclipsePlugin.getDefault().getJavaEditorTextHoverDescriptors();
58 for (int i= 0; i < hoverDescs.length; i++) {
59 // ensure that we don't add ourselves to the list
60 if (!PreferenceConstants.ID_BESTMATCH_HOVER.equals(hoverDescs[i].getId()))
61 fTextHoverSpecifications.add(hoverDescs[i]);
65 private void checkTextHovers() {
66 if (fTextHoverSpecifications.size() == 0)
69 for (Iterator iterator= new ArrayList(fTextHoverSpecifications).iterator(); iterator.hasNext(); ) {
70 JavaEditorTextHoverDescriptor spec= (JavaEditorTextHoverDescriptor) iterator.next();
72 IJavaEditorTextHover hover= spec.createTextHover();
74 hover.setEditor(getEditor());
76 fTextHoverSpecifications.remove(spec);
81 protected void addTextHover(ITextHover hover) {
82 if (!fInstantiatedTextHovers.contains(hover))
83 fInstantiatedTextHovers.add(hover);
87 * @see ITextHover#getHoverInfo(ITextViewer, IRegion)
89 public String getHoverInfo(ITextViewer textViewer, IRegion hoverRegion) {
94 if (fInstantiatedTextHovers == null)
97 for (Iterator iterator= fInstantiatedTextHovers.iterator(); iterator.hasNext(); ) {
98 ITextHover hover= (ITextHover)iterator.next();
100 String s= hover.getHoverInfo(textViewer, hoverRegion);
101 if (s != null && s.trim().length() > 0) {
111 * @see org.eclipse.jface.text.ITextHoverExtension#getHoverControlCreator()
114 public IInformationControlCreator getHoverControlCreator() {
115 if (fBestHover instanceof ITextHoverExtension)
116 return ((ITextHoverExtension)fBestHover).getHoverControlCreator();
122 * @see org.eclipse.jface.text.information.IInformationProviderExtension2#getInformationPresenterControlCreator()
125 public IInformationControlCreator getInformationPresenterControlCreator() {
126 if (fBestHover instanceof IInformationProviderExtension2)
127 return ((IInformationProviderExtension2)fBestHover).getInformationPresenterControlCreator();