diff options
author | Leif Åstrand <leif@vaadin.com> | 2013-05-17 15:10:48 +0300 |
---|---|---|
committer | Leif Åstrand <leif@vaadin.com> | 2013-05-17 15:10:48 +0300 |
commit | 9b6b735752e2f30bcdf6a521e031a8de22343bb0 (patch) | |
tree | cb40f3a2bb238057a3875aa4d2581ecda83667a7 /client | |
parent | 2f6d5e0d8c7cf4912bb82207c0dbe26101d168cb (diff) | |
parent | 42545ac81ae49cb9a3af2a8b3b06ba9525886b22 (diff) | |
download | vaadin-framework-9b6b735752e2f30bcdf6a521e031a8de22343bb0.tar.gz vaadin-framework-9b6b735752e2f30bcdf6a521e031a8de22343bb0.zip |
Merge changes from origin/7.0
55ea6dc More specific workaround for no rows in TreeTable with pagelenght = 0 (#9203)
dca728c Warn if using old widgetset (#11836)
936439d Verify that tests are run with the expected JRE version (#11835)
29eeda5 Merge "Clean up Table popup menu close handler to prevent a memory leak" from 6.8 (#11840)
6d7f5e4 Eliminate unnecessary conversions of option keys
b8c6a15 Clear items in ComboBox only if changed (#10924)
42545ac Fix NPE if there's no query in the URI (#11836)
Change-Id: I2e50ba59b45720a879c6e476333369523a730b9c
Diffstat (limited to 'client')
4 files changed, 161 insertions, 75 deletions
diff --git a/client/src/com/vaadin/client/ui/VFilterSelect.java b/client/src/com/vaadin/client/ui/VFilterSelect.java index 05535686d5..e08fbf8ab6 100644 --- a/client/src/com/vaadin/client/ui/VFilterSelect.java +++ b/client/src/com/vaadin/client/ui/VFilterSelect.java @@ -153,8 +153,8 @@ public class VFilterSelect extends Composite implements Field, KeyDownHandler, * * @return The key of the item */ - public int getOptionKey() { - return Integer.parseInt(key); + public String getOptionKey() { + return key; } /** @@ -174,6 +174,27 @@ public class VFilterSelect extends Composite implements Field, KeyDownHandler, public void execute() { onSuggestionSelected(this); } + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof FilterSelectSuggestion)) { + return false; + } + FilterSelectSuggestion other = (FilterSelectSuggestion) obj; + if ((key == null && other.key != null) + || (key != null && !key.equals(other.key))) { + return false; + } + if ((caption == null && other.caption != null) + || (caption != null && !caption.equals(other.caption))) { + return false; + } + if ((iconUri == null && other.iconUri != null) + || (iconUri != null && !iconUri.equals(other.iconUri))) { + return false; + } + return true; + } } /** @@ -1299,7 +1320,7 @@ public class VFilterSelect extends Composite implements Field, KeyDownHandler, newKey = ""; } else { // normal selection - newKey = String.valueOf(suggestion.getOptionKey()); + newKey = suggestion.getOptionKey(); } String text = suggestion.getReplacementString(); diff --git a/client/src/com/vaadin/client/ui/VScrollTable.java b/client/src/com/vaadin/client/ui/VScrollTable.java index d9dd542b15..8705a826cc 100644 --- a/client/src/com/vaadin/client/ui/VScrollTable.java +++ b/client/src/com/vaadin/client/ui/VScrollTable.java @@ -60,6 +60,7 @@ import com.google.gwt.event.dom.client.ScrollEvent; import com.google.gwt.event.dom.client.ScrollHandler; import com.google.gwt.event.logical.shared.CloseEvent; import com.google.gwt.event.logical.shared.CloseHandler; +import com.google.gwt.event.shared.HandlerRegistration; import com.google.gwt.user.client.Command; import com.google.gwt.user.client.DOM; import com.google.gwt.user.client.Element; @@ -556,15 +557,24 @@ public class VScrollTable extends FlowPanel implements HasWidgets, * <p> * For internal use only. May be removed or replaced in the future. */ - public class ContextMenuDetails { + public class ContextMenuDetails implements CloseHandler<PopupPanel> { public String rowKey; public int left; public int top; + HandlerRegistration closeRegistration; - public ContextMenuDetails(String rowKey, int left, int top) { + public ContextMenuDetails(VContextMenu menu, String rowKey, int left, + int top) { this.rowKey = rowKey; this.left = left; this.top = top; + this.closeRegistration = menu.addCloseHandler(this); + } + + @Override + public void onClose(CloseEvent<PopupPanel> event) { + contextMenu = null; + closeRegistration.removeHandler(); } } @@ -2104,6 +2114,15 @@ public class VScrollTable extends FlowPanel implements HasWidgets, * might have been (incorrectly) calculated earlier */ + /* + * TreeTable updates stuff in a funky order, so we must set the + * height as zero here before doing the real update to make it + * realize that there is no content, + */ + if (pageLength == totalRows && pageLength == 0) { + scrollBody.setHeight("0px"); + } + int bodyHeight; if (pageLength == totalRows) { /* @@ -4796,8 +4815,20 @@ public class VScrollTable extends FlowPanel implements HasWidgets, prepx = 0; } preSpacer.getStyle().setPropertyPx("height", prepx); - int postpx = measureRowHeightOffset(totalRows - 1) - - measureRowHeightOffset(lastRendered); + int postpx; + if (pageLength == 0 && totalRows == pageLength) { + /* + * TreeTable depends on having lastRendered out of sync in some + * situations, which makes this method miss the special + * situation in which one row worth of post spacer to be added + * if there are no rows in the table. #9203 + */ + postpx = measureRowHeightOffset(1); + } else { + postpx = measureRowHeightOffset(totalRows - 1) + - measureRowHeightOffset(lastRendered); + } + if (postpx < 0) { postpx = 0; } @@ -6000,15 +6031,20 @@ public class VScrollTable extends FlowPanel implements HasWidgets, public void showContextMenu(Event event) { if (enabled && actionKeys != null) { // Show context menu if there are registered action handlers - int left = Util.getTouchOrMouseClientX(event); - int top = Util.getTouchOrMouseClientY(event); - top += Window.getScrollTop(); - left += Window.getScrollLeft(); - contextMenu = new ContextMenuDetails(getKey(), left, top); - client.getContextMenu().showAt(this, left, top); + int left = Util.getTouchOrMouseClientX(event) + + Window.getScrollLeft(); + int top = Util.getTouchOrMouseClientY(event) + + Window.getScrollTop(); + showContextMenu(left, top); } } + public void showContextMenu(int left, int top) { + VContextMenu menu = client.getContextMenu(); + contextMenu = new ContextMenuDetails(menu, getKey(), left, top); + menu.showAt(this, left, top); + } + /** * Has the row been selected? * diff --git a/client/src/com/vaadin/client/ui/combobox/ComboBoxConnector.java b/client/src/com/vaadin/client/ui/combobox/ComboBoxConnector.java index e96d27032b..345bdc0cbb 100644 --- a/client/src/com/vaadin/client/ui/combobox/ComboBoxConnector.java +++ b/client/src/com/vaadin/client/ui/combobox/ComboBoxConnector.java @@ -15,7 +15,9 @@ */ package com.vaadin.client.ui.combobox; +import java.util.ArrayList; import java.util.Iterator; +import java.util.List; import com.vaadin.client.ApplicationConnection; import com.vaadin.client.Paintable; @@ -98,24 +100,6 @@ public class ComboBoxConnector extends AbstractFieldConnector implements getWidget().allowNewItem = uidl.hasAttribute("allownewitem"); getWidget().lastNewItemString = null; - getWidget().currentSuggestions.clear(); - if (!getWidget().waitingForFilteringResponse) { - /* - * Clear the current suggestions as the server response always - * includes the new ones. Exception is when filtering, then we need - * to retain the value if the user does not select any of the - * options matching the filter. - */ - getWidget().currentSuggestion = null; - /* - * Also ensure no old items in menu. Unless cleared the old values - * may cause odd effects on blur events. Suggestions in menu might - * not necessary exist in select at all anymore. - */ - getWidget().suggestionPopup.menu.clearItems(); - - } - final UIDL options = uidl.getChildUIDL(0); if (uidl.hasAttribute("totalMatches")) { getWidget().totalMatches = uidl.getIntAttribute("totalMatches"); @@ -123,55 +107,52 @@ public class ComboBoxConnector extends AbstractFieldConnector implements getWidget().totalMatches = 0; } + List<FilterSelectSuggestion> newSuggestions = new ArrayList<FilterSelectSuggestion>(); + for (final Iterator<?> i = options.getChildIterator(); i.hasNext();) { final UIDL optionUidl = (UIDL) i.next(); final FilterSelectSuggestion suggestion = getWidget().new FilterSelectSuggestion( optionUidl); - getWidget().currentSuggestions.add(suggestion); - if (optionUidl.hasAttribute("selected")) { - if (!getWidget().waitingForFilteringResponse - || getWidget().popupOpenerClicked) { - String newSelectedOptionKey = Integer.toString(suggestion - .getOptionKey()); - if (!newSelectedOptionKey - .equals(getWidget().selectedOptionKey) - || suggestion.getReplacementString().equals( - getWidget().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 - getWidget().setPromptingOff( - suggestion.getReplacementString()); - getWidget().selectedOptionKey = newSelectedOptionKey; - } - } - getWidget().currentSuggestion = suggestion; - getWidget().setSelectedItemIcon(suggestion.getIconUri()); + newSuggestions.add(suggestion); + } + + // only close the popup if the suggestions list has actually changed + boolean suggestionsChanged = !getWidget().initDone + || !newSuggestions.equals(getWidget().currentSuggestions); + + if (suggestionsChanged) { + getWidget().currentSuggestions.clear(); + + if (!getWidget().waitingForFilteringResponse) { + /* + * Clear the current suggestions as the server response always + * includes the new ones. Exception is when filtering, then we + * need to retain the value if the user does not select any of + * the options matching the filter. + */ + getWidget().currentSuggestion = null; + /* + * Also ensure no old items in menu. Unless cleared the old + * values may cause odd effects on blur events. Suggestions in + * menu might not necessary exist in select at all anymore. + */ + getWidget().suggestionPopup.menu.clearItems(); + + } + + for (FilterSelectSuggestion suggestion : newSuggestions) { + getWidget().currentSuggestions.add(suggestion); } } - if ((!getWidget().waitingForFilteringResponse || getWidget().popupOpenerClicked) - && uidl.hasVariable("selected") - && uidl.getStringArrayVariable("selected").length == 0) { - // select nulled - if (!getWidget().waitingForFilteringResponse - || !getWidget().popupOpenerClicked) { - if (!getWidget().focused) { - /* - * client.updateComponent overwrites all styles so we must - * ALWAYS set the prompting style at this point, even though - * we think it has been set already... - */ - getWidget().prompting = false; - getWidget().setPromptingOn(); - } else { - // we have focus in field, prompting can't be set on, - // instead just clear the input - getWidget().tb.setValue(""); - } + // handle selection (null or a single value) + if (uidl.hasVariable("selected")) { + String[] selectedKeys = uidl.getStringArrayVariable("selected"); + if (selectedKeys.length > 0) { + performSelection(selectedKeys[0]); + } else { + resetSelection(); } - getWidget().setSelectedItemIcon(null); - getWidget().selectedOptionKey = null; } if (getWidget().waitingForFilteringResponse @@ -230,6 +211,55 @@ public class ComboBoxConnector extends AbstractFieldConnector implements getWidget().initDone = true; } + private void performSelection(String selectedKey) { + // some item selected + for (FilterSelectSuggestion suggestion : getWidget().currentSuggestions) { + String suggestionKey = suggestion.getOptionKey(); + if (suggestionKey.equals(selectedKey)) { + if (!getWidget().waitingForFilteringResponse + || getWidget().popupOpenerClicked) { + if (!suggestionKey.equals(getWidget().selectedOptionKey) + || suggestion.getReplacementString().equals( + getWidget().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 + getWidget().setPromptingOff( + suggestion.getReplacementString()); + getWidget().selectedOptionKey = suggestionKey; + } + } + getWidget().currentSuggestion = suggestion; + getWidget().setSelectedItemIcon(suggestion.getIconUri()); + // only a single item can be selected + break; + } + } + } + + private void resetSelection() { + if (!getWidget().waitingForFilteringResponse + || getWidget().popupOpenerClicked) { + // select nulled + if (!getWidget().focused) { + /* + * client.updateComponent overwrites all styles so we must + * ALWAYS set the prompting style at this point, even though we + * think it has been set already... + */ + getWidget().prompting = false; + getWidget().setPromptingOn(); + } else { + // we have focus in field, prompting can't be set on, instead + // just clear the input + getWidget().tb.setValue(""); + } + getWidget().setSelectedItemIcon(null); + getWidget().selectedOptionKey = null; + } + } + @Override public VFilterSelect getWidget() { return (VFilterSelect) super.getWidget(); diff --git a/client/src/com/vaadin/client/ui/table/TableConnector.java b/client/src/com/vaadin/client/ui/table/TableConnector.java index c8b4af83f2..36587ffe4d 100644 --- a/client/src/com/vaadin/client/ui/table/TableConnector.java +++ b/client/src/com/vaadin/client/ui/table/TableConnector.java @@ -364,9 +364,8 @@ public class TableConnector extends AbstractHasComponentsConnector implements Widget w = iterator.next(); VScrollTableRow row = (VScrollTableRow) w; if (row.getKey().equals(savedContextMenu.rowKey)) { - getWidget().contextMenu = savedContextMenu; - getConnection().getContextMenu().showAt(row, - savedContextMenu.left, savedContextMenu.top); + row.showContextMenu(savedContextMenu.left, + savedContextMenu.top); } } } |