Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » DND in a tree: how to prevent the item being dragged from being selected?
DND in a tree: how to prevent the item being dragged from being selected? [message #721967] Sat, 03 September 2011 20:29 Go to next message
McNuggets Missing name is currently offline McNuggets Missing name
Messages: 12
Registered: August 2011
Junior Member
Hi,

When you enable drag n' drop on a org.eclipse.swt.widgets.Tree, the item being dragged becomes selected when you start dragging it. I can understand there may be some valid reasons for that behaviour but I would like it not to happen because I have implemented some SelectionListener that I would like not to be executed when an item is dragged. How to do that?

This behaviour is an annoyance when you enable editing support upon a single click.

Best regards,
Re: DND in a tree: how to prevent the item being dragged from being selected? [message #722314 is a reply to message #721967] Mon, 05 September 2011 11:09 Go to previous messageGo to next message
Vijay Raj
Messages: 608
Registered: July 2009
Senior Member
It is Annoying indeed Smile
A crude solution would be to record selections and process them on mouse up only...

Note:Assuming you are only considering selections by mouse only.if u want all type of selections to be considered then may be you have to track mouse down also,if mouse down not present then process selection as normal(hence Crude)


---------------------
why, mr. Anderson, why, why do you persist?
Because I Choose To.
Regards,
Vijay

[Updated on: Tue, 06 September 2011 07:31]

Report message to a moderator

Re: DND in a tree: how to prevent the item being dragged from being selected? [message #723563 is a reply to message #722314] Thu, 08 September 2011 20:01 Go to previous messageGo to next message
McNuggets Missing name is currently offline McNuggets Missing name
Messages: 12
Registered: August 2011
Junior Member
Hello,

vijay wrote on Mon, 05 September 2011 07:09
A crude solution would be to record selections and process them on mouse up only...

Do you have an idea how I could do that?
Re: DND in a tree: how to prevent the item being dragged from being selected? [message #723657 is a reply to message #723563] Fri, 09 September 2011 05:06 Go to previous message
Vijay Raj
Messages: 608
Registered: July 2009
Senior Member
I presume u already have a selection listener of the tree,now add mouse listener also and in mousedown and mouseup methods set mousedown and mouseup flags(you have to reset them in their respective opposite methods,the correct logic would be as per your requirement and mousedown,selection and mouseup sequence)

Just to give u a direction ,this is not the solution and may not work,u have to test it and perfect it
public class DNDSelectionFix implements SelectionListener, MouseListener {

	private boolean mouseDown;
	private boolean mouseUp;
	private boolean selected;
	private Tree tree;

	@Override
	public void widgetDefaultSelected(SelectionEvent e) {
		// TODO Auto-generated method stub

	}

	@Override
	public void widgetSelected(SelectionEvent e) {
		if (!mouseDown) {
			yourMethod();
		}
		else{
			selected = true;	
		}
		mouseDown = false;
		mouseUp = false;
	}

	private void yourMethod() {
		//if tree
		TreeItem[] selection = tree.getSelection();
		//if TreeViewer then get the selection from the treeviewer
	}

	@Override
	public void mouseDoubleClick(MouseEvent e) {
		// TODO Auto-generated method stub

	}

	@Override
	public void mouseDown(MouseEvent e) {
		mouseDown = true;
		mouseUp = false;
	}

	@Override
	public void mouseUp(MouseEvent e) {
		mouseUp = true;
		mouseDown = false;
		if(selected)
		{
			yourMethod();
			selected=false;
                        mouseUp = false;
		        mouseDown = false;
		}
	}
}


---------------------
why, mr. Anderson, why, why do you persist?
Because I Choose To.
Regards,
Vijay
Previous Topic:Background image on Composite
Next Topic:Obtaining HTML String for fully rendered HTML given URL
Goto Forum:
  


Current Time: Sat Oct 25 23:49:23 GMT 2014

Powered by FUDForum. Page generated in 0.07329 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software