From 95e563a69b540bae2616466ae25646eba50d4afe Mon Sep 17 00:00:00 2001 From: Denis Anisimov Date: Wed, 12 Mar 2014 21:17:18 +0200 Subject: Prevent adding/setting parent component as child (#12720). Change-Id: I9b7b43f176e88d9edca591001297b94475a31854 --- server/src/com/vaadin/ui/AbstractComponent.java | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'server/src/com/vaadin/ui/AbstractComponent.java') diff --git a/server/src/com/vaadin/ui/AbstractComponent.java b/server/src/com/vaadin/ui/AbstractComponent.java index d980c27916..b6289e0b7d 100644 --- a/server/src/com/vaadin/ui/AbstractComponent.java +++ b/server/src/com/vaadin/ui/AbstractComponent.java @@ -991,4 +991,24 @@ public abstract class AbstractComponent extends AbstractClientConnector actionManager.removeAction(shortcut); } } + + /** + * Determine whether a content component is equal to, or the + * ancestor of this component. + * + * @param content + * the potential ancestor element + * @return true if the relationship holds + */ + protected boolean isOrHasAncestor(Component content) { + if (content instanceof HasComponents) { + for (Component parent = this; parent != null; parent = parent + .getParent()) { + if (parent == content) { + return true; + } + } + } + return false; + } } -- cgit v1.2.3