Tornadofx: View workflow

Created on 11 Jun 2017  路  3Comments  路  Source: edvin/tornadofx

Hi together,

I have problems to create a proper workflow between views.

  1. version: I create a new window, but then I don't know how to put additional data when I create it. But then IndexView should be closed at least.
class IndexView : View() {
    override val root: BorderPane by fxml("/view/IndexView.fxml", true)
    val newView: NewView by inject()

    init {
        title = "Hello Index View"
    }

    fun newView() {
        // Put some extra data to aboutView by input fields or something
        newView.openWindow() // what's the difference to modal?
        newView.openModal()
    }
}
  1. Version: I add the 2nd view in the root center of the previous view. But then I also have problems to add additional data like title, it just keep the old title Hello Index View.
class IndexView : View() {
    override val root: BorderPane by fxml("/view/IndexView.fxml", true)
    val newView: NewView by inject()

    init {
        title = "Hello Index View"
    }

    fun newView() {
        root.center = newView.root
    }
}

Can you help me?

UPDATE

replaceWith(myView::class, someAnimation)
seems really nice. But how could I exchange information like for logins?

Thanks and best regards
Gino

Most helpful comment

Great! I want to do a "How to create a login screen" video soon, will post the link here :)

All 3 comments

You can actually pass parameters between Views, but it is often more flexible to inject a ViewModel into both views, and simply binding towards those values in the first View. Whenever you do replaceWith to go to the second View, your data is already available to you. Check out the ViewModel in the guide:

https://edvin.gitbooks.io/tornadofx-guide/content/11.%20Editing%20Models%20and%20Validation.html

The difference between openWindow and openModal is that the first will not create a modal window by default, meaning that you can still interact with UI behind it. You can call close() on the IndexView when you open a new window or modal dialog.

You can for sure update the title of the containing View when you replace some parts of it with another, but I suspect you're looking for something like the Workspace for this use case. If I'm mistaken, maybe you can elaborate a little about your use case so I can suggest a better approach? Check out the Workspace here:

https://edvin.gitbooks.io/tornadofx-guide/content/16.%20Workspaces.html

If you just want to change the center node and update the title, you could do something like:

fun newView() {
    titleProperty.cleanBind(newView.titleProperty)
    root.center = newView.root
}

However, that seems like a hack, so I'm sure we can find a better way to do what you want.

Hi Edvin,

thanks this already helped a lot to understand. :) If something is still unclear for me, I will re-open the issue.

Best regards
Gino

Great! I want to do a "How to create a login screen" video soon, will post the link here :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

elliotcm picture elliotcm  路  7Comments

jagiellonczyk14 picture jagiellonczyk14  路  6Comments

pavan-p picture pavan-p  路  3Comments

iwh718 picture iwh718  路  3Comments

jordaorodolfo picture jordaorodolfo  路  6Comments