Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » How to update an element parent's label in EMF Editor ?
How to update an element parent's label in EMF Editor ? [message #1277161] Tue, 25 March 2014 15:38 Go to next message
Vincent De Bry is currently offline Vincent De BryFriend
Messages: 55
Registered: May 2013
Member
Hi,

Based on a generated emf editor, I want to customize some labels. Especially, when I change the value of an element A1 attribute, I want that the label of the element A, parent of A1, changes.

In element's A1 ItemProvider, I have added the following line to the method "notifyChanged(Notification notification)":

fireNotifyChanged(new ViewerNotification(notification, ((ASLinkElement)notification.getNotifier()).eContainer(), false, true));

But the notifyChanged method of the element's A ItemProvider is not called.

Could someone give me a tip on the right way to do ?

Thanks.
Re: How to update an element parent's label in EMF Editor ? [message #1277169 is a reply to message #1277161] Tue, 25 March 2014 15:47 Go to previous messageGo to next message
Vincent De Bry is currently offline Vincent De BryFriend
Messages: 55
Registered: May 2013
Member
A detail: in debug in A1's ItemProvider, I see that the "changeNotifier" contains an element of type DelegatingWrapperItemProvider which owner is a FeatureMapEntryWrapperItemProvider.

As I has lots of issues with this kind of elements, I think my problem is linked; I I cannot figure out what to do to maake it work.
Thanks
Re: How to update an element parent's label in EMF Editor ? [message #1277205 is a reply to message #1277161] Tue, 25 March 2014 17:01 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33216
Registered: July 2009
Senior Member
Vincent,

Comments below.

On 25/03/2014 8:38 AM, Vincent De Bry wrote:
> Hi,
>
> Based on a generated emf editor, I want to customize some labels.
> Especially, when I change the value of an element A1 attribute, I want
> that the label of the element A, parent of A1, changes.
>
> In element's A1 ItemProvider, I have added the following line to the
> method "notifyChanged(Notification notification)":
>
> fireNotifyChanged(new ViewerNotification(notification,
> ((ASLinkElement)notification.getNotifier()).eContainer(), false, true));
>
> But the notifyChanged method of the element's A ItemProvider is not
> called.
Because it listens to the EObject itself, but with the above you're
firing a notification to the things listening to the adapter factory itself.
>
> Could someone give me a tip on the right way to do ?
You had other questions that suggested there were wrappers involved, so
it's not clear if eContainer is what you need or perhaps better to be
using getParent on the item provider itself. Or perhaps you need
org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain.getWrapper(Object,
EditingDomain).
>
> Thanks.


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: How to update an element parent's label in EMF Editor ? [message #1277216 is a reply to message #1277205] Tue, 25 March 2014 17:21 Go to previous messageGo to next message
Vincent De Bry is currently offline Vincent De BryFriend
Messages: 55
Registered: May 2013
Member
Ed,

There is something I really do not figure out. If I define the following comparer and set it to the selectionViewer in the Editor's pages creation, I get the expecting behaviour for label update:

IElementComparer elementComparer = new IElementComparer() {
public boolean equals(Object a, Object b) {

Object comparableElementA = AdapterFactoryEditingDomain.unwrap(a);
Object comparableElementB = AdapterFactoryEditingDomain.unwrap(b);

return comparableElementA.equals(comparableElementB);
}

public int hashCode(Object element) {
Object comparableElement = AdapterFactoryEditingDomain.unwrap(element);
return comparableElement.hashCode();
}
};


But, in this case, if I create an element (which is actually a wrapper) whith a child, the contextual menu does not provide me with the "Delete" option...
So I think I have something wrong in my code, managing the wrappers, but I cannot figure out what.
Re: How to update an element parent's label in EMF Editor ? [message #1277236 is a reply to message #1277216] Tue, 25 March 2014 18:04 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33216
Registered: July 2009
Senior Member
Vincent,

Why do you need such a comparator? The generated editor doesn't give
you one by default so it's hard for me to comment about an
implementation of one...

