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:

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

The swing-view is a JTextField, bound using a 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?

The only thing in that direction I found in the JGoodies-Binding API is

beanAdapter.setBean(null)

But this doesn't - of course - remove the JGoodies-PropertyChangeListener and the JGoodies-DocumentListener from the JTextField. Is there a a nice way to remove those? Or do I have hack it down myself?

mKorbel
  • 109,525
  • 20
  • 134
  • 319
Peti
  • 1,670
  • 1
  • 20
  • 25

1 Answers1

0

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.

You cannot unbind a binding, you will have to refresh the binding with a new PresentationModel

rahul pasricha
  • 931
  • 1
  • 14
  • 35
  • Assuming you've got a BeanAdapter, I've had limited success using `beanAdapter.release()` to cause the `BeanAdapter` instance to drop all `PropertyChangeListeners` that are registered with bean adapter. But like I said, success was limited, and it depends greatly on how your beans, bean adapters, and ui components are wired together. – tones Dec 10 '14 at 02:51