Deleting Items
The easiest way to control which items can be deleted is by setting the deletableItems or deletablePredicate property, as mentioned in the Deleting Items section. For example, the following code snippet prevents nodes from being deleted when they still have edges connected to them:
// Prevent deletion of nodes that are connected to other nodes
graphEditorInputMode.deletablePredicate = (item) => {
if (item instanceof INode) {
if (graph.edgesAt(item).size !== 0) {
return false
}
}
return true
}
// Prevent deletion of nodes that are connected to other nodes
graphEditorInputMode.deletablePredicate = (item: IModelItem): boolean => {
if (item instanceof INode) {
if (graph.edgesAt(item).size !== 0) {
return false
}
}
return true
}
Note that the default deletablePredicate delegates to the deletableItems.Setting a custom deletablePredicate without considering the deletableItems means that the latter is ignored when determining whether items can be deleted. However, deletableItems is still used as a shortcut to decide whether the DELETE command should be enabled.
The deleteSelection method is called in response to the DELETE command and deletes the selected items after querying the deletablePredicate for each item. It also raises the events listed below. You can customize the entire process by overriding this method.
Event | Occurs … |
---|---|
The deletablePredicate may be called more than once for the same item.