Remove Links
I want to be able to remove any associated links to a symbol when the symbol is deleted from the diagram.
I have tried handling the Model.ChildrenChanging event however the links have already been removed from the Symbol Connections property at this point.
What's the best way to achieve this. We do not want to have any residual links pointing to nowhere.
Thanks,
Darren
I have tried handling the Model.ChildrenChanging event however the links have already been removed from the Symbol Connections property at this point.
What's the best way to achieve this. We do not want to have any residual links pointing to nowhere.
Thanks,
Darren
SIGN IN To post a reply.
6 Replies
AD
Administrator
Syncfusion Team
October 18, 2006 05:01 AM UTC
Hi Darren,
According to syncfusion there is a known issue with trying to delete links using the removenode command (see http://www.syncfusion.com/support/Forums/message.aspx?MessageID=45303
)
I have found this issue to also exist in 4.3.0.30. Syncfusion can clarify if this is true or not but I belive it is a bug (not only does the RemoveNodeCmd not work in this case but the EdgesLeaving and EdgesIncoming Collection counts are zero yet the Edges Count is not in the case of the code below, hence that is why I am forced to enumerate over the edges collection only. To me that is also a bug). I was able to code a work around as follows:
1. Add this code to override the symbol's (or your base symbol class if you have inheritance) childrenchanging event (NOTE the commented out code is the code that should work but doesn't):
protected override void OnChildrenChanging(NodeCollectionEventArgs evtArgs)
{
if (evtArgs.ChangeType == CollectionExChangeType.Remove)
{
IGraphNode curNode = this as IGraphNode;
if (curNode != null)
{
IEnumerator enumEdges = curNode.Edges.GetEnumerator();
//IEnumerator enumedgesEntering = curNode.EdgesEntering.GetEnumerator();
//IEnumerator enumedgesLeaving = curNode.EdgesLeaving.GetEnumerator();
//RemoveNodesCmd
RemoveNodesCmd rmnodesCmd = new RemoveNodesCmd();
//NodeCollection
NodeCollection links = new NodeCollection();
//All Links
ICollection allEdges = curNode.Edges;
while (enumEdges.MoveNext())
{
Link aLink = enumEdges.Current as Link;
aLink.DisconnectAll(aLink.HeadPort);
aLink.DisconnectAll(aLink.TailPort);
this.Model.RemoveChild(this.Model.GetChildIndex(aLink));
//links.Add(aLink);
}
//Incoming Links
//ICollection edgesEntering = curNode.EdgesEntering;
//while (enumedgesEntering.MoveNext())
//{
// Link incomingLink = enumedgesEntering.Current as Link;
// links.Add(incomingLink);
//}
////Leaving Links
//ICollection edgesLeaving = curNode.EdgesLeaving;
//while (enumedgesLeaving.MoveNext())
//{
// Link leavingLink = enumedgesLeaving.Current as Link;
// links.Add(leavingLink);
//}
//Concatatenation of the NodeCollection to the RemoveNodesCmd
//rmnodesCmd.Nodes.Concat(links);
//Execute the RemoveNodesCmd
//this.diagram1.Controller.ExecuteCommand(rmnodesCmd);
}
}
base.OnChildrenChanging(evtArgs);
}
Could somebody at syncfusion please explain why the RemoveNodesCmd doesn't work in this case and why the EdgesLeaving and EdgesIncoming have 0 counts when Edges does not??
Cheers
pF ROCKS! :o)
>I want to be able to remove any associated links to a symbol when the symbol is deleted from the diagram.
I have tried handling the Model.ChildrenChanging event however the links have already been removed from the Symbol Connections property at this point.
What's the best way to achieve this. We do not want to have any residual links pointing to nowhere.
Thanks,
Darren
According to syncfusion there is a known issue with trying to delete links using the removenode command (see http://www.syncfusion.com/support/Forums/message.aspx?MessageID=45303
)
I have found this issue to also exist in 4.3.0.30. Syncfusion can clarify if this is true or not but I belive it is a bug (not only does the RemoveNodeCmd not work in this case but the EdgesLeaving and EdgesIncoming Collection counts are zero yet the Edges Count is not in the case of the code below, hence that is why I am forced to enumerate over the edges collection only. To me that is also a bug). I was able to code a work around as follows:
1. Add this code to override the symbol's (or your base symbol class if you have inheritance) childrenchanging event (NOTE the commented out code is the code that should work but doesn't):
protected override void OnChildrenChanging(NodeCollectionEventArgs evtArgs)
{
if (evtArgs.ChangeType == CollectionExChangeType.Remove)
{
IGraphNode curNode = this as IGraphNode;
if (curNode != null)
{
IEnumerator enumEdges = curNode.Edges.GetEnumerator();
//IEnumerator enumedgesEntering = curNode.EdgesEntering.GetEnumerator();
//IEnumerator enumedgesLeaving = curNode.EdgesLeaving.GetEnumerator();
//RemoveNodesCmd
RemoveNodesCmd rmnodesCmd = new RemoveNodesCmd();
//NodeCollection
NodeCollection links = new NodeCollection();
//All Links
ICollection allEdges = curNode.Edges;
while (enumEdges.MoveNext())
{
Link aLink = enumEdges.Current as Link;
aLink.DisconnectAll(aLink.HeadPort);
aLink.DisconnectAll(aLink.TailPort);
this.Model.RemoveChild(this.Model.GetChildIndex(aLink));
//links.Add(aLink);
}
//Incoming Links
//ICollection edgesEntering = curNode.EdgesEntering;
//while (enumedgesEntering.MoveNext())
//{
// Link incomingLink = enumedgesEntering.Current as Link;
// links.Add(incomingLink);
//}
////Leaving Links
//ICollection edgesLeaving = curNode.EdgesLeaving;
//while (enumedgesLeaving.MoveNext())
//{
// Link leavingLink = enumedgesLeaving.Current as Link;
// links.Add(leavingLink);
//}
//Concatatenation of the NodeCollection to the RemoveNodesCmd
//rmnodesCmd.Nodes.Concat(links);
//Execute the RemoveNodesCmd
//this.diagram1.Controller.ExecuteCommand(rmnodesCmd);
}
}
base.OnChildrenChanging(evtArgs);
}
Could somebody at syncfusion please explain why the RemoveNodesCmd doesn't work in this case and why the EdgesLeaving and EdgesIncoming have 0 counts when Edges does not??
Cheers
pF ROCKS! :o)
>I want to be able to remove any associated links to a symbol when the symbol is deleted from the diagram.
I have tried handling the Model.ChildrenChanging event however the links have already been removed from the Symbol Connections property at this point.
What's the best way to achieve this. We do not want to have any residual links pointing to nowhere.
Thanks,
Darren
AD
Administrator
Syncfusion Team
October 18, 2006 06:00 AM UTC
MY BAD!
I made a typo in the previous message:
the line protected override void OnChildrenChanging(NodeCollectionEventArgs evtArgs)
SHOULD have read:
protected override void OnConnectionsChanging(ConnectionCollectionEventArgs evtArgs)
You could also do this in the AfterCommandDo override when the cmd parameter is = RemoveNodesCmd
Cheers
>Hi Darren,
According to syncfusion there is a known issue with trying to delete links using the removenode command (see http://www.syncfusion.com/support/Forums/message.aspx?MessageID=45303
)
I have found this issue to also exist in 4.3.0.30. Syncfusion can clarify if this is true or not but I belive it is a bug (not only does the RemoveNodeCmd not work in this case but the EdgesLeaving and EdgesIncoming Collection counts are zero yet the Edges Count is not in the case of the code below, hence that is why I am forced to enumerate over the edges collection only. To me that is also a bug). I was able to code a work around as follows:
1. Add this code to override the symbol's (or your base symbol class if you have inheritance) childrenchanging event (NOTE the commented out code is the code that should work but doesn't):
protected override void OnChildrenChanging(NodeCollectionEventArgs evtArgs)
{
if (evtArgs.ChangeType == CollectionExChangeType.Remove)
{
IGraphNode curNode = this as IGraphNode;
if (curNode != null)
{
IEnumerator enumEdges = curNode.Edges.GetEnumerator();
//IEnumerator enumedgesEntering = curNode.EdgesEntering.GetEnumerator();
//IEnumerator enumedgesLeaving = curNode.EdgesLeaving.GetEnumerator();
//RemoveNodesCmd
RemoveNodesCmd rmnodesCmd = new RemoveNodesCmd();
//NodeCollection
NodeCollection links = new NodeCollection();
//All Links
ICollection allEdges = curNode.Edges;
while (enumEdges.MoveNext())
{
Link aLink = enumEdges.Current as Link;
aLink.DisconnectAll(aLink.HeadPort);
aLink.DisconnectAll(aLink.TailPort);
this.Model.RemoveChild(this.Model.GetChildIndex(aLink));
//links.Add(aLink);
}
//Incoming Links
//ICollection edgesEntering = curNode.EdgesEntering;
//while (enumedgesEntering.MoveNext())
//{
// Link incomingLink = enumedgesEntering.Current as Link;
// links.Add(incomingLink);
//}
////Leaving Links
//ICollection edgesLeaving = curNode.EdgesLeaving;
//while (enumedgesLeaving.MoveNext())
//{
// Link leavingLink = enumedgesLeaving.Current as Link;
// links.Add(leavingLink);
//}
//Concatatenation of the NodeCollection to the RemoveNodesCmd
//rmnodesCmd.Nodes.Concat(links);
//Execute the RemoveNodesCmd
//this.diagram1.Controller.ExecuteCommand(rmnodesCmd);
}
}
base.OnChildrenChanging(evtArgs);
}
Could somebody at syncfusion please explain why the RemoveNodesCmd doesn't work in this case and why the EdgesLeaving and EdgesIncoming have 0 counts when Edges does not??
Cheers
pF ROCKS! :o)
>I want to be able to remove any associated links to a symbol when the symbol is deleted from the diagram.
I have tried handling the Model.ChildrenChanging event however the links have already been removed from the Symbol Connections property at this point.
What's the best way to achieve this. We do not want to have any residual links pointing to nowhere.
Thanks,
Darren
I made a typo in the previous message:
the line protected override void OnChildrenChanging(NodeCollectionEventArgs evtArgs)
SHOULD have read:
protected override void OnConnectionsChanging(ConnectionCollectionEventArgs evtArgs)
You could also do this in the AfterCommandDo override when the cmd parameter is = RemoveNodesCmd
Cheers
>Hi Darren,
According to syncfusion there is a known issue with trying to delete links using the removenode command (see http://www.syncfusion.com/support/Forums/message.aspx?MessageID=45303
)
I have found this issue to also exist in 4.3.0.30. Syncfusion can clarify if this is true or not but I belive it is a bug (not only does the RemoveNodeCmd not work in this case but the EdgesLeaving and EdgesIncoming Collection counts are zero yet the Edges Count is not in the case of the code below, hence that is why I am forced to enumerate over the edges collection only. To me that is also a bug). I was able to code a work around as follows:
1. Add this code to override the symbol's (or your base symbol class if you have inheritance) childrenchanging event (NOTE the commented out code is the code that should work but doesn't):
protected override void OnChildrenChanging(NodeCollectionEventArgs evtArgs)
{
if (evtArgs.ChangeType == CollectionExChangeType.Remove)
{
IGraphNode curNode = this as IGraphNode;
if (curNode != null)
{
IEnumerator enumEdges = curNode.Edges.GetEnumerator();
//IEnumerator enumedgesEntering = curNode.EdgesEntering.GetEnumerator();
//IEnumerator enumedgesLeaving = curNode.EdgesLeaving.GetEnumerator();
//RemoveNodesCmd
RemoveNodesCmd rmnodesCmd = new RemoveNodesCmd();
//NodeCollection
NodeCollection links = new NodeCollection();
//All Links
ICollection allEdges = curNode.Edges;
while (enumEdges.MoveNext())
{
Link aLink = enumEdges.Current as Link;
aLink.DisconnectAll(aLink.HeadPort);
aLink.DisconnectAll(aLink.TailPort);
this.Model.RemoveChild(this.Model.GetChildIndex(aLink));
//links.Add(aLink);
}
//Incoming Links
//ICollection edgesEntering = curNode.EdgesEntering;
//while (enumedgesEntering.MoveNext())
//{
// Link incomingLink = enumedgesEntering.Current as Link;
// links.Add(incomingLink);
//}
////Leaving Links
//ICollection edgesLeaving = curNode.EdgesLeaving;
//while (enumedgesLeaving.MoveNext())
//{
// Link leavingLink = enumedgesLeaving.Current as Link;
// links.Add(leavingLink);
//}
//Concatatenation of the NodeCollection to the RemoveNodesCmd
//rmnodesCmd.Nodes.Concat(links);
//Execute the RemoveNodesCmd
//this.diagram1.Controller.ExecuteCommand(rmnodesCmd);
}
}
base.OnChildrenChanging(evtArgs);
}
Could somebody at syncfusion please explain why the RemoveNodesCmd doesn't work in this case and why the EdgesLeaving and EdgesIncoming have 0 counts when Edges does not??
Cheers
pF ROCKS! :o)
>I want to be able to remove any associated links to a symbol when the symbol is deleted from the diagram.
I have tried handling the Model.ChildrenChanging event however the links have already been removed from the Symbol Connections property at this point.
What's the best way to achieve this. We do not want to have any residual links pointing to nowhere.
Thanks,
Darren
AD
Administrator
Syncfusion Team
October 18, 2006 12:56 PM UTC
Another issue with my code suggestion above:
You need to remove the lines:
aLink.DisconnectAll(aLink.HeadPort);
aLink.DisconnectAll(aLink.TailPort);
and replace them with :
int index = this.Model.GetChildIndex(aLink);
if (index != -1)
{
this.Model.RemoveChild(index);
}
This is because if you are handling this OnConnectionsCHanging on a base symbol class and the link you want to delete is between the same two types of symbols, the OnConnectionChanging will be called on both symbols. So when you try to delete the link again from the symbol(s) that is connected to the symbol you are deleting, you will find out that it has already been deleted from the diagram.
You need to remove the lines:
aLink.DisconnectAll(aLink.HeadPort);
aLink.DisconnectAll(aLink.TailPort);
and replace them with :
int index = this.Model.GetChildIndex(aLink);
if (index != -1)
{
this.Model.RemoveChild(index);
}
This is because if you are handling this OnConnectionsCHanging on a base symbol class and the link you want to delete is between the same two types of symbols, the OnConnectionChanging will be called on both symbols. So when you try to delete the link again from the symbol(s) that is connected to the symbol you are deleting, you will find out that it has already been deleted from the diagram.
J.
J.Nagarajan
Syncfusion Team
October 26, 2006 11:58 PM UTC
Hi ,
We are currently working on this issue . I will update you very soon.
Thanks for your patience.
Regards,
Nagaraj
We are currently working on this issue . I will update you very soon.
Thanks for your patience.
Regards,
Nagaraj
AD
Administrator
Syncfusion Team
February 9, 2007 05:15 AM UTC
Hi, I was wondering if I could get an update on this issue.
Has this problem been resolved, or is there a workaround available? I was able to remove links connected to a node being deleted using the ChildrenChanging event in version 4.2.0.37, but after upgrading to 4.4.0.51 this no longer works; evtArgs.Node.Edges, EdgesEntering, and EdgesEntering properties are always 0. It seems that the ConnectionsChanging event is triggered before ChildrenChanging, so the node is disconnected before being deleted. Is that correct? Unfortunately, when a connection is being removed, I can't tell if it's because a link is being deleted, a node connected to a link is being deleted, or one end of a link is being reconnected to another node (in which case I don't want to delete the link). How can I remove links connected to a node being deleted?
Has this problem been resolved, or is there a workaround available? I was able to remove links connected to a node being deleted using the ChildrenChanging event in version 4.2.0.37, but after upgrading to 4.4.0.51 this no longer works; evtArgs.Node.Edges, EdgesEntering, and EdgesEntering properties are always 0. It seems that the ConnectionsChanging event is triggered before ChildrenChanging, so the node is disconnected before being deleted. Is that correct? Unfortunately, when a connection is being removed, I can't tell if it's because a link is being deleted, a node connected to a link is being deleted, or one end of a link is being reconnected to another node (in which case I don't want to delete the link). How can I remove links connected to a node being deleted?
J.
J.Nagarajan
Syncfusion Team
February 13, 2007 08:14 PM UTC
Hi Eric,
Sorry for the delay in getting back to you. If your intention is to remove the link connected to a node being deleted then you have to use RemoveNodeCmd in ChildrenChanging event.
But the diagram history manager now does not allow another action (removing a link) to proceed when an action is pending (the add link action is considered complete only after the event handler returns). That is why the RemoveNodesCmd action is not executed. We have internally fixed this issue in our latest source. Please open a new Direct Trac incident (mention the forum link in the subject line) so that we can update with the download link of the private patch including this bug fix.
As a work around, Please refer to the attached sample. In this sample I have seperately called the RemoveNodeCmd (In DeleteNodes button Click event) after the ChildChanging event handler returns. Please do the following.
1. Add Symbols and connect them through link(Click Links->Link item)
2.Select a symbol and click on the DeleteNode button.
3. Now the the link and the selected node should be deleted.
DeleteLinks_Symbols.zip
Please let me know if you have any questions. Thanks for your patience.
Regards,
Nagaraj
Sorry for the delay in getting back to you. If your intention is to remove the link connected to a node being deleted then you have to use RemoveNodeCmd in ChildrenChanging event.
But the diagram history manager now does not allow another action (removing a link) to proceed when an action is pending (the add link action is considered complete only after the event handler returns). That is why the RemoveNodesCmd action is not executed. We have internally fixed this issue in our latest source. Please open a new Direct Trac incident (mention the forum link in the subject line) so that we can update with the download link of the private patch including this bug fix.
As a work around, Please refer to the attached sample. In this sample I have seperately called the RemoveNodeCmd (In DeleteNodes button Click event) after the ChildChanging event handler returns. Please do the following.
1. Add Symbols and connect them through link(Click Links->Link item)
2.Select a symbol and click on the DeleteNode button.
3. Now the the link and the selected node should be deleted.
DeleteLinks_Symbols.zip
Please let me know if you have any questions. Thanks for your patience.
Regards,
Nagaraj
SIGN IN To post a reply.
- 6 Replies
- 3 Participants
-
DM Darren Mombourquette
- Oct 18, 2006 02:23 AM UTC
- Feb 13, 2007 08:14 PM UTC