org.eclipse.jface.text.ITextHover Java Examples

The following examples show how to use org.eclipse.jface.text.ITextHover. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractCompositeHoverTest.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@SuppressWarnings("deprecation")
@Test public void testNullHoverList () {
	AbstractCompositeHover hover = new AbstractCompositeHover() {

		@Override
		protected List<ITextHover> createHovers() {
			return null;
		}
	};

	assertEquals (null, hover.getHovers());
	assertNull (hover.getHoverRegion(editor.getInternalSourceViewer(), 0));
	assertNull (hover.getHoverControlCreator());
	assertNull (hover.getHoverInfo(editor.getInternalSourceViewer(), new Region(0,0)));
	assertNull (hover.getHoverInfo2(editor.getInternalSourceViewer(), new Region(0,0)));
}
 
Example #2
Source File: AbstractCompositeHoverTest.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@SuppressWarnings("deprecation")
@Test public void testEmptyHoverList () {
	AbstractCompositeHover hover = new AbstractCompositeHover() {

		@Override
		protected List<ITextHover> createHovers() {
			List<ITextHover> hovers = Lists.newArrayList();
			return hovers;
		}
	};

	assertEquals (0, hover.getHovers().size());
	assertNull (hover.getHoverRegion(editor.getInternalSourceViewer(), 0));
	assertNull (hover.getHoverControlCreator());
	assertNull (hover.getHoverInfo(editor.getInternalSourceViewer(), new Region(0,0)));
	assertNull (hover.getHoverInfo2(editor.getInternalSourceViewer(), new Region(0,0)));
}
 
Example #3
Source File: ModulaEditorTextHover.java    From xds-ide with Eclipse Public License 1.0 6 votes vote down vote up
/**
   * {@inheritDoc}
   */
  @Override
  public String getHoverInfo(ITextViewer textViewer, IRegion hoverRegion) {
// Check through the contributed hover providers.
for (ITextHover hoverContributer : hoverContributors) {
	@SuppressWarnings("deprecation")
	String hoverText = hoverContributer.getHoverInfo(textViewer,
			hoverRegion);

	if (hoverText != null) {
		lastReturnedHover = hoverContributer;

		return hoverText;
	}
}
      
      return String.valueOf(getHoverInfo2(textViewer, hoverRegion));
  }
 
Example #4
Source File: BestMatchHover.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public String getHoverInfo(ITextViewer textViewer, IRegion hoverRegion) {

		checkTextHovers();
		fBestHover= null;

		if (fInstantiatedTextHovers == null)
			return null;

		for (Iterator<IJavaEditorTextHover> iterator= fInstantiatedTextHovers.iterator(); iterator.hasNext(); ) {
			ITextHover hover= iterator.next();
			if (hover == null)
				continue;

			String s= hover.getHoverInfo(textViewer, hoverRegion);
			if (s != null && s.trim().length() > 0) {
				fBestHover= hover;
				return s;
			}
		}

		return null;
	}
 
Example #5
Source File: DotHtmlLabelAdaptingTextHover.java    From gef with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public IRegion getHoverRegion(ITextViewer textViewer, int offset) {
	HtmlOffsetPair html = htmlOffsetPair(offset, textViewer);
	if (html == null) {
		return super.getHoverRegion(textViewer, offset);
	}
	synchronized (sourceViewer) {
		try {
			sourceViewer.setDocument(
					DotEditorUtils.getDocument(injector, html.code));
		} catch (Exception e) {
			return super.getHoverRegion(textViewer, offset);
		}
		if (hover instanceof ITextHover) {
			IRegion htmlRegion = ((ITextHover) hover)
					.getHoverRegion(sourceViewer, offset - html.offset);
			if (htmlRegion == null) {
				return null;
			}
			return new Region(html.offset + htmlRegion.getOffset(),
					htmlRegion.getLength());
		}
	}
	return super.getHoverRegion(textViewer, offset);
}
 
Example #6
Source File: AbstractCompositeHover.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public IRegion getHoverRegion(ITextViewer textViewer, int offset) {
	if (getHovers() != null) {
		for (ITextHover hover : getHovers()) {
			IRegion region = hover.getHoverRegion(textViewer, offset);
			if (region != null) {
				// We always take the first that answers with a region
				// In org.eclipse.xtext.ui.editor.hover.DefaultCompositeHover.createHovers() the AnnotationWithQuickFixesHover 
				// is always the first and answers with a region only when there is a problemmarker
				// In all other cases an instance of org.eclipse.xtext.ui.editor.hover.DispatchingEObjectTextHover is the next in the order.
				currentHover = hover;
				return region;
			}
		}
	}
	currentHover = null;
	return null;
}
 
