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

using connectWorkspaceActions() with stackPane #604

Closed
mostfa-ayad opened this issue Jan 23, 2018 · 18 comments
Closed

using connectWorkspaceActions() with stackPane #604

mostfa-ayad opened this issue Jan 23, 2018 · 18 comments

Comments

@mostfa-ayad
Copy link

hello
stackPane missing the connectWorkspaceActions() method to using workspace actions over subviews

@edvin
Copy link
Owner

edvin commented Jan 23, 2018

This could be useful, but StackPane isn't as good a match as TabPane but I think it's doable. We would need to create a property that always contains the top most Node in the children view. When we have that, the rest should be pretty straight forward.

edvin pushed a commit that referenced this issue Jan 23, 2018
…rty and various Workspace related functions and properties (#604)
@edvin
Copy link
Owner

edvin commented Jan 23, 2018

I have added StackPane.connectWorkspaceActions() now, and I'll push a new snapshot to the sonatype repo right away :)

@mostfa-ayad
Copy link
Author

thank you

@edvin
Copy link
Owner

edvin commented Jan 24, 2018

My pleasure. Will you close the issue when you have tested it?

@mostfa-ayad
Copy link
Author

i can't test it now . i will do after testing

@mostfa-ayad
Copy link
Author

one missing questions
is i can use when refresh in subview and can override onactions in subviews
becuse i have atable in subview and can't do refresh on the table using whenRefresh or by onRefresh

@mostfa-ayad
Copy link
Author

this is my final work do you have alook

class UserView : View("Users View") {
    val controller:UserController by inject()
    val model: UserModel by inject()
    override val savable = model.editModeProperty
    override val creatable=!model.editModeProperty
    var list:UserList= UserList()
    init {
        controller.users.setAll(controller.loadUsers())
    }
    override val root=stackpane {
        add(list)
        add<UserEditor>()
        connectWorkspaceActions()
    }
    override fun onCreate() {
        model.item=User()
        model.isNew=true
        model.editMode=true
        model.editor=true
    }
    override fun onSave() {
        model.commit() {

            if (model.isNew) {
                model.item = controller.insertUser(model)
                println(model.item.toJSON())
            } else {
                controller.updateUser(model)
            }
        }
    }

    override fun onDock() {
        with(workspace) {

            button("list"){
                disableWhen(model.editorProperty.not())
                action {
                model.editor=false

                initModel()
            }
            }

                button("edit") {
                    disableWhen(model.editModeProperty)
                    action {
                        model.editMode = true
                        model.editor=true

                    }
                }
            }
        }
    fun initModel(){
        model.editMode=false
        model.isNew=false
    }
    override fun onRefresh() {
        list.userTable.refresh()
    }
}

@edvin
Copy link
Owner

edvin commented Jan 25, 2018

var list:UserList= UserList() is wrong, it should be injected:

val list: UserList by inject()

:)

@mostfa-ayad
Copy link
Author

mostfa-ayad commented Jan 25, 2018

UserList is not subType of ScopedInstance

@edvin
Copy link
Owner

edvin commented Jan 25, 2018

Aha, I see :) About refresh - have implemented the functions needed, did you get it to work?

@mostfa-ayad
Copy link
Author

mostfa-ayad commented Jan 25, 2018

if you mean by using var list:UserList= UserList() yes it work

@mostfa-ayad
Copy link
Author

if the sub views can inject in the main view it will be perfect

@edvin
Copy link
Owner

edvin commented Jan 26, 2018

Sure they can :)

@mostfa-ayad
Copy link
Author

i'm confuse how :)

@edvin
Copy link
Owner

edvin commented Jan 26, 2018

Make sure the main view extends View and that they are in the same scope. Then simply declare val mainView: MainView by inject() wherever you need it.

@mostfa-ayad
Copy link
Author

ok i changed userList to View from Fragment and inject it in the main view
val listView:UserList by inject()
and call refresh method for refresh table
this is my last comment in this issue
thank you for your help

@edvin
Copy link
Owner

edvin commented Jan 26, 2018

You're welcome. You can do this with less tight coupling by firing an event in the subview and subscribing to that event in the mainview :)

@mostfa-ayad
Copy link
Author

ther is no event in the subview
the sub view is a list of data i need refresh to load data change from restful service
it work now


class UserView : View("Users View") {
    val controller:UserController by inject()
    val model: UserModel by inject()
    val listView:UserList by inject()
    override val savable = model.editModeProperty
    override val creatable=!model.editModeProperty
    init {
        controller.users.setAll(controller.loadUsers())
    }
    override val root=stackpane {
        add<UserList>()
        add<UserEditor>()
        connectWorkspaceActions()
    }
    override fun onCreate() {
        model.item=User()
        model.isNew=true
        model.editMode=true
        model.editor=true
    }
    override fun onSave() {
        model.commit() {

            if (model.isNew) {
                model.item = controller.insertUser(model)
                println(model.item.toJSON())
            } else {
                controller.updateUser(model)
            }
        }
    }

    override fun onDock() {
        with(workspace) {

            button("list"){
                disableWhen(model.editorProperty.not())
                action {
                model.editor=false

                initModel()
            }
            }

                button("edit") {
                    disableWhen(model.editModeProperty)
                    action {
                        model.editMode = true
                        model.editor=true
                    }
                }
            refreshButton.action {
                workspace.onRefresh()
            }
            }
        }
    fun initModel(){
        model.editMode=false
        model.isNew=false
    }

    override fun onRefresh() {
        listView.refresh()
    }
}

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