Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » A double click on a org.eclipse.swt.custom.TreeCursor isn't detected
A double click on a org.eclipse.swt.custom.TreeCursor isn't detected [message #1067280] Mon, 08 July 2013 04:04
Denis Aristov is currently offline Denis Aristov
Messages: 9
Registered: March 2013
Location: Moscow
Junior Member
When I select an item and then double click it the method mouseDoubleClick() will be called, but when I double click an item which wasn't selected previously then it won't be called. Why? I can hardly believe that this is a bug because this operation/situation seems to be elementary and must be widely used.

To reproduce it execute the source code below:

import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.*;
import org.eclipse.swt.events.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;

public class DoubleClickOnATreeCursor {

    public static void main(String[] args) {
        Display display = new Display();
        Shell shell = new Shell(display);
        shell.setLayout(new GridLayout());

        // create a a tree with 3 columns and fill with data
        final Tree tree = new Tree(shell, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION);
        tree.setLayoutData(new GridData(GridData.FILL_BOTH));
        tree.setHeaderVisible(true);
        TreeColumn column1 = new TreeColumn(tree, SWT.NONE);
        TreeColumn column2 = new TreeColumn(tree, SWT.NONE);
        TreeColumn column3 = new TreeColumn(tree, SWT.NONE);

        for (int i = 0; i < 9; i++) {
            TreeItem item = new TreeItem(tree, SWT.NONE);
            item.setText(new String[] { "root " + i + " 0", "root " + i + " 1", "root " + i + " 2" });
            for (int j = 0; j < 9; j++) {
                TreeItem item2 = new TreeItem(item, SWT.NONE);
                item2.setText(new String[] { "child " + j + " 0", "child " + j + " 1", "child " + j + " 2" });
                TreeItem current = item2;
                for (int k = 0; k < 5; k++) {
                    TreeItem item3 = new TreeItem(current, SWT.NONE);
                    item3.setText(new String[] { "descendent " + k + " 0", "descendent " + k + " 1", "descendent " + k + " 2" });
                    current = item3;
                }
            }
        }
        column1.setWidth(200);
        column2.setWidth(100);
        column3.setWidth(100);

        final TreeCursor cursor = new TreeCursor(tree, SWT.NONE);

        cursor.addMouseListener(new MouseListener() {

            @Override
            public void mouseDoubleClick(MouseEvent e) {
                // TODO Auto-generated method stub
                System.out.println("mouseDoubleClick");
            }

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

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

        shell.pack();
        shell.open();
        while (!shell.isDisposed()) {
            if (!display.readAndDispatch())
                display.sleep();
        }
        display.dispose();
    }

}


Previous Topic:Hidden Id for TableItem
Next Topic:SWT table/column header foreground and background color
Goto Forum:
  


Current Time: Fri Aug 22 10:03:34 EDT 2014

Powered by FUDForum. Page generated in 0.03335 seconds