Skip to content
This repository was archived by the owner on Sep 28, 2024. It is now read-only.
This repository was archived by the owner on Sep 28, 2024. It is now read-only.

OSGi Explanation #156

@edvin

Description

@edvin

As demonstrated in the OSGi screencast, TornadoFX let's a bundle export a View to other bundles by calling this function:

activator.registerView(MyView::class, "discriminator")

Under the covers, this implements an interface called ViewProvider and calls BundleContext#registerService with that implementation.

interface ViewProvider {
    fun getView(): UIComponent
    val discriminator: Any?
}

Here is the actual registerView function:

fun BundleContext.registerView(viewType: KClass<out UIComponent>, discriminator: Any? = null) {
    val provider = object : ViewProvider {
        override fun getView() = find(viewType)
        override val discriminator = discriminator
    }
    registerService(ViewProvider::class.java, provider, Hashtable<String, String>())
}

TornadoFX hides the need to implement this interface, but doesn't force you to abandon DS - you might just as well implement the interface manually. The choice is entirely up to the user, but you actually write less code by using the registerView extension function, and you don't need the extra build step so I suspect TornadoFX users will prefer the explicit way demonstrated in the screencast.

Granted, I'm no OSGi expert, and any input is greatly appreciated.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions