Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » programmatically created connections do not show(initializing diagram with node/connection set without using commands, connections dont show, nodes do)
programmatically created connections do not show [message #883385] Fri, 08 June 2012 12:28 Go to next message
Lars Wißler is currently offline 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 #884034 is a reply to message #883385] Sat, 09 June 2012 23:59 Go to previous messageGo to next message
Lars Wißler is currently offline Lars Wißler
Messages: 4
Registered: June 2012
Junior Member
Solved:

Source must be added to the Resource and target to the connection. No idea why but it works. Correct code:

	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();
		RDFEditor.Attribute att = RDFEditorFactory.eINSTANCE.createAttribute();
		RDFEditor.Attribute attr = RDFEditorFactory.eINSTANCE.createAttribute();
		
		EStructuralFeature target = res.eClass().getEStructuralFeature("targetConnections");
		EStructuralFeature source = res.eClass().getEStructuralFeature("sourceConnections");
		EStructuralFeature attribute = res.eClass().getEStructuralFeature("attributes");
		
		res2.setName("rdfs:Resource");
		res.setName("rdfs:Class");
		con.setName("rdfs:type");
		
		con.setTarget(res2);
		res.getSourceConnections().add(con);				
		
		List<? extends Shape> resList = Arrays.asList(res,res2);
		
		EStructuralFeature shapes = diagram.eClass().getEStructuralFeature("shapes");
		diagram.eSet(shapes, resList);
		
		RDFWriter writer = new RDFWriter(diagram);
		
		diagram = writer.ontModelToDiagram();
		
		return diagram;
	}
Re: programmatically created connections do not show [message #885456 is a reply to message #883385] Wed, 13 June 2012 03:16 Go to previous messageGo to next message
Oskar van Rest is currently offline Oskar van Rest
Messages: 12
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

Re: programmatically created connections do not show [message #885469 is a reply to message #885456] Wed, 13 June 2012 04:12 Go to previous message
Oskar van Rest is currently offline Oskar van Rest
Messages: 12
Registered: February 2012
Junior Member
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 04:12]

Report message to a moderator

Previous Topic:trace files
Next Topic:TextDirectEditManager giving old value
Goto Forum:
  


Current Time: Fri Oct 24 10:25:44 GMT 2014

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

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