Is it possible to detect when a LinkingTool doDeactivate() method has finished if no link has been drawn (i.e. the user has quit drawing the link)?
I’m asking because I want to remove some LinkLabel nodes in case the user quits drawing the link.
I know that a RolledBackTransaction occurs, but from the documentation: “As a general rule, you should not make any changes to the model or any of its data in a listener for any Transaction ChangedEvent.”
For some reason, I am unable to remove a link label node from the model. This is my code:
LinkLabelLinkingTool.prototype.doNoLink = function (fromNode, fromPort, toNode, toPort) {
if (fromNode.category !== 'LinkLabel') return;
if (fromNode !== null) {
let diagram = fromNode.diagram;
let model = diagram.model;
let targetKey = fromNode.data.key;
// need to find the actual link on which the LinkLabel node is located
let link = undefined;
diagram.links.each(l => {
if (l.data !== null && _.some(l.data.labelKeys, k => k === targetKey)) {
link = l;
}
});
diagram.startTransaction('removeLinkLabel');
model.removeLabelKeyForLinkData(link.data, fromNode.data.key);
model.removeNodeData(fromNode.data);
diagram.commitTransaction('removeLinkLabel');
console.log(model.nodeDataArray)
console.log(model.nodeDataArray.length)
}
};
The LinkLabel node is still present on the link after it should have been removed. Also, in the console.log - it initially displays an array of 2 elements (which should be correct), but upon expanding, it shows also the node that should have been removed…,
I’ve made a small screen recording to show this, it can be downloaded from here.
Unfortunately, I can still see the node that acts as the linkLabel… Should the Link.data.LabelKeys property be equal to [null] when the only linkLabel is removed?
I just tried selecting a link in Links to Links, and then:
var link = myDiagram.selection.first();
var src = link.labelNodes.first();
myDiagram.remove(src);
And sure enough both the label Node on that Link disappeared, along with the Link that I had drawn earlier coming out of that label node.
And a “save” confirmed that that label node had been removed from the Model.nodeDataArray and that its key had been removed from the link data’s “labelKeys” Array.