Link Modified


#1

Hi ,
In my diagram I have few type of object … like Square, rectangle, dimond etc…
I want the user to be able to connect only to objects of same type, Connect from a circle to circle not from Circle to a Square.
Also I want the user to be able to modify the link only to connect to same type of object .If ther user tries to connect a circle to Square… I need to give a message to the user that it cannot be done and reset the link to where it was earlier( with out using undo or any thing).
Thanks
rAjesh


#2

Basically you need to customize the implementation of valid links.
You can either override GoPort.IsValidLink or you can override GoToolLinkingNew and GoToolRelinking.IsValidLink, depending on where you want the code to be and when you want that behavior to take effect. There is some general discussion in both the User Guide and in the FAQ.
If you really need to display an error message when drawing or reconnecting a link fails because of type mismatches, you will probably want to override GoToolLinkingNew.DoNoNewLink and GoToolRelinking.DoNoRelink. Depending on whether GoToolLinking.Forwards is true, the port that is at the point where the user did a mouse up is either the first or the second argument. If it is non-null, then you can use it to put up an appropriate message box. When it is null, the user must have done a mouse up not over a port that is “invalid”.


#3

Do you have any code sample which shows how to override GoToolLinkingNew and relinking

Thanks
rajesh


#4

You might also override CreateLink and do this there.
Because otherwise you would have to create your own port class to be able to do this.
I did the following:
public override IGoLink CreateLink(IGoPort from, IGoPort to)
{
if (from != null && to != null)
{
if (cTool.CanCreateValidLink(from,to) || OverrideCreateValidLink)
{
[…]

CanCreateValidLink tests for the types.
You might ask:

//excerpt from cTool class
public static bool CanCreateValidLink(IGoPort portFrom, IGoPort portTo)
{
bool bValidLink = true;
GoObject objFromNode = portFrom.Node.GoObject;
GoObject objToNode = portTo.Node.GoObject;

//now you might just ask if they can connect or not.

if they are not of the same type just return null.


#5

Demo1 replaces the standard linking tools with custom ones. Look in GraphView.cs. It does the subclassing for a different purpose, of course, but the calls to GoView.ReplaceMouseTool would be the same.
(You won’t need to subclass GoView to do what you want.)