Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » Link doesn't show when adding a connection between nodes
Link doesn't show when adding a connection between nodes [message #535832] Tue, 25 May 2010 21:24
Jaime  is currently offline Jaime Friend
Messages: 1
Registered: May 2010
Junior Member
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();
		}

	}
Previous Topic:OCL statement in mapping to prevent node creation
Next Topic:Migration to Eclipse 3.6
Goto Forum:
  


Current Time: Tue May 21 09:55:45 GMT 2024

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

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

Back to the top