Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Papyrus » Create node at droplocation(Drag and Drop an item and create a node at the droplocation)
Create node at droplocation [message #1750281] Mon, 19 December 2016 13:51 Go to next message
Max Meyer is currently offline Max MeyerFriend
Messages: 3
Registered: December 2016
Junior Member
Hi
i want to drag and drop some items out of a list into the model viewer.
I already can do so but the node is always created at the top left of the viewer and i don't know how to create the node at the dropped location.

Here is the function that creates the node (x and y are the coordinates of the droplocation)

private View addNode(Node node, View deploymentView) {
		
		// use the view service to create the types. This is a bit cleaner than
		// using the sequence-diagram view provider directlys
		final String nodeType = UMLVisualIDRegistry
				.getType(org.eclipse.papyrus.uml.diagram.deployment.edit.parts.NodeEditPart.VISUAL_ID);
		org.eclipse.gmf.runtime.notation.Node nodeView = ViewService.createNode(deploymentView.getDiagram(), node,
				nodeType, UMLDiagramEditorPlugin.DIAGRAM_PREFERENCES_HINT);
		Bounds location = NotationFactory.eINSTANCE.createBounds();

		System.out.println("Dropped at x: "+ (int)this.x + " y: "+ (int)this.y);
		location.setX((int)this.x);
		location.setY((int)this.y);
		return nodeView;
	}

Re: Create node at droplocation [message #1750320 is a reply to message #1750281] Mon, 19 December 2016 22:08 Go to previous message
Max Meyer is currently offline Max MeyerFriend
Messages: 3
Registered: December 2016
Junior Member
Okay I fixed it.

private View addNode(Node node, View deploymentView) {
		final String nodeType = UMLVisualIDRegistry
				.getType(org.eclipse.papyrus.uml.diagram.deployment.edit.parts.NodeEditPart.VISUAL_ID);
		org.eclipse.gmf.runtime.notation.Node nodeView = ViewService.createNode(deploymentView.getDiagram(), node,
				nodeType, UMLDiagramEditorPlugin.DIAGRAM_PREFERENCES_HINT);
		

		System.out.println("Dropped at x: "+ (int)this.x + " y: "+ (int)this.y);
		
		
		nodeView.setLayoutConstraint(NotationFactory.eINSTANCE
				.createLocation());
		Location location = (Location) nodeView.getLayoutConstraint();
		location.setX((int)this.x);
		location.setY((int)this.y);
		return nodeView;
	}
Previous Topic:Operation should return a Collection but just returns Class (Code Generation)
Next Topic:Thanks to all who made Papyrus my favourite modelling tool
Goto Forum:
  


Current Time: Thu Apr 18 03:58:57 GMT 2024

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

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

Back to the top