DataBindingContext for TableViewer in ViewPart [message #12017] |
Mon, 08 June 2009 00:53  |
Eclipse User |
|
|
|
Hi,
I have created a TableViewer in a class that extends a ViewPart. This
TableViewer is called from yet another class. I wish to use a
DataBindingContext for this TableViewer, but I get an error "Realm cannot
be null". There is no way I can start a realm in a class that does not
have a main method, right? Does that mean that I should forget about
using DataBindingContext, and just manually synchronize TableViewer's
values with the model?
|
|
|
Re: DataBindingContext for TableViewer in ViewPart [message #12030 is a reply to message #12017] |
Mon, 08 June 2009 10:08   |
Eclipse User |
|
|
|
Igor Ganapolsky a écrit :
> Hi,
> I have created a TableViewer in a class that extends a ViewPart. This
> TableViewer is called from yet another class. I wish to use a
> DataBindingContext for this TableViewer, but I get an error "Realm
> cannot be null". There is no way I can start a realm in a class that
> does not have a main method, right? Does that mean that I should forget
> about using DataBindingContext, and just manually synchronize
> TableViewer's values with the model?
>
hi,
As I remember you can use Realm.getDefault()
like this :
IObservableValue amountBinding = BeansObservables.observeDetailValue(
Realm.getDefault(), sel, "amount", Integer.class);
dbc.bindValue(
SWTObservables.observeText(amount, SWT.Modify), amountBinding, null);
vincent
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Re: DataBindingContext for TableViewer in ViewPart [message #14115 is a reply to message #12156] |
Wed, 10 June 2009 12:13   |
Eclipse User |
|
|
|
Hi Igor,
We recommend that somewhere early in your application, you use
Realm.runWithDefault similar to what Tom has suggested:
public static void main(String[] args) {
Display d = new Display();
Ream.runWithDefault( SWTObservables.getRealm(d), new Runnable() {
public void run() {
internalMain();
}
});
}
private static void internalMain() {
}
In fact, when you look at the data binding snippets, they all contain code
like this.
Without this, you will need to specify the realm explicitly for things like
creating observables, setting up a data binding context, etc. for example
like this:
Realm realm = SWTObservables.getRealm(viewer.getTable().getDisplay());
bindingContext = new DataBindingContext(realm);
Boris
"Igor Ganapolsky" <eazyigz@gmail.com> wrote in message
news:3dad193d5ed5fd12428395cfb7f0709b$1@www.eclipse.org...
> I'm trying this code right now, but I'm getting a compilation error "Realm
> cannot be resolved." How can I declare and instantiate a Realm?
> Thank you.
>
|
|
|
Re: DataBindingContext for TableViewer in ViewPart [message #17643 is a reply to message #12911] |
Mon, 29 June 2009 18:25  |
Eclipse User |
|
|
|
Igor,
There is no default realm provided for you automatically--you must set
the default realm yourself. As Tom and Boris have suggested earlier,
the easiest way to fix this problem is to go back to your main class and
wrap the body in something like this:
before:
public class Main {
public void main(String[] args) {
// my main method
}
}
after:
public class Main {
public void main(String[] args) {
Realm.runWithDefault(
SWTObservables.getRealm(Display.getDefault()),
new Runnable() {
public void run() {
// my main method
}
} );
}
}
Hope this helps,
Matthew
Igor Ganapolsky wrote:
> I was able to compile your code snippet no problem (it was my spelling
> error). However, when I do the following in another class which defines
> the TableViewer I get an error "Realm cannot be null":
>
> bindingContext = new DataBindingContext(Realm.getDefault());
>
> Why is Realm null?
>
|
|
|
Powered by
FUDForum. Page generated in 0.07608 seconds