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

forwardWorkspaceActions inside tabpane with connectWorkspaceActions inside Workspace #894

Closed
DeMol-EE opened this issue Jan 16, 2019 · 8 comments

Comments

@DeMol-EE
Copy link
Contributor

DeMol-EE commented Jan 16, 2019

I've stumbled across odd behavior with a very particular situation. I'm docking a view with a tabpane as a root inside a workspace and want the workspace actions to be connected to the selected tab, so I use connectWorkspaceActions. So far, so good.

Now, I want to be able to replace the content of the first tab with that of a different view. As such, I've included a button inside the first tab's view to find an instance of ViewThree and use replaceWith to do the switch (see code below). Now comes the issue: I've noticed the workspace actions don't match the property values from ViewThree, even when using forwardWorkspaceActions to explicitly delegate them.

Here is a complete MVC:

package com.example.demo.view

import javafx.beans.property.SimpleBooleanProperty
import tornadofx.*

class WorkspaceApp : App(MainWorkspace::class)

// also happens for NavigationMode.Tabs
class MainWorkspace : Workspace("My View", NavigationMode.Stack) {
    init {
        dock<TabbedView>()
    }
}

class TabbedView : View("Root tab") {
    override val closeable = SimpleBooleanProperty(false)
    override val root = tabpane{
        connectWorkspaceActions()
        tab<ViewOne>()
        tab<ViewTwo>()
    }
}

class ViewOne : View("Child 1") {
    override val closeable = SimpleBooleanProperty(false)
    override val savable = SimpleBooleanProperty(true)
    override val creatable = SimpleBooleanProperty(true)
    override val deletable = SimpleBooleanProperty(false)
    override val refreshable = SimpleBooleanProperty(false)

    override val root = borderpane {
        center {
            label("1 is savable and creatable")
        }
        bottom {
            button("Replace With 3") {
                action {
                    val viewThree = find<ViewThree>()
                    replaceWith(viewThree)
                    forwardWorkspaceActions(viewThree)
                }
            }
        }
    }
}

class ViewTwo : View("Child 2") {
    override val closeable = SimpleBooleanProperty(false)
    override val savable = SimpleBooleanProperty(false)
    override val creatable = SimpleBooleanProperty(false)
    override val deletable = SimpleBooleanProperty(true)
    override val refreshable = SimpleBooleanProperty(true)

    override val root = borderpane {
        center {
            label("2 is deletable and refreshable")
        }
    }
}

class ViewThree : View("Child 3") {
    override val closeable = SimpleBooleanProperty(false)
    override val savable = SimpleBooleanProperty(true)
    override val creatable = SimpleBooleanProperty(false)
    override val deletable = SimpleBooleanProperty(false)
    override val refreshable = SimpleBooleanProperty(true)

    override val root = borderpane {
        center {
            label("3 is savable and refreshable")
        }
    }
}

Could you please tell me what I'm doing wrong?

@edvin
Copy link
Owner

edvin commented Jan 17, 2019

You're not doing anything wrong, but supporting this level of indirection with how this is implemented right now was kind of mind boggling :) I made an attempt, could you check out the latest revision and apply this patch to see if it works for you? I'd have to perform some more tests to make sure I didn't break anything before merging this.
Subdelegation_of_Workspace_button_states.zip

@edvin
Copy link
Owner

edvin commented Jan 17, 2019

Oh, and by the way - don't dock anything in init, you'd actually be creating yet another Workspace. Move the dock code to onBeforeShow() for example.

@DeMol-EE
Copy link
Contributor Author

I can't right now but I'll get back to you on the patch, thanks in advance.

In reply to your other comment, moving the docking commands from init to onBeforeShow does not work for me: the views are not docked at all. I believe the underlying problem is that I'm not loading the workspace correctly... It's detailed in #860 but the part that is relevant here is that the app starts with workspace A, with View A docked, and when the user presses a button in said View A, the workspace is replaced by workspace B with a call to replaceWith. Why I'm doing this is also explained in #860 and I'm very interested in getting your feedback on how I should do it right.

@edvin
Copy link
Owner

edvin commented Jan 17, 2019

It's working for me with your sample code, and the patch applied. However, you could use the WorkspaceApp feature that comes with the framework :)

I'm also wondering if NavigationMode.Tabs would fit your use case better?

Will look at #860 when I find time :)

@DeMol-EE
Copy link
Contributor Author

Can confirm this patch works for me, can't confirm it doesn't break other stuff ;) With regards to using a tabbed workspace: I already am using one, and one of the docked views contains the tabpane "Root tab" from the MVC. So it's a tab inside a tabpane inside a tab in a tabbed workspace, and it works with this patch :D

@edvin
Copy link
Owner

edvin commented Jan 20, 2019

It feels like there is a meme in there somewhere :) OK, I will run some tests against the patch tomorrow and hopefully merge.

@edvin
Copy link
Owner

edvin commented Jan 21, 2019

So far so good. I've deployed this patch in an internal app so I get a few more users on it, will merge tomorrow if no problems arise.

@edvin
Copy link
Owner

edvin commented Jan 22, 2019

Merged :)

@edvin edvin closed this as completed Jan 22, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants