|
Re: Exceptions and DataBindingContext.bindXXX methods [message #665217 is a reply to message #665013] |
Wed, 13 April 2011 18:01 |
Carsten Habicht Messages: 14 Registered: January 2011 |
Junior Member |
|
|
Hey J.-P.! :o)
The outcome of an invocation of a binding is stored in it's validation status, which you can observe. Let's assume that you have more than a few bindings, and don't want to bind to every single validation status of every binding. In this case a trick I just learned from RCP guru Kai Tödter comes in handy: let an instance of AggregateValidationStatus do the plumbing and listen to it's value changes.
I tried to hack an example together, hope it works in your code:
public void bind() {
DataBindingContext bindingContext = new DataBindingContext();
// ... do some bindings here ...
bindingContext.bindValue(SWTObservables.observeText(...),
BeansObservables.observeValue(...), null, null);
// ... do some more ...
// aggregate the status information of all bindings in one object
// (AggregateValidationStatus.MAX_SEVERITY means, that we get the most
// severe status when more than one is not OK.)
AggregateValidationStatus avs = new AggregateValidationStatus(bindingContext,
AggregateValidationStatus.MAX_SEVERITY);
// and react when at least one status is not ok.
avs.addValueChangeListener(new IValueChangeListener() {
@Override
public void handleValueChange(ValueChangeEvent event) {
IStatus newVal = (IStatus) event.diff.getNewValue();
if (!newVal.isOK()) {
newVal.getException().printStackTrace();
}
}
});
}
HTH
Carsten ;o)
[Updated on: Wed, 13 April 2011 18:04] Report message to a moderator
|
|
|
Re: Exceptions and DataBindingContext.bindXXX methods [message #665602 is a reply to message #665217] |
Fri, 15 April 2011 08:35 |
J.-P. Pellet Messages: 71 Registered: July 2009 |
Member |
|
|
Hi Carsten,
Thanks, this is of great help. I was about to watch the status of every
binding — glad to know I don't have to do that!
Cheers,
J.-P.
On 13.04.11 20:01, Carsten Habicht wrote:
> Hey J.-P.! :o)
>
> The outcome of an invocation of a binding is stored in it's validation
> status, which you can observe. Let's assume that you have more than a
> few bindings, and don't want to bind to every single validation status
> of every binding. In this case a trick I just learned from RPC guru Kai
> Tödter comes in handy: let an instance of AggregateValidationStatus do
> the plumbing and listen to it's value changes.
>
> I tried to hack an example together, hope it works in your code:
>
> public void bind() {
> DataBindingContext bindingContext = new DataBindingContext();
>
> // ... do some bindings here ...
> bindingContext.bindValue(SWTObservables.observeText(...),
> BeansObservables.observeValue(...), null, null);
> // ... do some more ...
>
> // aggregate the status information of all bindings in one object
> // (AggregateValidationStatus.MAX_SEVERITY means, that we get the most
> // severe status when more than one is not OK.)
> AggregateValidationStatus avs = new
> AggregateValidationStatus(bindingContext,
> AggregateValidationStatus.MAX_SEVERITY);
>
> // and react when at least one status is not ok.
> avs.addValueChangeListener(new IValueChangeListener() {
> @Override
> public void handleValueChange(ValueChangeEvent event) {
> IStatus newVal = (IStatus) event.diff.getNewValue();
> if (!newVal.isOK()) {
> newVal.getException().printStackTrace();
> }
> }
> });
> }
>
>
> HTH
> Carsten ;o)
>
|
|
|
|
Powered by
FUDForum. Page generated in 0.03534 seconds