EMF Notifications via Xtext index [message #886349] |
Thu, 14 June 2012 19:16 |
|
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 |
Henrik Lindberg 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 |
|
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 #888640 is a reply to message #886408] |
Mon, 18 June 2012 12:13 |
|
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!
|
|
|
Powered by
FUDForum. Page generated in 0.03141 seconds