Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » Diagram view doesn't display new edges after adding an edge programmatically
Diagram view doesn't display new edges after adding an edge programmatically [message #639235] Mon, 15 November 2010 17:20 Go to next message
Eclipse UserFriend
Originally posted by: Grit.Dudeck.gmx.net

Hello,

I have the following problem:

I want to modify models programmatically using the EMF reflective API.
The models are opened in a GMF-based editor and the changes are applied
within AbstractEMFOperations using the related
TransactionalEditingDomain. All works fine and the changes are displayed
automatically in the diagram view. But when adding a new connection to
the model and afterward adding the corresponding edge to the .notation
model, the diagram view is not refreshed. When I close and reopen the
model with the editor, the edges are displayed...

Is there any solution?

Thanks
Grit
Re: Diagram view doesn't display new edges after adding an edge programmatically [message #639246 is a reply to message #639235] Mon, 15 November 2010 17:58 Go to previous messageGo to next message
Asiri Rathnayake is currently offline Asiri RathnayakeFriend
Messages: 80
Registered: September 2010
Location: Colombo, Sri Lanka.
Member
Eclipse User wrote on Mon, 15 November 2010 12:20
Originally posted by: Grit.Dudeck.gmx.net

But when adding a new connection to the model and afterward adding the corresponding edge to the .notation model, the diagram view is not refreshed. When I close and reopen the model with the editor, the edges are displayed...

I believe you are trying to accomplish the task in two steps, create the model element corresponding to the connection and then update the notational model. Did you try using CreateConnectionViewAndElementRequest instead? this request encapsulates both of the tasks AFAIU, corresponding javadoc provides a wealth of information on how to use it (and googling will definitely find you sample code).

Hope this helps.

- Asiri

[Updated on: Mon, 15 November 2010 17:59]

Report message to a moderator

Re: Diagram view doesn't display new edges after adding an edge programmatically [message #639272 is a reply to message #639246] Mon, 15 November 2010 19:55 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: Grit.Dudeck.gmx.net

Am 15.11.2010 18:58, schrieb Asiri Rathnayake:
> Eclipse User wrote on Mon, 15 November 2010 12:20
>> Originally posted by: Grit.Dudeck.gmx.net
>>
>> But when adding a new connection to the model and afterward adding the
>> corresponding edge to the .notation model, the diagram view is not
>> refreshed. When I close and reopen the model with the editor, the
>> edges are displayed...
>
>
> I believe you are trying to accomplish the task in two steps, create the
> model element corresponding to the connection and then update the
> notational model. Did you try using
> CreateConnectionViewAndElementRequest instead? this request encapsulates
> both of the tasks AFAIU, corresponding javadoc provides a wealth of
> information on how to use it (and googling will definitely find you
> sample code).
>
> Hope this helps.
>
> - Asiri
>

But I don't want to use any GMF code but the reflective EMF API to
modify the model/notational model. When I want to add an element in the
model/notational model, an AbstractEMFOperation with the following code
is excecuted:

EList<Object> oldList = eObject.eGet(feature);
oldList.add(position,newValue);

But I don't understand why the diagram view isn't refreshed
automatically after an edge has been added. It works only for nodes...

Regards, Grit
Re: Diagram view doesn't display new edges after adding an edge programmatically [message #639311 is a reply to message #639272] Tue, 16 November 2010 01:19 Go to previous messageGo to next message
Asiri Rathnayake is currently offline Asiri RathnayakeFriend
Messages: 80
Registered: September 2010
Location: Colombo, Sri Lanka.
Member
Hi,

Eclipse User wrote on Mon, 15 November 2010 14:55
Originally posted by: Grit.Dudeck.gmx.net

But I don't want to use any GMF code but the reflective EMF API to
modify the model/notational model. When I want to add an element in the
model/notational model, an AbstractEMFOperation with the following code
is excecuted:

EList<Object> oldList = eObject.eGet(feature);
oldList.add(position,newValue);

But I don't understand why the diagram view isn't refreshed
automatically after an edge has been added. It works only for nodes...

AFAIK directly invoking reflective EMF API does not send the necessary notifications to listeners; you need to use EMF command infrastructure instead. Can you employ a CompositeCommand and two nested CreateCommand(s) for creating the model object and the edge itself? I'll try to find a sample code snippet as time permits.

- Asiri
Re: Diagram view doesn't display new edges after adding an edge programmatically [message #639316 is a reply to message #639311] Tue, 16 November 2010 01:48 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33146
Registered: July 2009
Senior Member
Asiri,

Comments below.

