Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 391830 - Combo refuses to accept input text
Summary: Combo refuses to accept input text
Status: CLOSED DUPLICATE of bug 390924
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.2.1   Edit
Hardware: PC Linux-GTK
: P3 major (vote)
Target Milestone: ---   Edit
Assignee: Platform-UI-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-10-12 16:08 EDT by John P. Petrakis CLA
Modified: 2012-10-19 13:28 EDT (History)
5 users (show)

See Also:


Attachments
trace showing selection change after CR in combo box. (3.94 KB, text/plain)
2012-10-19 11:36 EDT, John P. Petrakis CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description John P. Petrakis CLA 2012-10-12 16:08:51 EDT
We have a filesystem explorer... eg. a Tree control on the right with a results panel on the left... above the results view, we have an editable combo control... 
it's for typing in a path... that we would then find and select in the tree and results panel (assuming the path exists).  If we select a spot in the tree then this dropdown will pre-populates with the path represented by the tree selection.  In prior eclipse we can type in additinal chars and we listen for the  \r to tell us the user is done.  We then use Combo.getText() and send the tree selection to that spot... the problem is that now, anything typed in after the pre-selected tree location gets lost and getText only returns the string derived from the initial selection. in our tree... 

This "worked" as expected in 4.2.0 and 3.x... 4.2.1 doesn't work so well.
Is there some default behavior that changed? 

And this conclusion seems to be the case on both Windows XP and Linux GTK.
Comment 1 John P. Petrakis CLA 2012-10-12 16:10:51 EDT
... or did some default change and I just need to add an SWT... param?
Comment 2 John P. Petrakis CLA 2012-10-12 16:58:57 EDT
If I have a path selected in the combo box say:

/path/to/some/place

And I delete /place, then it does "the right thing" and Combo.getText() returns /path/to/some

So the combo does pick up and set that change somehow.
Comment 3 Silenio Quarti CLA 2012-10-12 17:03:18 EDT
I believe there are no changes in SWT between 4.2.0 and 4.2.1 that could cause this to happen.   There are some changes in GTK Combo.java, but they are unrelated. There are no changes in Windows at all.

It seems like from your description that the Combo is selecting the text when it gets focus and if you type the selection is removed. 

Here is a snippet that does something similar. When I click on the text field, the combo text is set and given focus.  I run this on Windows and GTK with both 4.2.1 and 4.2.0 and the all behave the same.  But that is expected behavior.

Could you provide a Snippet that reproduces your problem?


import org.eclipse.swt.*;
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.layout.*;

public class Snippet24 {

public static void main (String [] args) {
	Display display = new Display ();
	Shell shell = new Shell (display);
	shell.setLayout (new RowLayout ());
	final Combo combo = new Combo (shell, SWT.NONE);
	combo.setItems (new String [] {"A-1", "B-1", "C-1"});
	Text text = new Text (shell, SWT.SINGLE | SWT.BORDER);
	text.setText ("some text");
	combo.addListener (SWT.DefaultSelection, new Listener () {
		public void handleEvent (Event e) {
			System.out.println (e.widget + " - Default Selection");
		}
	});
	text.addListener (SWT.MouseDown, new Listener () {
		public void handleEvent (Event e) {
			combo.setText("Selected TExt");
			combo.setFocus();
			System.out.println (e.widget + " - Default Selection");
		}
	});
	shell.pack ();
	shell.open ();
	while (!shell.isDisposed()) {
		if (!display.readAndDispatch ()) display.sleep ();
	}
	display.dispose ();
}
}
Comment 4 John P. Petrakis CLA 2012-10-18 16:39:56 EDT
Hi,

I did try to get a simple code case that shows the problem but I really never got that far.  Here is what I do know:

We have a perspective and on the left is a tree view (i.e. filesystem navigator) and on the right is the "results view" i.e. directory contents.  This view also contains our combo box.  The views do have selection change listeners so that when a tree item is selected the path is pasted into the combo box and the location is then selected in the results view. 

Here is what happens.

Eclipse 4.2.0, Current CTE/CCRC code (debug session).

