8000 runAsyncWithOverlay with view root · Issue #873 · edvin/tornadofx · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
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.
runAsyncWithOverlay with view root #873
Open
@DeMol-EE

Description

@DeMol-EE

I'm trying to get a view to refresh each time it is docked but I'm running into trouble. To illustrate what's happening, I've set up a minimal code sample based off the IDEA template for a new tornadofx project with maven. I've edited the generated MainView to look as follows:

package com.example.demo.view

import tornadofx.*

class MainView : View("Hello TornadoFX") {

    private val wurds = observableList<String>()

    override val root = hbox(10)

    init {
        wurds.onChange {
            redrawContent()
        }
    }

    private fun redrawContent() {
        root.replaceChildren {
            wurds.forEach {
                label(it)
            }
        }
    }

    override fun onDock() {
        println("ondock")
        onRefresh()
    }

    override fun onRefresh() {
        println("onrefresh")
        with(root) {
            runAsyncWithOverlay {
                Thread.sleep(1000)
                listOf("Hello", "Edvin")
            } ui {
                wurds.setAll(it)
            }
        }
    }
}

My idea was to use an observable list as a sort of model of what labels should be shown and registering a listener to changes in the model from init. When changes happen, and each time the view is docked, I want the model to be refreshed based on the results of a database query (here replaced by sleeping the thread). The code above does not execute but instead gets stuck in an infinite loop of docking and calling refresh.
I believe the underlying reason must be that runAsyncWithOverlay actually undocks and redocks the view but I'm not sure.

How would I ideally achieve what I'm trying to do?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0