Asiri Rathnayake wrote:
> Hi,
>
> Eclipse User wrote on Mon, 15 November 2010 14:55
>> Originally posted by: Grit.Dudeck.gmx.net
>>
>> But I don't want to use any GMF code but the reflective EMF API to
>> modify the model/notational model. When I want to add an element in
>> the model/notational model, an AbstractEMFOperation with the
>> following code is excecuted:
>>
>> EList<Object> oldList = eObject.eGet(feature);
>> oldList.add(position,newValue);
>>
>> But I don't understand why the diagram view isn't refreshed
>> automatically after an edge has been added. It works only for nodes...
>
> AFAIK directly invoking reflective EMF API does not send the necessary
> notifications to listeners; you need to use EMF command infrastructure
> instead.
No, the model directly produces the notifications. And GMF uses
infrastructure where such changes can be recorded and then undone when
necessary.
> Can you employ a CompositeCommand and two nested CreateCommand(s) for
> creating the model object and the edge itself? I'll try to find a
> sample code snippet as time permits.
> - Asiri


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Diagram view doesn't display new edges after adding an edge programmatically [message #639323 is a reply to message #639316] Tue, 16 November 2010 05:13 Go to previous messageGo to next message
Asiri Rathnayake is currently offline Asiri RathnayakeFriend
Messages: 80
Registered: September 2010
Location: Colombo, Sri Lanka.
Member
Hi Ed,

Ed Merks wrote on Mon, 15 November 2010 20:48
Asiri,

> AFAIK directly invoking reflective EMF API does not send the necessary
> notifications to listeners; you need to use EMF command infrastructure
> instead.
No, the model directly produces the notifications. And GMF uses
infrastructure where such changes can be recorded and then undone when
necessary.

Many thanks for clearing that Smile and I believe you meant to write "And GMF uses command infrastructure..." (?)

- Asiri
Re: Diagram view doesn't display new edges after adding an edge programmatically [message #639417 is a reply to message #639323] Tue, 16 November 2010 13:24 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33146
Registered: July 2009
Senior Member
Asiri,

Yes, though the infrastructure also refers to things as operations
because it deals more generally with issues such as keeping reads and
writes exclusive in a threaded application...


Asiri Rathnayake wrote:
> Hi Ed,
>
> Ed Merks wrote on Mon, 15 November 2010 20:48
>> Asiri,
>>
>> > AFAIK directly invoking reflective EMF API does not send the
>> necessary > notifications to listeners; you need to use EMF command
>> infrastructure > instead. No, the model directly produces the
>> notifications. And GMF uses infrastructure where such changes can be
>> recorded and then undone when necessary.
>
> Many thanks for clearing that :) and I believe you meant to write "And
> GMF uses command infrastructure..." (?)
>
> - Asiri


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Diagram view doesn't display new edges after adding an edge programmatically [message #639431 is a reply to message #639417] Tue, 16 November 2010 14:17 Go to previous messageGo to next message
Asiri Rathnayake is currently offline Asiri RathnayakeFriend
Messages: 80
Registered: September 2010
Location: Colombo, Sri Lanka.
Member
Hi Ed,

Ed Merks wrote on Tue, 16 November 2010 08:24
Asiri,

Yes, though the infrastructure also refers to things as operations
because it deals more generally with issues such as keeping reads and
writes exclusive in a threaded application...

Thanks a lot for this explanation Smile

@Grit

Sorry if I have stolen your thread, I hope you were able to find a solution to your problem by now(?).

- Asiri

Re: Diagram view doesn't display new edges after adding an edge programmatically [message #639576 is a reply to message #639431] Tue, 16 November 2010 23:58 Go to previous messageGo to next message
Grit Dudeck is currently offline Grit DudeckFriend
Messages: 4
Registered: November 2010
Junior Member
Hi Asiri,

no matter... Wink But no, I didn't solve the problem. I think, maybe it is a GMF bug, because the problem occurs only when adding edges to the notational model.

Grit
Re: Diagram view doesn't display new edges after adding an edge programmatically [message #639597 is a reply to message #639272] Wed, 17 November 2010 06:44 Go to previous messageGo to next message
Asiri Rathnayake is currently offline Asiri RathnayakeFriend
Messages: 80
Registered: September 2010
Location: Colombo, Sri Lanka.
Member
Hi Grit,

Eclipse User wrote on Mon, 15 November 2010 14:55
Originally posted by: Grit.Dudeck.gmx.net

EList<Object> oldList = eObject.eGet(feature);
oldList.add(position,newValue);

But I don't understand why the diagram view isn't refreshed
automatically after an edge has been added. It works only for nodes...

If I understand your code correctly, here you are only updating your business model (adding a connection model object into your business model). How / where do you update the notational model? AFAIU if you only update the business model, your diagram will only be synchronized with it once you close and re-open your diagram file. Is it possible for you to create your edge using the ViewService as below (?):

