This is a migrated thread and some comments may be shown as answers.

Managaing connection between items

13 Answers 309 Views
Diagram
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Yoan
Top achievements
Rank 1
Yoan asked on 11 May 2012, 11:51 AM
Hello , 

is there a way to manage the connections between items , for example I want user not to be able to create more than "n" connections to an item , one thing that came in my mind was to handle the connection created event , but I did not suceed in handling it , because there wasn't such an event. Any ideas ? 

Best regards,
Yoan

13 Answers, 1 is accepted

Sort by
0
Alex Fidanov
Telerik team
answered on 14 May 2012, 08:20 AM
Hi Yoan,

 Currently, there is no straightforward way to achieve this. I have logged this as a feature request in PITS here so you can track its progress.

Greetings,
Alex Fidanov
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Shrikant
Top achievements
Rank 1
answered on 14 May 2012, 01:23 PM
Hi Alex,
What about connection created event ?
When User creates a connection between two shapes.
0
Alex Fidanov
Telerik team
answered on 17 May 2012, 03:14 PM
Hello,

 The closest event to what you are looking for is the ItemsChanged event, however it is raised too early to handle this behavior.

Regards,
Alex Fidanov
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Shrikant
Top achievements
Rank 1
answered on 21 May 2012, 07:04 AM
Hi Alex,
you are right, the event get raised too early & for each item change. So this is not a good choice
You need to do something for this, there should be unique Events
1. When your creating connections
2. When connection created
3. double or single click events for connection
4. connection modified or modifying


These events are more important when working on business application, I can not stay only with Item Changed event & writes my whole logic there.

Looking for better reply.
Thanks
0
Yoan
Top achievements
Rank 1
answered on 21 May 2012, 12:09 PM
Hi , sorry for late reply , which actually is part of an answer. I managed to do with this problem / not in the most beatiful way / , but after all it is some solution at this time. I really hope soon there will be unique events for each manipulation. My solution to those who need it :

First , we register for the items changed event , which captures the moment of creating a connection , after this we bind the target of the connection in two way mode to a property of the ViewModel , called TargetShape. Each time a new connection is created we remove the bindings for the old connections , and we handle the event in this way only if the diagram has already been loaded , because if we handle the event during serialization the targets become "null"s because of the binding. That is my way of managing with connections , I have also made an event "TargetShapeChanged" , through which to do some other operations.

Hope you like it , and use it if do not know other possibilities :)

private void diagram_ItemsChanged(object sender, DiagramItemsChangedEventArgs e)
       {
           if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add)
           {
               if (e.NewItems != null && e.NewItems.Count() > 0)
               {
                   if (e.NewItems.FirstOrDefault() is RadDiagramConnection)
                   {
                       if (!isDiagramReloaded)
                       {
                           RadDiagramConnection con = (RadDiagramConnection)e.NewItems.FirstOrDefault();
 
                           foreach (RadDiagramConnection connection in diagram.Connections)
                           {
                               IShape target = (IShape)connection.Target;
                               connection.ClearValue(RadDiagramConnection.TargetProperty);
                               connection.Target = target;
                           }
 
                           ViewModel.TargetShape = null;
 
                           Binding targetBinding = new Binding("TargetShape");
                           targetBinding.Source = this.DataContext;
                           targetBinding.Mode = BindingMode.TwoWay;
                           con.SetBinding(RadDiagramConnection.TargetProperty, targetBinding);
                       }
                   }
               }
           }
0
Alex Fidanov
Telerik team
answered on 22 May 2012, 03:10 PM
Hi,

 For the official release, we will be exposing two events, which can be handled. They will be raised respectively in the beginning and in the end of each connection manipulation - when creating a connection, when attaching, detaching from shape or when changing the end points of a floating connection. You will be able to handle these events and prevent the action from taking place. Stay tuned for the release.

Greetings,
Alex Fidanov
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Christian
Top achievements
Rank 2
answered on 03 Aug 2012, 01:48 PM
But the new event never have Target on its arguments.

