Abort the dragging Tool - with custom part value set

In my diagram, shapes are shown with custom adorments ( with different shapes shown)

With this approach, user is able to create different types of shapes from current shape with drag operation.
The draggingTool’s customPart needs to be set from diagram’s node collection. To set this value, a new temporary node is created and added in model. This newly created node is set to custompart.

But when user cancels the operation using esc key, the newly added nodes remains on diagram canvas. How this should be removed automatically. How one will know that diagram operation is cancelled ?

You also need to override DraggingTool.doCancel. Don’t forget to call the super method.

And how one will know that operation is completed successfully?

Because, I have implemented doDeactivate method - where I am performing database operation.

And In my case , when such node is dropped outside expected group, then I am cancelling the operation. In that case also doDeactivate gets fired and since it is not getting required information ( issue with code also) mouse is not released.

Where should I write the code instead of doDeactive , sothat I know operation is not cancelled ?
Or do I need to set some variable in doCancel method and check same in doDeactivate method ??

That’s right – Tool.doDeactivate is called whenever a Tool stops being active, for any reason.

You don’t even need to override any methods in order to do something when a drag completes successfully – there are the “SelectionMoved” and “SelectionCopied” DiagramEvents.

But since you are subclassing the DraggingTool anyway, you probably want to override DraggingTool.doDropOnto, which is called by DraggingTool.doMouseUp.

ok. will check how these methods can be used …

Still one question - can customPart be set to object/part which is not part of diagram’s model ??
Because, in this case -
since I am creating a node and adding it in model, which gets moved.
After drag operation complete, I am updating same in database and based on response from server updating same in diagram model again.
When operation is cancelled, I need to remove that node from diagram model.

if customPart is not part of diagram model, then simply on completion, i can send request to server and based on response add complete new object in model. For cancel, nothing needs to be done.

There is no DraggingTool.customPart property, so I am confused about what you are referring to.

You certainly can have Nodes and Links that are not modeled – i.e. not in the Diagram.model. However, that’s not the case for the nodes and links that are created temporarily by the DraggingTool during a copying operation, when the control key is held down. That’s because we want the usual data binding to be effective in the copied parts.

I think it’s OK that your operation is adding a node data object to the model and selecting the Node and starting the DraggingTool. Whether or not you get the server involved is your decision, but I would encourage you to avoid dependencies on the server, especially not for behavior that requires a fast response. I would only inform the server when the operation has completed successfully.

Sorry, CustomPart should be CurrentPart.

Based on your last answer, I think I should keep some nodes which are not part of model hidden/invisible in the diagram.
When my drag operation starts, I should make one of the required non-model node visible and set it to currentPart of dragging tool.

When drag tool is deactivated, just hide the non-model object which made visible.

In drop operation (when the non-model object dropped on some group - which is valid, I create the required object and add it in model. At the same time, send the request to server.) , So doDeactivate only hides the object which is made visible.

Is my above approach is right then ??

I think that could work too.

I guess you hadn’t seen this sample: Selection Adornment Buttons

Note that the two buttons, one for drawing a new link and one for creating and dragging a new node and a link to that new node, work both upon a click as well as a drag.