DND in a tree: how to prevent the item being dragged from being selected? [message #721967] |
Sat, 03 September 2011 16:29  |
Eclipse User |
|
|
|
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 #723657 is a reply to message #723563] |
Fri, 09 September 2011 01:06  |
Eclipse User |
|
|
|
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;
}
}
}
|
|
|
Powered by
FUDForum. Page generated in 0.04489 seconds