Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Notifications Problem
Notifications Problem [message #425405] Tue, 25 November 2008 09:27 Go to next message
Emil is currently offline EmilFriend
Messages: 3
Registered: July 2009
Junior Member
Hello,

I'm using an EMF Model and want to show an object within a Treeview.

Therefor I've copied code out of the generated editor class
and put it into my viewer class. When initially setting the Treeviewer input that data is displayed well.

But there is a problem with notifications. The
AdapterFactoryContentProvider seems not to keep track of them. It might be because of missing adapters. that happens when I try to create an Object from a job and adding it to the model like followed:

MyObject obj = MyModelFactory.eINSTANCE.createMyObject();
obj.setAttribute(3);

GlobalEMFRootObject.Myadd(obj);

in Myadd I m calling:

if (eNotificationRequired())
eNotify(new ENotificationImpl(this, Notification.SET, MyModelPackage.OBJECT, null, obj));

therefor eNotificationRequired always returns
false. (There are no adapters).

What do I have to do in order to get model changes displayed in my Treeview?

My code in the TreeView class:
protected ComposedAdapterFactory adapterFactory;
..

treeViewer.setContentProvider(new AdapterFactoryContentProvider(adapterFactory));

treeViewer.setLabelProvider(new AdapterFactoryLabelProvider.FontAndColorProvider(adapterFact ory,treeViewer));
..

In the MyObjectItemProvider class I'm using the function @Override
public Collection<?> getChildren(Object object)

instead of getChildFeature

Please help
thanks
Re: Notifications Problem [message #425410 is a reply to message #425405] Tue, 25 November 2008 16:10 Go to previous messageGo to next message
Renat Zubairov is currently offline Renat ZubairovFriend
Messages: 30
Registered: July 2009
Member
Hello Emil,

The method eNotificationRequired returns false only because your object has
no listeners (adapters) therefore sending of notification is not reqired in
this case. Generally EMF models are subject for state of art optimization,
all possible java performace optimizations are done there, for example
notifications are not sent when it's not needed, or lists are created
lazily.

So, the classes inside the Edit plugin are extending EMFContentAdapter which
automatically attach itself to all objects that are accessible from starting
object via _containment_ relations. So first of all check that your relation
is containment, then check that you are adding your new object usual way,
i.e. by fetching the children collection and adding element to it, only in
this case EMFContentAdapter will know that collection was modified and will
attach itself to newly added object.

Also, it might be not a best idea to manipulate model objects directly, the
better way is to use Commands for that. The advantage of commands is that
your changes will be integrated with another user changes therefore will be
a subject of undo/redo actions and editor dirty indicator.

BR
Renat


On 25.11.08 10:27, in article
16793125.191227605270772.JavaMail.root@cp1.dzone.com, "Emil"
<e.daoura@hotmail.com> wrote:

> Hello,
>
> I'm using an EMF Model and want to show an object within a Treeview.
>
> Therefor I've copied code out of the generated editor class
> and put it into my viewer class. When initially setting the Treeviewer input
> that data is displayed well.
>
> But there is a problem with notifications. The
> AdapterFactoryContentProvider seems not to keep track of them. It might be
> because of missing adapters. that happens when I try to create an Object from
> a job and adding it to the model like followed:
>
> MyObject obj = MyModelFactory.eINSTANCE.createMyObject();
> obj.setAttribute(3);
>
> GlobalEMFRootObject.Myadd(obj);
>
> in Myadd I m calling:
>
> if (eNotificationRequired())
> eNotify(new ENotificationImpl(this, Notification.SET, MyModelPackage.OBJECT,
> null, obj));
>
> therefor eNotificationRequired always returns
> false. (There are no adapters).
>
> What do I have to do in order to get model changes displayed in my Treeview?
>
> My code in the TreeView class:
> protected ComposedAdapterFactory adapterFactory;
> .
>
>
> treeViewer.setContentProvider(new
> AdapterFactoryContentProvider(adapterFactory));
>
> treeViewer.setLabelProvider(new
> AdapterFactoryLabelProvider.FontAndColorProvider(adapterFact ory,treeViewer));
> .
>
>
> In the MyObjectItemProvider class I'm using the function @Override
> public Collection<?> getChildren(Object object)
>
> instead of getChildFeature
>
> Please help
> thanks
Re: Notifications Problem [message #425431 is a reply to message #425410] Wed, 26 November 2008 09:15 Go to previous messageGo to next message
Emil is currently offline EmilFriend
Messages: 3
Registered: July 2009
Junior Member
Hi Renat,

thanks for your Reply.

I m using maps. That means I m using collections of MapEntrys (Key, Object) and my Object that I need to add into the EMF, is an Object that has to be added into the Map. I don't know how the contentProvider actuates with maps!!!!

Using command is the best way but i cannot use it always due of some functionality requirement of my program.

How can I add an adapter (listener) to my object? I don't want to create my own adapter, i want to use the ObjectItemProvider as a provider of notification adapters.

I think, It has to be something like that:
object.eAdapter().add(xxxxxx) xxxxxx has to be something like objectItemproviderObject. how can i do that?
Re: Notifications Problem [message #425444 is a reply to message #425431] Wed, 26 November 2008 13:39 Go to previous messageGo to next message
Ed Merks is currently online Ed MerksFriend
Messages: 33139
Registered: July 2009
Senior Member
Emil,

Comments below.

Emil wrote:
> Hi Renat,
>
> thanks for your Reply.
>
> I m using maps. That means I m using collections of MapEntrys (Key, Object) and my Object that I need to add into the EMF, is an Object that has to be added into the Map. I don't know how the contentProvider actuates with maps!!!!
>
> Using command is the best way but i cannot use it always due of some functionality requirement of my program.
>
A ChangeCommand can be used to record the changes and make them undoable.
> How can I add an adapter (listener) to my object?
It seems to me if you are creating a new object, no one will know about
it until you attach it to some container object and that container
object, if it's being viewed somewhere, will already have an adapter
that will notify about the addition of the child.
> I don't want to create my own adapter, i want to use the ObjectItemProvider as a provider of notification adapters.
>
From what you describe though, it seems to me that it's not possible
for any view to notice the created of "obj".
> I think, It has to be something like that:
> object.eAdapter().add(xxxxxx) xxxxxx has to be something like objectItemproviderObject. how can i do that?
>
Normally adapters are added automatically as the objects are viewed,
i.e, as the label or content provider is asked to produce text of
children, but from what you've described I don't see how the new object
you created could affect any existing views...


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Notifications Problem [message #425483 is a reply to message #425405] Thu, 27 November 2008 08:37 Go to previous message
Emil is currently offline EmilFriend
Messages: 3
Registered: July 2009
Junior Member
thanks for the Reply,

I resolved the Problem.

I needed to add an adapter for my rootObject "TreeView.Input(rootObject)" like followed:

rootObject.eAdapter().add(MyEMFItemProviderAdapterFactory(). createRootObjectAdapter());

I have done it at the beginning, when i had to create the first RootObject of the EMF Model.

Then I needed to insert the following lines in the View class:

tableViewer.setContentProvider(new AdapterFactoryContentProvider(adapterFactory)
{
public void notifyChanged(Notification notification)
{
Display.getDefault().asyncExec(new Runnable()
{
@Override
public void run()
{
if (!treeViewer.getTree().isDisposed())
{
treeViewer.refresh(true);
}
}
});
}
});

now it works.
Previous Topic:XSD and EList
Next Topic:getting a feature from an URI
Goto Forum:
  


Current Time: Tue Apr 23 08:04:57 GMT 2024

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

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

Back to the top