From dc6d4953ed09fdd91a814072d947f9feb5e9b99e Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Tue, 14 Jul 2015 18:04:09 +0300 Subject: [PATCH] Resynchronize everything after theme change (#18478) Change-Id: Id56d0ff7b2c675780c84efe999cb4b9d655df4cd --- .../vaadin/client/ApplicationConnection.java | 3 +- .../com/vaadin/client/ui/ui/UIConnector.java | 53 ++----------------- .../themes/LegacyComponentThemeChange.java | 6 ++- .../LegacyComponentThemeChangeTest.java | 16 +++++- 4 files changed, 26 insertions(+), 52 deletions(-) diff --git a/client/src/com/vaadin/client/ApplicationConnection.java b/client/src/com/vaadin/client/ApplicationConnection.java index 628559dd2a..45a5b32a40 100644 --- a/client/src/com/vaadin/client/ApplicationConnection.java +++ b/client/src/com/vaadin/client/ApplicationConnection.java @@ -63,7 +63,6 @@ import com.google.gwt.user.client.Window.ClosingHandler; import com.google.gwt.user.client.ui.HasWidgets; import com.google.gwt.user.client.ui.Widget; import com.vaadin.client.ApplicationConfiguration.ErrorMessage; -import com.vaadin.client.ApplicationConnection.ApplicationStoppedEvent; import com.vaadin.client.ResourceLoader.ResourceLoadEvent; import com.vaadin.client.ResourceLoader.ResourceLoadListener; import com.vaadin.client.communication.HasJavaScriptConnectorHelper; @@ -805,7 +804,7 @@ public class ApplicationConnection implements HasHandlers { return parameters; } - protected void repaintAll() { + public void repaintAll() { makeUidlRequest(Json.createArray(), getRepaintAllParameters()); } diff --git a/client/src/com/vaadin/client/ui/ui/UIConnector.java b/client/src/com/vaadin/client/ui/ui/UIConnector.java index 6d98e2108a..46956d95d1 100644 --- a/client/src/com/vaadin/client/ui/ui/UIConnector.java +++ b/client/src/com/vaadin/client/ui/ui/UIConnector.java @@ -1032,58 +1032,15 @@ public class UIConnector extends AbstractSingleComponentContainerConnector } - forceStateChangeRecursively(UIConnector.this); - // UIDL has no stored URL which we can repaint so we do some find and - // replace magic... - String newThemeBase = getConnection().translateVaadinUri("theme://"); - replaceThemeAttribute(oldThemeBase, newThemeBase); + // Request a full resynchronization from the server to deal with legacy + // components + getConnection().repaintAll(); + // Immediately update state and do layout while waiting for the resync + forceStateChangeRecursively(UIConnector.this); getLayoutManager().forceLayout(); } - /** - * Finds all attributes where theme:// urls have possibly been used and - * replaces any old theme url with a new one - * - * @param oldPrefix - * The start of the old theme URL - * @param newPrefix - * The start of the new theme URL - */ - private void replaceThemeAttribute(String oldPrefix, String newPrefix) { - // Images - replaceThemeAttribute("src", oldPrefix, newPrefix); - // Embedded flash - replaceThemeAttribute("value", oldPrefix, newPrefix); - replaceThemeAttribute("movie", oldPrefix, newPrefix); - } - - /** - * Finds any attribute of the given type where theme:// urls have possibly - * been used and replaces any old theme url with a new one - * - * @param attributeName - * The name of the attribute, e.g. "src" - * @param oldPrefix - * The start of the old theme URL - * @param newPrefix - * The start of the new theme URL - */ - private void replaceThemeAttribute(String attributeName, String oldPrefix, - String newPrefix) { - // Find all "attributeName=" which start with "oldPrefix" using e.g. - // [^src='http://oldpath'] - NodeList elements = querySelectorAll("[" + attributeName - + "^='" + oldPrefix + "']"); - for (int i = 0; i < elements.getLength(); i++) { - Element element = elements.getItem(i); - element.setAttribute( - attributeName, - element.getAttribute(attributeName).replace(oldPrefix, - newPrefix)); - } - } - /** * Force a full recursive recheck of every connector's state variables. * diff --git a/uitest/src/com/vaadin/tests/themes/LegacyComponentThemeChange.java b/uitest/src/com/vaadin/tests/themes/LegacyComponentThemeChange.java index 4582123f5f..0a57b77aa3 100644 --- a/uitest/src/com/vaadin/tests/themes/LegacyComponentThemeChange.java +++ b/uitest/src/com/vaadin/tests/themes/LegacyComponentThemeChange.java @@ -29,6 +29,7 @@ import com.vaadin.ui.ComboBox; import com.vaadin.ui.Embedded; import com.vaadin.ui.HorizontalLayout; import com.vaadin.ui.MenuBar; +import com.vaadin.ui.MenuBar.MenuItem; import com.vaadin.ui.Table; import com.vaadin.ui.VerticalLayout; @@ -60,7 +61,10 @@ public class LegacyComponentThemeChange extends AbstractTestUIWithLog { ThemeResource varyingIcon = new ThemeResource("menubar-theme-icon.png"); MenuBar bar = new MenuBar(); bar.addItem("runo", alwaysTheSameIconImage, null); - bar.addItem("seletedtheme", varyingIcon, null); + bar.addItem("selectedtheme", varyingIcon, null); + MenuItem sub = bar.addItem("sub menu", null); + sub.addItem("runo", alwaysTheSameIconImage, null); + sub.addItem("selectedtheme", varyingIcon, null); vl.addComponent(bar); diff --git a/uitest/src/com/vaadin/tests/themes/LegacyComponentThemeChangeTest.java b/uitest/src/com/vaadin/tests/themes/LegacyComponentThemeChangeTest.java index c6593104da..3c992f3af5 100644 --- a/uitest/src/com/vaadin/tests/themes/LegacyComponentThemeChangeTest.java +++ b/uitest/src/com/vaadin/tests/themes/LegacyComponentThemeChangeTest.java @@ -122,8 +122,22 @@ public class LegacyComponentThemeChangeTest extends MultiBrowserTest { // The other image should change with the theme WebElement themeImage = $(MenuBarElement.class).first().findElement( - By.xpath(".//span[text()='seletedtheme']/img")); + By.xpath(".//span[text()='selectedtheme']/img")); assertAttributePrefix(themeImage, "src", theme); + + WebElement subMenuItem = $(MenuBarElement.class).first().findElement( + By.xpath(".//span[text()='sub menu']")); + subMenuItem.click(); + + WebElement subMenu = findElement(By.className("v-menubar-popup")); + WebElement subMenuRuno = subMenu.findElement(By + .xpath(".//span[text()='runo']/img")); + String subMenuRunoImageSrc = subMenuRuno.getAttribute("src"); + Assert.assertEquals(getThemeURL("runo") + "icons/16/ok.png", + subMenuRunoImageSrc); + WebElement subMenuThemeImage = subMenu.findElement(By + .xpath(".//span[text()='selectedtheme']/img")); + assertAttributePrefix(subMenuThemeImage, "src", theme); } private void assertAttributePrefix(WebElement element, String attribute, -- 2.39.5