-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to connect two default nodes programmatically #42
Comments
Issue-Label Bot is automatically applying the label Links: app homepage, dashboard and code for this bot. |
You can use this method private void createLink(GNode srcNode, GNode targetNode) {
EReference NODES = GraphPackage.Literals.GMODEL__NODES;
EReference CONNECTIONS = GraphPackage.Literals.GMODEL__CONNECTIONS;
EReference CONNECTOR_CONNECTIONS = GraphPackage.Literals.GCONNECTOR__CONNECTIONS;
EditingDomain editingDomain = AdapterFactoryEditingDomain.getEditingDomainFor(this.model);
GConnector input = targetNode.getConnectors().get(0);
GConnector parentOutput = srcNode.getConnectors().get(1);
GConnection connection = GraphFactory.eINSTANCE.createGConnection();
connection.setSource(parentOutput);
connection.setTarget(input);
GJoint joint1 = GraphFactory.eINSTANCE.createGJoint();
GJoint joint2 = GraphFactory.eINSTANCE.createGJoint();
joint1.setX(parentOutput.getX());
joint1.setY(parentOutput.getY());
joint2.setX(input.getX());
joint2.setY(input.getY());
connection.getJoints().add(joint1);
connection.getJoints().add(joint2);
input.getConnections().add(connection);
// Set the rest of the values via EMF commands because they touch the currently-edited model.
CompoundCommand command = new CompoundCommand();
command.append(AddCommand.create(editingDomain, this.model, CONNECTIONS, connection));
command.append(AddCommand.create(editingDomain, parentOutput, CONNECTOR_CONNECTIONS, connection));
editingDomain.getCommandStack().execute(command);
} You'll want to edit the snippet to make sure you get the correct connectors, and to position the joints. (If the joints are positioned improperly, the link won't show up in the view.) Maybe there should be a convenience method in |
In general @drinkitup777 is right. But lets break it up:
Guessing from your question 1 & 2 should be done here. There is a utility to create a rectangular path for the "default" skin: You can convert each
Then you can create the
And finally you can register the new @drinkitup777 And I don't think that we can create a general utility for this as every implemention behaves differently (default skins use rectangular connections with points as joints whereas the tree skins use direct connection lines with no points) |
Ok thank you, I think I have resolved my doubt.
|
I didn't manage to connect two simple nodes together programmatically.
In the demo it is done with the tree skin, but what if I just want to do it with the default skin?
I would add this to the wiki documentation too if possible.
The text was updated successfully, but these errors were encountered: