GoJS® Diagramming Components
version 1.7.26 for JavaScript/HTML
by Northwoods Software®

## Class RelinkingTool

Extends LinkingBaseTool. The RelinkingTool allows the user to reconnect an existing Link if the Link.relinkableTo and/or Link.relinkableFrom properties are true.

For a general discussion of validation, see Introduction to Validation.

By default an instance of this tool is installed as a mouse-down tool in the Diagram.toolManager as the ToolManager.relinkingTool.

This tool makes use of two Adornments, each including a relink handle (potentially one for each end of the link), shown when a link is selected.

This tool conducts a transaction while the tool is active. A successful relinking will result in a "LinkRelinked" DiagramEvent and a "Relinking" transaction.

## Constructor Summary Details

Name | Description
--- | ---
RelinkingTool() | You do not normally need to create an instance of this tool because one already exists as the ToolManager.relinkingTool, which you can modify.More... The Tool.name of this tool is "Relinking".

## Properties Summary Details

Name, Value Type | Description
--- | ---

fromHandleArchetype
{GraphObject}

Gets or sets a small GraphObject that is copied as a relinking handle for the selected link path at the "from" end of the link.More... By default this is a Shape that is a small blue diamond. Setting this property does not raise any events.

Here is an example of changing the default handle to be larger green triangles:

    myDiagram.toolManager.relinkingTool.toHandleArchetype =
      $(go.Shape, "Triangle",
        { width: 10, height: 10, fill: "limegreen", segmentIndex: 0 });

See also:

- toHandleArchetype

handle {GraphObject} | This read-only property returns the GraphObject that is the tool handle being dragged by the user.More... This will be contained by an Adornment whose category is "RelinkFrom" or "RelinkTo". Its Adornment.adornedPart is the same as the originalLink.

toHandleArchetype
{GraphObject}

Gets or sets a small GraphObject that is copied as a relinking handle for the selected link path at the "to" end of the link.More... By default this is a Shape that is a small blue diamond. Setting this property does not raise any events.

Here is an example of changing the default handle to be larger orange triangles:

      myDiagram.toolManager.relinkingTool.toHandleArchetype =
      $(go.Shape, "Triangle",
        { width: 10, height: 10, fill: "orange", segmentIndex: -1 });

See also:

- fromHandleArchetype

Properties borrowed from class LinkingBaseTool:
  isForwards, isUnconnectedLinkValid, linkValidation, originalFromNode, originalFromPort, originalLink, originalToNode, originalToPort, portGravity, portTargeted, targetPort, temporaryFromNode, temporaryFromPort, temporaryLink, temporaryToNode, temporaryToPort
Properties borrowed from class Tool:
  diagram, isActive, isEnabled, name, transactionResult

## Method Summary Details

Name, Return Type | Description
--- | ---

canStart()
{boolean}

This tool can run when the diagram allows relinking, the model is modifiable, and there is a relink handle at the mouse-down point.More...

This method may be overridden, but we recommend that you call this base method.

Returns:
{boolean}

copyLinkProperties(reallink, templink)
1.3

Make a temporary link look and act like the real Link being relinked.More... By default this method copies many of the routing-oriented properties from the LinkingBaseTool.originalLink to the LinkingBaseTool.temporaryLink.

This method may be overridden, but we recommend that you call this base method. Please read the Introduction page on Extensions for how to override methods and how to call this base method.

Parameters:
{Link} reallink
{Link} templink

doActivate()

Start the relinking operation.More...

Find the relink handle by calling Tool.findToolHandleAt looking for either the "RelinkFrom" adornment or the "RelinkTo" adornment, saving the result in handle.

This starts a transaction, captures the mouse, and sets the cursor.

The value of isForwards is set depending on the category of the relink handle found. The LinkingBaseTool.originalLink property and various "Original..." port and node properties are set too. The temporary nodes and temporary link are also initialized.

This method may be overridden, but we recommend that you call this base method.

doDeactivate() | Finishing the linking operation stops the transaction, releases the mouse, and resets the cursor.More... This method may be overridden, but we recommend that you call this base method.

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.More...

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.

doNoRelink(existinglink, toend)
1.7

This method is called upon a mouse up when reconnectLink is not called.More...

This method may be overridden. By default this method does nothing. If you want to successfully perform any side-effects, you will need to set Tool.transactionResult to a string; otherwise this tool's transaction will be rolled-back. Please read the Introduction page on Extensions for how to override methods and how to call this base method.

Parameters:
{Link} existinglink
{boolean} toend
  If true, the user was trying to modify the link's "to" node and port.

reconnectLink(existinglink, newnode, newport, toend)
{boolean}

Modify an existing Link to connect to a new node and port.More...

This method may be overridden, but we recommend that you call this base method. Please read the Introduction page on Extensions for how to override methods and how to call this base method.

See also:

- doNoRelink

Parameters:
{Link} existinglink
{Node} newnode
  the Node to connect to or from.
{GraphObject} newport
  the GraphObject port to connect to or from.
{boolean} toend
  If true, this modifies the link's "to" node and port; otherwise it modifies the "from" node and port.

Returns:
{boolean} true if successful.

updateAdornments(part)

Show an Adornment for each end of the Link that the user may reconnect.More... The Adornment may have a copy of fromHandleArchetype and/or toHandleArchetype.

This method may be overridden.

Parameters:
{Part} part

Methods borrowed from class LinkingBaseTool:
  copyPortProperties, doMouseMove, findTargetPort, isInSameNode, isLinked, isValidCycle, isValidFrom, isValidLink, isValidTo, setNoTargetPortProperties
Methods borrowed from class Tool:
  cancelWaitAfter, canStartMultiTouch, doCancel, doKeyDown, doKeyUp, doMouseDown, doMouseWheel, doStart, doStop, doWaitAfter, findToolHandleAt, isBeyondDragSize, standardMouseClick, standardMouseOver, standardMouseSelect, standardMouseWheel, standardPinchZoomMove, standardPinchZoomStart, standardWaitAfter, startTransaction, stopTool, stopTransaction