Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » [DataBinding] AssertionFailedException: "null argument" when using DataBindingContext's de
[DataBinding] AssertionFailedException: "null argument" when using DataBindingContext's de [message #332591] Thu, 30 October 2008 10:18 Go to next message
Sebastian Paul is currently offline Sebastian PaulFriend
Messages: 106
Registered: July 2009
Senior Member
Hi,

I have a Wizard that runs a IRunnableWithProgress with
getContainer().run(true, false, runnable);

The runnable causes a notification somewhere that causes initialization
of a DataBindingContext in a UI component.

The component uses the default constructor DataBindingContext(), and
this works unless it is called from the wizards ModalContext. In that
case, the assertion in the constructor DataBindingContext(Realm) fails.
Obviously, Realm.getDefault() returned null.

What do I have to do? I have no idea which Realm to provide for the
DataBindingContext. Why is it necessary? This problem seems to be
similar to
http://www.eclipse.org/newsportal/article.php?id=78491&g roup=eclipse.platform#78491

Kind regards, Sebastian
Re: [DataBinding] AssertionFailedException: "null argument" when using DataBindingContext' [message #332592 is a reply to message #332591] Thu, 30 October 2008 10:41 Go to previous messageGo to next message
Sebastian Paul is currently offline Sebastian PaulFriend
Messages: 106
Registered: July 2009
Senior Member
Databinding is triggered by a PropertyChangeListener. I can workaround
my problem by databinding on the UI thread.

public void propertyChange(PropertyChangeEvent evt) {
[...]
getDisplay().asyncExec(new Runnable() {
public void run() {
bind(notifier);
}
});
}

protected void bind(PropertyChangeNotifier notifier) {
dataBindingContext = new DataBindingContext(); // PROBLEM HERE
dataBindingContext.bindValue(
SWTObservables.observeText(myText, SWT.Modify),
BeansObservables.observeValue(notifier, "MY_PROP"),
null, null);
[...]
}

But isn't it an implementation detail of DataBindingContext? If not,
where do I find information about the Realm stuff?

Kind regards, Sebastian
Re: [DataBinding] AssertionFailedException: "null argument" when using DataBindingContext' [message #332593 is a reply to message #332592] Thu, 30 October 2008 11:07 Go to previous messageGo to next message
Sebastian Paul is currently offline Sebastian PaulFriend
Messages: 106
Registered: July 2009
Senior Member
Sebastian Paul wrote:
> I can workaround my problem by databinding on the UI thread.
> [...]
> getDisplay().asyncExec(new Runnable() {

Must be syncExec, as strange behavior would occur. In my case, any
change in the Text control causes it to synchronize with the model,
moving the text cursor to the beginning on each key press. Might be
useful for typing from right to left :D

Kind regards, Sebastian
Re: [DataBinding] AssertionFailedException: "null argument" when using DataBindingContext' [message #332597 is a reply to message #332592] Thu, 30 October 2008 15:19 Go to previous messageGo to next message
Matthew Hall is currently offline Matthew HallFriend
Messages: 368
Registered: July 2009
Senior Member
Wrap you app's main() instructions in a call to:

The default realm is set using a call to Realm.runWithDefault(Realm,
Runnable). The default realm is set while the runnable is running, and
is set to the previous realm after the runnable completes.

Most of my apps have a main method that looks like this:

Display display = new Display();
Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() {
public void run() {
// create and open main application window
}
});

Matthew


Sebastian Paul wrote:
> Databinding is triggered by a PropertyChangeListener. I can workaround
> my problem by databinding on the UI thread.
>
> public void propertyChange(PropertyChangeEvent evt) {
> [...]
> getDisplay().asyncExec(new Runnable() {
> public void run() {
> bind(notifier);
> }
> });
> }
>
> protected void bind(PropertyChangeNotifier notifier) {
> dataBindingContext = new DataBindingContext(); // PROBLEM HERE
> dataBindingContext.bindValue(
> SWTObservables.observeText(myText, SWT.Modify),
> BeansObservables.observeValue(notifier, "MY_PROP"),
> null, null);
> [...]
> }
>
> But isn't it an implementation detail of DataBindingContext? If not,
> where do I find information about the Realm stuff?
>
> Kind regards, Sebastian
>
Re: [DataBinding] AssertionFailedException: "null argument" when using DataBindingContext' [message #332598 is a reply to message #332597] Thu, 30 October 2008 14:41 Go to previous messageGo to next message
Sebastian Paul is currently offline Sebastian PaulFriend
Messages: 106
Registered: July 2009
Senior Member
Matthew Hall wrote:
> Wrap you app's main() instructions in a call to:
>
> The default realm is set using a call to Realm.runWithDefault(Realm,
> Runnable). The default realm is set while the runnable is running, and
> is set to the previous realm after the runnable completes.
>
> Most of my apps have a main method that looks like this:
>
> Display display = new Display();
> Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() {
> public void run() {
> // create and open main application window
> }
> });

