Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » EMF Notifications via Xtext index(Receiving EMF notifications as users work in the editors)
EMF Notifications via Xtext index [message #886349] Thu, 14 June 2012 19:16 Go to next message
Joey Mink is currently offline Joey MinkFriend
Messages: 87
Registered: July 2009
Location: Centreville, VA, USA
Member

Hi,

I'm new to the EMF notification framework, but found some examples and started experimenting unsuccessfully. So I thought I'd ask a general question...

Can I register for EMF notifications if I obtain an EObject through the Xtext index? Something like this...

public class SomeClass {
	@Inject
	private IResourceDescriptions xtextIndex;

	public void addListener(EContentAdapter adapter, URI uri) {
		IResourceDescription resourceDesc = xtextIndex.getResourceDescription(uri);
                EList<Contents> contents = resourceDesc.getExportedObjectsByType(
                    DslPackage.eINSTANCE.getContents());
                contents.eAdapters().add(adapter);
	}
}


If the user edits and saves the IFile corresponding to the URI received by SomeClass.addListener, can I expect a call to adapter.notifyChanged() on the adapter passed in to addListener?
Re: EMF Notifications via Xtext index [message #886354 is a reply to message #886349] Thu, 14 June 2012 19:28 Go to previous messageGo to next message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2509
Registered: July 2009
Senior Member
Short Answer: No that will not work.

Longer:
Xtext modifies the model "all the time", what you are attaching
listeners to will get thrown away.

The thing you probably want is achieved by participating in the
incremental build. In the IDE, Xtext maintains a global index of
EObjectDescriptions, and descriptions of references, and also of
imports/exports - this is used to figure out the order in which things
needs to be "built"/updated.

This happens automatically for the reference support built in to Xtext.

Not knowing what you are trying to achieve with the suggested listner it
is difficult to give more concrete advice. Can you describe your usecase?

Regards
- henrik

On 2012-14-06 21:17, Joey Mink wrote:
> Hi,
>
> I'm new to the EMF notification framework, but found some examples and
> started experimenting unsuccessfully. So I thought I'd ask a general
> question...
>
> Can I register for EMF notifications if I obtain an EObject through the
> Xtext index? Something like this...
>
>
> public class SomeClass {
> @Inject
> private IResourceDescriptions xtextIndex;
>
> public void addListener(EContentAdapter adapter, URI uri) {
> IResourceDescription resourceDesc =
> xtextIndex.getResourceDescription(uri);
> EList<Contents> contents =
> resourceDesc.getExportedObjectsByType(
> DslPackage.eINSTANCE.getContents());
> contents.eAdapters().add(adapter);
> }
> }
>
>
> If the user edits and saves the IFile corresponding to the URI received
> by SomeClass.addListener, can I expect a call to adapter.notifyChanged()
> on the adapter passed in to addListener?
Re: EMF Notifications via Xtext index [message #886361 is a reply to message #886354] Thu, 14 June 2012 19:49 Go to previous messageGo to next message
Joey Mink is currently offline Joey MinkFriend
Messages: 87
Registered: July 2009
Location: Centreville, VA, USA
Member

Henrik,

Thanks for the informative response! What I'm effectively trying to do is update the contents of a Common Navigator view when EObjects of a centain type are created/removed/updated. I tried to do something like the above example by making a Common Navigator's content provider implement EContentAdapter. But as you said, I received no updates of any kind.
Re: EMF Notifications via Xtext index [message #886408 is a reply to message #886361] Thu, 14 June 2012 21:37 Go to previous messageGo to next message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2509
Registered: July 2009
Senior Member
On 2012-14-06 21:49, Joey Mink wrote:
> Henrik,
>
> Thanks for the informative response! What I'm effectively trying to do
> is update the contents of a Common Navigator view when EObjects of a
> centain type are created/removed/updated. I tried to do something like
> the above example by making a Common Navigator's content provider
> implement EContentAdapter. But as you said, I received no updates of
> any kind.

ok, note that there are two indexes; one that represents the saved state
on disk, and one that describes the current state in dirty editors.

For a navigator you probably want to show the saved state only.

I recommend writing a builder that updates your common navigator.
You have to be careful to not have to open every resource on changes
(gets very expensive).

Sounds like you are trying to do a global "outline" - maybe you get some
hints from looking at the implementation of that.

That is if you really need to keep a view updated at all times.
Wrt to navigation, there are already things like "open declaration of",
and "find references" that you may want to look at.

I wrote a similar thing that is specialized in cloudsmith / geppetto
@github.

Regards
- henrik
Re: EMF Notifications via Xtext index [message #888640 is a reply to message #886408] Mon, 18 June 2012 12:13 Go to previous message
Joey Mink is currently offline Joey MinkFriend
Messages: 87
Registered: July 2009
Location: Centreville, VA, USA
Member

Henrik,

You are correct! I'm implementing yet another global outline view. I've done others that implement IResourceChangeListener and use the Xtext index to rebuild the navigator's contents. But I thought I'd try things a different way this time. Sounds like I should consider hooking up to the build.

Thanks for the insights and advice!
Previous Topic:Serializing a model with references to dynamically created objects
Next Topic:Ambiguous Grammar?
Goto Forum:
  


Current Time: Thu Apr 25 10:33:03 GMT 2024

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

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

Back to the top