Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic drag and drop shape, and create link automatically (Read 2151 times)
jagdipa
Junior Member
**
Offline


I love YaBB 1G - SP1!

Posts: 52
Joined: Jun 23rd, 2011
drag and drop shape, and create link automatically
Jun 28th, 2011 at 3:39pm
Print Post  
I was wondering whether someone could tell me if this is possible:

I am using the Java version, with a ShapeBoxList. I have disabled any new shapes from the Diagram. The user must drag and drop a shape from the list.

What I would like to do is, when the user drags a shape and drops it onto the diagram, the following happens:
1. The shape is created on the page.
2. The user must drop the new shape on top of an existing shape. A link is created between the new shape and the existing shape that it is dropped on. If the user does not drop it onto an existing shape, then the new shape is not added.
3. The diagram is re-arranged.

I have basically accomplished 1 and 3. I am struggling to find out whether 2 is possible. For example, how do I know a shape is being dragged into the page, and not something else? How do I findout the existing shape that the new shape has been dropped onto? How do I create a link between the existing shape and new shape?

I am guessing I need to do all of this in Javascript.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: drag and drop shape, and create link automatic
Reply #1 - Jun 29th, 2011 at 6:07am
Print Post  
Try this:

Code
Select All
function onNodeCreated(sender, args)
{
	var applet = <%= diagramView.AppletElement %>;
	var diagram = applet.getDiagram();
	var script = applet.getScriptHelper();

	var r = args.getNode().getBounds();
	var point = script.createPointF(
		r.getX() + r.getWidth() / 2,
		r.getY() + r.getHeight() / 2);

	var nodes = diagram.getNodesAt(point);
	if (nodes.size() < 2)
		diagram.getNodes().remove(args.getNode());
	else
		diagram.getFactory().createDiagramLink(nodes.get(1), args.getNode());
} 

  
Back to top
 
IP Logged
 
jagdipa
Junior Member
**
Offline


I love YaBB 1G - SP1!

Posts: 52
Joined: Jun 23rd, 2011
Re: drag and drop shape, and create link automatic
Reply #2 - Jun 29th, 2011 at 8:29am
Print Post  
Stoyo, you are a god. Thank you for your help.
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint