Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I easily show/hide views in Griffon

Tags:

groovy

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

like image 662
Konrad 'ktoso' Malawski Avatar asked Dec 05 '10 01:12

Konrad 'ktoso' Malawski


3 Answers

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".

like image 99
zorkle Avatar answered Nov 02 '22 16:11

zorkle


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.

like image 26
ecspike Avatar answered Nov 02 '22 16:11

ecspike


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" :-)

like image 32
Konrad 'ktoso' Malawski Avatar answered Nov 02 '22 14:11

Konrad 'ktoso' Malawski