Example #7
Source File: DebugScriptSourceViewerConfiguration.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
public ITextHover getTextHover( ISourceViewer sourceViewer,
		String contentType, int stateMask )
{

	if ( !( JSPartitionScanner.JS_COMMENT.equals( contentType )
			//|| JSPartitionScanner.JS_KEYWORD.equals( contentType ) 
			|| JSPartitionScanner.JS_STRING.equals( contentType ) ) )
	{
		return new ScriptDebugHover( );
	}
	return super.getTextHover( sourceViewer, contentType, stateMask );
}
 
Example #8
Source File: ModulaEditorTextHover.java    From xds-ide with Eclipse Public License 1.0 5 votes vote down vote up
public ModulaEditorTextHover(ITextEditor editor, ITextHover defaultHover, ResourceRegistry resourceRegistry) {
      this.editor = editor;
      if (editor != null) {
      	this.project = CoreEditorUtils.getIProjectFrom(editor.getEditorInput());
      }
      else{
      	this.project = null;
      }
      this.defaultHover = defaultHover;
      this.fDecorationColor = JFaceResources.getColorRegistry().get(JFacePreferences.DECORATIONS_COLOR);
      this.resourceRegistry = resourceRegistry;
      
ModulaEditorHoverRegistry.get().contributions().stream()
		.forEach(ModulaEditorTextHover::addContributer);
  }
 
Example #9
Source File: ModulaEditorTextHover.java    From xds-ide with Eclipse Public License 1.0 5 votes vote down vote up
/**
   * {@inheritDoc}
   */
  @Override
  public Object getHoverInfo2(ITextViewer textViewer, IRegion hoverRegion) {
// Overridden from ITextHoverExtension2. We try and return the richest
// help available; this
// means trying to call getHoverInfo2() on any contributors, and falling
// back on getHoverInfo().
lastReturnedHover = null;

// Check through the contributed hover providers.
for (ITextHover hoverContributer : hoverContributors) {
	if (hoverContributer instanceof ITextHoverExtension2) {
		Object hoverInfo = ((ITextHoverExtension2) hoverContributer)
				.getHoverInfo2(textViewer, hoverRegion);

		if (hoverInfo != null) {
			lastReturnedHover = hoverContributer;
			return hoverInfo;
		}
	} else {
		@SuppressWarnings("deprecation")
		String hoverText = hoverContributer.getHoverInfo(textViewer,
				hoverRegion);

		if (hoverText != null) {
			lastReturnedHover = hoverContributer;
			return hoverText;
		}
	}
}
      
      return getModulaDocHover(textViewer, hoverRegion);
  }
 
Example #10
Source File: DotSourceViewerConfiguration.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public ITextHover getTextHover(ISourceViewer sourceViewer,
		String contentType) {
	if (contentType.equals(
			DotTerminalsTokenTypeToPartitionMapper.HTML_STRING_PARTITION)) {
		ITextHover hover = htmlHoverProvider.get();
		if (hover instanceof ISourceViewerAware) {
			((ISourceViewerAware) hover).setSourceViewer(sourceViewer);
		}
		return hover;
	}
	return super.getTextHover(sourceViewer, contentType);
}
 
Example #11
Source File: TLASourceViewerConfiguration.java    From tlaplus with MIT License 5 votes vote down vote up
@Override
public ITextHover getTextHover(ISourceViewer sourceViewer, String contentType) {
	if (TLAPartitionScanner.TLA_PCAL.equals(contentType)) {
		return new PCalHover();
	}
	return new ToolboxHover();
}
 
Example #12
Source File: TLACoverageEditor.java    From tlaplus with MIT License 5 votes vote down vote up
@Override
public ITextHover getTextHover(final ISourceViewer sourceViewer, String contentType) {
	return new DefaultTextHover(sourceViewer) {
		@Override
		public String getHoverInfo(ITextViewer textViewer, IRegion hoverRegion) {
			return coverage.getHoverInfo(hoverRegion.getOffset());
		}
	};
}
 