View sourceView = ...  // Source view (notational)
View targetView = ... // Target view (notational)
EObject connectionObj = ... // Business model object corresponding to your connection.
String connectionType = YourPackageElementTypes.<link_type>
preferenceHint = containerEditPart.getDiagramPreferencesHint();
ViewService.createEdge(sourceView, targetView, connectionObj, connectionType, preferencesHint)

Hope this helps.

- Asiri

[Updated on: Wed, 17 November 2010 06:45]

Report message to a moderator

Re: Diagram view doesn't display new edges after adding an edge programmatically [message #639629 is a reply to message #639597] Wed, 17 November 2010 09:06 Go to previous messageGo to next message
Grit Dudeck is currently offline Grit DudeckFriend
Messages: 4
Registered: November 2010
Junior Member
Hi Asiri,

Am 17.11.2010 07:44, schrieb Asiri Rathnayake:
> Hi Grit,
>
> Eclipse User wrote on Mon, 15 November 2010 14:55
>> Originally posted by: Grit.Dudeck.gmx.net
>>
>> EList<Object> oldList = eObject.eGet(feature);
>> oldList.add(position,newValue);
>>
>> But I don't understand why the diagram view isn't refreshed
>> automatically after an edge has been added. It works only for nodes...
>
>
> If I understand your code correctly, here you are only updating your
> business model (adding a connection model object into your business
> model). How / where do you update the notational model?

The scenario is the following:

I record changes made to a model, which is modified in a GMF-based
editor. Than, these change are applied to another model. This means, if
I add an edge to the diagram via drag and drop, a notification is
recorded (an Edge object is added to the feature 'edges' for example).
So, with the code above, the edge object is added. If the edge is
created via the palette, I get also a notification that a connection was
added to the business-model. Because the notifications are processed
step-by-step, the connection is added to the business-model first and
afterward the corresponding edge is added to the notational model (with
the code above).

I do this procedure for each change and the diagram view for the updated
model is always refreshed automatically except for edges...

> AFAIU if you
> only update the business model, your diagram will only be synchronized
> with it once you close and re-open your diagram file. Is it possible for
> you to create your edge using the ViewService as below (?):
>
>
> View sourceView = ... // Source view (notational)
> View targetView = ... // Target view (notational)
> EObject connectionObj = ... // Business model object corresponding to
> your connection.
> String connectionType = YourPackageElementTypes.<link_type>
> preferenceHint = containerEditPart.getDiagramPreferencesHint();
> ViewService.createEdge(sourceView, targetView, connectionObj,
> connectionType, preferencesHint)
>
> Hope this helps.
>
> - Asiri

Grit
Re: Diagram view doesn't display new edges after adding an edge programmatically [message #639633 is a reply to message #639629] Wed, 17 November 2010 09:58 Go to previous messageGo to next message
Asiri Rathnayake is currently offline Asiri RathnayakeFriend
Messages: 80
Registered: September 2010
Location: Colombo, Sri Lanka.
Member
Hi Grit,

Grit Dudeck wrote on Wed, 17 November 2010 04:06

The scenario is the following:

I record changes made to a model, which is modified in a GMF-based
editor. Than, these change are applied to another model. This means, if
I add an edge to the diagram via drag and drop, a notification is
recorded (an Edge object is added to the feature 'edges' for example).
So, with the code above, the edge object is added. If the edge is
created via the palette, I get also a notification that a connection was
added to the business-model. Because the notifications are processed
step-by-step, the connection is added to the business-model first and
afterward the corresponding edge is added to the notational model (with
the code above).

I do this procedure for each change and the diagram view for the updated
model is always refreshed automatically except for edges...

I'm afraid I'm unable to grasp / understand your use-case Sad Let's hope someone else can help you out Smile

- Asiri
Re: Diagram view doesn't display new edges after adding an edge programmatically [message #754184 is a reply to message #639633] Tue, 01 November 2011 09:09 Go to previous message
J.Teutsch  is currently offline J.Teutsch Friend
Messages: 7
Registered: November 2010
Junior Member
Hi Grit,

I think your problem is the same like
http://www.eclipse.org/forums/index.php/m/691844/?srch=gmf+edge#msg_691844

so overriding
org.eclipse.gmf.runtime.diagram.ui.editparts.ShapeNodeEditPart.getModelSourceConnections() and ...TargetConnections is the solution
Previous Topic:Changes required in the generated code to add new Node in to the Palette
Next Topic:Update/Synchronize diagram after execute EMF operations
Goto Forum:
  


Current Time: Sat May 11 00:52:46 GMT 2024

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

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

Back to the top