programmatically created connections do not show [message #883385] |
Fri, 08 June 2012 12:28 |
Lars Wißler Messages: 4 Registered: June 2012 |
Junior Member |
|
|
0 down vote favorite
share [g+] share [fb] share [tw]
Hi I am developing an graphical editor with GMF and want to create a set of nodes (Resources in my project) and connections between them upon initialization of a new diagram. I do not want to use commands here because without the code is much slimmer, easier to read and also faster it seems to me.
There is no problem creating nodes by calling my XXXFactory.eInstance.createResource() and adding them to the diagram model. My connection is contained as source-/targetConnections feature in the resource class. So I added a similarly created connection as source/target to the resources. But it will not show up in the diagram even though it exists in the ResourceImpl structural feature. Maybe I need to add it additionally to the diagram but since it's contained by a feature contained by the diagram, I don't know how.
Am I doing something wrong or missing something or is it just not possible to do this without commands? Any help would be much appreciated. Sample code is below. The output of it is the two nodes but no connection.
Thanks Lars
private static RDFEditor.ShapesDiagram createInitialModel() {
ShapesDiagram diagram = RDFEditor.RDFEditorFactory.eINSTANCE.createShapesDiagram();
RDFEditor.Resource res = RDFEditorFactory.eINSTANCE.createResource();
RDFEditor.Resource res2 = RDFEditorFactory.eINSTANCE.createResource();
Connection con = RDFEditorFactory.eINSTANCE.createConnection();
EStructuralFeature target = res.eClass().getEStructuralFeature("targetConnections");
EStructuralFeature source = res.eClass().getEStructuralFeature("sourceConnections");
res2.setName("rdfs:Resource");
res.setName("rdfs:Class");
con.setName("rdfs:type");
con.setSource(res);
con.setTarget(res2);
res.getSourceConnections().add(con);
res.getTargetConnections().add(con);
//res2.eSet(target, con);
//res.eSet(source, con);
List<? extends Shape> resList = Arrays.asList(res,res2);
EStructuralFeature shapes = diagram.eClass().getEStructuralFeature("shapes");
diagram.eSet(shapes, resList);
return diagram;
}
[Updated on: Fri, 08 June 2012 13:14] Report message to a moderator
|
|
|
|
Re: programmatically created connections do not show [message #885456 is a reply to message #883385] |
Wed, 13 June 2012 03:16 |
Oskar van Rest Messages: 13 Registered: February 2012 |
Junior Member |
|
|
I have the same problem. My connections don't show up until I add a new node to the canvas (either programmatically or graphically).
Lars' solution doesn't work in my case because I let EMF compare do the model update, so I don't have control over this.
Any ideas anyone?
The way I update my model is as follows:
editingDomain.getCommandStack().execute(new RecordingCommand(editingDomain) {
protected void doExecute() {
// update model
}});
Is that the proper way to do it?
[Updated on: Wed, 13 June 2012 03:19] Report message to a moderator
|
|
|
|
Powered by
FUDForum. Page generated in 0.02804 seconds