Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » e(fx)clipse » What bundle should I depend on for javafx.embed.swt.FXCanvas?
What bundle should I depend on for javafx.embed.swt.FXCanvas? [message #1766551] Fri, 23 June 2017 01:02 Go to next message
Theodore Murdock is currently offline Theodore MurdockFriend
Messages: 5
Registered: January 2015
Junior Member
I'm wondering what bundle one should depend on currently in order to have access to javafx.embed.swt.FXCanvas in an Eclipse plugin.

I'm in the process of switching a plugin from depending on a customized version of SWT_AWT + Albireo to instead use FXCanvas + SwingNode to display Swing components in Eclipse. (SWT_AWT + Albireo is deadlock prone, we've modified it over the years to remove synchronous calls between the SWT and AWT threads, but the bridge still causes some issues, such as tooltips being unreliable in SWT, which makes the FXCanvas approach very attractive.)

I gather, from what I've seen, that classloading FXCanvas is a bit complicated in osgi, but I was happy to see that you had put out an orbit bundle (org.eclipse.fx.javafx) that we could depend on to make sure it was available...but now it seems you've deprecated that bundle, as I'm seeing a warning to that effect when I debug our plugin.

I'm also seeing suggestions that the plugin dependency should instead be replaced with the VM argument -Dorg.osgi.framework.bundle.parent=ext

...is that command-line argument sufficient for all Eclipse installations, regardless of whether e(fx)clipse is installed, or is there a p2 orbit bundle that we must also depend on?

