From 07b67c0a22646409e9be45abdff5ef2ea7cb2918 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Leif=20=C3=85strand?= Date: Wed, 14 Sep 2011 08:36:44 +0000 Subject: [PATCH] #7560 ComboBox: Writing the name of a new item and clicking on drop down menu works inconsistently svn changeset:21002/svn branch:6.6 --- .../terminal/gwt/client/ui/VFilterSelect.java | 52 +++++++----- .../ComboBoxClosePopupRetainText.html | 80 +++++++++++++++++++ 2 files changed, 112 insertions(+), 20 deletions(-) create mode 100644 tests/src/com/vaadin/tests/components/combobox/ComboBoxClosePopupRetainText.html diff --git a/src/com/vaadin/terminal/gwt/client/ui/VFilterSelect.java b/src/com/vaadin/terminal/gwt/client/ui/VFilterSelect.java index c977f9fb18..dd21c4f372 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VFilterSelect.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VFilterSelect.java @@ -466,6 +466,7 @@ public class VFilterSelect extends Composite implements Paintable, Field, * com.google.gwt.event.logical.shared.CloseHandler#onClose(com.google * .gwt.event.logical.shared.CloseEvent) */ + @Override public void onClose(CloseEvent event) { if (event.isAutoClosed()) { lastAutoClosed = (new Date()).getTime(); @@ -988,7 +989,9 @@ public class VFilterSelect extends Composite implements Paintable, Field, } final UIDL options = uidl.getChildUIDL(0); - totalMatches = uidl.getIntAttribute("totalMatches"); + if (uidl.hasAttribute("totalMatches")) { + totalMatches = uidl.getIntAttribute("totalMatches"); + } String captions = inputPrompt; @@ -999,8 +1002,17 @@ public class VFilterSelect extends Composite implements Paintable, Field, currentSuggestions.add(suggestion); if (optionUidl.hasAttribute("selected")) { if (!filtering || popupOpenerClicked) { - setPromptingOff(suggestion.getReplacementString()); - selectedOptionKey = "" + suggestion.getOptionKey(); + String newSelectedOptionKey = Integer.toString(suggestion + .getOptionKey()); + if (!newSelectedOptionKey.equals(selectedOptionKey) + || suggestion.getReplacementString().equals( + tb.getText())) { + // Update text field if we've got a new selection + // Also update if we've got the same text to retain old + // text selection behavior + setPromptingOff(suggestion.getReplacementString()); + selectedOptionKey = newSelectedOptionKey; + } } currentSuggestion = suggestion; setSelectedItemIcon(suggestion.getIconUri()); @@ -1237,7 +1249,21 @@ public class VFilterSelect extends Composite implements Paintable, Field, */ public void onKeyDown(KeyDownEvent event) { if (enabled && !readonly) { - if (suggestionPopup.isAttached()) { + if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER) { + // Same reaction to enter no matter on whether the popup is open + if (suggestionPopup.isAttached()) { + filterOptions(currentPage); + } + if (currentSuggestions.size() == 1 && !allowNewItem) { + // If there is only one suggestion, select that + suggestionPopup.menu.selectItem(suggestionPopup.menu + .getItems().get(0)); + } + suggestionPopup.menu.doSelectedItemAction(); + + event.stopPropagation(); + return; + } else if (suggestionPopup.isAttached()) { popupKeyDown(event); } else { inputFieldKeyDown(event); @@ -1312,19 +1338,6 @@ public class VFilterSelect extends Composite implements Paintable, Field, } // onBlur() takes care of the rest break; - case KeyCodes.KEY_ENTER: - if (suggestionPopup.isAttached()) { - filterOptions(currentPage); - } - if (currentSuggestions.size() == 1 && !allowNewItem) { - // If there is only one suggestion, select that - suggestionPopup.menu.selectItem(suggestionPopup.menu.getItems() - .get(0)); - } - suggestionPopup.menu.doSelectedItemAction(); - - event.stopPropagation(); - break; } } @@ -1390,9 +1403,6 @@ public class VFilterSelect extends Composite implements Paintable, Field, filterOptions(-1, ""); popupOpenerClicked = true; lastFilter = ""; - } else if (selectedOptionKey == null) { - tb.setText(inputPrompt); - prompting = true; } DOM.eventPreventDefault(DOM.eventGetCurrentEvent()); focus(); @@ -1514,6 +1524,8 @@ public class VFilterSelect extends Composite implements Paintable, Field, } if (selectedOptionKey == null) { setPromptingOn(); + } else if (currentSuggestion != null) { + setPromptingOff(currentSuggestion.caption); } } removeStyleDependentName("focus"); diff --git a/tests/src/com/vaadin/tests/components/combobox/ComboBoxClosePopupRetainText.html b/tests/src/com/vaadin/tests/components/combobox/ComboBoxClosePopupRetainText.html new file mode 100644 index 0000000000..9248938b28 --- /dev/null +++ b/tests/src/com/vaadin/tests/components/combobox/ComboBoxClosePopupRetainText.html @@ -0,0 +1,80 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
open/run/com.vaadin.tests.components.combobox.ComboBoxes2?restartApplication
mouseClickvaadin=runcomvaadintestscomponentscomboboxComboBoxes2::PID_StestComponent/domChild[0]47,8
typevaadin=runcomvaadintestscomponentscomboboxComboBoxes2::PID_StestComponent/domChild[0]I
mouseClickvaadin=runcomvaadintestscomponentscomboboxComboBoxes2::PID_StestComponent/domChild[1]14,10
mouseClickvaadin=runcomvaadintestscomponentscomboboxComboBoxes2::PID_StestComponent/domChild[1]14,10
assertValuevaadin=runcomvaadintestscomponentscomboboxComboBoxes2::PID_StestComponent/domChild[0]I
open/run/com.vaadin.tests.components.combobox.ComboBoxes2?restartApplication
mouseClickvaadin=runcomvaadintestscomponentscomboboxComboBoxes2::PID_StestComponent/domChild[1]14,10
mouseClickvaadin=runcomvaadintestscomponentscomboboxComboBoxes2::Root/VFilterSelect$SuggestionPopup[0]/VFilterSelect$SuggestionMenu[0]#item247,9
typevaadin=runcomvaadintestscomponentscomboboxComboBoxes2::PID_StestComponent/domChild[0]I
mouseClickvaadin=runcomvaadintestscomponentscomboboxComboBoxes2::PID_StestComponent/domChild[1]14,10
assertValuevaadin=runcomvaadintestscomponentscomboboxComboBoxes2::PID_StestComponent/domChild[0]I
+ + -- 2.39.5