diff options
author | Artur Signell <artur.signell@itmill.com> | 2011-11-15 09:25:09 +0000 |
---|---|---|
committer | Artur Signell <artur.signell@itmill.com> | 2011-11-15 09:25:09 +0000 |
commit | efd5a01e0903fb1294a006b42d6986c1c44a41a0 (patch) | |
tree | 4d16f3f03d434fccc4218783034571ef050887d0 /src | |
parent | a7502f10347cb510263bbd6372c400e4249449da (diff) | |
download | vaadin-framework-efd5a01e0903fb1294a006b42d6986c1c44a41a0.tar.gz vaadin-framework-efd5a01e0903fb1294a006b42d6986c1c44a41a0.zip |
#7739 Code cleanup
svn changeset:21998/svn branch:6.7
Diffstat (limited to 'src')
-rw-r--r-- | src/com/vaadin/terminal/gwt/client/ui/VFilterSelect.java | 65 |
1 files changed, 37 insertions, 28 deletions
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VFilterSelect.java b/src/com/vaadin/terminal/gwt/client/ui/VFilterSelect.java index 2db534b8f7..07597f0656 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VFilterSelect.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VFilterSelect.java @@ -287,7 +287,7 @@ public class VFilterSelect extends Composite implements Paintable, Field, .getText().length() - lastFilter.length()); } else if (hasNextPage()) { - lastIndex = index - 1; // save for paging + selectPopupItemWhenResponseIsReceived = Select.FIRST; filterOptions(currentPage + 1, lastFilter); } } @@ -306,7 +306,7 @@ public class VFilterSelect extends Composite implements Paintable, Field, .getText().length() - lastFilter.length()); } else if (index == -1) { if (currentPage > 0) { - lastIndex = index + 1; // save for paging + selectPopupItemWhenResponseIsReceived = Select.LAST; filterOptions(currentPage - 1, lastFilter); } } else { @@ -624,7 +624,7 @@ public class VFilterSelect extends Composite implements Paintable, Field, return; } - selectItemWhenReponseIsReceived = waitingForFilteringReponse; + updateSelectionWhenReponseIsReceived = waitingForFilteringReponse; if (!waitingForFilteringReponse) { doPostFilterSelectedItemAction(); } @@ -637,7 +637,7 @@ public class VFilterSelect extends Composite implements Paintable, Field, final MenuItem item = getSelectedItem(); final String enteredItemValue = tb.getText(); - selectItemWhenReponseIsReceived = false; + updateSelectionWhenReponseIsReceived = false; // check for exact match in menu int p = getItems().size(); @@ -738,6 +738,17 @@ public class VFilterSelect extends Composite implements Paintable, Field, delayedImageLoadExecutioner.trigger(); } + + public void selectFirstItem() { + MenuItem firstItem = getItems().get(0); + selectItem(firstItem); + } + + public void selectLastItem() { + List<MenuItem> items = getItems(); + MenuItem lastItem = items.get(items.size() - 1); + selectItem(lastItem); + } } public static final int FILTERINGMODE_OFF = 0; @@ -822,19 +833,24 @@ public class VFilterSelect extends Composite implements Paintable, Field, * A collection of available suggestions (options) as received from the * server. */ - private final Collection<FilterSelectSuggestion> currentSuggestions = new ArrayList<FilterSelectSuggestion>(); + private final List<FilterSelectSuggestion> currentSuggestions = new ArrayList<FilterSelectSuggestion>(); private boolean immediate; private String selectedOptionKey; private boolean waitingForFilteringReponse = false; - private boolean selectItemWhenReponseIsReceived = false; + private boolean updateSelectionWhenReponseIsReceived = false; private boolean tabPressedWhenPopupOpen = false; private boolean initDone = false; private String lastFilter = ""; - private int lastIndex = -1; // last selected index when using arrows + + private enum Select { + NONE, FIRST, LAST + }; + + private Select selectPopupItemWhenResponseIsReceived = Select.NONE; /** * The current suggestion selected from the dropdown. This is one of the @@ -1123,35 +1139,28 @@ public class VFilterSelect extends Composite implements Paintable, Field, suggestionPopup.showSuggestions(currentSuggestions, currentPage, totalMatches); waitingForFilteringReponse = false; - if (!popupOpenerClicked && lastIndex != -1) { + if (!popupOpenerClicked + && selectPopupItemWhenResponseIsReceived != Select.NONE) { // we're paging w/ arrows - MenuItem activeMenuItem; - if (lastIndex == 0) { - // going up, select last item - int lastItem = pageLength - 1; - List<MenuItem> items = suggestionPopup.menu.getItems(); - /* - * The first page can contain less than 10 items if the null - * selection item is filtered away - */ - if (lastItem >= items.size()) { - lastItem = items.size() - 1; - } - activeMenuItem = items.get(lastItem); - suggestionPopup.menu.selectItem(activeMenuItem); + if (selectPopupItemWhenResponseIsReceived == Select.LAST) { + suggestionPopup.menu.selectLastItem(); } else { - // going down, select first item - activeMenuItem = suggestionPopup.menu.getItems().get(0); - suggestionPopup.menu.selectItem(activeMenuItem); + suggestionPopup.menu.selectFirstItem(); } + // This is used for paging so we update the keyboard selection + // variable as well. + MenuItem activeMenuItem = suggestionPopup.menu + .getSelectedItem(); + + // Update text field to contain the correct text setTextboxText(activeMenuItem.getText()); tb.setSelectionRange(lastFilter.length(), activeMenuItem .getText().length() - lastFilter.length()); - lastIndex = -1; // reset + selectPopupItemWhenResponseIsReceived = Select.NONE; // reset } - if (selectItemWhenReponseIsReceived) { + if (updateSelectionWhenReponseIsReceived) { suggestionPopup.menu.doPostFilterSelectedItemAction(); } } @@ -1263,7 +1272,7 @@ public class VFilterSelect extends Composite implements Paintable, Field, * The suggestion that just got selected. */ public void onSuggestionSelected(FilterSelectSuggestion suggestion) { - selectItemWhenReponseIsReceived = false; + updateSelectionWhenReponseIsReceived = false; currentSuggestion = suggestion; String newKey; |