/* 
@VaadinApache2LicenseForJavaFiles@
 */

package com.vaadin.terminal.gwt.client.extensions;

import com.vaadin.terminal.gwt.client.ServerConnector;
import com.vaadin.terminal.gwt.client.ui.AbstractConnector;

public abstract class AbstractExtensionConnector extends AbstractConnector {
    @Override
    public void setParent(ServerConnector parent) {
        ServerConnector oldParent = getParent();
        if (oldParent != null && oldParent != parent) {
            throw new IllegalStateException(
                    "An extension can not be moved from one parent to another.");
        }

        super.setParent(parent);

        extend(parent);
    }

    protected void extend(ServerConnector target) {
        // Default does nothing
    }
}

@@ -282,16 +282,54 @@
 ector %7B%0A
+    boolean hasBeenAttached = false;%0A%0A
     @Ove
@@ -334,16 +334,16 @@
 verride%0A
-
     publ
@@ -461,38 +461,125 @@
 ent 
-!= null && oldParent != parent
+== parent) %7B%0A            // Nothing to do%0A            return;%0A        %7D%0A        if (hasBeenAttached && parent != null
 ) %7B%0A
@@ -762,23 +762,103 @@
     
-extend(parent);
+if (parent != null) %7B%0A            extend(parent);%0A            hasBeenAttached = true;%0A        %7D
 %0A   

Allow detaching Extension once (#9282)