Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Can't get the diagram's active item -- always null (Read 1942 times)
Megan1717
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 39
Joined: Jun 20th, 2016
Can't get the diagram's active item -- always null
May 20th, 2020 at 7:52pm
Print Post  
Hello,

When selecting a node or a link, I am expecting that this item would become the "activeItem" in the diagram properties and retrievable using the getActiveItem() method. However, if I attach an event handler to the "LinkSelectedScript" of the diagram view, and examine the diagram's activeItem property, it is always null. Same thing for a selected node. The Selection array is also empty. If the link selected script or node selected script event handler is firing, clearly the item has been selected, so I'm not sure what I'm missing.

Also, if I examine the properties of the link or the node in the deleting or deleted event handler, the "selected" property is false. This also makes no sense. To delete the item from the map, clearly the map has to keep track of the selected item somehow.

This has become an issue when deleting a node, because any attached links are also deleted and the link deleted event handler fires before the node deleted event handler. If I can't delete the node for some reason (determined by business logic), I need to prevent the deletion of any attached links.

How can I get the selected item? (I did try setting the activeItem specifically in the link selected handler, but it was again null in the "deleting" event handler. )

Thanks.
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3153
Joined: Oct 19th, 2005
Re: Can't get the diagram's active item -- always null
Reply #1 - May 21st, 2020 at 7:40am
Print Post  
Hi,

There's dedicated nodeDeleting validation event raised to let you cancel node deletion, and what node's getting deleted is provided as event argument.

Selection arrays are not empty in my test -

Code
Select All
function onLinkSelected(sender, args)
{
	var link = args.getLink();
	var diagram = link.getParent();
	var selection = diagram.getSelection();
	console.log(selection.links.indexOf(link));
	console.log(selection.items.indexOf(link));
} 



ActiveItem is set after this event fires indeed. We'll have in mind setting it before raising the event for next release.

Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
Megan1717
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 39
Joined: Jun 20th, 2016
Re: Can't get the diagram's active item -- always null
Reply #2 - May 21st, 2020 at 11:24pm
Print Post  
Hello,

So the "selected" methods, such as onNodeSelected or onLinkSelected, do work and I can get the diagram's active item. These are not the issue.

I am having trouble with the "delete" and "deleting" methods, such as onLinkDeleting or onLinkDeleted. In these event handlers, the active item is null and the Selection array is empty.

Am I understanding you correctly that this is expected behavior?

Thanks.
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3153
Joined: Oct 19th, 2005
Re: Can't get the diagram's active item -- always null
Reply #3 - May 22nd, 2020 at 5:13am
Print Post  
Hi,

The item being deleted is both activeItem and inside selection array when *Deleting events are raised in my test -

Code
Select All
function onLinkDeleting(sender, args)
{
	var link = args.getLink();
	var diagram = link.getParent();
	console.log(args.getLink() == diagram.activeItem);
	console.log(diagram.selection.items.length);
} 



link/nodeDeleted event are raised after deletion, and the deleted items are already removed from both selection and diagram's items arrays at that point. Anyway the item being deleted is provided as argument to both sets of events, so you shouldn't need to look for it in selection / activeItem.

Regards,
Slavcho
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint