RelinkingTool: unconnected links and doNoRelink()

Hi, i extended the method doNoRelink of the relinkingTool to create a new element when the user finish the link drag operation.

let relinkingTool: RelinkingTool = this.diagram.toolManager.relinkingTool;
let modelEditor = this;
relinkingTool.doNoRelink = function (existingLink, toend) {
   go.RelinkingTool.prototype.doNoRelink.call(relinkingTool);
   createJunction(modelEditor, existingLink, toend);
};

The extension is working well. The problem arise when i want to allow disconnected links in the relinking tool.

When I enable this feature

'relinkingTool.isUnconnectedLinkValid': true

the method doNoRelink() is not invoked when the user finish the drag operation without a valid target port.

Thanks, Dario

Furthermore, when dragging a link does connect with valid ports, there’s no call to RelinkingTool.reconnectLink, either. (RelinkingTool.doMouseUp calls either reconnectLink or doNoRelink.)

You could implement a “LinkRelinked” DiagramEvent listener.

Sorry but i don’t understand your response

The api say:

doMouseUp()
A mouse-up ends the relinking operation; if there is a valid targetPort nearby, this modifies the old link to connect with the target port.

A successful relinking calls reconnectLink to actually change the link. The “LinkRelinked” DiagramEvent is raised with the link as the DiagramEvent.subject and with the now-disconnected original port as the DiagramEvent.parameter. If the link was not reconnected, this calls doNoRelink. In any case this stops the tool.

A failure to find a valid target port results in no changes and no DiagramEvent.

This method may be overridden, but we recommend that you call this base method. You might find it easier to override reconnectLink. It is actually most common to implement a “LinkRelinked” DiagramEvent listener on the Diagram.

My question is:

Why the method doNoRelink is not invoked when the mouseUp() finish when there isn’t a valid port?

Thanks.

Your quotes are about the RelinkingTool, not about the DraggingTool. The latter is what is actually running when dragging a Link.

I think you’re the first person to want that behavior. I suppose we should consider it. That means calling either reconnectLink as well as doNoRelink.

To confirm if i’m right
when the value of ‘relinkingTool.isUnconnectedLinkValid’ is false, the tool that is running is RelinkingTool,
when the value of ‘relinkingTool.isUnconnectedLinkValid’ is true, the tool that is running is DraggingTool

Is this ok?

Thanks, Dario

Well, normal dragging is handled by the DraggingTool and relinking by moving a relinking handle is handled by the RelinkingTool. Dragging a Link when DraggingTool.dragsLink is true is handled by the DraggingTool, but that DraggingTool calls methods on the RelinkingTool. Basically you’re asking us to have it call a few more methods of the RelinkingTool.

I looked into potentially calling RelinkingTool.reconnectLink and RelinkingTool.doNoRelink from DraggingTool when DraggingTool.dragsLink is true and the user is dragging a link.

There are some problems with trying to do so.

First is that those two RelinkingTool methods take a boolean “toend” property so that when the method is called you know which end of the link was reconnected or which failed to reconnect. But the DraggingTool will often disconnect and/or reconnect both ends of the link, not just one end.

Second, the meaning of having RelinkingTool.doNoRelink be called would be different. In the typical situation, it would be valid to connect to nothing, so one would not expect to call doNoRelink at all. Instead, all link drags would result in calls to reconnectLink.

Third, I’m wary of the potential confusion and additional interdependencies between the two tools.

Thank you very much Walter. Maybe I need to rethink my solution.

Can you say me if this solution is right or there is a better possibility?

1- When the user drop a shape from stencil, we create a node with disconnected links.

2- The user drags the link end over other link.

3- When the user ends the drag operation, a new node is build, replacing the original link by two new links and connecting the link that had been dragged to the new node.

To do this, i am doing an override of the method doNoRelink of the relinking tool. The method finds the nearest link to the mouse up point and does all the tasks.

The problem arises when i want to allow disconnected links in the relinking tool (relinkingTool.isUnconnectedLinkValid: true) to allow to the user drags the end link to other position. When i enable this feature, the method doNoRelink is never invoked.

I couldn’t find other method to override to give support to this feature.

Again, thank you very much for your time.

Dario.

Is RelinkingTool.isUnconnectedLinkValid true in your app? If so, maybe you should be overriding RelinkingTool.reconnectLink instead.

A completely different possibility is to add label Nodes to each of your Links. You can see the simplest case of this at Links to Links. That combined with not setting RelinkingTool.isUnconnectedLinkValid to true would mean a call to reconnectLink and a “LinkRelinked” DiagramEvent when relinking to a Link, or a call to doNoRelink when the user does not reconnect a link to a link.

Overriding the method reconnectLink did the work.

Thank you very much Walter, excellent support.