Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2008 itemis AG (http://www.itemis.eu) and others. All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html /
 
 package org.eclipse.xtext.ui.editor.hover;
import  org.eclipse.jface.text.BadLocationException;
import  org.eclipse.jface.text.DefaultInformationControl;
import  org.eclipse.jface.text.IDocument;
import  org.eclipse.jface.text.IInformationControl;
import  org.eclipse.jface.text.IInformationControlCreator;
import  org.eclipse.jface.text.IRegion;
import  org.eclipse.jface.text.ITextHover;
import  org.eclipse.jface.text.ITextHoverExtension;
import  org.eclipse.jface.text.ITextHoverExtension2;
import  org.eclipse.jface.text.ITextViewer;
import  org.eclipse.jface.text.Region;
import  org.eclipse.jface.text.source.ISourceViewer;
import  org.eclipse.swt.graphics.Point;
import  org.eclipse.swt.widgets.Shell;
import  org.eclipse.ui.editors.text.EditorsUI;

Author(s):
Patrick Schoenbach - Initial API and implementation
public abstract class AbstractHover implements ITextHover, ITextHoverExtension, ITextHoverExtension2, ISourceViewerAware {
	protected ISourceViewer sourceViewer;
	public void setSourceViewer(ISourceViewer sourceViewer) {
		this. = sourceViewer;		
	}
	public IDocument getDocument() {
		return .getDocument();
	}


Deprecated:
Use getHoverInfo2(ITextViewer, IRegion) instead
	public String getHoverInfo(final ITextViewer textViewerfinal IRegion hoverRegion) {
		Object o = getHoverInfo2(textViewerhoverRegion);
		if (o!=null)
			return o.toString();
		return null;
	}
	public int getLineNumber (final ITextViewer textViewerfinal IRegion hoverRegionthrows BadLocationException {
		return textViewer.getDocument().getLineOfOffset(hoverRegion.getOffset());
	}
	public IRegion getHoverRegion(final ITextViewer textViewerfinal int offset) {
		final Point selection = textViewer.getSelectedRange();
		if (selection.x <= offset && offset < selection.x + selection.y)
			return new Region(selection.x, selection.y);
		return new Region(offset, 0);
	}
	/*
	 * @see ITextHoverExtension#getHoverControlCreator()
	 * @since 3.0
	 */
	public IInformationControlCreator getHoverControlCreator() {
		return new IInformationControlCreator() {
			public IInformationControl createInformationControl(Shell parent) {
				return new DefaultInformationControl(parent, EditorsUI.getTooltipAffordanceString());
			}
		};
	}
New to GrepCode? Check out our FAQ X