|
|
@@ -35,8 +35,8 @@ import com.vaadin.shared.ui.combobox.FilteringMode; |
|
|
|
import com.vaadin.ui.ComboBox; |
|
|
|
|
|
|
|
@Connect(ComboBox.class) |
|
|
|
public class ComboBoxConnector extends AbstractFieldConnector |
|
|
|
implements Paintable, SimpleManagedLayout { |
|
|
|
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. |
|
|
@@ -65,16 +65,15 @@ public class ComboBoxConnector extends AbstractFieldConnector |
|
|
|
// work without additional UIDL messages |
|
|
|
boolean noTextInput = uidl |
|
|
|
.hasAttribute(ComboBoxConstants.ATTR_NO_TEXT_INPUT) |
|
|
|
&& uidl.getBooleanAttribute( |
|
|
|
ComboBoxConstants.ATTR_NO_TEXT_INPUT); |
|
|
|
&& uidl.getBooleanAttribute(ComboBoxConstants.ATTR_NO_TEXT_INPUT); |
|
|
|
getWidget().setTextInputEnabled(!noTextInput); |
|
|
|
|
|
|
|
// not a FocusWidget -> needs own tabindex handling |
|
|
|
getWidget().tb.setTabIndex(getState().tabIndex); |
|
|
|
|
|
|
|
if (uidl.hasAttribute("filteringmode")) { |
|
|
|
getWidget().filteringmode = FilteringMode |
|
|
|
.valueOf(uidl.getStringAttribute("filteringmode")); |
|
|
|
getWidget().filteringmode = FilteringMode.valueOf(uidl |
|
|
|
.getStringAttribute("filteringmode")); |
|
|
|
} |
|
|
|
|
|
|
|
getWidget().immediate = getState().immediate; |
|
|
@@ -105,6 +104,13 @@ public class ComboBoxConnector extends AbstractFieldConnector |
|
|
|
getWidget().suggestionPopupWidth = null; |
|
|
|
} |
|
|
|
|
|
|
|
if (uidl.hasAttribute("suggestionPopupWidth")) { |
|
|
|
getWidget().suggestionPopupWidth = uidl |
|
|
|
.getStringAttribute("suggestionPopupWidth"); |
|
|
|
} else { |
|
|
|
getWidget().suggestionPopupWidth = null; |
|
|
|
} |
|
|
|
|
|
|
|
getWidget().suggestionPopup.updateStyleNames(uidl, getState()); |
|
|
|
|
|
|
|
getWidget().allowNewItem = uidl.hasAttribute("allownewitem"); |
|
|
@@ -181,12 +187,16 @@ public class ComboBoxConnector extends AbstractFieldConnector |
|
|
|
// started. |
|
|
|
if (selectedKeys.length > 0 && !selectedKeys[0].equals("")) { |
|
|
|
performSelection(selectedKeys[0]); |
|
|
|
// if selected key is available, assume caption is know based on |
|
|
|
// it as well and clear selected caption |
|
|
|
getWidget().setSelectedCaption(null); |
|
|
|
|
|
|
|
} else if (!getWidget().waitingForFilteringResponse |
|
|
|
&& uidl.hasAttribute("selectedCaption")) { |
|
|
|
// scrolling to correct page is disabled, caption is passed as a |
|
|
|
// special parameter |
|
|
|
getWidget().tb |
|
|
|
.setText(uidl.getStringAttribute("selectedCaption")); |
|
|
|
getWidget().setSelectedCaption( |
|
|
|
uidl.getStringAttribute("selectedCaption")); |
|
|
|
} else { |
|
|
|
resetSelection(); |
|
|
|
} |
|
|
@@ -274,16 +284,16 @@ public class ComboBoxConnector extends AbstractFieldConnector |
|
|
|
if (!getWidget().waitingForFilteringResponse |
|
|
|
|| getWidget().popupOpenerClicked) { |
|
|
|
if (!suggestionKey.equals(getWidget().selectedOptionKey) |
|
|
|
|| suggestion.getReplacementString() |
|
|
|
.equals(getWidget().tb.getText()) |
|
|
|
|| 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().setPromptingOff( |
|
|
|
suggestion.getReplacementString()); |
|
|
|
getWidget().selectedOptionKey = suggestionKey; |
|
|
|
} |
|
|
|
} |
|
|
@@ -296,8 +306,8 @@ public class ComboBoxConnector extends AbstractFieldConnector |
|
|
|
|
|
|
|
private boolean isWidgetsCurrentSelectionTextInTextBox() { |
|
|
|
return getWidget().currentSuggestion != null |
|
|
|
&& getWidget().currentSuggestion.getReplacementString() |
|
|
|
.equals(getWidget().tb.getText()); |
|
|
|
&& getWidget().currentSuggestion.getReplacementString().equals( |
|
|
|
getWidget().tb.getText()); |
|
|
|
} |
|
|
|
|
|
|
|
private void resetSelection() { |
|
|
@@ -319,9 +329,18 @@ public class ComboBoxConnector extends AbstractFieldConnector |
|
|
|
// just clear the input if the value has changed from something |
|
|
|
// else to null |
|
|
|
if (getWidget().selectedOptionKey != null |
|
|
|
|| (getWidget().allowNewItem |
|
|
|
&& !getWidget().tb.getValue().isEmpty())) { |
|
|
|
|| (getWidget().allowNewItem && !getWidget().tb |
|
|
|
.getValue().isEmpty())) { |
|
|
|
|
|
|
|
boolean openedPopupWithNonScrollingMode = (getWidget().popupOpenerClicked |
|
|
|
&& getWidget().getSelectedCaption() != null); |
|
|
|
if (!openedPopupWithNonScrollingMode) { |
|
|
|
getWidget().tb.setValue(""); |
|
|
|
} else { |
|
|
|
getWidget().tb |
|
|
|
.setValue(getWidget().getSelectedCaption()); |
|
|
|
getWidget().tb.selectAll(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
getWidget().currentSuggestion = null; // #13217 |