How do I easily show/hide views in Griffon

First: I'm shocked that I have to ask this question. Nowhere in the docs is it explained how the new "WindowManager" should be used... I've been hacking around some hours around this and I still dont have an satistactionary way of doing something as trivial as this:

def vName = 'Error'
if (!app.views[vName]) { //I just want to create it once, otherwise I'd just change it's model and want to show() it!
  buildMVCGroup(vName, vName, errorCode: 500, message: "fail detected ;-)") //ok, this indeed shows the idem (as it's an "frame(/**/show: true,/*...*/", but I dont want to create it each time
}

//    app.windowManager.show(app.views.Error) //fails, show() want's an Window, and app.views.Error is of ErrorView type
//    app.views.Error.visible = true //won't display the view
//    app.views.Error.show() // there is no such method

I'd also need an nice way to hide, something like:

//in controller
def view
def hideAction = {
  //view.hide() //fails, no such method...
}

Another way that would make me happy, is an easy way to "when user clicks OK (in the ErrorView", dispose of this MVCGroup. I have been searching and reading the examples quite some time today, yet still can't figure out how to code such easy application flow hmm...

Many thanks in advance for any idea on how to do this, cheers

Upvotes: 5

Views: 985

Answers (4)

cdeszaq
cdeszaq

Reputation: 31290

Another option is to use a CardLayout for each screen you want to display. Then you can easily show/hide screens. That, combined with MigLayout for the individual cards, works pretty well.

Upvotes: 0

zorkle
zorkle

Reputation: 369

For frames - what I've done...

In my view I provide a name for the frame

application(name: 'login', ...

Then in my controller I do

app.windowManager.hide(app.windowManager.findWindow('login')) app.windowManager.show(app.windowManager.findWindow('workspace'))

So... I'm making sure I 'name' all of my views and then I can easily show/hide with the window manager...

Your right about the docs. I'm hoping that what I'm doing is the "right thing to do too".

Upvotes: 4

ecspike
ecspike

Reputation: 21

It is indeed. It makes a call the the setVisible function that is on most JComponents.

show()/hide() are syntactic sugar in Groovy/Griffon that was at one point in J2SE but has been long been deprecated.

Upvotes: 2

Ok, I found quite nice solution for this:

application(/**/){
  //...
  myError = dialog(/**/){
    //thats my error window
  }
}

And then in the controller I'd just:

view.myError.visible = true

It's quite elegant for such an thing, hope it's "the right thing to do" :-)

Upvotes: 1

Related Questions