diff options
author | Leif Åstrand <leif@vaadin.com> | 2013-01-09 13:18:32 +0000 |
---|---|---|
committer | Vaadin Code Review <review@vaadin.com> | 2013-01-09 13:18:32 +0000 |
commit | 9624d0a1540d790ea2889af9ba5f5a39ee2713d8 (patch) | |
tree | 15ac19ef7eb0bb6a9a527f636fe07b17cf3958fe /server/src/com/vaadin/ui | |
parent | 7daf3cbb584c78e27432164d8f5e9dd861f7a13c (diff) | |
parent | 447befae430975748f15b47aab99f58ce54854ad (diff) | |
download | vaadin-framework-9624d0a1540d790ea2889af9ba5f5a39ee2713d8.tar.gz vaadin-framework-9624d0a1540d790ea2889af9ba5f5a39ee2713d8.zip |
Merge "Merge of (#10471) to Vaadin 7."
Diffstat (limited to 'server/src/com/vaadin/ui')
-rw-r--r-- | server/src/com/vaadin/ui/ComboBox.java | 234 |
1 files changed, 121 insertions, 113 deletions
diff --git a/server/src/com/vaadin/ui/ComboBox.java b/server/src/com/vaadin/ui/ComboBox.java index 4a82cf27e2..0f42749acd 100644 --- a/server/src/com/vaadin/ui/ComboBox.java +++ b/server/src/com/vaadin/ui/ComboBox.java @@ -82,10 +82,10 @@ public class ComboBox extends AbstractSelect implements private boolean optionRequest; /** - * True if the container is being filtered temporarily and item set change - * notifications should be suppressed. + * True while painting to suppress item set change notifications that could + * be caused by temporary filtering. */ - private boolean filteringContainer; + private boolean isPainting; /** * Flag to indicate whether to scroll the selected item visible (select the @@ -147,141 +147,151 @@ public class ComboBox extends AbstractSelect implements @Override public void paintContent(PaintTarget target) throws PaintException { - if (inputPrompt != null) { - target.addAttribute(ComboBoxConstants.ATTR_INPUTPROMPT, inputPrompt); - } + isPainting = true; + try { + if (inputPrompt != null) { + target.addAttribute(ComboBoxConstants.ATTR_INPUTPROMPT, + inputPrompt); + } - if (!textInputAllowed) { - target.addAttribute(ComboBoxConstants.ATTR_NO_TEXT_INPUT, true); - } + if (!textInputAllowed) { + target.addAttribute(ComboBoxConstants.ATTR_NO_TEXT_INPUT, true); + } - // clear caption change listeners - getCaptionChangeListener().clear(); + // clear caption change listeners + getCaptionChangeListener().clear(); - // The tab ordering number - if (getTabIndex() != 0) { - target.addAttribute("tabindex", getTabIndex()); - } + // The tab ordering number + if (getTabIndex() != 0) { + target.addAttribute("tabindex", getTabIndex()); + } - // If the field is modified, but not committed, set modified attribute - if (isModified()) { - target.addAttribute("modified", true); - } + // If the field is modified, but not committed, set modified + // attribute + if (isModified()) { + target.addAttribute("modified", true); + } - if (isNewItemsAllowed()) { - target.addAttribute("allownewitem", true); - } + if (isNewItemsAllowed()) { + target.addAttribute("allownewitem", true); + } - boolean needNullSelectOption = false; - if (isNullSelectionAllowed()) { - target.addAttribute("nullselect", true); - needNullSelectOption = (getNullSelectionItemId() == null); - if (!needNullSelectOption) { - target.addAttribute("nullselectitem", true); + boolean needNullSelectOption = false; + if (isNullSelectionAllowed()) { + target.addAttribute("nullselect", true); + needNullSelectOption = (getNullSelectionItemId() == null); + if (!needNullSelectOption) { + target.addAttribute("nullselectitem", true); + } } - } - // Constructs selected keys array - String[] selectedKeys = new String[(getValue() == null - && getNullSelectionItemId() == null ? 0 : 1)]; + // Constructs selected keys array + String[] selectedKeys = new String[(getValue() == null + && getNullSelectionItemId() == null ? 0 : 1)]; - target.addAttribute("pagelength", pageLength); + target.addAttribute("pagelength", pageLength); - target.addAttribute("filteringmode", getFilteringMode().toString()); + target.addAttribute("filteringmode", getFilteringMode().toString()); - // Paints the options and create array of selected id keys - int keyIndex = 0; + // Paints the options and create array of selected id keys + int keyIndex = 0; - target.startTag("options"); + target.startTag("options"); - if (currentPage < 0) { - optionRequest = false; - currentPage = 0; - filterstring = ""; - } + if (currentPage < 0) { + optionRequest = false; + currentPage = 0; + filterstring = ""; + } - boolean nullFilteredOut = filterstring != null - && !"".equals(filterstring) - && filteringMode != FilteringMode.OFF; - // null option is needed and not filtered out, even if not on current - // page - boolean nullOptionVisible = needNullSelectOption && !nullFilteredOut; - - // first try if using container filters is possible - List<?> options = getOptionsWithFilter(nullOptionVisible); - if (null == options) { - // not able to use container filters, perform explicit in-memory - // filtering - options = getFilteredOptions(); - filteredSize = options.size(); - options = sanitetizeList(options, nullOptionVisible); - } + boolean nullFilteredOut = filterstring != null + && !"".equals(filterstring) + && filteringMode != FilteringMode.OFF; + // null option is needed and not filtered out, even if not on + // current + // page + boolean nullOptionVisible = needNullSelectOption + && !nullFilteredOut; + + // first try if using container filters is possible + List<?> options = getOptionsWithFilter(nullOptionVisible); + if (null == options) { + // not able to use container filters, perform explicit in-memory + // filtering + options = getFilteredOptions(); + filteredSize = options.size(); + options = sanitetizeList(options, nullOptionVisible); + } - final boolean paintNullSelection = needNullSelectOption - && currentPage == 0 && !nullFilteredOut; + final boolean paintNullSelection = needNullSelectOption + && currentPage == 0 && !nullFilteredOut; - if (paintNullSelection) { - target.startTag("so"); - target.addAttribute("caption", ""); - target.addAttribute("key", ""); - target.endTag("so"); - } + if (paintNullSelection) { + target.startTag("so"); + target.addAttribute("caption", ""); + target.addAttribute("key", ""); + target.endTag("so"); + } - final Iterator<?> i = options.iterator(); - // Paints the available selection options from data source + final Iterator<?> i = options.iterator(); + // Paints the available selection options from data source - while (i.hasNext()) { + while (i.hasNext()) { - final Object id = i.next(); + final Object id = i.next(); - if (!isNullSelectionAllowed() && id != null - && id.equals(getNullSelectionItemId()) && !isSelected(id)) { - continue; - } + if (!isNullSelectionAllowed() && id != null + && id.equals(getNullSelectionItemId()) + && !isSelected(id)) { + continue; + } - // Gets the option attribute values - final String key = itemIdMapper.key(id); - final String caption = getItemCaption(id); - final Resource icon = getItemIcon(id); - getCaptionChangeListener().addNotifierForItem(id); + // Gets the option attribute values + final String key = itemIdMapper.key(id); + final String caption = getItemCaption(id); + final Resource icon = getItemIcon(id); + getCaptionChangeListener().addNotifierForItem(id); - // Paints the option - target.startTag("so"); - if (icon != null) { - target.addAttribute("icon", icon); - } - target.addAttribute("caption", caption); - if (id != null && id.equals(getNullSelectionItemId())) { - target.addAttribute("nullselection", true); - } - target.addAttribute("key", key); - if (isSelected(id) && keyIndex < selectedKeys.length) { - target.addAttribute("selected", true); - selectedKeys[keyIndex++] = key; + // Paints the option + target.startTag("so"); + if (icon != null) { + target.addAttribute("icon", icon); + } + target.addAttribute("caption", caption); + if (id != null && id.equals(getNullSelectionItemId())) { + target.addAttribute("nullselection", true); + } + target.addAttribute("key", key); + if (isSelected(id) && keyIndex < selectedKeys.length) { + target.addAttribute("selected", true); + selectedKeys[keyIndex++] = key; + } + target.endTag("so"); } - target.endTag("so"); - } - target.endTag("options"); + target.endTag("options"); - target.addAttribute("totalitems", size() - + (needNullSelectOption ? 1 : 0)); - if (filteredSize > 0 || nullOptionVisible) { - target.addAttribute("totalMatches", filteredSize - + (nullOptionVisible ? 1 : 0)); - } + target.addAttribute("totalitems", size() + + (needNullSelectOption ? 1 : 0)); + if (filteredSize > 0 || nullOptionVisible) { + target.addAttribute("totalMatches", filteredSize + + (nullOptionVisible ? 1 : 0)); + } - // Paint variables - target.addVariable(this, "selected", selectedKeys); - if (isNewItemsAllowed()) { - target.addVariable(this, "newitem", ""); - } + // Paint variables + target.addVariable(this, "selected", selectedKeys); + if (isNewItemsAllowed()) { + target.addVariable(this, "newitem", ""); + } - target.addVariable(this, "filter", filterstring); - target.addVariable(this, "page", currentPage); + target.addVariable(this, "filter", filterstring); + target.addVariable(this, "page", currentPage); - currentPage = -1; // current page is always set by client + currentPage = -1; // current page is always set by client - optionRequest = true; + optionRequest = true; + } finally { + isPainting = false; + } } @@ -355,7 +365,6 @@ public class ComboBox extends AbstractSelect implements // change events from the underlying container, but the ComboBox does // not process or propagate them based on the flag filteringContainer if (filter != null) { - filteringContainer = true; filterable.addContainerFilter(filter); } @@ -395,7 +404,6 @@ public class ComboBox extends AbstractSelect implements // to the outside, filtering should not be visible if (filter != null) { filterable.removeContainerFilter(filter); - filteringContainer = false; } } } @@ -435,7 +443,7 @@ public class ComboBox extends AbstractSelect implements @Override public void containerItemSetChange(Container.ItemSetChangeEvent event) { - if (!filteringContainer) { + if (!isPainting) { super.containerItemSetChange(event); } } |