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
Watabe Kichi is currently offline Watabe KichiFriend
Messages: 25
Registered: July 2011
Junior 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();
	}
}
Previous Topic:JFace databinding
Next Topic:JFace Action that supports drop-down AND checkbox
Goto Forum:
  


Current Time: Mon Dec 09 15:26:56 GMT 2019

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

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

Back to the top