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 |
Eclipse User |
|
|
|
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 |
|
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 |
Eclipse User |
|
|
|
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 |
|
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 #639323 is a reply to message #639316] |
Tue, 16 November 2010 05:13 |
|
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
|
|
| | | |
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 |
|
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 |
Grit Dudeck 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 |
|
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 Let's hope someone else can help you out
- Asiri
|
|
| |
Goto Forum:
Current Time: Mon Jun 03 21:40:32 GMT 2024
Powered by FUDForum. Page generated in 0.04375 seconds
|