diff options
author | Tomi Virtanen <tltv@vaadin.com> | 2014-01-15 10:39:02 +0200 |
---|---|---|
committer | Vaadin Code Review <review@vaadin.com> | 2014-01-15 09:02:53 +0000 |
commit | b9a6a48ab6ce9e3c7d8d025520e866643d19c004 (patch) | |
tree | dc1005f512e56a5967ca2212d5d7f5760b5ad882 /client | |
parent | 857de0f2f3964f4459b665d1928641c1689ccd37 (diff) | |
download | vaadin-framework-b9a6a48ab6ce9e3c7d8d025520e866643d19c004.tar.gz vaadin-framework-b9a6a48ab6ce9e3c7d8d025520e866643d19c004.zip |
Update textbox when Select item caption changes (#9250)
Fixed logic that detects changed item caption and triggers update to
textbox text. Changed test case description.
Change-Id: I9fbb0cc686e73404bab8e624a5332644cca53737
Diffstat (limited to 'client')
-rw-r--r-- | client/src/com/vaadin/client/ui/combobox/ComboBoxConnector.java | 33 |
1 files changed, 26 insertions, 7 deletions
diff --git a/client/src/com/vaadin/client/ui/combobox/ComboBoxConnector.java b/client/src/com/vaadin/client/ui/combobox/ComboBoxConnector.java index 24597d1d8c..8dec26cf90 100644 --- a/client/src/com/vaadin/client/ui/combobox/ComboBoxConnector.java +++ b/client/src/com/vaadin/client/ui/combobox/ComboBoxConnector.java @@ -37,6 +37,10 @@ import com.vaadin.ui.ComboBox; public class ComboBoxConnector extends AbstractFieldConnector implements Paintable, SimpleManagedLayout { + // oldSuggestionTextMatchTheOldSelection is used to detect when it's safe to + // update textbox text by a changed item caption. + private boolean oldSuggestionTextMatchTheOldSelection; + /* * (non-Javadoc) * @@ -117,7 +121,10 @@ public class ComboBoxConnector extends AbstractFieldConnector implements boolean suggestionsChanged = !getWidget().initDone || !newSuggestions.equals(getWidget().currentSuggestions); + oldSuggestionTextMatchTheOldSelection = false; + if (suggestionsChanged) { + oldSuggestionTextMatchTheOldSelection = isWidgetsCurrentSelectionTextInTextBox(); getWidget().currentSuggestions.clear(); if (!getWidget().waitingForFilteringResponse) { @@ -217,13 +224,19 @@ public class ComboBoxConnector extends AbstractFieldConnector implements } if (!getWidget().waitingForFilteringResponse || getWidget().popupOpenerClicked) { - // 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 - // OR if selected item caption is changed. - getWidget().setPromptingOff(suggestion.getReplacementString()); - getWidget().selectedOptionKey = suggestionKey; + if (!suggestionKey.equals(getWidget().selectedOptionKey) + || suggestion.getReplacementString().equals( + getWidget().tb.getText()) + || oldSuggestionTextMatchTheOldSelection) { + // 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 + // OR if selected item caption is changed. + getWidget().setPromptingOff( + suggestion.getReplacementString()); + getWidget().selectedOptionKey = suggestionKey; + } } getWidget().currentSuggestion = suggestion; getWidget().setSelectedItemIcon(suggestion.getIconUri()); @@ -232,6 +245,12 @@ public class ComboBoxConnector extends AbstractFieldConnector implements } } + private boolean isWidgetsCurrentSelectionTextInTextBox() { + return getWidget().currentSuggestion != null + && getWidget().currentSuggestion.getReplacementString().equals( + getWidget().tb.getText()); + } + private void resetSelection() { if (!getWidget().waitingForFilteringResponse || getWidget().popupOpenerClicked) { |