summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLeif Åstrand <leif@vaadin.com>2011-09-14 08:36:44 +0000
committerLeif Åstrand <leif@vaadin.com>2011-09-14 08:36:44 +0000
commit07b67c0a22646409e9be45abdff5ef2ea7cb2918 (patch)
treeba7aa0f7f2f740f530cc4a6d3b361ae911606317 /src
parent0c2b3dd59ccc0e7648dfe700f6a47fde5a4eafe1 (diff)
downloadvaadin-framework-07b67c0a22646409e9be45abdff5ef2ea7cb2918.tar.gz
vaadin-framework-07b67c0a22646409e9be45abdff5ef2ea7cb2918.zip
#7560 ComboBox: Writing the name of a new item and clicking on drop down menu works inconsistently
svn changeset:21002/svn branch:6.6
Diffstat (limited to 'src')
-rw-r--r--src/com/vaadin/terminal/gwt/client/ui/VFilterSelect.java52
1 files changed, 32 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 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<PopupPanel> 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");