You can check between what kind of shapes the link is created and remove it if you need to do so. I will give you an example on how to cancel the connection between Actor and Actor shapes.
First - add LinkCreatedScript to your diagram and make it point a JavaScript function, here is mine declaration:
<ndiag:DiagramView ID="diagramView" runat="server" Style="left: 0px; width: 800px;
position: absolute; top: 0px; height: 505px" Behavior="DrawControls" BackColor="White"
AllowInplaceEdit="true" LinkCreatedScript="onLinkCreated" />
Now add the onLinkCreated function in the page head :
<script type="text/javascript">
function onLinkCreated(diagram, args) {
var link = args.getLink();
var shapeOrigin = link.getOrigin().getShape();
var shapeDestination = link.getDestination().getShape();
if (shapeDestination.getDisplayName() == 'Actor' && shapeOrigin.getDisplayName() == 'Actor') {
diagram.getLinks().remove(link);
alert('Cannot crate link between ' + shapeOrigin.getDisplayName() + ' and ' + shapeDestination.getDisplayName());
}
}
</script>
1. What we did is - we get the link that was just created from the args.
2. We get the Origin and Destination shapes from the link.
3. We then checked their display names and verify they are Actor and Actor.
4. We asked the diagarm object to remove a link, to be more specific - our link, the one that was just created.
I think there may be more elegant ways to achieve this, but currently this is the only I could think of.
Hope it helps somebody out there ...
No comments:
Post a Comment