programmatically created connections do not show [message #883385] |
Fri, 08 June 2012 08:28  |
Eclipse User |
|
|
|
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 09:14] by Moderator
|
|
|
|
|
Re: programmatically created connections do not show [message #885469 is a reply to message #885456] |
Wed, 13 June 2012 00:12  |
Eclipse User |
|
|
|
Currently solved it with the following hack:
Display.getDefault().asyncExec(new Runnable() {
public void run() {
diagramEditor.getDiagramEditPart().addNotify();
}});
I added this piece of code right after I programmatically update my semantic model. No idea what this method 'addNotify()' exactly does...
[Updated on: Wed, 13 June 2012 00:12] by Moderator
|
|
|
Powered by
FUDForum. Page generated in 0.04273 seconds