Example #13
Source File: BestMatchHover.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private static IInformationControlCreator getInformationPresenterControlCreator(ITextHover hover) {
	if (hover instanceof IInformationProviderExtension2) // this is wrong, but left here for backwards compatibility
		return ((IInformationProviderExtension2)hover).getInformationPresenterControlCreator();

	if (hover instanceof AbstractJavaEditorTextHover) {
		return ((AbstractJavaEditorTextHover) hover).getInformationPresenterControlCreator();
	}
	return null;
}
 
Example #14
Source File: BestMatchHover.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Returns the information which should be presented when a hover or persistent popup is shown
 * for the specified hover region.
 * 
 * @param textViewer the viewer on which the hover popup should be shown
 * @param hoverRegion the text range in the viewer which is used to determine the hover display
 *            information
 * @param forInformationProvider <code>true</code> iff the hover info is requested by the
 *            information presenter. In this case, the method only considers text hovers for
 *            which a proper IInformationControlCreator is available that can supply focusable
 *            and resizable information controls.
 * 
 * @return the hover popup display information, or <code>null</code> if none available
 * 
 * @see ITextHoverExtension2#getHoverInfo2(ITextViewer, IRegion)
 * @since 3.8
 */
public Object getHoverInfo2(ITextViewer textViewer, IRegion hoverRegion, boolean forInformationProvider) {

	checkTextHovers();
	fBestHover= null;

	if (fInstantiatedTextHovers == null)
		return null;

	for (Iterator<IJavaEditorTextHover> iterator= fInstantiatedTextHovers.iterator(); iterator.hasNext(); ) {
		ITextHover hover= iterator.next();
		if (hover == null)
			continue;

		if (hover instanceof ITextHoverExtension2) {
			Object info= ((ITextHoverExtension2) hover).getHoverInfo2(textViewer, hoverRegion);
			if (info != null && !(forInformationProvider && getInformationPresenterControlCreator(hover) == null)) {
				fBestHover= hover;
				return info;
			}
		} else {
			String s= hover.getHoverInfo(textViewer, hoverRegion);
			if (s != null && s.trim().length() > 0) {
				fBestHover= hover;
				return s;
			}
		}
	}

	return null;
}
 
Example #15
Source File: CommonSourceViewerConfiguration.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
@Override
public IRegion getHoverRegion(ITextViewer textViewer, int offset)
{
	activeTextHover = null;
	List<TextHoverDescriptor> descriptors = getEnabledTextHoverDescriptors(textViewer, offset);
	for (TextHoverDescriptor descriptor : descriptors)
	{
		ITextHover textHover = descriptor.createTextHover();
		IRegion region = null;
		if (textHover != null)
		{
			region = textHover.getHoverRegion(textViewer, offset);
		}
		if (region != null)
		{
			if (descriptors.size() > 1)
			{
				if (textHover instanceof ITextHoverExtension2)
				{
					if (((ITextHoverExtension2) textHover).getHoverInfo2(textViewer, region) == null)
					{
						continue;
					}
				}
				else if (textHover.getHoverInfo(textViewer, region) == null)
				{
					continue;
				}
			}
			activeTextHover = textHover;
			return region;
		}
	}
	return super.getHoverRegion(textViewer, offset);
}
 
Example #16
Source File: TextHoverDescriptor.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates text hover
 * @return
 */
public ITextHover createTextHover() {
	try {
		return (ITextHover) configurationElement.createExecutableExtension(ATT_CLASS);
	} catch (CoreException e) {
		IdeLog.logError(CommonEditorPlugin.getDefault(), e);
	}
	return null;
}
 
Example #17
Source File: JavaSourceViewerConfiguration.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public ITextHover getTextHover(ISourceViewer sourceViewer, String contentType, int stateMask) {
	JavaEditorTextHoverDescriptor[] hoverDescs= JavaPlugin.getDefault().getJavaEditorTextHoverDescriptors();
	int i= 0;
	while (i < hoverDescs.length) {
		if (hoverDescs[i].isEnabled() &&  hoverDescs[i].getStateMask() == stateMask)
			return new JavaEditorTextHoverProxy(hoverDescs[i], getEditor());
		i++;
	}

	return null;
}
 
