Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Cancel dropping nodes in containers (Read 4402 times)
SavyCat
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 38
Joined: Sep 4th, 2007
Cancel dropping nodes in containers
Jan 31st, 2008 at 1:13pm
Print Post  
Hi guys, I cant see the preffered way of preventing a user from dropping a node into a container. Conversely how do you prevent a node from being dragged out of a container? I also need the node to go back to its previous location and or previous container. I cant seem to find any useful events for it; I noticed you could derive a new container class and over-ride some of the functions there; but after playing around with these Im just not convinced im doing what might have been intended.
Thanks for your guidance.
Best wishes
Mat
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Cancel dropping nodes in containers
Reply #1 - Jan 31st, 2008 at 1:50pm
Print Post  
Hi Mat,

Preventing a user from dropping a node into a container:

Code
Select All
private void diagram_NodeModifying(object sender, MindFusion.Diagramming.NodeValidationEventArgs e)
{
	if (diagram.GetNodeAt(e.MousePosition, true, true) is ContainerNode)
		e.Cancel = true;
}
 



Setting e.Cancel = true should automatically move the node back to its original position and container.

If you derive from ContainerNode, you could do something similar by returning false from OnDragOver and OnDragDrop.

To prevent a node from being dragged out of a container:

Code
Select All
childNode.Constraints.KeepInsideParent = true;
 



I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
SavyCat
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 38
Joined: Sep 4th, 2007
Re: Cancel dropping nodes in containers
Reply #2 - Jan 31st, 2008 at 2:06pm
Print Post  
Thats great, thanks Stoyan, you are a legend Smiley
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Cancel dropping nodes in containers
Reply #3 - Jan 31st, 2008 at 4:29pm
Print Post  
Grin
  
Back to top
 
IP Logged
 
Howard
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 1
Joined: Mar 25th, 2008
Re: Cancel dropping nodes in containers
Reply #4 - Mar 25th, 2008 at 10:51pm
Print Post  
Great solution, I had just spend about half an hour trying to prevent ContainerNode's from being added to other ContainerNode's (I don't want to allow nesting), I started by using the just released ContainerChildAdded( ) event but it doesn't allow canceling the addition.

I also started to see if I could use the UndoManager to accomplish this and it may actually have been a solution but it was starting to look a bit more like a hack (didn't seem to be a clean solution).

So finally I decided to hit the forum and sure enough, the answer was in this thread. For those that may be interested, the following code (based on Stoyo's) prevents the creation of nested ContainerNode's.

Code
Select All
private void myDiagram_NodeModifying(object sender, NodeValidationEventArgs e)
{
    // We don't allow nesting of Container Nodes, let's make sure we prevent this.
    if (((Diagram)sender).ActiveItem is ContainerNode)
    {
        if (myDiagram.GetNodeAt(e.MousePosition, true, true) is ContainerNode)
            e.Cancel = true;
    }
}
 

  
Back to top
 
IP Logged
 
MUDO
Junior Member
**
Offline



Posts: 90
Joined: Nov 29th, 2008
Re: Cancel dropping nodes in containers
Reply #5 - May 16th, 2009 at 11:13pm
Print Post  
Hi.

Thx for your code "(based on Stoyo's) prevents the creation of nested ContainerNode's"...

If you are dragging container "A" into container "B" this code is ok only if drop is permormed directly over container "B". If in "B" is any shape and drop is performed over it --> it doesnt work.

So I guess I should to use "GetNodesAt" function instead of "GetNodeAt" and iterate DiagramNodeCollection object which is returned by this function.

My two solutions:
1) - handling NodeModifying event
Code
Select All
 Private Sub fcDiagram_NodeModifying(ByVal sender As Object, ByVal e As MindFusion.Diagramming.NodeValidationEventArgs) Handles fcDiagram.NodeModifying
'preventing nesting of containers
   Select Case e.Node.GetType.Name
      Case "ClsMMContainerNode"
         Dim LoDiagramNodeCollection As DiagramNodeCollection = Me.fcDiagram.GetNodesAt(e.MousePosition)

         For Each LoNode As DiagramNode In LoDiagramNodeCollection
            If (LoNode.GetType.Name = "ClsMMContainerNode") And (Not LoNode.Equals(e.Node)) Then 'prevention of selfchecking
               e.Cancel = True
               Exit For
            End If
         Next
   End Select
End sub
 



2) - deriving from ContainerNode
Code
Select All
'overrided sub - when a diagram item is being dragged over this node
    Public Overrides Function OnDragOver(ByVal item As MindFusion.Diagramming.DiagramItem) As Boolean
        If item.GetType.Name = "ClsMMContainerNode" Then
            Return False
        Else
            Return MyBase.OnDragOver(item)
        End If
    End Function
'overrided sub - when a diagram item is dropped over this node
    Public Overrides Function OnDropOver(ByVal item As MindFusion.Diagramming.DiagramItem) As Boolean
        If item.GetType.Name = "ClsMMContainerNode" Then
            Return False
        Else
            Return MyBase.OnDropOver(item)
        End If
    End Function
 



In first case there is presented also "feature" - Setting e.Cancel = true should automatically move the node back to its original position and container.

In second case node is not returned back to original position.

It seems MyBase.OnDropOver performs any other operations because if I return true instead of MyBase.OnDropOver nothing is happen.

Any comment guys? Any suggestion for improoving procedure "Cancel dropping nodes in containers"? Smiley

Thx.

...MUDO...
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Cancel dropping nodes in containers
Reply #6 - May 18th, 2009 at 7:43am
Print Post  
Hi,

Solution 1 looks good enough. If you prefer solution 2 and need to return the modified node to its original position, try calling diagram.Interaction.Cancel(). Returning false from OnDropOver tells the diagram it should ignore this container and notify other containers below it. If all containers at this location return false, the interaction is still completed successfully and the dropped node will be placed under the mouse, but won't be added to a container.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
ilafon
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 9
Joined: May 24th, 2009
Re: Cancel dropping nodes in containers
Reply #7 - Jun 13th, 2009 at 1:44am
Print Post  
Hi,

I have overrided the OnDropOver method in my derived ContainerNode class.
As you've mentionned in this thread, I'm using the
Parent.Interaction.Cancel(Parent); to cancel the operation and get the node back to its original position.

This is working perfectly if one node is selected and dropped. But if multiple nodes are selected and dropped, cancelling the operation does not move the nodes back to their original position. The nodes stay at the dropping position.

Is there a way to have all selected nodes back to their original position when the operation is cancelled?

Thanks in advance.

Isabelle.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Cancel dropping nodes in containers
Reply #8 - Jun 14th, 2009 at 10:37am
Print Post  
Hi Isabelle,

Unfortunately the nodes have already been placed at their new position when OnDropOver is called, and the interaction state is marked as complete. Calling Interaction.Cancel() at that point works only accidentally for a single selected node.

You could cancel the interaction and return the nodes to their original positions from a handler of the SelectionMoving event. The validation code could be localized in your custom container class to some extent by running it from an OnDragOver override, setting Selection.Tag to a boolean flag indicating whether the operation should be cancelled, and cancelling it from SelectionMoving when the flag is set.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint