Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » [Databinding] Resetting targets after removing binding
[Databinding] Resetting targets after removing binding [message #333980] Thu, 15 January 2009 08:31
Sebastian Paul is currently offline Sebastian PaulFriend
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
Previous Topic:Invoking Find/Replace
Next Topic:How to wait for launches to finish
Goto Forum:
  


Current Time: Fri Apr 26 07:25:32 GMT 2024

Powered by FUDForum. Page generated in 0.03307 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top