On 25/03/2014 10:21 AM, Vincent De Bry wrote:
> Ed,
>
> There is something I really do not figure out. If I define the
> following comparer and set it to the selectionViewer in the Editor's
> pages creation, I get the expecting behaviour for label update:
>
> IElementComparer elementComparer = new IElementComparer() {
> public boolean equals(Object a, Object b) {
>
> Object comparableElementA =
> AdapterFactoryEditingDomain.unwrap(a);
> Object comparableElementB =
> AdapterFactoryEditingDomain.unwrap(b);
>
> return comparableElementA.equals(comparableElementB);
> }
>
> public int hashCode(Object element) {
> Object comparableElement =
> AdapterFactoryEditingDomain.unwrap(element);
> return comparableElement.hashCode();
> }
> };
>
>
> But, in this case, if I create an element (which is actually a
> wrapper) whith a child, the contextual menu does not provide me with
> the "Delete" option...
> So I think I have something wrong in my code, managing the wrappers,
> but I cannot figure out what.
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: How to update an element parent's label in EMF Editor ? [message #1277247 is a reply to message #1277236] Tue, 25 March 2014 18:28 Go to previous messageGo to next message
Vincent De Bry is currently offline Vincent De BryFriend
Messages: 55
Registered: May 2013
Member
Ed,

indeed, I should not need one. I just notice that I get the expected behaviour for the label update when I have one, and I don't understand why.

On the other hand, I have tried using getParent(), but obviously, I dont know how to use it: getParent(notification.getNotifier()) ? and what should I do with it ?
and the same for getWrapper... MoreHover, AdapterfactoryEditingDomain.getEditingdomainFor(notification.getNotifier()) returns null. I don't understand why Sad
Re: How to update an element parent's label in EMF Editor ? [message #1277830 is a reply to message #1277247] Wed, 26 March 2014 14:17 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33216
Registered: July 2009
Senior Member
Vincent,

Comments below.

On 25/03/2014 7:28 PM, Vincent De Bry wrote:
> Ed,
>
> indeed, I should not need one. I just notice that I get the expected
> behaviour for the label update when I have one, and I don't understand
> why.
The generated editors work fine without one...
>
> On the other hand, I have tried using getParent(), but obviously, I
> dont know how to use it: getParent(notification.getNotifier()) ?
Yes.
> and what should I do with it ?
Is that object different from the one you get from eContainer()?
> and the same for getWrapper... MoreHover,
> AdapterfactoryEditingDomain.getEditingdomainFor(notification.getNotifier())
> returns null. I don't understand why :(
Are you using the generated editor?


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: How to update an element parent's label in EMF Editor ? [message #1277844 is a reply to message #1277830] Wed, 26 March 2014 14:39 Go to previous messageGo to next message
Vincent De Bry is currently offline Vincent De BryFriend
Messages: 55
Registered: May 2013
Member
Hi Ed,

Yes, I am using the generated Editor.
Actually, I've reached my goal with the following statement:

Object parent = AdapterFactoryEditingDomain.getWrapper(getParent(notification.getNotifier()), editingDomain);
fireNotifyChanged(new ViewerNotification(notification, parent, false, true));

But in order to get the editingDomain, initialized in the editor, I've done something which seems not clean to me, as when in ItemProvider, I cannot access the editor instance to call getEditingDomain()... Is there a way to get is easily, when in an ItemProvider ?

Thanks

Re: How to update an element parent's label in EMF Editor ? [message #1277891 is a reply to message #1277844] Wed, 26 March 2014 15:53 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33216
Registered: July 2009
Senior Member
Vincent,

I would expect
org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain.getEditingDomainFor(Object)
to work given the notifier of the notification.


On 26/03/2014 3:39 PM, Vincent De Bry wrote:
> Hi Ed,
>
> Yes, I am using the generated Editor.
> Actually, I've reached my goal with the following statement:
>
> Object parent =
> AdapterFactoryEditingDomain.getWrapper(getParent(notification.getNotifier()),
> editingDomain);
> fireNotifyChanged(new ViewerNotification(notification, parent,
> false, true));
>
> But in order to get the editingDomain, initialized in the editor, I've
> done something which seems not clean to me, as when in ItemProvider, I
> cannot access the editor instance to call getEditingDomain()... Is
> there a way to get is easily, when in an ItemProvider ?
>
> Thanks
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: How to update an element parent's label in EMF Editor ? [message #1277897 is a reply to message #1277891] Wed, 26 March 2014 16:00 Go to previous messageGo to next message
Vincent De Bry is currently offline Vincent De BryFriend
Messages: 55
Registered: May 2013
Member
Actually not, AdapterFactoryEditingDomain.getEditingDomainFor(notification.getNotifier()) returns null.

Anyway, as told, I have reached my goal, accessing the editingDomain as I could. It's good for me.
Thank you very much for your support.
Re: How to update an element parent's label in EMF Editor ? [message #1277905 is a reply to message #1277897] Wed, 26 March 2014 16:10 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33216
Registered: July 2009
Senior Member
Vincent,

Comments below.

On 26/03/2014 5:00 PM, Vincent De Bry wrote:
> Actually not,
> AdapterFactoryEditingDomain.getEditingDomainFor(notification.getNotifier())
> returns null.
If you debug step through it, why does it return null? I assume you're
passing in an EObject and that it's in a resource in a resource set and
that the resource set provides access to the editing domain; that's how
generated editors normally work (and if it's not working, I'd be
concerned that your properties view doesn't work properly either, i.e.,
doesn't produce undoable changes).
>
> Anyway, as told, I have reached my goal, accessing the editingDomain
> as I could.
How did you get it?
> It's good for me.
> Thank you very much for your support.


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: How to update an element parent's label in EMF Editor ? [message #1277914 is a reply to message #1277905] Wed, 26 March 2014 16:33 Go to previous messageGo to next message
Vincent De Bry is currently offline Vincent De BryFriend
Messages: 55
Registered: May 2013
Member
I have extended ItemProviderAdapter with a static value for editingDomain and setter called from the editor, on creation, to set this editing domain value. not very clean, but seems working...
Re: How to update an element parent's label in EMF Editor ? [message #1278238 is a reply to message #1277914] Thu, 27 March 2014 04:17 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33216
Registered: July 2009
Senior Member
Vincent,

Comments below.

On 26/03/2014 5:33 PM, Vincent De Bry wrote:
> I have extended ItemProviderAdapter with a static value for
> editingDomain and setter called from the editor, on creation, to set
> this editing domain value. not very clean, but seems working...
I doubt that will work when you have two editors. I'd suggest you use
the debugger to determine why what I suggested isn't working. I.e., I
expect
org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain.getEditingDomainFor(EObject)
would end up being called (because the notifier is most likely an
EObject), and I'd expect that method to find that the containing
resource set itself implements IEditingDomainProvider or that the
resource set has an adapter to implement that. Best you figure out
what's going on that this isn't working rather take an approach that
appears to work but is likely to cause you problems later when you test
further...


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: How to update an element parent's label in EMF Editor ? [message #1278338 is a reply to message #1278238] Thu, 27 March 2014 07:38 Go to previous message
Vincent De Bry is currently offline Vincent De BryFriend
Messages: 55
Registered: May 2013
Member
Hi Ed,

You are right, I should probably spent more time time find out wath is really wrong, but actually, I have contraints that force me to go ahead. One thing I did not mentionned: I am sharing an editing domain for all my editors, so that this really seems to work well with two or more editors.
I'll try to come back on this issue when I will have less pressure.
Thanks again.

Vincent
Previous Topic:EMF official maven repository?
Next Topic:[CDO] Recovering corrupt repos
Goto Forum:
  


Current Time: Thu Sep 19 06:45:05 GMT 2024

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

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

Back to the top