Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Over-riding EContentAdapter#addAdapter - side effects?
Over-riding EContentAdapter#addAdapter - side effects? [message #1807969] Thu, 13 June 2019 13:58 Go to next message
Phil Beauvoir is currently offline Phil BeauvoirFriend
Messages: 51
Registered: October 2012
Member
Hi,

I'm using an EContentAdapter, but as some EObjects have a very large containment tree it takes some time to add and remove the EContentAdapter. As I'm only interested in some types of containment object I improved things by only adapting to a certain child clas:

    private Adapter eAdapter = new EContentAdapter()  {
        @Override
        public void notifyChanged(Notification msg) {
            super.notifyChanged(msg);
            // Do some work
        }
        
        @Override
        protected void addAdapter(Notifier notifier) {
            if(notifier instanceof MyClass) {
                super.addAdapter(notifier);
            }
        };
    };


Effectively it is only adapting to one type (MyClass).

Are there any side-effects to doing this that I might have missed?

Thanks for any advice!
Re: Over-riding EContentAdapter#addAdapter - side effects? [message #1807970 is a reply to message #1807969] Thu, 13 June 2019 14:19 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 30679
Registered: July 2009
Senior Member
An EContentAdapter can be added to a ResourceSet or a Resource as well, so that looks disabled. Knowing thing about your model, I don't know that you only ever add it to a MyClass and I don't know that all MyClass instances are only reachable via other MyClass instances...
Re: Over-riding EContentAdapter#addAdapter - side effects? [message #1807973 is a reply to message #1807970] Thu, 13 June 2019 14:27 Go to previous messageGo to next message
Phil Beauvoir is currently offline Phil BeauvoirFriend
Messages: 51
Registered: October 2012
Member
Ed Merks wrote on Thu, 13 June 2019 14:19
An EContentAdapter can be added to a ResourceSet or a Resource as well, so that looks disabled. Knowing thing about your model, I don't know that you only ever add it to a MyClass and I don't know that all MyClass instances are only reachable via other MyClass instances...


This is a very specific usage and the EContentAdapter is only ever added to an EObject. The EObject may contain many thousands of child EObjects and I am only interested in Notifications from (1) the EObject itself and (2) direct child EObjects of type "MyClass" in this example.

This seems to work and I can't see any gotchas

Thanks for the response, I appreciate it.
Re: Over-riding EContentAdapter#addAdapter - side effects? [message #1807982 is a reply to message #1807973] Thu, 13 June 2019 15:49 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 6534
Registered: July 2009
Senior Member
Hi

It is your Adapter that you create and use for your purposes.

I would recommend making it a non-anonymous class so that MyEContentAdapter shows up in the debugger rather than ParentClass$1.

You might want to consider whether to implement isAdapterForType().

Since EContentAdapter does not implement isAdapterForType() there is a risk that there are EMF applications that do instanceof EContentAdapter and so might be fooled by your different MyEContentAdapter. Deriving your MyEContentAdapter direct from AdapterImpl with only those functionalities you want might be faster and safer.

Regards

Ed Willink
Re: Over-riding EContentAdapter#addAdapter - side effects? [message #1807985 is a reply to message #1807982] Thu, 13 June 2019 17:03 Go to previous messageGo to next message
Phil Beauvoir is currently offline Phil BeauvoirFriend
Messages: 51
Registered: October 2012
Member
Ed Willink wrote on Thu, 13 June 2019 15:49
Hi

It is your Adapter that you create and use for your purposes.

I would recommend making it a non-anonymous class so that MyEContentAdapter shows up in the debugger rather than ParentClass$1.

You might want to consider whether to implement isAdapterForType().

Since EContentAdapter does not implement isAdapterForType() there is a risk that there are EMF applications that do instanceof EContentAdapter and so might be fooled by your different MyEContentAdapter. Deriving your MyEContentAdapter direct from AdapterImpl with only those functionalities you want might be faster and safer.

Regards

Ed Willink



Thanks for the advice.

I'm not sure how I can derive from AdapterImpl given that I need to be notified by the target EObject and also a certain class of child object. Basically I need the functionality of EContentAdapter but not for all of the containment tree.

My EObject has an EList of child objects. I'd like the EContentAdapter to notify me when an object is added/removed/modified in the Elist, but not interested in other child objects.
Re: Over-riding EContentAdapter#addAdapter - side effects? [message #1807986 is a reply to message #1807985] Thu, 13 June 2019 17:30 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 6534
Registered: July 2009
Senior Member
Hi

EContentAdapter extends AdapterImpl so you just cut and paste as much of EContentAdapter as you need.

Regards

Ed Willink
Re: Over-riding EContentAdapter#addAdapter - side effects? [message #1807989 is a reply to message #1807986] Thu, 13 June 2019 19:06 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 30679
Registered: July 2009
Senior Member
This seems like bade advice to me. Copy and paste is mostly a really bad solution to almost any problem. Implementing isAdapterForType is kind of a must if an application wants to find its own adapter, so applications just using instanceof EContentAdapter are simply asking for trouble; Phil seems highly unlikely to encounter that in his use case.
Re: Over-riding EContentAdapter#addAdapter - side effects? [message #1807991 is a reply to message #1807989] Thu, 13 June 2019 19:13 Go to previous message
Phil Beauvoir is currently offline Phil BeauvoirFriend
Messages: 51
Registered: October 2012
Member
Thanks for the advice Ed(s).

I've looked deeper into EContentAdapter and my solution seems to be the best thing. Adapters are only added to immediate child objects that match the class I'm interested in.
Previous Topic:EMF Validation Framework and reading a file
Next Topic:Ecore validation
Goto Forum:
  


Current Time: Thu Dec 05 17:00:01 GMT 2019

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

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

Back to the top