Ah thank you, the missing piece.
We have an RCP application here. Any idea who to do it in an elegant way?

I'm still lacking good documentation. I found some short tutorials
covering just the basics.

Kind regards, Sebastian
Re: [DataBinding] AssertionFailedException: "null argument" when using DataBindingContext' [message #332600 is a reply to message #332598] Thu, 30 October 2008 15:12 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
The workbench already does this when to starts up.

Tom

Sebastian Paul schrieb:
> Matthew Hall wrote:
>> Wrap you app's main() instructions in a call to:
>>
>> The default realm is set using a call to Realm.runWithDefault(Realm,
>> Runnable). The default realm is set while the runnable is running,
>> and is set to the previous realm after the runnable completes.
>>
>> Most of my apps have a main method that looks like this:
>>
>> Display display = new Display();
>> Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() {
>> public void run() {
>> // create and open main application window
>> }
>> });
>
> Ah thank you, the missing piece.
> We have an RCP application here. Any idea who to do it in an elegant way?
>
> I'm still lacking good documentation. I found some short tutorials
> covering just the basics.
>
> Kind regards, Sebastian


--
B e s t S o l u t i o n . at
------------------------------------------------------------ --------
Tom Schindl JFace-Committer
------------------------------------------------------------ --------
Re: [DataBinding] AssertionFailedException: "null argument" when using DataBindingContext' [message #332616 is a reply to message #332600] Fri, 31 October 2008 16:06 Go to previous messageGo to next message
Boris Bokowski is currently offline Boris BokowskiFriend
Messages: 272
Registered: July 2009
Senior Member
The workbench sets the default realm for you (or you can use
Realm.runWithDefault) but this will only set the default realm for the UI
thread. If you start other threads (directly, or through scheduling a Job,
or IRunnableContext.run), welcome to the wonderful world of multi-threaded
programming where you start having to worry about things that you didn't
even know existed before.

What exactly are you trying to do in your runnable? It will be executed by a
separate thread. From that thread, you cannot just access observables and a
data binding context that was created using the default realm, like you
cannot just call methods on SWT widgets.

Have a look at this wiki page, does it explain what's going on?
http://wiki.eclipse.org/JFace_Data_Binding/Realm

If not, what questions does it leave open?

Boris

"Tom Schindl" <tom.schindl@bestsolution.at> wrote in message
news:gecisc$2rv$1@build.eclipse.org...
> The workbench already does this when to starts up.
>
> Tom
>
> Sebastian Paul schrieb:
>> Matthew Hall wrote:
>>> Wrap you app's main() instructions in a call to:
>>>
>>> The default realm is set using a call to Realm.runWithDefault(Realm,
>>> Runnable). The default realm is set while the runnable is running,
>>> and is set to the previous realm after the runnable completes.
>>>
>>> Most of my apps have a main method that looks like this:
>>>
>>> Display display = new Display();
>>> Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() {
>>> public void run() {
>>> // create and open main application window
>>> }
>>> });
>>
>> Ah thank you, the missing piece.
>> We have an RCP application here. Any idea who to do it in an elegant way?
>>
>> I'm still lacking good documentation. I found some short tutorials
>> covering just the basics.
>>
>> Kind regards, Sebastian
>
>
> --
> B e s t S o l u t i o n . at
> ------------------------------------------------------------ --------
> Tom Schindl JFace-Committer
> ------------------------------------------------------------ --------
Re: [DataBinding] AssertionFailedException: "null argument" when using DataBindingContext' [message #332617 is a reply to message #332616] Fri, 31 October 2008 16:07 Go to previous messageGo to next message
Boris Bokowski is currently offline Boris BokowskiFriend
Messages: 272
Registered: July 2009
Senior Member
It might help if you can post a code snippet, or at least describe in detail
what you are trying to do.

