summaryrefslogtreecommitdiffstats
path: root/server/src/com/vaadin/ui/UI.java
diff options
context:
space:
mode:
authorJohannes Dahlström <johannesd@vaadin.com>2014-03-19 17:29:45 +0200
committerVaadin Code Review <review@vaadin.com>2014-03-31 08:39:15 +0000
commite4a50934a2cfb0e652b872376decf581bc0ab057 (patch)
treee7ea07ee5d1f13292ed6abcc9435c47892d8b10c /server/src/com/vaadin/ui/UI.java
parent7a91d29097e606a7e2dc4440443cb21ae7dfa61b (diff)
downloadvaadin-framework-e4a50934a2cfb0e652b872376decf581bc0ab057.tar.gz
vaadin-framework-e4a50934a2cfb0e652b872376decf581bc0ab057.zip
Add reinit method for preserve-on-refresh UIs (#12191)
UI.reinit() is now called when an existing, preserved UI is shown after a browser reload of the current page. The default implementation is empty. The browser window size and location are up to date in UI.reinit(); window resize and URI fragment listeners, if any, will be called after returning from UI.reinit(). Change-Id: Ie7aa670aaecf8e0e1510c91325b2a137b41263af
Diffstat (limited to 'server/src/com/vaadin/ui/UI.java')
-rw-r--r--server/src/com/vaadin/ui/UI.java57
1 files changed, 55 insertions, 2 deletions
diff --git a/server/src/com/vaadin/ui/UI.java b/server/src/com/vaadin/ui/UI.java
index b3004e9ad2..2b2e773601 100644
--- a/server/src/com/vaadin/ui/UI.java
+++ b/server/src/com/vaadin/ui/UI.java
@@ -16,6 +16,7 @@
package com.vaadin.ui;
+import java.net.URI;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@@ -27,6 +28,7 @@ import java.util.concurrent.Future;
import java.util.logging.Level;
import java.util.logging.Logger;
+import com.vaadin.annotations.PreserveOnRefresh;
import com.vaadin.event.Action;
import com.vaadin.event.Action.Handler;
import com.vaadin.event.ActionManager;
@@ -161,7 +163,7 @@ public abstract class UI extends AbstractSingleComponentContainer implements
public void resize(int viewWidth, int viewHeight, int windowWidth,
int windowHeight) {
// TODO We're not doing anything with the view dimensions
- getPage().updateBrowserWindowSize(windowWidth, windowHeight);
+ getPage().updateBrowserWindowSize(windowWidth, windowHeight, true);
}
@Override
@@ -361,7 +363,7 @@ public abstract class UI extends AbstractSingleComponentContainer implements
if (variables.containsKey(UIConstants.LOCATION_VARIABLE)) {
String location = (String) variables
.get(UIConstants.LOCATION_VARIABLE);
- getPage().updateLocation(location);
+ getPage().updateLocation(location, true);
}
}
@@ -660,6 +662,57 @@ public abstract class UI extends AbstractSingleComponentContainer implements
protected abstract void init(VaadinRequest request);
/**
+ * Internal reinitialization method, should not be overridden.
+ *
+ * @since 7.2
+ * @param request
+ * the request that caused this UI to be reloaded
+ */
+ public void doReinit(VaadinRequest request) {
+ // This is a horrible hack. We want to have the most recent location and
+ // browser window size available in reinit(), but we want to call
+ // listeners, if any, only after reinit(). So we momentarily assign the
+ // old values back before setting the new values again to ensure the
+ // events are properly fired.
+
+ Page page = getPage();
+
+ URI oldLocation = page.getLocation();
+ int oldWidth = page.getBrowserWindowWidth();
+ int oldHeight = page.getBrowserWindowHeight();
+
+ page.init(request);
+
+ reinit(request);
+
+ URI newLocation = page.getLocation();
+ int newWidth = page.getBrowserWindowWidth();
+ int newHeight = page.getBrowserWindowHeight();
+
+ page.updateLocation(oldLocation.toString(), false);
+ page.updateBrowserWindowSize(oldWidth, oldHeight, false);
+
+ page.updateLocation(newLocation.toString(), true);
+ page.updateBrowserWindowSize(newWidth, newHeight, true);
+ }
+
+ /**
+ * Reinitializes this UI after a browser refresh if the UI is set to be
+ * preserved on refresh, typically using the {@link PreserveOnRefresh}
+ * annotation. This method is intended to be overridden by subclasses if
+ * needed; the default implementation is empty.
+ * <p>
+ * The {@link VaadinRequest} can be used to get information about the
+ * request that caused this UI to be reloaded.
+ *
+ * @since 7.2
+ * @param request
+ * the request that caused this UI to be reloaded
+ */
+ protected void reinit(VaadinRequest request) {
+ }
+
+ /**
* Sets the thread local for the current UI. This method is used by the
* framework to set the current application whenever a new request is
* processed and it is cleared when the request has been processed.