Disable a particular node in palette window

Hi Team,

If Start or End node is dragged and dropped once from the palette window to the myDiagram window, then I want that these two nodes should get disabled in the palette window, so that it cannot be dragged second time.

How can we implement this functionality.

In the target Diagram you could implement an “ExternalObjectsDropped” DiagramEvent listener that looks at the Diagram.selection or the whole Diagram.nodes collection to see if there is a start or an end node. If there is, remove the corresponding node from the palette.

I don’t want to remove the Start or End node from the palette, I only want that these nodes should be unmovable or inactive, so that they cannot be moved for the second time. Please suggest.

The normal design is to remove the “used” items, so that the user won’t be tricked into thinking that those items are still options to be dragged.

But if you want to leave them, that’s fine – just make them not Part.copyable. I would still think that you would want to show them as disabled somehow, perhaps by changing the color of a Shape or the opacity of the whole Part.

Any sample code for this. Please share.

We don’t have any samples that do exactly what you want. (As I implied earlier, your request is unusual.) But there are many examples of everything that you need to do throughout the http://gojs.net/latest/intro and http://gojs.net/latest/samples. Just search all of the files for the particular event handler and properties that I mentioned.

Hi walter,

I wrote a code block using the event ‘ExternalObjectsDropped’ on diagram.addDiagramListener and able to restrict the user from dropping the Start and End node on myDiagram window for multiple time.

myDiagram.addDiagramListener(“ExternalObjectsDropped”, function(e){
var sel = e.diagram.selection;
var elem = sel.first();
var selectText = elem.findObject(“TEXT”); // Name of the TextBlock.
var selectShape = elem.findObject(“SHAPE”); // Name of the Shape.
myDiagram.remove(selectShape.part);

});

The user will get the alert and the myDiagram.remove(selectShape.part) will remove the selected node from the myDiagram.

Thanks.

I see some issues that your code raises.

Unless you have set the Diagram.maxSelectionCount of your Palette to 1, the user might drag and drop more than one item. So you need to iterate over the e.diagram.selection, not just get the first() dropped Part.

You haven’t really used selectText or selectShape to decide if it’s a “Start” or an “End” node.

“selectShape.part” is the same value as “elem”.