]> source.dussan.org Git - vaadin-framework.git/commitdiff
Move ComboBox pageLength to state (#19929)
authorHenri Sara <hesara@vaadin.com>
Mon, 9 Nov 2015 10:33:07 +0000 (12:33 +0200)
committerTeemu Suo-Anttila <teemusa@vaadin.com>
Thu, 21 Jul 2016 10:15:17 +0000 (10:15 +0000)
Use shared state for the page length and update related tests.
This change also removes an unused widget field.

Change-Id: Id8719661121a9570be40028da09e32f27bec82b5

client/src/main/java/com/vaadin/client/ui/VFilterSelect.java
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
uitest/src/main/java/com/vaadin/tests/components/combobox/Comboboxes.java
uitest/src/main/java/com/vaadin/tests/layouts/MovingComponentsWhileOldParentInvisible.java

index 5e1ee616427c62ca89f119dbba7df3f2b201a984..efca4c58dccc5c11e7ab66758f641c03fd8c6ac6 100644 (file)
@@ -1453,9 +1453,6 @@ public class VFilterSelect extends Composite implements Field, KeyDownHandler,
     /** For internal use only. May be removed or replaced in the future. */
     public ComboBoxConnector connector;
 
-    /** For internal use only. May be removed or replaced in the future. */
-    public String paintableId;
-
     /** For internal use only. May be removed or replaced in the future. */
     public int currentPage;
 
index 702afe5c907b62c1255c993240e7534b44aef3b8..cf88913f6aab94f752ec14ab995da23f0a9ee727 100644 (file)
@@ -81,6 +81,8 @@ public class ComboBoxConnector extends AbstractFieldConnector implements
             getWidget().inputPrompt = "";
         }
 
+        getWidget().pageLength = getState().pageLength;
+
         Profiler.leave("ComboBoxConnector.onStateChanged update content");
     }
 
@@ -92,9 +94,6 @@ public class ComboBoxConnector extends AbstractFieldConnector implements
      */
     @Override
     public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
-        // Save details
-        getWidget().paintableId = uidl.getId();
-
         if (!isRealUpdate(uidl)) {
             return;
         }
index 597410bd485a035fed52d2f734ad45bbb0a6e683..92f8f873fb54d0efa5bc6b2ea2e00d1aefcf7dd8 100644 (file)
@@ -112,11 +112,6 @@ public class ComboBox extends AbstractSelect implements
         }
     };
 
-    /**
-     * Holds value of property pageLength. 0 disables paging.
-     */
-    protected int pageLength = 10;
-
     // Current page when the user is 'paging' trough options
     private int currentPage = -1;
 
@@ -231,11 +226,6 @@ public class ComboBox extends AbstractSelect implements
             // clear caption change listeners
             getCaptionChangeListener().clear();
 
-            // The tab ordering number
-            if (getTabIndex() != 0) {
-                target.addAttribute("tabindex", getTabIndex());
-            }
-
             // If the field is modified, but not committed, set modified
             // attribute
             if (isModified()) {
@@ -259,8 +249,6 @@ public class ComboBox extends AbstractSelect implements
             String[] selectedKeys = new String[(getValue() == null
                     && getNullSelectionItemId() == null ? 0 : 1)];
 
-            target.addAttribute("pagelength", pageLength);
-
             if (suggestionPopupWidth != null) {
                 target.addAttribute("suggestionPopupWidth",
                         suggestionPopupWidth);
@@ -449,7 +437,7 @@ public class ComboBox extends AbstractSelect implements
     protected List<?> getOptionsWithFilter(boolean needNullSelectOption) {
         Container container = getContainerDataSource();
 
-        if (pageLength == 0 && !isFilteringNeeded()) {
+        if (getPageLength() == 0 && !isFilteringNeeded()) {
             // no paging or filtering: return all items
             filteredSize = container.size();
             assert filteredSize >= 0;
@@ -571,7 +559,7 @@ public class ComboBox extends AbstractSelect implements
      */
     private List<?> sanitetizeList(List<?> options, boolean needNullSelectOption) {
 
-        if (pageLength != 0 && options.size() > pageLength) {
+        if (getPageLength() != 0 && options.size() > getPageLength()) {
 
             int indexToEnsureInView = -1;
 
@@ -616,7 +604,7 @@ public class ComboBox extends AbstractSelect implements
             int size) {
         // Not all options are visible, find out which ones are on the
         // current "page".
-        int first = currentPage * pageLength;
+        int first = currentPage * getPageLength();
         if (needNullSelectOption && currentPage > 0) {
             first--;
         }
@@ -643,7 +631,7 @@ public class ComboBox extends AbstractSelect implements
     private int getLastItemIndexOnCurrentPage(boolean needNullSelectOption,
             int size, int first) {
         // page length usable for non-null items
-        int effectivePageLength = pageLength
+        int effectivePageLength = getPageLength()
                 - (needNullSelectOption && (currentPage == 0) ? 1 : 0);
         return Math.min(size - 1, first + effectivePageLength - 1);
     }
@@ -671,12 +659,12 @@ public class ComboBox extends AbstractSelect implements
             int indexToEnsureInView, int size) {
         if (indexToEnsureInView != -1) {
             int newPage = (indexToEnsureInView + (needNullSelectOption ? 1 : 0))
-                    / pageLength;
+                    / getPageLength();
             page = newPage;
         }
         // adjust the current page if beyond the end of the list
-        if (page * pageLength > size) {
-            page = (size + (needNullSelectOption ? 1 : 0)) / pageLength;
+        if (page * getPageLength() > size) {
+            page = (size + (needNullSelectOption ? 1 : 0)) / getPageLength();
         }
         return page;
     }
@@ -870,7 +858,7 @@ public class ComboBox extends AbstractSelect implements
      * @return the pageLength
      */
     public int getPageLength() {
-        return pageLength;
+        return getState(false).pageLength;
     }
 
     /**
@@ -891,8 +879,7 @@ public class ComboBox extends AbstractSelect implements
      *            the pageLength to set
      */
     public void setPageLength(int pageLength) {
-        this.pageLength = pageLength;
-        markAsDirty();
+        getState().pageLength = pageLength;
     }
 
     /**
index 1856aac00d14f218d84a64a6bb0074f69711962d..21bf4b934015f022a2f1569eb60644f0615210dd 100644 (file)
@@ -44,4 +44,8 @@ public class ComboBoxState extends AbstractSelectState {
      */
     public String inputPrompt = null;
 
+    /**
+     * Number of items to show per page or 0 to disable paging.
+     */
+    public int pageLength = 10;
 }
index 5b2608b389a82a7711aaf91b5f403c2d1a622932..cf754d3fee57702274cc4e42110c73bdb0863b27 100644 (file)
@@ -78,7 +78,7 @@ public class Comboboxes extends ComponentTestCase<ComboBox> {
     public class PageLength0ComboBox extends ComboBox {
         public PageLength0ComboBox() {
             super();
-            pageLength = 0;
+            setPageLength(0);
         }
     }
 
index 364a0e267a12679aee015e8627719c8207be0313..04d318c62ca4417f69abefbf5bd26c8cb6b7d2d1 100644 (file)
@@ -39,7 +39,7 @@ public class MovingComponentsWhileOldParentInvisible extends TestBase {
 
         ComboBox componentContainerSelect = new ComboBox("Container") {
             {
-                pageLength = 0;
+                setPageLength(0);
             }
         };
         componentContainerSelect.setId("componentContainerSelect");