diff options
author | Artur Signell <artur@vaadin.com> | 2015-06-24 21:03:26 +0300 |
---|---|---|
committer | Vaadin Code Review <review@vaadin.com> | 2015-06-26 05:25:00 +0000 |
commit | 86fb07068fb15c9f6fa27ce9cc2e0b0266c2f068 (patch) | |
tree | 9665c1888445e79508a0f96eeb5c4231c3524300 /client | |
parent | 10e7a466bc936737b81005cb50d90c8bc8ca49bd (diff) | |
download | vaadin-framework-86fb07068fb15c9f6fa27ce9cc2e0b0266c2f068.tar.gz vaadin-framework-86fb07068fb15c9f6fa27ce9cc2e0b0266c2f068.zip |
Update theme resource references for legacy components (#17027)
Change-Id: Id4f119b22d44f6abf63e730442e22a34e7c1953f
Diffstat (limited to 'client')
-rw-r--r-- | client/src/com/vaadin/client/ui/VFilterSelect.java | 15 | ||||
-rw-r--r-- | client/src/com/vaadin/client/ui/VScrollTable.java | 5 | ||||
-rw-r--r-- | client/src/com/vaadin/client/ui/ui/UIConnector.java | 51 |
3 files changed, 61 insertions, 10 deletions
diff --git a/client/src/com/vaadin/client/ui/VFilterSelect.java b/client/src/com/vaadin/client/ui/VFilterSelect.java index d99779b7ec..7951759fa2 100644 --- a/client/src/com/vaadin/client/ui/VFilterSelect.java +++ b/client/src/com/vaadin/client/ui/VFilterSelect.java @@ -79,6 +79,7 @@ import com.vaadin.shared.AbstractComponentState; import com.vaadin.shared.EventId; import com.vaadin.shared.ui.ComponentStateUtil; import com.vaadin.shared.ui.combobox.FilteringMode; +import com.vaadin.shared.util.SharedUtil; /** * Client side implementation of the Select component. @@ -98,7 +99,7 @@ public class VFilterSelect extends Composite implements Field, KeyDownHandler, private final String key; private final String caption; - private String iconUri; + private String untranslatedIconUri; /** * Constructor @@ -110,8 +111,7 @@ public class VFilterSelect extends Composite implements Field, KeyDownHandler, key = uidl.getStringAttribute("key"); caption = uidl.getStringAttribute("caption"); if (uidl.hasAttribute("icon")) { - iconUri = client.translateVaadinUri(uidl - .getStringAttribute("icon")); + untranslatedIconUri = uidl.getStringAttribute("icon"); } } @@ -124,7 +124,8 @@ public class VFilterSelect extends Composite implements Field, KeyDownHandler, @Override public String getDisplayString() { final StringBuffer sb = new StringBuffer(); - final Icon icon = client.getIcon(iconUri); + final Icon icon = client.getIcon(client + .translateVaadinUri(untranslatedIconUri)); if (icon != null) { sb.append(icon.getElement().getString()); } @@ -164,7 +165,7 @@ public class VFilterSelect extends Composite implements Field, KeyDownHandler, * @return */ public String getIconUri() { - return iconUri; + return client.translateVaadinUri(untranslatedIconUri); } /** @@ -190,8 +191,8 @@ public class VFilterSelect extends Composite implements Field, KeyDownHandler, || (caption != null && !caption.equals(other.caption))) { return false; } - if ((iconUri == null && other.iconUri != null) - || (iconUri != null && !iconUri.equals(other.iconUri))) { + if (!SharedUtil.equals(untranslatedIconUri, + other.untranslatedIconUri)) { return false; } return true; diff --git a/client/src/com/vaadin/client/ui/VScrollTable.java b/client/src/com/vaadin/client/ui/VScrollTable.java index 0ef0cb6949..6bb3199b08 100644 --- a/client/src/com/vaadin/client/ui/VScrollTable.java +++ b/client/src/com/vaadin/client/ui/VScrollTable.java @@ -1647,8 +1647,7 @@ public class VScrollTable extends FlowPanel implements HasWidgets, actionMap.put(key + "_c", caption); if (action.hasAttribute("icon")) { // TODO need some uri handling ?? - actionMap.put(key + "_i", client.translateVaadinUri(action - .getStringAttribute("icon"))); + actionMap.put(key + "_i", action.getStringAttribute("icon")); } else { actionMap.remove(key + "_i"); } @@ -1661,7 +1660,7 @@ public class VScrollTable extends FlowPanel implements HasWidgets, } public String getActionIcon(String actionKey) { - return actionMap.get(actionKey + "_i"); + return client.translateVaadinUri(actionMap.get(actionKey + "_i")); } private void updateHeader(String[] strings) { diff --git a/client/src/com/vaadin/client/ui/ui/UIConnector.java b/client/src/com/vaadin/client/ui/ui/UIConnector.java index 264b2de0e1..cfb444ada6 100644 --- a/client/src/com/vaadin/client/ui/ui/UIConnector.java +++ b/client/src/com/vaadin/client/ui/ui/UIConnector.java @@ -1005,6 +1005,8 @@ public class UIConnector extends AbstractSingleComponentContainerConnector activeTheme); } + String oldThemeBase = getConnection().translateVaadinUri("theme://"); + activeTheme = newTheme; if (newTheme != null) { @@ -1013,13 +1015,62 @@ public class UIConnector extends AbstractSingleComponentContainerConnector activeTheme); updateVaadinFavicon(newTheme); + } 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); + 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. * * @see #forceStateChange() |