Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » EMF.Edit's ItemProviders ad-hoc behavior
EMF.Edit's ItemProviders ad-hoc behavior [message #494950] Tue, 03 November 2009 11:17 Go to next message
John S. is currently offline John S.Friend
Messages: 22
Registered: October 2009
Junior Member
Hello,

I would like to monitor the notifications so i put a println method for the console to display it, like:

public void notifyChanged(Notification notification) {
System.out.println("TableItemProvider: " + notification);
...
}

When I start a new Eclipse instance for the GMF editor to edit the model, I cannot always see that println method would run, because there is nothing on the console. It means that the notifyChanged does not run when for example I create a Table (this is a Model Element) on the diagram. Sometimes when I remove than re-add the Properties view of Eclipse windows and create a new diagram again, it seems good (a trick, but not sure it is the answer for the question).

I really don't know why I get notification in an ad-hoc way when something changed. The notifyChanged should be called every time when there is a change on the model caused by the diagram, but it doesn't seem to work in this way.

Regards, John S.
Re: EMF.Edit's ItemProviders ad-hoc behavior [message #494995 is a reply to message #494950] Tue, 03 November 2009 13:55 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
John,

Comments below.

John S. wrote:
> Hello,
>
> I would like to monitor the notifications so i put a println method
> for the console to display it, like:
>
> public void notifyChanged(Notification notification) {
> System.out.println("TableItemProvider: " + notification);
> ..
> }
Of course this only monitors changes for objects that have been viewed.
>
> When I start a new Eclipse instance for the GMF editor to edit the
> model, I cannot always see that println method would run, because
> there is nothing on the console. It means that the notifyChanged does
> not run when for example I create a Table (this is a Model Element) on
> the diagram.
I don't think GMF is using the item providers for the diagrams
themselves, only for the outline I think...
> Sometimes when I remove than re-add the Properties view of Eclipse
> windows and create a new diagram again, it seems good (a trick, but
> not sure it is the answer for the question).
> I really don't know why I get notification in an ad-hoc way when
> something changed. The notifyChanged should be called every time when
> there is a change on the model caused by the diagram, but it doesn't
> seem to work in this way.
If you want to consistently monitor all changes, regardless of whether
the objects have been viewed, use an EContentAdapter on the resource set.
>
> Regards, John S.


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: EMF.Edit's ItemProviders ad-hoc behavior [message #495071 is a reply to message #494995] Tue, 03 November 2009 17:18 Go to previous messageGo to next message
John S. is currently offline John S.Friend
Messages: 22
Registered: October 2009
Junior Member
Hello,

I tried to use an EContentAdapter on the resource set as it was suggested, but actually I do not know that it is the right class/method where I put the EcontentAdapter, because it has no effect:

public void notifyChanged(Notification notification) {
EObject eNotifier = (EObject) notification.getNotifier();
ResourceSet resourceSet = eNotifier.eResource().getResourceSet();
resourceSet.eAdapters().add(new EContentAdapter() {});
System.out.println("ClassItemProvider: " + notification);
...}

Perhaps EContentAdapter should be put somewhere else, like around (not inside) this notifyChanged or in anothod method what will call this notifyChanged method, but I could not figure it out.

So where is this EContentAdapter supposed to use?

Regards,
John
Re: EMF.Edit's ItemProviders ad-hoc behavior [message #495113 is a reply to message #495071] Tue, 03 November 2009 19:53 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
John,

Comments below.

John S. wrote:
> Hello,
>
> I tried to use an EContentAdapter on the resource set as it was
> suggested, but actually I do not know that it is the right
> class/method where I put the EcontentAdapter, because it has no effect:
>
> public void notifyChanged(Notification notification) {
> EObject eNotifier = (EObject) notification.getNotifier();
> ResourceSet resourceSet = eNotifier.eResource().getResourceSet();
> resourceSet.eAdapters().add(new EContentAdapter() {});
> System.out.println("ClassItemProvider: " + notification);
> ..}
>
It's important to call super because processing of notifications is how
it ensures it's attached to children being added and removed from
children being removed. If you attach it to a resource or resource set,
the notifier won't be an EObject.
> Perhaps EContentAdapter should be put somewhere else, like around
> (not inside) this notifyChanged or in anothod method what will call
> this notifyChanged method, but I could not figure it out.
You created it and add it to the eAdapters list of a Notifier.
>
> So where is this EContentAdapter supposed to use?
>
> Regards,
> John


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: EMF.Edit's ItemProviders ad-hoc behavior [message #495197 is a reply to message #495113] Wed, 04 November 2009 07:12 Go to previous messageGo to next message
John S. is currently offline John S.Friend
Messages: 22
Registered: October 2009
Junior Member
Hello,

>> If you want to consistently monitor all changes, regardless of whether
>> the objects have been viewed, use an EContentAdapter on the resource set.

My code looks like this in the itemprovider of a modelelement, but it still doesnt monitor all the time when i create this element with the GMF editor.

@Override
public void notifyChanged(Notification notification) {

EContentAdapter adapter = new EContentAdapter() {
@Override
public void notifyChanged(Notification notification) {
super.notifyChanged(notification);
System.out.println("Notfication received from the data model. Data model has changed!!!");
}
};
EObject eNotifier = (EObject) notification.getNotifier();
ResourceSet resourceSet =eNotifier.eResource().getResourceSet();
resourceSet .eAdapters().add(adapter);
...}


I do not know what is missing.

Best Regards
John
Re: EMF.Edit's ItemProviders ad-hoc behavior [message #495334 is a reply to message #495197] Wed, 04 November 2009 15:34 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
John,

Comments below.

John S. wrote:
> Hello,
>
>>> If you want to consistently monitor all changes, regardless of whether
>>> the objects have been viewed, use an EContentAdapter on the resource
>>> set.
>
> My code looks like this in the itemprovider of a modelelement, but it
> still doesnt monitor all the time when i create this element with the
> GMF editor.
>
> @Override
> public void notifyChanged(Notification notification) {
>
> EContentAdapter adapter = new EContentAdapter() {
> @Override
> public void notifyChanged(Notification notification) {
> super.notifyChanged(notification);
> System.out.println("Notfication received from the data
> model. Data model has changed!!!");
> }
> };
> EObject eNotifier = (EObject) notification.getNotifier();
> ResourceSet resourceSet =eNotifier.eResource().getResourceSet();
> resourceSet .eAdapters().add(adapter);
You add a new one each time you get a notification. That sounds more
than a little horrible and still leaves you with the problem of it not
being attached until the objects is viewed. You need to attach it once
when the editor is opened and the resource set is created.
> ..}
>
> I do not know what is missing.
>
> Best Regards
> John


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:eProxyURI as reference to the model
Next Topic:Loss of base type validation when restriction specified
Goto Forum:
  


Current Time: Wed Apr 24 16:03:59 GMT 2024

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

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

Back to the top