Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Sharing EMF objects between views
Sharing EMF objects between views [message #916253] Tue, 18 September 2012 20:10 Go to next message
Mark Rowe is currently offline Mark RoweFriend
Messages: 23
Registered: January 2012
Junior Member
Firstly I would like to thank everyone for these fantastic frameworks and all the support available through these forums. Cool

Now for my latest problem...

I would like to have an E4 RCP application with two views (side by side).

The first view contains a JFace TableViewer bound to list of (say) books, whilst the second has text widgets that display/edit the attributes in the currently selected book.

In other words I would like to share the book object between two views.

I can do this with DI (per Tom Schindl's MailStore 4.0 App), i.e. using an ESelectionService to inject the currently selected book into the view with the text widgets. I also know it is possible with CDO, but this would mean hitting the server each time a selection is made?

Is there a way to do this using EMF? Can two views share a single model object?

Many thanks!
Re: Sharing EMF objects between views [message #916267 is a reply to message #916253] Tue, 18 September 2012 20:38 Go to previous messageGo to next message
Erdal Karaca is currently offline Erdal KaracaFriend
Messages: 854
Registered: July 2009
Senior Member

Mark Rowe wrote on Tue, 18 September 2012 16:10

I can do this with DI (per Tom Schindl's MailStore 4.0 App), i.e. using an ESelectionService to inject the currently selected book into the view with the text widgets. I also know it is possible with CDO, but this would mean hitting the server each time a selection is made?


If you already have your books list loaded into memory: why would you need to reload them from db?
What do you mean by "hitting the server each time a selection is made"?

Mark Rowe wrote on Tue, 18 September 2012 16:10

Can two views share a single model object?


Do you mean an E4 part or a CDO view?
Re: Sharing EMF objects between views [message #916280 is a reply to message #916267] Tue, 18 September 2012 20:55 Go to previous messageGo to next message
Mark Rowe is currently offline Mark RoweFriend
Messages: 23
Registered: January 2012
Junior Member
Sorry for not writing clearly (and my basic understanding of CDO).

Quote:
What do you mean by "hitting the server each time a selection is made"?


What I meant is that I assumed the application (i.e. CDO client) would send a request to the CDO server every time a new object was required. As the CDO server is on a physically different machine I assumed this request would be across my (possibly slow) network.

Are you saying that the CDO client will keep an in-memory copy of the list of books?

Quote:
Do you mean an E4 part or a CDO view


I mean an E4 part, but... maybe a CDO view is the answer to my question? Reading more... Smile

[Updated on: Tue, 18 September 2012 21:08]

Report message to a moderator

Re: Sharing EMF objects between views [message #916476 is a reply to message #916280] Wed, 19 September 2012 03:54 Go to previous messageGo to next message
Eike Stepper is currently offline Eike StepperFriend
Messages: 6690
Registered: July 2009
Senior Member
Am 18.09.2012 22:55, schrieb Mark Rowe:
> What I meant is that the application would send a request to the CDO server every time a new object was required. As
> the CDO server is on a physically different machine I assumed this request would be across my (possibly slow) network.
I'm a little confused about this. Your original question was about a master/detail kind of user interface and how to
exchange EObjects between the two. You don't need a server for this, just one EMF ResourceSet to feed the master view
with EObjects. Such a view normally needs read-only access to the model and registers an ISelectionProvider (the JFace
viewer) with the part site. The details view can then directly access the EObject selected in the master view and change it.

If you architecture includes a CDO remote server for other reasons you'll have to consider/tweak the load
characteristics (cache types, demand/partial loading, prefetching, offline replication, ...) anyway, so that's not
master/detail specific. A real use case for CDO would be if both of your view parts are supposed to modify EObjects in
separate concurrent transactions. This is often the implication of long running actions in the popup menus of the master
view. But still, without a primary need for collaboration you'd not set up a remote server but simply embed a CDO
repository into your application.

> Are you saying that the CDO client will keep an in-memory copy of the list of books?
CDO caches all objects individually. In your case the Library (which contains the list of books) is cached, as well as
each individual book in that list. Caches are implemented with SoftReferences by default and of course no eviction
happens for objects your application is holding pointers to.

Cheers
/Eike

----
http://www.esc-net.de
http://thegordian.blogspot.com
http://twitter.com/eikestepper


Re: Sharing EMF objects between views [message #916721 is a reply to message #916476] Wed, 19 September 2012 11:11 Go to previous message
Mark Rowe is currently offline Mark RoweFriend
Messages: 23
Registered: January 2012
Junior Member
Hi Eike,

Thank you for your help again. Yes, you answered my original question which was how to implement the two views using EMF. The objects in this case are only used in the presentation of the user interface, the persistence is performed by other objects.

Quote:
You don't need a server for this, just one EMF ResourceSet to feed the master view with EObjects. Such a view normally needs read-only access to the model and registers an ISelectionProvider (the JFace viewer) with the part site. The details view can then directly access the EObject selected in the master view and change it.


Late last night Rolling Eyes I came to a similar conclusion. So in the list view I bound the table viewer to the list of books and then registered an ISelectionProvider (I think) with the following:

getSite().setSelectionProvider(tableViewer);

(credit: Tom Schindl)

Then in the detail view I listen to the selection changes as follows:

   ISelectionListener listener = new ISelectionListener() {
      public void selectionChanged(IWorkbenchPart part, ISelection sel) {
         if (!(sel instanceof IStructuredSelection))
            return;
         IStructuredSelection ss = (IStructuredSelection) sel;
         Object o = ss.getFirstElement();
         if (o instanceof Book) {
         	updateBook((Book)o);
                System.out.println("Table view selection changed");
         }
      }

(credit: Vincenzo Caselli)

updateBook is intended to set the "book" EObject to which the text widgets are bound to be the one which is currently selected in the table viewer. Vincenzo uses CDO transactions to do this.

So my current sticking point is what to updateBook should do? I have just found Tom's series on EMF Databinding (Parts 1 - 5) though, so I will read through that before asking any more questions Razz

Well okay one more... (maybe not for this forum) in E4, shouldn't I use DI to inject the selection change to the detail view rather than listening?


Previous Topic:properties view sync with multiple tree viewer
Next Topic:[Teneo] Error when storing EAttribute
Goto Forum:
  


Current Time: Tue Sep 24 23:09:33 GMT 2024

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

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

Back to the top