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

Commit

Permalink
--dicontainer=diContainerClass parameter allows assignment of DICon…
Browse files Browse the repository at this point in the history
…tainer from command line (edvin/tornadofx-idea-plugin#56)
  • Loading branch information
Edvin Syse committed Apr 16, 2018
1 parent b4e76f4 commit 4ab6327
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

### Additions

- `--dicontainer=diContainerClass` parameter allows assignment of DIContainer from command line (https://github.com/edvin/tornadofx-idea-plugin/issues/56)
- `readonly` and `cancel` pseudoclasses added to type safe CSS
- Added add/remove/toggle class for Tab
- ContextMenu.radiomenuitem (https://github.com/edvin/tornadofx/issues/646)
Expand Down
21 changes: 21 additions & 0 deletions src/main/java/tornadofx/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ open class App(open val primaryView: KClass<out UIComponent> = NoPrimaryViewSpec

override fun start(stage: Stage) {
FX.registerApplication(scope, this, stage)
detectDiContainerArgument()

try {
val primaryViewType = determinePrimaryView()
Expand All @@ -97,6 +98,26 @@ open class App(open val primaryView: KClass<out UIComponent> = NoPrimaryViewSpec
}
}

/**
* Detect if --di-container= argument was given on the command line and assign it to FX.dicontainer
*
* Another implementation can still be assigned to FX.dicontainer programmatically
*/
private fun detectDiContainerArgument() {
parameters.named?.get("di-container")?.let { diContainerClassName ->
val dic = try {
Class.forName(diContainerClassName).newInstance()
} catch (ex: Exception) {
log.warning("Unable to instantiate --di-container=${parameters.named?.get("di-container")}: ${ex.message}")
null
}
if (dic is DIContainer)
FX.dicontainer = dic
else
log.warning("--di-container=${parameters.named?.get("di-container")} did not resolve to an instance of tornadofx.DIContainer, ignoring assignment")
}
}

open fun onBeforeShow(view: UIComponent) {

}
Expand Down

0 comments on commit 4ab6327

Please sign in to comment.