]> source.dussan.org Git - vaadin-framework.git/commitdiff
Make Vaadin component handling proxy-friendly (#14639)
authorJuuso Valli <juuso@vaadin.com>
Thu, 11 Sep 2014 13:34:03 +0000 (16:34 +0300)
committerJuuso Valli <juuso@vaadin.com>
Fri, 12 Sep 2014 10:40:25 +0000 (13:40 +0300)
Comparisons with the ==-operator between a proxy and it's underlying
instance fail, so we should use a custom equals method instead.
Change-Id: Iaa86ae830fecbedfb1f55636e25f5affebf5aba3

14 files changed:
server/src/com/vaadin/event/ActionManager.java
server/src/com/vaadin/server/AbstractClientConnector.java
server/src/com/vaadin/ui/AbstractComponent.java
server/src/com/vaadin/ui/AbstractComponentContainer.java
server/src/com/vaadin/ui/AbstractOrderedLayout.java
server/src/com/vaadin/ui/AbstractSingleComponentContainer.java
server/src/com/vaadin/ui/ConnectorTracker.java
server/src/com/vaadin/ui/CssLayout.java
server/src/com/vaadin/ui/CustomComponent.java
server/src/com/vaadin/ui/DateField.java
server/src/com/vaadin/ui/PopupView.java
server/src/com/vaadin/ui/TabSheet.java
server/src/com/vaadin/ui/Table.java
server/src/com/vaadin/ui/UI.java

index b42a5d8dde2684ddd9c0ecddf3fe1756257f481b..6eb698d08abfc75c9ddc4e22b7b6917db60211c8 100644 (file)
@@ -78,7 +78,10 @@ public class ActionManager implements Action.Container, Action.Handler,
 
     public <T extends Component & Container & VariableOwner> void setViewer(
             T viewer) {
-        if (viewer == this.viewer) {
+        // This somewhat complicated check exists to make sure that proxies are
+        // handled correctly
+        if (this.viewer == viewer
+                || (this.viewer != null && this.viewer.equals(viewer))) {
             return;
         }
         if (this.viewer != null) {
@@ -113,7 +116,7 @@ public class ActionManager implements Action.Container, Action.Handler,
 
     @Override
     public void addActionHandler(Handler actionHandler) {
-        if (actionHandler == this) {
+        if (equals(actionHandler)) {
             // don't add the actionHandler to itself
             return;
         }
index 19796af48d0cd65078273a7947b62ab6a67436eb..32277fcc3a95952e6eda1d38b8665cf26ec440c9 100644 (file)
@@ -43,6 +43,7 @@ import com.vaadin.ui.Component.Event;
 import com.vaadin.ui.HasComponents;
 import com.vaadin.ui.LegacyComponent;
 import com.vaadin.ui.UI;
+
 import elemental.json.JsonObject;
 
 /**
@@ -547,7 +548,7 @@ public abstract class AbstractClientConnector implements ClientConnector,
      */
     protected void addExtension(Extension extension) {
         ClientConnector previousParent = extension.getParent();
-        if (previousParent == this) {
+        if (equals(previousParent)) {
             // Nothing to do, already attached
             return;
         } else if (previousParent != null) {
@@ -997,4 +998,32 @@ public abstract class AbstractClientConnector implements ClientConnector,
     public void setErrorHandler(ErrorHandler errorHandler) {
         this.errorHandler = errorHandler;
     }
+
+    private AbstractClientConnector getInstance() {
+        // returns the underlying instance regardless of proxies
+        return this;
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see java.lang.Object#equals(java.lang.Object)
+     */
+    @Override
+    public boolean equals(Object obj) {
+        if (obj instanceof AbstractClientConnector) {
+            return super.equals(((AbstractClientConnector) obj).getInstance());
+        }
+        return false;
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see java.lang.Object#hashCode()
+     */
+    @Override
+    public int hashCode() {
+        return super.hashCode();
+    }
 }
index c9639813caa90a9499eb6e8b1146bf3328ebf12d..5c4fba739d91fa42a0f0ac7bdbf248b9e67ca8c3 100644 (file)
@@ -462,7 +462,7 @@ public abstract class AbstractComponent extends AbstractClientConnector
     @Override
     public void setParent(HasComponents parent) {
         // If the parent is not changed, don't do anything
-        if (parent == this.parent) {
+        if (parent == null ? this.parent == null : parent.equals(this.parent)) {
             return;
         }
 
@@ -1005,7 +1005,7 @@ public abstract class AbstractComponent extends AbstractClientConnector
         if (content instanceof HasComponents) {
             for (Component parent = this; parent != null; parent = parent
                     .getParent()) {
-                if (parent == content) {
+                if (parent.equals(content)) {
                     return true;
                 }
             }
index b1e69ba76bf91646a5b78125a83ab60da355446e..e70b0fa0cef85db375890773c5175920c0869220 100644 (file)
@@ -220,7 +220,7 @@ public abstract class AbstractComponentContainer extends AbstractComponent
      */
     @Override
     public void removeComponent(Component c) {
-        if (c.getParent() == this) {
+        if (equals(c.getParent())) {
             c.setParent(null);
             fireComponentDetachEvent(c);
         }
index 27880db75f35d81e6bc1e8485badbf472e2de277..638f6bc3f9182d1556cb9fd911a6943094e8a39a 100644 (file)
@@ -105,7 +105,7 @@ public abstract class AbstractOrderedLayout extends AbstractLayout implements
     public void addComponentAsFirst(Component c) {
         // If c is already in this, we must remove it before proceeding
         // see ticket #7668
-        if (c.getParent() == this) {
+        if (equals(c.getParent())) {
             removeComponent(c);
         }
         components.addFirst(c);
@@ -131,7 +131,7 @@ public abstract class AbstractOrderedLayout extends AbstractLayout implements
     public void addComponent(Component c, int index) {
         // If c is already in this, we must remove it before proceeding
         // see ticket #7668
-        if (c.getParent() == this) {
+        if (equals(c.getParent())) {
             // When c is removed, all components after it are shifted down
             if (index > getComponentIndex(c)) {
                 index--;
index ba108fc302fa812e92d8dfd62ddaf0892ec4af1f..e7b5205f2da3aa49acead4213345d779382f355b 100644 (file)
@@ -134,7 +134,7 @@ public abstract class AbstractSingleComponentContainer extends
             // do not set the same content twice
             return;
         }
-        if (oldContent != null && oldContent.getParent() == this) {
+        if (oldContent != null && equals(oldContent.getParent())) {
             oldContent.setParent(null);
             fireComponentDetachEvent(oldContent);
         }
index 5386eb9d646e359331f5864c904d21fd4bbde20c..95a80b7be0a9f2c988317537f4ac10fef237dc7c 100644 (file)
@@ -372,7 +372,7 @@ public class ConnectorTracker implements Serializable {
             for (ClientConnector child : children) {
                 stack.add(child);
 
-                if (child.getParent() != connector) {
+                if (!connector.equals(child.getParent())) {
                     noErrors = false;
                     getLogger()
                             .log(Level.WARNING,
index 7fdae32bd13303660651c379d8c33ca14aa221aa..e7b63cc87a8baa22c4778505139ddbad3395782b 100644 (file)
@@ -135,7 +135,7 @@ public class CssLayout extends AbstractLayout implements LayoutClickNotifier {
     public void addComponentAsFirst(Component c) {
         // If c is already in this, we must remove it before proceeding
         // see ticket #7668
-        if (c.getParent() == this) {
+        if (equals(c.getParent())) {
             removeComponent(c);
         }
         components.addFirst(c);
@@ -160,7 +160,7 @@ public class CssLayout extends AbstractLayout implements LayoutClickNotifier {
     public void addComponent(Component c, int index) {
         // If c is already in this, we must remove it before proceeding
         // see ticket #7668
-        if (c.getParent() == this) {
+        if (equals(c.getParent())) {
             // When c is removed, all components after it are shifted down
             if (index > getComponentIndex(c)) {
                 index--;
index cfd109d175c078236466f8752213ea0829a61b80..7f20086bbf98bb1fa0861bad84fe4d5b6534d404 100644 (file)
@@ -107,7 +107,7 @@ public class CustomComponent extends AbstractComponent implements HasComponents
      */
     protected void setCompositionRoot(Component compositionRoot) {
         if (compositionRoot != root) {
-            if (root != null && root.getParent() == this) {
+            if (root != null && equals(root.getParent())) {
                 // remove old component
                 root.setParent(null);
             }
index ba1178548fde7a014c8b2690e37927790da59b16..e88d767bc9d8e43bcbeeceb81d3a39ab567088ed 100644 (file)
@@ -723,7 +723,7 @@ public class DateField extends AbstractField<Date> implements
                 Collection<?> visibleItemProperties = f.getItemPropertyIds();
                 for (Object fieldId : visibleItemProperties) {
                     Field<?> field = f.getField(fieldId);
-                    if (field == this) {
+                    if (equals(field)) {
                         /*
                          * this datefield is logically in a form. Do the same
                          * thing as form does in its value change listener that
index 90c60edc6e9e76dda9f8019236d1934ccab5b031..2a2da26b62cbbd3c585f2a774e4be1144829b1ee 100644 (file)
@@ -152,7 +152,7 @@ public class PopupView extends AbstractComponent implements HasComponents {
                 }
                 visibleComponent.setParent(this);
             } else {
-                if (visibleComponent.getParent() == this) {
+                if (equals(visibleComponent.getParent())) {
                     visibleComponent.setParent(null);
                 }
                 visibleComponent = null;
index 0e4ea0d034b692b5a3199d08be5a6c09bc540335..d3410464a2300ff52ebf986ebc7fe6f0291ef8ef 100644 (file)
@@ -1229,7 +1229,7 @@ public class TabSheet extends AbstractComponentContainer implements Focusable,
         @Override
         public Component getComponent() {
             for (Map.Entry<Component, Tab> entry : tabs.entrySet()) {
-                if (entry.getValue() == this) {
+                if (equals(entry.getValue())) {
                     return entry.getKey();
                 }
             }
index 84e4eaed1326b25257614a3aedf3b13ccf080bb8..d574ed5ba80e873640eb0e7e384578acfe542420 100644 (file)
@@ -2386,7 +2386,7 @@ public class Table extends AbstractSelect implements Action.Container,
                 "Registered {0}: {1}",
                 new Object[] { component.getClass().getSimpleName(),
                         component.getCaption() });
-        if (component.getParent() != this) {
+        if (!equals(component.getParent())) {
             component.setParent(this);
         }
         visibleComponents.add(component);
@@ -4199,7 +4199,7 @@ public class Table extends AbstractSelect implements Action.Container,
 
     @Override
     public void valueChange(Property.ValueChangeEvent event) {
-        if (event.getProperty() == this
+        if (equals(event.getProperty())
                 || event.getProperty() == getPropertyDataSource()) {
             super.valueChange(event);
         } else {
index 5abeea9480ea8c28d494a5818233305ced620525..d67e08828aa117651c24be3174921c96c6db452b 100644 (file)
@@ -319,9 +319,9 @@ public abstract class UI extends AbstractSingleComponentContainer implements
 
         if (pendingFocus != null) {
             // ensure focused component is still attached to this main window
-            if (pendingFocus.getUI() == this
-                    || (pendingFocus.getUI() != null && pendingFocus.getUI()
-                            .getParent() == this)) {
+            if (equals(pendingFocus.getUI())
+                    || (pendingFocus.getUI() != null && equals(pendingFocus
+                            .getUI().getParent()))) {
                 target.addAttribute("focused", pendingFocus);
             }
             pendingFocus = null;