]> source.dussan.org Git - vaadin-framework.git/commitdiff
Allow JavaScriptConnectors to get unRegister events (#9292) 60/360/1
authorLeif Åstrand <leif@vaadin.com>
Fri, 23 Nov 2012 10:34:47 +0000 (12:34 +0200)
committerLeif Åstrand <leif@vaadin.com>
Fri, 23 Nov 2012 10:34:47 +0000 (12:34 +0200)
Change-Id: Ie9e11810df6484e34d3895be175d6a180911252f

client/src/com/vaadin/client/JavaScriptConnectorHelper.java
client/src/com/vaadin/client/JavaScriptExtension.java
client/src/com/vaadin/client/ui/JavaScriptComponentConnector.java
uitest/src/com/vaadin/tests/components/javascriptcomponent/BasicJavaScriptComponent.html
uitest/src/com/vaadin/tests/components/javascriptcomponent/BasicJavaScriptComponent.java
uitest/src/com/vaadin/tests/components/javascriptcomponent/BasicJavaScriptComponentConnector.js

index 80d5297d3344bc6128ae8dd767fb04ba942b901c..b275cd0a680ad9d0936926436078b0d8db10c488 100644 (file)
@@ -96,7 +96,7 @@ public class JavaScriptConnectorHelper {
                     inited = true;
                 }
 
-                fireNativeStateChange(wrapper);
+                invokeIfPresent(wrapper, "onStateChange");
             }
         });
     }
@@ -165,14 +165,6 @@ public class JavaScriptConnectorHelper {
         return connectorWrapper;
     }
 
-    private static native void fireNativeStateChange(
-            JavaScriptObject connectorWrapper)
-    /*-{
-        if (typeof connectorWrapper.onStateChange == 'function') {
-            connectorWrapper.onStateChange();
-        }
-    }-*/;
-
     private static native JavaScriptObject createConnectorWrapper(
             JavaScriptConnectorHelper h, ApplicationConnection c,
             JavaScriptObject nativeState, JavaScriptObject registeredRpc,
@@ -382,4 +374,16 @@ public class JavaScriptConnectorHelper {
         return (JavaScriptConnectorState) connector.getState();
     }
 
+    public void onUnregister() {
+        invokeIfPresent(connectorWrapper, "onUnregister");
+    }
+
+    private static native void invokeIfPresent(
+            JavaScriptObject connectorWrapper, String functionName)
+    /*-{
+        if (typeof connectorWrapper[functionName] == 'function') {
+            connectorWrapper[functionName].apply(connectorWrapper, arguments);
+        }
+    }-*/;
+
 }
index 0a3d6b81baa3da2f2eefa8ce5e5d9fc57f07cd3b..bf1bb5b56aae86d21c9d5bc29f2011bb88f17af6 100644 (file)
@@ -43,4 +43,10 @@ public final class JavaScriptExtension extends AbstractExtensionConnector
     public JavaScriptExtensionState getState() {
         return (JavaScriptExtensionState) super.getState();
     }
+
+    @Override
+    public void onUnregister() {
+        super.onUnregister();
+        helper.onUnregister();
+    }
 }
index 82ab32e23e2677ffc8c2eaaaa270c4bd5730c735..0dab9e21a6c6c3aebb3b6f87ce1c3664ed91d587 100644 (file)
@@ -54,4 +54,10 @@ public final class JavaScriptComponentConnector extends
     public JavaScriptComponentState getState() {
         return (JavaScriptComponentState) super.getState();
     }
+
+    @Override
+    public void onUnregister() {
+        super.onUnregister();
+        helper.onUnregister();
+    }
 }
index 56d86fdc6c3fcbd8c176aae5095e8c3e954cdea0..d7024b297254f576a9b97b020e339edad38e0e9c 100644 (file)
        <td>vaadin=runcomvaadintestscomponentsjavascriptcomponentBasicJavaScriptComponent::/VVerticalLayout[0]/VVerticalLayout[0]/JavaScriptWidget[0]/domChild[3]</td>
        <td>1. Parent element className: v-verticallayout v-layout v-vertical v-widget v-has-width</td>
 </tr>
+<tr>
+       <td>click</td>
+       <td>vaadin=runcomvaadintestscomponentsjavascriptcomponentBasicJavaScriptComponent::PID_SRemoveButton/domChild[0]/domChild[0]</td>
+       <td></td>
+</tr>
+<tr>
+       <td>assertText</td>
+       <td>vaadin=runcomvaadintestscomponentsjavascriptcomponentBasicJavaScriptComponent::PID_SRemoveButton</td>
+       <td>Remove componentDon't mess with me</td>
+</tr>
 </tbody></table>
 </body>
 </html>
index 9e316e77f1ef5b68c1621dc538ca9cd85ce13bc5..8fdd0fee87e7dee369f44ca030f8fb980f486e5d 100644 (file)
@@ -35,6 +35,8 @@ import com.vaadin.shared.ui.JavaScriptComponentState;
 import com.vaadin.tests.components.AbstractTestUI;
 import com.vaadin.tests.util.Log;
 import com.vaadin.ui.AbstractJavaScriptComponent;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.Button.ClickEvent;
 import com.vaadin.ui.HasComponents;
 import com.vaadin.ui.JavaScriptFunction;
 
@@ -142,9 +144,19 @@ public class BasicJavaScriptComponent extends AbstractTestUI {
     protected void setup(VaadinRequest request) {
         addComponent(log);
 
-        ExampleWidget c = new ExampleWidget();
+        final ExampleWidget c = new ExampleWidget();
         c.setCaption("Component caption");
         addComponent(c);
+
+        Button removeButton = new Button("Remove component",
+                new Button.ClickListener() {
+                    @Override
+                    public void buttonClick(ClickEvent event) {
+                        removeComponent(c);
+                    }
+                });
+        removeButton.setId("RemoveButton");
+        addComponent(removeButton);
     }
 
     @Override
index b0ece6217df5b245d9d168dde8bcc3db4c260efa..004d34040e7467da58721957f7c75c50c630b813 100644 (file)
@@ -35,6 +35,10 @@ window.com_vaadin_tests_components_javascriptcomponent_BasicJavaScriptComponent_
                }
        });
        
+       this.onUnregister = function() {
+               document.getElementById('RemoveButton').appendChild(document.createTextNode("Don't mess with me"));
+       };
+       
        this.messageToClient = function(message) {
                this.messageToServer(message + " processed");
        }