From 69d6bf76820929777168055bf0a941d691463a6b Mon Sep 17 00:00:00 2001 From: Johannes Dahlström Date: Mon, 16 Jan 2012 07:03:15 +0000 Subject: Merge from 6.7 svn changeset:22637/svn branch:6.8 --- WebContent/VAADIN/themes/reindeer-tests/styles.css | 27 ++- .../terminal/gwt/client/ApplicationConnection.java | 139 ++++++++++---- .../vaadin/terminal/gwt/client/ui/VFormLayout.java | 19 +- .../terminal/gwt/client/ui/VPopupCalendar.java | 22 ++- .../terminal/gwt/client/ui/VTextualDate.java | 10 +- .../components/datefield/DatePopupStyleName.html | 32 ++++ .../components/datefield/DatePopupStyleName.java | 33 ++++ .../WidthRecalculationOnEnableStateChange.html | 51 +++++ .../WidthRecalculationOnEnableStateChange.java | 44 +++++ .../formlayout/FormLayoutCaptionStyles.html | 46 +++++ .../formlayout/FormLayoutCaptionStyles.java | 55 ++++++ .../orderedlayout/OrderedLayoutCases.html | 102 ++++++++++ .../orderedlayout/OrderedLayoutCases.java | 171 ++++++++++++++++- .../VerticalLayoutChangingChildrenSizes.html | 211 +++++++++++++++++++++ 14 files changed, 899 insertions(+), 63 deletions(-) create mode 100644 tests/testbench/com/vaadin/tests/components/datefield/DatePopupStyleName.html create mode 100644 tests/testbench/com/vaadin/tests/components/datefield/DatePopupStyleName.java create mode 100644 tests/testbench/com/vaadin/tests/components/datefield/WidthRecalculationOnEnableStateChange.html create mode 100644 tests/testbench/com/vaadin/tests/components/datefield/WidthRecalculationOnEnableStateChange.java create mode 100644 tests/testbench/com/vaadin/tests/components/formlayout/FormLayoutCaptionStyles.html create mode 100644 tests/testbench/com/vaadin/tests/components/formlayout/FormLayoutCaptionStyles.java create mode 100644 tests/testbench/com/vaadin/tests/components/orderedlayout/OrderedLayoutCases.html create mode 100644 tests/testbench/com/vaadin/tests/components/orderedlayout/VerticalLayoutChangingChildrenSizes.html diff --git a/WebContent/VAADIN/themes/reindeer-tests/styles.css b/WebContent/VAADIN/themes/reindeer-tests/styles.css index 7d1727d4ca..243d1b87d4 100644 --- a/WebContent/VAADIN/themes/reindeer-tests/styles.css +++ b/WebContent/VAADIN/themes/reindeer-tests/styles.css @@ -1,4 +1,29 @@ @import url(../reindeer/styles.css); .table-equal-rowheight .v-table-row {height: 30px;} -.table-equal-rowheight .v-table-row-odd {height: 30px;} \ No newline at end of file +.table-equal-rowheight .v-table-row-odd {height: 30px;} + +.v-datefield-enabled-readonly-styled { + background: #ddd; +} + +.v-datefield-enabled-readonly-styled input.v-datefield-textfield { + border: 1px solid black; +} + +.v-datefield-enabled-readonly-styled .v-datefield.v-disabled { + opacity: 1; +} + +.v-disabled.v-datefield-enabled-readonly-styled .v-datefield-button, +.v-readonly.v-datefield-enabled-readonly-styled .v-datefield-button { + display: none; +} + +.popup-style .v-datefield-calendarpanel-header, +.v-datefield-popup-popup-style .v-datefield-calendarpanel-time { + background: red; +} +.popup-style .v-datefield-calendarpanel-body { + background: yellow; +} diff --git a/src/com/vaadin/terminal/gwt/client/ApplicationConnection.java b/src/com/vaadin/terminal/gwt/client/ApplicationConnection.java index 89952afe8c..0bb311600c 100644 --- a/src/com/vaadin/terminal/gwt/client/ApplicationConnection.java +++ b/src/com/vaadin/terminal/gwt/client/ApplicationConnection.java @@ -22,6 +22,8 @@ import com.google.gwt.http.client.RequestBuilder; import com.google.gwt.http.client.RequestCallback; import com.google.gwt.http.client.RequestException; import com.google.gwt.http.client.Response; +import com.google.gwt.regexp.shared.MatchResult; +import com.google.gwt.regexp.shared.RegExp; import com.google.gwt.user.client.Command; import com.google.gwt.user.client.DOM; import com.google.gwt.user.client.Element; @@ -94,6 +96,27 @@ public class ApplicationConnection { public static final String ATTRIBUTE_DESCRIPTION = "description"; public static final String ATTRIBUTE_ERROR = "error"; + /** + * A string that, if found in a non-JSON response to a UIDL request, will + * cause the browser to refresh the page. If followed by a colon, optional + * whitespace, and a URI, causes the browser to synchronously load the URI. + * + *

+ * This allows, for instance, a servlet filter to redirect the application + * to a custom login page when the session expires. For example: + *

+ * + *
+     * if (sessionExpired) {
+     *     response.setHeader("Content-Type", "text/html");
+     *     response.getWriter().write(
+     *             myLoginPageHtml + "<!-- Vaadin-Refresh: "
+     *                     + request.getContextPath() + " -->");
+     * }
+     * 
+ */ + public static final String UIDL_REFRESH_TOKEN = "Vaadin-Refresh"; + // will hold the UIDL security key (for XSS protection) once received private String uidlSecurityKey = "init"; @@ -513,6 +536,27 @@ public class ApplicationConnection { return; } + String contentType = response.getHeader("Content-Type"); + if (contentType == null + || !contentType.startsWith("application/json")) { + /* + * A servlet filter or equivalent may have intercepted + * the request and served non-UIDL content (for + * instance, a login page if the session has expired.) + * If the response contains a magic substring, do a + * synchronous refresh. + */ + MatchResult refreshToken = RegExp.compile( + UIDL_REFRESH_TOKEN + "(:\\s*(.*?))?(\\s|$)") + .exec(response.getText()); + if (refreshToken != null) { + redirect(refreshToken.getGroup(2)); + VConsole.log("*** REDIRECT : " + + refreshToken.getGroup(2)); + return; + } + } + final Date start = new Date(); // for(;;);[realjson] final String jsonText = response.getText().substring(9, @@ -1812,9 +1856,60 @@ public class ApplicationConnection { fw.setEnabled(enabled); } + TooltipInfo tooltipInfo = componentDetail.getTooltipInfo(null); + // Update tooltip + if (uidl.hasAttribute(ATTRIBUTE_DESCRIPTION)) { + tooltipInfo + .setTitle(uidl.getStringAttribute(ATTRIBUTE_DESCRIPTION)); + } else { + tooltipInfo.setTitle(null); + } + + // add error classname to components w/ error + if (uidl.hasAttribute(ATTRIBUTE_ERROR)) { + tooltipInfo.setErrorUidl(uidl.getErrors()); + } else { + tooltipInfo.setErrorUidl(null); + } + + // Style names + component.setStyleName(getStyleName(component.getStylePrimaryName(), + uidl, component instanceof Field)); + + // Set captions + if (manageCaption) { + final Container parent = Util.getLayout(component); + if (parent != null) { + parent.updateCaption((Paintable) component, uidl); + } + } + /* + * updateComponentSize need to be after caption update so caption can be + * taken into account + */ + + updateComponentSize(componentDetail, uidl); + + return false; + } + + /** + * Generates the style name for the widget based on the given primary style + * name (typically returned by Widget.getPrimaryStyleName()) and the UIDL. + * An additional "modified" style name can be added if the field parameter + * is set to true. + * + * @param primaryStyleName + * @param uidl + * @param isField + * @return + */ + public static String getStyleName(String primaryStyleName, UIDL uidl, + boolean field) { + boolean enabled = !uidl.getBooleanAttribute("disabled"); + StringBuffer styleBuf = new StringBuffer(); - final String primaryName = component.getStylePrimaryName(); - styleBuf.append(primaryName); + styleBuf.append(primaryStyleName); // first disabling and read-only status if (!enabled) { @@ -1832,7 +1927,7 @@ public class ApplicationConnection { final String[] styles = uidl.getStringAttribute("style").split(" "); for (int i = 0; i < styles.length; i++) { styleBuf.append(" "); - styleBuf.append(primaryName); + styleBuf.append(primaryStyleName); styleBuf.append("-"); styleBuf.append(styles[i]); styleBuf.append(" "); @@ -1841,55 +1936,25 @@ public class ApplicationConnection { } // add modified classname to Fields - if (uidl.hasAttribute("modified") && component instanceof Field) { + if (field && uidl.hasAttribute("modified")) { styleBuf.append(" "); styleBuf.append(MODIFIED_CLASSNAME); } - TooltipInfo tooltipInfo = componentDetail.getTooltipInfo(null); - // Update tooltip - if (uidl.hasAttribute(ATTRIBUTE_DESCRIPTION)) { - tooltipInfo - .setTitle(uidl.getStringAttribute(ATTRIBUTE_DESCRIPTION)); - } else { - tooltipInfo.setTitle(null); - } - - // add error classname to components w/ error if (uidl.hasAttribute(ATTRIBUTE_ERROR)) { - tooltipInfo.setErrorUidl(uidl.getErrors()); styleBuf.append(" "); - styleBuf.append(primaryName); + styleBuf.append(primaryStyleName); styleBuf.append(ERROR_CLASSNAME_EXT); - } else { - tooltipInfo.setErrorUidl(null); } - // add required style to required components if (uidl.hasAttribute("required")) { styleBuf.append(" "); - styleBuf.append(primaryName); + styleBuf.append(primaryStyleName); styleBuf.append(REQUIRED_CLASSNAME_EXT); } - // Styles + disabled & readonly - component.setStyleName(styleBuf.toString()); - - // Set captions - if (manageCaption) { - final Container parent = Util.getLayout(component); - if (parent != null) { - parent.updateCaption((Paintable) component, uidl); - } - } - /* - * updateComponentSize need to be after caption update so caption can be - * taken into account - */ - - updateComponentSize(componentDetail, uidl); + return styleBuf.toString(); - return false; } private void updateComponentSize(ComponentDetail cd, UIDL uidl) { diff --git a/src/com/vaadin/terminal/gwt/client/ui/VFormLayout.java b/src/com/vaadin/terminal/gwt/client/ui/VFormLayout.java index 9f9c6ffbba..d31d1acdd6 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VFormLayout.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VFormLayout.java @@ -114,8 +114,7 @@ public class VFormLayout extends SimplePanel implements Container { final Paintable p = client.getPaintable(childUidl); Caption caption = componentToCaption.get(p); if (caption == null) { - caption = new Caption(p, client, - getStylesFromUIDL(childUidl)); + caption = new Caption(p, client); caption.addClickHandler(this); componentToCaption.put(p, caption); } @@ -197,7 +196,7 @@ public class VFormLayout extends SimplePanel implements Container { if (oldComponent == candidate) { Caption oldCap = componentToCaption.get(oldComponent); final Caption newCap = new Caption( - (Paintable) newComponent, client, null); + (Paintable) newComponent, client); newCap.addClickHandler(this); newCap.setStyleName(oldCap.getStyleName()); componentToCaption.put((Paintable) newComponent, newCap); @@ -319,12 +318,15 @@ public class VFormLayout extends SimplePanel implements Container { * return null * @param client */ - public Caption(Paintable component, ApplicationConnection client, - String[] styles) { + public Caption(Paintable component, ApplicationConnection client) { super(); this.client = client; owner = component; + sinkEvents(VTooltip.TOOLTIP_EVENTS); + } + + private void setStyles(String[] styles) { String style = CLASSNAME; if (styles != null) { for (int i = 0; i < styles.length; i++) { @@ -332,16 +334,13 @@ public class VFormLayout extends SimplePanel implements Container { } } setStyleName(style); - - sinkEvents(VTooltip.TOOLTIP_EVENTS); } public void updateCaption(UIDL uidl) { setVisible(!uidl.getBooleanAttribute("invisible")); - setStyleName(getElement(), - ApplicationConnection.DISABLED_CLASSNAME, - uidl.hasAttribute("disabled")); + // Update styles as they might have changed when the caption changed + setStyles(getStylesFromUIDL(uidl)); boolean isEmpty = true; diff --git a/src/com/vaadin/terminal/gwt/client/ui/VPopupCalendar.java b/src/com/vaadin/terminal/gwt/client/ui/VPopupCalendar.java index 150831d4ed..549248aab3 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VPopupCalendar.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VPopupCalendar.java @@ -45,6 +45,9 @@ import com.vaadin.terminal.gwt.client.ui.VCalendarPanel.TimeChangeListener; public class VPopupCalendar extends VTextualDate implements Paintable, Field, ClickHandler, CloseHandler, SubPartAware { + private static final String POPUP_PRIMARY_STYLE_NAME = VDateField.CLASSNAME + + "-popup"; + private final Button calendarToggle; private VCalendarPanel calendar; @@ -90,7 +93,7 @@ public class VPopupCalendar extends VTextualDate implements Paintable, Field, }); popup = new VOverlay(true, true, true); - popup.setStyleName(VDateField.CLASSNAME + "-popup"); + popup.setStyleName(POPUP_PRIMARY_STYLE_NAME); popup.setWidget(calendar); popup.addCloseHandler(this); @@ -154,13 +157,18 @@ public class VPopupCalendar extends VTextualDate implements Paintable, Field, @SuppressWarnings("deprecation") public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { boolean lastReadOnlyState = readonly; + boolean lastEnabledState = isEnabled(); + parsable = uidl.getBooleanAttribute("parsable"); super.updateFromUIDL(uidl, client); - popup.setStyleName(VDateField.CLASSNAME + "-popup " - + VDateField.CLASSNAME + "-" - + resolutionToString(currentResolution)); + String popupStyleNames = ApplicationConnection.getStyleName( + POPUP_PRIMARY_STYLE_NAME, uidl, false); + popupStyleNames += " " + VDateField.CLASSNAME + "-" + + resolutionToString(currentResolution); + popup.setStyleName(popupStyleNames); + calendar.setDateTimeService(getDateTimeService()); calendar.setShowISOWeekNumbers(isShowISOWeekNumbers()); if (calendar.getResolution() != currentResolution) { @@ -216,7 +224,11 @@ public class VPopupCalendar extends VTextualDate implements Paintable, Field, calendarToggle.removeStyleName(CLASSNAME + "-button-readonly"); } - if (lastReadOnlyState != readonly) { + if (lastReadOnlyState != readonly || lastEnabledState != isEnabled()) { + // Enabled or readonly state changed. Differences in theming might + // affect the width (for instance if the popup button is hidden) so + // we have to recalculate the width (IF the width of the field is + // fixed) updateWidth(); } diff --git a/src/com/vaadin/terminal/gwt/client/ui/VTextualDate.java b/src/com/vaadin/terminal/gwt/client/ui/VTextualDate.java index ff4378aedf..fb41829efc 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VTextualDate.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VTextualDate.java @@ -384,8 +384,16 @@ public class VTextualDate extends VDateField implements Paintable, Field, return fieldExtraWidth; } + /** + * Force an recalculation of the width of the component IF the width has + * been defined. Does nothing if width is undefined as the width will be + * automatically adjusted by the browser. + */ public void updateWidth() { - needLayout = true; + if (!needLayout) { + return; + } + fieldExtraWidth = -1; iLayout(); } diff --git a/tests/testbench/com/vaadin/tests/components/datefield/DatePopupStyleName.html b/tests/testbench/com/vaadin/tests/components/datefield/DatePopupStyleName.html new file mode 100644 index 0000000000..f367fc383b --- /dev/null +++ b/tests/testbench/com/vaadin/tests/components/datefield/DatePopupStyleName.html @@ -0,0 +1,32 @@ + + + + + + +New Test + + + + + + + + + + + + + + + + + + + + + + +
New Test
open/run/com.vaadin.tests.components.datefield.DatePopupStyleName?&restartApplication
mouseClickvaadin=runcomvaadintestscomponentsdatefieldDatePopupStyleName::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VPopupCalendar[0]#popupButton4,10
screenCapturestyled-popup
+ + diff --git a/tests/testbench/com/vaadin/tests/components/datefield/DatePopupStyleName.java b/tests/testbench/com/vaadin/tests/components/datefield/DatePopupStyleName.java new file mode 100644 index 0000000000..ba4e324dc1 --- /dev/null +++ b/tests/testbench/com/vaadin/tests/components/datefield/DatePopupStyleName.java @@ -0,0 +1,33 @@ +package com.vaadin.tests.components.datefield; + +import java.util.Date; + +import com.vaadin.terminal.UserError; +import com.vaadin.tests.components.TestBase; +import com.vaadin.ui.DateField; + +public class DatePopupStyleName extends TestBase { + @Override + public void setup() { + setTheme("reindeer-tests"); + + final DateField df = new DateField(); + df.setValue(new Date(1203910239L)); + df.setWidth("200px"); + df.setRequired(true); + df.setComponentError(new UserError("abc")); + df.addStyleName("popup-style"); + addComponent(df); + } + + @Override + protected String getDescription() { + return "The DateField is given a style name 'test', but that style isn't applied on the calendar popup element."; + } + + @Override + protected Integer getTicketNumber() { + return 8083; + } + +} diff --git a/tests/testbench/com/vaadin/tests/components/datefield/WidthRecalculationOnEnableStateChange.html b/tests/testbench/com/vaadin/tests/components/datefield/WidthRecalculationOnEnableStateChange.html new file mode 100644 index 0000000000..70441efd9f --- /dev/null +++ b/tests/testbench/com/vaadin/tests/components/datefield/WidthRecalculationOnEnableStateChange.html @@ -0,0 +1,51 @@ + + + + + + +New Test + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
New Test
open/run/com.vaadin.tests.components.datefield.WidthRecalculationOnEnableStateChange?restartApplication
clickvaadin=runcomvaadintestscomponentsdatefieldWidthRecalculationOnEnableStateChange::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[1]/VButton[0]/domChild[0]/domChild[0]
screenCapturedisabled
clickvaadin=runcomvaadintestscomponentsdatefieldWidthRecalculationOnEnableStateChange::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[1]/VButton[0]/domChild[0]/domChild[0]
screenCaptureenabled
clickvaadin=runcomvaadintestscomponentsdatefieldWidthRecalculationOnEnableStateChange::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[2]/VButton[0]/domChild[0]/domChild[0]
screenCapturereadonly
+ + diff --git a/tests/testbench/com/vaadin/tests/components/datefield/WidthRecalculationOnEnableStateChange.java b/tests/testbench/com/vaadin/tests/components/datefield/WidthRecalculationOnEnableStateChange.java new file mode 100644 index 0000000000..f25a9f0350 --- /dev/null +++ b/tests/testbench/com/vaadin/tests/components/datefield/WidthRecalculationOnEnableStateChange.java @@ -0,0 +1,44 @@ +package com.vaadin.tests.components.datefield; + +import java.util.Date; + +import com.vaadin.tests.components.TestBase; +import com.vaadin.ui.Button; +import com.vaadin.ui.Button.ClickEvent; +import com.vaadin.ui.DateField; + +public class WidthRecalculationOnEnableStateChange extends TestBase { + @Override + public void setup() { + setTheme("reindeer-tests"); + + final DateField df = new DateField(); + df.setValue(new Date(1203910239L)); + df.setWidth("200px"); + df.addStyleName("enabled-readonly-styled"); + addComponent(df); + addComponent(new Button("Toggle disabled for date field", + new Button.ClickListener() { + public void buttonClick(ClickEvent event) { + df.setEnabled(!df.isEnabled()); + } + })); + addComponent(new Button("Toggle read only for date field", + new Button.ClickListener() { + public void buttonClick(ClickEvent event) { + df.setReadOnly(!df.isReadOnly()); + } + })); + } + + @Override + protected String getDescription() { + return "Setting the disabled state doesn't recalculate the input element width. Setting the read-only state instead recalculates the width. In both cases, the popup button is hidden using CSS.

The DateField is also given a style name 'test', but that style isn't applied on the calendar popup element."; + } + + @Override + protected Integer getTicketNumber() { + return 8085; + } + +} diff --git a/tests/testbench/com/vaadin/tests/components/formlayout/FormLayoutCaptionStyles.html b/tests/testbench/com/vaadin/tests/components/formlayout/FormLayoutCaptionStyles.html new file mode 100644 index 0000000000..14b5cc4c53 --- /dev/null +++ b/tests/testbench/com/vaadin/tests/components/formlayout/FormLayoutCaptionStyles.html @@ -0,0 +1,46 @@ + + + + + + +New Test + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
New Test
open/run/com.vaadin.tests.components.formlayout.FormLayoutCaptionStyles?restartApplication
assertCSSClassvaadin=runcomvaadintestscomponentsformlayoutFormLayoutCaptionStyles::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VFormLayout[0]/domChild[0]/domChild[1]/domChild[2]/domChild[0]/domChild[0]v-caption-bold
assertCSSClassvaadin=runcomvaadintestscomponentsformlayoutFormLayoutCaptionStyles::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VFormLayout[0]/VFormLayout$VFormLayoutTable[0]/VTextField[1]bold
clickvaadin=runcomvaadintestscomponentsformlayoutFormLayoutCaptionStyles::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VFormLayout[0]/VFormLayout$VFormLayoutTable[0]/VButton[0]/domChild[0]/domChild[0]
assertNotCSSClassvaadin=runcomvaadintestscomponentsformlayoutFormLayoutCaptionStyles::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VFormLayout[0]/VFormLayout$VFormLayoutTable[0]/VTextField[1]bold
assertNotCSSClassvaadin=runcomvaadintestscomponentsformlayoutFormLayoutCaptionStyles::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VFormLayout[0]/domChild[0]/domChild[1]/domChild[2]/domChild[0]/domChild[0]v-caption-bold
+ + diff --git a/tests/testbench/com/vaadin/tests/components/formlayout/FormLayoutCaptionStyles.java b/tests/testbench/com/vaadin/tests/components/formlayout/FormLayoutCaptionStyles.java new file mode 100644 index 0000000000..e74969f637 --- /dev/null +++ b/tests/testbench/com/vaadin/tests/components/formlayout/FormLayoutCaptionStyles.java @@ -0,0 +1,55 @@ +package com.vaadin.tests.components.formlayout; + +import com.vaadin.tests.components.TestBase; +import com.vaadin.ui.Button; +import com.vaadin.ui.Button.ClickEvent; +import com.vaadin.ui.FormLayout; +import com.vaadin.ui.TextField; + +public class FormLayoutCaptionStyles extends TestBase { + + @Override + protected void setup() { + setTheme("reindeer-tests"); + FormLayout fl = new FormLayout(); + + TextField f1 = createTextField("Text field 1", ""); + final TextField f2 = createTextField("Text field 2", "bold"); + + fl.addComponent(f1); + fl.addComponent(new Button("Toggle Text field 2 bold style", + new Button.ClickListener() { + + public void buttonClick(ClickEvent event) { + if ("bold".equals(f2.getStyleName())) { + f2.setStyleName(""); + } else { + f2.setStyleName("bold"); + } + + } + + })); + fl.addComponent(f2); + + addComponent(fl); + + } + + private TextField createTextField(String caption, String style) { + TextField tf = new TextField(caption); + tf.setStyleName(style); + return tf; + } + + @Override + protected String getDescription() { + return "The component style should be copied to the caption element. Changing the component style should update the caption style also"; + } + + @Override + protected Integer getTicketNumber() { + return 5982; + } + +} diff --git a/tests/testbench/com/vaadin/tests/components/orderedlayout/OrderedLayoutCases.html b/tests/testbench/com/vaadin/tests/components/orderedlayout/OrderedLayoutCases.html new file mode 100644 index 0000000000..9e1400521b --- /dev/null +++ b/tests/testbench/com/vaadin/tests/components/orderedlayout/OrderedLayoutCases.html @@ -0,0 +1,102 @@ + + + + + + +New Test + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
New Test
open/run/com.vaadin.tests.components.orderedlayout.OrderedLayoutCases?restartApplication
clickvaadin=runcomvaadintestscomponentsorderedlayoutOrderedLayoutCases::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VHorizontalLayout[0]/ChildComponentContainer[0]/VButton[0]/domChild[0]/domChild[0]
screenCapture1-undefined-without-relative
clickvaadin=runcomvaadintestscomponentsorderedlayoutOrderedLayoutCases::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VHorizontalLayout[0]/ChildComponentContainer[1]/VButton[0]/domChild[0]/domChild[0]
screenCapture2-undefined-with-relative
clickvaadin=runcomvaadintestscomponentsorderedlayoutOrderedLayoutCases::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VHorizontalLayout[0]/ChildComponentContainer[2]/VButton[0]/domChild[0]
screenCapture3-fixed-with-overflow
clickvaadin=runcomvaadintestscomponentsorderedlayoutOrderedLayoutCases::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VHorizontalLayout[0]/ChildComponentContainer[3]/VButton[0]/domChild[0]/domChild[0]
screenCapture4-fixed-with-extra-space
clickvaadin=runcomvaadintestscomponentsorderedlayoutOrderedLayoutCases::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VHorizontalLayout[0]/ChildComponentContainer[7]/VButton[0]/domChild[0]
screenCapture8-undefined-relative-height
clickvaadin=runcomvaadintestscomponentsorderedlayoutOrderedLayoutCases::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VHorizontalLayout[0]/ChildComponentContainer[6]/VButton[0]/domChild[0]/domChild[0]
screenCapture7-fixed-relative-height
clickvaadin=runcomvaadintestscomponentsorderedlayoutOrderedLayoutCases::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VHorizontalLayout[0]/ChildComponentContainer[5]/VButton[0]/domChild[0]/domChild[0]
screenCapture6-multiple-expands
clickvaadin=runcomvaadintestscomponentsorderedlayoutOrderedLayoutCases::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VHorizontalLayout[0]/ChildComponentContainer[4]/VButton[0]/domChild[0]/domChild[0]
screenCapture5-expand-with-alignment
+ + diff --git a/tests/testbench/com/vaadin/tests/components/orderedlayout/OrderedLayoutCases.java b/tests/testbench/com/vaadin/tests/components/orderedlayout/OrderedLayoutCases.java index d8b01c4099..dae44e3299 100644 --- a/tests/testbench/com/vaadin/tests/components/orderedlayout/OrderedLayoutCases.java +++ b/tests/testbench/com/vaadin/tests/components/orderedlayout/OrderedLayoutCases.java @@ -11,17 +11,21 @@ import com.vaadin.tests.components.TestBase; import com.vaadin.tests.util.TestUtils; import com.vaadin.ui.AbstractOrderedLayout; import com.vaadin.ui.Alignment; +import com.vaadin.ui.Button; +import com.vaadin.ui.Button.ClickEvent; +import com.vaadin.ui.Button.ClickListener; +import com.vaadin.ui.Component; import com.vaadin.ui.HorizontalLayout; import com.vaadin.ui.NativeSelect; import com.vaadin.ui.VerticalLayout; public class OrderedLayoutCases extends TestBase { - private static final String[] dimensionValues = { "-1px", "5px", "300px", + private static final String[] dimensionValues = { "-1px", "5px", "350px", "800px", "100%", "50%" }; private static class SampleChild extends VerticalLayout { public SampleChild() { - setStyleName("showBorders"); + setStyleName("sampleChild"); addComponent(createSimpleSelector("Child width", new ValueChangeListener() { public void valueChange(ValueChangeEvent event) { @@ -101,18 +105,24 @@ public class OrderedLayoutCases extends TestBase { } private AbstractOrderedLayout currentLayout; + private HorizontalLayout sizeBar; @Override - public void setup() { - TestUtils.injectCSS(getMainWindow(), - ".showBorders {border: 1px solid black};"); + protected void setup() { + TestUtils + .injectCSS( + getMainWindow(), + ".sampleChild, .theLayout {border: 1px solid black;}" + + ".theLayout > div > div:first-child {background: aqua;}" + + ".theLayout > div > div:first-child + div {background: yellow;}" + + ".theLayout > div > div:first-child + div + div {background: lightgrey;}"); currentLayout = new HorizontalLayout(); for (int i = 0; i < 3; i++) { currentLayout.addComponent(new SampleChild()); } - HorizontalLayout sizeBar = new HorizontalLayout(); + sizeBar = new HorizontalLayout(); sizeBar.setSpacing(true); sizeBar.addComponent(createSimpleSelector("Layout width", @@ -129,6 +139,20 @@ public class OrderedLayoutCases extends TestBase { .toString()); } }, dimensionValues)); + sizeBar.addComponent(createSimpleSelector("Spacing", + new ValueChangeListener() { + public void valueChange(ValueChangeEvent event) { + currentLayout.setSpacing(Boolean.parseBoolean(event + .getProperty().getValue().toString())); + } + }, "false", "true")); + sizeBar.addComponent(createSimpleSelector("Margin", + new ValueChangeListener() { + public void valueChange(ValueChangeEvent event) { + currentLayout.setMargin(Boolean.parseBoolean(event + .getProperty().getValue().toString())); + } + }, "false", "true")); sizeBar.addComponent(createSimpleSelector("Direction", new ValueChangeListener() { public void valueChange(ValueChangeEvent event) { @@ -145,7 +169,7 @@ public class OrderedLayoutCases extends TestBase { newLayout.addComponent(currentLayout .getComponent(0)); } - newLayout.setStyleName("showBorders"); + newLayout.setStyleName("theLayout"); newLayout.setHeight(currentLayout.getHeight(), currentLayout.getHeightUnits()); @@ -157,15 +181,145 @@ public class OrderedLayoutCases extends TestBase { } }, "Horizontal", "Vertical")); + HorizontalLayout caseBar = new HorizontalLayout(); + caseBar.addComponent(new Button("Undefined without relative", + new ClickListener() { + public void buttonClick(ClickEvent event) { + resetState(); + // width: 350px to middle child + setChildState(1, 0, 2); + } + })); + caseBar.addComponent(new Button("Undefined with relative", + new ClickListener() { + public void buttonClick(ClickEvent event) { + resetState(); + // width: 100% to middle child + setChildState(1, 0, 4); + } + })); + caseBar.addComponent(new Button("Fixed with overflow", + new ClickListener() { + public void buttonClick(ClickEvent event) { + resetState(); + // layout width: 350px + setState(sizeBar, 0, 2); + // layout margin enabled + setState(sizeBar, 3, 1); + } + })); + caseBar.addComponent(new Button("Fixed with extra space", + new ClickListener() { + public void buttonClick(ClickEvent event) { + resetState(); + // Layout width: 800px + setState(sizeBar, 0, 3); + // layout margin enabled + setState(sizeBar, 3, 1); + // width: 350px to middle child + setChildState(1, 0, 2); + } + })); + + caseBar.addComponent(new Button("Expand with alignment", + new ClickListener() { + public void buttonClick(ClickEvent event) { + resetState(); + // Layout width: 800px + setState(sizeBar, 0, 3); + // Layout height: 350px + setState(sizeBar, 1, 2); + // Expand: 1 to middle child + setChildState(1, 3, 1); + // Align bottom left to middle child + setChildState(1, 4, 6); + } + })); + + caseBar.addComponent(new Button("Multiple expands", + new ClickListener() { + public void buttonClick(ClickEvent event) { + resetState(); + // Layout width: 800px + setState(sizeBar, 0, 3); + // Layout height: 350px + setState(sizeBar, 1, 2); + // Width 350px to middle child + setChildState(1, 0, 2); + // Apply to left and middle child + for (int i = 0; i < 2; i++) { + // Expand: 1 + setChildState(i, 3, 1); + // Align: middle center + setChildState(i, 4, 5); + } + } + })); + + caseBar.addComponent(new Button("Fixed + relative height", + new ClickListener() { + public void buttonClick(ClickEvent event) { + resetState(); + // Layout height: 100% + setState(sizeBar, 1, 4); + // Height: 350px to left child + setChildState(0, 1, 2); + // Height: 100% to middle child + setChildState(1, 1, 4); + } + })); + + caseBar.addComponent(new Button("Undefined + relative height", + new ClickListener() { + public void buttonClick(ClickEvent event) { + resetState(); + // Height: 350px to left child + setChildState(0, 1, 2); + // Height: 100% to middle child + setChildState(1, 1, 4); + } + })); + + caseBar.setSpacing(true); + + addComponent(caseBar); addComponent(sizeBar); addComponent(currentLayout); getLayout().setSpacing(true); - getMainWindow().getContent().setSizeFull(); + getLayout().getParent().setSizeFull(); getLayout().setSizeFull(); getLayout().setExpandRatio(currentLayout, 1); } + private void resetState() { + for (int i = 0; i < sizeBar.getComponentCount(); i++) { + setState(sizeBar, i, 0); + } + for (int i = 0; i < 3; i++) { + // Child width and height -> -1px + SampleChild child = (SampleChild) currentLayout.getComponent(i); + for (int j = 0; j < child.getComponentCount(); j++) { + if (j == 4) { + setState(child, j, 1); + } else { + setState(child, j, 0); + } + } + } + } + + private void setChildState(int childIndex, int selectIndex, int valueIndex) { + Component child = currentLayout.getComponent(childIndex); + setState(child, selectIndex, valueIndex); + } + + private static void setState(Component container, int selectIndex, int value) { + NativeSelect select = (NativeSelect) ((AbstractOrderedLayout) container) + .getComponent(selectIndex); + select.setValue(new ArrayList(select.getItemIds()).get(value)); + } + private static NativeSelect createSimpleSelector(String caption, ValueChangeListener listener, String... values) { return createSimpleSelector(caption, listener, Arrays.asList(values), @@ -185,7 +339,6 @@ public class OrderedLayoutCases extends TestBase { @Override protected Integer getTicketNumber() { - // TODO Auto-generated method stub return null; } diff --git a/tests/testbench/com/vaadin/tests/components/orderedlayout/VerticalLayoutChangingChildrenSizes.html b/tests/testbench/com/vaadin/tests/components/orderedlayout/VerticalLayoutChangingChildrenSizes.html new file mode 100644 index 0000000000..edcf60176d --- /dev/null +++ b/tests/testbench/com/vaadin/tests/components/orderedlayout/VerticalLayoutChangingChildrenSizes.html @@ -0,0 +1,211 @@ + + + + + + +New Test + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
New Test
open/run/com.vaadin.tests.components.orderedlayout.VerticalLayoutTest?restartApplication
mouseClickvaadin=runcomvaadintestscomponentsorderedlayoutVerticalLayoutTest::PID_Smenu#item128,5
mouseClickvaadin=runcomvaadintestscomponentsorderedlayoutVerticalLayoutTest::Root/VOverlay[0]/VMenuBar[0]#item030,8
mouseClickvaadin=runcomvaadintestscomponentsorderedlayoutVerticalLayoutTest::PID_Smenu#item041,8
mouseClickvaadin=runcomvaadintestscomponentsorderedlayoutVerticalLayoutTest::Root/VOverlay[0]/VMenuBar[0]#item384,6
mouseClickvaadin=runcomvaadintestscomponentsorderedlayoutVerticalLayoutTest::Root/VOverlay[1]/VMenuBar[0]#item043,6
mouseClickvaadin=runcomvaadintestscomponentsorderedlayoutVerticalLayoutTest::Root/VOverlay[2]/VMenuBar[0]#item068,8
mouseClickvaadin=runcomvaadintestscomponentsorderedlayoutVerticalLayoutTest::Root/VOverlay[3]/VMenuBar[0]#item030,11
screenCaptureauto-auto-one-button
mouseClickvaadin=runcomvaadintestscomponentsorderedlayoutVerticalLayoutTest::PID_Smenu#item035,11
mouseClickvaadin=runcomvaadintestscomponentsorderedlayoutVerticalLayoutTest::Root/VOverlay[0]/VMenuBar[0]#item385,5
mouseClickvaadin=runcomvaadintestscomponentsorderedlayoutVerticalLayoutTest::Root/VOverlay[1]/VMenuBar[0]#item083,3
mouseClickvaadin=runcomvaadintestscomponentsorderedlayoutVerticalLayoutTest::Root/VOverlay[2]/VMenuBar[0]#item128,7
mouseClickvaadin=runcomvaadintestscomponentsorderedlayoutVerticalLayoutTest::Root/VOverlay[3]/VMenuBar[0]#item140,10
screenCaptureauto-auto-two-buttons
mouseClickvaadin=runcomvaadintestscomponentsorderedlayoutVerticalLayoutTest::PID_Smenu#item042,6
mouseClickvaadin=runcomvaadintestscomponentsorderedlayoutVerticalLayoutTest::Root/VOverlay[0]/VMenuBar[0]#item377,6
mouseClickvaadin=runcomvaadintestscomponentsorderedlayoutVerticalLayoutTest::Root/VOverlay[1]/VMenuBar[0]#item2115,7
mouseClickvaadin=runcomvaadintestscomponentsorderedlayoutVerticalLayoutTest::Root/VOverlay[2]/VMenuBar[0]#item072,8
mouseClickvaadin=runcomvaadintestscomponentsorderedlayoutVerticalLayoutTest::Root/VOverlay[3]/VMenuBar[0]#item414,2
screenCaptureauto-auto-two-buttons-equal-width
mouseClickvaadin=runcomvaadintestscomponentsorderedlayoutVerticalLayoutTest::PID_Smenu#item022,9
mouseClickvaadin=runcomvaadintestscomponentsorderedlayoutVerticalLayoutTest::Root/VOverlay[0]/VMenuBar[0]#item3117,9
mouseClickvaadin=runcomvaadintestscomponentsorderedlayoutVerticalLayoutTest::Root/VOverlay[1]/VMenuBar[0]#item3104,8
mouseClickvaadin=runcomvaadintestscomponentsorderedlayoutVerticalLayoutTest::Root/VOverlay[2]/VMenuBar[0]#item174,12
mouseClickvaadin=runcomvaadintestscomponentsorderedlayoutVerticalLayoutTest::Root/VOverlay[3]/VMenuBar[0]#item223,8
screenCaptureauto-auto-two-buttons-lower-higher
mouseClickvaadin=runcomvaadintestscomponentsorderedlayoutVerticalLayoutTest::PID_Smenu#item024,11
mouseClickvaadin=runcomvaadintestscomponentsorderedlayoutVerticalLayoutTest::Root/VOverlay[0]/VMenuBar[0]#item3104,12
mouseClickvaadin=runcomvaadintestscomponentsorderedlayoutVerticalLayoutTest::Root/VOverlay[1]/VMenuBar[0]#item2114,10
mouseClickvaadin=runcomvaadintestscomponentsorderedlayoutVerticalLayoutTest::Root/VOverlay[2]/VMenuBar[0]#item087,11
mouseClickvaadin=runcomvaadintestscomponentsorderedlayoutVerticalLayoutTest::Root/VOverlay[3]/VMenuBar[0]#item017,8
mouseClickvaadin=runcomvaadintestscomponentsorderedlayoutVerticalLayoutTest::PID_Smenu#item028,3
mouseClickvaadin=runcomvaadintestscomponentsorderedlayoutVerticalLayoutTest::Root/VOverlay[0]/VMenuBar[0]#item377,8
mouseClickvaadin=runcomvaadintestscomponentsorderedlayoutVerticalLayoutTest::Root/VOverlay[1]/VMenuBar[0]#item396,6
mouseClickvaadin=runcomvaadintestscomponentsorderedlayoutVerticalLayoutTest::Root/VOverlay[2]/VMenuBar[0]#item175,10
mouseClickvaadin=runcomvaadintestscomponentsorderedlayoutVerticalLayoutTest::Root/VOverlay[3]/VMenuBar[0]#item019,3
screenCaptureauto-auto-two-buttons
+ + -- cgit v1.2.3