Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » Issue when creating Edges programatically
Issue when creating Edges programatically [message #481584] Fri, 21 August 2009 16:30 Go to next message
Maxence VANBÉSIEN is currently offline Maxence VANBÉSIENFriend
Messages: 40
Registered: July 2009
Location: Lille, France
Member
Hello,

I am currently trying to generate programatically a diagram associated to
a semantic model and I have a question. (I know we should always let the
diagram generate itself, but I am working on a tool that migrate diagrams
from a tool based on GMF 1.0 to a tool based on GMF 2.x and in order to
have the nodes/edges keep the same positions, I have to do everything by
myself...)

(Sorry in advance if my query is a little bit verbose... And I will try to
be as clear as possible...)

My question is about the
org.eclipse.gmf.runtime.diagram.core.services.ViewService and the
XXXViewProvider class, generated with GMF...

Here is the context:

When I tried to create manually an Edge, I wanted to use the "public
static Edge createEdge(View source, View target, EObject eObject,String
type, PreferencesHint preferencesHint)" method of the ViewService class.

But this never worked, because this method creates an IAdapter using
"IAdaptable viewModel = (eObject != null) ? new EObjectAdapter(eObject):
null", and when the ViewService tries to resolve the ViewProvider
associated to the semantic hint of the semantic element, the Generated
"XXXViewProvider.provides(CreateEdgeViewOperation op)" method is called
and seems to wait for an IAdaptable object, "adapting" a IElementType
instance and not an EObject instance.

The consequence is that the
" XXXViewProvider.getSemanticElementType(op.getSemanticAdapter ()); " always
returns a null object, and the ViewProvider can never be used to generate
the wanted edge. (So the Edge I want to generate is always null...)

However, I saw that this kind of issue was managed while generating Nodes,
because the "XXXViewProvider.provides(CreateNodeViewOperation op)" method
relies on VisualIDs from the semantic object to determine if the
ViewProvider can be used for generating Views from this Semantic Object.

Temporarily, I had to modify the generated code to adapt the
"XXXViewProvider.provides(CreateEdgeViewOperation op)" and the
XXXViewProvider.createEdge(IAdaptable semanticAdapter, View containerView,
String semanticHint, int index, boolean persisted, PreferencesHint
preferencesHint)" to make them work the same way as the methods for nodes
creations. And now, it seems to work...

So my questions are:
- Is this normal that the provides() and createNode/Edge are coded in a
different way ? And if this is normal, could you tell me why ?
- If this is not normal, is the "workaround" I defined is something
clean, otherwise, how could I manage my Edge creation ?

I hope you manage to understand my problem and my explanations. I tried to
be as clear as possible without having to copy and paste lots of source
code. Of course, I can go further in details if needed, and provide my
source code if necessary.

Thanks anyway in advance, for the time you will spend on my request.

Best regards, and have a nice week end ;)

Maxence
Re: Issue when creating Edges programatically [message #481867 is a reply to message #481584] Mon, 24 August 2009 15:26 Go to previous messageGo to next message
Alexander Shatalin is currently offline Alexander ShatalinFriend
Messages: 2928
Registered: July 2009
Senior Member
Hello Maxence,

> So my questions are:
> - Is this normal that the provides() and createNode/Edge are coded in
> a different way ? And if this is normal, could you tell me why ?
It's just an implementation details. Probably you sre right telling these
two methods should work consistently.

> - If this is not normal, is the "workaround" I defined is something
> clean, otherwise, how could I manage my Edge creation ?
I think it's ok to modify generated code in a way you described. In addition
I can say that during edge creation proper IAdaptable instance (keeping ElementType
inside) will be created and used, so you can consider using different IAdaptable
implementation in your code.

-----------------
Alex Shatalin
Re: Issue when creating Edges programatically [message #482034 is a reply to message #481867] Tue, 25 August 2009 08:00 Go to previous messageGo to next message
Maxence VANBÉSIEN is currently offline Maxence VANBÉSIENFriend
Messages: 40
Registered: July 2009
Location: Lille, France
Member
Hello Alex,

Thus, I will continue with modified generated code.

Thanks for your answer and for the time to took to consider my issue.

Maxence
Re: Issue when creating Edges programatically [message #516316 is a reply to message #482034] Tue, 23 February 2010 15:24 Go to previous message
No real name is currently offline No real nameFriend
Messages: 1
Registered: February 2010
Junior Member
Hello Maxence,

I faced exact the same problem and solved it in kinda dirty manner like you but i'm not fully happy with that.

The aim was to show certain, invisible model elements from an emf on an gmf diagram editor. Adding nodes like described here worked fine, but creating the edges between them was hard, took me hours to figure out... I finally ended up with following code that added the connection:
final IElementType elementTypeCopy = XXXElementTypes.getElementType(TestRelationEditPart.VISUAL_ID);
CreateRelationshipRequest req = new CreateRelationshipRequest (elementTypeCopy);
req.setNewElement(relation);
req.setSource(relation.getLinksFrom());
req.setTarget(relation.getLinksTo());
Command cmd = CreateConnectionViewRequest.getCreateCommand( (IAdaptable)new CreateElementRequestAdapter(req),
sourceViewAdapter ,targetViewAdapter,selectedElement, selectedElement.getDiagramPreferencesHint());

selectedElement.getDiagramEditDomain().getDiagramCommandStack().execute(cmd);

As description, "relation" is my emf model element the view should be added for,"selectedElement" the selected edit part, sourceViewAdapter and targetViewAdapter are retrieved during creation of the node elements using "((List)createViewRequest.getNewObject()).get(0)".

The code above only works when I modify the method "provides(CreateEdgeViewOperation op)" in class "XXXViewProvider." so that the one semantic hint is no more tested against the other.

Does anybody know whether there's a simplier solution for that?
What bothers me:
- In this case, the visible nodes must exist previously (to obtain the viewadapter from them)
- had to modify the XXXViewProvider
- from my research in the internet, I expected to use the DeferredCreateConnectionViewCommand to accomplish this, but without success

Hope this helps others having same problem, perhaps anyone can give me hints for a better solution

Regards,
Armin
Previous Topic:PropertySheet/Common Navigator problem
Next Topic:Creating nodes programatically
Goto Forum:
  


Current Time: Tue Mar 19 10:31:28 GMT 2024

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

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

Back to the top