简体   繁体   中英

How to open multiple editor views open in TornadoFX

I've been following the guide here where it gives an example of an editor using a ViewModel.

I'm looking to change this so that instead of a single editor that is rebound to each domain object for editing, instead each object will bring up its own separate editor.

I want to keep using the ViewModels as I like the separation they provide and the API they have (easy rollback / saving).

How should I handle opening an editor per domain object (especially in a TornadoFX way)?

The solution is to create a new scope for the new editor and inserting the relevant models into that new scope. If you're using the Workspace, this is done using built in functions like dockInNewScope :

workspace.dockInNewScope<MyEditor>(myModel1, myModel2, etc)

If you're not using Workspace, you can create a new scope manually, put models into it and lookup views in the new scope as well:

val newScope = Scope(myModel1, myModel2)
find<MyEditor>(newScope).openWindow()

MyEditor will in this instance see myModel and myModel2 in it's scope, so that it can inject them.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM