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 |
Vincent De Bry 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 #1277205 is a reply to message #1277161] |
Tue, 25 March 2014 17:01 |
Ed Merks 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 #1277236 is a reply to message #1277216] |
Tue, 25 March 2014 18:04 |
Ed Merks 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 #1277830 is a reply to message #1277247] |
Wed, 26 March 2014 14:17 |
Ed Merks 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 |
Vincent De Bry 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 |
Ed Merks 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 #1277905 is a reply to message #1277897] |
Wed, 26 March 2014 16:10 |
Ed Merks 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/
|
|
| | | |
Goto Forum:
Current Time: Thu Sep 19 06:45:05 GMT 2024
Powered by FUDForum. Page generated in 0.04381 seconds
|