]> source.dussan.org Git - vaadin-framework.git/commitdiff
[merge from 6.7] #5833 and #7013 combo box width fix and tests
authorAutomerge <automerge@vaadin.com>
Tue, 14 Feb 2012 14:06:37 +0000 (14:06 +0000)
committerAutomerge <automerge@vaadin.com>
Tue, 14 Feb 2012 14:06:37 +0000 (14:06 +0000)
svn changeset:23000/svn branch:6.8

src/com/vaadin/terminal/gwt/client/ui/VFilterSelect.java
tests/testbench/com/vaadin/tests/components/combobox/PopUpWidth.html [new file with mode: 0644]
tests/testbench/com/vaadin/tests/components/combobox/PopUpWidth.java [new file with mode: 0644]
tests/testbench/com/vaadin/tests/components/combobox/WidthToggleReadOnly.html [new file with mode: 0644]
tests/testbench/com/vaadin/tests/components/combobox/WidthToggleReadOnly.java [new file with mode: 0644]

index e261286cb7f7adaa3f91ee2c0585b6817eced200..5cf02532b1f20bca56cad8e252b46e6eb7c4dcde 100644 (file)
@@ -1842,14 +1842,6 @@ public class VFilterSelect extends Composite implements Paintable, Field,
              */
             int tbWidth = Util.getRequiredWidth(tb);
 
