From cc4914f4969141fcdc92f636ccb67b84c99f32f7 Mon Sep 17 00:00:00 2001 From: Automerge Date: Tue, 14 Feb 2012 14:06:37 +0000 Subject: [PATCH] [merge from 6.7] #5833 and #7013 combo box width fix and tests svn changeset:23000/svn branch:6.8 --- .../terminal/gwt/client/ui/VFilterSelect.java | 28 +++++--- .../tests/components/combobox/PopUpWidth.html | 57 ++++++++++++++++ .../tests/components/combobox/PopUpWidth.java | 43 ++++++++++++ .../combobox/WidthToggleReadOnly.html | 67 +++++++++++++++++++ .../combobox/WidthToggleReadOnly.java | 48 +++++++++++++ 5 files changed, 232 insertions(+), 11 deletions(-) create mode 100644 tests/testbench/com/vaadin/tests/components/combobox/PopUpWidth.html create mode 100644 tests/testbench/com/vaadin/tests/components/combobox/PopUpWidth.java create mode 100644 tests/testbench/com/vaadin/tests/components/combobox/WidthToggleReadOnly.html create mode 100644 tests/testbench/com/vaadin/tests/components/combobox/WidthToggleReadOnly.java diff --git a/src/com/vaadin/terminal/gwt/client/ui/VFilterSelect.java b/src/com/vaadin/terminal/gwt/client/ui/VFilterSelect.java index e261286cb7..5cf02532b1 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VFilterSelect.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VFilterSelect.java @@ -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 index 0000000000..35a6bcf29a --- /dev/null +++ b/tests/testbench/com/vaadin/tests/components/combobox/PopUpWidth.html @@ -0,0 +1,57 @@ + + + + + + +PopUpWidth + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
PopUpWidth
open/run/com.vaadin.tests.components.combobox.PopUpWidth
mouseClickvaadin=runcomvaadintestscomponentscomboboxPopUpWidth::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[1]/VFilterSelect[0]/domChild[1]9,14
mouseClickvaadin=runcomvaadintestscomponentscomboboxPopUpWidth::Root/VFilterSelect$SuggestionPopup[0]/domChild[0]/domChild[2]/domChild[0]106,5
mouseClickvaadin=runcomvaadintestscomponentscomboboxPopUpWidth::Root/VFilterSelect$SuggestionPopup[0]/domChild[0]/domChild[2]/domChild[0]103,5
mouseClickvaadin=runcomvaadintestscomponentscomboboxPopUpWidth::Root/VFilterSelect$SuggestionPopup[0]/domChild[0]/domChild[2]/domChild[0]103,5
mouseClickvaadin=runcomvaadintestscomponentscomboboxPopUpWidth::Root/VFilterSelect$SuggestionPopup[0]/domChild[0]/domChild[2]/domChild[0]103,5
mouseClickvaadin=runcomvaadintestscomponentscomboboxPopUpWidth::Root/VFilterSelect$SuggestionPopup[0]/domChild[0]/domChild[2]/domChild[0]103,5
screenCapturecombos-and-popup-with-same-width
+ + 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 index 0000000000..e22482ed8b --- /dev/null +++ b/tests/testbench/com/vaadin/tests/components/combobox/PopUpWidth.java @@ -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 index 0000000000..b661aa2bd7 --- /dev/null +++ b/tests/testbench/com/vaadin/tests/components/combobox/WidthToggleReadOnly.html @@ -0,0 +1,67 @@ + + + + + + +WidthToggleReadOnly + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
WidthToggleReadOnly
open/run/com.vaadin.tests.components.combobox.WidthToggleReadOnly
mouseClickvaadin=runcomvaadintestscomponentscomboboxWidthToggleReadOnly::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[2]/VCheckBox[0]/domChild[0]5,7
mouseClickvaadin=runcomvaadintestscomponentscomboboxWidthToggleReadOnly::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[2]/VCheckBox[0]/domChild[0]5,7
mouseClickvaadin=runcomvaadintestscomponentscomboboxWidthToggleReadOnly::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[2]/VCheckBox[0]/domChild[0]5,7
mouseClickvaadin=runcomvaadintestscomponentscomboboxWidthToggleReadOnly::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[2]/VCheckBox[0]/domChild[0]5,7
mouseClickvaadin=runcomvaadintestscomponentscomboboxWidthToggleReadOnly::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[2]/VCheckBox[0]/domChild[0]5,7
mouseClickvaadin=runcomvaadintestscomponentscomboboxWidthToggleReadOnly::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[2]/VCheckBox[0]/domChild[0]5,7
mouseClickvaadin=runcomvaadintestscomponentscomboboxWidthToggleReadOnly::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[2]/VCheckBox[0]/domChild[0]5,7
mouseClickvaadin=runcomvaadintestscomponentscomboboxWidthToggleReadOnly::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[2]/VCheckBox[0]/domChild[0]5,7
screenCaptureboth-combo-with-same-width
+ + 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 index 0000000000..654f42e233 --- /dev/null +++ b/tests/testbench/com/vaadin/tests/components/combobox/WidthToggleReadOnly.java @@ -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; + } + +} -- 2.39.5