diff options
author | Henri Sara <henri.sara@itmill.com> | 2011-09-15 09:34:16 +0000 |
---|---|---|
committer | Henri Sara <henri.sara@itmill.com> | 2011-09-15 09:34:16 +0000 |
commit | 776889c300e9eb373e1064b8ff190ca8b04b3c0f (patch) | |
tree | 34570ca8a7c273acdeadc7847c106d17a2171b66 | |
parent | 6e658db4eb6b80fe54b5cf4c60d66174e64d1d77 (diff) | |
parent | b2e2d4156276e1ec981cc44fe6e24a1b44055db6 (diff) | |
download | vaadin-framework-776889c300e9eb373e1064b8ff190ca8b04b3c0f.tar.gz vaadin-framework-776889c300e9eb373e1064b8ff190ca8b04b3c0f.zip |
Merge changes from 6.6
svn changeset:21036/svn branch:6.7
-rw-r--r-- | src/com/vaadin/terminal/gwt/client/ui/VFilterSelect.java | 57 | ||||
-rw-r--r-- | tests/src/com/vaadin/tests/components/combobox/ComboBoxClosePopupRetainText.html | 80 |
2 files changed, 117 insertions, 20 deletions
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VFilterSelect.java b/src/com/vaadin/terminal/gwt/client/ui/VFilterSelect.java index d858d9a2d2..ae58ec4618 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VFilterSelect.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VFilterSelect.java @@ -1032,7 +1032,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; @@ -1043,8 +1045,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()); @@ -1281,7 +1292,27 @@ 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); + } else if (currentSuggestion != null + && tb.getText().equals( + currentSuggestion.getReplacementString())) { + // Retain behavior from #6686 by returning without stopping + // propagation if there's nothing to do + return; + } + 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); @@ -1356,19 +1387,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; } } @@ -1434,9 +1452,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(); @@ -1558,6 +1573,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 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> +<head profile="http://selenium-ide.openqa.org/profiles/test-case"> +<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> +<link rel="selenium.base" href="" /> +<title></title> +</head> +<body> +<table cellpadding="1" cellspacing="1" border="1"> +<thead> +<tr><td rowspan="1" colspan="3"></td></tr> +</thead><tbody> +<tr> + <td>open</td> + <td>/run/com.vaadin.tests.components.combobox.ComboBoxes2?restartApplication</td> + <td></td> +</tr> +<tr> + <td>mouseClick</td> + <td>vaadin=runcomvaadintestscomponentscomboboxComboBoxes2::PID_StestComponent/domChild[0]</td> + <td>47,8</td> +</tr> +<tr> + <td>type</td> + <td>vaadin=runcomvaadintestscomponentscomboboxComboBoxes2::PID_StestComponent/domChild[0]</td> + <td>I</td> +</tr> +<!--Open popup--> +<tr> + <td>mouseClick</td> + <td>vaadin=runcomvaadintestscomponentscomboboxComboBoxes2::PID_StestComponent/domChild[1]</td> + <td>14,10</td> +</tr> +<!--Close poup--> +<tr> + <td>mouseClick</td> + <td>vaadin=runcomvaadintestscomponentscomboboxComboBoxes2::PID_StestComponent/domChild[1]</td> + <td>14,10</td> +</tr> +<tr> + <td>assertValue</td> + <td>vaadin=runcomvaadintestscomponentscomboboxComboBoxes2::PID_StestComponent/domChild[0]</td> + <td>I</td> +</tr> +<!--Select a value--> +<tr> + <td>open</td> + <td>/run/com.vaadin.tests.components.combobox.ComboBoxes2?restartApplication</td> + <td></td> +</tr> +<tr> + <td>mouseClick</td> + <td>vaadin=runcomvaadintestscomponentscomboboxComboBoxes2::PID_StestComponent/domChild[1]</td> + <td>14,10</td> +</tr> +<tr> + <td>mouseClick</td> + <td>vaadin=runcomvaadintestscomponentscomboboxComboBoxes2::Root/VFilterSelect$SuggestionPopup[0]/VFilterSelect$SuggestionMenu[0]#item2</td> + <td>47,9</td> +</tr> +<tr> + <td>type</td> + <td>vaadin=runcomvaadintestscomponentscomboboxComboBoxes2::PID_StestComponent/domChild[0]</td> + <td>I</td> +</tr> +<tr> + <td>mouseClick</td> + <td>vaadin=runcomvaadintestscomponentscomboboxComboBoxes2::PID_StestComponent/domChild[1]</td> + <td>14,10</td> +</tr> +<!--Entered value should remain in the text field even though the popup is opened--> +<tr> + <td>assertValue</td> + <td>vaadin=runcomvaadintestscomponentscomboboxComboBoxes2::PID_StestComponent/domChild[0]</td> + <td>I</td> +</tr> +</tbody></table> +</body> +</html> |