]> source.dussan.org Git - vaadin-framework.git/commitdiff
Move ComboBox filtering mode to state (#19929)
authorHenri Sara <hesara@vaadin.com>
Mon, 9 Nov 2015 10:42:25 +0000 (12:42 +0200)
committerVaadin Code Review <review@vaadin.com>
Thu, 21 Jul 2016 12:04:48 +0000 (12:04 +0000)
Change-Id: Ida38de55e1fc06aa6ec5e693f34cd5bc14ac4fc5

client/src/main/java/com/vaadin/client/ui/combobox/ComboBoxConnector.java
server/src/main/java/com/vaadin/ui/ComboBox.java
shared/src/main/java/com/vaadin/shared/ui/combobox/ComboBoxState.java

index cf88913f6aab94f752ec14ab995da23f0a9ee727..e300fa4d54abab8f7d257ee8d1e460176b45e7ce 100644 (file)
@@ -34,10 +34,8 @@ import com.vaadin.client.ui.VFilterSelect.FilterSelectSuggestion;
 import com.vaadin.shared.EventId;
 import com.vaadin.shared.communication.FieldRpc.FocusAndBlurServerRpc;
 import com.vaadin.shared.ui.Connect;
-import com.vaadin.shared.ui.combobox.ComboBoxConstants;
 import com.vaadin.shared.ui.combobox.ComboBoxServerRpc;
 import com.vaadin.shared.ui.combobox.ComboBoxState;
-import com.vaadin.shared.ui.combobox.FilteringMode;
 import com.vaadin.ui.ComboBox;
 
 @Connect(ComboBox.class)
@@ -83,6 +81,8 @@ public class ComboBoxConnector extends AbstractFieldConnector implements
 
         getWidget().pageLength = getState().pageLength;
 
+        getWidget().filteringmode = getState().filteringMode;
+
         Profiler.leave("ComboBoxConnector.onStateChanged update content");
     }
 
@@ -101,11 +101,6 @@ public class ComboBoxConnector extends AbstractFieldConnector implements
         // not a FocusWidget -> needs own tabindex handling
         getWidget().tb.setTabIndex(getState().tabIndex);
 
-        if (uidl.hasAttribute("filteringmode")) {
-            getWidget().filteringmode = FilteringMode.valueOf(uidl
-                    .getStringAttribute("filteringmode"));
-        }
-
         getWidget().nullSelectionAllowed = uidl.hasAttribute("nullselect");
 
         getWidget().nullSelectItem = uidl.hasAttribute("nullselectitem")
@@ -113,10 +108,6 @@ public class ComboBoxConnector extends AbstractFieldConnector implements
 
         getWidget().currentPage = uidl.getIntVariable("page");
 
-        if (uidl.hasAttribute("pagelength")) {
-            getWidget().pageLength = uidl.getIntAttribute("pagelength");
-        }
-
         if (uidl.hasAttribute("suggestionPopupWidth")) {
             getWidget().suggestionPopupWidth = uidl
                     .getStringAttribute("suggestionPopupWidth");
index 92f8f873fb54d0efa5bc6b2ea2e00d1aefcf7dd8..f36dcb840600cddedb7625fb07ce13e139b6bcf4 100644 (file)
@@ -115,8 +115,6 @@ public class ComboBox extends AbstractSelect implements
     // Current page when the user is 'paging' trough options
     private int currentPage = -1;
 
-    private FilteringMode filteringMode = FilteringMode.STARTSWITH;
-
     private String filterstring;
     private String prevfilterstring;
 
@@ -216,7 +214,7 @@ public class ComboBox extends AbstractSelect implements
 
     private boolean isFilteringNeeded() {
         return filterstring != null && filterstring.length() > 0
-                && filteringMode != FilteringMode.OFF;
+                && getFilteringMode() != FilteringMode.OFF;
     }
 
     @Override
@@ -254,8 +252,6 @@ public class ComboBox extends AbstractSelect implements
                         suggestionPopupWidth);
             }
 
-            target.addAttribute("filteringmode", getFilteringMode().toString());
-
             // Paints the options and create array of selected id keys
             int keyIndex = 0;
 
@@ -452,7 +448,7 @@ public class ComboBox extends AbstractSelect implements
 
         Filterable filterable = (Filterable) container;
 
-        Filter filter = buildFilter(filterstring, filteringMode);
+        Filter filter = buildFilter(filterstring, getFilteringMode());
 
         // adding and removing filters leads to extraneous item set
         // change events from the underlying container, but the ComboBox does
@@ -707,7 +703,7 @@ public class ComboBox extends AbstractSelect implements
             } else {
                 caption = caption.toLowerCase(getLocale());
             }
-            switch (filteringMode) {
+            switch (getFilteringMode()) {
             case CONTAINS:
                 if (caption.indexOf(filterstring) > -1) {
                     filteredOptions.add(itemId);
@@ -750,12 +746,12 @@ public class ComboBox extends AbstractSelect implements
 
     @Override
     public void setFilteringMode(FilteringMode filteringMode) {
-        this.filteringMode = filteringMode;
+        getState().filteringMode = filteringMode;
     }
 
     @Override
     public FilteringMode getFilteringMode() {
-        return filteringMode;
+        return getState(false).filteringMode;
     }
 
     @Override
@@ -889,7 +885,8 @@ public class ComboBox extends AbstractSelect implements
      * 
      * @see #getPopupWidth()
      * @since 7.7
-     * @param width the width
+     * @param width
+     *            the width
      */
     public void setPopupWidth(String width) {
         suggestionPopupWidth = width;
index 21bf4b934015f022a2f1569eb60644f0615210dd..6eae3fc46e4a2375c0fe3c93748f03f0ef571276 100644 (file)
@@ -48,4 +48,11 @@ public class ComboBoxState extends AbstractSelectState {
      * Number of items to show per page or 0 to disable paging.
      */
     public int pageLength = 10;
+
+    /**
+     * Current filtering mode (look for match of the user typed string in the
+     * beginning of the item caption or anywhere in the item caption).
+     */
+    public FilteringMode filteringMode = FilteringMode.STARTSWITH;
+
 }