EMF Notifications via Xtext index [message #886349] |
Thu, 14 June 2012 15:16  |
Eclipse User |
|
|
|
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 15:28   |
Eclipse User |
|
|
|
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 #888640 is a reply to message #886408] |
Mon, 18 June 2012 08:13  |
Eclipse User |
|
|
|
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 1.37959 seconds