CollapsingRecordNode question

Hi,

I’m using GoDiagrams Version 4.1

I’m using CollapsingRecordNode and I want to programatically remove a CollapsingRecordNodeItemList (Which has the CollapsingRecordNodeItem + link) from a CollapsingRecordNode and insert it to another.

When I try to do the same somehow the link disappears.

Here is the code I use:

private void EditLinkStart(string start, Transition link, string end)
{
Doc.StartTransaction();
CollapsingRecordNodeItem item = link.FromNode as CollapsingRecordNodeItem;
CollapsingStateNode oldStartNode = item.ParentNode as CollapsingStateNode;
CollapsingStateNode startNode = ((CollapsingStateNode)Doc.FindNode(start));
CollapsingStateNode endNode = ((CollapsingStateNode)Doc.FindNode(end));

        if (oldStartNode != null)
        {
            oldStartNode.List.Remove(item.ParentList);
        }
        if (startNode != null && endNode != null)
        {
            startNode.List.Add(item.ParentList);
            link.FromPort = item.Ports.First;
            link.ToPort = endNode.Ports.First;
            link.InvalidateViews();
        }
        Doc.FinishTransaction("Updating link start");
    }

Even when i save this to xml, the link info is missing from the xml.
Is something wrong with the above code? What is the best way to achieve what I’m trying to do?

Thanks,
Ekta

I made the following changes and it seems to work:

private void EditLinkStart(string start, Transition link, string end)
{
Doc.StartTransaction();
CollapsingRecordNodeItem item = link.FromNode as CollapsingRecordNodeItem;
CollapsingStateNode oldStartNode = item.ParentNode as CollapsingStateNode;
CollapsingStateNode startNode = ((CollapsingStateNode)Doc.FindNode(start));
CollapsingStateNode endNode = ((CollapsingStateNode)Doc.FindNode(end));
if (oldStartNode != null)
{
oldStartNode.List.Remove(item.ParentList);
}
if (startNode != null && endNode != null)
{
startNode.List.Add(item.ParentList);
link.FromPort = item.Ports.First;
link.ToPort = endNode.Ports.First;
link.InvalidateViews();
if (!Doc.LinksLayer.Contains(link))
{
Doc.LinksLayer.Add(link);
}
}
Doc.FinishTransaction("Updating link start");
}
Is this the best way to do it?

When you do the oldStartNode.List.Remove, you pull the node out of the document, which sets all it’s children’s parents (including ports) to null. A side effect of that is for all links connected to that port to be removed.

so, you need to disconnect the link from the FromPort before that happens…

  if (oldStartNode != null) {
    link.FromPort = null;    <font color="#ff0000">// NEW</font>
    oldStartNode.List.Remove(item.ParentList);
  }
  if (startNode != null && endNode != null) {
    startNode.List.Add(item.ParentList);
    link.FromPort = item.Ports.First;
   <font color="#ff0000"> //</font>link.ToPort = endNode.Ports.First;
    <font color="#ff0000">//</font>link.InvalidateViews();
  }

This code works for me, at least in the situation I’m testing. I’m not 100% sure I’m accurately reproducing your entire scenario. note I’ve commented out a couple of lines.

you might want to save the old FromPort

oldPort = link.FromPort;
link.FromPort = null;

link.FromPort = oldPort;

if the goal is to reattach the link to the same spot.

That worked! Thank you!