"Boris Bokowski" <Boris_Bokowski@ca.ibm.com> wrote in message
news:gefaef$bd0$1@build.eclipse.org...
> The workbench sets the default realm for you (or you can use
> Realm.runWithDefault) but this will only set the default realm for the UI
> thread. If you start other threads (directly, or through scheduling a Job,
> or IRunnableContext.run), welcome to the wonderful world of multi-threaded
> programming where you start having to worry about things that you didn't
> even know existed before.
>
> What exactly are you trying to do in your runnable? It will be executed by
> a separate thread. From that thread, you cannot just access observables
> and a data binding context that was created using the default realm, like
> you cannot just call methods on SWT widgets.
>
> Have a look at this wiki page, does it explain what's going on?
> http://wiki.eclipse.org/JFace_Data_Binding/Realm
>
> If not, what questions does it leave open?
>
> Boris
>
> "Tom Schindl" <tom.schindl@bestsolution.at> wrote in message
> news:gecisc$2rv$1@build.eclipse.org...
>> The workbench already does this when to starts up.
>>
>> Tom
>>
>> Sebastian Paul schrieb:
>>> Matthew Hall wrote:
>>>> Wrap you app's main() instructions in a call to:
>>>>
>>>> The default realm is set using a call to Realm.runWithDefault(Realm,
>>>> Runnable). The default realm is set while the runnable is running,
>>>> and is set to the previous realm after the runnable completes.
>>>>
>>>> Most of my apps have a main method that looks like this:
>>>>
>>>> Display display = new Display();
>>>> Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() {
>>>> public void run() {
>>>> // create and open main application window
>>>> }
>>>> });
>>>
>>> Ah thank you, the missing piece.
>>> We have an RCP application here. Any idea who to do it in an elegant
>>> way?
>>>
>>> I'm still lacking good documentation. I found some short tutorials
>>> covering just the basics.
>>>
>>> Kind regards, Sebastian
>>
>>
>> --
>> B e s t S o l u t i o n . at
>> ------------------------------------------------------------ --------
>> Tom Schindl JFace-Committer
>> ------------------------------------------------------------ --------
>
>
Re: [DataBinding] AssertionFailedException: "null argument" when using DataBindingContext' [message #332637 is a reply to message #332617] Mon, 03 November 2008 11:35 Go to previous message
Sebastian Paul is currently offline Sebastian PaulFriend
Messages: 106
Registered: July 2009
Senior Member
Hi Boris,
thanks for the explanations. Sorry for not providing an example, but the
problem is trivial.

There's a long running operation on my model that is triggered in a
wizard using IRunnableContext.run(boolean, boolean,
IRunnableWithProgress), with fork = true. So, model changes are
definitely not run on the UI thread.

I have situations where I have to bind to a different model object or
unbind completely. For this, I have 2 methods - bind(ModelObject) and
unbind(), where the first will create the DataBindingContext and the
latter dispose it. These are called from event handlers in my UI
component class.

In another forum thread, I discussed the problem where dispose() caused
an AssertionException. I had to wrap the call like this:
dataBindingContext.getBindings().getRealm().exec(new Runnable() {
public void run() {
dataBindingContext.dispose();
dataBindingContext = null;
}
});

Similar problem in bind(). I have to make sure that it is run on the UI
thread.

What I don't fully understand: Why do I have to worry about such thing.
Shouldn't the observables take care of this?
Where do I know in which Realm I have to create the DataBindingContext?
Is it always the target's realm, and never the model's realm?

A good point for a quote from the wiki:
"To bridge between observables in different realms, use a data binding
context - you can bind two observables even if they belong to different
realms and the bindings take care of this for you by using
Realm.asyncExec() where necessary."

I just want to understand, when and why *I* have to take care.

Kind regards, Sebastian
Previous Topic:how to know workbench is ready to use
Next Topic:tableviewer error on events ... eclipse 3.3.2
Goto Forum:
  


Current Time: Tue Jul 16 14:07:21 GMT 2024

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

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

Back to the top