2

I'm using Griffon 1.5 .. In a view I have a panel defined as ..

panel(background: bind { model.background },
         visible: bind { model.stillageComplete },
         constraints: 'grow,wrap') {
     migLayout(layoutConstraints:'fill')
     label(text: bind{model.stateText}, constraints:'align center', foreground:   bind{model.foreground},
             font: new Font("Sans Serif", Font.BOLD, 20))
 }

and in a model I have ..

 @Bindable
 @PropertyListener(stillageCompleteCheck)
 boolean toggle

 @Bindable
 stillageComplete = false

 @Bindable
 stateText

.. along with other fields and the property listener method ..

 private stillageCompleteCheck = { evt ->

    def contentsChecked = checkContents()

    stillageComplete =
            (currentContentCount == stillageSize && !(statusList.find { it != Color.green })

    println "StillageComplete  ?  ${stillageComplete} ${currentContentCount} ${stillageSize}"
    println "StateText         ?  ${stateText}"

}

I set the model.toggle variable in a controller method which runs the propertyListener code and correctly sets the parameters BUT the panel IS NOT displayed .. Can anyone see a problem with my code ?

As an aside .. I have another panel as below which works without problem ..

panel(background: Color.yellow,
        visible: bind { model.stillageOverdue },
        constraints: 'grow,wrap') {
    migLayout(layoutConstraints: 'fill')
    label("Finish Time Overdue", constraints: 'align center', foreground: Color.red,
            font: new Font("Sans Serif", Font.BOLD, 20))
}
user3914455
  • 257
  • 1
  • 10
  • while with the annotation this might be valid groovy (without it, it ain't), but in case you are desperate: does it work, if you provide a proper type (e.g. `@Bindable Boolean stillageComplete = false`)? – cfrick Jan 13 '15 at 20:16
  • Unfortunately not .. – user3914455 Jan 14 '15 at 01:00

1 Answers1

1

I think the problem lies in the following line

stillageComplete = (currentContentCount == stillageSize && !(statusList.find { it != Color.green })

This is a typical Groovy gotcha. What looks like field access from the outside (model.stillageComplete = true) is actually model.setStillageComplete(true), in other words, this is actually property access. But this rule is overturned when invoking the same code from within the instance that holds the "property", effectively field access wins over. So what ends of happening is that the expected PropertyChangeEvent for property stillageComplete is not triggered.

The fix is simply, explicitly call the setter or trigger the PCE yourself. Calling the setter is easier.

setStllageComplete((currentContentCount == stillageSize && !(statusList.find { it != Color.green }))
Andres Almiray
  • 3,236
  • 18
  • 28