From b515618fedf9dff7ef534dec1d3b82fa6aa2206f Mon Sep 17 00:00:00 2001 From: Joonas Lehtinen Date: Wed, 24 Sep 2008 15:10:40 +0000 Subject: [PATCH] Fixes #2100 : Prevent window from being added to multiple places svn changeset:5507/svn branch:trunk --- src/com/itmill/toolkit/Application.java | 7 +++++++ src/com/itmill/toolkit/ui/Window.java | 14 ++++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/com/itmill/toolkit/Application.java b/src/com/itmill/toolkit/Application.java index c8f318979d..adbf587299 100644 --- a/src/com/itmill/toolkit/Application.java +++ b/src/com/itmill/toolkit/Application.java @@ -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(); diff --git a/src/com/itmill/toolkit/ui/Window.java b/src/com/itmill/toolkit/ui/Window.java index 8615480553..2d9ce6e9cf 100644 --- a/src/com/itmill/toolkit/ui/Window.java +++ b/src/com/itmill/toolkit/ui/Window.java @@ -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); -- 2.39.5