I set a selection in the tree and the path is pasted in the combo box, and the folder in question is shown and selected in the results sheet (recall combo and results sheet in same view).

The combo box has a keyListener and if I type a path we listen for the \r key (carriage return) and do nothing until the \r key is pressed.  Once this key is pressed, we get the text out of the combo box and set it in a selection event to the tree and results panels.  In fact if I set breakpoints in our selection listener and keyListener, the keyListener is hit first on the \r then the selection change events fire.

In Eclipse 4.2.1 the EXACT same code in a debug session things occur differently.  In this case, when I hit the <cr> the selection change event from the results panel fires (i.e. the VIEW gets a change event) even though the combo box has focus!  Then at some point the keyListener on the combo box fires but because the selection event has fired FIRST, the items that are already selected in the tree overwrite the combo box text... I'm quite sure that we don't have a key listener in the view but that's how its acting.
Comment 5 John P. Petrakis CLA 2012-10-18 16:40:26 EDT
of course that whole thing means that the title of this bug is a bit off...
Comment 6 Silenio Quarti CLA 2012-10-19 10:40:52 EDT
Ok, so the event ordering changed for you.  As far as we can tell there are no changes in SWT between 4.2 and 4.2.1 that could introduce this behavior. Are you using plain SWT? Or do you have jface as well?

This is a snippet that tries to implement what you described. It works fine for me. Does it fail for you?

import org.eclipse.swt.*;
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.layout.*;

public class Snippet24 {

public static void main (String [] args) {
	Display display = new Display ();
	Shell shell = new Shell (display);
	shell.setLayout (new GridLayout (1, false));
	final Combo combo = new Combo (shell, SWT.NONE);
	combo.setItems (new String [] {"A-1", "B-1", "C-1"});
	combo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
	final Tree tree = new Tree (shell, SWT.MULTI | SWT.BORDER);
	for (int i = 0; i < 10; i++) {
		TreeItem item = new TreeItem(tree, SWT.NONE);
		item.setText("Item" + i);
	}
	tree.setLayoutData(new GridData(GridData.FILL_BOTH));
	combo.addListener (SWT.KeyDown, new Listener () {
		public void handleEvent (Event e) {
			if (e.keyCode == SWT.CR || e.keyCode == SWT.LF) {
				String text = combo.getText();
				System.out.println ("Text in combo is=" + text);
				TreeItem[] items = tree.getItems();
				for (int i = 0; i < items.length; i++) {
					if (items[i].getText().equals(text)) {
						tree.setSelection(items[i]);
					}
				}
			}
		}
	});
	tree.addListener(SWT.Selection, new Listener () {
		public void handleEvent (Event e) {
			TreeItem[] items = tree.getSelection();
			if (items.length <= 0) return;
			combo.setText(items[0].getText());
		}
	});
	shell.setSize (300, 300);
	shell.open ();
	while (!shell.isDisposed()) {
		if (!display.readAndDispatch ()) display.sleep ();
	}
	display.dispose ();
}
}
Comment 7 John P. Petrakis CLA 2012-10-19 11:36:51 EDT
Created attachment 222586 [details]
trace showing selection change after CR in combo box.
Comment 8 John P. Petrakis CLA 2012-10-19 11:38:47 EDT
I added the stack trace as an attachment.  What it shows is a focus shift when I hit <CR>.  You get exactly the same sort of focus shift when you hit <TAB>.  I annotated the stack with where our code picks up.
Comment 9 Silenio Quarti CLA 2012-10-19 11:55:39 EDT
From the stack, CompatibilityView is moving the focus to the tree inside the view.  which causes the selection event on the tree. I think the change that is causing this difference in behavior is in UI. Moving to UI for comment.
Comment 10 Paul Webster CLA 2012-10-19 12:33:21 EDT
Eric, is this related to the stack traversal we fixed recently?

PW
Comment 11 Nobody - feel free to take it CLA 2012-10-19 13:28:09 EDT
Same bug. This is already fixed in master.

*** This bug has been marked as a duplicate of bug 390924 ***