| Summary: | Tree does not fire SelectionChanged event | ||
|---|---|---|---|
| Product: | [Eclipse Project] Platform | Reporter: | Randy Hudson <hudsonr> |
| Component: | SWT | Assignee: | Mike Wilson <Mike_Wilson> |
| Status: | RESOLVED WORKSFORME | QA Contact: | |
| Severity: | normal | ||
| Priority: | P3 | ||
| Version: | 2.0 | ||
| Target Milestone: | --- | ||
| Hardware: | PC | ||
| OS: | Windows 2000 | ||
| Whiteboard: | |||
|
Description
Randy Hudson
The following code shows that SWT.Selection for Tree comes in before SWT.Show
for Menu when the right button is pressed:
import org.eclipse.swt.*;
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.layout.*;
public class PR_22594 {
public static void main (String [] args) {
Display display = new Display ();
Shell shell = new Shell (display);
final Tree tree = new Tree (shell, SWT.BORDER);
for (int i=0; i<16; i++) {
TreeItem item = new TreeItem (tree, SWT.NONE);
item.setText ("Item " + i);
}
Menu menu = new Menu (shell, SWT.POP_UP);
for (int i=0; i<16; i++) {
MenuItem item = new MenuItem (menu, SWT.NONE);
item.setText ("Item " + i);
}
tree.setMenu (menu);
Listener listener = new Listener () {
public void handleEvent (Event event) {
String name = event.type ==
SWT.Show ? "Show" : "Selection";
System.out.print (name + ": {");
TreeItem [] selection = tree.getSelection ();
for (int i=0; i<selection.length; i++) {
System.out.print (selection [i] + " ");
}
System.out.println ("}");
}
};
menu.addListener (SWT.Show, listener);
tree.addListener (SWT.Selection, listener);
shell.setLayout (new FillLayout ());
tree.pack ();
shell.pack ();
shell.open ();
while (!shell.isDisposed ()) {
if (!display.readAndDispatch ()) display.sleep ();
}
display.dispose ();
}
}
Sorry, my recollection was incorrect. Next time I'll write the testcase. The situation in which selection used to not occur was on DragStart, not menuPopup. It appears that this has been fixed in 2.0.0. |