Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic OnContainerChildAdding event (Read 6462 times)
Kiran B
Full Member
***
Offline


I Love MindFusion!

Posts: 102
Joined: Apr 19th, 2013
OnContainerChildAdding event
Apr 29th, 2013 at 9:13am
Print Post  
Hi,

OnContainerChildAdding event is missing in Diagramming MVC version.  I really need this event to handle a business scenario. Is there any way to get this event?

My requirements is like this. I have a container shape and i am having some rules such that certain shapes cannot be added into the container node. If i had OnContainerChildAdding event i could do my logic here in this event and give a setCancel so that everything works fine. Is there any way to achieve this.

This has to work in below scenarios.

1. Adding the shape to container from NodeListView control
2. Drag and drop a shape to the container
3. Re-sizing child nodes and adding to the container node.
4. If there is anymore user interaction in which a shape node can be added to container there also it has to work

Thanks
Kiran B
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: OnContainerChildAdding event
Reply #1 - Apr 29th, 2013 at 10:19am
Print Post  
Hi,

You could replace the containers' add function:

Code
Select All
var originalAdd = ContainerNode.prototype.add;
ContainerNode.prototype.add = function (node)
{
	if (shouldNotAdd(node))
		return;
	originalAdd.apply(this, [node]);
}; 



I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Kiran B
Full Member
***
Offline


I Love MindFusion!

Posts: 102
Joined: Apr 19th, 2013
Re: OnContainerChildAdding event
Reply #2 - Apr 29th, 2013 at 12:30pm
Print Post  
Hi Stoyan,

Hey i am facing a serious issue when i implemented your code. I am having a container with a child node exactly at the center of the container. When i try to move the container having this child, the add event is getting fired. Why its behaving in this manner? Any solution for this problem?

Also i need to get the parent container to which this children is getting added to preform the validation.
I mean inside the shouldNotAdd method.

Thanks
Kiran B
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: OnContainerChildAdding event
Reply #3 - Apr 29th, 2013 at 12:44pm
Print Post  
The base add method will do nothing when called in that case, it has the following checks in beginning which you could call too:

if (node.containsRecursively && node.containsRecursively(this))
    return;

Just add a container argument to your shouldNotAdd function and pass the 'this' pointer as its value.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Kiran B
Full Member
***
Offline


I Love MindFusion!

Posts: 102
Joined: Apr 19th, 2013
Re: OnContainerChildAdding event
Reply #4 - Apr 29th, 2013 at 1:36pm
Print Post  
Hi Stoyan,

Its working perfectly. I need 2 more things.

1. I need to bring back the child to the original position if its not allowed to drop.
2. Show not allowed icon at that time.

Thanks
Kiran B
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: OnContainerChildAdding event
Reply #5 - Apr 29th, 2013 at 4:07pm
Print Post  
Hi,

That should be possible from the nodeModifying handler, as in http://mindfusion.eu/Forum/YaBB.pl?num=1366656522

I think it should be enough to move the outermost if statement to the innermost one, and add an || shouldNotAdd check to it.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Kiran B
Full Member
***
Offline


I Love MindFusion!

Posts: 102
Joined: Apr 19th, 2013
Re: OnContainerChildAdding event
Reply #6 - Apr 30th, 2013 at 6:04am
Print Post  
Hi,

Is it possible to handle this inside shouldNotAdd method itself? I dont want to distribute logic spread across more than 2 methods or events. I am already doing lot of these hacks inside almost of the events. It will complicate when the codes grows.

Can i do this implementation in a better way. If i need to do this the same way like containerChildAdded event like below. What all things i need to do extra.

diagram.addEventListener(‘containerChildAdded’, this.onAdded);
diagram.addEventListener(‘containerChildAdding’, this. shouldNotAdd);


Thanks
Kiran B

  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: OnContainerChildAdding event
Reply #7 - May 1st, 2013 at 8:21am
Print Post  
Hi,

You could bring back the node from shouldNotAdd, but since add is called only when mouse button is released, you won't be able to change the mouse cursor while users drag nodes. That can be done only from modifying/creating events at this time.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Kiran B
Full Member
***
Offline


I Love MindFusion!

Posts: 102
Joined: Apr 19th, 2013
Re: OnContainerChildAdding event
Reply #8 - May 1st, 2013 at 9:14am
Print Post  
Hi Stoyan,

I think it is really easy for you guys to achieve this. I am giving you a code sample. Verify and just say if i need to take care of anything. Most of the items i have asked you in this forum are really things that is lacking in your product. Ideally you have to take all the forum items and put this as a feature in your product. It will only make your product more flexible and stable. Most of the items that i asked are really easy to do, by looking into your workaround codes. Then why cant you put all these thing as part of your framework. The problem now i am facing is i am not getting enough time to handle my business scenarios coz i need to fix lot of things in Mindfusion framework. lot of work arounds. For what ever things i am asking you are giving me solutions in the modifying event. Its really growing.... It will reach a state where i will struggle to figure out my business logics out of your workaround codes. So please take it as serious. Lot of events are lacking in your framework that you could easily figure out and fix it out. Please do that...As you are saying everything might be handled by modifying event, but that is not the ideal way.

Mouse cursor let me give some time to figure out the work around. But please include these as part of your framework.

<script type="text/javascript" language="javascript">
var ContainerNodeEventArgs = function (container, childNode) {
//private variable
var _cancel = false;

return {
setCancel: function (val) {
if (val === true || val === false) {
_cancel = val;
}
},
getCancel: function () {
return _cancel;
},
getContainer: function () {
return container;
},
getNode: function () {
return childNode;
}
};

};

MindFusion.Diagramming.Events.onContainerChildAdding = "onContainerChildAdding";
var originalAdd = MindFusion.Diagramming.ContainerNode.prototype.add;
MindFusion.Diagramming.ContainerNode.prototype.add = function (childNode) {

var diagram = childNode.getParent();
if (diagram !== undefined && diagram !== null) {

var handlers = diagram.eventHandlers._list[MindFusion.Diagramming.Events.onContainerChildAdding];
if (handlers !== undefined && handlers !== null && handlers.length > 0) {

var args = new ContainerNodeEventArgs(diagram, childNode);

Array.forEach(handlers, function (handler) {
handler(diagram, args);
});
var result = args.getCancel();
if (result === true) {
if (diagram.interaction !== undefined && diagram.interaction !== null) {
var savedState = diagram.interaction.interactionState.originalStates;
var originalBounds = savedState.get(childNode).bounds;
//move back the child node to original position
childNode.setBounds(originalBounds, true, true);
}
}
return;
}
}

originalAdd.apply(this, [childNode]);
};


$(document).ready(function () {

var _diagram = $find("diagramView1");

_diagram.addEventListener(MindFusion.Diagramming.Events.onContainerChildAdding,
onChildAdding);

function onChildAdding(sender, args) {

args.setCancel(true);
}
});
</script>

Thanks
Kiran B
  
Back to top
 
IP Logged
 
Kiran B
Full Member
***
Offline


I Love MindFusion!

Posts: 102
Joined: Apr 19th, 2013
Re: OnContainerChildAdding event
Reply #9 - May 1st, 2013 at 9:24am
Print Post  
Hi,

One more thing. I feel that will help you understand my problem better. I am doing lot of business functionality while nodeCreated and containerchildadded events. Its really hectic for me to rollback once it is happened. So i need to cancel it out in adding event so that it wont reach the added event and it makes my code clean. That why need these events. i could do a rollback logic but if i get these events i could avoid lot of unwanted codes. I think you got my point.

Thanks
Kiran B
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint