简体   繁体   English

如何从JGoodies-Binding(2.9.0)解除绑定

[英]How to unbind a binding from JGoodies-Binding (2.9.0)

I have the rare use case, where the swing-view lives longer than the related presentation-model: The swing-view lives as long as the application lives, the presentation-model is replaced each time a new "run" is started in the application. 我有一个罕见的用例,挥杆视图的寿命比相关表示模型的寿命长:挥杆视图的寿命与应用程序的寿命一样长,每次在模型中启动新的“运行”时,表示模型都会被替换。应用。

The presentation-model is a groovy bean: 表示模型是一个普通的bean:

@Bindable
static class MyPresentationModel{
   String myText = 'default-text'
}

The swing-view is a JTextField, bound using a JGoodies BeanAdapter: swing-view是一个JTextField,使用JGoodies BeanAdapter绑定:

JTextField myTextField = new JTextField()
MyPresentationModel pm = new MyPresentationModel()
BeanAdapter<MyPresentationModel> beanAdapter = new BeanAdapter<MyPresentationModel>(pm, true)
Bindings.bind(myTextField , beanAdapter.getValueModel('myText'))

How can I unbind the presentation model from the JTextField afterwards? 之后,我如何从JTextField 取消绑定表示模型?

The only thing in that direction I found in the JGoodies-Binding API is 我在JGoodies-Binding API中发现的唯一方向是

beanAdapter.setBean(null)

But this doesn't - of course - remove the JGoodies-PropertyChangeListener and the JGoodies-DocumentListener from the JTextField. 但这当然不是-从JTextField中删除JGoodies-PropertyChangeListener和JGoodies-DocumentListener。 Is there aa nice way to remove those? 是否有删除这些内容的好方法? Or do I have hack it down myself? 还是我自己将其破解?

The only way as far as i know is to call 据我所知,唯一的方法是打电话

Bindings.bind(myTextField , beanAdapter.getValueModel('myText'))

the above statement everytime with a new bean adapter from a new PresentationModel. 每次使用来自新PresentationModel的新bean适配器的上述语句。

You cannot unbind a binding, you will have to refresh the binding with a new PresentationModel 您无法取消绑定的绑定,必须使用新的PresentationModel刷新绑定

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM