tornadofx.jaris loaded in an OSGi container, a number of services are automatically installed in the runtime. These services enable some very interesting features which we will discuss.
Appclass with an application proxy which will keep the JavaFX environment running even when your application shuts down.
BundleActivatorthat provides a means to
App. Registering your application for this functionality can be done by calling
Appclass as the single parameter in your bundle
Viewwill have this stylesheet applied. When the bundle is unloaded, the stylesheet is automatically removed. If you want to provide multiple stylesheets based on the same style classes, it is a good idea to create one bundle that exports the
cssclassdefinitions, so that your Views can reference these styles, and the stylesheet bundles can create selectors based on them.
Viewthat can hold other Views, and tells the TornadoFX OSGi Runtime that it would like to automatically embed Views if they meet certain criteria.
Viewthat contains a
VBox. We tell the TornadoFX OSGi Runtime that we would like to have other Views embedded into it if they are tagged with the discriminator dashboard:
addViewsWhenfunction returns true, the
Viewis added to the
VBox. To offer up Views to this Dashboard, another bundle would declare that it wants to export it's View by setting the
dashboarddiscriminator. Here we register a fictive
MusicPlayerview to be docked into the dashboard when it's bundle becomes active.
addViewsWhenfunction is smart enough to inspect the
VBoxand find out how to add the child View it was presented. It can also figure out that if you call the function on a
TabPaneit would create a new
Taband set the title to the child View title etc. If you would like to do something custom with the presented Views, you can return
falsefrom the function so that the child View will not be added automatically and then do whatever you want with it. Even though the Tab example is supported out of the box, you could do it explicitly like this:
Manual handling of dynamic Views
tornadofx-maven-osgi-projecttemplate in the TornadoFX IntelliJ IDEA plugin. This contains everything you need to build OSGi bundles from your sources. The OSGI IDEA plugin makes it very easy to setup and run an OSGi container directly from the IDE. There is a screencast at https://www.youtube.com/watch?v=liOFCH5MMKk that shows these concepts in action.
Alt-Meta-Oor configure another shortcut by setting
FX.osgiConsoleShortcutor programmatically opening the
bundledirectory of the container. Note that any jar that is to be used in an OSGi container needs to be "OSGi enabled", which effectively means adding some OSGi specific entries the
*The Kotlin OSGi bundle contains special versions of
kotlin-reflectwith the required OSGi manifest information.
**This links to the Apache Felix implementation of the OSGi Config Admin interface. Feel free to use the implementation from your OSGi container instead. Some containers, like Apache Karaf, already has the Config Admin bundle loaded, so you won't need it there.