2015-01-13 24 views
2

我使用犬1.5。在一個視圖我有定義爲面板..格里芬結合不工作

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)) 
} 

和模型中的我有..

@Bindable 
@PropertyListener(stillageCompleteCheck) 
boolean toggle 

@Bindable 
stillageComplete = false 

@Bindable 
stateText 

..連同其他字段和屬性聽者方法..

private stillageCompleteCheck = { evt -> 

    def contentsChecked = checkContents() 

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

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

} 

我設置在控制器中的方法變量model.toggle它運行在對propertyList代碼和正確設置參數,但面板不顯示..任何人都可以看到我的代碼有問題嗎?

順便說一句..我有另一個面板下面這沒有問題工程..

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)) 
} 
+0

同時與註釋,這可能是有效的常規(沒有它,它不是),但如果你感到絕望:它的工作原理,如果你提供一個合適的類型(例如'@Bindable布爾stillageComplete = FALSE')? – cfrick

+0

很遺憾不是.. – user3914455

回答

1

我認爲問題出在下面的行

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

這是一個典型的Groovy疑難雜症。來自外部的字段訪問(model.stillageComplete = true)實際上是model.setStillageComplete(true),換句話說,這實際上是屬性訪問。但是,當從擁有「屬性」的實例中調用相同的代碼時,該規則被推翻,有效地實現了字段訪問。那麼發生什麼事情的結果是,未觸發屬性​​的預期PropertyChangeEvent。

修復很簡單,明確地調用setter或自己觸發PCE。調用setter更容易。

setStllageComplete((currentContentCount == stillageSize && !(statusList.find { it != Color.green })) 
+1

謝謝!我會嘗試並報告回來..我只想說感謝格里芬.. – user3914455