Regards
0
Christian
Top achievements
Rank 2
answered on 03 Aug 2012, 07:17 PM
This is the code that I use to solve the Target Problem:
private void diagram_ConnectionManipulationCompleted(object sender, ManipulationRoutedEventArgs e)
{
 var connectedShapes = diagram.GetOutgoingConnectionsForShape(e.Shape).Select(c => c.Target);           
 var test = connectedShapes.FirstOrDefault().Content;
 
 e.Connection.Target = connectedShapes.FirstOrDefault();
}

Hope it helps. 
0
Alex Fidanov
Telerik team
answered on 07 Aug 2012, 07:12 AM
Hello,

 The event arguments provide some properties to determine the nature of the action that this event describes. For example, you can use the e.ManipulationStatus value to check whether the connections has been attached to a shape, detached from a shape or moved as a floating connection. If you need to check the target shape, you can use the e.Connector property, which represents the connector of the target. The connector itself has a Shape property that you can use to get the target shape reference.

Regards,
Alex Fidanov
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Gary Paul
Top achievements
Rank 1
answered on 13 Aug 2012, 08:24 PM
private void diagram_ConnectionManipulationCompleted(object sender, ManipulationRoutedEventArgs e)
{
    e.Handled = TestConnection(e.Connection, e.Connector);
}
 
private bool TestConnection(IConnection connection, IConnector targetConnector)
{
    var connector = connection;
    var sourceShape = connection.Source;
    var sourceConnectorName = connection.SourceConnectorPosition;
    var targetShape = targetConnector.Shape;
    var targetConnectorName = targetConnector.Name;
 
    return false;
}

 

 I setting up to test if a connection is legal. I have the info I need but how to I cancel the connection? I have tried setting Handled = true and false but the connection is always made. I would like return false from TestConnection and have the connection not occur.

It would be very nice to show an X over the target Connector if it is not a legal connection.

 

 

 

 

0
Alex Fidanov
Telerik team
answered on 16 Aug 2012, 07:01 AM
Hello,

 I believe you have in mind the scenario where you create a connection using a shape's connector and try to attach it to another shape. You do can handle the event args of the ConnectionManipulationCompleted event (e.Handled=true). However, please note that this action only determines whether the connection will be attached or not to the target shape. If you check, you would see that the connection is not attached. However, this would not revert the creation of the connection. If you want this as well, I would recommend removing the connection as a whole using the diagram remove methods or using the Undo mechanism.

Greetings,
Alex Fidanov
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Gary Paul
Top achievements
Rank 1
answered on 16 Aug 2012, 01:41 PM
I will attempt to make this work, however, I still do not see a solution for the mouse over requirement of showing that a connection is invalid.
As a feature enhancement I would like to see more complete information in the following scenarios:

Connector Mouse Over: Raise a MouseOver Event providing these three properties at the root of the EventArgs:
1) Source Connector (the connector on the other end of the Connection)
2) The Connection itself
3) The Target Cnnector (the connector the Mouse is over)
 
ConnectionManipulation Completed should allow you to fail the connection and remove it from the diagram without addtional code.

All in all I'm very happy with the Diagram Control, however there are many areas for it to mature in.

Thanks to the team for all their good work!

G
0
Tina Stancheva
Telerik team
answered on 17 Aug 2012, 12:10 PM
Hello Gary,

I will wrap up our discussion here as well, in case the someone else encounters the same issues:

First, we in order to provide visual feedback about a connector while it is active/inactive, the RadDiagramConnector.ActivationChangedEvent should be used. However as it doesn't allow you to cancel a connection, we've logged a feature request to provide a preview event to allow you to cancel a connection from attaching to a connector and will provide information about what is activating the connector.

In the meantime you can try the approach demonstrated in the attached solution - the connectors are validated, visual feedback is provided for the invalidated connectors and one connector can only be attached to one connection.

All the best,
Tina Stancheva
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
Diagram
Asked by
Yoan
Top achievements
Rank 1
Answers by
Alex Fidanov
Telerik team
Shrikant
Top achievements
Rank 1
Yoan
Top achievements
Rank 1
Christian
Top achievements
Rank 2
Gary Paul
Top achievements
Rank 1
Tina Stancheva
Telerik team
Share this question
or