Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Hook after edits
icon5.gif  Hook after edits [message #644085] Thu, 09 December 2010 12:31 Go to next message
Marco  is currently offline Marco Friend
Messages: 216
Registered: August 2009
Senior Member
Hi,

I want to process changes to the model immediately. I expect a hook to which I can register my code which is then called with the changed EObject as parameter.

Imagine something like a code generator which works real-time (in a background job) instead of batch.

Any advise?

Thanks,
Marco
Re: Hook after edits [message #644106 is a reply to message #644085] Thu, 09 December 2010 14:21 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
Hi Marco,

you could try to register an
org.eclipse.xtext.ui.editor.model.IXtextModelListener

Regards,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com

Am 09.12.10 13:31, schrieb Marco:
> Hi,
>
> I want to process changes to the model immediately. I expect a hook to
> which I can register my code which is then called with the changed
> EObject as parameter.
>
> Imagine something like a code generator which works real-time (in a
> background job) instead of batch.
>
> Any advise?
>
> Thanks,
> Marco
Re: Hook after edits [message #644135 is a reply to message #644106] Thu, 09 December 2010 16:04 Go to previous messageGo to next message
Marco  is currently offline Marco Friend
Messages: 216
Registered: August 2009
Senior Member
Sebastian,

Thank you for your quick answer.

There is no service I can use to register the listener. So I need to register to the XTextDocument, right? So I need to register it to all XTextDocuments for which an editor was opened, right? What is then the hook to use to act when a document was opened?

An IXtextModelListener.modelChanged just gets the resource. How can I then efficiently identify which object was just changed?

/m
Re: Hook after edits [message #644777 is a reply to message #644135] Tue, 14 December 2010 08:36 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
Hi Marco,

you may want to use the IStateChangeEventBroker and inspect the deltas.

Regards,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com

Am 09.12.10 17:04, schrieb Marco:
> Sebastian,
>
> Thank you for your quick answer.
>
> There is no service I can use to register the listener. So I need to
> register to the XTextDocument, right? So I need to register it to all
> XTextDocuments for which an editor was opened, right? What is then the
> hook to use to act when a document was opened?
>
> An IXtextModelListener.modelChanged just gets the resource. How can I
> then efficiently identify which object was just changed?
>
> /m
Re: Hook after edits [message #644855 is a reply to message #644777] Tue, 14 December 2010 13:35 Go to previous messageGo to next message
Marco  is currently offline Marco Friend
Messages: 216
Registered: August 2009
Senior Member
Hi Sebastian,

This works fine for the general notification. But the delta does not provide any specific information about the change EObject.

Comparing the content of new with the content of old would be quite slow. I am even not sure if I would recognize if there is a non-structural change like the value of a literal in an expression.

Do you have any further hint?

Thanks,
Marco
Re: Hook after edits [message #644881 is a reply to message #644855] Tue, 14 December 2010 15:15 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
Hi Marco,

you could try to use some kind of hash in the user data of EObjects that
reflects the structure. Sorting the old descriptions and new
descriptions and walking both collections should be pretty fast if you
can simply compare the hash values.
There is no other protocol in Xtext available, but you could always use
an EMF adapter to get very fine grained notifications.

Regards,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com

Am 14.12.10 14:35, schrieb Marco:
> Hi Sebastian,
>
> This works fine for the general notification. But the delta does not
> provide any specific information about the change EObject.
>
> Comparing the content of new with the content of old would be quite
> slow. I am even not sure if I would recognize if there is a
> non-structural change like the value of a literal in an expression.
>
> Do you have any further hint?
>
> Thanks,
> Marco
Re: Hook after edits [message #644888 is a reply to message #644881] Tue, 14 December 2010 15:50 Go to previous messageGo to next message
Marco  is currently offline Marco Friend
Messages: 216
Registered: August 2009
Senior Member
Sebastian,

For the hash approach I would need to define a post processing for the generator which would generate a hash method into each relevant EObject, right?

What is this EMF adapter thing?

BTW: Is there a simple method for a generic deep copy of a model. I want to take a quick snapshot for heavy processing in the background. This way I would then also compare the model with the latest snapshot instead of track all changes.

Thx,
Marco
Re: Hook after edits [message #644926 is a reply to message #644888] Tue, 14 December 2010 18:50 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
Hi Marco,

I assumend that you customize your resource description manager to add
user data to the descriptions of EObjects. There is no need to generate
something into every EClass.

Please refer to the EMF documentation about Notifications and EAdapter
for details on this concept.

EcoreUtil.copy() is your friend if you want to create a deep copy.

Regards,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com

Am 14.12.10 16:50, schrieb Marco:
> Sebastian,
>
> For the hash approach I would need to define a post processing for the
> generator which would generate a hash method into each relevant EObject,
> right?
>
> What is this EMF adapter thing?
>
> BTW: Is there a simple method for a generic deep copy of a model. I want
> to take a quick snapshot for heavy processing in the background. This
> way I would then also compare the model with the latest snapshot instead
> of track all changes.
>
> Thx,
> Marco
Re: Hook after edits [message #655343 is a reply to message #644926] Sat, 19 February 2011 16:43 Go to previous message
No real name is currently offline No real nameFriend
Messages: 1
Registered: February 2011
Junior Member
Hi Sebastian,

Could you kindly suggest where to hook up the EMF adapter to listen for model changes in the Xtext generated projects?

I have exactly the same requirements as Marco. But I'd like to use the model changes to customise the content assist and drive parts of the validation. I suspect the "MyDSL.ui" project is the right project, but where in the APIs is the appropriate place to hook the model change listener?

Thanks in advance.

Regards,
Dayo
Previous Topic:popup actions on the editor text
Next Topic:Xtext as RCP but with integration in external JAVA SWT application.
Goto Forum:
  


Current Time: Thu Apr 18 01:28:28 GMT 2024

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

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

Back to the top