Options
All
  • Public
  • Public/Protected
  • All
Menu

Class RelinkingTool

Hierarchy

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.

Index

Constructors

constructor

Properties

fromHandleArchetype : GraphObject | null

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

    toHandleArchetype

Read-only handle : GraphObject | null

toHandleArchetype : GraphObject | null

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

    fromHandleArchetype

Methods

Override canStart

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

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

    Returns boolean

Protected Virtual copyLinkProperties

  • copyLinkProperties(reallink: Link | null, templink: Link): void
  • Make a temporary link look and act like the real Link being relinked. 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.

    since

    1.3

    Parameters

    Returns void

Override doActivate

  • doActivate(): void
  • Start the relinking operation.

    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.

    Returns void

Override doDeactivate

  • doDeactivate(): void
  • Finishing the linking operation stops the transaction, releases the mouse, and resets the cursor.

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

    Returns void

Override doMouseUp

  • doMouseUp(): void
  • 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.

    Returns void

Virtual doNoRelink

  • doNoRelink(existinglink: Link, toend: boolean): void
  • This method is called upon a mouse up when reconnectLink is not called.

    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.

    since

    1.7

    Parameters

    • existinglink: Link
    • toend: boolean

      If true, the user was trying to modify the link's "to" node and port.

    Returns void

Virtual reconnectLink

  • reconnectLink(existinglink: Link, newnode: Node | null, newport: GraphObject | null, toend: boolean): boolean
  • Modify an existing Link to connect to a new node and port.

    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

    doNoRelink

    Parameters

    • existinglink: Link
    • newnode: Node | null

      the Node to connect to or from.

    • newport: GraphObject | null

      the GraphObject port to connect to or from.

    • toend: boolean

      If true, this modifies the link's "to" node and port; otherwise it modifies the "from" node and port.

    Returns boolean

    true if successful.

Override updateAdornments

  • updateAdornments(part: Part): void