Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Problems changing hover size & colors (Xtext 2.24)
Problems changing hover size & colors (Xtext 2.24) [message #1842106] Wed, 09 June 2021 07:38 Go to next message
Eclipse UserFriend
Hello,

I am new to Xtext, and am trying to write custom hovers, but I have an issue changing the hover's default size. What I did :

I have a HoverProviderXtend class, that extends DefaultEObjectHoverProvider and implements ITextHover.

I override getHoverInfoAsHtml(EObject o){ //text displayed depending on the object } to show hover information.
Following this thread : https://www.eclipse.org/forums/index.php/m/901294/?srch=hover+size#msg_901294 I override getHoverControlCreator() like this :

	override getHoverControlCreator() {
		var informationControl = new IInformationControlCreator() {
			override createInformationControl(Shell parent) {
				var defaultInfoControl = new DefaultInformationControl(parent)
				defaultInfoControl.backgroundColor = new Color(0,255,0)
				defaultInfoControl.setSize(500,500)
				return defaultInfoControl
			}
		}
		return informationControl
	}


However, this does not change my hover's color or size. Instead, my hover displays this :

<html><head><style CHARSET="ISO-8859-1" TYPE="text/css">/* Font definitions */
html         { font-family: 'Ubuntu',sans-serif; font-size: 13pt; font-style: normal; font-weight: normal; }
body, h1, h2, h3, h4, h5, h6, p, table, td, caption, th, ul, ol, dl, li, dd, dt { font-size: 1em; }
pre          { font-family: monospace; }

/* Margins */
body	     { overflow: auto; margin-top: 0px; margin-bottom: 0.5em; margin-left: 0.3em; margin-right: 0px; }
h1           { margin-top: 0.3em; margin-bottom: 0.04em; }	
h2           { margin-top: 2em; margin-bottom: 0.25em; }
h3           { margin-top: 1.7em; margin-bottom: 0.25em; }
h4           { margin-top: 2em; margin-bottom: 0.3em; }
h5           { margin-top: 0px; margin-bottom: 0px; }
p            { margin-top: 1em; margin-bottom: 1em; }
pre          { margin-left: 0.6em; }
ul	         { margin-top: 0px; margin-bottom: 1em; margin-left: 1em; padding-left: 1em;}
li	         { margin-top: 0px; margin-bottom: 0px; } 
li p	     { margin-top: 0px; margin-bottom: 0px; } 
ol	         { margin-top: 0px; margin-bottom: 1em; margin-left: 1em; padding-left: 1em; }
dl	         { margin-top: 0px; margin-bottom: 1em; }
dt	         { margin-top: 0px; margin-bottom: 0px; font-weight: bold; }
dd	         { margin-top: 0px; margin-bottom: 0px; }

/* Styles and colors */
a:link	     { color: #0000FF; }
a:hover	     { color: #000080; }
a:visited    { text-decoration: underline; }
a.header:link    { text-decoration: none; color: #eeeeee }
a.header:visited { text-decoration: none; color: #eeeeee }
a.header:hover   { text-decoration: underline; color: #000080; }
h4           { font-style: italic; }
strong	     { font-weight: bold; }
em	         { font-style: italic; }
var	         { font-style: italic; }
th	         { font-weight: bold; }
</style></head><body text="#eeeeee" bgcolor="#34393d"><p style="color:red">This is a TargetDecl.</p></body></html>


If I erase the getHoverControlCreator(), my text is correctly displayed (but the hover size is still too small). What should I do to have a correct hover size/change colors ?


Thank you for your help.
Re: Problems changing hover size & colors (Xtext 2.24) [message #1842108 is a reply to message #1842106] Wed, 09 June 2021 07:45 Go to previous messageGo to next message
Eclipse UserFriend
the default (org.eclipse.xtext.ui.editor.hover.html.DefaultEObjectHoverProvider.HoverControlCreator.doCreateInformationControl(Shell))
does create an XtextBrowserInformationControl, not a DefaultInformationControl
Re: Problems changing hover size & colors (Xtext 2.24) [message #1842115 is a reply to message #1842108] Wed, 09 June 2021 10:41 Go to previous messageGo to next message
Eclipse UserFriend
Hello,

Thanks for your quick answer ! I tried doing this :
	override getHoverControlCreator() {
		var informationControl = new IInformationControlCreator() {
			override createInformationControl(Shell parent) {
				var infoControl = new XtextBrowserInformationControl(parent, definedFont, true)
				infoControl.backgroundColor = new Color(0,255,0)
				infoControl.setSize(10,10)
				return infoControl
			}
		}
		return informationControl
	}


However, my runtime Eclipse freezes when I try to Hover. I debugged to see where was the problem and saw that the infoControl was well created, but in the AbstractInformationControlManager, there is an exception thrown when trying to do the computeTrim() method (last line):
	private void internalShowInformationControl(Rectangle subjectArea, Object information) {
		if (this instanceof InformationControlReplacer) {
			((InformationControlReplacer) this).showInformationControl(subjectArea, information);
			return;
		}

		IInformationControl informationControl= getInformationControl();
		if (informationControl != null) {

			Point sizeConstraints= computeSizeConstraints(fSubjectControl, fSubjectArea, informationControl);
			if (informationControl instanceof IInformationControlExtension3) {
				IInformationControlExtension3 iControl3= (IInformationControlExtension3) informationControl;
				Rectangle trim= iControl3.computeTrim();


Do you know why is this happening ? My runtime Eclipse just freezes when I hover, and no exceptions are shown.
Re: Problems changing hover size & colors (Xtext 2.24) [message #1842116 is a reply to message #1842115] Wed, 09 June 2021 10:42 Go to previous messageGo to next message
Eclipse UserFriend
sry have no idea on this
Re: Problems changing hover size & colors (Xtext 2.24) [message #1842122 is a reply to message #1842116] Wed, 09 June 2021 12:16 Go to previous messageGo to next message
Eclipse UserFriend
Hi

A recursive method call is very easy when overriding frameworks and often results in a hang. Eclipse is really bad at dealing with Stack Overflow. Too often it finds it has run out of memory and so cannot call a routine to diagnose.

Use a debugger or JVisualVM to break and see what is executing a few seconds after the hang starts.

Regards

Ed Willink
Re: Problems changing hover size & colors (Xtext 2.24) [message #1842276 is a reply to message #1842122] Tue, 15 June 2021 05:30 Go to previous messageGo to next message
Eclipse UserFriend
Hello,

I discovered that my problem comes from
return new XtextBrowserInformationControl(parent, font, true)

if i change the 'resizable' parameter to 'false', my hovers appear again...
But obviously, the 'setSize()' method does not apply afterwards.

[Updated on: Tue, 15 June 2021 05:30] by Moderator

Re: Problems changing hover size & colors (Xtext 2.24) [message #1843177 is a reply to message #1842276] Mon, 19 July 2021 05:50 Go to previous message
Eclipse UserFriend
Hello,

Concerning the customizable hovers, I managed to achieve this by using instead SWT tools : I create a SWT browser that I customize and set to Visible when needed.

Thank you all for you propositions !
Previous Topic:Customizing XtextAnnotation
Next Topic:Xtext and Java 16
Goto Forum:
  


Current Time: Sun Jul 06 05:34:51 EDT 2025

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

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

Back to the top