Inserting New EntityObjects

What’s the best way to override the copying of the ProtoTypeData in the ClickCreatingTool?

Now that I’m using actual EntityObjects, the default Copy method is a really, really bad thing to do. What I’d like to do is set the PrototypeData to be some kind of dummy reference, and then based on that type, create an entirely new object base on my own construction method.

From what I read here (forum post)

And based on the (API)
<span =“nodetext”><span =“nodetext”>
Should I add my logic in the ClickCreatingTool.InsertNode() method?
Is the copying done in the DoStart() method?

I’d prefer to avoid the tool making a copy of anything at all, since EntityFramework automagically adds things to the context and crufts up the database that way.


That’s right – you don’t want to use ClickCreatingTool.PrototypeData at all. Instead, override InsertNode to do whatever you need to do to cause the desired record/object to show up. Because you have set up the Model to be updated automatically, that will cause the Model.NodesSource collection to be augmented, which will in turn cause a Node to be added to the Diagram.

Your override of InsertNode should perform everything within a GoXam Transaction by calling StartTransaction, doing the work, setting TransactionResult to the name of that particular transaction, and then calling StopTransaction. It is also customary to select the new Node, which you can find via the PartManager given the new model node data (EntityObject).

The standard definition of InsertNode also raises the “NodeCreated” DiagramEvent, but you don’t need to bother if no code in your application has an interest in listenening for that event.

Will ClickCreatingTool even fire InsertNode if there’s no PrototypeData?

Here is what my current override looks like. It isn’t returning any Parts in the DiagramEventArgs, so I have a hack in my NodeAdded code to handle that. It works, but I wish I found figure out why it’s not returning any args (I’m OK with my hack, as long as I’m not going to incur pain down the line)

Here’s my hack to retreive the associated Node (Goxam part), and the proper insertion point

It’s working reasonably well. The last major hurdle I see is when the EntityCollection underlying the LinksSource or the NodesSource changes. What would be the recommend method for doing that?

In other words, node index 10 disappears, to be replaced with a different node. EntityCollections do not throw CollectionChanged, so listening there is out of the question.

What I have now is my NodesSource and LinksSource updating as expected, but the old Node.Data object is still in the Diagram.Nodes still contains the old object. I was able to change the Diagram.Nodes to reflect the new Node, but how do I change the Links?

The FromData/FromNode are read only. Do I delete the Link, and then add a new Link?

I tried this method, and it doesn’t work on my GraphLinksModel. The number of links stayed constant, and no new links were created (I assume since it’s bound to the LinksSource). I was able to create the Node programatically, it’s just not connected anywhere.

OasisDiagram.StartTransaction(“Reconnect New Node”);
foreach (Link link in connectedLinks)
if (link.FromData == oldRe)
OasisDiagram.Model.AddLink(oldRe, null, link.ToData, null);
if (link.ToData == oldRe)
OasisDiagram.Model.AddLink(link.FromData, null, oldRe, null);
OasisDiagram.CommitTransaction(“Reconnect New Node”);[/quote]

Sorry for the delay – I missed this post.

Because EntityCollection does not implement INotifyCollectionChanged, you need to explicitly call GraphLinksModel.DoLinkAdded and/or DoLinkRemoved.

In your code above, I hope connectedLinks is a copy of the collection of links that you want to replace.