]> source.dussan.org Git - vaadin-framework.git/commitdiff
Fixes #2100 : Prevent window from being added to multiple places
authorJoonas Lehtinen <joonas.lehtinen@itmill.com>
Wed, 24 Sep 2008 15:10:40 +0000 (15:10 +0000)
committerJoonas Lehtinen <joonas.lehtinen@itmill.com>
Wed, 24 Sep 2008 15:10:40 +0000 (15:10 +0000)
svn changeset:5507/svn branch:trunk

src/com/itmill/toolkit/Application.java
src/com/itmill/toolkit/ui/Window.java

index c8f318979d7f9ea58201678ac9c764614da6f3cb..adbf58729988843a60a9617d0d3f1c77cefce54c 100644 (file)
@@ -286,6 +286,13 @@ public abstract class Application implements URIHandler, Terminal.ErrorListener
             return;
         }
 
+        // Check that one is not adding a sub-window to application
+        if (window.getParent() != null) {
+            throw new IllegalArgumentException(
+                    "Window was already added inside another window"
+                            + " - it can not be added to application also.");
+        }
+
         // Gets the naming proposal from window
         String name = window.getName();
 
index 86154805530e75721bbcd2fb055929845b880444..2d9ce6e9cff10405a77236d8403fd5a310850d7e 100644 (file)
@@ -1009,13 +1009,19 @@ public class Window extends Panel implements URIHandler, ParameterHandler {
     public void addWindow(Window window) throws IllegalArgumentException,
             NullPointerException {
 
-        if (getParent() != null) {
+        if (window == null) {
+            throw new NullPointerException("Argument must not be null");
+        }
+
+        if (application.getWindows().contains(window)) {
             throw new IllegalArgumentException(
-                    "You can only add windows inside application-level windows");
+                    "Window was already added to application"
+                            + " - it can not be added to another window also.");
         }
 
-        if (window == null) {
-            throw new NullPointerException("Argument must not be null");
+        if (getParent() != null) {
+            throw new IllegalArgumentException(
+                    "You can only add windows inside application-level windows");
         }
 
         subwindows.add(window);