Remove a GoObject

Hi,

we have a graphical (GoDocument) and a logical (LogicalModel) net. Every action we do has to pass the logical net. So also the removing of GoNodes.

If node.Remove() is called you have to ask the LogicalModel if it can remove the node. If it is possible it removes the logical representation and finally the the corresponding node will be removed.
My problem is that i cannot override the GoNode.Remove() method to do the described action. Do anybody see a chance/another way?

Thanks very much in advance

Programmatically, you can of course ask your model if it’s OK to call Remove() before calling it.

For user interactions, you can override GoNode.CanDelete() to determine whether the user can delete it.
Or you can implement a GoView.SelectionDeleting event handler, which allows you to cancel the deletion operation as a whole, rather than a node-at-a-time.

If i call node.Remove() the GoView.SelectionDeleting event will not be fired. The node must be removed because of removing the logical object not because of removing the node:

node.Remove (do not remove, only notify the logical element that you want to remove it) -> logicalObject.Remove() -> RemoveNode(node)

Is there anything like GoView.SelectionDeleting i can use for this kind of action?

GoObject.Remove() is responsible for removing the object from its parent group (if any) or from the layer that it is in (if any).

It isn't a user action, so there's no GoView event. Think of it like changing the Position of the object, or setting the Brush of a shape. You're just making a programmatic change, and the only event is a GoDocument.Changed event, if the object belongs to a document.
You can call GoView.DeleteSelection if you want all the GoView events that go with the user's delete action. But if you are just updating a GoDocument to correspond to changes in your model, I would think you would not want to get any events anyway.
You probably want to set GoPort.ClearsLinksWhenRemoved to false for every GoPort in your application. That way when a node is removed, no links are automatically removed -- your code to update the document from the model should be responsible for removing links from the document.
You might be interested in the UpdateDemo sample, which demonstrates updating a document upon changes to a model, and updating a model upon changes to a document. It also handles undo/redo changes. All updates happen at the end of transactions.

Hi Walter,

dnerjes is a collegue of mine. So i am giving a short statement about this issue.

We are developing a set of base classes which are going to be used in at least two applications. Both applications handle graphs (we call them ‘logical nets’) and store them in an own structure. Our set of classes is kind of a view framework which listens to changes of the graph. And now we want to limit access on graphical net (based on GoDocument, which should allways automatically synchronize with the graph). The main reason is to assure consistency of the graph and the GoDocument.

So we tried to write an own Layer which handles changes after an GraphChanged occured. But GoLayer and GoLayerCollection are both sealed :( Now we are setting CanDelete of nodes and arrows to false. And only in our GraphChanged event handler it will be set temporarily to true.

regards,
Jörn