Browse Source

#7560 ComboBox: Writing the name of a new item and clicking on drop down menu works inconsistently

svn changeset:21002/svn branch:6.6
tags/6.7.0.rc1
Leif Åstrand 12 years ago
parent
commit
07b67c0a22

+ 32
- 20
src/com/vaadin/terminal/gwt/client/ui/VFilterSelect.java View File

@@ -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");

+ 80
- 0
tests/src/com/vaadin/tests/components/combobox/ComboBoxClosePopupRetainText.html View File

@@ -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>

Loading…
Cancel
Save