This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
Hello, We need some of our custom node types (for example start and end nodes) to be read only and not to be deleted from diagram surface by pressing Delete key or another way, How can we manage to do it? Thanks. |
|
|
Hello When you implemented the custom node type, you probably also implemented an IDiagramNodeBuilder. There is a similar mechanism for providing custom removal logic which you do by implementing the IDiagramNodeRemover. Unlike the builder, there is only one node-remover per diagram which will contain all the node-removal logic you need. Create a new class and implement the IDiagramNodeRemover which has a single method - RemoveNodes. This method takes in the IDiagramModel and a list of the nodes that are trying to be deleted. The first thing you should do in this method is null checks on the given parameters. Then you iterate through the given list of nodes and can use model.Nodes.Remove(node), where model is the given model, and node is the current node in the iteration. To provide your logic, you just need to check to see what type of node you are currently going to delete. If it is a start node or end node, then don't remove it from the model. Once you've implemented your custom node remover, you need to tell the diagram model to use it. IDiagramModel has a property called NodeRemover. But as far as the IDiagramModel interface is concerned, this property is read-only. So there are a couple of scenarios here: If you are NOT setting the Diagram property of the DiagramSurface, then the DiagramSurface will set the Diagram property to an instance of Diagram by default. The Diagram implementation has a setter on the NodeRemover property, so you can get the Diagram property of the DiagramSurface, cast it into a Diagram, then set the NodeRemover property. If you are setting the Diagram property yourself, then it will probably either be an instance of Diagram, FlowDiagramModel, or your own implementation. Both Diagram and FlowDiagramModel, let you set the NodeRemover property. If you have a custom diagram model implementation, make sure the NodeRemover property can be set. Ideally your custom diagram implementation should extend the Diagram class. Once you've set the NodeRemover property, your logic will be in effect. Let me know if you need any help with this. As a suggestion, you may want a message box to popup or some other notification when the user tries to delete a node that can not be deleted. This will avoid any confusion of why the delete key isn't working for some nodes. Jason Fauchelle |
|