Does this change also mean it is necessary to require customers who install via our update site to modify their Eclipse.ini by hand if we switch to using FXCanvas?
Re: What bundle should I depend on for javafx.embed.swt.FXCanvas? [message #1766965 is a reply to message #1766551] Thu, 29 June 2017 07:27 Go to previous messageGo to next message
Christoph Keimel is currently offline Christoph KeimelFriend
Messages: 482
Registered: December 2010
Location: Germany
Senior Member
FXCanvas is used to show SWT components in a JavaFX Application.
If I understand you correctly you want to show Swing components in an SWT Application, right?
If so, you can use the SWT/AWT Bridge [1].

[1] https://www.eclipse.org/articles/article.php?file=Article-Swing-SWT-Integration/index.html

[Updated on: Thu, 29 June 2017 07:28]

Report message to a moderator

Re: What bundle should I depend on for javafx.embed.swt.FXCanvas? [message #1768696 is a reply to message #1766965] Fri, 21 July 2017 18:25 Go to previous messageGo to next message
Theodore Murdock is currently offline Theodore MurdockFriend
Messages: 5
Registered: January 2015
Junior Member
No, the SWT/AWT bridge - unless something has changed about the assumptions it makes in the last couple of years - is fundamentally broken, and should not be used as implemented for anything. SWT/AWT makes the assumption that it's safe for one of the two UI threads to make a blocking call on the other, so long as a blocking call from the other UI thread never occurs. This assumption is fundamentally false, because both UIs lock common native resources. On Windows, SWT/AWT uses a hack to pump the native event queue and tell Swing "you go first", but on OSX and Linux no such hack exists, so SWT/AWT regularly deadlocks.

Currently, we are using our own alternative to SWT/AWT (with the deadlock-producing assumption removed) together with our own version of the abandoned Albireo project, which fixes a few issues and makes life under the SWT/AWT bridge a bit more viable -- but not really as good as it should be. For example, tooltips stop working in Eclipse as soon as SWT/AWT starts up, and sometimes transfers of focus go wrong, such as the find dialog not gaining focus when it's opened, and losing its connection to the active editor.

Can FXCanvas also be used as an FX->SWT part? That's not how Oracle describes its use: http://docs.oracle.com/javafx/2/swt_interoperability/jfxpub-swt_interoperability.htm. I've successfully used it to embed FX content in SWT (by depending on the deprecated org.eclipse.fx.javafx bundle), and I know e(fx)clipse uses it internally also.

Using that in combination with embedding Swing in FX (which is a standard part of Java and doesn't need any fancy classloading to work properly), I find that things work a lot better, the tooltip issues and focus loss don't occur, and embedding FX in SWT is safe, because they made the correct assumption that communication between UI threads must always be via invokeLater and asyncExec.

Ideally, the SWT/AWT bridge should be replaced with something that uses (or itself be refactored to use) FXCanvas + SwingNode, but if that is to be done, it needs to be coordinated with e(fx)clipse, as I think it could potentially be unsafe to have two copies of FXCanvas class-loaded in the same process, unless its designers considered that possibility and wrote the side-effects of its interaction with the shared classes of JavaFX itself defensively.

This is also why I'd prefer to get FXCanvas as loaded by e(fx)clipse if possible.

If there's a better way to embed FX into SWT than using FXCanvas directly, I'm also open to that, I just want to reach the point at which I can say "add our update site, install, we'll find our dependencies via p2/orbit, done". I considered depending on e(fx)clipse itself to embed FX in SWT, but I initially thought it wasn't a part of the default Eclipse repository, and I thought I'd try to keep the dependencies minimal.

I also came across something that suggested installing e(fx)clipse isn't as simple as adding the plugin, that you also have to modify the vmargs in your eclipse launch script, is that the case? Why was org.eclipse.fx.javafx deprecated?

[Updated on: Fri, 21 July 2017 18:26]

Report message to a moderator

Re: What bundle should I depend on for javafx.embed.swt.FXCanvas? [message #1768824 is a reply to message #1768696] Mon, 24 July 2017 07:54 Go to previous messageGo to next message
Christoph Keimel is currently offline Christoph KeimelFriend
Messages: 482
Registered: December 2010
Location: Germany
Senior Member
FXCanvas is part of the JRE. You will find it in jre/lib/jfxswt.jar.

I assume you are having problems loading the class in an osgi (equinox) application?
With e(fx)clipse 1.x you used to add -Dosgi.framework.extensions=org.eclipse.fx.osgi to your vm arguments. This hook needed the bunde org.eclipse.fx.javafx to stand in for the JavaFX classes.

Since e(fx)clipse 2.0 this has changed. Best practice is to start with -Dorg.osgi.framework.bundle.parent=ext instead. The bunde org.eclipse.fx.javafx is not necessary in this scenario and it is also not necessary to import javafx.* packages in the MANIFEST.MF.

See this old forum post:
https://www.eclipse.org/forums/index.php/t/1063826/
Re: What bundle should I depend on for javafx.embed.swt.FXCanvas? [message #1768828 is a reply to message #1768824] Mon, 24 July 2017 08:09 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
I always thought that FXCanvas is used to use JavaFX controls in an SWT UI. At least I used it this way: https://blog.codecentric.de/en/2015/04/add-javafx-controls-swt-eclipse-4-application-eclipse-rcp-cookbook/

And IIRC you still need the -Dosgi.framework.extensions=org.eclipse.fx.osgi vm argument in that case and not the new one as it is a different scenario. At least I thought that Tom corrected me regarding that a while ago.
Re: What bundle should I depend on for javafx.embed.swt.FXCanvas? [message #1768830 is a reply to message #1768828] Mon, 24 July 2017 08:21 Go to previous messageGo to next message
Christoph Keimel is currently offline Christoph KeimelFriend
Messages: 482
Registered: December 2010
Location: Germany
Senior Member
Dirk Fauth wrote on Mon, 24 July 2017 10:09
And IIRC you still need the -Dosgi.framework.extensions=org.eclipse.fx.osgi vm argument in that case and not the new one as it is a different scenario. At least I thought that Tom corrected me regarding that a while ago.


Ok, thanks Dirk! That could be the case. I'm not actively using FXCanvas, so I don't have any practical experience.

Re: What bundle should I depend on for javafx.embed.swt.FXCanvas? [message #1768852 is a reply to message #1768830] Mon, 24 July 2017 10:59 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Dirk is right. For FXCanvas in OSGi you need the adapter-hooks because we need to construct a special classloader (or in Java9 we need to construct a module-layer on the fly) with SWT in the hierarchy.
Re: What bundle should I depend on for javafx.embed.swt.FXCanvas? [message #1769128 is a reply to message #1768852] Wed, 26 July 2017 21:02 Go to previous messageGo to next message
Theodore Murdock is currently offline Theodore MurdockFriend
Messages: 5
Registered: January 2015
Junior Member
What is it that (potentially) goes wrong without the -Dosgi.framework.extensions=org.eclipse.fx.osgi VM argument?

So far, my tests (giving my plugin a dependency on the deprecated org.eclipse.fx.javafx bundle on OSX) have worked fine without any special VM flags, and it's pretty frustrating requiring customers to add a vm argument to their Eclipse.ini. My feeling is that you lose more than half of the people that would otherwise try your plugin via update site if you also require the user to edit Eclipse.ini.

Is the issue related to bundle activation order, or class loading order in some way? Our use is pretty limited, and it may be easier for me to constrain the order in which bundles must be activated or classes must be referenced than it is to require our customers to add something to their .ini file.
Re: What bundle should I depend on for javafx.embed.swt.FXCanvas? [message #1769211 is a reply to message #1769128] Thu, 27 July 2017 19:38 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Let me try to clear up some confusion and half correct statements:
a) You had to have an AdapterHook running to get JavaFX-SWT integration since ever (reason is that JavaFX-SWT is - THANK GOD - on no default classpath)
b) In former days you had to add import package AND the AdapterHook in place
c) We removed the need for the package import and let you treat javafx.* as if they are exported by the system-bundle (defined by the EE)
d) No user has to manually edit an Eclipse.ini because p2 modifies the Eclipse.ini upon install and instructs Equinox to launch the adapter hook (to prove it works look at your Eclipse.ini if you have e(fx)clipse tooling installed)
Re: What bundle should I depend on for javafx.embed.swt.FXCanvas? [message #1770751 is a reply to message #1769211] Wed, 16 August 2017 18:16 Go to previous messageGo to next message
Arian Fornaris is currently offline Arian FornarisFriend
Messages: 8
Registered: February 2014
Junior Member
Hi Thomas,

I just installed the last efxclipse IDE inside Oxygen but now my RCP application do not find FXCanvas. I was looking for the org.eclipse.fx.javafx plugin (if I understand well it is needed to load JavaFX-SWT bridge) but I cannot find it in the installation, so I cannot add it to the Target Runtime. In my old setup (Neon + fxeclipse 2.*) it just worked. I added both parameters -Dorg.osgi.framework.bundle.parent=ext -Dosgi.framework.extensions=org.eclipse.fx.osgi but it does not work.

Actually, I do not find the source code for org.eclipse.fx.osgi 3.0, I looked into the efxclipse github repo and the git repo hosted by Eclipse but this one only contains the 2.* versions.

For me it is not clear how is the right setup for efxclipse 3.0 and Oxygen.

Regards
Arian
Re: What bundle should I depend on for javafx.embed.swt.FXCanvas? [message #1770753 is a reply to message #1770751] Wed, 16 August 2017 18:47 Go to previous messageGo to next message
Arian Fornaris is currently offline Arian FornarisFriend
Messages: 8
Registered: February 2014
Junior Member
Finally I found how it works thanks to this post:

https://www.eclipse.org/forums/index.php/t/1087038/

The steps are:

1- Create a Target Runtime for your application
2- Install the features provided here (it contains the org.eclipse.fx.osgi plugin): http://download.eclipse.org/efxclipse/runtime-shared-released/3.0.0/site/
3- Add the org.eclipse.fx.runtime.min.feature to the product dependencies.
4- Add the -Dorg.osgi.framework.bundle.parent=ext -Dosgi.framework.extensions=org.eclipse.fx.osgi parameters to the product arguments.

It would be great to have in the Efxclipse website a short guide about to embed JavaFX into Eclipse RCP application . There is a guide to install Efxclipse IDE, but RCP developers needs a short guide too ;-)
Re: What bundle should I depend on for javafx.embed.swt.FXCanvas? [message #1770765 is a reply to message #1770753] Wed, 16 August 2017 22:33 Go to previous message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
https://wiki.eclipse.org/Efxclipse/Tutorials/Tutorial2 - Not 100% up-to-date but it is a wiki and you might want to edit it?
Previous Topic:Eclipse freeze opening e(fx)clipse based plugin view (Linux)
Next Topic:How can I add maven libraries to an e(fx)clipse project?
Goto Forum:
  


Current Time: Thu Apr 18 00:04:56 GMT 2024

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

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

Back to the top