Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » JFace » Eclipse 3.2 Databinding -> Realm is null
Eclipse 3.2 Databinding -> Realm is null [message #527749] Fri, 16 April 2010 11:17 Go to next message
Jan  is currently offline Jan Friend
Messages: 9
Registered: March 2010
Junior Member
Hi,

we work with Eclipse 3.2 and EMF 2.3 and we use the Databinding functionalities from Eclipse 3.4 and EMF 2.4.

Now I have the problem that there isn't set a default realm. The following call returns "null":
Realm testRealm = Realm.getDefault();

If I set-up a DataBindingContext I get an Exception: "Validation realm cannot be null"

Cause of that I have implemented my own Realm:
public class MyTestValidationRealm extends Realm {

  private Realm previousRealm;

  public boolean isCurrent() {
           return true;
  }
	
  public MyTestValidationRealm() {
          previousRealm = super.setDefault(this);
  }
	
  protected void syncExec(Runnable runnable) {
        runnable.run();
    }

   public void asyncExec(Runnable runnable) {
        throw new UnsupportedOperationException("asyncExec is unsupported");
    }

    public void dispose() {
        if (getDefault() == this) {
            setDefault(previousRealm);
        }
    }
}


But with this I get an error if I want to bind some things in another composite:
ObservableListTreeContentProvider cp = new ObservableListTreeContentProvider(EMFEditObservables.listFactory(Realm.getDefault(), editingDomain, WebpagePackage.Literals.MY_WEB__PAGES),null);

There I get the error:
"Children observable collection must be on the Display realm"

I don't thing it is a good idea for:
ObservableListTreeContentProvider cp = new ObservableListTreeContentProvider(EMFEditObservables.listFactory(SWTObservables.getRealm(compTreeViewer.getDisplay()), editingDomain, WebpagePackage.Literals.MY_WEB__PAGES),null);

Cause then I have different Realms, and my BindingContext doesn't know anything about the other.

What is wrong in this implementation and how it is right?

Greetings
Jan
Re: Eclipse 3.2 Databinding -> Realm is null [message #527752 is a reply to message #527749] Fri, 16 April 2010 11:32 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Are you running as a RCP-Application or stand-alone?

Running standalone:
-------------------
The standard trick normally is that you launch your application like this:

------------8<------------
Display d = new Display();
Shell s = new Shell();

Realm.runWithDefault(SWTObservable.getRealm(d), new Runnable() {
public void run() {
runApp();

while( ! s.isDiposed() ) {
if( ! d.readAndDispatch() ) {
d.sleep();
}
}
}
})

d.dispose();
------------8<------------

Running in RCP or EclipsePlugin:
--------------------------------
I'm not sure about when the workbench itself started using
Eclipse-Databinding but it could be that workbench-startup in 3.2 is not
wrapped inside a run block like shown above.

So if this is the case then you need wrap your code your own in a block
like the one shown above. This way always a default-realm is set which
is working on the swt-ui-thread.

Tom

Am 16.04.10 13:17, schrieb Jan:
> Hi,
>
> we work with Eclipse 3.2 and EMF 2.3 and we use the Databinding
> functionalities from Eclipse 3.4 and EMF 2.4.
>
> Now I have the problem that there isn't set a default realm. The
> following call returns "null":
> Realm testRealm = Realm.getDefault();
>
> If I set-up a DataBindingContext I get an Exception: "Validation realm
> cannot be null"
>
> Cause of that I have implemented my own Realm:
>
> public class MyTestValidationRealm extends Realm {
>
> private Realm previousRealm;
>
> public boolean isCurrent() {
> return true;
> }
>
> public MyTestValidationRealm() {
> previousRealm = super.setDefault(this);
> }
>
> protected void syncExec(Runnable runnable) {
> runnable.run();
> }
>
> public void asyncExec(Runnable runnable) {
> throw new UnsupportedOperationException("asyncExec is unsupported");
> }
>
> public void dispose() {
> if (getDefault() == this) {
> setDefault(previousRealm);
> }
> }
> }
>
>
> But with this I get an error if I want to bind some things in another
> composite:
>
> ObservableListTreeContentProvider cp = new
> ObservableListTreeContentProvider(EMFEditObservables.listFac tory(Realm.getDefault(),
> editingDomain, WebpagePackage.Literals.MY_WEB__PAGES),null);
>
> There I get the error: "Children observable collection must be on the
> Display realm"
>
> I don't thing it is a good idea for:
>
> ObservableListTreeContentProvider cp = new
> ObservableListTreeContentProvider(EMFEditObservables.listFac tory(SWTObservables.getRealm(compTreeViewer.getDisplay()),
> editingDomain, WebpagePackage.Literals.MY_WEB__PAGES),null);
>
> Cause then I have different Realms, and my BindingContext doesn't know
> anything about the other.
>
> What is wrong in this implementation and how it is right?
>
> Greetings
> Jan
Re: Eclipse 3.2 Databinding -> Realm is null [message #527757 is a reply to message #527749] Fri, 16 April 2010 11:51 Go to previous messageGo to next message
Jan  is currently offline Jan Friend
Messages: 9
Registered: March 2010
Junior Member
Hi Tom,

we are writing a Plugin for the Notes client which, in version 8 depends on Eclipse 3.2.

In my test-application for DataBinding I have written also a plugin for Eclipse 3.2 with an own view.

I don't know where I should implement your shown code. The display already exists if I run my plugin. Do I have to implement this code in Activator class of my Plugin or in my View class?
public class SampleView extends ViewPart implements IEditingDomainProvider, IViewerProvider{
Or is there another class where I should implement this?

In Eclipse 3.5 I saw that there is already a default realm set.

Greetings
Jan
Re: Eclipse 3.2 Databinding -> Realm is null [message #527762 is a reply to message #527757] Fri, 16 April 2010 12:01 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Hi Jan,

Ok. That's what I meant if you are running as a plugin you'll get into
trouble because you don't control the startup process - as you found out
Eclipse 3.5 (IIRC it was introduced in 3.3) sets the default realm like
I showed in my first reply.

So the only thing you can do in 3.2 is make your ViewPart like this:

public void createPartControl(Composite parent) {
Realm.runWithDefault( SWTObservables.getRealm(), new Runnable() {
public void run() {
doCreatePartControl(parent);
// You can NOT spin the event loop here => see Button comment
}
});
}

private void doCreatePartControl(Composite parent) {
// You have a default realm while running here
syserr(Realm.getDefault()); // Prints the SWTRealm

Button b = new Button(parent,SWT.PUSH);
b.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent evt) {
syserr(Realm.getDefault()); // prints null because we can't spin
// event loop
}
});
}

Tom

Am 16.04.10 13:51, schrieb Jan:
> Hi Tom,
>
> we are writing a Plugin for the Notes client which, in version 8 depends
> on Eclipse 3.2.
>
> In my test-application for DataBinding I have written also a plugin for
> Eclipse 3.2 with an own view.
>
> I don't know where I should implement your shown code. The display
> already exists if I run my plugin. Do I have to implement this code in
> Activator class of my Plugin or in my View class?
> public class SampleView extends ViewPart implements
> IEditingDomainProvider, IViewerProvider{ Or is there another class where
> I should implement this?
>
> In Eclipse 3.5 I saw that there is already a default realm set.
>
> Greetings Jan
Re: Eclipse 3.2 Databinding -> Realm is null [message #527804 is a reply to message #527762] Fri, 16 April 2010 14:39 Go to previous message
Jan  is currently offline Jan Friend
Messages: 9
Registered: March 2010
Junior Member
Hi Tom,

cool, it works Razz .
Thanks for your fast help.

Greetings
Jan
Previous Topic:Linking Databinding Validation with WizardPage [WizardPageSupport]
Next Topic:FontRegistry usage
Goto Forum:
  


Current Time: Fri Apr 19 20:54:06 GMT 2024

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

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

Back to the top