From 1b73b00b2875c5eafa3c641b77f5d9efc2f7d929 Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Wed, 11 Jun 2014 20:35:04 +0300 Subject: Allow changing theme on the fly (#2874) Change-Id: I70c153c4109428686002f985bfe1cb7cba2c9b31 --- server/src/com/vaadin/ui/UI.java | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) (limited to 'server') diff --git a/server/src/com/vaadin/ui/UI.java b/server/src/com/vaadin/ui/UI.java index a72cbe5c30..4bde8a95b3 100644 --- a/server/src/com/vaadin/ui/UI.java +++ b/server/src/com/vaadin/ui/UI.java @@ -549,8 +549,6 @@ public abstract class UI extends AbstractSingleComponentContainer implements private boolean resizeLazy = false; - private String theme; - private Navigator navigator; private PushConnection pushConnection = null; @@ -633,7 +631,7 @@ public abstract class UI extends AbstractSingleComponentContainer implements this.embedId = embedId; // Actual theme - used for finding CustomLayout templates - theme = request.getParameter("theme"); + getState(false).theme = request.getParameter("theme"); getPage().init(request); @@ -1135,12 +1133,31 @@ public abstract class UI extends AbstractSingleComponentContainer implements } /** - * Gets the theme that was used when the UI was initialized. + * Gets the theme currently in use by this UI * * @return the theme name */ public String getTheme() { - return theme; + return getState(false).theme; + } + + /** + * Sets the theme currently in use by this UI + *

+ * Calling this method will remove the old theme (CSS file) from the + * application and add the new theme. + *

+ * Note that this method is NOT SAFE to call in a portal environment or + * other environment where there are multiple UIs on the same page. The old + * CSS file will be removed even if there are other UIs on the page which + * are still using it. + * + * @since + * @param theme + * The new theme name + */ + public void setTheme(String theme) { + getState().theme = theme; } /** -- cgit v1.2.3