Side effects on adding or removing nodes

In my gojs-palette, i have 5 nodes (Start, End, Filter, Email, Decision), so when i drag those to gojs-diagram i need to check

  1. If Start or End node was dragged to diagram, need to check whether there is already a Start or End exists and need to restrict that to add in diagram if exists
  2. When ever a new Start node is dragged to diagram, need to automatically attach a Filter node to it.
  3. If a node is double clicked/selected node is Deleted, need to get that node’s Key and need to call a function
  4. Need to show link label options if the links are originating from Decision node

Why not change your design so that there is always a Start node and an End node, and make them undeletable and uncopyable by setting their deletable and copyable properties to false? That way you wouldn’t need to have Start or End nodes in your palette and you wouldn’t have to worry about possible duplication. The Flowgrammer sample does that (and a lot more): Flowgrammer

Anyway, I’ll answer your questions as written. I’ll assume the user is dragging nodes from a Palette.

  1. Implement an “ExternalObjectsDropped” DiagramEvent listener that looks to see if any of the dropped nodes (in the DiagramEvent.subject collection) are Start or End nodes. If so – look to see if there is more than one Start or End node, and if there is, remove it from the Diagram.
  2. If the dropped node is a Start node and it is the only one present, call Model.addNodeData and GraphLinksModel.addLinkData to add a node and a link to the diagram.
  3. Define a doubleClick event handler on your node template(s) that calls CommandHandler.deleteSelection.
    Then you can either call your function, or more generally (to handle other ways in which nodes might be deleted, e.g. via the Delete key) implement a Model Changed listener to see if a transaction or undo or redo has just happened, and if so, see if any nodes have been removed from the model. For those node data objects that were removed, call your function.
  4. The FlowChart sample demonstrates this: Flowchart See how the showLinkLabel function is called and how it is defined. Notice that the link label starts off not visible by default.