[Databinding] Resetting targets after removing binding [message #333980] |
Thu, 15 January 2009 08:31 |
Sebastian Paul Messages: 106 Registered: July 2009 |
Senior Member |
|
|
Hi,
I have an SWT based form and a Beans based model. The model is bound to
the form with bind(), where the DataBindingContext and all Bindings are
created.
The binding to the model can be removed while the form is displayed. The
method unbind() does this by disposing the DataBindingContext.
When unbind() is called, all fields in the form should be resetted to
the state they had before bind(), in my case they just have to be empty.
I solved this as follows:
public void unbind() {
if (dataBindingContext != null) {
@SuppressWarnings("unchecked")
final List<Binding>bindings = dataBindingContext.getBindings();
// collect targets, so they can be resetted
final List<ISWTObservableValue> targets =
new ArrayList<ISWTObservableValue>(bindings.size());
for (final Binding binding : bindings) {
final IObservable target = binding.getTarget();
if (target instanceof ISWTObservableValue) {
targets.add((ISWTObservableValue) target);
}
}
// remove binding to model
dataBindingContext.dispose();
dataBindingContext = null;
// reset targets
for (final ISWTObservableValue observableValue : targets) {
observableValue.setValue("");
}
}
}
This works fine. But is there another way of doing that? Maybe more general?
Kind regards, Sebastian
|
|
|
Powered by
FUDForum. Page generated in 0.01785 seconds