DataBindingContext for TableViewer in ViewPart [message #12017] |
Mon, 08 June 2009 04:53 |
|
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 14:08 |
vincent pucheux Messages: 15 Registered: July 2009 |
Junior Member |
|
|
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 #12115 is a reply to message #12103] |
Mon, 08 June 2009 16:57 |
|
I already have a main method in another ApplicationWindow (the activator
class of my program). That class in turn calls several other composites
(which call other viewers). This is how my program is set up. Even if I
didn't extend ViewPart in this particular case, and just extended
TableViewer, I don't think that would make any difference as far as
instantiating a Realm because there is no main method in this class.
|
|
|
|
|
|
|
Re: DataBindingContext for TableViewer in ViewPart [message #12911 is a reply to message #12103] |
Tue, 09 June 2009 00:45 |
|
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?
|
|
|
|
Re: DataBindingContext for TableViewer in ViewPart [message #13055 is a reply to message #12940] |
Tue, 09 June 2009 14:25 |
|
Here is the partial code of my TableViewer class. At I get an error
"Realm cannot be null when I create a DataBindingContext. There is no
need for you to see the rest of the code since it doesn't make it there.
public class OrderTableViewer extends TableViewer{
static int orderNumber;
BigDecimal subtotal;
//TableViewer for ordered items from DB
private TableViewer viewer;
TableViewerColumn column;
private DataBindingContext bindingContext;
//constructor
public OrderTableViewer(Composite parent) {
super(parent);
createPartControl(parent);
}
public void createPartControl(Composite parent) {
createViewer(parent);
// Get the content for the viewer, setInput will call getElements in the
// contentProvider
try{
viewer.setInput(ModelProvider.getInstance().getItems());
}
catch(Exception e){
System.err.println("Exception setting input for the viewer: " +
e.getMessage());
}
bindingContext = new DataBindingContext(Realm.getDefault());
bindingContext.getBindings().getRealm().exec(new Runnable() {
public void run() {
bindingContext.dispose();
bindingContext = null;
}
});
bindData();
}
|
|
|
Re: DataBindingContext for TableViewer in ViewPart [message #13083 is a reply to message #12940] |
Tue, 09 June 2009 14:27 |
|
Here is the partial code of my TableViewer class. I get an error "Realm
cannot be null" when I create a DataBindingContext. There is no need for
you to see the rest of the code since it doesn't make it there.
public class OrderTableViewer extends TableViewer{
static int orderNumber;
BigDecimal subtotal;
//TableViewer for ordered items from DB
private TableViewer viewer;
TableViewerColumn column;
private DataBindingContext bindingContext;
//constructor
public OrderTableViewer(Composite parent) {
super(parent);
createPartControl(parent);
}
public void createPartControl(Composite parent) {
createViewer(parent);
// Get the content for the viewer, setInput will call getElements in the
// contentProvider
try{
viewer.setInput(ModelProvider.getInstance().getItems());
}
catch(Exception e){
System.err.println("Exception setting input for the viewer: " +
e.getMessage());
}
bindingContext = new DataBindingContext(Realm.getDefault());
bindingContext.getBindings().getRealm().exec(new Runnable() {
public void run() {
bindingContext.dispose();
bindingContext = null;
}
});
bindData();
}
|
|
|
|
Re: DataBindingContext for TableViewer in ViewPart [message #13141 is a reply to message #13112] |
Tue, 09 June 2009 18:23 |
|
Sorry for not being clear. By saying "a fully running example" you mean a
class with a main method, right? Well I have a complex application with
many classes calling each other, so the Activator class where my main
method resides is not suitable for creating a DataBindingContext. That's
why I'm trying to create a DataBindingContext in the same class that
defines a TableViewer. And all it is is a plain class that has
TableViewer and column definitions to get from the model.
As far as the code I posted, I cleaned it up and and now its not extending
anything and I'm not disposing the DataBindingContext. Lets just say that
I have a line there:
DataBindingContext context = new DataBindingContext();
A runtime stack trace will show an error "Realm cannot be null" for this
line.
That's my main concern. Am I creating a DataBindingContext in the wrong
class? What general guidelines do you follow to decide which class to
create the DataBindingContext in?
|
|
|
|
|
|
Re: DataBindingContext for TableViewer in ViewPart [message #13277 is a reply to message #13252] |
Wed, 10 June 2009 00:49 |
|
My fault, the only reason I said Activator is because that was created for
me by default (I guess I chose an OSGi project template or something).
But for the sake of clarity I'm not even using the Activator class. I'm
just referring to my MainClass as an activator,which has the main method
and calls all the other classes in my project. Does that sound fair?
|
|
|
|
Re: DataBindingContext for TableViewer in ViewPart [message #14115 is a reply to message #12156] |
Wed, 10 June 2009 16:13 |
Boris Bokowski Messages: 272 Registered: July 2009 |
Senior Member |
|
|
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.
>
|
|
|
|
Powered by
FUDForum. Page generated in 0.03496 seconds