Change-Id: Id56d0ff7b2c675780c84efe999cb4b9d655df4cdtags/7.6.0.alpha4
@@ -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; | |||
@@ -804,7 +803,7 @@ public class ApplicationConnection implements HasHandlers { | |||
return parameters; | |||
} | |||
protected void repaintAll() { | |||
public void repaintAll() { | |||
makeUidlRequest(Json.createArray(), getRepaintAllParameters()); | |||
} | |||
@@ -1040,58 +1040,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<Element> 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. | |||
* |
@@ -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); | |||
@@ -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, |