Friday, April 29, 2011

How to show a second MVC group as a dialog box in griffon

I can see how to instantiate a second MVC group, e.g.

    def (loginPaneModel, loginPaneView, loginPaneController) =
        createMVCGroup('LoginPane', 'LoginPane', [:]);
    view.loginPanel = loginPaneView.loginPanel

But I don't want to show as part of my main window. I want it to pop up over it. What do I call to do that? Thanks!

From stackoverflow
  • Well, it seems that only the first line is needed. That was enough to pop up a window. I believe the key, though, was to make the view a frame.

    def frame = frame(title:'Login', pack:true, locationByPlatform:true) {
    ...
    }
    frame.pack()
    frame.show()

  • The easiest way would be to use the view panel as the root of a dialog in the parent MVC group. In the view for the group that yor code snippet is the controller of you could do something like this...

    application(title:'your app', ....) {
      // your existing code...
    
      loginDialog = dialog(title:'Login Panel', visible:false) {
        panel(loginPanel)
      }
    }
    

    And then when you need to show the dialog (in the same controller)

    view.loginDialog.visible = true
    

    Nesting a dialog inside of another window has the side effect of setting the dialog's owner to the frame or dialog of the parent. Having a dialog owned by another dialog/window is what causes the dialog to be linked with the parent and always float on top of that parent. It will also raise/lower with the parent as well.

0 comments:

Post a Comment