Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Listener for all EMF based models
Listener for all EMF based models [message #424750] Tue, 04 November 2008 21:20 Go to next message
Philip Langer is currently offline Philip LangerFriend
Messages: 31
Registered: July 2009
Member
Hello,

Sorry, I'm quite new to writing plug-ins. So please be patient :)

I'm currently trying to write a plug-in which tracks all operations on
EMF based resources (UML2 models, ecore models, ...) made by any editor
(tree editor, GMF based editors, ...).

Therefore I tried to use a ResourceSetListener with the
org.eclipse.emf.transaction.listeners extension point. Because I want to
track ALL resource operations I didn't specifiy any specific editing
domain. Unfortunately my listener implementation didn't receive any
notifications while editing an ecore model.

My extension point in the plugin.xml:

<extension
id="at.ac.tuwien.big.motrack.operationListener"
name="ModelOperationListener"
point="org.eclipse.emf.transaction.listeners">
<listener
class="at.ac.tuwien.big.motrack.ModelOperationListener">
</listener>
</extension>

Is there something wrong with my extension point configuration? Or is my
approach completely wrong? Is there a better way to get notified of all
model modifications?

Thank you very much in advance!

Philip Langer
Re: Listener for all EMF based models [message #424753 is a reply to message #424750] Tue, 04 November 2008 23:00 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
Philip,

Comments below.

Philip Langer wrote:
> Hello,
>
> Sorry, I'm quite new to writing plug-ins. So please be patient :)
>
Patient? I don't do patient. :-P
> I'm currently trying to write a plug-in which tracks all operations on
> EMF based resources (UML2 models, ecore models, ...) made by any editor
> (tree editor, GMF based editors, ...).
>
> Therefore I tried to use a ResourceSetListener with the
> org.eclipse.emf.transaction.listeners extension point. Because I want to
> track ALL resource operations I didn't specifiy any specific editing
> domain. Unfortunately my listener implementation didn't receive any
> notifications while editing an ecore model.
>
An EContentAdapter is a more basic thing, but I'm sure that Christian
will comment on the ResourceSetListener aspect...
> My extension point in the plugin.xml:
>
> <extension
> id="at.ac.tuwien.big.motrack.operationListener"
> name="ModelOperationListener"
> point="org.eclipse.emf.transaction.listeners">
> <listener
> class="at.ac.tuwien.big.motrack.ModelOperationListener">
> </listener>
> </extension>
>
> Is there something wrong with my extension point configuration?
Did you check that an instance of your Listener is being created by
setting a breakpoint?
> Or is my
> approach completely wrong? Is there a better way to get notified of all
> model modifications?
>
It seems like a reasonable approach... I wonder what would happen if
100 different plugins all decide they want to listen to everything
that's going on?
> Thank you very much in advance!
>
> Philip Langer
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Listener for all EMF based models [message #424756 is a reply to message #424753] Tue, 04 November 2008 23:56 Go to previous messageGo to next message
Philip Langer is currently offline Philip LangerFriend
Messages: 31
Registered: July 2009
Member
First of all, thanks a lot for your fast reply!!

Please see below.

Am Tue, 04 Nov 2008 18:00:19 -0500 schrieb Ed Merks:

> Philip,
>
> Comments below.
>
> Philip Langer wrote:
>> Hello,
>>
>> Sorry, I'm quite new to writing plug-ins. So please be patient :)
>>
> Patient? I don't do patient. :-P

Thank you for your patience :-)

>> I'm currently trying to write a plug-in which tracks all operations on
>> EMF based resources (UML2 models, ecore models, ...) made by any editor
>> (tree editor, GMF based editors, ...).
>>
>> Therefore I tried to use a ResourceSetListener with the
>> org.eclipse.emf.transaction.listeners extension point. Because I want
>> to track ALL resource operations I didn't specifiy any specific editing
>> domain. Unfortunately my listener implementation didn't receive any
>> notifications while editing an ecore model.
>>
> An EContentAdapter is a more basic thing, but I'm sure that Christian
> will comment on the ResourceSetListener aspect...

Thank you for the EContentAdapter hint. I used this one before when I was
handling ecore files programmatically. But how can I use it within my
context? Is there a kind of "resource starts being edited-extension
point" which invokes my class where I can register the adapter to the
resource in question?

>> My extension point in the plugin.xml:
>>
>> <extension
>> id="at.ac.tuwien.big.motrack.operationListener"
>> name="ModelOperationListener"
>> point="org.eclipse.emf.transaction.listeners"> <listener
>> class="at.ac.tuwien.big.motrack.ModelOperationListener">
>> </listener>
>> </extension>
>>
>> Is there something wrong with my extension point configuration?
> Did you check that an instance of your Listener is being created by
> setting a breakpoint?

Yes I already checked that. I set a breakpoint within the default
constructor. But unfortunately it didn't stop there in debug mode. So it
seems that the listener class isn't even instantiated. But, I have no
idea why!?! Do you need any specific file to give me a hint?

>> Or is my
>> approach completely wrong? Is there a better way to get notified of all
>> model modifications?
>>
> It seems like a reasonable approach... I wonder what would happen if
> 100 different plugins all decide they want to listen to everything
> that's going on?

You are absolutely right! I'm just doing my first steps here :-) I also
thought about reading the command history as soon as the resource is
persisted. Then I should be able to gather the same information without
listening directly, am I not? But how would I accomplish that? What
extension should I use to get to the specific command history? Sorry, I'm
a real eclipse plug-in beginner :-(

>> Thank you very much in advance!

Thanks again! I'm very grateful!

>>
>> Philip Langer
>>
Re: Listener for all EMF based models [message #424759 is a reply to message #424750] Wed, 05 November 2008 03:00 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: cdamus.zeligsoft.com

Hi, Philip,

The ResourceSetListener is attached to TransactionalEditingDomains. The
EMF-generated tree editors do not use transactions; they create regular
EditingDomains. GMF-generated editors do use the TED, so I would expect
your listener to be created in that context.

Were you editing an Ecore model in, e.g., the graphical EcoreTools
editor? That should cause your listener to be attached.

Note that, in the 1.3 branch, your listener can now be notified when it
is attached to or detached from an editing domain, by implementing the
ResourceSetListener.Internal interface (the ResourceSetListenerImpl and
its subclasses implement this by default).

HTH,

Christian

Philip Langer wrote:
> Hello,
>
> Sorry, I'm quite new to writing plug-ins. So please be patient :)
>
> I'm currently trying to write a plug-in which tracks all operations on
> EMF based resources (UML2 models, ecore models, ...) made by any editor
> (tree editor, GMF based editors, ...).
>
> Therefore I tried to use a ResourceSetListener with the
> org.eclipse.emf.transaction.listeners extension point. Because I want to
> track ALL resource operations I didn't specifiy any specific editing
> domain. Unfortunately my listener implementation didn't receive any
> notifications while editing an ecore model.
>
> My extension point in the plugin.xml:
>
> <extension
> id="at.ac.tuwien.big.motrack.operationListener"
> name="ModelOperationListener"
> point="org.eclipse.emf.transaction.listeners">
> <listener
> class="at.ac.tuwien.big.motrack.ModelOperationListener">
> </listener>
> </extension>
>
> Is there something wrong with my extension point configuration? Or is my
> approach completely wrong? Is there a better way to get notified of all
> model modifications?
>
> Thank you very much in advance!
>
> Philip Langer
Re: Listener for all EMF based models [message #424774 is a reply to message #424759] Wed, 05 November 2008 10:04 Go to previous messageGo to next message
Philip Langer is currently offline Philip LangerFriend
Messages: 31
Registered: July 2009
Member
Hi Christian,

thank you for your reply! Please see below!

Am Tue, 04 Nov 2008 22:00:30 -0500 schrieb Christian W. Damus:

> The ResourceSetListener is attached to TransactionalEditingDomains. The
> EMF-generated tree editors do not use transactions; they create regular
> EditingDomains. GMF-generated editors do use the TED, so I would expect
> your listener to be created in that context.

I didn't know that I can only attach a ResourceSetListener to GMF-based
editors. I always tested my listener with the sample ecore tree editor.

>
> Were you editing an Ecore model in, e.g., the graphical EcoreTools
> editor? That should cause your listener to be attached.

Unfortunately it neither is listening when i use the Ecore Diagram
Editor. I initialized the diagram file from my ecore model and opened it
with the diagram editor, edited it and no breakpoint (constructor of
listener, resourceSetChanged()) was passed in debug mode. Have you got
any ideas what could be wrong? Please have a look at my artefacts below.

Is there another way to track the changes in EMF based models, even if
they are edited in e.g. the sample tree editor? Reading the command
history, or as Ed said, using the EContentAdapter? Which extension point
should I use then?

Thank you very much for your help!

Philip Langer


-- my code --

My manifest.mf:

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Motrack Plug-in
Bundle-SymbolicName: at.ac.tuwien.big.motrack; singleton:=true
Bundle-Version: 1.0.0
Bundle-Activator: at.ac.tuwien.big.motrack.Activator
Bundle-Vendor: at.ac.tuwien.big
Require-Bundle: org.eclipse.ui,
org.eclipse.core.runtime,
org.eclipse.core.resources,
org.eclipse.emf;bundle-version="2.4.0",
org.eclipse.emf.compare;bundle-version="0.8.1",
org.eclipse.emf.transaction;bundle-version="1.2.1"
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Bundle-ActivationPolicy: lazy

My extension:

<extension
id="at.ac.tuwien.big.motrack.operationListener"
name="ModelOperationListener"
point="org.eclipse.emf.transaction.listeners">
<listener
class="at.ac.tuwien.big.motrack.ModelOperationListener">
</listener>
</extension>

My listener:

public class ModelOperationListener extends ResourceSetListenerImpl
implements ResourceSetListener {

public ModelOperationListener() {
System.out.println("ModelOperationListener is
instantiated");
}

@Override
public void resourceSetChanged(ResourceSetChangeEvent event) {
System.out.println("Received change event:" +
event.toString());
super.resourceSetChanged(event);
}

@Override
public Command transactionAboutToCommit(ResourceSetChangeEvent
event)
throws RollbackException {
System.out.println("Received pre change event:" +
event.toString());
return super.transactionAboutToCommit(event);
}
}
Re: Listener for all EMF based models [message #424793 is a reply to message #424774] Wed, 05 November 2008 14:13 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: cdamus.zeligsoft.com

Hi, Philip,

Your ResourceSetListener will only be added to
TransactionalEditingDomain instances that are registered in the
TransactionalEditingDomain.Registry. Domains can be registered on an
extension point or in code. Perhaps the EcoreTools editor does neither?

I would suggest debugging the initialization of the EcoreTools editor's
editing domain from the point of its construction to see whether it is
registered.

GMF is only one example of a client of the EMF Transaction API that I
happen to know registers its editing domains. It is by no means the
only one.

I am surprised that you would be able to test your editor with the Ecore
tree editor, because it does not use a TransactionalEditingDomain.

Any Eclipse EditorPart that uses an EditingDomain of some kind
(transactional or not) should provide an IEditingDomainProvider adapter
(via IAdaptable::getAdapter(Class) method), and the EditingDomain thus
obtained provides a ResourceSet to which you can attach an
EContentAdapter. Add a part-listener to the workbench to track the
creation of editor parts, and you should be able to add your listener to
any EMF-based editor. Note that I have never tried this ...

HTH

Christian

Philip Langer wrote:
> Hi Christian,
>
> thank you for your reply! Please see below!
>
> Am Tue, 04 Nov 2008 22:00:30 -0500 schrieb Christian W. Damus:
>
>> The ResourceSetListener is attached to TransactionalEditingDomains. The
>> EMF-generated tree editors do not use transactions; they create regular
>> EditingDomains. GMF-generated editors do use the TED, so I would expect
>> your listener to be created in that context.
>
> I didn't know that I can only attach a ResourceSetListener to GMF-based
> editors. I always tested my listener with the sample ecore tree editor.
>
>> Were you editing an Ecore model in, e.g., the graphical EcoreTools
>> editor? That should cause your listener to be attached.
>
> Unfortunately it neither is listening when i use the Ecore Diagram
> Editor. I initialized the diagram file from my ecore model and opened it
> with the diagram editor, edited it and no breakpoint (constructor of
> listener, resourceSetChanged()) was passed in debug mode. Have you got
> any ideas what could be wrong? Please have a look at my artefacts below.
>
> Is there another way to track the changes in EMF based models, even if
> they are edited in e.g. the sample tree editor? Reading the command
> history, or as Ed said, using the EContentAdapter? Which extension point
> should I use then?
>
> Thank you very much for your help!
>
> Philip Langer
>
>
> -- my code --
>
> My manifest.mf:
>
> Manifest-Version: 1.0
> Bundle-ManifestVersion: 2
> Bundle-Name: Motrack Plug-in
> Bundle-SymbolicName: at.ac.tuwien.big.motrack; singleton:=true
> Bundle-Version: 1.0.0
> Bundle-Activator: at.ac.tuwien.big.motrack.Activator
> Bundle-Vendor: at.ac.tuwien.big
> Require-Bundle: org.eclipse.ui,
> org.eclipse.core.runtime,
> org.eclipse.core.resources,
> org.eclipse.emf;bundle-version="2.4.0",
> org.eclipse.emf.compare;bundle-version="0.8.1",
> org.eclipse.emf.transaction;bundle-version="1.2.1"
> Bundle-RequiredExecutionEnvironment: JavaSE-1.6
> Bundle-ActivationPolicy: lazy
>
> My extension:
>
> <extension
> id="at.ac.tuwien.big.motrack.operationListener"
> name="ModelOperationListener"
> point="org.eclipse.emf.transaction.listeners">
> <listener
> class="at.ac.tuwien.big.motrack.ModelOperationListener">
> </listener>
> </extension>
>
> My listener:
>
> public class ModelOperationListener extends ResourceSetListenerImpl
> implements ResourceSetListener {
>
> public ModelOperationListener() {
> System.out.println("ModelOperationListener is
> instantiated");
> }
>
> @Override
> public void resourceSetChanged(ResourceSetChangeEvent event) {
> System.out.println("Received change event:" +
> event.toString());
> super.resourceSetChanged(event);
> }
>
> @Override
> public Command transactionAboutToCommit(ResourceSetChangeEvent
> event)
> throws RollbackException {
> System.out.println("Received pre change event:" +
> event.toString());
> return super.transactionAboutToCommit(event);
> }
> }
Re: Listener for all EMF based models [message #424827 is a reply to message #424793] Thu, 06 November 2008 11:02 Go to previous message
Philip Langer is currently offline Philip LangerFriend
Messages: 31
Registered: July 2009
Member
Hi Christian,

I will try out the EContentAdapter/EditorPart Extension approach!

Thank you very much!

Regards,

Philip

Am Wed, 05 Nov 2008 09:13:36 -0500 schrieb Christian W. Damus:

> Hi, Philip,
>
> Your ResourceSetListener will only be added to
> TransactionalEditingDomain instances that are registered in the
> TransactionalEditingDomain.Registry. Domains can be registered on an
> extension point or in code. Perhaps the EcoreTools editor does neither?
>
> I would suggest debugging the initialization of the EcoreTools editor's
> editing domain from the point of its construction to see whether it is
> registered.
>
> GMF is only one example of a client of the EMF Transaction API that I
> happen to know registers its editing domains. It is by no means the
> only one.
>
> I am surprised that you would be able to test your editor with the Ecore
> tree editor, because it does not use a TransactionalEditingDomain.
>
> Any Eclipse EditorPart that uses an EditingDomain of some kind
> (transactional or not) should provide an IEditingDomainProvider adapter
> (via IAdaptable::getAdapter(Class) method), and the EditingDomain thus
> obtained provides a ResourceSet to which you can attach an
> EContentAdapter. Add a part-listener to the workbench to track the
> creation of editor parts, and you should be able to add your listener to
> any EMF-based editor. Note that I have never tried this ...
>
> HTH
>
> Christian
>
> Philip Langer wrote:
>> Hi Christian,
>>
>> thank you for your reply! Please see below!
>>
>> Am Tue, 04 Nov 2008 22:00:30 -0500 schrieb Christian W. Damus:
>>
>>> The ResourceSetListener is attached to TransactionalEditingDomains.
>>> The EMF-generated tree editors do not use transactions; they create
>>> regular EditingDomains. GMF-generated editors do use the TED, so I
>>> would expect your listener to be created in that context.
>>
>> I didn't know that I can only attach a ResourceSetListener to GMF-based
>> editors. I always tested my listener with the sample ecore tree editor.
>>
>>> Were you editing an Ecore model in, e.g., the graphical EcoreTools
>>> editor? That should cause your listener to be attached.
>>
>> Unfortunately it neither is listening when i use the Ecore Diagram
>> Editor. I initialized the diagram file from my ecore model and opened
>> it with the diagram editor, edited it and no breakpoint (constructor of
>> listener, resourceSetChanged()) was passed in debug mode. Have you got
>> any ideas what could be wrong? Please have a look at my artefacts
>> below.
>>
>> Is there another way to track the changes in EMF based models, even if
>> they are edited in e.g. the sample tree editor? Reading the command
>> history, or as Ed said, using the EContentAdapter? Which extension
>> point should I use then?
>>
>> Thank you very much for your help!
>>
>> Philip Langer
>>
>>
>> -- my code --
>>
>> My manifest.mf:
>>
>> Manifest-Version: 1.0
>> Bundle-ManifestVersion: 2
>> Bundle-Name: Motrack Plug-in
>> Bundle-SymbolicName: at.ac.tuwien.big.motrack; singleton:=true
>> Bundle-Version: 1.0.0
>> Bundle-Activator: at.ac.tuwien.big.motrack.Activator Bundle-Vendor:
>> at.ac.tuwien.big
>> Require-Bundle: org.eclipse.ui,
>> org.eclipse.core.runtime,
>> org.eclipse.core.resources,
>> org.eclipse.emf;bundle-version="2.4.0",
>> org.eclipse.emf.compare;bundle-version="0.8.1",
>> org.eclipse.emf.transaction;bundle-version="1.2.1"
>> Bundle-RequiredExecutionEnvironment: JavaSE-1.6
>> Bundle-ActivationPolicy: lazy
>>
>> My extension:
>>
>> <extension
>> id="at.ac.tuwien.big.motrack.operationListener"
>> name="ModelOperationListener"
>> point="org.eclipse.emf.transaction.listeners">
>> <listener
>> class="at.ac.tuwien.big.motrack.ModelOperationListener">
>> </listener>
>> </extension>
>>
>> My listener:
>>
>> public class ModelOperationListener extends ResourceSetListenerImpl
>> implements ResourceSetListener {
>>
>> public ModelOperationListener() {
>> System.out.println("ModelOperationListener is
>> instantiated");
>> }
>>
>> @Override
>> public void resourceSetChanged(ResourceSetChangeEvent event) {
>> System.out.println("Received change event:" +
>> event.toString());
>> super.resourceSetChanged(event);
>> }
>>
>> @Override
>> public Command transactionAboutToCommit(ResourceSetChangeEvent
>> event)
>> throws RollbackException {
>> System.out.println("Received pre change event:" +
>> event.toString());
>> return super.transactionAboutToCommit(event);
>> }
>> }
Previous Topic:What is the org.eclipse.emf.java example?
Next Topic:hasXxx() instead of isXxx()
Goto Forum:
  


Current Time: Thu Apr 25 10:12:02 GMT 2024

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

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

Back to the top