creating a link the target is always null [message #156136] |
Wed, 17 October 2007 17:53 |
Eclipse User |
|
|
|
Originally posted by: bmoros.um.es
Hi all,
I am completely frustrated!! I have been trying to create a element and a
link programmatically for some weeks with no success. Although I have
followed the example provided in the GMF tutorial (MindMap example) I only
have been able to create the element but not the link.
I am trying to create them in the handleNotificationEvent-method of the
ElementEditPart since the new element has to be created when the current
element changes. Once the new element is created, it has to be linked to the
current one. The current element is the source (sourceViewAdapter) of the
DeferredCreateConnectionViewAndElementCommand, and the new element is the
target (targetViewAdapter) of the Command. Consequently, the command is
created as follows:
//Target of the link: the new created element
IAdaptable targetViewAdapter =
(IAdaptable)((List)elementRequest.getNewObject()).get(0);
// Source of the link: the current element
IAdaptable sourceViewAdapter = new EObjectAdapter((EObject)this.getModel());
ICommand createLinkCmd = new DeferredCreateConnectionViewAndElementCommand(
createLinkRequest,
sourceViewAdapter,
targetViewAdapter,
this.getViewer());
Debugging the code, I have realized that the execution of the
doExecuteWithResult-method, in the DeferredCreateConnectionViewAndElement
class, looks for the EditPart corresponding to the targetViewAdapter. The
targetViewAdapter is not a key of the EditPartRegistry (I guess the reason
is that the element has been already created and the registry has not been
updated yet) so the targetEditPart is always null. Then, the command is not
executed and the link is not created.
I do not understand why the creation works when the element and the link are
created in an Action but it does not work when they are created in a method
of an EditPart.
Can anybody explain it to me? can anybody give me a hint?
Best regards,
Bego
|
|
|
Re: creating a link the target is always null [message #156145 is a reply to message #156136] |
Wed, 17 October 2007 18:50 |
Eclipse User |
|
|
|
Originally posted by: trommas.yahoo.com
the targetEditPart is always null. Then, the command is not
> executed and the link is not created.
I had the same problem. I solved it by executing the command that
creates target first. Have you tired this?
Regards,
Tomas
|
|
|
|
Re: creating a link the target is always null [message #157391 is a reply to message #156136] |
Fri, 26 October 2007 20:05 |
Cherie Revells Messages: 299 Registered: July 2009 |
Senior Member |
|
|
Begoña,
The handleNotificationEvent() method of an editpart is not the correct
place to create a new element for the relationship. This element should
be created by the edithelpers as these are responsible for creating the
semantic elements.
Is your diagram canonical? If so, then if the element is created the
connection should be created automatically.
Regards,
Cherie
Begoña Moros wrote:
> Hi all,
>
> I am completely frustrated!! I have been trying to create a element and a
> link programmatically for some weeks with no success. Although I have
> followed the example provided in the GMF tutorial (MindMap example) I only
> have been able to create the element but not the link.
>
> I am trying to create them in the handleNotificationEvent-method of the
> ElementEditPart since the new element has to be created when the current
> element changes. Once the new element is created, it has to be linked to the
> current one. The current element is the source (sourceViewAdapter) of the
> DeferredCreateConnectionViewAndElementCommand, and the new element is the
> target (targetViewAdapter) of the Command. Consequently, the command is
> created as follows:
>
> //Target of the link: the new created element
> IAdaptable targetViewAdapter =
> (IAdaptable)((List)elementRequest.getNewObject()).get(0);
>
> // Source of the link: the current element
>
> IAdaptable sourceViewAdapter = new EObjectAdapter((EObject)this.getModel());
>
>
> ICommand createLinkCmd = new DeferredCreateConnectionViewAndElementCommand(
>
> createLinkRequest,
>
> sourceViewAdapter,
>
> targetViewAdapter,
>
> this.getViewer());
>
> Debugging the code, I have realized that the execution of the
> doExecuteWithResult-method, in the DeferredCreateConnectionViewAndElement
> class, looks for the EditPart corresponding to the targetViewAdapter. The
> targetViewAdapter is not a key of the EditPartRegistry (I guess the reason
> is that the element has been already created and the registry has not been
> updated yet) so the targetEditPart is always null. Then, the command is not
> executed and the link is not created.
>
> I do not understand why the creation works when the element and the link are
> created in an Action but it does not work when they are created in a method
> of an EditPart.
>
> Can anybody explain it to me? can anybody give me a hint?
>
> Best regards,
> Begoña
>
>
>
|
|
|
Re: creating a link the target is always null [message #157452 is a reply to message #157391] |
Sun, 28 October 2007 08:04 |
Eclipse User |
|
|
|
Originally posted by: bmoros.um.es
Cherie, thank you very much for your answers!!!
> The handleNotificationEvent() method of an editpart is not the correct
> place to create a new element for the relationship. This element should
> be created by the edithelpers as these are responsible for creating the
> semantic elements.
>
I will study about edithelpers, any good reference?
I am using the editors generated automatically by GMF from the ecore and I
am afraid I am still not in control of all the GMF/EMF features.
> Is your diagram canonical? If so, then if the element is created the
> connection should be created automatically.
>
I really do not know. Is the diagram of the generated GMF editors canonical?
The problem is that the connection is not always created when a node is
created. A node can be created by means of the palette tool or
programmatically under some circunstances. Only when the node is created
programmatically the connection has to be created too.
Regards,
Bego
|
|
|
Powered by
FUDForum. Page generated in 0.04103 seconds