Example #18
Source File: PyEditConfiguration.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public ITextHover getTextHover(ISourceViewer sourceViewer, String contentType, int stateMask) {
    /**
     * Return the combining hover if the preferences are set accordingly and the state mask matches.
     */
    if (PyHoverPreferencesPage.getCombineHoverInfo()) {
        PyEditorTextHoverDescriptor combiningHover = PydevPlugin.getCombiningHoverDescriptor();
        if (combiningHover.getStateMask() == stateMask) {
            return new PyEditorTextHoverProxy(combiningHover, contentType);
        }
    }

    /**
     * We return the highest priority registered hover whose state mask matches. If two or more hovers
     * have the highest priority, it is indeterminate which will be selected. The proper way to combine
     * hover info is to select that option on the PyDev->Editor->Hover preference page. This will cause
     * the combining hover to be returned by the code above.
     */
    PyEditorTextHoverDescriptor[] hoverDescs = PydevPlugin.getDefault().getPyEditorTextHoverDescriptors();
    int i = 0;
    while (i < hoverDescs.length) {
        if (hoverDescs[i].isEnabled() && hoverDescs[i].getStateMask() == stateMask) {
            return new PyEditorTextHoverProxy(hoverDescs[i], contentType);
        }
        i++;
    }

    return null;
}
 
Example #19
Source File: XtextSourceViewerConfiguration.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public ITextHover getTextHover(ISourceViewer sourceViewer, String contentType) {
	ITextHover hover = textHoverProvider.get();
	if (hover instanceof ISourceViewerAware) {
		((ISourceViewerAware) hover).setSourceViewer(sourceViewer);
	}
	return hover;
}
 
Example #20
Source File: DefaultCompositeHover.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected List<ITextHover> createHovers() {
	List<ITextHover> list = new ArrayList<ITextHover>();
	list.add (annotationHover);
	if(htmlHover instanceof ITextHover)
		list.add ((ITextHover) htmlHover);
	return list;
}
 
Example #21
Source File: AbstractCompositeHover.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void setSourceViewer(ISourceViewer sourceViewer) {
	if (getHovers() != null) {
		for (ITextHover hover : getHovers()) {
			if (hover instanceof ISourceViewerAware)
				((ISourceViewerAware) hover).setSourceViewer(sourceViewer);
		}
	}
}
 
Example #22
Source File: PropertiesFileSourceViewerConfiguration.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public ITextHover getTextHover(ISourceViewer sourceViewer, String contentType, int stateMask) {
	return new PropertiesFileHover(super.getTextHover(sourceViewer, contentType));
}
 
Example #23
Source File: HConfiguration.java    From http4e with Apache License 2.0 4 votes vote down vote up
/**
 * @Override
 */
public ITextHover getTextHover( ISourceViewer sourceViewer, String contentType){
   return new MyTextHover();
}
 
Example #24
Source File: AbstractLangSourceViewerConfiguration.java    From goclipse with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public ITextHover getTextHover(ISourceViewer sourceViewer, String contentType, int stateMask) {
	return getBestMatchHover();
}
 
Example #25
Source File: AbstractLangSourceViewerConfiguration.java    From goclipse with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public final ITextHover getTextHover(ISourceViewer sourceViewer, String contentType) {
	return getTextHover(sourceViewer, contentType, ITextViewerExtension2.DEFAULT_HOVER_STATE_MASK);
}
 
Example #26
Source File: ScriptConsoleViewerWrapper.java    From Pydev with Eclipse Public License 1.0 4 votes vote down vote up
public ITextHover getCurrentTextHover() {
    return viewer.getCurrentTextHover();
}
 
Example #27
Source File: ScriptConsoleViewerWrapper.java    From Pydev with Eclipse Public License 1.0 4 votes vote down vote up
public void setTextHover(ITextHover hover, String contentType, int stateMask) {
    viewer.setTextHover(hover, contentType, stateMask);
}
 
Example #28
Source File: ScriptConsoleViewerWrapper.java    From Pydev with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public void setTextHover(ITextHover hover, String contentType) {
    viewer.setTextHover(hover, contentType);
}
 
Example #29
Source File: SimpleJavaSourceViewerConfiguration.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public ITextHover getTextHover(ISourceViewer sourceViewer, String contentType, int stateMask) {
	return null;
}
 
Example #30
Source File: SimpleJavaSourceViewerConfiguration.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public ITextHover getTextHover(ISourceViewer sourceViewer, String contentType) {
	return null;
}