-            if (popupWidth < 0) {
-                /*
-                 * Only use the first page popup width so the textbox will not
-                 * get resized whenever the popup is resized.
-                 */
-                popupWidth = Util.getRequiredWidth(popupOpener);
-            }
-
             /*
              * Note: iconWidth is here calculated as a negative pixel value so
              * you should consider this in further calculations.
@@ -1858,7 +1850,7 @@ public class VFilterSelect extends Composite implements Paintable, Field,
                     .measureMarginLeft(tb.getElement())
                     - Util.measureMarginLeft(selectedItemIcon.getElement()) : 0;
 
-            int w = tbWidth + popupWidth + iconWidth;
+            int w = tbWidth + getPopUpOpenerWidth() + iconWidth;
 
             /*
              * When the select has a undefined with we need to check that we are
@@ -1894,6 +1886,20 @@ public class VFilterSelect extends Composite implements Paintable, Field,
         }
     }
 
+    /**
+     * Only use the first page popup width so the textbox will not get resized
+     * whenever the popup is resized. This also resolves issue where toggling
+     * combo box between read only and normal state makes it grow larger.
+     * 
+     * @return Width of popup opener
+     */
+    private int getPopUpOpenerWidth() {
+        if (popupWidth < 0) {
+            popupWidth = Util.getRequiredWidth(popupOpener);
+        }
+        return popupWidth;
+    }
+
     /**
      * Get the width of the select in pixels where the text area and icon has
      * been included.
@@ -1921,10 +1927,10 @@ public class VFilterSelect extends Composite implements Paintable, Field,
      */
     private void setTextboxWidth(int componentWidth) {
         int padding = getTextboxPadding();
-        int popupOpenerWidth = Util.getRequiredWidth(popupOpener);
         int iconWidth = selectedItemIcon.isAttached() ? Util
                 .getRequiredWidth(selectedItemIcon) : 0;
-        int textboxWidth = componentWidth - padding - popupOpenerWidth
+
+        int textboxWidth = componentWidth - padding - getPopUpOpenerWidth()
                 - iconWidth;
         if (textboxWidth < 0) {
             textboxWidth = 0;
diff --git a/tests/testbench/com/vaadin/tests/components/combobox/PopUpWidth.html b/tests/testbench/com/vaadin/tests/components/combobox/PopUpWidth.html
new file mode 100644 (file)
index 0000000..35a6bcf
--- /dev/null
@@ -0,0 +1,57 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head profile="http://selenium-ide.openqa.org/profiles/test-case">
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+<link rel="selenium.base" href="" />
+<title>PopUpWidth</title>
+</head>
+<body>
+<table cellpadding="1" cellspacing="1" border="1">
+<thead>
+<tr><td rowspan="1" colspan="3">PopUpWidth</td></tr>
+</thead><tbody>
+<tr>
+       <td>open</td>
+       <td>/run/com.vaadin.tests.components.combobox.PopUpWidth</td>
+       <td></td>
+</tr>
+<tr>
+       <td>mouseClick</td>
+       <td>vaadin=runcomvaadintestscomponentscomboboxPopUpWidth::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[1]/VFilterSelect[0]/domChild[1]</td>
+       <td>9,14</td>
+</tr>
+<tr>
+       <td>mouseClick</td>
+       <td>vaadin=runcomvaadintestscomponentscomboboxPopUpWidth::Root/VFilterSelect$SuggestionPopup[0]/domChild[0]/domChild[2]/domChild[0]</td>
+       <td>106,5</td>
+</tr>
+<tr>
+       <td>mouseClick</td>
+       <td>vaadin=runcomvaadintestscomponentscomboboxPopUpWidth::Root/VFilterSelect$SuggestionPopup[0]/domChild[0]/domChild[2]/domChild[0]</td>
+       <td>103,5</td>
+</tr>
+<tr>
+       <td>mouseClick</td>
+       <td>vaadin=runcomvaadintestscomponentscomboboxPopUpWidth::Root/VFilterSelect$SuggestionPopup[0]/domChild[0]/domChild[2]/domChild[0]</td>
+       <td>103,5</td>
+</tr>
+<tr>
+       <td>mouseClick</td>
+       <td>vaadin=runcomvaadintestscomponentscomboboxPopUpWidth::Root/VFilterSelect$SuggestionPopup[0]/domChild[0]/domChild[2]/domChild[0]</td>
+       <td>103,5</td>
+</tr>
+<tr>
+       <td>mouseClick</td>
+       <td>vaadin=runcomvaadintestscomponentscomboboxPopUpWidth::Root/VFilterSelect$SuggestionPopup[0]/domChild[0]/domChild[2]/domChild[0]</td>
+       <td>103,5</td>
+</tr>
+<tr>
+       <td>screenCapture</td>
+       <td></td>
+       <td>combos-and-popup-with-same-width</td>
+</tr>
+
+</tbody></table>
+</body>
+</html>
diff --git a/tests/testbench/com/vaadin/tests/components/combobox/PopUpWidth.java b/tests/testbench/com/vaadin/tests/components/combobox/PopUpWidth.java
new file mode 100644 (file)
index 0000000..e22482e
--- /dev/null
@@ -0,0 +1,43 @@
+package com.vaadin.tests.components.combobox;
+
+import com.vaadin.data.Item;
+import com.vaadin.terminal.Resource;
+import com.vaadin.terminal.ThemeResource;
+import com.vaadin.tests.components.TestBase;
+import com.vaadin.ui.ComboBox;
+
+public class PopUpWidth extends TestBase {
+
+    @Override
+    protected void setup() {
+
+        addComponent(createComboBox("Do not touch this"));
+        addComponent(createComboBox("Browse this (check that width does not change)"));
+    }
+
+    private ComboBox createComboBox(String caption) {
+        ComboBox cb = new ComboBox(caption);
+        cb.addContainerProperty("caption", String.class, null);
+        cb.addContainerProperty("icon", Resource.class, null);
+        for (int i = 1; i < 200 + 1; i++) {
+            Item item = cb.addItem(i);
+            item.getItemProperty("caption").setValue("Item " + i);
+            item.getItemProperty("icon").setValue(
+                    new ThemeResource("../runo/icons/16/users.png"));
+        }
+        cb.setItemIconPropertyId("icon");
+        cb.setItemCaptionPropertyId("caption");
+        return cb;
+    }
+
+    @Override
+    protected String getDescription() {
+        return "Check that width of popup or combobox does not change when paging.";
+    }
+
+    @Override
+    protected Integer getTicketNumber() {
+        return 7013;
+    }
+
+}
diff --git a/tests/testbench/com/vaadin/tests/components/combobox/WidthToggleReadOnly.html b/tests/testbench/com/vaadin/tests/components/combobox/WidthToggleReadOnly.html
new file mode 100644 (file)
index 0000000..b661aa2
--- /dev/null
@@ -0,0 +1,67 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head profile="http://selenium-ide.openqa.org/profiles/test-case">
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+<link rel="selenium.base" href="" />
+<title>WidthToggleReadOnly</title>
+</head>
+<body>
+<table cellpadding="1" cellspacing="1" border="1">
+<thead>
+<tr><td rowspan="1" colspan="3">WidthToggleReadOnly</td></tr>
+</thead><tbody>
+<tr>
+       <td>open</td>
+       <td>/run/com.vaadin.tests.components.combobox.WidthToggleReadOnly</td>
+       <td></td>
+</tr>
+<tr>
+       <td>mouseClick</td>
+       <td>vaadin=runcomvaadintestscomponentscomboboxWidthToggleReadOnly::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[2]/VCheckBox[0]/domChild[0]</td>
+       <td>5,7</td>
+</tr>
+<tr>
+       <td>mouseClick</td>
+       <td>vaadin=runcomvaadintestscomponentscomboboxWidthToggleReadOnly::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[2]/VCheckBox[0]/domChild[0]</td>
+       <td>5,7</td>
+</tr>
+<tr>
+       <td>mouseClick</td>
+       <td>vaadin=runcomvaadintestscomponentscomboboxWidthToggleReadOnly::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[2]/VCheckBox[0]/domChild[0]</td>
+       <td>5,7</td>
+</tr>
+<tr>
+       <td>mouseClick</td>
+       <td>vaadin=runcomvaadintestscomponentscomboboxWidthToggleReadOnly::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[2]/VCheckBox[0]/domChild[0]</td>
+       <td>5,7</td>
+</tr>
+<tr>
+       <td>mouseClick</td>
+       <td>vaadin=runcomvaadintestscomponentscomboboxWidthToggleReadOnly::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[2]/VCheckBox[0]/domChild[0]</td>
+       <td>5,7</td>
+</tr>
+<tr>
+       <td>mouseClick</td>
+       <td>vaadin=runcomvaadintestscomponentscomboboxWidthToggleReadOnly::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[2]/VCheckBox[0]/domChild[0]</td>
+       <td>5,7</td>
+</tr>
+<tr>
+       <td>mouseClick</td>
+       <td>vaadin=runcomvaadintestscomponentscomboboxWidthToggleReadOnly::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[2]/VCheckBox[0]/domChild[0]</td>
+       <td>5,7</td>
+</tr>
+<tr>
+       <td>mouseClick</td>
+       <td>vaadin=runcomvaadintestscomponentscomboboxWidthToggleReadOnly::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[2]/VCheckBox[0]/domChild[0]</td>
+       <td>5,7</td>
+</tr>
+<tr>
+       <td>screenCapture</td>
+       <td></td>
+       <td>both-combo-with-same-width</td>
+</tr>
+
+</tbody></table>
+</body>
+</html>
diff --git a/tests/testbench/com/vaadin/tests/components/combobox/WidthToggleReadOnly.java b/tests/testbench/com/vaadin/tests/components/combobox/WidthToggleReadOnly.java
new file mode 100644 (file)
index 0000000..654f42e
--- /dev/null
@@ -0,0 +1,48 @@
+package com.vaadin.tests.components.combobox;
+
+import com.vaadin.data.util.MethodProperty;
+import com.vaadin.tests.components.TestBase;
+import com.vaadin.ui.CheckBox;
+import com.vaadin.ui.ComboBox;
+
+public class WidthToggleReadOnly extends TestBase {
+
+    @Override
+    protected void setup() {
+        ComboBox combo = createNewComboBoxA("Untouched combobox");
+        addComponent(combo);
+
+        combo = createNewComboBoxA("Toggled combobox");
+        addComponent(combo);
+        addComponent(createReadOnlyForComboBox(combo));
+    }
+
+    private ComboBox createNewComboBoxA(String caption) {
+        ComboBox combo = new ComboBox(caption);
+        combo.addItem("first");
+        combo.setValue("first");
+
+        addComponent(combo);
+
+        return combo;
+    }
+
+    private CheckBox createReadOnlyForComboBox(ComboBox combo) {
+        CheckBox readonly = new CheckBox("Second combobox is read only",
+                new MethodProperty(combo, "readOnly"));
+        readonly.setImmediate(true);
+        addComponent(readonly);
+        return readonly;
+    }
+
+    @Override
+    protected String getDescription() {
+        return "Check that toggling read only mode of second combobox does not change it's width.";
+    }
+
+    @Override
+    protected Integer getTicketNumber() {
+        return 5833;
+    }
+
+}