Select a node when dragging it

Hi,

when a node is clicked, the ChangedSelection event is triggered when mouseUp instead of mouseDown, which is good.

But when a node is dragged, the ChangedSelection event is triggered at the beginning of the dragging. Is it possible to customize the behavior so that the ChangedSelection event is triggered when the mouse is released (mouseUp) and a node is dropped instead of when dragging starts?

In my case, I am centering the selected node when a node is clicked. I have scrollToPart inside the ChangedSelection event listener. But when a node is dragged, the node is first centered and then when the drag happens, the dragged node is no longer under the mouse, as illustrated below. If the ChangedSelection event can be triggered when mouseUp, the node will be centered after it is dropped.

recording

Thanks for your time!

Min

Well, no, because the selection collection does change near the beginning of the DraggingTool’s operation. Not when the drag finishes.

Why don’t you do your scrolling when a node is clicked, not when it is selected?

Hi Walter, clicking a node does not mean selecting it. We have business logic to decide if a node should be selected when is clicked. And the requirement is that the selected node needs to be scrolled to the center.

Moreover, when if I want to center the dropped selected node as well.

Is it possible to customize the DraggingTool?

Thanks,
Min

Yes, that is right – clicking is separate from selecting. Although they do interact in the ClickSelectingTool, which is I assume what you have overridden to decide whether or not a click selects the node. Or do you change Node.selectable in some manner?

You can customize the behavior at the end of a successful drag by implementing a “SelectionMoved” DiagramEvent listener. Customizing the behavior at the start of a drag or during a drag probably requires overriding a method.

But there are other tools that depend on selection. I assume you have checked all of them to make sure they can’t run in your app.