Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » JFace » How to make BrowserInformationControl focusable(TextHover)
How to make BrowserInformationControl focusable [message #1795752] Thu, 27 September 2018 23:44 Go to next message
Missing name Mising name is currently offline Missing name Mising nameFriend
Messages: 41
Registered: July 2011
Member
Hello, I'm writing this message from Japan.

I want to make org.eclipse.jface.internal.text.html.BrowserInformationControl focusable (sticky).

It failed to focus by pressing F2 or mouse moving into popup (Hover Popup disappears).

If I use DefaultInformationControl instead, popups can be focused without any problem.

Thank you very much in advance.

--- My Environment
Windows 10
SWT+JFace jars are taken from plugin directory of eclipse 4.7
---

Here is a single file SSCCE.

import org.eclipse.jface.internal.text.html.BrowserInformationControl;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.jface.text.Document;
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.ITextViewer;
import org.eclipse.jface.text.Region;
import org.eclipse.jface.text.TextViewer;
import org.eclipse.jface.text.source.SourceViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Layout;
import org.eclipse.swt.widgets.Shell;

public class SimpleHoverTest extends SWTApp {

	public static void main(String[] args) {
		Composite comp = launch();
		
		TextViewer viewer = new SourceViewer(comp, null, SWT.NONE);
		
		viewer.setHoverControlCreator(new IInformationControlCreator() {

			@Override
			public IInformationControl createInformationControl(Shell parent) {
				return new BrowserInformationControl(comp.getShell(), JFaceResources.DIALOG_FONT, "Press F2 to Focus");
			}
			
		});
		
		viewer.setTextHover(new ITextHover() {

			@Override
			public String getHoverInfo(ITextViewer textViewer, IRegion hoverRegion) {
				return "TEST";
			}

			@Override
			public IRegion getHoverRegion(ITextViewer textViewer, int offset) {
				return new Region(offset, 5);
			}
			
		}, IDocument.DEFAULT_CONTENT_TYPE);
		
		viewer.setDocument(new Document());
		viewer.getTextWidget().setText("TEST\nTEST\nTEST\nTEST\nTEST");
		
		
		loop(false);
	}
	
}

class SWTApp {
	private static Display display;
	private static Shell   shell;
	
	protected static Composite launch() {
		return launch(new FillLayout());
	}
	
	protected static Composite launch( Layout layout ) {
		display = new Display();
		shell = new Shell(display);
		
		shell.setLayout(new FillLayout());
		Composite comp = new Composite(shell, SWT.None);
		comp.setLayout( layout );
		
		return comp;
	}
	
	protected static void loop() {
	    loop(true);
	}
	
	protected static void loop(boolean pack) {
		shell.open();
		if(pack) shell.pack();
		while( !shell.isDisposed() ) {
			if( !display.readAndDispatch() ) {
				display.sleep();
			}
		}
		display.dispose();
	}
}
Re: How to make BrowserInformationControl focusable [message #1819138 is a reply to message #1795752] Wed, 08 January 2020 15:26 Go to previous messageGo to next message
Jerry Bib is currently offline Jerry BibFriend
Messages: 13
Registered: October 2015
Junior Member
I ran into exactly same problem. Can anyone help here?
Re: How to make BrowserInformationControl focusable [message #1819168 is a reply to message #1795752] Thu, 09 January 2020 09:23 Go to previous message
Jerry Bib is currently offline Jerry BibFriend
Messages: 13
Registered: October 2015
Junior Member
I'm really surprised as to how complex this issue can be that no one posted any comment for so long.

Anyway, after digging up intensively in the code, I found the solution:

BrowserInformationControl needs to be extended to implement the function:
getInformationPresenterControlCreator() of AbstractInformationControl
which is not implemented by default.

	/*
	 * @see org.eclipse.jface.text.IInformationControlExtension5#getInformationPresenterControlCreator()
	 * @since 3.4
	 */
	public IInformationControlCreator getInformationPresenterControlCreator() {
		return new IInformationControlCreator() {
			/*
			 * @see org.eclipse.jface.text.IInformationControlCreator#createInformationControl(org.eclipse.swt.widgets.Shell)
			 */
			public IInformationControl createInformationControl(Shell parent) {
				boolean resizable = true;
				return new MyBrowserInformationControl(parent, fSymbolicFontName, resizable);
			}
		};
	}



Previous Topic:How to make TextHover sticky?
Next Topic:Display Table viewer with many columns
Goto Forum:
  


Current Time: Thu Oct 01 09:06:25 GMT 2020

Powered by FUDForum. Page generated in 0.01751 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top