From 25f664f993a1eb936cb516f1b748773b9b4d5239 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Johannes=20Dahlstr=C3=B6m?= Date: Wed, 18 Jul 2012 16:39:36 +0300 Subject: [PATCH] Initial commit for root cleanup support (#7893) --- src/com/vaadin/Application.java | 23 +++++++++++++++++++ .../gwt/client/ui/root/RootConnector.java | 16 +++++++++++++ .../gwt/client/ui/root/RootServerRpc.java | 1 + src/com/vaadin/ui/Root.java | 16 +++++++++++++ 4 files changed, 56 insertions(+) diff --git a/src/com/vaadin/Application.java b/src/com/vaadin/Application.java index 468a7ee8be..79480f8dab 100644 --- a/src/com/vaadin/Application.java +++ b/src/com/vaadin/Application.java @@ -1066,6 +1066,7 @@ public class Application implements Terminal.ErrorListener, Serializable { * @see com.vaadin.terminal.Terminal.ErrorListener#terminalError(com.vaadin.terminal.Terminal.ErrorEvent) */ + @Override public void terminalError(Terminal.ErrorEvent event) { final Throwable t = event.getThrowable(); if (t instanceof SocketException) { @@ -1810,6 +1811,7 @@ public class Application implements Terminal.ErrorListener, Serializable { this.throwable = throwable; } + @Override public Throwable getThrowable() { return throwable; } @@ -2188,11 +2190,14 @@ public class Application implements Terminal.ErrorListener, Serializable { */ public Root getRootForRequest(WrappedRequest request) throws RootRequiresMoreInformationException { + System.out.println(" --- GET ROOT"); Root root = Root.getCurrent(); if (root != null) { + System.out.println(" ----- HAS CURRENT " + root.getRootId()); return root; } Integer rootId = getRootId(request); + System.out.println(" ----- ROOT ID FROM REQUEST " + rootId); synchronized (this) { BrowserDetails browserDetails = request.getBrowserDetails(); @@ -2202,6 +2207,7 @@ public class Application implements Terminal.ErrorListener, Serializable { root = roots.get(rootId); if (root == null && isRootPreserved()) { + System.out.println(" ----- ROOT NOT FOUND, CHECK IF PRESERVED"); // Check for a known root if (!retainOnRefreshRoots.isEmpty()) { @@ -2214,6 +2220,9 @@ public class Application implements Terminal.ErrorListener, Serializable { } if (retainedRootId != null) { + System.out.println(" ----- RETAINED ROOT ID " + + retainedRootId); + rootId = retainedRootId; root = roots.get(rootId); } @@ -2221,9 +2230,13 @@ public class Application implements Terminal.ErrorListener, Serializable { } if (root == null) { + System.out.println(" ----- ROOT STILL NULL"); + // Throws exception if root can not yet be created root = getRoot(request); + System.out.println(" ----- GET ROOT " + root.getRootId()); + // Initialize some fields for a newly created root if (root.getApplication() == null) { root.setApplication(this); @@ -2236,6 +2249,7 @@ public class Application implements Terminal.ErrorListener, Serializable { } root.setRootId(rootId.intValue()); roots.put(rootId, root); + System.out.println(" ----- CREATED ROOT " + rootId); } } @@ -2243,6 +2257,8 @@ public class Application implements Terminal.ErrorListener, Serializable { Root.setCurrent(root); if (!initedRoots.contains(rootId)) { + System.out.println(" ----- INIT ROOT " + rootId); + boolean initRequiresBrowserDetails = isRootPreserved() || !root.getClass() .isAnnotationPresent(EagerInit.class); @@ -2263,6 +2279,7 @@ public class Application implements Terminal.ErrorListener, Serializable { } } // end synchronized block + System.out.println(" ----- USING ROOT " + root.getRootId()); return root; } @@ -2387,4 +2404,10 @@ public class Application implements Terminal.ErrorListener, Serializable { public Root getRootById(int rootId) { return roots.get(rootId); } + + public void removeRoot(int rootId) { + System.out.println(" --- REMOVE ROOT ID " + rootId); + System.out.println(" ----- EXISTS? " + roots.containsKey(rootId)); + roots.remove(rootId); + } } diff --git a/src/com/vaadin/terminal/gwt/client/ui/root/RootConnector.java b/src/com/vaadin/terminal/gwt/client/ui/root/RootConnector.java index 2371fb1140..0ab27e92c1 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/root/RootConnector.java +++ b/src/com/vaadin/terminal/gwt/client/ui/root/RootConnector.java @@ -11,6 +11,8 @@ import com.google.gwt.core.client.Scheduler; import com.google.gwt.dom.client.NativeEvent; import com.google.gwt.dom.client.Style; import com.google.gwt.dom.client.Style.Position; +import com.google.gwt.event.logical.shared.CloseEvent; +import com.google.gwt.event.logical.shared.CloseHandler; import com.google.gwt.user.client.Command; import com.google.gwt.user.client.DOM; import com.google.gwt.user.client.Event; @@ -51,6 +53,7 @@ public class RootConnector extends AbstractComponentContainerConnector private HandlerRegistration childStateChangeHandlerRegistration; private final StateChangeHandler childStateChangeHandler = new StateChangeHandler() { + @Override public void onStateChanged(StateChangeEvent stateChangeEvent) { // TODO Should use a more specific handler that only reacts to // size changes @@ -62,12 +65,14 @@ public class RootConnector extends AbstractComponentContainerConnector protected void init() { super.init(); registerRpc(PageClientRpc.class, new PageClientRpc() { + @Override public void setTitle(String title) { com.google.gwt.user.client.Window.setTitle(title); } }); } + @Override public void updateFromUIDL(final UIDL uidl, ApplicationConnection client) { ConnectorMap paintableMap = ConnectorMap.get(getConnection()); getWidget().rendering = true; @@ -118,6 +123,7 @@ public class RootConnector extends AbstractComponentContainerConnector // to finish rendering this window in case this is a download // (and window stays open). Scheduler.get().scheduleDeferred(new Command() { + @Override public void execute() { VRoot.goTo(url); } @@ -182,6 +188,7 @@ public class RootConnector extends AbstractComponentContainerConnector if (uidl.hasAttribute("focused")) { // set focused component when render phase is finished Scheduler.get().scheduleDeferred(new Command() { + @Override public void execute() { ComponentConnector paintable = (ComponentConnector) uidl .getPaintableAttribute("focused", getConnection()); @@ -274,6 +281,13 @@ public class RootConnector extends AbstractComponentContainerConnector root.add(getWidget()); + Window.addCloseHandler(new CloseHandler() { + @Override + public void onClose(CloseEvent event) { + rpc.close(); + } + }); + if (applicationConnection.getConfiguration().isStandalone()) { // set focus to iview element by default to listen possible keyboard // shortcuts. For embedded applications this is unacceptable as we @@ -293,6 +307,7 @@ public class RootConnector extends AbstractComponentContainerConnector }; + @Override public void updateCaption(ComponentConnector component) { // NOP The main view never draws caption for its layout } @@ -412,6 +427,7 @@ public class RootConnector extends AbstractComponentContainerConnector } Scheduler.get().scheduleDeferred(new Command() { + @Override public void execute() { componentConnector.getWidget().getElement().scrollIntoView(); } diff --git a/src/com/vaadin/terminal/gwt/client/ui/root/RootServerRpc.java b/src/com/vaadin/terminal/gwt/client/ui/root/RootServerRpc.java index 389500949d..066645d130 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/root/RootServerRpc.java +++ b/src/com/vaadin/terminal/gwt/client/ui/root/RootServerRpc.java @@ -8,4 +8,5 @@ import com.vaadin.terminal.gwt.client.ui.ClickRpc; public interface RootServerRpc extends ClickRpc, ServerRpc { + public void close(); } \ No newline at end of file diff --git a/src/com/vaadin/ui/Root.java b/src/com/vaadin/ui/Root.java index 9271097a46..23f491949f 100644 --- a/src/com/vaadin/ui/Root.java +++ b/src/com/vaadin/ui/Root.java @@ -419,9 +419,16 @@ public abstract class Root extends AbstractComponentContainer implements private Page page = new Page(this); private RootServerRpc rpc = new RootServerRpc() { + @Override public void click(MouseEventDetails mouseDetails) { fireEvent(new ClickEvent(Root.this, mouseDetails)); } + + @Override + public void close() { + System.out.println(" --- ROOT CLOSE RPC " + rootId); + getApplication().removeRoot(rootId); + } }; /** @@ -502,6 +509,7 @@ public abstract class Root extends AbstractComponentContainer implements return this; } + @Override public void replaceComponent(Component oldComponent, Component newComponent) { throw new UnsupportedOperationException(); } @@ -511,6 +519,7 @@ public abstract class Root extends AbstractComponentContainer implements return application; } + @Override public void paintContent(PaintTarget target) throws PaintException { page.paintContent(target); @@ -550,6 +559,7 @@ public abstract class Root extends AbstractComponentContainer implements fireEvent(new ClickEvent(this, mouseDetails)); } + @Override @SuppressWarnings("unchecked") public void changeVariables(Object source, Map variables) { if (variables.containsKey(CLICK_EVENT_ID)) { @@ -578,6 +588,7 @@ public abstract class Root extends AbstractComponentContainer implements * * @see com.vaadin.ui.ComponentContainer#getComponentIterator() */ + @Override public Iterator getComponentIterator() { // TODO could directly create some kind of combined iterator instead of // creating a new ArrayList @@ -597,6 +608,7 @@ public abstract class Root extends AbstractComponentContainer implements * * @see com.vaadin.ui.ComponentContainer#getComponentCount() */ + @Override public int getComponentCount() { return windows.size() + (getContent() == null ? 0 : 1); } @@ -956,11 +968,13 @@ public abstract class Root extends AbstractComponentContainer implements return actionManager; } + @Override public void addAction( T action) { getActionManager().addAction(action); } + @Override public void removeAction( T action) { if (actionManager != null) { @@ -968,10 +982,12 @@ public abstract class Root extends AbstractComponentContainer implements } } + @Override public void addActionHandler(Handler actionHandler) { getActionManager().addActionHandler(actionHandler); } + @Override public void removeActionHandler(Handler actionHandler) { if (actionManager != null) { actionManager.removeActionHandler(actionHandler); -- 2.39.5