Page Index Toggle Pages: 1 Send TopicPrint
Hot Topic (More than 10 Replies) Multiple selection and cancel drag operation. (Read 6409 times)
rajesh_patil74
Full Member
***
Offline


I love YaBB 1G - SP1!

Posts: 220
Joined: Sep 3rd, 2009
Multiple selection and cancel drag operation.
Dec 21st, 2009 at 6:32am
Print Post  
Hi Stoyo

I have seen the Drag-Drop between two diagram controsl few days back.

I am also using Telrik Controls in my application and there latest control supports drag-drop for any control (control which captures mouse events also works with new telerik version).

I adpted this new controls for drag-drop between multiple controls. With Telrik Drag-Drop manager I can perform following actions -

1.  Dragging any node and dropping on any other control ( it doesn't matter whether the node/shape is selected or not).

2. When node is selected then Telrik drag-drop work well if I press the mouse button on adjustment handles.
Mouse down on adjustment handle allows me to resize my node or mouse down on center adjustment handle allows me to reposition the node ( This is as per my requirement)

Now, the issue is when I select multiple nodes and select the center or any adjustment handle for one of the node it starts repositioning all nodes. ( This is also ok for me)

But when my mouse button is down on one of the node (not on any adjustment handle) with mouse move events diagramlite starts re-positioing the control. At the same time Telerik control starts its drag operation. 
In this situation I want to cancel the Diagramlite reposition functionality.

Can you tell me how one can prevent re-positioning when multiple nodes are selected. There is no node modified event occurs when multiple nodes are selected.
  
Back to top
WWW  
IP Logged
 
rajesh_patil74
Full Member
***
Offline


I love YaBB 1G - SP1!

Posts: 220
Joined: Sep 3rd, 2009
Re: Multiple selection and cancel drag operation.
Reply #1 - Dec 21st, 2009 at 9:02am
Print Post  
Hi

Is there any possiblity that if writing following  statement I can disable the dragging of multiple items to change the postion?

this.diagram.selection.Locked = false;

I will be able to write statement in the code from where Telerik will initiates its drag operation.


- Rajesh
  
Back to top
WWW  
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Multiple selection and cancel drag operation.
Reply #2 - Dec 21st, 2009 at 10:24am
Print Post  
Perhaps the easiest way to do that is through a custom LinkShapesBehavior -derived class, whose StartDraw method returns null in the situations when drag-and-drop should start, otherwise returns base.StartDraw(). E.g. it could look like this

Code
Select All
public override InteractionState StartDraw(Point point)
{
	if (App.ShouldDragAndDrop)
		return null;
	return base.StartDraw(point);
}

diagram.CustomBehavior = new MyBehavior(diagram);
 



Setting item.Locked also deselects the item, so to lock all selected items:
Code
Select All
var selectedItems = new DiagramItemCollection(diagram.Selection.Items);
foreach (DiagramItem item in selectedItems)
	item.Locked = true;
 



I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
rajesh_patil74
Full Member
***
Offline


I love YaBB 1G - SP1!

Posts: 220
Joined: Sep 3rd, 2009
Re: Multiple selection and cancel drag operation.
Reply #3 - Dec 21st, 2009 at 10:47am
Print Post  
Hi Stoyo

I already tried the second approach.

foreach(Diagram item in diagram.Selection.Items)
item.locked = true;

First thing, applying for loop raises exception since setting the locked property removes the item for the collection ( Your code may work properly without exception since you stored the collection in separate variable)

Setting the locked property = true, removes the item from collection and the adjustment handles displayed on the screen also gets removed.
In my app, setting all items locked, seems that nothing is selected. ( Here i want to show the effect of droping multiple items on another control - )


The first approach is not working. The newly overriden method gets invoked when I start dragging when single node is selected or no node is selected. ( In single node selection also when dragging is done using adjustment handle, the function is not invoked.)

With multiple selection, new function doesn't get invoked ( independent of mouse postion .. it can be either of any node or any adjustment handle ).

Regards
Rajesh


  
Back to top
WWW  
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Multiple selection and cancel drag operation.
Reply #4 - Dec 21st, 2009 at 3:28pm
Print Post  
Hi Rajesh,

Ok, it seems starting to move the selection is something that works the same for all behaviors, and it does not happen in StartDraw but in OnMouseMove. I suppose you could check for drag-and-drop in an OnMouseMove override - if you detect drag-and-drop has started, just return, otherwise call the base OnMouseMove implementation.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
rajesh_patil74
Full Member
***
Offline


I love YaBB 1G - SP1!

Posts: 220
Joined: Sep 3rd, 2009
Re: Multiple selection and cancel drag operation.
Reply #5 - Dec 22nd, 2009 at 7:23am
Print Post  
Hi Stoyo

Following override function doesn't help at all

protected override void OnMouseMove(System.Windows.Input.MouseEventArgs e)
       {
           if (this.Selection.Items.Count > 1 )
               return;
        else
               base.OnMouseMove(e);
       }
  
Back to top
WWW  
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Multiple selection and cancel drag operation.
Reply #6 - Dec 22nd, 2009 at 1:09pm
Print Post  
Hi Rajesh,

I've meant you should override the BehaviorBase.OnMouseMove method, not the diagram's one, and assign the behavior instance to diagram.CustomBehavior.

Stoyan
  
Back to top
 
IP Logged
 
rajesh_patil74
Full Member
***
Offline


I love YaBB 1G - SP1!

Posts: 220
Joined: Sep 3rd, 2009
Re: Multiple selection and cancel drag operation.
Reply #7 - Dec 22nd, 2009 at 2:53pm
Print Post  
Hi Stoyo

Thanks for your response.
After overriding the method in custom Behavior it is working as required with one minor issue.

I set the App.ShouldDragAndDrop = true when Telerik control knows that dragging started

And app value is reset in MouseUp event.

The issue with this is that with every drag operation start minor movement is done for all selected item.

How I can fix this minor movement ?

Regards
Rajesh


  
Back to top
WWW  
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Multiple selection and cancel drag operation.
Reply #8 - Dec 22nd, 2009 at 3:48pm
Print Post  
Hi,

This could happen if OnMouseMove is called one or more times before App.ShouldDragAndDrop is set. Can't you determine earlier if drag and drop would start at that position?

Stoyan
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Multiple selection and cancel drag operation.
Reply #9 - Dec 22nd, 2009 at 3:50pm
Print Post  
... if the telerik drag and drop starts after the mouse moves at least for a few pixels, you could add a similar check to your OnMouseMove implementation to make sure the base code doesn't start any interaction before drag-and-drop has its chance to start.
  
Back to top
 
IP Logged
 
rajesh_patil74
Full Member
***
Offline


I love YaBB 1G - SP1!

Posts: 220
Joined: Sep 3rd, 2009
Re: Multiple selection and cancel drag operation.
Reply #10 - Dec 23rd, 2009 at 9:03am
Print Post  
Hi Stoyo

With following code I am able to achive the drag drop as per my requirement.

    public class MyBehavirour : LinkShapesBehavior
    {
       bool bRepositionItems = false;
       public MyBehavirour(Diagram diagram)
           : base(diagram)
       {
       }

       protected override bool OnMouseDown(System.Windows.Input.MouseButtonEventArgs e)
       {
           Point? point;
           bRepositionItems = true;
           point = new Point?(e.GetPosition(base.Diagram.DocumentPlane));
           if (base.Diagram.Selection.Items.Count > 1)
           {
               bRepositionItems = false;
               if (point.HasValue)
               {
                   foreach (UIElement element in UIElements(point.Value))
                   {
                       System.Windows.Shapes.Rectangle rectangle = element as System.Windows.Shapes.Rectangle;
                       if (rectangle != null)
                       {
                           if (rectangle.Tag is AdjustmentHandle)
                           {
                               bRepositionItems = true;
                               break;
                           }
                       }
                   }
               }
           }
           return base.OnMouseDown(e);
       }

       protected override void OnMouseMove(System.Windows.Input.MouseEventArgs e)
       {
           if (bRepositionItems)
               base.OnMouseMove(e);
       }

       protected override void OnMouseUp(System.Windows.Input.MouseButtonEventArgs e)
       {
           bRepositionItems = true;
           base.OnMouseUp(e);
       }

       private IEnumerable<UIElement> UIElements(Point _point)
       {
           return VisualTreeHelper.FindElementsInHostCoordinates(base.Diagram.DocumentPlane.GetPoi
nt(_point), base.Diagram.DocumentPlane);
       }
    }


Is it not possible that version 1.3 should provide one more property which disables draging of multiple items unless it is done by adjustment handles ?

-Rajesh
  
Back to top
WWW  
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Multiple selection and cancel drag operation.
Reply #11 - Dec 23rd, 2009 at 10:29am
Print Post  
We'll think of something.

Stoyan
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint