@Override public final void setParent(Parent parent) { if (parent == this.parent) { // Ignore } else if (parent == null || parent.canAddChild(this)) { // We always allow setting a null parent // Detach current parent if (this.parent != null) { this.parent.getModifiableChildren().remove(this); this.parent = null; } // Attach new parent if (parent != null) { parent.getModifiableChildren().add(this); this.parent = parent; } } else { throw new IllegalStateException("Can not set parent. child: " + getType() + " parent: " + parent.getType()); } }