I am programmatically adding 10 nodes and 9 connections to my diagram. I have no problems when I add the nodes, but only 8 of the 9 connections are shown on the screen. When I add another node using the GUI, then the 9th connection appears.
The program flow is the following:
1. Call foundIP method 10 times
2. Call foundConnection 9 times
The code for adding a node and adding a connection between nodes is below.
Thank you for any help.
ADDING A NODE:
public void foundIP(final URI tmpURI) {
TransactionalEditingDomain editingDomain = GMFEditingDomainFactory.INSTANCE
.getEditingDomain(diagramResource.getResourceSet());
AbstractTransactionalCommand command = new AbstractTransactionalCommand(
editingDomain, "Creating Node", Collections.EMPTY_LIST) {
protected CommandResult doExecuteWithResult(
IProgressMonitor monitor, IAdaptable info)
throws ExecutionException {
Diagram diagram = (Diagram) diagramResource.getContents()
.get(0);
Network model = (Network) diagram.getElement();
if (myNodes.get(tmpURI) == null) {
// Must keep track of all created nodes in my hashmap:
Router tmpNode = NetdiagFactory.eINSTANCE.createRouter();
tmpNode.setIpAddress(tmpURI.toString());
model.getClients().add(tmpNode);
myNodes.put(tmpURI, tmpNode);
} else
System.out
.println("FOUNDIP: Duplicate" + tmpURI.toString());
return CommandResult.newOKCommandResult();
}
};
try {
command.execute(null, null);
} catch (ExecutionException e) {
e.printStackTrace();
}
}
FOR ADDING A CONNECTION:
public void foundConnection(final URI fromURI, final URI toURI) {
TransactionalEditingDomain editingDomain = GMFEditingDomainFactory.INSTANCE
.getEditingDomain(diagramResource.getResourceSet());
AbstractTransactionalCommand command = new AbstractTransactionalCommand(
editingDomain, "Creating connection", Collections.EMPTY_LIST) {
protected CommandResult doExecuteWithResult(
IProgressMonitor monitor, IAdaptable info)
throws ExecutionException {
// Obtain the node objects from my hashmap
Diagram diagram = (Diagram) diagramResource.getContents()
.get(0);
Network model = (Network) diagram.getElement();
Router fromNode = (Router) myNodes.get(fromURI);
Router toNode = (Router) myNodes.get(toURI);
if (fromNode == null) {
System.out.println("Creating " + fromURI.toFileString());
fromNode = NetdiagFactory.eINSTANCE.createRouter();
// Must keep track of all created nodes in my hashmap:
fromNode.setIpAddress(fromURI.toString());
model.getClients().add(fromNode);
myNodes.put(fromURI, fromNode);
}
if (toNode == null) {
System.out.println("Creating " + toURI.toFileString());
toNode = NetdiagFactory.eINSTANCE.createRouter();
// Must keep track of all created nodes in my hashmap:
toNode.setIpAddress(toURI.toString());
model.getClients().add(toNode);
myNodes.put(fromURI, toNode);
}
fromNode.getConnection().add(toNode);
return CommandResult.newOKCommandResult();
}
};
try {
command.execute(null, null);
} catch (ExecutionException e) {
e.printStackTrace();
}
}