Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » JFace » Exceptions and DataBindingContext.bindXXX methods
Exceptions and DataBindingContext.bindXXX methods [message #665013] Tue, 12 April 2011 20:06 Go to next message
J.-P. Pellet is currently offline J.-P. PelletFriend
Messages: 71
Registered: July 2009
Member
Suppose I bind two values with DataBindingContext.bindValue(). Later,
one value changes and the other one is updated correspondingly, but its
setter throws an exception. I don't see this exception, as it is caught
by DataBindingContext. Is there a way to by default print a stack trace
each time that such an exception occurs? What's the preferred way of
dealing with such exceptions?

Cheers,
J.-P.
Re: Exceptions and DataBindingContext.bindXXX methods [message #665217 is a reply to message #665013] Wed, 13 April 2011 18:01 Go to previous messageGo to next message
Carsten Habicht is currently offline Carsten HabichtFriend
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 Go to previous messageGo to next message
J.-P. Pellet is currently offline J.-P. PelletFriend
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)
>
Re: Exceptions and DataBindingContext.bindXXX methods [message #665913 is a reply to message #665013] Mon, 18 April 2011 06:59 Go to previous message
jim liu is currently offline jim liuFriend
Messages: 37
Registered: February 2011
Location: shanghai
Member
org.eclipse.core.databinding.AggregateValidationStatus


java eclipse Search
http://javafind.appspot.com/
Previous Topic:Expand Dialog to one direction by Button
Next Topic:Zest Graph Viewer reference points to null all of a sudden
Goto Forum:
  


Current Time: Tue Apr 16 10:06:17 GMT 2024

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

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

Back to the top