Unique key of the node last deleted

Hi, I don’t want to delete a node by pressing the delete button. Rather I want to show an icon on which the delete button is clicked. So I want to know the unique key to which the delete button is pressed.

You have a few options. You can simply set deletable: false in your Node template. You can still programmatically delete it with the button (icon) of your own making. Would that work in your case?

Actually, I have to do something out I the canvas also. So I want to know the items which are selected on the canvas
Eg: Let say a user has selected 3 nodes on canvas and hit the delete button. I need to know those three items. Because I need to send those three items to backed via API.

So please let me a way to know the selected items on the canvas.

The normal design is to use optimistic transactions, so for deletion, the deletion happens immediately locally in the client/browser and only if there is a problem on the server does the deletion get undone in the client/browser.

If you do not want that kind of design, then I suggest that you override CommandHandler.deleteSelection not to actually do the deletion (i.e. do not call the super method) but just change the appearance of the Parts in the Diagram.selection. Then when the server eventually provides the results of the attempted deletion, you can run a transactions that either updates the model with the actually deleted Parts or if the deletion failed you can restore the appearance of those selected Parts.

Actually I have to show a minus sign to the selected node when someone hits the delete button. I have tried CommandHandler.deleteSelection but it doesn’t work. I have tried commandHandler.doKeyDown and it is working. Can you tell me a way to do so by hitting delete button.

The reason I suggested overriding CommandHandler.deleteSelection is because it is called not only by the key down event handler, but also by context menu buttons and maybe by some HTML click listeners on your page.

Note also that the user may have selected more than one node. That is why Diagram.selection is a collection, not just a single Part.

How have you defined the override?